~ubuntu-branches/ubuntu/trusty/libjgoodies-forms-java/trusty

« back to all changes in this revision

Viewing changes to src/main/com/jgoodies/forms/factories/ButtonBarFactory.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2008-02-25 10:57:07 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080225105707-pe51fdbcq1dt3vi6
Tags: 1.2.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (c) 2002-2004 JGoodies Karsten Lentzsch. All Rights Reserved.
3
 
 *
4
 
 * Redistribution and use in source and binary forms, with or without 
5
 
 * modification, are permitted provided that the following conditions are met:
6
 
 * 
7
 
 *  o Redistributions of source code must retain the above copyright notice, 
8
 
 *    this list of conditions and the following disclaimer. 
9
 
 *     
10
 
 *  o Redistributions in binary form must reproduce the above copyright notice, 
11
 
 *    this list of conditions and the following disclaimer in the documentation 
12
 
 *    and/or other materials provided with the distribution. 
13
 
 *     
14
 
 *  o Neither the name of JGoodies Karsten Lentzsch nor the names of 
15
 
 *    its contributors may be used to endorse or promote products derived 
16
 
 *    from this software without specific prior written permission. 
17
 
 *     
18
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
19
 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
20
 
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
21
 
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
22
 
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
23
 
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
24
 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
25
 
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
26
 
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
27
 
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
28
 
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
29
 
 */
30
 
 
31
 
package com.jgoodies.forms.factories;
32
 
 
33
 
import javax.swing.JButton;
34
 
import javax.swing.JPanel;
35
 
 
36
 
import com.jgoodies.forms.builder.ButtonBarBuilder;
37
 
 
38
 
/**
39
 
 * A factory class that consists only of static methods to build frequently used 
40
 
 * button bars. Utilizes the {@link com.jgoodies.forms.builder.ButtonBarBuilder} 
41
 
 * that in turn uses the {@link com.jgoodies.forms.layout.FormLayout} 
42
 
 * to lay out the bars.<p>
43
 
 * 
44
 
 * The button bars returned by this builder comply with popular UI style guides.
45
 
 *
46
 
 * @author Karsten Lentzsch
47
 
 * @version $Revision: 1.8 $
48
 
 * 
49
 
 * @see com.jgoodies.forms.builder.ButtonBarBuilder
50
 
 * @see com.jgoodies.forms.util.LayoutStyle
51
 
 */
52
 
 
53
 
public final class ButtonBarFactory {
54
 
    
55
 
    
56
 
    private ButtonBarFactory() {
57
 
        // Suppresses default constructor, ensuring non-instantiability.
58
 
    }
59
 
 
60
 
        
61
 
    // General Purpose Factory Methods: Left Aligned ************************
62
 
 
63
 
    /**
64
 
     * Builds and returns a left aligned bar with one button.
65
 
     * 
66
 
     * @param button1  the first button to add
67
 
     * @return a button bar with the given button
68
 
     */
69
 
    public static JPanel buildLeftAlignedBar(JButton button1) {
70
 
        return buildLeftAlignedBar(new JButton[]{
71
 
                button1
72
 
                });
73
 
    }
74
 
    
75
 
    
76
 
    /**
77
 
     * Builds and returns a left aligned bar with two buttons.
78
 
     * 
79
 
     * @param button1  the first button to add
80
 
     * @param button2  the second button to add
81
 
     * @return a button bar with the given buttons
82
 
     */
83
 
    public static JPanel buildLeftAlignedBar(
84
 
            JButton button1, JButton button2) {
85
 
        return buildLeftAlignedBar(new JButton[]{
86
 
                button1, button2
87
 
                },
88
 
                true);
89
 
    }
90
 
    
91
 
    
92
 
    /**
93
 
     * Builds and returns a left aligned bar with three buttons.
94
 
     * 
95
 
     * @param button1  the first button to add
96
 
     * @param button2  the second button to add
97
 
     * @param button3  the third button to add
98
 
     * @return a button bar with the given buttons
99
 
     */
100
 
    public static JPanel buildLeftAlignedBar(
101
 
            JButton button1, JButton button2, JButton button3) {
102
 
        return buildLeftAlignedBar(new JButton[]{
103
 
                button1, button2, button3
104
 
                },
105
 
                true);
106
 
    }
107
 
    
108
 
    
109
 
    /**
110
 
     * Builds and returns a left aligned bar with four buttons.
111
 
     * 
112
 
     * @param button1  the first button to add
113
 
     * @param button2  the second button to add
114
 
     * @param button3  the third button to add
115
 
     * @param button4  the fourth button to add
116
 
     * @return a button bar with the given buttons
117
 
     */
118
 
    public static JPanel buildLeftAlignedBar(
119
 
            JButton button1, JButton button2, JButton button3, JButton button4) {
120
 
        return buildLeftAlignedBar(new JButton[]{
121
 
                button1, button2, button3, button4
122
 
                },
123
 
                true);
124
 
    }
125
 
    
126
 
    
127
 
    /**
128
 
     * Builds and returns a left aligned bar with five buttons.
129
 
     * 
130
 
     * @param button1  the first button to add
131
 
     * @param button2  the second button to add
132
 
     * @param button3  the third button to add
133
 
     * @param button4  the fourth button to add
134
 
     * @param button5  the fifth button to add
135
 
     * @return a button bar with the given buttons
136
 
     */
137
 
    public static JPanel buildLeftAlignedBar(
138
 
            JButton button1, JButton button2, JButton button3, 
139
 
            JButton button4, JButton button5) {
140
 
        return buildLeftAlignedBar(new JButton[]{
141
 
                button1, button2, button3, button4, button5
142
 
                },
143
 
                true);
144
 
    }   
145
 
    
146
 
    
147
 
    /**
148
 
     * Builds and returns a left aligned button bar with the given buttons.
149
 
     * 
150
 
     * @param buttons  an array of buttons to add
151
 
     * @return a left aligned button bar with the given buttons
152
 
     */
153
 
    public static JPanel buildLeftAlignedBar(JButton[] buttons) {
154
 
        ButtonBarBuilder builder = new ButtonBarBuilder();
155
 
        builder.addGriddedButtons(buttons);
156
 
        builder.addGlue();
157
 
        return builder.getPanel();
158
 
    }
159
 
    
160
 
 
161
 
    /**
162
 
     * Builds and returns a left aligned button bar with the given buttons.
163
 
     * 
164
 
     * @param buttons                  an array of buttons to add
165
 
     * @param leftToRightButtonOrder   the order in which the buttons to add
166
 
     * @return a left aligned button bar with the given buttons
167
 
     */
168
 
    public static JPanel buildLeftAlignedBar(
169
 
            JButton[] buttons,
170
 
            boolean  leftToRightButtonOrder) {
171
 
        ButtonBarBuilder builder = new ButtonBarBuilder();
172
 
        builder.setLeftToRightButtonOrder(leftToRightButtonOrder);
173
 
        builder.addGriddedButtons(buttons);
174
 
        builder.addGlue();
175
 
        return builder.getPanel();
176
 
    }
177
 
    
178
 
 
179
 
    // General Purpose Factory Methods: Centered ****************************
180
 
 
181
 
    /**
182
 
     * Builds and returns a centered bar with one button.
183
 
     * 
184
 
     * @param button1  the first button to add
185
 
     * @return a button bar with the given button
186
 
     */
187
 
    public static JPanel buildCenteredBar(JButton button1) {
188
 
        return buildCenteredBar(new JButton[]{
189
 
            button1
190
 
        });
191
 
    }
192
 
    
193
 
    
194
 
    /**
195
 
     * Builds and returns a centered bar with two buttons.
196
 
     * 
197
 
     * @param button1  the first button to add
198
 
     * @param button2  the second button to add
199
 
     * @return a button bar with the given buttons
200
 
     */
201
 
    public static JPanel buildCenteredBar(
202
 
            JButton button1, JButton button2) {
203
 
        return buildCenteredBar(new JButton[]{
204
 
            button1, button2
205
 
        });
206
 
    }
207
 
    
208
 
    
209
 
    /**
210
 
     * Builds and returns a centered bar with three buttons.
211
 
     * 
212
 
     * @param button1  the first button to add
213
 
     * @param button2  the second button to add
214
 
     * @param button3  the third button to add
215
 
     * @return a button bar with the given buttons
216
 
     */
217
 
    public static JPanel buildCenteredBar(
218
 
            JButton button1, JButton button2, JButton button3) {
219
 
        return buildCenteredBar(new JButton[]{
220
 
            button1, button2, button3
221
 
        });
222
 
    }
223
 
    
224
 
    
225
 
    /**
226
 
     * Builds and returns a centered bar with four buttons.
227
 
     * 
228
 
     * @param button1  the first button to add
229
 
     * @param button2  the second button to add
230
 
     * @param button3  the third button to add
231
 
     * @param button4  the fourth button to add
232
 
     * @return a button bar with the given buttons
233
 
     */
234
 
    public static JPanel buildCenteredBar(
235
 
            JButton button1, JButton button2, JButton button3, JButton button4) {
236
 
        return buildCenteredBar(new JButton[]{
237
 
            button1, button2, button3, button4
238
 
        });
239
 
    }
240
 
    
241
 
    
242
 
