KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > forms > factories > ButtonBarFactory


1 /*
2  * Copyright (c) 2003 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 JavaDoc;
34 import javax.swing.JPanel JavaDoc;
35
36 import com.jgoodies.forms.builder.ButtonBarBuilder;
37
38 /**
39  * A factory class that consists only of static methods to build frequently
40  * used button bars. Utilizes the
41  * {@link com.jgoodies.forms.builder.ButtonBarBuilder} that in turn uses
42  * the {@link com.jgoodies.forms.layout.FormLayout} to layout the bars.
43  * <p>
44  * The button bars answered by this build comply with popular UI style guides.
45  *
46  * @author Karsten Lentzsch
47  * @version $Revision: 1.3 $
48  */

49
50 public final class ButtonBarFactory {
51     
52     private ButtonBarFactory() {
53         // Suppresses default constructor, ensuring non-instantiability.
54
}
55
56     
57     // General Purpose Factory Methods: Left Aligned ************************
58

59     /**
60      * Builds and answers a left aligned bar with one button.
61      *
62      * @param button1 the first button to add
63      * @return a button bar with the given button
64      */

65     public static JPanel JavaDoc buildLeftAlignedBar(JButton JavaDoc button1) {
66         return buildLeftAlignedBar(new JButton JavaDoc[]{
67             button1
68         });
69     }
70     
71     /**
72      * Builds and answers a left aligned bar with two buttons.
73      *
74      * @param button1 the first button to add
75      * @param button2 the second button to add
76      * @return a button bar with the given buttons
77      */

78     public static JPanel JavaDoc buildLeftAlignedBar(
79             JButton JavaDoc button1, JButton JavaDoc button2) {
80         return buildLeftAlignedBar(new JButton JavaDoc[]{
81             button1, button2
82         });
83     }
84     
85     /**
86      * Builds and answers a left aligned bar with three buttons.
87      *
88      * @param button1 the first button to add
89      * @param button2 the second button to add
90      * @param button3 the third button to add
91      * @return a button bar with the given buttons
92      */

93     public static JPanel JavaDoc buildLeftAlignedBar(
94             JButton JavaDoc button1, JButton JavaDoc button2, JButton JavaDoc button3) {
95         return buildLeftAlignedBar(new JButton JavaDoc[]{
96             button1, button2, button3
97         });
98     }
99     
100     /**
101      * Builds and answers a left aligned bar with four buttons.
102      *
103      * @param button1 the first button to add
104      * @param button2 the second button to add
105      * @param button3 the third button to add
106      * @param button4 the fourth button to add
107      * @return a button bar with the given buttons
108      */

109     public static JPanel JavaDoc buildLeftAlignedBar(
110             JButton JavaDoc button1, JButton JavaDoc button2, JButton JavaDoc button3, JButton JavaDoc button4) {
111         return buildLeftAlignedBar(new JButton JavaDoc[]{
112             button1, button2, button3, button4
113         });
114     }
115     
116     /**
117      * Builds and answers a left aligned bar with five buttons.
118      *
119      * @param button1 the first button to add
120      * @param button2 the second button to add
121      * @param button3 the third button to add
122      * @param button4 the fourth button to add
123      * @param button5 the fifth button to add
124      * @return a button bar with the given buttons
125      */

126     public static JPanel JavaDoc buildLeftAlignedBar(
127             JButton JavaDoc button1, JButton JavaDoc button2, JButton JavaDoc button3,
128             JButton JavaDoc button4, JButton JavaDoc button5) {
129         return buildLeftAlignedBar(new JButton JavaDoc[]{
130             button1, button2, button3, button4, button5
131         });
132     }
133     
134     /**
135      * Builds and answers a left aligned button bar with the given buttons.
136      *
137      * @param buttons an array of buttons to add
138      * @return a left aligned button bar with the given buttons
139      */

140     public static JPanel JavaDoc buildLeftAlignedBar(JButton JavaDoc[] buttons) {
141         ButtonBarBuilder builder = new ButtonBarBuilder();
142         builder.addGriddedButtons(buttons);
143         builder.addGlue();
144         return builder.getPanel();
145     }
146
147     // General Purpose Factory Methods: Centered ****************************
148

149     /**
150      * Builds and answers a centered bar with one button.
151      *
152      * @param button1 the first button to add
153      * @return a button bar with the given button
154      */

155     public static JPanel JavaDoc buildCenteredBar(JButton JavaDoc button1) {
156         return buildCenteredBar(new JButton JavaDoc[]{
157             button1
158         });
159     }
160     
161     /**
162      * Builds and answers a centered bar with two buttons.
163      *
164      * @param button1 the first button to add
165      * @param button2 the second button to add
166      * @return a button bar with the given buttons
167      */

168     public static JPanel JavaDoc buildCenteredBar(
169             JButton JavaDoc button1, JButton JavaDoc button2) {
170         return buildCenteredBar(new JButton JavaDoc[]{
171             button1, button2
172         });
173     }
174     
175     /**
176      * Builds and answers a centered bar with three buttons.
177      *
178      * @param button1 the first button to add
179      * @param button2 the second button to add
180      * @param button3 the third button to add
181      * @return a button bar with the given buttons
182      */

183     public static JPanel JavaDoc buildCenteredBar(
184             JButton JavaDoc button1, JButton JavaDoc button2, JButton JavaDoc button3) {
185         return buildCenteredBar(new JButton JavaDoc[]{
186             button1, button2, button3
187         });
188     }
189     
190     /**
191      * Builds and answers a centered bar with four buttons.
192      *
193      * @param button1 the first button to add
194      * @param button2 the second button to add
195      * @param button3 the third button to add
196      * @param button4 the fourth button to add
197      * @return a button bar with the given buttons
198      */

199     public static JPanel JavaDoc buildCenteredBar(
200             JButton JavaDoc button1, JButton JavaDoc button2, JButton JavaDoc button3, JButton JavaDoc button4) {
201         return buildCenteredBar(new JButton JavaDoc[]{
202             button1, button2, button3, button4
203         });
204     }
205     
206     /**
207      * Builds and answers a centered bar with five buttons.
208      *
209      * @param button1 the first button to add
210      * @param button2 the second button to add
211      * @param button3 the third button to add
212      * @param button4 the fourth button to add
213      * @param button5 the fifth button to add
214      * @return a button bar with the given buttons
215      */

216     public static JPanel JavaDoc buildCenteredBar(
217             JButton JavaDoc button1, JButton JavaDoc button2, JButton JavaDoc button3,
218             JButton JavaDoc button4, JButton JavaDoc button5) {
219         return buildCenteredBar(new JButton JavaDoc[]{
220             button1, button2, button3, button4, button5
221         });
222     }
223     
224     /**
225      * Builds and answers a centered button bar with the given buttons.
226      *
227      * @param buttons an array of buttons to add
228      * @return a centered button bar with the given buttons
229      */

230     public static JPanel JavaDoc buildCenteredBar(JButton JavaDoc[] buttons) {
231         ButtonBarBuilder builder = new ButtonBarBuilder();
232         builder.addGlue();
233         builder.addGriddedButtons(buttons);
234         builder.addGlue();
235         return builder.getPanel();
236     }
237     
238
239     /**
240      * Builds and answers a filled bar with one button.
241      *
242      * @param button1 the first button to add
243      * @return a button bar with the given button
244      */

245     public static JPanel JavaDoc buildGrowingBar(JButton JavaDoc button1) {
246         return buildGrowingBar(new JButton JavaDoc[]{
247             button1
248         });
249     }
250     
251     /**
252      * Builds and answers a filled button bar with two buttons.
253      *
254      * @param button1 the first button to add
255      * @param button2 the second button to add
256      * @return a button bar with the given buttons
257      */

258     public static JPanel JavaDoc buildGrowingBar(
259             JButton JavaDoc button1, JButton JavaDoc button2) {
260         return buildGrowingBar(new JButton JavaDoc[]{
261             button1, button2
262         });
263     }
264     
265     /**
266      * Builds and answers a filled bar with three buttons.
267      *
268      * @param button1 the first button to add
269      * @param button2 the second button to add
270      * @param button3 the third button to add
271      * @return a button bar with the given buttons
272      */

273     public static JPanel JavaDoc buildGrowingBar(
274             JButton JavaDoc button1, JButton JavaDoc button2, JButton JavaDoc button3) {
275         return buildGrowingBar(new JButton JavaDoc[]{
276             button1, button2, button3
277         });
278     }
279     
280     /**
281      * Builds and answers a filled bar with four buttons.
282      *
283      * @param button1 the first button to add
284      * @param button2 the second button to add
285      * @param button3 the third button to add
286      * @param button4 the fourth button to add
287      * @return a button bar with the given buttons
288      */

289     public static JPanel JavaDoc buildGrowingBar(
290             JButton JavaDoc button1, JButton JavaDoc button2, JButton JavaDoc button3, JButton JavaDoc button4) {
291         return buildGrowingBar(new JButton JavaDoc[]{
292             button1, button2, button3, button4
293         });
294     }
295     
296     /**
297      * Builds and answers a filled bar with five buttons.
298      *
299      * @param button1 the first button to add
300      * @param button2 the second button to add
301      * @param button3 the third button to add
302      * @param button4 the fourth button to add
303      * @param button5 the fifth button to add
304      * @return a button bar with the given buttons
305      */

306     public static JPanel JavaDoc buildGrowingBar(
307             JButton JavaDoc button1, JButton JavaDoc button2, JButton JavaDoc button3,
308             JButton JavaDoc button4, JButton JavaDoc button5) {
309         return buildGrowingBar(new JButton JavaDoc[]{
310             button1, button2, button3, button4, button5
311         });
312     }
313     
314     /**
315      * Builds and answers a button bar with the given buttons. All button
316      * columns will grow with the bar.
317      *
318      * @param buttons an array of buttons to add
319      * @return a filled button bar with the given buttons
320      */

321     public static JPanel JavaDoc buildGrowingBar(JButton JavaDoc[] buttons) {
322         ButtonBarBuilder builder = new ButtonBarBuilder();
323         builder.addGriddedGrowingButtons(buttons);
324         return builder.getPanel();
325     }
326
327
328     // General Purpose Factory Methods: Right Aligned ***********************
329

330     /**
331      * Builds and answers a right aligned bar with one button.
332      *
333      * @param button1 the first button to add
334      * @return a button bar with the given button
335      */

336     public static JPanel JavaDoc buildRightAlignedBar(JButton JavaDoc button1) {
337         return buildRightAlignedBar(new JButton JavaDoc[]{
338             button1
339         });
340     }
341     
342     /**
343      * Builds and answers a right aligned bar with two buttons.
344      *
345      * @param button1 the first button to add
346      * @param button2 the second button to add
347      * @return a button bar with the given buttons
348      */

349     public static JPanel JavaDoc buildRightAlignedBar(
350             JButton JavaDoc button1, JButton JavaDoc button2) {
351         return buildRightAlignedBar(new JButton JavaDoc[]{
352             button1, button2
353         });
354     }
355     
356     /**
357      * Builds and answers a right aligned bar with three buttons.
358      *
359      * @param button1 the first button to add
360      * @param button2 the second button to add
361      * @param button3 the third button to add
362      * @return a button bar with the given buttons
363      */

364     public static JPanel JavaDoc buildRightAlignedBar(
365             JButton JavaDoc button1, JButton JavaDoc button2, JButton JavaDoc button3) {
366         return buildRightAlignedBar(new JButton JavaDoc[]{
367             button1, button2, button3
368         });
369     }
370     
371     /**
372      * Builds and answers a right aligned bar with four buttons.
373      *
374      * @param button1 the first button to add
375      * @param button2 the second button to add
376      * @param button3 the third button to add
377      * @param button4 the fourth button to add
378      * @return a button bar with the given buttons
379      */

380     public static JPanel JavaDoc buildRightAlignedBar(
381             JButton JavaDoc button1, JButton JavaDoc button2, JButton JavaDoc button3, JButton JavaDoc button4) {
382         return buildRightAlignedBar(new JButton JavaDoc[]{
383             button1, button2, button3, button4
384         });
385     }
386     
387     /**
388      * Builds and answers a right aligned bar with five buttons.
389      *
390      * @param button1 the first button to add
391      * @param button2 the second button to add
392      * @param button3 the third button to add
393      * @param button4 the fourth button to add
394      * @param button5 the fifth button to add
395      * @return a button bar with the given buttons
396      */

397     public static JPanel JavaDoc buildRightAlignedBar(
398             JButton JavaDoc button1, JButton JavaDoc button2, JButton JavaDoc button3,
399             JButton JavaDoc button4, JButton JavaDoc button5) {
400         return buildRightAlignedBar(new JButton JavaDoc[]{
401             button1, button2, button3, button4, button5
402         });
403     }
404     
405     /**
406      * Builds and answers a right aligned button bar with the given buttons.
407      *
408      * @param buttons an array of buttons to add
409      * @return a right aligned button bar with the given buttons
410      */

411     public static JPanel JavaDoc buildRightAlignedBar(JButton JavaDoc[] buttons) {
412         ButtonBarBuilder builder = new ButtonBarBuilder();
413         builder.addGlue();
414         builder.addGriddedButtons(buttons);
415         return builder.getPanel();
416     }
417     
418
419     // Right Aligned Button Bars with Help in the Left **********************
420

421     /**
422      * Builds and answers a right aligned bar with help and one button.
423      *
424      * @param help the help button to add on the left side
425      * @param button1 the first button to add
426      * @return a button bar with the given buttons
427      */

428     public static JPanel JavaDoc buildHelpBar(JButton JavaDoc help,
429             JButton JavaDoc button1) {
430         return buildHelpBar(help, new JButton JavaDoc[]{
431             button1
432         });
433     }
434     
435     /**
436      * Builds and answers a right aligned bar with help and two buttons.
437      *
438      * @param help the help button to add on the left side
439      * @param button1 the first button to add
440      * @param button2 the second button to add
441      * @return a button bar with the given buttons
442      */

443     public static JPanel JavaDoc buildHelpBar(JButton JavaDoc help,
444             JButton JavaDoc button1, JButton JavaDoc button2) {
445         return buildHelpBar(help, new JButton JavaDoc[]{
446             button1, button2
447         });
448     }
449     
450     /**
451      * Builds and answers a right aligned bar with help and three buttons.
452      *
453      * @param help the help button to add on the left side
454      * @param button1 the first button to add
455      * @param button2 the second button to add
456      * @param button3 the third button to add
457      * @return a button bar with the given buttons
458      */

459     public static JPanel JavaDoc buildHelpBar(JButton JavaDoc help,
460             JButton JavaDoc button1, JButton JavaDoc button2, JButton JavaDoc button3) {
461         return buildHelpBar(help, new JButton JavaDoc[]{
462             button1, button2, button3
463         });
464     }
465     
466     /**
467      * Builds and answers a right aligned bar with help and four buttons.
468      *
469      * @param help the help button to add on the left side
470      * @param button1 the first button to add
471      * @param button2 the second button to add
472      * @param button3 the third button to add
473      * @param button4 the fourth button to add
474      * @return a button bar with the given buttons
475      */

476     public static JPanel JavaDoc buildHelpBar(JButton JavaDoc help,
477             JButton JavaDoc button1, JButton JavaDoc button2, JButton JavaDoc button3, JButton JavaDoc button4) {
478         return buildHelpBar(help, new JButton JavaDoc[]{
479             button1, button2, button3, button4
480         });
481     }
482     
483     /**
484      * Builds and answers a right aligned bar with help and other buttons.
485      *
486      * @param help the help button to add on the left side
487      * @param buttons an array of buttons to add
488      * @return a right aligned button bar with the given buttons
489      */

490     public static JPanel JavaDoc buildHelpBar(JButton JavaDoc help, JButton JavaDoc[] buttons) {
491         ButtonBarBuilder builder = new ButtonBarBuilder();
492         builder.addGridded(help);
493         builder.addRelatedGap();
494         builder.addGlue();
495         builder.addGriddedButtons(buttons);
496         return builder.getPanel();
497     }
498
499
500     // Popular Dialog Button Bars: No Help **********************************
501

502     /**
503      * Builds and answers a button bar with Close.
504      *
505      * @param close the Close button
506      */

507     public static JPanel JavaDoc buildCloseBar(JButton JavaDoc close) {
508         return buildRightAlignedBar(close);
509     }
510     
511     /**
512      * Builds and answers a button bar with OK.
513      *
514      * @param ok the OK button
515      */

516     public static JPanel JavaDoc buildOKBar(JButton JavaDoc ok) {
517         return buildRightAlignedBar(ok);
518     }
519     
520     /**
521      * Builds and answers a button bar with OK and Cancel.
522      *
523      * @param ok the OK button
524      * @param cancel the Cancel button
525      */

526     public static JPanel JavaDoc buildOKCancelBar(
527             JButton JavaDoc ok, JButton JavaDoc cancel) {
528         return buildRightAlignedBar(ok, cancel);
529     }
530     
531     /**
532      * Builds and answers a button bar with OK, Cancel and Apply.
533      *
534      * @param ok the OK button
535      * @param cancel the Cancel button
536      * @param apply the Apply button
537      */

538     public static JPanel JavaDoc buildOKCancelApplyBar(
539             JButton JavaDoc ok, JButton JavaDoc cancel, JButton JavaDoc apply) {
540         return buildRightAlignedBar(ok, cancel, apply);
541     }
542     
543     // Popular Dialog Button Bars: Help in the Left *************************
544

545     /**
546      * Builds and answers a button bar with
547      * Help and Close.
548      *
549      * @param help the Help button
550      * @param close the Close button
551      */

552     public static JPanel JavaDoc buildHelpCloseBar(
553             JButton JavaDoc help, JButton JavaDoc close) {
554         return buildHelpBar(help, close);
555     }
556     
557     /**
558      * Builds and answers a button bar with
559      * Help and OK.
560      *
561      * @param help the Help button
562      * @param ok the OK button
563      */

564     public static JPanel JavaDoc buildHelpOKBar(
565             JButton JavaDoc help, JButton JavaDoc ok) {
566         return buildHelpBar(help, ok);
567     }
568     
569     /**
570      * Builds and answers a button bar with
571      * Help, OK and Cancel.
572      *
573      * @param help the Help button
574      * @param ok the OK button
575      * @param cancel the Cancel button
576      */

577     public static JPanel JavaDoc buildHelpOKCancelBar(
578             JButton JavaDoc help, JButton JavaDoc ok, JButton JavaDoc cancel) {
579         return buildHelpBar(help, ok, cancel);
580     }
581     
582     /**
583      * Builds and answers a button bar with
584      * Help, OK, Cancel and Apply.
585      *
586      * @param help the Help button
587      * @param ok the OK button
588      * @param cancel the Cancel button
589      * @param apply the Apply button
590      */

591     public static JPanel JavaDoc buildHelpOKCancelApplyBar(
592             JButton JavaDoc help, JButton JavaDoc ok, JButton JavaDoc cancel, JButton JavaDoc apply) {
593         return buildHelpBar(help, ok, cancel, apply);
594     }
595     
596     
597     // Popular Dialog Button Bars: Help in the Right Hand Side **************
598

599     /**
600      * Builds and answers a button bar with
601      * Close and Help.
602      *
603      * @param close the Close button
604      * @param help the Help button
605      */

606     public static JPanel JavaDoc buildCloseHelpBar(
607             JButton JavaDoc close, JButton JavaDoc help) {
608         return buildRightAlignedBar(close, help);
609     }
610     
611     /**
612      * Builds and answers a button bar with
613      * OK and Help.
614      *
615      * @param ok the OK button
616      * @param help the Help button
617      */

618     public static JPanel JavaDoc buildOKHelpBar(
619             JButton JavaDoc ok, JButton JavaDoc help) {
620         return buildRightAlignedBar(ok, help);
621     }
622     
623     /**
624      * Builds and answers a button bar with
625      * OK, Cancel, and Help.
626      *
627      * @param ok the OK button
628      * @param cancel the Cancel button
629      * @param help the Help button
630      */

631     public static JPanel JavaDoc buildOKCancelHelpBar(
632             JButton JavaDoc ok, JButton JavaDoc cancel, JButton JavaDoc help) {
633         return buildRightAlignedBar(ok, cancel, help);
634     }
635     
636     /**
637      * Builds and answers a button bar with
638      * OK, Cancel, Apply and Help.
639      *
640      * @param ok the OK button
641      * @param cancel the Cancel button
642      * @param apply the Apply button
643      * @param help the Help button
644      */

645     public static JPanel JavaDoc buildOKCancelApplyHelpBar(
646             JButton JavaDoc ok, JButton JavaDoc cancel, JButton JavaDoc apply, JButton JavaDoc help) {
647         return buildRightAlignedBar(ok, cancel, apply, help);
648     }
649     
650     
651     // Add..., Remove *******************************************************
652

653     /**
654      * Builds and answers a left aligned button bar with
655      * Add and Remove.
656      *
657      * @param add the Add button
658      * @param remove the Remove button
659      */

660     public static JPanel JavaDoc buildAddRemoveLeftBar(
661             JButton JavaDoc add, JButton JavaDoc remove) {
662         return buildLeftAlignedBar(add, remove);
663     }
664     
665     /**
666      * Builds and answers a filled button bar with Add and Remove.
667      *
668      * @param add the Add button
669      * @param remove the Remove button
670      */

671     public static JPanel JavaDoc buildAddRemoveBar(
672             JButton JavaDoc add, JButton JavaDoc remove) {
673         return buildGrowingBar(add, remove);
674     }
675     
676     /**
677      * Builds and answers a right aligned button bar with
678      * Add and Remove.
679      *
680      * @param add the Add button
681      * @param remove the Remove button
682      */

683     public static JPanel JavaDoc buildAddRemoveRightBar(
684             JButton JavaDoc add, JButton JavaDoc remove) {
685         return buildRightAlignedBar(add, remove);
686     }
687     
688
689     // Add..., Remove, Properties... ****************************************
690

691     /**
692      * Builds and answers a left aligned button bar with
693      * Add, Remove, and Properties.
694      *
695      * @param add the Add button
696      * @param remove the Remove button
697      * @param properties the Properties button
698      */

699     public static JPanel JavaDoc buildAddRemovePropertiesLeftBar(
700             JButton JavaDoc add, JButton JavaDoc remove, JButton JavaDoc properties) {
701         ButtonBarBuilder builder = new ButtonBarBuilder();
702         builder.addGriddedButtons(new JButton JavaDoc[]{
703             add, remove, properties
704         });
705         builder.addGlue();
706         return builder.getPanel();
707     }
708     
709     /**
710      * Builds and answers a filled button bar with Add, Remove, and
711      * Properties.
712      *
713      * @param add the Add button
714      * @param remove the Remove button
715      * @param properties the Properties button
716      */

717     public static JPanel JavaDoc buildAddRemovePropertiesBar(
718             JButton JavaDoc add, JButton JavaDoc remove, JButton JavaDoc properties) {
719         ButtonBarBuilder builder = new ButtonBarBuilder();
720         builder.addGriddedGrowing(add);
721         builder.addRelatedGap();
722         builder.addGriddedGrowing(remove);
723         builder.addRelatedGap();
724         builder.addGriddedGrowingNarrow(properties);
725         return builder.getPanel();
726     }
727     
728     /**
729      * Builds and answers a right aligned button bar with
730      * Add, Remove, and Properties.
731      *
732      * @param add the Add button
733      * @param remove the Remove button
734      * @param properties the Properties button
735      */

736     public static JPanel JavaDoc buildAddRemovePropertiesRightBar(
737             JButton JavaDoc add, JButton JavaDoc remove, JButton JavaDoc properties) {
738         ButtonBarBuilder builder = new ButtonBarBuilder();
739         builder.addGlue();
740         builder.addGriddedButtons(new JButton JavaDoc[]{
741             add, remove, properties
742         });
743         return builder.getPanel();
744     }
745     
746     // Wizard Bars **********************************************************
747

748     /**
749      * Builds and answers a wizard button bar with
750      * Back, Next, Finish, Cancel
751      *
752      * @param back the Back button
753      * @param next the Next button
754      * @param finish the Finish button
755      * @param cancel the Cancel button
756      * @return a wizard button bar for back, next, finish, cancel
757      */

758     public static JPanel JavaDoc buildWizardBar(
759             JButton JavaDoc back, JButton JavaDoc next, JButton JavaDoc finish, JButton JavaDoc cancel) {
760         return buildWizardBar(back, next, new JButton JavaDoc[]{finish, cancel});
761     }
762     
763     /**
764      * Builds and answers a wizard button bar with
765      * Help and Back, Next, Finish, Cancel
766      *
767      * @param help the Help button
768      * @param back the Back button
769      * @param next the Next button
770      * @param finish the Finish button
771      * @param cancel the Cancel button
772      * @return a wizard button bar for help, back, next, finish, cancel
773      */

774     public static JPanel JavaDoc buildWizardBar(
775             JButton JavaDoc help, JButton JavaDoc back, JButton JavaDoc next, JButton JavaDoc finish, JButton JavaDoc cancel) {
776         return buildWizardBar(new JButton JavaDoc[]{help},
777                                back, next,
778                                new JButton JavaDoc[]{finish, cancel});
779     }
780     
781     /**
782      * Builds and answers a wizard button bar that consists of the back and
783      * next buttons, and some right aligned buttons.
784      *
785      * @param back the mandatory back button
786      * @param next the mandatory next button
787      * @param rightAlignedButtons an optional array of buttons that will be
788      * located in the bar's right hand side
789      * @return a wizard button bar with back, next and a bunch of buttons
790      */

791     public static JPanel JavaDoc buildWizardBar(JButton JavaDoc back, JButton JavaDoc next,
792                                          JButton JavaDoc[] rightAlignedButtons) {
793         return buildWizardBar(null, back, next, rightAlignedButtons);
794     }
795     
796     /**
797      * Builds and answers a wizard button bar. It consists of some left
798      * aligned buttons, the back and next buttons, and some right aligned
799      * buttons.
800      *
801      * @param leftAlignedButtons an optional array of buttons that will be
802      * positioned in the bar's left hand side
803      * @param back the mandatory back button
804      * @param next the mandatory next button
805      * @param rightAlignedButtons an optional array of buttons that will be
806      * located in the bar's right hand side
807      * @return a wizard button bar with back, next and a bunch of buttons
808      */

809     public static JPanel JavaDoc buildWizardBar(JButton JavaDoc[] leftAlignedButtons,
810                                          JButton JavaDoc back, JButton JavaDoc next,
811                                          JButton JavaDoc[] rightAlignedButtons) {
812         return buildWizardBar(leftAlignedButtons,
813                                back, next, null,
814                                rightAlignedButtons);
815     }
816     
817     /**
818      * Builds and answers a wizard button bar. It consists of some left
819      * aligned buttons, the back, next group, and some right aligned buttons.
820      * To allow the finish button to overlay the next button, you can
821      * optionally provide the <code>overlayedFinish</code> parameter.
822      *
823      * @param leftAlignedButtons an optional array of buttons that will be
824      * positioned in the bar's left hand side
825      * @param back the mandatory back button
826      * @param next the mandatory next button
827      * @param overlayedFinish the optional overlayed finish button
828      * @param rightAlignedButtons an optional array of buttons that will be
829      * located in the bar's right hand side
830      * @return a wizard button bar with back, next and a bunch of buttons
831      */

832     public static JPanel JavaDoc buildWizardBar(JButton JavaDoc[] leftAlignedButtons,
833                                          JButton JavaDoc back,
834                                          JButton JavaDoc next,
835                                          JButton JavaDoc overlayedFinish,
836                                          JButton JavaDoc[] rightAlignedButtons) {
837                                             
838         ButtonBarBuilder builder = new ButtonBarBuilder();
839         if (leftAlignedButtons != null) {
840             builder.addGriddedButtons(leftAlignedButtons);
841             builder.addRelatedGap();
842         }
843         builder.addGlue();
844         builder.addGridded(back);
845         builder.addGridded(next);
846         
847         // Optionally overlay the finish and next button.
848
if (overlayedFinish != null) {
849             builder.nextColumn(-1);
850             builder.add(overlayedFinish);
851             builder.nextColumn();
852         }
853         
854         if (rightAlignedButtons != null) {
855             builder.addRelatedGap();
856             builder.addGriddedButtons(rightAlignedButtons);
857         }
858         return builder.getPanel();
859     }
860     
861     
862 }
Popular Tags