001/*
002 * Copyright (c) 2002-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003 *
004 * Redistribution and use in source and binary forms, with or without
005 * modification, are permitted provided that the following conditions are met:
006 *
007 *  o Redistributions of source code must retain the above copyright notice,
008 *    this list of conditions and the following disclaimer.
009 *
010 *  o Redistributions in binary form must reproduce the above copyright notice,
011 *    this list of conditions and the following disclaimer in the documentation
012 *    and/or other materials provided with the distribution.
013 *
014 *  o Neither the name of JGoodies Karsten Lentzsch nor the names of
015 *    its contributors may be used to endorse or promote products derived
016 *    from this software without specific prior written permission.
017 *
018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030
031package com.jgoodies.forms.factories;
032
033import javax.swing.JButton;
034import javax.swing.JPanel;
035
036import com.jgoodies.forms.builder.ButtonBarBuilder;
037
038/**
039 * A factory class that consists only of static methods to build frequently used
040 * button bars. Utilizes the {@link com.jgoodies.forms.builder.ButtonBarBuilder}
041 * that in turn uses the {@link com.jgoodies.forms.layout.FormLayout}
042 * to lay out the bars.<p>
043 *
044 * The button bars returned by this builder comply with popular UI style guides.
045 *
046 * @author Karsten Lentzsch
047 * @version $Revision$
048 *
049 * @see com.jgoodies.forms.builder.ButtonBarBuilder
050 * @see com.jgoodies.forms.util.LayoutStyle
051 */
052
053public final class ButtonBarFactory {
054
055    private ButtonBarFactory() {
056        // Suppresses default constructor, ensuring non-instantiability.
057    }
058
059    // General Purpose Factory Methods: Left Aligned ************************
060
061    /**
062     * Builds and returns a left aligned bar with one button.
063     *
064     * @param button1  the first button to add
065     * @return a button bar with the given button
066     */
067    public static JPanel buildLeftAlignedBar(JButton button1) {
068        return buildLeftAlignedBar(new JButton[] { button1 });
069    }
070
071    /**
072     * Builds and returns a left aligned bar with two buttons.
073     *
074     * @param button1  the first button to add
075     * @param button2  the second button to add
076     * @return a button bar with the given buttons
077     */
078    public static JPanel buildLeftAlignedBar(JButton button1, JButton button2) {
079        return buildLeftAlignedBar(new JButton[] { button1, button2 }, true);
080    }
081
082    /**
083     * Builds and returns a left aligned bar with three buttons.
084     *
085     * @param button1  the first button to add
086     * @param button2  the second button to add
087     * @param button3  the third button to add
088     * @return a button bar with the given buttons
089     */
090    public static JPanel buildLeftAlignedBar(JButton button1, JButton button2,
091            JButton button3) {
092        return buildLeftAlignedBar(new JButton[] { button1, button2, button3 },
093                true);
094    }
095
096    /**
097     * Builds and returns a left aligned bar with four buttons.
098     *
099     * @param button1  the first button to add
100     * @param button2  the second button to add
101     * @param button3  the third button to add
102     * @param button4  the fourth button to add
103     * @return a button bar with the given buttons
104     */
105    public static JPanel buildLeftAlignedBar(JButton button1, JButton button2,
106            JButton button3, JButton button4) {
107        return buildLeftAlignedBar(
108                new JButton[] { button1, button2, button3, button4 }, true);
109    }
110
111    /**
112     * Builds and returns a left aligned bar with five buttons.
113     *
114     * @param button1  the first button to add
115     * @param button2  the second button to add
116     * @param button3  the third button to add
117     * @param button4  the fourth button to add
118     * @param button5  the fifth button to add
119     * @return a button bar with the given buttons
120     */
121    public static JPanel buildLeftAlignedBar(JButton button1, JButton button2,
122            JButton button3, JButton button4, JButton button5) {
123        return buildLeftAlignedBar(
124                new JButton[] { button1, button2, button3, button4, button5 },
125                true);
126    }
127
128    /**
129     * Builds and returns a left aligned button bar with the given buttons.
130     *
131     * @param buttons  an array of buttons to add
132     * @return a left aligned button bar with the given buttons
133     */
134    public static JPanel buildLeftAlignedBar(JButton[] buttons) {
135        ButtonBarBuilder builder = new ButtonBarBuilder();
136        builder.addGriddedButtons(buttons);
137        builder.addGlue();
138        return builder.getPanel();
139    }
140
141    /**
142     * Builds and returns a left aligned button bar with the given buttons.
143     *
144     * @param buttons                  an array of buttons to add
145     * @param leftToRightButtonOrder   the order in which the buttons to add
146     * @return a left aligned button bar with the given buttons
147     */
148    public static JPanel buildLeftAlignedBar(JButton[] buttons,
149            boolean leftToRightButtonOrder) {
150        ButtonBarBuilder builder = new ButtonBarBuilder();
151        builder.setLeftToRightButtonOrder(leftToRightButtonOrder);
152        builder.addGriddedButtons(buttons);
153        builder.addGlue();
154        return builder.getPanel();
155    }
156
157    // General Purpose Factory Methods: Centered ****************************
158
159    /**
160     * Builds and returns a centered bar with one button.
161     *
162     * @param button1  the first button to add
163     * @return a button bar with the given button
164     */
165    public static JPanel buildCenteredBar(JButton button1) {
166        return buildCenteredBar(new JButton[] { button1 });
167    }
168
169    /**
170     * Builds and returns a centered bar with two buttons.
171     *
172     * @param button1  the first button to add
173     * @param button2  the second button to add
174     * @return a button bar with the given buttons
175     */
176    public static JPanel buildCenteredBar(JButton button1, JButton button2) {
177        return buildCenteredBar(new JButton[] { button1, button2 });
178    }
179
180    /**
181     * Builds and returns a centered bar with three buttons.
182     *
183     * @param button1  the first button to add
184     * @param button2  the second button to add
185     * @param button3  the third button to add
186     * @return a button bar with the given buttons
187     */
188    public static JPanel buildCenteredBar(JButton button1, JButton button2,
189            JButton button3) {
190        return buildCenteredBar(new JButton[] { button1, button2, button3 });
191    }
192
193    /**
194     * Builds and returns a centered bar with four buttons.
195     *
196     * @param button1  the first button to add
197     * @param button2  the second button to add
198     * @param button3  the third button to add
199     * @param button4  the fourth button to add
200     * @return a button bar with the given buttons
201     */
202    public static JPanel buildCenteredBar(JButton button1, JButton button2,
203            JButton button3, JButton button4) {
204        return buildCenteredBar(
205                new JButton[] { button1, button2, button3, button4 });
206    }
207
208    /**
209     * Builds and returns a centered bar with five buttons.
210     *
211     * @param button1  the first button to add
212     * @param button2  the second button to add
213     * @param button3  the third button to add
214     * @param button4  the fourth button to add
215     * @param button5  the fifth button to add
216     * @return a button bar with the given buttons
217     */
218    public static JPanel buildCenteredBar(JButton button1, JButton button2,
219            JButton button3, JButton button4, JButton button5) {
220        return buildCenteredBar(
221                new JButton[] { button1, button2, button3, button4, button5 });
222    }
223
224    /**
225     * Builds and returns 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 buildCenteredBar(JButton[] buttons) {
231        ButtonBarBuilder builder = new ButtonBarBuilder();
232        builder.addGlue();
233        builder.addGriddedButtons(buttons);
234        builder.addGlue();
235        return builder.getPanel();
236    }
237
238    /**
239     * Builds and returns a filled bar with one button.
240     *
241     * @param button1  the first button to add
242     * @return a button bar with the given button
243     */
244    public static JPanel buildGrowingBar(JButton button1) {
245        return buildGrowingBar(new JButton[] { button1 });
246    }
247
248    /**
249     * Builds and returns a filled button bar with two buttons.
250     *
251     * @param button1  the first button to add
252     * @param button2  the second button to add
253     * @return a button bar with the given buttons
254     */
255    public static JPanel buildGrowingBar(JButton button1, JButton button2) {
256        return buildGrowingBar(new JButton[] { button1, button2 });
257    }
258
259    /**
260     * Builds and returns a filled bar with three buttons.
261     *
262     * @param button1  the first button to add
263     * @param button2  the second button to add
264     * @param button3  the third button to add
265     * @return a button bar with the given buttons
266     */
267    public static JPanel buildGrowingBar(JButton button1, JButton button2,
268            JButton button3) {
269        return buildGrowingBar(new JButton[] { button1, button2, button3 });
270    }
271
272    /**
273     * Builds and returns a filled bar with four buttons.
274     *
275     * @param button1  the first button to add
276     * @param button2  the second button to add
277     * @param button3  the third button to add
278     * @param button4  the fourth button to add
279     * @return a button bar with the given buttons
280     */
281    public static JPanel buildGrowingBar(JButton button1, JButton button2,
282            JButton button3, JButton button4) {
283        return buildGrowingBar(
284                new JButton[] { button1, button2, button3, button4 });
285    }
286
287    /**
288     * Builds and returns a filled bar with five buttons.
289     *
290     * @param button1  the first button to add
291     * @param button2  the second button to add
292     * @param button3  the third button to add
293     * @param button4  the fourth button to add
294     * @param button5  the fifth button to add
295     * @return a button bar with the given buttons
296     */
297    public static JPanel buildGrowingBar(JButton button1, JButton button2,
298            JButton button3, JButton button4, JButton button5) {
299        return buildGrowingBar(
300                new JButton[] { button1, button2, button3, button4, button5 });
301    }
302
303    /**
304     * Builds and returns a button bar with the given buttons. All button
305     * columns will grow with the bar.
306     *
307     * @param buttons  an array of buttons to add
308     * @return a filled button bar with the given buttons
309     */
310    public static JPanel buildGrowingBar(JButton[] buttons) {
311        ButtonBarBuilder builder = new ButtonBarBuilder();
312        builder.addGriddedGrowingButtons(buttons);
313        return builder.getPanel();
314    }
315
316    // General Purpose Factory Methods: Right Aligned ***********************
317
318    /**
319     * Builds and returns a right aligned bar with one button.
320     *
321     * @param button1  the first button to add
322     * @return a button bar with the given button
323     */
324    public static JPanel buildRightAlignedBar(JButton button1) {
325        return buildRightAlignedBar(new JButton[] { button1 });
326    }
327
328    /**
329     * Builds and returns a right aligned bar with two buttons.
330     *
331     * @param button1  the first button to add
332     * @param button2  the second button to add
333     * @return a button bar with the given buttons
334     */
335    public static JPanel buildRightAlignedBar(JButton button1,
336            JButton button2) {
337        return buildRightAlignedBar(new JButton[] { button1, button2 }, true);
338    }
339
340    /**
341     * Builds and returns a right aligned bar with three buttons.
342     *
343     * @param button1  the first button to add
344     * @param button2  the second button to add
345     * @param button3  the third button to add
346     * @return a button bar with the given buttons
347     */
348    public static JPanel buildRightAlignedBar(JButton button1, JButton button2,
349            JButton button3) {
350        return buildRightAlignedBar(new JButton[] { button1, button2, button3 },
351                true);
352    }
353
354    /**
355     * Builds and returns a right aligned bar with four buttons.
356     *
357     * @param button1  the first button to add
358     * @param button2  the second button to add
359     * @param button3  the third button to add
360     * @param button4  the fourth button to add
361     * @return a button bar with the given buttons
362     */
363    public static JPanel buildRightAlignedBar(JButton button1, JButton button2,
364            JButton button3, JButton button4) {
365        return buildRightAlignedBar(
366                new JButton[] { button1, button2, button3, button4 }, true);
367    }
368
369    /**
370     * Builds and returns a right aligned bar with five buttons.
371     *
372     * @param button1  the first button to add
373     * @param button2  the second button to add
374     * @param button3  the third button to add
375     * @param button4  the fourth button to add
376     * @param button5  the fifth button to add
377     * @return a button bar with the given buttons
378     */
379    public static JPanel buildRightAlignedBar(JButton button1, JButton button2,
380            JButton button3, JButton button4, JButton button5) {
381        return buildRightAlignedBar(
382                new JButton[] { button1, button2, button3, button4, button5 },
383                true);
384    }
385
386    /**
387     * Builds and returns a right aligned button bar with the given buttons.
388     *
389     * @param buttons  an array of buttons to add
390     * @return a right aligned button bar with the given buttons
391     */
392    public static JPanel buildRightAlignedBar(JButton[] buttons) {
393        ButtonBarBuilder builder = new ButtonBarBuilder();
394        builder.addGlue();
395        builder.addGriddedButtons(buttons);
396        return builder.getPanel();
397    }
398
399    /**
400     * Builds and returns a right aligned button bar with the given buttons.
401     *
402     * @param buttons  an array of buttons to add
403     * @param leftToRightButtonOrder   the order in which the buttons to add
404     * @return a right aligned button bar with the given buttons
405     */
406    public static JPanel buildRightAlignedBar(JButton[] buttons,
407            boolean leftToRightButtonOrder) {
408        ButtonBarBuilder builder = new ButtonBarBuilder();
409        builder.setLeftToRightButtonOrder(leftToRightButtonOrder);
410        builder.addGlue();
411        builder.addGriddedButtons(buttons);
412        return builder.getPanel();
413    }
414
415    // Right Aligned Button Bars with Help in the Left **********************
416
417    /**
418     * Builds and returns a right aligned bar with help and one button.
419     *
420     * @param help     the help button to add on the left side
421     * @param button1  the first button to add
422     * @return a button bar with the given buttons
423     */
424    public static JPanel buildHelpBar(JButton help, JButton button1) {
425        return buildHelpBar(help, new JButton[] { button1 });
426    }
427
428    /**
429     * Builds and returns a right aligned bar with help and two buttons.
430     *
431     * @param help     the help button to add on the left side
432     * @param button1  the first button to add
433     * @param button2  the second button to add
434     * @return a button bar with the given buttons
435     */
436    public static JPanel buildHelpBar(JButton help, JButton button1,
437            JButton button2) {
438        return buildHelpBar(help, new JButton[] { button1, button2 });
439    }
440
441    /**
442     * Builds and returns a right aligned bar with help and three buttons.
443     *
444     * @param help     the help button to add on the left side
445     * @param button1  the first button to add
446     * @param button2  the second button to add
447     * @param button3  the third button to add
448     * @return a button bar with the given buttons
449     */
450    public static JPanel buildHelpBar(JButton help, JButton button1,
451            JButton button2, JButton button3) {
452        return buildHelpBar(help, new JButton[] { button1, button2, button3 });
453    }
454
455    /**
456     * Builds and returns a right aligned bar with help and four buttons.
457     *
458     * @param help     the help button to add on the left side
459     * @param button1  the first button to add
460     * @param button2  the second button to add
461     * @param button3  the third button to add
462     * @param button4  the fourth button to add
463     * @return a button bar with the given buttons
464     */
465    public static JPanel buildHelpBar(JButton help, JButton button1,
466            JButton button2, JButton button3, JButton button4) {
467        return buildHelpBar(help,
468                new JButton[] { button1, button2, button3, button4 });
469    }
470
471    /**
472     * Builds and returns a right aligned bar with help and other buttons.
473     *
474     * @param help     the help button to add on the left side
475     * @param buttons  an array of buttons to add
476     * @return a right aligned button bar with the given buttons
477     */
478    public static JPanel buildHelpBar(JButton help, JButton[] buttons) {
479        ButtonBarBuilder builder = new ButtonBarBuilder();
480        builder.addGridded(help);
481        builder.addRelatedGap();
482        builder.addGlue();
483        builder.addGriddedButtons(buttons);
484        return builder.getPanel();
485    }
486
487    // Popular Dialog Button Bars: No Help **********************************
488
489    /**
490     * Builds and returns a button bar with Close.
491     *
492     * @param close           the Close button
493     * @return a panel that contains the button(s)
494     */
495    public static JPanel buildCloseBar(JButton close) {
496        return buildRightAlignedBar(close);
497    }
498
499    /**
500     * Builds and returns a button bar with OK.
501     *
502     * @param ok           the OK button
503     * @return a panel that contains the button(s)
504     */
505    public static JPanel buildOKBar(JButton ok) {
506        return buildRightAlignedBar(ok);
507    }
508
509    /**
510     * Builds and returns a button bar with OK and Cancel.
511     *
512     * @param ok                the OK button
513     * @param cancel        the Cancel button
514     * @return a panel that contains the button(s)
515     */
516    public static JPanel buildOKCancelBar(JButton ok, JButton cancel) {
517        return buildRightAlignedBar(new JButton[] { ok, cancel });
518    }
519
520    /**
521     * Builds and returns a button bar with OK, Cancel and Apply.
522     *
523     * @param ok        the OK button
524     * @param cancel    the Cancel button
525     * @param apply        the Apply button
526     * @return a panel that contains the button(s)
527     */
528    public static JPanel buildOKCancelApplyBar(JButton ok, JButton cancel,
529            JButton apply) {
530        return buildRightAlignedBar(new JButton[] { ok, cancel, apply });
531    }
532
533    // Popular Dialog Button Bars: Help in the Left *************************
534
535    /**
536     * Builds and returns a button bar with
537     * Help and Close.
538     *
539     * @param help     the Help button
540     * @param close    the Close button
541     * @return a panel that contains the button(s)
542     */
543    public static JPanel buildHelpCloseBar(JButton help, JButton close) {
544        return buildHelpBar(help, close);
545    }
546
547    /**
548     * Builds and returns a button bar with
549     * Help and OK.
550     *
551     * @param help     the Help button
552     * @param ok            the OK button
553     * @return a panel that contains the button(s)
554     */
555    public static JPanel buildHelpOKBar(JButton help, JButton ok) {
556        return buildHelpBar(help, ok);
557    }
558
559    /**
560     * Builds and returns a button bar with
561     * Help, OK and Cancel.
562     *
563     * @param help     the Help button
564     * @param ok       the OK button
565     * @param cancel        the Cancel button
566     * @return a panel that contains the button(s)
567     */
568    public static JPanel buildHelpOKCancelBar(JButton help, JButton ok,
569            JButton cancel) {
570        return buildHelpBar(help, ok, cancel);
571    }
572
573    /**
574     * Builds and returns a button bar with
575     * Help, OK, Cancel and Apply.
576     *
577     * @param help     the Help button
578     * @param ok       the OK button
579     * @param cancel   the Cancel button
580     * @param apply        the Apply button
581     * @return a panel that contains the button(s)
582     */
583    public static JPanel buildHelpOKCancelApplyBar(JButton help, JButton ok,
584            JButton cancel, JButton apply) {
585        return buildHelpBar(help, ok, cancel, apply);
586    }
587
588    // Popular Dialog Button Bars: Help in the Right Hand Side **************
589
590    /**
591     * Builds and returns a button bar with
592     * Close and Help.
593     *
594     * @param close        the Close button
595     * @param help     the Help button
596     * @return a panel that contains the button(s)
597     */
598    public static JPanel buildCloseHelpBar(JButton close, JButton help) {
599        return buildRightAlignedBar(new JButton[] { close, help });
600    }
601
602    /**
603     * Builds and returns a button bar with
604     * OK and Help.
605     *
606     * @param ok                the OK button
607     * @param help     the Help button
608     * @return a panel that contains the button(s)
609     */
610    public static JPanel buildOKHelpBar(JButton ok, JButton help) {
611        return buildRightAlignedBar(new JButton[] { ok, help });
612    }
613
614    /**
615     * Builds and returns a button bar with
616     * OK, Cancel, and Help.
617     *
618     * @param ok       the OK button
619     * @param cancel        the Cancel button
620     * @param help     the Help button
621     * @return a panel that contains the button(s)
622     */
623    public static JPanel buildOKCancelHelpBar(JButton ok, JButton cancel,
624            JButton help) {
625        return buildRightAlignedBar(new JButton[] { ok, cancel, help });
626    }
627
628    /**
629     * Builds and returns a button bar with
630     * OK, Cancel, Apply and Help.
631     *
632     * @param ok       the OK button
633     * @param cancel        the Cancel button
634     * @param apply        the Apply button
635     * @param help     the Help button
636     * @return a panel that contains the button(s)
637     */
638    public static JPanel buildOKCancelApplyHelpBar(JButton ok, JButton cancel,
639            JButton apply, JButton help) {
640        return buildRightAlignedBar(new JButton[] { ok, cancel, apply, help });
641    }
642
643    // Add..., Remove *******************************************************
644
645    /**
646     * Builds and returns a left aligned button bar with
647     * Add and Remove.
648     *
649     * @param add                the Add button
650     * @param remove        the Remove button
651     * @return a panel that contains the button(s)
652     */
653    public static JPanel buildAddRemoveLeftBar(JButton add, JButton remove) {
654        return buildLeftAlignedBar(add, remove);
655    }
656
657    /**
658     * Builds and returns a filled button bar with Add and Remove.
659     *
660     * @param add       the Add button
661     * @param remove    the Remove button
662     * @return a panel that contains the button(s)
663     */
664    public static JPanel buildAddRemoveBar(JButton add, JButton remove) {
665        return buildGrowingBar(add, remove);
666    }
667
668    /**
669     * Builds and returns a right aligned button bar with
670     * Add and Remove.
671     *
672     * @param add       the Add button
673     * @param remove    the Remove button
674     * @return a panel that contains the button(s)
675     */
676    public static JPanel buildAddRemoveRightBar(JButton add, JButton remove) {
677        return buildRightAlignedBar(add, remove);
678    }
679
680    // Add..., Remove, Properties... ****************************************
681
682    /**
683     * Builds and returns a left aligned button bar with
684     * Add, Remove, and Properties.
685     *
686     * @param add               the Add button
687     * @param remove            the Remove button
688     * @param properties        the Properties button
689     * @return a panel that contains the button(s)
690     */
691    public static JPanel buildAddRemovePropertiesLeftBar(JButton add,
692            JButton remove, JButton properties) {
693        return buildLeftAlignedBar(add, remove, properties);
694    }
695
696    /**
697     * Builds and returns a filled button bar with Add, Remove, and
698     * Properties.
699     *
700     * @param add           the Add button
701     * @param remove        the Remove button
702     * @param properties    the Properties button
703     * @return a panel that contains the button(s)
704     */
705    public static JPanel buildAddRemovePropertiesBar(JButton add,
706            JButton remove, JButton properties) {
707        ButtonBarBuilder builder = new ButtonBarBuilder();
708        builder.addGriddedGrowing(add);
709        builder.addRelatedGap();
710        builder.addGriddedGrowing(remove);
711        builder.addRelatedGap();
712        builder.addGriddedGrowing(properties);
713        return builder.getPanel();
714    }
715
716    /**
717     * Builds and returns a right aligned button bar with
718     * Add, Remove, and Properties.
719     *
720     * @param add           the Add button
721     * @param remove        the Remove button
722     * @param properties    the Properties button
723     * @return a panel that contains the button(s)
724     */
725    public static JPanel buildAddRemovePropertiesRightBar(JButton add,
726            JButton remove, JButton properties) {
727        return buildRightAlignedBar(add, remove, properties);
728    }
729
730    // Wizard Bars **********************************************************
731
732    /**
733     * Builds and returns a wizard button bar with:
734     * Back, Next, Finish, Cancel.
735     *
736     * @param back                the Back button
737     * @param next                the Next button
738     * @param finish        the Finish button
739     * @param cancel        the Cancel button
740     * @return a wizard button bar for back, next, finish, cancel
741     */
742    public static JPanel buildWizardBar(JButton back, JButton next,
743            JButton finish, JButton cancel) {
744        return buildWizardBar(back, next, new JButton[] { finish, cancel });
745    }
746
747    /**
748     * Builds and returns a wizard button bar with:
749     * Help and Back, Next, Finish, Cancel.
750     *
751     * @param help                the Help button
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 help, back, next, finish, cancel
757     */
758    public static JPanel buildWizardBar(JButton help, JButton back,
759            JButton next, JButton finish, JButton cancel) {
760        return buildWizardBar(new JButton[] { help }, back, next,
761                new JButton[] { finish, cancel });
762    }
763
764    /**
765     * Builds and returns a wizard button bar that consists of the back and
766     * next buttons, and some right aligned buttons.
767     *
768     * @param back                the mandatory back button
769     * @param next                the mandatory next button
770     * @param rightAlignedButtons an optional array of buttons that will be
771     *      located in the bar's right hand side
772     * @return a wizard button bar with back, next and a bunch of buttons
773     */
774    public static JPanel buildWizardBar(JButton back, JButton next,
775            JButton[] rightAlignedButtons) {
776        return buildWizardBar(null, back, next, rightAlignedButtons);
777    }
778
779    /**
780     * Builds and returns a wizard button bar. It consists of some left
781     * aligned buttons, the back and next buttons, and some right aligned
782     * buttons.
783     *
784     * @param leftAlignedButtons  an optional array of buttons that will be
785     *     positioned in the bar's left hand side
786     * @param back                the mandatory back button
787     * @param next                the mandatory next button
788     * @param rightAlignedButtons an optional array of buttons that will be
789     *     located in the bar's right hand side
790     * @return a wizard button bar with back, next and a bunch of buttons
791     */
792    public static JPanel buildWizardBar(JButton[] leftAlignedButtons,
793            JButton back, JButton next, JButton[] rightAlignedButtons) {
794        return buildWizardBar(leftAlignedButtons, back, next, null,
795                rightAlignedButtons);
796    }
797
798    /**
799     * Builds and returns a wizard button bar. It consists of some left
800     * aligned buttons, the back, next group, and some right aligned buttons.
801     * To allow the finish button to overlay the next button, you can
802     * optionally provide the <code>overlayedFinish</code> parameter.
803     *
804     * @param leftAlignedButtons  an optional array of buttons that will be
805     *     positioned in the bar's left hand side
806     * @param back                the mandatory back button
807     * @param next                the mandatory next button
808     * @param overlayedFinish     the optional overlayed finish button
809     * @param rightAlignedButtons an optional array of buttons that will be
810     *     located in the bar's right hand side
811     * @return a wizard button bar with back, next and a bunch of buttons
812     */
813    public static JPanel buildWizardBar(JButton[] leftAlignedButtons,
814            JButton back, JButton next, JButton overlayedFinish,
815            JButton[] rightAlignedButtons) {
816
817        ButtonBarBuilder builder = new ButtonBarBuilder();
818        if (leftAlignedButtons != null) {
819            builder.addGriddedButtons(leftAlignedButtons);
820            builder.addRelatedGap();
821        }
822        builder.addGlue();
823        builder.addGridded(back);
824        builder.addGridded(next);
825
826        // Optionally overlay the finish and next button.
827        if (overlayedFinish != null) {
828            builder.nextColumn(-1);
829            builder.add(overlayedFinish);
830            builder.nextColumn();
831        }
832
833        if (rightAlignedButtons != null) {
834            builder.addRelatedGap();
835            builder.addGriddedButtons(rightAlignedButtons);
836        }
837        return builder.getPanel();
838    }
839
840}