    /**
243
 
     * Builds and returns a centered bar with five buttons.
244
 
     * 
245
 
     * @param button1  the first button to add
246
 
     * @param button2  the second button to add
247
 
     * @param button3  the third button to add
248
 
     * @param button4  the fourth button to add
249
 
     * @param button5  the fifth button to add
250
 
     * @return a button bar with the given buttons
251
 
     */
252
 
    public static JPanel buildCenteredBar(
253
 
            JButton button1, JButton button2, JButton button3, 
254
 
            JButton button4, JButton button5) {
255
 
        return buildCenteredBar(new JButton[]{
256
 
            button1, button2, button3, button4, button5
257
 
        });
258
 
    }
259
 
    
260
 
    
261
 
    /**
262
 
     * Builds and returns a centered button bar with the given buttons.
263
 
     * 
264
 
     * @param buttons  an array of buttons to add
265
 
     * @return a centered button bar with the given buttons
266
 
     */
267
 
    public static JPanel buildCenteredBar(JButton[] buttons) {
268
 
        ButtonBarBuilder builder = new ButtonBarBuilder();
269
 
        builder.addGlue();
270
 
        builder.addGriddedButtons(buttons);
271
 
        builder.addGlue();
272
 
        return builder.getPanel();
273
 
    }
274
 
    
275
 
 
276
 
    /**
277
 
     * Builds and returns a filled bar with one button.
278
 
     * 
279
 
     * @param button1  the first button to add
280
 
     * @return a button bar with the given button
281
 
     */
282
 
    public static JPanel buildGrowingBar(JButton button1) {
283
 
        return buildGrowingBar(new JButton[]{
284
 
            button1
285
 
        });
286
 
    }
287
 
    
288
 
    
289
 
    /**
290
 
     * Builds and returns a filled button bar with two buttons.
291
 
     * 
292
 
     * @param button1  the first button to add
293
 
     * @param button2  the second button to add
294
 
     * @return a button bar with the given buttons
295
 
     */
296
 
    public static JPanel buildGrowingBar(
297
 
            JButton button1, JButton button2) {
298
 
        return buildGrowingBar(new JButton[]{
299
 
            button1, button2
300
 
        });
301
 
    }
302
 
    
303
 
    
304
 
    /**
305
 
     * Builds and returns a filled bar with three buttons.
306
 
     * 
307
 
     * @param button1  the first button to add
308
 
     * @param button2  the second button to add
309
 
     * @param button3  the third button to add
310
 
     * @return a button bar with the given buttons
311
 
     */
312
 
    public static JPanel buildGrowingBar(
313
 
            JButton button1, JButton button2, JButton button3) {
314
 
        return buildGrowingBar(new JButton[]{
315
 
            button1, button2, button3
316
 
        });
317
 
    }
318
 
    
319
 
    
320
 
    /**
321
 
     * Builds and returns a filled bar with four buttons.
322
 
     * 
323
 
     * @param button1  the first button to add
324
 
     * @param button2  the second button to add
325
 
     * @param button3  the third button to add
326
 
     * @param button4  the fourth button to add
327
 
     * @return a button bar with the given buttons
328
 
     */
329
 
    public static JPanel buildGrowingBar(
330
 
            JButton button1, JButton button2, JButton button3, JButton button4) {
331
 
        return buildGrowingBar(new JButton[]{
332
 
            button1, button2, button3, button4
333
 
        });
334
 
    }
335
 
    
336
 
    
337
 
    /**
338
 
     * Builds and returns a filled bar with five buttons.
339
 
     * 
340
 
     * @param button1  the first button to add
341
 
     * @param button2  the second button to add
342
 
     * @param button3  the third button to add
343
 
     * @param button4  the fourth button to add
344
 
     * @param button5  the fifth button to add
345
 
     * @return a button bar with the given buttons
346
 
     */
347
 
    public static JPanel buildGrowingBar(
348
 
            JButton button1, JButton button2, JButton button3, 
349
 
            JButton button4, JButton button5) {
350
 
        return buildGrowingBar(new JButton[]{
351
 
            button1, button2, button3, button4, button5
352
 
        });
353
 
    }
354
 
    
355
 
    
356
 
    /**
357
 
     * Builds and returns a button bar with the given buttons. All button
358
 
     * columns will grow with the bar.
359
 
     * 
360
 
     * @param buttons  an array of buttons to add
361
 
     * @return a filled button bar with the given buttons
362
 
     */
363
 
    public static JPanel buildGrowingBar(JButton[] buttons) {
364
 
        ButtonBarBuilder builder = new ButtonBarBuilder();
365
 
        builder.addGriddedGrowingButtons(buttons);
366
 
        return builder.getPanel();
367
 
    }
368
 
 
369
 
 
370
 
