ComponentFactory.java
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13: package xeij;
14:
15: import java.awt.*;
16: import java.awt.event.*;
17: import java.awt.image.*;
18: import java.lang.*;
19: import java.net.*;
20: import java.util.*;
21: import java.util.regex.*;
22: import javax.swing.*;
23: import javax.swing.border.*;
24: import javax.swing.event.*;
25: import javax.swing.plaf.metal.*;
26: import javax.swing.text.*;
27:
28: public class ComponentFactory {
29:
30:
31:
32:
33:
34:
35:
36: public static <T extends AbstractButton> T addListener (T button, ActionListener listener) {
37: if (listener != null) {
38: button.addActionListener (listener);
39: }
40: return button;
41: }
42:
43:
44:
45: public static <T extends JComboBox<String>> T addListener (T comboBox, ActionListener listener) {
46: if (listener != null) {
47: comboBox.addActionListener (listener);
48: }
49: return comboBox;
50: }
51:
52:
53:
54: public static <T extends JSlider> T addListener (T slider, ChangeListener listener) {
55: if (listener != null) {
56: slider.addChangeListener (listener);
57: }
58: return slider;
59: }
60:
61:
62:
63: public static <T extends JSpinner> T addListener (T spinner, ChangeListener listener) {
64: if (listener != null) {
65: spinner.addChangeListener (listener);
66: }
67: return spinner;
68: }
69:
70:
71:
72: public static <T extends ScrollList> T addListener (T scrollList, ListSelectionListener listener) {
73: if (listener != null) {
74: scrollList.addListSelectionListener (listener);
75: }
76: return scrollList;
77: }
78:
79:
80:
81: public static <T extends Component> T addListener (T component, FocusListener listener) {
82: if (listener != null) {
83: component.addFocusListener (listener);
84: }
85: return component;
86: }
87:
88:
89:
90: public static <T extends Component> T addListener (T component, KeyListener listener) {
91: if (listener != null) {
92: component.addKeyListener (listener);
93: }
94: return component;
95: }
96:
97:
98:
99: public static <T extends Component> T addListener (T component, ComponentListener listener) {
100: if (listener != null) {
101: component.addComponentListener (listener);
102: }
103: return component;
104: }
105:
106:
107:
108: public static <T extends Component> T addListener (T component, MouseAdapter listener) {
109: if (listener != null) {
110: component.addMouseListener (listener);
111: component.addMouseMotionListener (listener);
112: component.addMouseWheelListener (listener);
113: }
114: return component;
115: }
116:
117:
118:
119: public static <T extends Component> T addListener (T component, MouseListener listener) {
120: if (listener != null) {
121: component.addMouseListener (listener);
122: }
123: return component;
124: }
125:
126:
127:
128: public static <T extends Component> T addListener (T component, MouseMotionListener listener) {
129: if (listener != null) {
130: component.addMouseMotionListener (listener);
131: }
132: return component;
133: }
134:
135:
136:
137: public static <T extends Component> T addListener (T component, MouseWheelListener listener) {
138: if (listener != null) {
139: component.addMouseWheelListener (listener);
140: }
141: return component;
142: }
143:
144:
145:
146: public static <T extends Window> T addListener (T window, WindowAdapter listener) {
147: if (listener != null) {
148: window.addWindowListener (listener);
149: window.addWindowStateListener (listener);
150: window.addWindowFocusListener (listener);
151: }
152: return window;
153: }
154:
155:
156:
157: public static <T extends Window> T addListener (T window, WindowListener listener) {
158: if (listener != null) {
159: window.addWindowListener (listener);
160: }
161: return window;
162: }
163:
164:
165:
166: public static <T extends Window> T addListener (T window, WindowStateListener listener) {
167: if (listener != null) {
168: window.addWindowStateListener (listener);
169: }
170: return window;
171: }
172:
173:
174:
175: public static <T extends Window> T addListener (T window, WindowFocusListener listener) {
176: if (listener != null) {
177: window.addWindowFocusListener (listener);
178: }
179: return window;
180: }
181:
182:
183:
184: public static <T extends JTextComponent> T addListener (T textComponent, CaretListener listener) {
185: if (listener != null) {
186: textComponent.addCaretListener (listener);
187: }
188: return textComponent;
189: }
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201: public static <T extends JComponent> T setToolTipText (T component, String toolTipText) {
202: component.setToolTipText (toolTipText);
203: return component;
204: }
205:
206:
207: public static <T extends Component> T setName (T component, String name) {
208: component.setName (name);
209: return component;
210: }
211:
212:
213: public static <T extends Component> T setVisible (T component, boolean visible) {
214: component.setVisible (visible);
215: return component;
216: }
217:
218:
219: public static <T extends Component> T setColor (T component, Color foreground, Color background) {
220: component.setBackground (background);
221: component.setForeground (foreground);
222: return component;
223: }
224:
225:
226: public static <T extends Component> T setFont (T component, Font font) {
227: component.setFont (font);
228: return component;
229: }
230:
231:
232:
233:
234: public static <T extends Component> T bold (T component) {
235: return setFont (component, component.getFont ().deriveFont (Font.BOLD));
236: }
237: public static <T extends Component> T italic (T component) {
238: return setFont (component, component.getFont ().deriveFont (Font.ITALIC));
239: }
240: public static <T extends Component> T boldItalic (T component) {
241: return setFont (component, component.getFont ().deriveFont (Font.BOLD | Font.ITALIC));
242: }
243:
244:
245: public static <T extends Component> T pointSize (T component, int size) {
246: return setFont (component, component.getFont ().deriveFont ((float) size));
247: }
248:
249:
250:
251: public static <T extends Component> T setEnabled (T component, boolean enabled) {
252: component.setEnabled (enabled);
253: return component;
254: }
255:
256:
257:
258: public static <T extends Component> T setMaximumSize (T component, int width, int height) {
259: component.setMaximumSize (new Dimension (width, height));
260: return component;
261: }
262:
263:
264:
265: public static <T extends Component> T setMinimumSize (T component, int width, int height) {
266: component.setMinimumSize (new Dimension (width, height));
267: return component;
268: }
269:
270:
271:
272: public static <T extends Component> T setPreferredSize (T component, int width, int height) {
273: component.setPreferredSize (new Dimension (width, height));
274: return component;
275: }
276:
277:
278:
279: public static <T extends Component> T setFixedSize (T component, int width, int height) {
280: Dimension d = new Dimension (width, height);
281: component.setMinimumSize (d);
282: component.setMaximumSize (d);
283: component.setPreferredSize (d);
284: return component;
285: }
286:
287:
288:
289: public static <T extends JComponent> T setEmptyBorder (T component, int top, int left, int bottom, int right) {
290: component.setBorder (new EmptyBorder (top, left, bottom, right));
291: return component;
292: }
293:
294:
295:
296: public static <T extends JComponent> T setLineBorder (T component) {
297: component.setBorder (new LineBorder (MetalLookAndFeel.getSeparatorForeground (), 1));
298: return component;
299: }
300:
301:
302:
303: public static <T extends JComponent> T setTitledLineBorder (T component, String title) {
304: component.setBorder (new TitledBorder (new LineBorder (MetalLookAndFeel.getSeparatorForeground (), 1), title));
305: return component;
306: }
307:
308:
309:
310: public static <T extends JComponent> T setEtchedBorder (T component) {
311: component.setBorder (new EtchedBorder (new Color (LnF.lnfRGB[10]), new Color (LnF.lnfRGB[14])));
312: return component;
313: }
314:
315:
316:
317: public static <T extends JComponent> T setTitledEtchedBorder (T component, String title) {
318: component.setBorder (new TitledBorder (new EtchedBorder (), title));
319: return component;
320: }
321:
322:
323:
324: public static <T extends JComponent> T addComponents (T parent, Component... components) {
325: for (Component component : components) {
326: if (component != null) {
327: parent.add (component);
328: }
329: }
330: return parent;
331: }
332:
333:
334:
335: public static <T extends JComponent> T removeComponents (T parent, Component... components) {
336: for (Component component : components) {
337: if (component != null) {
338: parent.remove (component);
339: }
340: }
341: return parent;
342: }
343:
344:
345:
346:
347: public static <T extends AbstractButton> T setText (T button, String text) {
348: button.setText (text);
349: return button;
350: }
351:
352:
353:
354:
355:
356:
357:
358: public static <T extends AbstractButton> T setHorizontalAlignment (T button, int alignment) {
359: button.setHorizontalAlignment (alignment);
360: return button;
361: }
362:
363:
364:
365:
366:
367: public static <T extends AbstractButton> T setVerticalAlignment (T button, int alignment) {
368: button.setVerticalAlignment (alignment);
369: return button;
370: }
371:
372:
373:
374:
375:
376:
377:
378:
379:
380: public static <T extends JTextField> T setHorizontalAlignment (T textField, int alignment) {
381: textField.setHorizontalAlignment (alignment);
382: return textField;
383: }
384:
385:
386:
387:
388:
389: public static <T extends JTextComponent> T setEditable (T component, boolean enabled) {
390: component.setEditable (enabled);
391: return component;
392: }
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418: public static JFrame createFrame (String title, JMenuBar mnbMenuBar, JComponent component) {
419: JFrame frame = new JFrame (title);
420: frame.setUndecorated (true);
421: frame.getRootPane().setWindowDecorationStyle (JRootPane.FRAME);
422:
423: frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
424: if (mnbMenuBar != null) {
425: frame.setJMenuBar (mnbMenuBar);
426: }
427:
428: component.setOpaque (true);
429: frame.setContentPane (component);
430: frame.pack ();
431: frame.setVisible (true);
432: return frame;
433: }
434:
435: public static JFrame createSubFrame (String title, JMenuBar mnbMenuBar, JComponent component) {
436: JFrame frame = new JFrame (title);
437: frame.setUndecorated (true);
438: frame.getRootPane().setWindowDecorationStyle (JRootPane.FRAME);
439: frame.setLocationByPlatform (true);
440: frame.setDefaultCloseOperation (JFrame.HIDE_ON_CLOSE);
441: if (mnbMenuBar != null) {
442: frame.setJMenuBar (mnbMenuBar);
443: }
444:
445: component.setOpaque (true);
446: frame.setContentPane (component);
447: frame.pack ();
448: return frame;
449: }
450:
451: public static JFrame createRestorableFrame (String key, String title, JMenuBar mnbMenuBar, JComponent component) {
452: JFrame frame = new RestorableFrame (key, title);
453: frame.setUndecorated (true);
454: frame.getRootPane().setWindowDecorationStyle (JRootPane.FRAME);
455:
456: frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
457: if (mnbMenuBar != null) {
458: frame.setJMenuBar (mnbMenuBar);
459: }
460:
461: component.setOpaque (true);
462: frame.setContentPane (component);
463: frame.pack ();
464: frame.setVisible (true);
465: return frame;
466: }
467:
468: public static JFrame createRestorableSubFrame (String key, String title, JMenuBar mnbMenuBar, JComponent component) {
469: return createRestorableSubFrame (key, title, mnbMenuBar, component, true);
470: }
471: public static JFrame createRestorableSubFrame (String key, String title, JMenuBar mnbMenuBar, JComponent component, boolean resizable) {
472: JFrame frame = new RestorableFrame (key, title, resizable);
473: frame.setUndecorated (true);
474: frame.getRootPane().setWindowDecorationStyle (JRootPane.FRAME);
475:
476: frame.setDefaultCloseOperation (JFrame.HIDE_ON_CLOSE);
477: if (mnbMenuBar != null) {
478: frame.setJMenuBar (mnbMenuBar);
479: }
480:
481: component.setOpaque (true);
482: frame.setContentPane (component);
483: frame.setResizable (resizable);
484: frame.pack ();
485: return frame;
486: }
487:
488:
489:
490:
491:
492:
493:
494:
495: public static JDialog createModalDialog (Frame owner, String title, JComponent component) {
496: return createDialog (owner, title, true, component);
497: }
498: public static JDialog createModelessDialog (Frame owner, String title, JComponent component) {
499: return createDialog (owner, title, false, component);
500: }
501: public static JDialog createDialog (Frame owner, String title, boolean modal, JComponent component) {
502: JDialog dialog = new JDialog (owner, title, modal);
503: dialog.setUndecorated (true);
504: dialog.getRootPane ().setWindowDecorationStyle (JRootPane.FRAME);
505: dialog.setAlwaysOnTop (modal);
506: dialog.setLocationByPlatform (true);
507: dialog.setDefaultCloseOperation (WindowConstants.HIDE_ON_CLOSE);
508: dialog.getContentPane ().add (component, BorderLayout.CENTER);
509: dialog.pack ();
510: dialog.setVisible (false);
511: return dialog;
512: }
513:
514:
515:
516:
517:
518:
519:
520: public static Box createHorizontalBox (Component... components) {
521: return addComponents (Box.createHorizontalBox (), components);
522: }
523:
524:
525:
526: public static Box createVerticalBox (Component... components) {
527: return addComponents (Box.createVerticalBox (), components);
528: }
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539: public static Box createGlueBox (JComponent component) {
540: return createGlueBox (SwingConstants.CENTER, component);
541: }
542: public static Box createGlueBox (int orientation, JComponent component) {
543: Box box = (orientation == SwingConstants.NORTH_WEST ||
544: orientation == SwingConstants.WEST ||
545: orientation == SwingConstants.SOUTH_WEST ?
546: createHorizontalBox (component, Box.createHorizontalGlue ()) :
547: orientation == SwingConstants.NORTH_EAST ||
548: orientation == SwingConstants.EAST ||
549: orientation == SwingConstants.SOUTH_EAST ?
550: createHorizontalBox (Box.createHorizontalGlue (), component) :
551: createHorizontalBox (Box.createHorizontalGlue (), component, Box.createHorizontalGlue ()));
552: return (orientation == SwingConstants.NORTH_WEST ||
553: orientation == SwingConstants.NORTH ||
554: orientation == SwingConstants.NORTH_EAST ?
555: createVerticalBox (box, Box.createVerticalGlue ()) :
556: orientation == SwingConstants.SOUTH_WEST ||
557: orientation == SwingConstants.SOUTH ||
558: orientation == SwingConstants.SOUTH_EAST ?
559: createVerticalBox (Box.createVerticalGlue (), box) :
560: createVerticalBox (Box.createVerticalGlue (), box, Box.createVerticalGlue ()));
561: }
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572: public static JPanel createFlowPanel (Component... components) {
573: return createFlowPanel (FlowLayout.LEFT, 0, 0, components);
574: }
575: public static JPanel createFlowPanel (int align, Component... components) {
576: return createFlowPanel (align, 0, 0, components);
577: }
578: public static JPanel createFlowPanel (int hgap, int vgap, Component... components) {
579: return createFlowPanel (FlowLayout.LEFT, hgap, vgap, components);
580: }
581: public static JPanel createFlowPanel (int align, int hgap, int vgap, Component... components) {
582: JPanel panel = new JPanel (new FlowLayout (align, hgap, vgap));
583: panel.setOpaque (true);
584: return addComponents (panel, components);
585: }
586:
587:
588:
589:
590:
591:
592: public static JPanel createBorderPanel (JComponent... components) {
593: return createBorderPanel (0, 0, components);
594: }
595: public static JPanel createBorderPanel (int hgap, int vgap, JComponent... components) {
596: JPanel panel = new JPanel (new BorderLayout (hgap, vgap));
597: panel.setOpaque (true);
598: if (components.length >= 1) {
599: if (components[0] != null) {
600: panel.add (components[0], BorderLayout.CENTER);
601: }
602: if (components.length >= 2) {
603: if (components[1] != null) {
604: panel.add (components[1], BorderLayout.NORTH);
605: }
606: if (components.length >= 3) {
607: if (components[2] != null) {
608: panel.add (components[2], BorderLayout.WEST);
609: }
610: if (components.length >= 4) {
611: if (components[3] != null) {
612: panel.add (components[3], BorderLayout.SOUTH);
613: }
614: if (components.length >= 5 && components[4] != null) {
615: panel.add (components[4], BorderLayout.EAST);
616: }
617: }
618: }
619: }
620: }
621: return panel;
622: }
623:
624:
625:
626:
627:
628:
629:
630:
631:
632:
633:
634:
635:
636:
637:
638:
639:
640:
641:
642:
643:
644:
645:
646:
647:
648:
649:
650:
651:
652:
653: public static JPanel createGridPanel (int colCount, int rowCount, String gridStyles, String colStyless, String rowStyless, String cellStyless, Object... objectArray) {
654: String[] colStylesArray = (colStyless != null ? colStyless : "").split (";");
655: String[] rowStylesArray = (rowStyless != null ? rowStyless : "").split (";");
656: String[] cellStylesArray = (cellStyless != null ? cellStyless : "").split (";");
657: int cellCount = colCount * rowCount;
658:
659: boolean[] cellFilledArray = new boolean[cellCount];
660: GridBagLayout gridbag = new GridBagLayout ();
661: JPanel panel = new JPanel (gridbag);
662: GridBagConstraints c = new GridBagConstraints ();
663: int objectIndex = 0;
664: boolean objectClosed = objectArray.length < cellCount;
665: for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
666: for (int colIndex = 0; colIndex < colCount; colIndex++) {
667: int cellIndex = colIndex + colCount * rowIndex;
668: if (cellFilledArray[cellIndex]) {
669: continue;
670: }
671: int colSpan = 1;
672: int rowSpan = 1;
673: int width = 1;
674: int height = 1;
675: int fill = 0;
676: int anchor = 0;
677: int paddingTop = 0;
678: int paddingRight = 0;
679: int paddingBottom = 0;
680: int paddingLeft = 0;
681: int fontStyle = 0;
682: for (String style : ((gridStyles != null ? gridStyles : "") + "," +
683: (colIndex < colStylesArray.length ? colStylesArray[colIndex] : "") + "," +
684: (rowIndex < rowStylesArray.length ? rowStylesArray[rowIndex] : "") + "," +
685: ((objectClosed ? objectIndex : cellIndex) < cellStylesArray.length ? cellStylesArray[objectClosed ? objectIndex : cellIndex] : "")).split (",")) {
686: String[] keyValue = style.split ("=");
687: String key = keyValue.length < 1 ? "" : keyValue[0].trim ();
688: int value = keyValue.length < 2 ? 1 : Integer.parseInt (keyValue[1]);
689: switch (key) {
690: case "colSpan":
691: colSpan = value;
692: break;
693: case "rowSpan":
694: rowSpan = value;
695: break;
696: case "width":
697: width = value;
698: break;
699: case "height":
700: height = value;
701: break;
702: case "widen":
703: fill |= 1;
704: break;
705: case "lengthen":
706: fill |= 2;
707: break;
708: case "center":
709: anchor &= ~0b0011;
710: break;
711: case "left":
712: anchor = anchor & ~0b0011 | 0b0001;
713: break;
714: case "right":
715: anchor = anchor & ~0b0011 | 0b0010;
716: break;
717: case "middle":
718: anchor &= ~0b1100;
719: break;
720: case "top":
721: anchor = anchor & ~0b1100 | 0b0100;
722: break;
723: case "bottom":
724: anchor = anchor & ~0b1100 | 0b1000;
725: break;
726: case "paddingTop":
727: paddingTop = value;
728: break;
729: case "paddingRight":
730: paddingRight = value;
731: break;
732: case "paddingBottom":
733: paddingBottom = value;
734: break;
735: case "paddingLeft":
736: paddingLeft = value;
737: break;
738: case "bold":
739: fontStyle |= 1;
740: break;
741: case "italic":
742: fontStyle |= 2;
743: break;
744: }
745: }
746: c.gridx = colIndex;
747: c.gridy = rowIndex;
748: c.gridwidth = colSpan;
749: c.gridheight = rowSpan;
750: c.weightx = 0.0;
751: c.weighty = 0.0;
752: c.fill = (fill == 1 ? GridBagConstraints.HORIZONTAL :
753: fill == 2 ? GridBagConstraints.VERTICAL :
754: fill == 3 ? GridBagConstraints.BOTH :
755: GridBagConstraints.NONE);
756: c.anchor = (anchor == 0b0001 ? GridBagConstraints.WEST :
757: anchor == 0b0010 ? GridBagConstraints.EAST :
758: anchor == 0b0100 ? GridBagConstraints.NORTH :
759: anchor == 0b1000 ? GridBagConstraints.SOUTH :
760: anchor == 0b0101 ? GridBagConstraints.NORTHWEST :
761: anchor == 0b0110 ? GridBagConstraints.NORTHEAST :
762: anchor == 0b1001 ? GridBagConstraints.SOUTHWEST :
763: anchor == 0b1010 ? GridBagConstraints.SOUTHEAST :
764: GridBagConstraints.CENTER);
765: c.insets = new Insets (paddingTop, paddingLeft, paddingBottom, paddingRight);
766: Object object = (objectClosed ? objectIndex : cellIndex) < objectArray.length ? objectArray[objectClosed ? objectIndex : cellIndex] : null;
767: Component component;
768: if (object == null) {
769: component = new JPanel ();
770: } else if (object instanceof String) {
771: String string = (String) object;
772: component = string.startsWith ("http://") || string.startsWith ("https://") ? createAnchor (string, string) : createLabel ((String) object);
773: } else if (object instanceof Component) {
774: component = (Component) object;
775: } else {
776: component = new JPanel ();
777: }
778: if (component instanceof JLabel) {
779: JLabel label = (JLabel) component;
780: if (fontStyle == 1) {
781: bold (label);
782: } else if (fontStyle == 2) {
783: italic (label);
784: } else if (fontStyle == 3) {
785: boldItalic (label);
786: }
787: }
788:
789: component.setMinimumSize (new Dimension (width, height));
790: if (width > 1 || height > 1) {
791: component.setPreferredSize (new Dimension (width, height));
792: }
793: gridbag.setConstraints (component, c);
794: panel.add (component);
795:
796: for (int y = 0; y < rowSpan; y++) {
797: for (int x = 0; x < colSpan; x++) {
798: cellFilledArray[(colIndex + x) + colCount * (rowIndex + y)] = true;
799: }
800: }
801:
802: objectIndex++;
803: }
804: }
805: return panel;
806: }
807:
808:
809:
810:
811:
812:
813:
814:
815:
816:
817:
818:
819:
820: public static JScrollPane createScrollPane (Component view) {
821: return createScrollPane (view,
822: ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
823: ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
824: }
825: public static JScrollPane createScrollPane (Component view, int vsbPolicy, int hsbPolicy) {
826: return new JScrollPane (view, vsbPolicy, hsbPolicy);
827: }
828:
829:
830:
831:
832:
833:
834:
835:
836: public static JSplitPane createHorizontalSplitPane (Component... components) {
837: return createSplitPane (JSplitPane.HORIZONTAL_SPLIT, components);
838: }
839: public static JSplitPane createVerticalSplitPane (Component... components) {
840: return createSplitPane (JSplitPane.VERTICAL_SPLIT, components);
841: }
842: public static JSplitPane createSplitPane (int orientation, Component... components) {
843: JSplitPane splitPane = new JSplitPane (orientation, true, components[0], components[1]);
844: for (int i = 2; i < components.length; i++) {
845: splitPane = new JSplitPane (orientation, true, splitPane, components[i]);
846: }
847: return splitPane;
848: }
849:
850:
851:
852:
853:
854:
855:
856:
857: public static JSeparator createHorizontalSeparator () {
858: return new JSeparator (SwingConstants.HORIZONTAL);
859: }
860: public static JSeparator createVerticalSeparator () {
861: return new JSeparator (SwingConstants.VERTICAL);
862: }
863:
864:
865:
866:
867:
868:
869:
870:
871: public static JLabel createLabel (String enText) {
872: return createLabel (enText, SwingConstants.CENTER);
873: }
874: public static JLabel createLabel (String enText, int alignment) {
875: JLabel label = new JLabel (enText);
876: label.setForeground (MetalLookAndFeel.getBlack ());
877: if (alignment == SwingConstants.NORTH_WEST ||
878: alignment == SwingConstants.NORTH ||
879: alignment == SwingConstants.NORTH_EAST ||
880: alignment == SwingConstants.TOP) {
881: label.setVerticalAlignment (SwingConstants.TOP);
882: } else if (alignment == SwingConstants.SOUTH_WEST ||
883: alignment == SwingConstants.SOUTH ||
884: alignment == SwingConstants.SOUTH_EAST ||
885: alignment == SwingConstants.BOTTOM) {
886: label.setVerticalAlignment (SwingConstants.BOTTOM);
887: } else if (alignment == SwingConstants.CENTER) {
888: label.setVerticalAlignment (SwingConstants.CENTER);
889: }
890: if (alignment == SwingConstants.NORTH_WEST ||
891: alignment == SwingConstants.WEST ||
892: alignment == SwingConstants.SOUTH_WEST ||
893: alignment == SwingConstants.LEFT) {
894: label.setHorizontalAlignment (SwingConstants.LEFT);
895: } else if (alignment == SwingConstants.NORTH_EAST ||
896: alignment == SwingConstants.EAST ||
897: alignment == SwingConstants.SOUTH_EAST ||
898: alignment == SwingConstants.RIGHT) {
899: label.setHorizontalAlignment (SwingConstants.RIGHT);
900: } else if (alignment == SwingConstants.CENTER) {
901: label.setHorizontalAlignment (SwingConstants.CENTER);
902: }
903: return label;
904: }
905:
906:
907:
908: public static JLabel createIconLabel (Image image) {
909: JLabel label = new JLabel (new ImageIcon (image));
910: label.setBorder (new EmptyBorder (1, 1, 1, 1));
911: return label;
912: }
913:
914:
915:
916:
917:
918:
919:
920:
921:
922:
923: public static boolean isObsoleteURI (String uri) {
924: return uri.startsWith ("http://www.nifty.ne.jp/forum/");
925: }
926: public static JLabel createAnchor (String enText, String uri) {
927: JLabel label = new UnderlinedLabel (enText);
928: label.setForeground (MetalLookAndFeel.getBlack ());
929: if (uri != null) {
930: if (isObsoleteURI (uri)) {
931: uri = "https://web.archive.org/web/" + "*" + "/" + uri;
932: }
933: label.setCursor (Cursor.getPredefinedCursor (Cursor.HAND_CURSOR));
934: label.setToolTipText (uri);
935: label.addMouseListener (new AnchorAdapter (uri));
936: }
937: return label;
938: }
939:
940:
941:
942:
943:
944:
945:
946: public static JTextField createTextField (String text, int columns) {
947: JTextField textField = new JTextField (text, columns);
948: textField.setForeground (new Color (LnF.lnfRGB[14]));
949: textField.setSelectionColor (new Color (LnF.lnfRGB[7]));
950:
951: return textField;
952: }
953:
954:
955:
956: public static JTextField createNumberField (String text, int columns) {
957: return setHorizontalAlignment (
958: setFixedSize (
959:
960:
961:
962:
963: new JTextField (text),
964: 10 + (LnF.lnfFontSize * 2 / 3) * columns, LnF.lnfFontSize + 4
965: ),
966: JTextField.RIGHT);
967: }
968:
969:
970:
971:
972:
973:
974:
975:
976: public static ScrollTextArea createScrollTextArea (String text, int width, int height) {
977: return createScrollTextArea (text, width, height, false);
978: }
979: public static ScrollTextArea createScrollTextArea (String text, int width, int height, boolean editable) {
980: ScrollTextArea scrollTextArea = setPreferredSize (
981: setFont (new ScrollTextArea (), LnF.lnfMonospacedFont),
982: width, height);
983: setEmptyBorder (scrollTextArea, 0, 0, 0, 0);
984: scrollTextArea.setMargin (new Insets (2, 4, 2, 4));
985: JTextArea textArea = scrollTextArea.getTextArea ();
986: textArea.setEditable (editable);
987: scrollTextArea.setText (text);
988: scrollTextArea.setCaretPosition (0);
989: return scrollTextArea;
990: }
991:
992:
993:
994:
995:
996:
997:
998:
999:
1000:
1001:
1002: public static JScrollPane createScrollTextPane (String text, int width, int height) {
1003: JTextPane textPane = new JTextPane ();
1004: StyledDocument document = textPane.getStyledDocument ();
1005: Style defaultStyle = document.addStyle ("default", StyleContext.getDefaultStyleContext ().getStyle (StyleContext.DEFAULT_STYLE));
1006: int anchorNumber = 0;
1007:
1008:
1009: Matcher matcher = Pattern.compile ("\\b" +
1010: "(?:" +
1011: "(?<!\\()https?://[-.0-9A-Za-z]*(?:/(?:[!$&-;=?-Z_a-z~]|%[0-9A-Fa-f]{2})*)?" +
1012: "|" +
1013: "(?<=\\()https?://[-.0-9A-Za-z]*(?:/(?:[!$&-(*-;=?-Z_a-z~]|%[0-9A-Fa-f]{2})*)?" +
1014: ")").matcher (text);
1015: try {
1016: int start = 0;
1017: while (matcher.find ()) {
1018: int end = matcher.start ();
1019: if (start < end) {
1020: document.insertString (document.getLength (), text.substring (start, end), defaultStyle);
1021: }
1022: String anchorHref = matcher.group ();
1023: Style anchorStyle = document.addStyle ("anchor" + anchorNumber++, defaultStyle);
1024: JLabel anchorLabel = createAnchor (anchorHref, anchorHref);
1025: Dimension anchorSize = anchorLabel.getPreferredSize ();
1026: anchorLabel.setAlignmentY ((float) anchorLabel.getBaseline (anchorSize.width, anchorSize.height) / (float) anchorSize.height);
1027: StyleConstants.setComponent (anchorStyle, anchorLabel);
1028: document.insertString (document.getLength (), anchorHref, anchorStyle);
1029: start = matcher.end ();
1030: }
1031: document.insertString (document.getLength (), text.substring (start), defaultStyle);
1032: } catch (BadLocationException ble) {
1033: }
1034: textPane.setMargin (new Insets (2, 4, 2, 4));
1035: textPane.setEditable (false);
1036: textPane.setCaretPosition (0);
1037: JScrollPane scrollPane = new JScrollPane (textPane);
1038: scrollPane.setPreferredSize (new Dimension (width, height));
1039: return scrollPane;
1040: }
1041:
1042:
1043:
1044:
1045:
1046:
1047:
1048:
1049: public static JButton createButton (String enText, ActionListener listener) {
1050: return createButton (enText, KeyEvent.VK_UNDEFINED, listener);
1051: }
1052: public static JButton createButton (String enText, int mnemonic, ActionListener listener) {
1053: JButton button = new JButton ();
1054: return setButtonCommons (button, enText, mnemonic, listener);
1055: }
1056:
1057:
1058:
1059:
1060:
1061:
1062: public static JButton createButton (Image image, String enText, ActionListener listener) {
1063: return createButton (image, null, enText, KeyEvent.VK_UNDEFINED, listener);
1064: }
1065: public static JButton createButton (Image image, String enText, int mnemonic, ActionListener listener) {
1066: return createButton (image, null, enText, mnemonic, listener);
1067: }
1068: public static JButton createButton (Image image, Image disabledImage, String enText, ActionListener listener) {
1069: return createButton (image, disabledImage, enText, KeyEvent.VK_UNDEFINED, listener);
1070: }
1071: public static JButton createButton (Image image, Image disabledImage, String enText, int mnemonic, ActionListener listener) {
1072: JButton button = new JButton (new ImageIcon (image));
1073: if (disabledImage != null) {
1074: button.setDisabledIcon (new ImageIcon (disabledImage));
1075: }
1076: button.setBorder (new EmptyBorder (1, 1, 1, 1));
1077: button.setIconTextGap (3);
1078: return setButtonCommons (button, enText, mnemonic, listener);
1079: }
1080:
1081:
1082:
1083:
1084:
1085:
1086:
1087: public static JButton createIconButton (ImageIcon icon, String enToolTipText, ActionListener listener) {
1088: return createIconButton (icon, null, enToolTipText, listener);
1089: }
1090: public static JButton createIconButton (ImageIcon icon, ImageIcon disabledIcon, String enToolTipText, ActionListener listener) {
1091: JButton button = new JButton (icon);
1092: if (disabledIcon != null) {
1093: button.setDisabledIcon (disabledIcon);
1094: }
1095:
1096: button.setBorder (new EmptyBorder (1, 1, 1, 1));
1097:
1098:
1099: if (enToolTipText != null) {
1100: button.setToolTipText (enToolTipText);
1101: button.setActionCommand (enToolTipText);
1102: }
1103: return addListener (button, listener);
1104: }
1105: public static JButton createImageButton (Image image, String enToolTipText, ActionListener listener) {
1106: return createImageButton (image, null, enToolTipText, listener);
1107: }
1108: public static JButton createImageButton (Image image, Image disabledImage, String enToolTipText, ActionListener listener) {
1109: JButton button = new JButton (new ImageIcon (image));
1110: if (disabledImage != null) {
1111: button.setDisabledIcon (new ImageIcon (disabledImage));
1112: }
1113:
1114: button.setBorder (new EmptyBorder (1, 1, 1, 1));
1115:
1116:
1117: if (enToolTipText != null) {
1118: button.setToolTipText (enToolTipText);
1119: button.setActionCommand (enToolTipText);
1120: }
1121: return addListener (button, listener);
1122: }
1123:
1124:
1125:
1126:
1127: public static JCheckBox createCheckBox (boolean selected, String enText, ActionListener listener) {
1128: return createCheckBox (selected, enText, KeyEvent.VK_UNDEFINED, listener);
1129: }
1130: public static JCheckBox createCheckBox (boolean selected, String enText, int mnemonic, ActionListener listener) {
1131: JCheckBox button = new JCheckBox ();
1132: button.setBorder (new EmptyBorder (0, 0, 0, 0));
1133: button.setSelected (selected);
1134: return setButtonCommons (button, enText, mnemonic, listener);
1135: }
1136:
1137:
1138:
1139:
1140:
1141: public static JCheckBox createIconCheckBox (boolean selected, Image image, Image selectedImage, String enToolTipText, ActionListener listener) {
1142: return createIconCheckBox (selected, image, selectedImage, null, null, enToolTipText, listener);
1143: }
1144: public static JCheckBox createIconCheckBox (boolean selected, Image image, Image selectedImage, Image disabledImage, Image disabledSelectedImage, String enToolTipText, ActionListener listener) {
1145: JCheckBox button = new JCheckBox (new ImageIcon (image));
1146: button.setBorder (new EmptyBorder (1, 1, 1, 1));
1147: button.setSelected (selected);
1148: button.setSelectedIcon (new ImageIcon (selectedImage));
1149: if (disabledImage != null) {
1150: button.setDisabledIcon (new ImageIcon (disabledImage));
1151: }
1152: if (disabledSelectedImage != null) {
1153: button.setDisabledSelectedIcon (new ImageIcon (disabledSelectedImage));
1154: }
1155: if (enToolTipText != null) {
1156: button.setToolTipText (enToolTipText);
1157: button.setActionCommand (enToolTipText);
1158: }
1159: return addListener (button, listener);
1160: }
1161:
1162:
1163:
1164:
1165: public static JRadioButton createRadioButton (ButtonGroup group, boolean selected, String enText, ActionListener listener) {
1166: return createRadioButton (group, selected, enText, KeyEvent.VK_UNDEFINED, listener);
1167: }
1168: public static JRadioButton createRadioButton (ButtonGroup group, boolean selected, String enText, int mnemonic, ActionListener listener) {
1169: JRadioButton button = new JRadioButton ();
1170: button.setBorder (new EmptyBorder (0, 0, 0, 0));
1171: group.add (button);
1172: button.setSelected (selected);
1173: return setButtonCommons (button, enText, mnemonic, listener);
1174: }
1175:
1176:
1177:
1178:
1179: public static JRadioButton createIconRadioButton (ButtonGroup group, boolean selected, Image image, Image selectedImage, String enToolTipText, ActionListener listener) {
1180: JRadioButton button = new JRadioButton (new ImageIcon (image));
1181: button.setBorder (new EmptyBorder (1, 1, 1, 1));
1182: group.add (button);
1183: button.setSelected (selected);
1184: button.setSelectedIcon (new ImageIcon (selectedImage));
1185: if (enToolTipText != null) {
1186: button.setToolTipText (enToolTipText);
1187: button.setActionCommand (enToolTipText);
1188: }
1189: return addListener (button, listener);
1190: }
1191:
1192:
1193:
1194:
1195:
1196:
1197:
1198: public static JSlider createHorizontalSlider (int min, int max, int value, int major, int minor, String[] texts, ChangeListener listener) {
1199: JSlider slider = createHorizontalSlider (min, max, value, major, minor, listener);
1200: Hashtable<Integer,JComponent> table = new Hashtable<Integer,JComponent> ();
1201: for (int i = min; i <= max; i++) {
1202: if (i % major == 0 && texts[i - min] != null) {
1203: table.put (i, createLabel (texts[i - min]));
1204: }
1205: }
1206: slider.setLabelTable (table);
1207: return slider;
1208: }
1209:
1210:
1211:
1212: public static JSlider createHorizontalSlider (int min, int max, int value, int major, int minor, ChangeListener listener) {
1213: JSlider slider = new JSlider (SwingConstants.HORIZONTAL, min, max, value);
1214: if (major != 0) {
1215: slider.setLabelTable (slider.createStandardLabels (major));
1216: slider.setPaintLabels (true);
1217: slider.setMajorTickSpacing (major);
1218: if (minor != 0) {
1219: slider.setMinorTickSpacing (minor);
1220: }
1221: slider.setPaintTicks (true);
1222: slider.setSnapToTicks (true);
1223: }
1224: return addListener (slider, listener);
1225: }
1226:
1227:
1228:
1229:
1230:
1231:
1232:
1233:
1234:
1235:
1236: public static JMenuBar createMenuBar (Component... components) {
1237: JMenuBar bar = new JMenuBar ();
1238: for (Component component : components) {
1239: if (component != null) {
1240: bar.add (component);
1241: }
1242: }
1243: return bar;
1244: }
1245:
1246:
1247:
1248:
1249:
1250:
1251:
1252:
1253: public static JMenu createMenu (String enText, JComponent... items) {
1254: return createMenu (enText, KeyEvent.VK_UNDEFINED, items);
1255: }
1256: public static JMenu createMenu (String enText, int mnemonic, JComponent... items) {
1257: JMenu menu = new JMenu ();
1258: for (JComponent item : items) {
1259: if (item != null) {
1260: menu.add (item);
1261: }
1262: }
1263:
1264:
1265: return setButtonCommons (menu, enText, mnemonic, null);
1266: }
1267:
1268:
1269:
1270:
1271:
1272:
1273:
1274: public static JPopupMenu createPopupMenu (JComponent... items) {
1275: JPopupMenu popupMenu = new JPopupMenu ();
1276: for (JComponent item : items) {
1277: if (item != null) {
1278: popupMenu.add (item);
1279: }
1280: }
1281: return popupMenu;
1282: }
1283:
1284:
1285:
1286:
1287: public static JMenuItem createMenuItem (String enText, ActionListener listener) {
1288: return createMenuItem (enText, KeyEvent.VK_UNDEFINED, listener);
1289: }
1290: public static JMenuItem createMenuItem (String enText, int mnemonic, ActionListener listener) {
1291: return createMenuItem (enText, mnemonic, 0, listener);
1292: }
1293: public static JMenuItem createMenuItem (String enText, int mnemonic, int modifiers, ActionListener listener) {
1294: JMenuItem item = new JMenuItem ();
1295: if (modifiers != 0) {
1296: item.setAccelerator (KeyStroke.getKeyStroke (mnemonic, modifiers));
1297: mnemonic = KeyEvent.VK_UNDEFINED;
1298: }
1299: return setButtonCommons (item, enText, mnemonic, listener);
1300: }
1301:
1302:
1303:
1304:
1305: public static JCheckBoxMenuItem createCheckBoxMenuItem (boolean selected, String enText, ActionListener listener) {
1306: return createCheckBoxMenuItem (selected, enText, KeyEvent.VK_UNDEFINED, listener);
1307: }
1308: public static JCheckBoxMenuItem createCheckBoxMenuItem (boolean selected, String enText, int mnemonic, ActionListener listener) {
1309: return createCheckBoxMenuItem (selected, enText, mnemonic, 0, listener);
1310: }
1311: public static JCheckBoxMenuItem createCheckBoxMenuItem (boolean selected, String enText, int mnemonic, int modifiers, ActionListener listener) {
1312: JCheckBoxMenuItem item = new JCheckBoxMenuItem ();
1313: item.setSelected (selected);
1314: if (modifiers != 0) {
1315: item.setAccelerator (KeyStroke.getKeyStroke (mnemonic, modifiers));
1316: mnemonic = KeyEvent.VK_UNDEFINED;
1317: }
1318: return setButtonCommons (item, enText, mnemonic, listener);
1319: }
1320:
1321:
1322:
1323:
1324: public static JRadioButtonMenuItem createRadioButtonMenuItem (ButtonGroup group, boolean selected, String enText, ActionListener listener) {
1325: return createRadioButtonMenuItem (group, selected, enText, KeyEvent.VK_UNDEFINED, listener);
1326: }
1327: public static JRadioButtonMenuItem createRadioButtonMenuItem (ButtonGroup group, boolean selected, String enText, int mnemonic, ActionListener listener) {
1328: return createRadioButtonMenuItem (group, selected, enText, mnemonic, 0, listener);
1329: }
1330: public static JRadioButtonMenuItem createRadioButtonMenuItem (ButtonGroup group, boolean selected, String enText, int mnemonic, int modifiers, ActionListener listener) {
1331: JRadioButtonMenuItem item = new JRadioButtonMenuItem ();
1332: group.add (item);
1333: item.setSelected (selected);
1334: if (modifiers != 0) {
1335: item.setAccelerator (KeyStroke.getKeyStroke (mnemonic, modifiers));
1336: mnemonic = KeyEvent.VK_UNDEFINED;
1337: }
1338: return setButtonCommons (item, enText, mnemonic, listener);
1339: }
1340:
1341:
1342:
1343:
1344:
1345:
1346:
1347: public static <T extends AbstractButton> T setButtonCommons (T button, String enText, int mnemonic, ActionListener listener) {
1348: button.setMnemonic (mnemonic);
1349: if (mnemonic == KeyEvent.VK_UNDEFINED) {
1350: button.setText (enText);
1351: } else {
1352:
1353: String mnemonicText = KeyEvent.getKeyText (mnemonic);
1354: int index = enText.indexOf (mnemonicText);
1355: if (index < 0) {
1356: index = enText.toLowerCase ().indexOf (mnemonicText.toLowerCase ());
1357: }
1358: if (index >= 0) {
1359: button.setText (enText);
1360: button.setDisplayedMnemonicIndex (index);
1361: } else {
1362: button.setText (enText + "(" + mnemonicText + ")");
1363: button.setDisplayedMnemonicIndex (enText.length () + 1);
1364: }
1365: }
1366: button.setActionCommand (enText);
1367: return addListener (button, listener);
1368: }
1369:
1370:
1371:
1372:
1373:
1374:
1375:
1376:
1377:
1378:
1379:
1380: public static ScrollList createScrollList (String[] texts, int visibleRowCount, int selectedIndex, ListSelectionListener listener) {
1381: return createScrollList (texts, visibleRowCount, selectedIndex, ListSelectionModel.SINGLE_SELECTION, listener);
1382: }
1383: public static ScrollList createScrollList (String[] texts, int visibleRowCount, int selectedIndex, int selectionMode, ListSelectionListener listener) {
1384: DefaultListModel<String> listModel = new DefaultListModel<String> ();
1385: for (String text : texts) {
1386: listModel.addElement (text);
1387: }
1388: ScrollList list = new ScrollList (listModel);
1389: list.setVisibleRowCount (visibleRowCount);
1390: list.setSelectionMode (selectionMode);
1391: list.setSelectedIndex (selectedIndex);
1392: return addListener (list, listener);
1393: }
1394:
1395:
1396:
1397:
1398:
1399:
1400:
1401: public static JComboBox<String> createComboBox (int selectedIndex, String enToolTipText, ActionListener listener, String... texts) {
1402: JComboBox<String> comboBox = new JComboBox<String> (texts);
1403: comboBox.setBorder (new EmptyBorder (0, 0, 0, 0));
1404: comboBox.setEditable (false);
1405: comboBox.setSelectedIndex (selectedIndex);
1406:
1407: int digits = 0;
1408: for (String text : texts) {
1409: digits = Math.max (digits, text.length ());
1410: }
1411: comboBox.setMaximumSize (new Dimension (30 + 10 * digits, 20));
1412: comboBox.setPreferredSize (new Dimension (30 + 10 * digits, 20));
1413: if (enToolTipText != null) {
1414: comboBox.setToolTipText (enToolTipText);
1415: comboBox.setActionCommand (enToolTipText);
1416: }
1417: return addListener (comboBox, listener);
1418: }
1419:
1420:
1421:
1422:
1423:
1424:
1425:
1426: public static NumberSpinner createNumberSpinner (SpinnerNumberModel model, int digits, ChangeListener listener) {
1427: NumberSpinner spinner = new NumberSpinner (model);
1428: spinner.setBorder (new LineBorder (MetalLookAndFeel.getBlack (), 1));
1429: spinner.setPreferredSize (new Dimension (24 + (LnF.lnfFontSize * 2 / 3) * digits, LnF.lnfFontSize + 4));
1430: spinner.setMaximumSize (new Dimension (24 + (LnF.lnfFontSize * 2 / 3) * digits, LnF.lnfFontSize + 4));
1431: JSpinner.NumberEditor editor = (JSpinner.NumberEditor) spinner.getEditor ();
1432: editor.getFormat ().setGroupingUsed (false);
1433: JTextField textField = editor.getTextField ();
1434: textField.setHorizontalAlignment (JTextField.RIGHT);
1435:
1436: return addListener (spinner, listener);
1437: }
1438:
1439:
1440:
1441:
1442:
1443: public static DecimalSpinner createDecimalSpinner (int value, int minimum, int maximum, int stepSize) {
1444: return createDecimalSpinner (value, minimum, maximum, stepSize, 0, null);
1445: }
1446: public static DecimalSpinner createDecimalSpinner (int value, int minimum, int maximum, int stepSize, int option) {
1447: return createDecimalSpinner (value, minimum, maximum, stepSize, option, null);
1448: }
1449: public static DecimalSpinner createDecimalSpinner (int value, int minimum, int maximum, int stepSize, int option, ChangeListener listener) {
1450: return addListener (new DecimalSpinner (value, minimum, maximum, stepSize, option), listener);
1451: }
1452:
1453:
1454:
1455: public static Hex8Spinner createHex8Spinner (int value, int mask, boolean reverse, ChangeListener listener) {
1456: return addListener (new Hex8Spinner (value, mask, reverse), listener);
1457: }
1458:
1459:
1460:
1461: public static JSpinner createListSpinner (java.util.List<?> list, Object value, ChangeListener listener) {
1462: SpinnerListModel model = new SpinnerListModel (list);
1463: JSpinner spinner = new JSpinner (model);
1464: spinner.setBorder (new LineBorder (MetalLookAndFeel.getSeparatorForeground (), 1));
1465: int digits = 0;
1466: for (Object t : list) {
1467: digits = Math.max (digits, String.valueOf (t).length ());
1468: }
1469: spinner.setPreferredSize (new Dimension (24 + (LnF.lnfFontSize * 2 / 3) * digits, LnF.lnfFontSize + 4));
1470: spinner.setMaximumSize (new Dimension (24 + (LnF.lnfFontSize * 2 / 3) * digits, LnF.lnfFontSize + 4));
1471: JSpinner.ListEditor editor = (JSpinner.ListEditor) spinner.getEditor ();
1472: JTextField textField = editor.getTextField ();
1473: textField.setHorizontalAlignment (JTextField.RIGHT);
1474:
1475: model.setValue (value);
1476: return addListener (spinner, listener);
1477: }
1478:
1479:
1480:
1481: public static JSpinner createStringSpinner (String[] array, int index, ChangeListener listener) {
1482: ArrayList<String> list = new ArrayList<String> ();
1483: for (String string : array) {
1484: list.add (string);
1485: }
1486: return createListSpinner (list, array[index], listener);
1487: }
1488:
1489:
1490:
1491:
1492:
1493:
1494:
1495: public static void printAncestorClass (Object object) {
1496: System.out.print (object);
1497: if (object != null) {
1498: Class<? extends Object> c = object.getClass ();
1499: for (c = c.getSuperclass (); c != null; c = c.getSuperclass ()) {
1500: System.out.print (" < " + c.getName ());
1501: }
1502: }
1503: System.out.println ();
1504: }
1505:
1506:
1507:
1508:
1509: public static void printComponentTree (Component component) {
1510: printComponentTree (component, "0.");
1511: }
1512: public static void printComponentTree (Component component, String prefix) {
1513: System.out.print (prefix + " ");
1514: printAncestorClass (component);
1515: if (component instanceof Container) {
1516: Container container = (Container) component;
1517: int n = container.getComponentCount ();
1518: for (int i = 0; i < n; i++) {
1519: printComponentTree (container.getComponent (i), " " + prefix + i + ".");
1520: }
1521: }
1522: }
1523:
1524:
1525: }
1526:
1527:
1528: