001: /*
002: * Copyright (c) 2002-2004 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:
031: package com.jgoodies.forms.factories;
032:
033: import javax.swing.JButton;
034: import javax.swing.JPanel;
035:
036: import 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} to lay out
042: * the bars.
043: * <p>
044: *
045: * The button bars returned by this builder comply with popular UI style guides.
046: *
047: * @author Karsten Lentzsch
048: * @version $Revision: 1.2 $
049: *
050: * @see com.jgoodies.forms.builder.ButtonBarBuilder
051: * @see com.jgoodies.forms.util.LayoutStyle
052: */
053:
054: public final class ButtonBarFactory {
055:
056: private ButtonBarFactory() {
057: // Suppresses default constructor, ensuring non-instantiability.
058: }
059:
060: // General Purpose Factory Methods: Left Aligned ************************
061:
062: /**
063: * Builds and returns a left aligned bar with one button.
064: *
065: * @param button1
066: * the first button to add
067: * @return a button bar with the given button
068: */
069: public static JPanel buildLeftAlignedBar(JButton button1) {
070: return buildLeftAlignedBar(new JButton[] { button1 });
071: }
072:
073: /**
074: * Builds and returns a left aligned bar with two buttons.
075: *
076: * @param button1
077: * the first button to add
078: * @param button2
079: * the second button to add
080: * @return a button bar with the given buttons
081: */
082: public static JPanel buildLeftAlignedBar(JButton button1,
083: JButton button2) {
084: return buildLeftAlignedBar(new JButton[] { button1, button2 },
085: true);
086: }
087:
088: /**
089: * Builds and returns a left aligned bar with three buttons.
090: *
091: * @param button1
092: * the first button to add
093: * @param button2
094: * the second button to add
095: * @param button3
096: * the third button to add
097: * @return a button bar with the given buttons
098: */
099: public static JPanel buildLeftAlignedBar(JButton button1,
100: JButton button2, JButton button3) {
101: return buildLeftAlignedBar(new JButton[] { button1, button2,
102: button3 }, true);
103: }
104:
105: /**
106: * Builds and returns a left aligned bar with four buttons.
107: *
108: * @param button1
109: * the first button to add
110: * @param button2
111: * the second button to add
112: * @param button3
113: * the third button to add
114: * @param button4
115: * the fourth button to add
116: * @return a button bar with the given buttons
117: */
118: public static JPanel buildLeftAlignedBar(JButton button1,
119: JButton button2, JButton button3, JButton button4) {
120: return buildLeftAlignedBar(new JButton[] { button1, button2,
121: button3, button4 }, true);
122: }
123:
124: /**
125: * Builds and returns a left aligned bar with five buttons.
126: *
127: * @param button1
128: * the first button to add
129: * @param button2
130: * the second button to add
131: * @param button3
132: * the third button to add
133: * @param button4
134: * the fourth button to add
135: * @param button5
136: * the fifth button to add
137: * @return a button bar with the given buttons
138: */
139: public static JPanel buildLeftAlignedBar(JButton button1,
140: JButton button2, JButton button3, JButton button4,
141: JButton button5) {
142: return buildLeftAlignedBar(new JButton[] { button1, button2,
143: button3, button4, button5 }, true);
144: }
145:
146: /**
147: * Builds and returns a left aligned button bar with the given buttons.
148: *
149: * @param buttons
150: * 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: * Builds and returns a left aligned button bar with the given buttons.
162: *
163: * @param buttons
164: * an array of buttons to add
165: * @param leftToRightButtonOrder
166: * the order in which the buttons to add
167: * @return a left aligned button bar with the given buttons
168: */
169: public static JPanel buildLeftAlignedBar(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: // General Purpose Factory Methods: Centered ****************************
179:
180: /**
181: * Builds and returns a centered bar with one button.
182: *
183: * @param button1
184: * 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[] { button1 });
189: }
190:
191: /**
192: * Builds and returns a centered bar with two buttons.
193: *
194: * @param button1
195: * the first button to add
196: * @param button2
197: * the second button to add
198: * @return a button bar with the given buttons
199: */
200: public static JPanel buildCenteredBar(JButton button1,
201: JButton button2) {
202: return buildCenteredBar(new JButton[] { button1, button2 });
203: }
204:
205: /**
206: * Builds and returns a centered bar with three buttons.
207: *
208: * @param button1
209: * the first button to add
210: * @param button2
211: * the second button to add
212: * @param button3
213: * the third button to add
214: * @return a button bar with the given buttons
215: */
216: public static JPanel buildCenteredBar(JButton button1,
217: JButton button2, JButton button3) {
218: return buildCenteredBar(new JButton[] { button1, button2,
219: button3 });
220: }
221:
222: /**
223: * Builds and returns a centered bar with four buttons.
224: *
225: * @param button1
226: * the first button to add
227: * @param button2
228: * the second button to add
229: * @param button3
230: * the third button to add
231: * @param button4
232: * the fourth button to add
233: * @return a button bar with the given buttons
234: */
235: public static JPanel buildCenteredBar(JButton button1,
236: JButton button2, JButton button3, JButton button4) {
237: return buildCenteredBar(new JButton[] { button1, button2,
238: button3, button4 });
239: }
240:
241: /**
242: * Builds and returns a centered bar with five buttons.
243: *
244: * @param button1
245: * the first button to add
246: * @param button2
247: * the second button to add
248: * @param button3
249: * the third button to add
250: * @param button4
251: * the fourth button to add
252: * @param button5
253: * the fifth button to add
254: * @return a button bar with the given buttons
255: */
256: public static JPanel buildCenteredBar(JButton button1,
257: JButton button2, JButton button3, JButton button4,
258: JButton button5) {
259: return buildCenteredBar(new JButton[] { button1, button2,
260: button3, button4, button5 });
261: }
262:
263: /**
264: * Builds and returns a centered button bar with the given buttons.
265: *
266: * @param buttons
267: * an array of buttons to add
268: * @return a centered button bar with the given buttons
269: */
270: public static JPanel buildCenteredBar(JButton[] buttons) {
271: ButtonBarBuilder builder = new ButtonBarBuilder();
272: builder.addGlue();
273: builder.addGriddedButtons(buttons);
274: builder.addGlue();
275: return builder.getPanel();
276: }
277:
278: /**
279: * Builds and returns a filled bar with one button.
280: *
281: * @param button1
282: * the first button to add
283: * @return a button bar with the given button
284: */
285: public static JPanel buildGrowingBar(JButton button1) {
286: return buildGrowingBar(new JButton[] { button1 });
287: }
288:
289: /**
290: * Builds and returns a filled button bar with two buttons.
291: *
292: * @param button1
293: * the first button to add
294: * @param button2
295: * the second button to add
296: * @return a button bar with the given buttons
297: */
298: public static JPanel buildGrowingBar(JButton button1,
299: JButton button2) {
300: return buildGrowingBar(new JButton[] { button1, button2 });
301: }
302:
303: /**
304: * Builds and returns a filled bar with three buttons.
305: *
306: * @param button1
307: * the first button to add
308: * @param button2
309: * the second button to add
310: * @param button3
311: * the third button to add
312: * @return a button bar with the given buttons
313: */
314: public static JPanel buildGrowingBar(JButton button1,
315: JButton button2, JButton button3) {
316: return buildGrowingBar(new JButton[] { button1, button2,
317: button3 });
318: }
319:
320: /**
321: * Builds and returns a filled bar with four buttons.
322: *
323: * @param button1
324: * the first button to add
325: * @param button2
326: * the second button to add
327: * @param button3
328: * the third button to add
329: * @param button4
330: * the fourth button to add
331: * @return a button bar with the given buttons
332: */
333: public static JPanel buildGrowingBar(JButton button1,
334: JButton button2, JButton button3, JButton button4) {
335: return buildGrowingBar(new JButton[] { button1, button2,
336: button3, button4 });
337: }
338:
339: /**
340: * Builds and returns a filled bar with five buttons.
341: *
342: * @param button1
343: * the first button to add
344: * @param button2
345: * the second button to add
346: * @param button3
347: * the third button to add
348: * @param button4
349: * the fourth button to add
350: * @param button5
351: * the fifth button to add
352: * @return a button bar with the given buttons
353: */
354: public static JPanel buildGrowingBar(JButton button1,
355: JButton button2, JButton button3, JButton button4,
356: JButton button5) {
357: return buildGrowingBar(new JButton[] { button1, button2,
358: button3, button4, button5 });
359: }
360:
361: /**
362: * Builds and returns a button bar with the given buttons. All button
363: * columns will grow with the bar.
364: *
365: * @param buttons
366: * an array of buttons to add
367: * @return a filled button bar with the given buttons
368: */
369: public static JPanel buildGrowingBar(JButton[] buttons) {
370: ButtonBarBuilder builder = new ButtonBarBuilder();
371: builder.addGriddedGrowingButtons(buttons);
372: return builder.getPanel();
373: }
374:
375: // General Purpose Factory Methods: Right Aligned ***********************
376:
377: /**
378: * Builds and returns a right aligned bar with one button.
379: *
380: * @param button1
381: * the first button to add
382: * @return a button bar with the given button
383: */
384: public static JPanel buildRightAlignedBar(JButton button1) {
385: return buildRightAlignedBar(new JButton[] { button1 });
386: }
387:
388: /**
389: * Builds and returns a right aligned bar with two buttons.
390: *
391: * @param button1
392: * the first button to add
393: * @param button2
394: * the second button to add
395: * @return a button bar with the given buttons
396: */
397: public static JPanel buildRightAlignedBar(JButton button1,
398: JButton button2) {
399: return buildRightAlignedBar(new JButton[] { button1, button2 },
400: true);
401: }
402:
403: /**
404: * Builds and returns a right aligned bar with three buttons.
405: *
406: * @param button1
407: * the first button to add
408: * @param button2
409: * the second button to add
410: * @param button3
411: * the third button to add
412: * @return a button bar with the given buttons
413: */
414: public static JPanel buildRightAlignedBar(JButton button1,
415: JButton button2, JButton button3) {
416: return buildRightAlignedBar(new JButton[] { button1, button2,
417: button3 }, true);
418: }
419:
420: /**
421: * Builds and returns a right aligned bar with four buttons.
422: *
423: * @param button1
424: * the first button to add
425: * @param button2
426: * the second button to add
427: * @param button3
428: * the third button to add
429: * @param button4
430: * the fourth button to add
431: * @return a button bar with the given buttons
432: */
433: public static JPanel buildRightAlignedBar(JButton button1,
434: JButton button2, JButton button3, JButton button4) {
435: return buildRightAlignedBar(new JButton[] { button1, button2,
436: button3, button4 }, true);
437: }
438:
439: /**
440: * Builds and returns a right aligned bar with five buttons.
441: *
442: * @param button1
443: * the first button to add
444: * @param button2
445: * the second button to add
446: * @param button3
447: * the third button to add
448: * @param button4
449: * the fourth button to add
450: * @param button5
451: * the fifth button to add
452: * @return a button bar with the given buttons
453: */
454: public static JPanel buildRightAlignedBar(JButton button1,
455: JButton button2, JButton button3, JButton button4,
456: JButton button5) {
457: return buildRightAlignedBar(new JButton[] { button1, button2,
458: button3, button4, button5 }, true);
459: }
460:
461: /**
462: * Builds and returns a right aligned button bar with the given buttons.
463: *
464: * @param buttons
465: * an array of buttons to add
466: * @return a right aligned button bar with the given buttons
467: */
468: public static JPanel buildRightAlignedBar(JButton[] buttons) {
469: ButtonBarBuilder builder = new ButtonBarBuilder();
470: builder.addGlue();
471: builder.addGriddedButtons(buttons);
472: return builder.getPanel();
473: }
474:
475: /**
476: * Builds and returns a right aligned button bar with the given buttons.
477: *
478: * @param buttons
479: * an array of buttons to add
480: * @param leftToRightButtonOrder
481: * the order in which the buttons to add
482: * @return a right aligned button bar with the given buttons
483: */
484: public static JPanel buildRightAlignedBar(JButton[] buttons,
485: boolean leftToRightButtonOrder) {
486: ButtonBarBuilder builder = new ButtonBarBuilder();
487: builder.setLeftToRightButtonOrder(leftToRightButtonOrder);
488: builder.addGlue();
489: builder.addGriddedButtons(buttons);
490: return builder.getPanel();
491: }
492:
493: // Right Aligned Button Bars with Help in the Left **********************
494:
495: /**
496: * Builds and returns a right aligned bar with help and one button.
497: *
498: * @param help
499: * the help button to add on the left side
500: * @param button1
501: * the first button to add
502: * @return a button bar with the given buttons
503: */
504: public static JPanel buildHelpBar(JButton help, JButton button1) {
505: return buildHelpBar(help, new JButton[] { button1 });
506: }
507:
508: /**
509: * Builds and returns a right aligned bar with help and two buttons.
510: *
511: * @param help
512: * the help button to add on the left side
513: * @param button1
514: * the first button to add
515: * @param button2
516: * the second button to add
517: * @return a button bar with the given buttons
518: */
519: public static JPanel buildHelpBar(JButton help, JButton button1,
520: JButton button2) {
521: return buildHelpBar(help, new JButton[] { button1, button2 });
522: }
523:
524: /**
525: * Builds and returns a right aligned bar with help and three buttons.
526: *
527: * @param help
528: * the help button to add on the left side
529: * @param button1
530: * the first button to add
531: * @param button2
532: * the second button to add
533: * @param button3
534: * the third button to add
535: * @return a button bar with the given buttons
536: */
537: public static JPanel buildHelpBar(JButton help, JButton button1,
538: JButton button2, JButton button3) {
539: return buildHelpBar(help, new JButton[] { button1, button2,
540: button3 });
541: }
542:
543: /**
544: * Builds and returns a right aligned bar with help and four buttons.
545: *
546: * @param help
547: * the help button to add on the left side
548: * @param button1
549: * the first button to add
550: * @param button2
551: * the second button to add
552: * @param button3
553: * the third button to add
554: * @param button4
555: * the fourth button to add
556: * @return a button bar with the given buttons
557: */
558: public static JPanel buildHelpBar(JButton help, JButton button1,
559: JButton button2, JButton button3, JButton button4) {
560: return buildHelpBar(help, new JButton[] { button1, button2,
561: button3, button4 });
562: }
563:
564: /**
565: * Builds and returns a right aligned bar with help and other buttons.
566: *
567: * @param help
568: * the help button to add on the left side
569: * @param buttons
570: * an array of buttons to add
571: * @return a right aligned button bar with the given buttons
572: */
573: public static JPanel buildHelpBar(JButton help, JButton[] buttons) {
574: ButtonBarBuilder builder = new ButtonBarBuilder();
575: builder.addGridded(help);
576: builder.addRelatedGap();
577: builder.addGlue();
578: builder.addGriddedButtons(buttons);
579: return builder.getPanel();
580: }
581:
582: // Popular Dialog Button Bars: No Help **********************************
583:
584: /**
585: * Builds and returns a button bar with Close.
586: *
587: * @param close
588: * the Close button
589: * @return a panel that contains the button(s)
590: */
591: public static JPanel buildCloseBar(JButton close) {
592: return buildRightAlignedBar(close);
593: }
594:
595: /**
596: * Builds and returns a button bar with OK.
597: *
598: * @param ok
599: * the OK button
600: * @return a panel that contains the button(s)
601: */
602: public static JPanel buildOKBar(JButton ok) {
603: return buildRightAlignedBar(ok);
604: }
605:
606: /**
607: * Builds and returns a button bar with OK and Cancel.
608: *
609: * @param ok
610: * the OK button
611: * @param cancel
612: * the Cancel button
613: * @return a panel that contains the button(s)
614: */
615: public static JPanel buildOKCancelBar(JButton ok, JButton cancel) {
616: return buildRightAlignedBar(new JButton[] { ok, cancel });
617: }
618:
619: /**
620: * Builds and returns a button bar with OK, Cancel and Apply.
621: *
622: * @param ok
623: * the OK button
624: * @param cancel
625: * the Cancel button
626: * @param apply
627: * the Apply button
628: * @return a panel that contains the button(s)
629: */
630: public static JPanel buildOKCancelApplyBar(JButton ok,
631: JButton cancel, JButton apply) {
632: return buildRightAlignedBar(new JButton[] { ok, cancel, apply });
633: }
634:
635: // Popular Dialog Button Bars: Help in the Left *************************
636:
637: /**
638: * Builds and returns a button bar with Help and Close.
639: *
640: * @param help
641: * the Help button
642: * @param close
643: * the Close button
644: * @return a panel that contains the button(s)
645: */
646: public static JPanel buildHelpCloseBar(JButton help, JButton close) {
647: return buildHelpBar(help, close);
648: }
649:
650: /**
651: * Builds and returns a button bar with Help and OK.
652: *
653: * @param help
654: * the Help button
655: * @param ok
656: * the OK button
657: * @return a panel that contains the button(s)
658: */
659: public static JPanel buildHelpOKBar(JButton help, JButton ok) {
660: return buildHelpBar(help, ok);
661: }
662:
663: /**
664: * Builds and returns a button bar with Help, OK and Cancel.
665: *
666: * @param help
667: * the Help button
668: * @param ok
669: * the OK button
670: * @param cancel
671: * the Cancel button
672: * @return a panel that contains the button(s)
673: */
674: public static JPanel buildHelpOKCancelBar(JButton help, JButton ok,
675: JButton cancel) {
676: return buildHelpBar(help, ok, cancel);
677: }
678:
679: /**
680: * Builds and returns a button bar with Help, OK, Cancel and Apply.
681: *
682: * @param help
683: * the Help button
684: * @param ok
685: * the OK button
686: * @param cancel
687: * the Cancel button
688: * @param apply
689: * the Apply button
690: * @return a panel that contains the button(s)
691: */
692: public static JPanel buildHelpOKCancelApplyBar(JButton help,
693: JButton ok, JButton cancel, JButton apply) {
694: return buildHelpBar(help, ok, cancel, apply);
695: }
696:
697: // Popular Dialog Button Bars: Help in the Right Hand Side **************
698:
699: /**
700: * Builds and returns a button bar with Close and Help.
701: *
702: * @param close
703: * the Close button
704: * @param help
705: * the Help button
706: * @return a panel that contains the button(s)
707: */
708: public static JPanel buildCloseHelpBar(JButton close, JButton help) {
709: return buildRightAlignedBar(new JButton[] { close, help });
710: }
711:
712: /**
713: * Builds and returns a button bar with OK and Help.
714: *
715: * @param ok
716: * the OK button
717: * @param help
718: * the Help button
719: * @return a panel that contains the button(s)
720: */
721: public static JPanel buildOKHelpBar(JButton ok, JButton help) {
722: return buildRightAlignedBar(new JButton[] { ok, help });
723: }
724:
725: /**
726: * Builds and returns a button bar with OK, Cancel, and Help.
727: *
728: * @param ok
729: * the OK button
730: * @param cancel
731: * the Cancel button
732: * @param help
733: * the Help button
734: * @return a panel that contains the button(s)
735: */
736: public static JPanel buildOKCancelHelpBar(JButton ok,
737: JButton cancel, JButton help) {
738: return buildRightAlignedBar(new JButton[] { ok, cancel, help });
739: }
740:
741: /**
742: * Builds and returns a button bar with OK, Cancel, Apply and Help.
743: *
744: * @param ok
745: * the OK button
746: * @param cancel
747: * the Cancel button
748: * @param apply
749: * the Apply button
750: * @param help
751: * the Help button
752: * @return a panel that contains the button(s)
753: */
754: public static JPanel buildOKCancelApplyHelpBar(JButton ok,
755: JButton cancel, JButton apply, JButton help) {
756: return buildRightAlignedBar(new JButton[] { ok, cancel, apply,
757: help });
758: }
759:
760: // Add..., Remove *******************************************************
761:
762: /**
763: * Builds and returns a left aligned button bar with Add and Remove.
764: *
765: * @param add
766: * the Add button
767: * @param remove
768: * the Remove button
769: * @return a panel that contains the button(s)
770: */
771: public static JPanel buildAddRemoveLeftBar(JButton add,
772: JButton remove) {
773: return buildLeftAlignedBar(add, remove);
774: }
775:
776: /**
777: * Builds and returns a filled button bar with Add and Remove.
778: *
779: * @param add
780: * the Add button
781: * @param remove
782: * the Remove button
783: * @return a panel that contains the button(s)
784: */
785: public static JPanel buildAddRemoveBar(JButton add, JButton remove) {
786: return buildGrowingBar(add, remove);
787: }
788:
789: /**
790: * Builds and returns a right aligned button bar with Add and Remove.
791: *
792: * @param add
793: * the Add button
794: * @param remove
795: * the Remove button
796: * @return a panel that contains the button(s)
797: */
798: public static JPanel buildAddRemoveRightBar(JButton add,
799: JButton remove) {
800: return buildRightAlignedBar(add, remove);
801: }
802:
803: // Add..., Remove, Properties... ****************************************
804:
805: /**
806: * Builds and returns a left aligned button bar with Add, Remove, and
807: * Properties.
808: *
809: * @param add
810: * the Add button
811: * @param remove
812: * the Remove button
813: * @param properties
814: * the Properties button
815: * @return a panel that contains the button(s)
816: */
817: public static JPanel buildAddRemovePropertiesLeftBar(JButton add,
818: JButton remove, JButton properties) {
819: return buildLeftAlignedBar(add, remove, properties);
820: }
821:
822: /**
823: * Builds and returns a filled button bar with Add, Remove, and Properties.
824: *
825: * @param add
826: * the Add button
827: * @param remove
828: * the Remove button
829: * @param properties
830: * the Properties button
831: * @return a panel that contains the button(s)
832: */
833: public static JPanel buildAddRemovePropertiesBar(JButton add,
834: JButton remove, JButton properties) {
835: ButtonBarBuilder builder = new ButtonBarBuilder();
836: builder.addGriddedGrowing(add);
837: builder.addRelatedGap();
838: builder.addGriddedGrowing(remove);
839: builder.addRelatedGap();
840: builder.addGriddedGrowing(properties);
841: return builder.getPanel();
842: }
843:
844: /**
845: * Builds and returns a right aligned button bar with Add, Remove, and
846: * Properties.
847: *
848: * @param add
849: * the Add button
850: * @param remove
851: * the Remove button
852: * @param properties
853: * the Properties button
854: * @return a panel that contains the button(s)
855: */
856: public static JPanel buildAddRemovePropertiesRightBar(JButton add,
857: JButton remove, JButton properties) {
858: return buildRightAlignedBar(add, remove, properties);
859: }
860:
861: // Wizard Bars **********************************************************
862:
863: /**
864: * Builds and returns a wizard button bar with Back, Next, Finish, Cancel
865: *
866: * @param back
867: * the Back button
868: * @param next
869: * the Next button
870: * @param finish
871: * the Finish button
872: * @param cancel
873: * the Cancel button
874: * @return a wizard button bar for back, next, finish, cancel
875: */
876: public static JPanel buildWizardBar(JButton back, JButton next,
877: JButton finish, JButton cancel) {
878: return buildWizardBar(back, next, new JButton[] { finish,
879: cancel });
880: }
881:
882: /**
883: * Builds and returns a wizard button bar with Help and Back, Next, Finish,
884: * Cancel
885: *
886: * @param help
887: * the Help button
888: * @param back
889: * the Back button
890: * @param next
891: * the Next button
892: * @param finish
893: * the Finish button
894: * @param cancel
895: * the Cancel button
896: * @return a wizard button bar for help, back, next, finish, cancel
897: */
898: public static JPanel buildWizardBar(JButton help, JButton back,
899: JButton next, JButton finish, JButton cancel) {
900: return buildWizardBar(new JButton[] { help }, back, next,
901: new JButton[] { finish, cancel });
902: }
903:
904: /**
905: * Builds and returns a wizard button bar that consists of the back and next
906: * buttons, and some right aligned buttons.
907: *
908: * @param back
909: * the mandatory back button
910: * @param next
911: * the mandatory next button
912: * @param rightAlignedButtons
913: * an optional array of buttons that will be located in the bar's
914: * right hand side
915: * @return a wizard button bar with back, next and a bunch of buttons
916: */
917: public static JPanel buildWizardBar(JButton back, JButton next,
918: JButton[] rightAlignedButtons) {
919: return buildWizardBar(null, back, next, rightAlignedButtons);
920: }
921:
922: /**
923: * Builds and returns a wizard button bar. It consists of some left aligned
924: * buttons, the back and next buttons, and some right aligned buttons.
925: *
926: * @param leftAlignedButtons
927: * an optional array of buttons that will be positioned in the
928: * bar's left hand side
929: * @param back
930: * the mandatory back button
931: * @param next
932: * the mandatory next button
933: * @param rightAlignedButtons
934: * an optional array of buttons that will be located in the bar's
935: * right hand side
936: * @return a wizard button bar with back, next and a bunch of buttons
937: */
938: public static JPanel buildWizardBar(JButton[] leftAlignedButtons,
939: JButton back, JButton next, JButton[] rightAlignedButtons) {
940: return buildWizardBar(leftAlignedButtons, back, next, null,
941: rightAlignedButtons);
942: }
943:
944: /**
945: * Builds and returns a wizard button bar. It consists of some left aligned
946: * buttons, the back, next group, and some right aligned buttons. To allow
947: * the finish button to overlay the next button, you can optionally provide
948: * the <code>overlayedFinish</code> parameter.
949: *
950: * @param leftAlignedButtons
951: * an optional array of buttons that will be positioned in the
952: * bar's left hand side
953: * @param back
954: * the mandatory back button
955: * @param next
956: * the mandatory next button
957: * @param overlayedFinish
958: * the optional overlayed finish button
959: * @param rightAlignedButtons
960: * an optional array of buttons that will be located in the bar's
961: * right hand side
962: * @return a wizard button bar with back, next and a bunch of buttons
963: */
964: public static JPanel buildWizardBar(JButton[] leftAlignedButtons,
965: JButton back, JButton next, JButton overlayedFinish,
966: JButton[] rightAlignedButtons) {
967:
968: ButtonBarBuilder builder = new ButtonBarBuilder();
969: if (leftAlignedButtons != null) {
970: builder.addGriddedButtons(leftAlignedButtons);
971: builder.addRelatedGap();
972: }
973: builder.addGlue();
974: builder.addGridded(back);
975: builder.addGridded(next);
976:
977: // Optionally overlay the finish and next button.
978: if (overlayedFinish != null) {
979: builder.nextColumn(-1);
980: builder.add(overlayedFinish);
981: builder.nextColumn();
982: }
983:
984: if (rightAlignedButtons != null) {
985: builder.addRelatedGap();
986: builder.addGriddedButtons(rightAlignedButtons);
987: }
988: return builder.getPanel();
989: }
990:
991: }
|