    // General Purpose Factory Methods: Right Aligned ***********************
371
 
 
372
 
    /**
373
 
     * Builds and returns a right aligned bar with one button.
374
 
     * 
375
 
     * @param button1  the first button to add
376
 
     * @return a button bar with the given button
377
 
     */
378
 
    public static JPanel buildRightAlignedBar(JButton button1) {
379
 
        return buildRightAlignedBar(new JButton[]{
380
 
                button1
381
 
                });
382
 
    }
383
 
    
384
 
    
385
 
    /**
386
 
     * Builds and returns a right aligned bar with two buttons.
387
 
     * 
388
 
     * @param button1  the first button to add
389
 
     * @param button2  the second button to add
390
 
     * @return a button bar with the given buttons
391
 
     */
392
 
    public static JPanel buildRightAlignedBar(
393
 
            JButton button1, JButton button2) {
394
 
        return buildRightAlignedBar(new JButton[]{
395
 
                button1, button2
396
 
                }, 
397
 
                true);
398
 
    }
399
 
    
400
 
    
401
 
    /**
402
 
     * Builds and returns a right aligned bar with three buttons.
403
 
     * 
404
 
     * @param button1  the first button to add
405
 
     * @param button2  the second button to add
406
 
     * @param button3  the third button to add
407
 
     * @return a button bar with the given buttons
408
 
     */
409
 
    public static JPanel buildRightAlignedBar(
410
 
            JButton button1, JButton button2, JButton button3) {
411
 
        return buildRightAlignedBar(new JButton[]{
412
 
                button1, button2, button3
413
 
                }, 
414
 
                true);
415
 
    }
416
 
    
417
 
    
418
 
    /**
419
 
     * Builds and returns a right aligned bar with four buttons.
420
 
     * 
421
 
     * @param button1  the first button to add
422
 
     * @param button2  the second button to add
423
 
     * @param button3  the third button to add
424
 
     * @param button4  the fourth button to add
425
 
     * @return a button bar with the given buttons
426
 
     */
427
 
    public static JPanel buildRightAlignedBar(
428
 
            JButton button1, JButton button2, JButton button3, JButton button4) {
429
 
        return buildRightAlignedBar(new JButton[]{
430
 
                button1, button2, button3, button4
431
 
                }, 
432
 
                true);
433
 
    }
434
 
    
435
 
    
436
 
    /**
437
 
     * Builds and returns a right aligned bar with five buttons.
438
 
     * 
439
 
     * @param button1  the first button to add
440
 
     * @param button2  the second button to add
441
 
     * @param button3  the third button to add
442
 
     * @param button4  the fourth button to add
443
 
     * @param button5  the fifth button to add
444
 
     * @return a button bar with the given buttons
445
 
     */
446
 
    public static JPanel buildRightAlignedBar(
447
 
            JButton button1, JButton button2, JButton button3, 
448
 
            JButton button4, JButton button5) {
449
 
        return buildRightAlignedBar(new JButton[]{
450
 
                button1, button2, button3, button4, button5
451
 
                }, 
452
 
                true);
453
 
    }
454
 
    
455
 
    
456
 
    /**
457
 
     * Builds and returns a right aligned button bar with the given buttons.
458
 
     * 
459
 
     * @param buttons  an array of buttons to add
460
 
     * @return a right aligned button bar with the given buttons
461
 
     */
462
 
    public static JPanel buildRightAlignedBar(JButton[] buttons) {
463
 
        ButtonBarBuilder builder = new ButtonBarBuilder();
464
 
        builder.addGlue();
465
 
        builder.addGriddedButtons(buttons);
466
 
        return builder.getPanel();
467
 
    }
468
 
    
469
 
 
470
 
    /**
471
 
     * Builds and returns a right aligned button bar with the given buttons.
472
 
     * 
473
 
     * @param buttons  an array of buttons to add
474
 
     * @param leftToRightButtonOrder   the order in which the buttons to add
475
 
     * @return a right aligned button bar with the given buttons
476
 
     */
477
 
    public static JPanel buildRightAlignedBar(
478
 
             JButton[] buttons,
479
 
             boolean leftToRightButtonOrder) {
480
 
        ButtonBarBuilder builder = new ButtonBarBuilder();
481
 
        builder.setLeftToRightButtonOrder(leftToRightButtonOrder);
482
 
        builder.addGlue();
483
 
        builder.addGriddedButtons(buttons);
484
 
        return builder.getPanel();
485
 
    }
486
 
    
487
 
 
488
 
    // Right Aligned Button Bars with Help in the Left **********************    
489
 
    
490
 
    /**
491
 
     * Builds and returns a right aligned bar with help and one button.
492
 
     * 
493
 
     * @param help     the help button to add on the left side
494
 
     * @param button1  the first button to add
495
 
     * @return a button bar with the given buttons
496
 
     */
497
 
    public static JPanel buildHelpBar(JButton help, 
498
 
            JButton button1) {
499
 
        return buildHelpBar(help, new JButton[]{
500
 
            button1
501
 
        });
502
 
    }
503
 
    
504
 
    
505
 
    /**
506
 
     * Builds and returns a right aligned bar with help and two buttons.
507
 
     * 
508
 
     * @param help     the help button to add on the left side
509
 
     * @param button1  the first button to add
510
 
     * @param button2  the second button to add
511
 
     * @return a button bar with the given buttons
512
 
     */
513
 
    public static JPanel buildHelpBar(JButton help,
514
 
            JButton button1, JButton button2) {
515
 
        return buildHelpBar(help, new JButton[]{
516
 
            button1, button2
517
 
        });
518
 
    }
519
 
    
520
 
    
521
 
    /**
522
 
     * Builds and returns a right aligned bar with help and three buttons.
523
 
     * 
524
 
     * @param help     the help button to add on the left side
525
 
     * @param button1  the first button to add
526
 
     * @param button2  the second button to add
527
 
     * @param button3  the third button to add
528
 
     * @return a button bar with the given buttons
529
 
     */
530
 
    public static JPanel buildHelpBar(JButton help,
531
 
            JButton button1, JButton button2, JButton button3) {
532
 
        return buildHelpBar(help, new JButton[]{
533
 
            button1, button2, button3
534
 
        });
535
 
    }
536
 
    
537
 
    
538
 
    /**
539
 
     * Builds and returns a right aligned bar with help and four buttons.
540
 
     * 
541
 
     * @param help     the help button to add on the left side
542
 
     * @param button1  the first button to add
543
 
     * @param button2  the second button to add
544
 
     * @param button3  the third button to add
545
 
     * @param button4  the fourth button to add
546
 
     * @return a button bar with the given buttons
547
 
     */
548
 
    public static JPanel buildHelpBar(JButton help,
549
 
            JButton button1, JButton button2, JButton button3, JButton button4) {
550
 
        return buildHelpBar(help, new JButton[]{
551
 
            button1, button2, button3, button4
552
 
        });
553
 
    }
554
 
    
555
 
    
556
 
    /**
557
 
     * Builds and returns a right aligned bar with help and other buttons.
558
 
     * 
559
 
     * @param help     the help button to add on the left side
560
 
     * @param buttons  an array of buttons to add
561
 
     * @return a right aligned button bar with the given buttons
562
 
     */
563
 
    public static JPanel buildHelpBar(JButton help, JButton[] buttons) {
564
 
        ButtonBarBuilder builder = new ButtonBarBuilder();
565
 
        builder.addGridded(help);
566
 
        builder.addRelatedGap();
567
 
        builder.addGlue();
568
 
        builder.addGriddedButtons(buttons);
569
 
        return builder.getPanel();
570
 
    }
571
 
 
572
 
 
573
 
    // Popular Dialog Button Bars: No Help **********************************    
574
 
        
575
 
    /**
576
 
     * Builds and returns a button bar with Close.
577
 
     * 
578
 
     * @param close     the Close button
579
 
     * @return a panel that contains the button(s)
580
 
     */
581
 
    public static JPanel buildCloseBar(JButton close) {
582
 
        return buildRightAlignedBar(close);
583
 
    }
584
 
    
585
 
    
586
 
        /**
587
 
         * Builds and returns a button bar with OK.
588
 
     * 
589
 
     * @param ok        the OK button
590
 
     * @return a panel that contains the button(s)
591
 
         */
592
 
        public static JPanel buildOKBar(JButton ok) {
593
 
        return buildRightAlignedBar(ok);
594
 
    }
595
 
        
596
 
        
597
 
    /**
598
 
     * Builds and returns a button bar with OK and Cancel.
599
 
     * 
600
 
     * @param ok                the OK button
601
 
     * @param cancel    the Cancel button
602
 
     * @return a panel that contains the button(s)
603
 
     */
604
 
    public static JPanel buildOKCancelBar(
605
 
            JButton ok, JButton cancel) {
606
 
        return buildRightAlignedBar(new JButton[] {ok, cancel});
607
 
    }
608
 
    
609
 
    
610
 
    /**
611
 
     * Builds and returns a button bar with OK, Cancel and Apply.
612
 
     * 
613
 
     * @param ok        the OK button
614
 
     * @param cancel    the Cancel button
615
 
     * @param apply     the Apply button
616
 
     * @return a panel that contains the button(s)
617
 
     */
618
 
    public static JPanel buildOKCancelApplyBar(
619
 
            JButton ok, JButton cancel, JButton apply) {
620
 
        return buildRightAlignedBar(new JButton[] {ok, cancel, apply});
621
 
    }
622
 
    
623
 
    
624
 
    // Popular Dialog Button Bars: Help in the Left *************************    
625
 
    
626
 
    /**
627
 
     * Builds and returns a button bar with 
628
 
     * Help and Close.
629
 
     * 
630
 
     * @param help     the Help button
631
 
     * @param close    the Close button
632
 
     * @return a panel that contains the button(s)
633
 
     */
634
 
    public static JPanel buildHelpCloseBar(
635
 
            JButton help, JButton close) {
636
 
        return buildHelpBar(help, close);
637
 
    }
638
 
    
639
 
    
640
 
    /**
641
 
     * Builds and returns a button bar with 
642
 
     * Help and OK.
643
 
     * 
644
 
     * @param help     the Help button
645
 
     * @param ok            the OK button
646
 
     * @return a panel that contains the button(s)
647
 
     */
648
 
    public static JPanel buildHelpOKBar(
649
 
            JButton help, JButton ok) {
650
 
        return buildHelpBar(help, ok);
651
 
    }
652
 
    
653
 
    
654
 
    /**
655
 
     * Builds and returns a button bar with 
656
 
     * Help, OK and Cancel.
657
 
     * 
658
 
     * @param help     the Help button
659
 
     * @param ok       the OK button
660
 
     * @param cancel    the Cancel button
661
 
     * @return a panel that contains the button(s)
662
 
     */
663
 
    public static JPanel buildHelpOKCancelBar(
664
 
            JButton help, JButton ok, JButton cancel) {
665
 
        return buildHelpBar(help, ok, cancel);
666
 
    }
667
 
    
668
 
    
669
 
    /**
670
 
     * Builds and returns a button bar with 
671
 
     * Help, OK, Cancel and Apply.
672
 
     * 
673
 
     * @param help     the Help button
674
 
     * @param ok       the OK button
675
 
     * @param cancel   the Cancel button
676
 
     * @param apply     the Apply button
677
 
     * @return a panel that contains the button(s)
678
 
     */
679
 
    public static JPanel buildHelpOKCancelApplyBar(
680
 
            JButton help, JButton ok, JButton cancel, JButton apply) {
681
 
        return buildHelpBar(help, ok, cancel, apply);
682
 
    }
683
 
    
684
 
    
685
 
    // Popular Dialog Button Bars: Help in the Right Hand Side **************    
686
 
    
687
 
    /**
688
 
     * Builds and returns a button bar with 
689
 
     * Close and Help.
690
 
     * 
691
 
     * @param close     the Close button
692
 
     * @param help     the Help button
693
 
     * @return a panel that contains the button(s)
694
 
     */
695
 
    public static JPanel buildCloseHelpBar(
696
 
            JButton close, JButton help) {
697
 
        return buildRightAlignedBar(new JButton[] {close, help});
698
 
    }
699
 
    
700
 
    
701
 
    /**
702
 
     * Builds and returns a button bar with 
703
 
     * OK and Help.
704
 
     * 
705
 
     * @param ok                the OK button
706
 
     * @param help     the Help button
707
 
     * @return a panel that contains the button(s)
708
 
     */
709
 
    public static JPanel buildOKHelpBar(
710
 
            JButton ok, JButton help) {
711
 
        return buildRightAlignedBar(new JButton[] {ok, help});
712
 
    }
713
 
    
714
 
    
715
 
    /**
716
 
     * Builds and returns a button bar with 
717
 
     * OK, Cancel, and Help.
718
 
     * 
719
 
     * @param ok       the OK button
720
 
     * @param cancel    the Cancel button
721
 
     * @param help     the Help button
722
 
     * @return a panel that contains the button(s)
723
 
     */
724
 
    public static JPanel buildOKCancelHelpBar(
725
 
            JButton ok, JButton cancel, JButton help) {
726
 
        return buildRightAlignedBar(new JButton[] {ok, cancel, help});
727
 
    }
728
 
    
729
 
    
730
 
    /**
731
 
     * Builds and returns a button bar with 
732
 
     * OK, Cancel, Apply and Help.
733
 
     * 
734
 
     * @param ok       the OK button
735
 
     * @param cancel    the Cancel button
736
 
     * @param apply     the Apply button
737
 
     * @param help     the Help button
738
 
     * @return a panel that contains the button(s)
739
 
     */
740
 
    public static JPanel buildOKCancelApplyHelpBar(
741
 
            JButton ok, JButton cancel, JButton apply, JButton help) {
742
 
        return buildRightAlignedBar(new JButton[] {ok, cancel, apply, help});
743
 
    }
744
 
    
745
 
    
746
 
    // Add..., Remove *******************************************************
747
 
        
748
 
    /**
749
 
     * Builds and returns a left aligned button bar with 
750
 
     * Add and Remove.
751
 
     * 
752
 
     * @param add               the Add button
753
 
     * @param remove    the Remove button
754
 
     * @return a panel that contains the button(s)
755
 
     */
756
 
    public static JPanel buildAddRemoveLeftBar(
757
 
            JButton add, JButton remove) {
758
 
        return buildLeftAlignedBar(add, remove);
759
 
    }
760
 
    
761
 
    
762
 
    /**
763
 
     * Builds and returns a filled button bar with Add and Remove.
764
 
     * 
765
 
     * @param add       the Add button
766
 
     * @param remove    the Remove button
767
 
     * @return a panel that contains the button(s)
768
 
     */
769
 
    public static JPanel buildAddRemoveBar(
770
 
            JButton add, JButton remove) {
771
 
        return buildGrowingBar(add, remove);
772
 
    }
773
 
    
774
 
    
775
 
    /**
776
 
     * Builds and returns a right aligned button bar with 
777
 
     * Add and Remove.
778
 
     * 
779
 
     * @param add       the Add button
780
 
     * @param remove    the Remove button
781
 
     * @return a panel that contains the button(s)
782
 
     */
783
 
    public static JPanel buildAddRemoveRightBar(
784
 
            JButton add, JButton remove) {
785
 
        return buildRightAlignedBar(add, remove);
786
 
    }
787
 
    
788
 
 
789
 
    // Add..., Remove, Properties... ****************************************
790
 
        
791
 
    /**
792
 
     * Builds and returns a left aligned button bar with 
793
 
     * Add, Remove, and Properties.
794
 
     * 
795
 
     * @param add               the Add button
796
 
     * @param remove            the Remove button
797
 
     * @param properties        the Properties button
798
 
     * @return a panel that contains the button(s)
799
 
     */
800
 
    public static JPanel buildAddRemovePropertiesLeftBar(
801
 
            JButton add, JButton remove, JButton properties) {
802
 
        return buildLeftAlignedBar(add, remove, properties);
803
 
    }
804
 
    
805
 
    
806
 
    /**
807
 
     * Builds and returns a filled button bar with Add, Remove, and
808
 
     * Properties.
809
 
     * 
810
 
     * @param add           the Add button
811
 
     * @param remove        the Remove button
812
 
     * @param properties    the Properties button
813
 
     * @return a panel that contains the button(s)
814
 
     */
815
 
    public static JPanel buildAddRemovePropertiesBar(
816
 
            JButton add, JButton remove, JButton properties) {
817
 
        ButtonBarBuilder builder = new ButtonBarBuilder();
818
 
        builder.addGriddedGrowing(add);
819
 
        builder.addRelatedGap();
820
 
        builder.addGriddedGrowing(remove);
821
 
        builder.addRelatedGap();
822
 
        builder.addGriddedGrowing(properties);
823
 
        return builder.getPanel();
824
 
    }
825
 
    
826
 
    
827
 
    /**
828
 
     * Builds and returns a right aligned button bar with 
829
 
     * Add, Remove, and Properties.
830
 
     * 
831
 
     * @param add           the Add button
832
 
     * @param remove        the Remove button
833
 
     * @param properties    the Properties button
834
 
     * @return a panel that contains the button(s)
835
 
     */
836
 
    public static JPanel buildAddRemovePropertiesRightBar(
837
 
            JButton add, JButton remove, JButton properties) {
838
 
        return buildRightAlignedBar(add, remove, properties);
839
 
    }
840
 
    
841
 
    
842
 
    // Wizard Bars **********************************************************
843
 
    
844
 
    /**
845
 
     * Builds and returns a wizard button bar with 
846
 
     * Back, Next, Finish, Cancel
847
 
     *
848
 
     * @param back              the Back button
849
 
     * @param next              the Next button
850
 
     * @param finish    the Finish button
851
 
     * @param cancel    the Cancel button
852
 
     * @return a wizard button bar for back, next, finish, cancel
853
 
     */
854
 
    public static JPanel buildWizardBar(
855
 
            JButton back, JButton next, JButton finish, JButton cancel) {
856
 
        return buildWizardBar(back, next, new JButton[]{finish, cancel});
857
 
    }
858
 
    
859
 
    
860
 
    /**
861
 
     * Builds and returns a wizard button bar with 
862
 
     * Help and Back, Next, Finish, Cancel
863
 
     * 
864
 
     * @param help              the Help button
865
 
     * @param back      the Back button
866
 
     * @param next      the Next button
867
 
     * @param finish    the Finish button
868
 
     * @param cancel    the Cancel button
869
 
     * @return a wizard button bar for help, back, next, finish, cancel
870
 
     */
871
 
    public static JPanel buildWizardBar(
872
 
            JButton help, JButton back, JButton next, JButton finish, JButton cancel) {
873
 
        return buildWizardBar(new JButton[]{help},
874
 
                               back, next, 
875
 
                               new JButton[]{finish, cancel});
876
 
    }
877
 
    
878
 
    
879
 
    /**
880
 
     * Builds and returns a wizard button bar that consists of the back and
881
 
     * next buttons, and some right aligned buttons.
882
 
     * 
883
 
     * @param back                the mandatory back button
884
 
     * @param next                the mandatory next button
885
 
     * @param rightAlignedButtons an optional array of buttons that will be
886
 
     *      located in the bar's right hand side
887
 
     * @return a wizard button bar with back, next and a bunch of buttons
888
 
     */
889
 
    public static JPanel buildWizardBar(JButton back, JButton next,
890
 
                                         JButton[] rightAlignedButtons) {
891
 
        return buildWizardBar(null, back, next, rightAlignedButtons);
892
 
    }
893
 
    
894
 
    
895
 
    /**
896
 
     * Builds and returns a wizard button bar. It consists of some left
897
 
     * aligned buttons, the back and next buttons, and some right aligned
898
 
     * buttons. 
899
 
     * 
900
 
     * @param leftAlignedButtons  an optional array of buttons that will be
901
 
     *     positioned in the bar's left hand side
902
 
     * @param back                the mandatory back button
903
 
     * @param next                the mandatory next button
904
 
     * @param rightAlignedButtons an optional array of buttons that will be
905
 
     *     located in the bar's right hand side
906
 
     * @return a wizard button bar with back, next and a bunch of buttons
907
 
     */
908
 
    public static JPanel buildWizardBar(JButton[] leftAlignedButtons,
909
 
                                         JButton back, JButton next,
910
 
                                         JButton[] rightAlignedButtons) {
911
 
        return buildWizardBar(leftAlignedButtons, 
912
 
                               back, next, null, 
913
 
                               rightAlignedButtons);
914
 
    }
915
 
    
916
 
    
917
 
    /**
918
 
     * Builds and returns a wizard button bar. It consists of some left
919
 
     * aligned buttons, the back, next group, and some right aligned buttons.
920
 
     * To allow the finish button to overlay the next button, you can
921
 
     * optionally provide the <code>overlayedFinish</code> parameter.
922
 
     * 
923
 
     * @param leftAlignedButtons  an optional array of buttons that will be
924
 
     *     positioned in the bar's left hand side
925
 
     * @param back                the mandatory back button
926
 
     * @param next                the mandatory next button
927
 
     * @param overlayedFinish     the optional overlayed finish button
928
 
     * @param rightAlignedButtons an optional array of buttons that will be
929
 
     *     located in the bar's right hand side
930
 
     * @return a wizard button bar with back, next and a bunch of buttons
931
 
     */
932
 
    public static JPanel buildWizardBar(JButton[] leftAlignedButtons,
933
 
                                         JButton back, 
934
 
                                         JButton next, 
935
 
                                         JButton overlayedFinish,
936
 
                                         JButton[] rightAlignedButtons) {
937
 
                                            
938
 
        ButtonBarBuilder builder = new ButtonBarBuilder();
939
 
        if (leftAlignedButtons != null) {
940
 
            builder.addGriddedButtons(leftAlignedButtons);
941
 
            builder.addRelatedGap();
942
 
        } 
943
 
        builder.addGlue();
944
 
        builder.addGridded(back);
945
 
        builder.addGridded(next);
946
 
        
947
 
        // Optionally overlay the finish and next button.
948
 
        if (overlayedFinish != null) {
949
 
            builder.nextColumn(-1);
950
 
            builder.add(overlayedFinish);
951
 
            builder.nextColumn();
952
 
        }
953
 
        
954
 
        if (rightAlignedButtons != null) {
955
 
            builder.addRelatedGap();
956
 
            builder.addGriddedButtons(rightAlignedButtons);
957
 
        } 
958
 
        return builder.getPanel();
959
 
    }
960
 
    
961
 
        
962
 
}
 
 
b'\\ No newline at end of file'