1:
37:
38:
39: package ;
40:
41: import ;
42:
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60:
61: import ;
62: import ;
63: import ;
64: import ;
65: import ;
66: import ;
67: import ;
68: import ;
69: import ;
70: import ;
71: import ;
72: import ;
73: import ;
74: import ;
75: import ;
76: import ;
77: import ;
78: import ;
79: import ;
80: import ;
81:
82:
85: public class BasicOptionPaneUI extends OptionPaneUI
86: {
87:
95: public class ButtonActionListener implements ActionListener
96: {
97:
98: protected int buttonIndex;
99:
100:
105: public ButtonActionListener(int buttonIndex)
106: {
107: this.buttonIndex = buttonIndex;
108: }
109:
110:
115: public void actionPerformed(ActionEvent e)
116: {
117: Object value = new Integer(JOptionPane.CLOSED_OPTION);
118: Object[] options = optionPane.getOptions();
119: if (options != null)
120: value = new Integer(buttonIndex);
121: else
122: {
123: String text = ((JButton) e.getSource()).getText();
124: if (text.equals(OK_STRING))
125: value = new Integer(JOptionPane.OK_OPTION);
126: if (text.equals(CANCEL_STRING))
127: value = new Integer(JOptionPane.CANCEL_OPTION);
128: if (text.equals(YES_STRING))
129: value = new Integer(JOptionPane.YES_OPTION);
130: if (text.equals(NO_STRING))
131: value = new Integer(JOptionPane.NO_OPTION);
132: }
133: optionPane.setValue(value);
134: resetInputValue();
135:
136: Window owner = SwingUtilities.windowForComponent(optionPane);
137:
138: if (owner instanceof JDialog)
139: ((JDialog) owner).dispose();
140:
141:
142: JInternalFrame inf = (JInternalFrame) SwingUtilities.getAncestorOfClass(JInternalFrame.class,
143: optionPane);
144: if (inf != null)
145: {
146: try
147: {
148: inf.setClosed(true);
149: }
150: catch (PropertyVetoException pve)
151: {
152:
153: }
154: }
155: }
156: }
157:
158:
167: public static class ButtonAreaLayout implements LayoutManager
168: {
169:
170: protected boolean centersChildren = true;
171:
172:
173: protected int padding;
174:
175:
176: protected boolean syncAllWidths;
177:
178:
179: private transient int widthOfWidestButton;
180:
181:
182: private transient int tallestButton;
183:
184:
191: public ButtonAreaLayout(boolean syncAllWidths, int padding)
192: {
193: this.syncAllWidths = syncAllWidths;
194: this.padding = padding;
195: }
196:
197:
203: public void addLayoutComponent(String string, Component comp)
204: {
205:
206: }
207:
208:
213: public boolean getCentersChildren()
214: {
215: return centersChildren;
216: }
217:
218:
223: public int getPadding()
224: {
225: return padding;
226: }
227:
228:
234: public boolean getSyncAllWidths()
235: {
236: return syncAllWidths;
237: }
238:
239:
244: public void layoutContainer(Container container)
245: {
246: Component[] buttonList = container.getComponents();
247: int x = container.getInsets().left;
248: if (getCentersChildren())
249: x += (int) ((double) (container.getSize().width) / 2
250: - (double) (buttonRowLength(container)) / 2);
251: for (int i = 0; i < buttonList.length; i++)
252: {
253: Dimension dims = buttonList[i].getPreferredSize();
254: if (syncAllWidths)
255: {
256: buttonList[i].setBounds(x, 0, widthOfWidestButton, dims.height);
257: x += widthOfWidestButton + getPadding();
258: }
259: else
260: {
261: buttonList[i].setBounds(x, 0, dims.width, dims.height);
262: x += dims.width + getPadding();
263: }
264: }
265: }
266:
267:
275: private int buttonRowLength(Container c)
276: {
277: Component[] buttonList = c.getComponents();
278:
279: int buttonLength = 0;
280: int widest = 0;
281: int tallest = 0;
282:
283: for (int i = 0; i < buttonList.length; i++)
284: {
285: Dimension dims = buttonList[i].getPreferredSize();
286: buttonLength += dims.width + getPadding();
287: widest = Math.max(widest, dims.width);
288: tallest = Math.max(tallest, dims.height);
289: }
290:
291: widthOfWidestButton = widest;
292: tallestButton = tallest;
293:
294: int width;
295: if (getSyncAllWidths())
296: width = widest * buttonList.length
297: + getPadding() * (buttonList.length - 1);
298: else
299: width = buttonLength;
300:
301: Insets insets = c.getInsets();
302: width += insets.left + insets.right;
303:
304: return width;
305: }
306:
307:
314: public Dimension minimumLayoutSize(Container c)
315: {
316: return preferredLayoutSize(c);
317: }
318:
319:
326: public Dimension preferredLayoutSize(Container c)
327: {
328: int w = buttonRowLength(c);
329:
330: return new Dimension(w, tallestButton);
331: }
332:
333:
339: public void removeLayoutComponent(Component c)
340: {
341:
342: }
343:
344:
349: public void setCentersChildren(boolean newValue)
350: {
351: centersChildren = newValue;
352: }
353:
354:
359: public void setPadding(int newPadding)
360: {
361: padding = newPadding;
362: }
363:
364:
369: public void setSyncAllWidths(boolean newValue)
370: {
371: syncAllWidths = newValue;
372: }
373: }
374:
375:
382: public class PropertyChangeHandler implements PropertyChangeListener
383: {
384:
390: public void propertyChange(PropertyChangeEvent e)
391: {
392: if (e.getPropertyName().equals(JOptionPane.ICON_PROPERTY)
393: || e.getPropertyName().equals(JOptionPane.MESSAGE_TYPE_PROPERTY))
394: addIcon(messageAreaContainer);
395: else if (e.getPropertyName().equals(JOptionPane.INITIAL_SELECTION_VALUE_PROPERTY))
396: resetSelectedValue();
397: else if (e.getPropertyName().equals(JOptionPane.INITIAL_VALUE_PROPERTY)
398: || e.getPropertyName().equals(JOptionPane.OPTIONS_PROPERTY)
399: || e.getPropertyName().equals(JOptionPane.OPTION_TYPE_PROPERTY))
400: {
401: Container newButtons = createButtonArea();
402: optionPane.remove(buttonContainer);
403: optionPane.add(newButtons);
404: buttonContainer = newButtons;
405: }
406:
407: else if (e.getPropertyName().equals(JOptionPane.MESSAGE_PROPERTY)
408: || e.getPropertyName().equals(JOptionPane.WANTS_INPUT_PROPERTY)
409: || e.getPropertyName().equals(JOptionPane.SELECTION_VALUES_PROPERTY))
410: {
411: optionPane.remove(messageAreaContainer);
412: messageAreaContainer = createMessageArea();
413: optionPane.add(messageAreaContainer);
414: Container newButtons = createButtonArea();
415: optionPane.remove(buttonContainer);
416: optionPane.add(newButtons);
417: buttonContainer = newButtons;
418: optionPane.add(buttonContainer);
419: }
420: optionPane.invalidate();
421: optionPane.repaint();
422: }
423: }
424:
425:
428: public static final int MinimumWidth = 262;
429:
430:
433: public static final int MinimumHeight = 90;
434:
435:
436: protected boolean hasCustomComponents = false;
437:
438:
439:
440:
441:
442:
443:
448: protected Component initialFocusComponent;
449:
450:
451: protected JComponent inputComponent;
452:
453:
454: protected Dimension minimumSize;
455:
456:
457: protected PropertyChangeListener propertyChangeListener;
458:
459:
460: protected JOptionPane optionPane;
461:
462:
463:
464: private static final int iconSize = 36;
465:
466:
467: private transient Color messageForeground;
468:
469:
470: private transient Border messageBorder;
471:
472:
473: private transient Border buttonBorder;
474:
475:
476: private static final String OK_STRING = "OK";
477:
478:
479: private static final String YES_STRING = "Yes";
480:
481:
482: private static final String NO_STRING = "No";
483:
484:
485: private static final String CANCEL_STRING = "Cancel";
486:
487:
489: transient Container messageAreaContainer;
490:
491:
493: transient Container buttonContainer;
494:
495:
499: private static class MessageIcon implements Icon
500: {
501:
506: public int getIconWidth()
507: {
508: return iconSize;
509: }
510:
511:
516: public int getIconHeight()
517: {
518: return iconSize;
519: }
520:
521:
530: public void paintIcon(Component c, Graphics g, int x, int y)
531: {
532:
533: }
534: }
535:
536:
537: private static MessageIcon errorIcon = new MessageIcon()
538: {
539: public void paintIcon(Component c, Graphics g, int x, int y)
540: {
541: Polygon oct = new Polygon(new int[] { 0, 0, 9, 27, 36, 36, 27, 9 },
542: new int[] { 9, 27, 36, 36, 27, 9, 0, 0 }, 8);
543: g.translate(x, y);
544:
545: Color saved = g.getColor();
546: g.setColor(Color.RED);
547:
548: g.fillPolygon(oct);
549:
550: g.setColor(Color.BLACK);
551: g.drawRect(13, 16, 10, 4);
552:
553: g.setColor(saved);
554: g.translate(-x, -y);
555: }
556: };
557:
558:
559: private static MessageIcon infoIcon = new MessageIcon()
560: {
561: public void paintIcon(Component c, Graphics g, int x, int y)
562: {
563: g.translate(x, y);
564: Color saved = g.getColor();
565:
566:
567: g.setColor(Color.RED);
568:
569: g.fillOval(0, 0, iconSize, iconSize);
570:
571: g.setColor(Color.BLACK);
572: g.drawOval(16, 6, 4, 4);
573:
574: Polygon bottomI = new Polygon(new int[] { 15, 15, 13, 13, 23, 23, 21, 21 },
575: new int[] { 12, 28, 28, 30, 30, 28, 28, 12 },
576: 8);
577: g.drawPolygon(bottomI);
578:
579: g.setColor(saved);
580: g.translate(-x, -y);
581: }
582: };
583:
584:
585: private static MessageIcon warningIcon = new MessageIcon()
586: {
587: public void paintIcon(Component c, Graphics g, int x, int y)
588: {
589: g.translate(x, y);
590: Color saved = g.getColor();
591: g.setColor(Color.YELLOW);
592:
593: Polygon triangle = new Polygon(new int[] { 0, 18, 36 },
594: new int[] { 36, 0, 36 }, 3);
595: g.fillPolygon(triangle);
596:
597: g.setColor(Color.BLACK);
598:
599: Polygon excl = new Polygon(new int[] { 15, 16, 20, 21 },
600: new int[] { 8, 26, 26, 8 }, 4);
601: g.drawPolygon(excl);
602: g.drawOval(16, 30, 4, 4);
603:
604: g.setColor(saved);
605: g.translate(-x, -y);
606: }
607: };
608:
609:
610: private static MessageIcon questionIcon = new MessageIcon()
611: {
612: public void paintIcon(Component c, Graphics g, int x, int y)
613: {
614: g.translate(x, y);
615: Color saved = g.getColor();
616: g.setColor(Color.GREEN);
617:
618: g.fillRect(0, 0, iconSize, iconSize);
619:
620: g.setColor(Color.BLACK);
621:
622: g.drawOval(11, 2, 16, 16);
623: g.drawOval(14, 5, 10, 10);
624:
625: g.setColor(Color.GREEN);
626: g.fillRect(0, 10, iconSize, iconSize - 10);
627:
628: g.setColor(Color.BLACK);
629:
630: g.drawLine(11, 10, 14, 10);
631:
632: g.drawLine(24, 10, 17, 22);
633: g.drawLine(27, 10, 20, 22);
634: g.drawLine(17, 22, 20, 22);
635:
636: g.drawOval(17, 25, 3, 3);
637:
638: g.setColor(saved);
639: g.translate(-x, -y);
640: }
641: };
642:
643:
644:
645:
646:
647:
650: public BasicOptionPaneUI()
651: {
652:
653: }
654:
655:
666: protected void addButtonComponents(Container container, Object[] buttons,
667: int initialIndex)
668: {
669: if (buttons == null)
670: return;
671: for (int i = 0; i < buttons.length; i++)
672: {
673: if (buttons[i] != null)
674: {
675: Component toAdd;
676: if (buttons[i] instanceof Component)
677: toAdd = (Component) buttons[i];
678: else
679: {
680: if (buttons[i] instanceof Icon)
681: toAdd = new JButton((Icon) buttons[i]);
682: else
683: toAdd = new JButton(buttons[i].toString());
684: hasCustomComponents = true;
685: }
686: if (toAdd instanceof JButton)
687: ((JButton) toAdd).addActionListener(createButtonActionListener(i));
688: if (i == initialIndex)
689: initialFocusComponent = toAdd;
690: container.add(toAdd);
691: }
692: }
693: selectInitialValue(optionPane);
694: }
695:
696:
701: protected void addIcon(Container top)
702: {
703: JLabel iconLabel = null;
704: Icon icon = getIcon();
705: if (icon != null)
706: {
707: iconLabel = new JLabel(icon);
708: top.add(iconLabel, BorderLayout.WEST);
709: }
710: }
711:
712:
718: private static GridBagConstraints createConstraints()
719: {
720: GridBagConstraints constraints = new GridBagConstraints();
721: constraints.gridx = GridBagConstraints.REMAINDER;
722: constraints.gridy = GridBagConstraints.REMAINDER;
723: constraints.gridwidth = 0;
724: constraints.anchor = GridBagConstraints.LINE_START;
725: constraints.fill = GridBagConstraints.NONE;
726: constraints.insets = new Insets(0, 0, 3, 0);
727:
728: return constraints;
729: }
730:
731:
747: protected void addMessageComponents(Container container,
748: GridBagConstraints cons, Object msg,
749: int maxll, boolean internallyCreated)
750: {
751: if (msg == null)
752: return;
753: hasCustomComponents = internallyCreated;
754: if (msg instanceof Object[])
755: {
756: Object[] arr = (Object[]) msg;
757: for (int i = 0; i < arr.length; i++)
758: addMessageComponents(container, cons, arr[i], maxll,
759: internallyCreated);
760: return;
761: }
762: else if (msg instanceof Component)
763: {
764: container.add((Component) msg, cons);
765: cons.gridy++;
766: }
767: else if (msg instanceof Icon)
768: {
769: container.add(new JLabel((Icon) msg), cons);
770: cons.gridy++;
771: }
772: else
773: {
774:
775:
776:
777:
778:
779: if (msg.toString().length() > maxll || msg.toString().contains("\n"))
780: {
781: Box tmp = new Box(BoxLayout.Y_AXIS);
782: burstStringInto(tmp, msg.toString(), maxll);
783: addMessageComponents(container, cons, tmp, maxll, true);
784: }
785: else
786: addMessageComponents(container, cons, new JLabel(msg.toString()),
787: maxll, true);
788: }
789: }
790:
791:
799: protected void burstStringInto(Container c, String d, int maxll)
800: {
801: if (d == null || c == null)
802: return;
803:
804: int newlineIndex = d.indexOf('\n');
805: String line;
806: String remainder;
807: if (newlineIndex >= 0 && newlineIndex < maxll)
808: {
809: line = d.substring(0, newlineIndex);
810: remainder = d.substring(newlineIndex + 1);
811: }
812: else
813: {
814: line = d.substring(0, maxll);
815: remainder = d.substring(maxll);
816: }
817: JLabel label = new JLabel(line);
818: c.add(label);
819:
820:
821: if (remainder.length() == 0)
822: return;
823:
824:
825: if ((remainder.length() > maxll || remainder.contains("\n")))
826: burstStringInto(c, remainder, maxll);
827: else
828:
829: c.add(new JLabel(remainder));
830: }
831:
832:
840: public boolean containsCustomComponents(JOptionPane op)
841: {
842: return hasCustomComponents;
843: }
844:
845:
852: protected ActionListener createButtonActionListener(int buttonIndex)
853: {
854: return new ButtonActionListener(buttonIndex);
855: }
856:
857:
862: protected Container createButtonArea()
863: {
864: JPanel buttonPanel = new JPanel();
865:
866: buttonPanel.setLayout(createLayoutManager());
867: addButtonComponents(buttonPanel, getButtons(), getInitialValueIndex());
868:
869: return buttonPanel;
870: }
871:
872:
877: protected LayoutManager createLayoutManager()
878: {
879: return new ButtonAreaLayout(getSizeButtonsToSameWidth(), 6);
880: }
881:
882:
887: protected Container createMessageArea()
888: {
889: JPanel messageArea = new JPanel();
890: messageArea.setLayout(new BorderLayout());
891: addIcon(messageArea);
892:
893: JPanel rightSide = new JPanel();
894: rightSide.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
895: rightSide.setLayout(new GridBagLayout());
896: GridBagConstraints con = createConstraints();
897:
898: addMessageComponents(rightSide, con, getMessage(),
899: getMaxCharactersPerLineCount(), false);
900:
901: if (optionPane.getWantsInput())
902: {
903: Object[] selection = optionPane.getSelectionValues();
904:
905: if (selection == null)
906: inputComponent = new JTextField(15);
907: else if (selection.length < 20)
908: inputComponent = new JComboBox(selection);
909: else
910: inputComponent = new JList(selection);
911: if (inputComponent != null)
912: {
913: addMessageComponents(rightSide, con, inputComponent,
914: getMaxCharactersPerLineCount(), false);
915: resetSelectedValue();
916: selectInitialValue(optionPane);
917: }
918: }
919:
920: messageArea.add(rightSide, BorderLayout.CENTER);
921:
922: return messageArea;
923: }
924:
925:
931: protected PropertyChangeListener createPropertyChangeListener()
932: {
933: return new PropertyChangeHandler();
934: }
935:
936:
942: protected Container createSeparator()
943: {
944:
945:
946: return null;
947: }
948:
949:
956: public static ComponentUI createUI(JComponent x)
957: {
958: return new BasicOptionPaneUI();
959: }
960:
961:
967: protected Object[] getButtons()
968: {
969: if (optionPane.getOptions() != null)
970: return optionPane.getOptions();
971: switch (optionPane.getOptionType())
972: {
973: case JOptionPane.YES_NO_OPTION:
974: return new Object[] { YES_STRING, NO_STRING };
975: case JOptionPane.YES_NO_CANCEL_OPTION:
976: return new Object[] { YES_STRING, NO_STRING, CANCEL_STRING };
977: case JOptionPane.OK_CANCEL_OPTION:
978: return new Object[] { OK_STRING, CANCEL_STRING };
979: case JOptionPane.DEFAULT_OPTION:
980: return (optionPane.getWantsInput() ) ?
981: new Object[] { OK_STRING, CANCEL_STRING } :
982: ( optionPane.getMessageType() == JOptionPane.QUESTION_MESSAGE ) ?
983: new Object[] { YES_STRING, NO_STRING, CANCEL_STRING } :
984:
985: new Object[] { OK_STRING };
986: }
987: return null;
988: }
989:
990:
996: protected Icon getIcon()
997: {
998: if (optionPane.getIcon() != null)
999: return optionPane.getIcon();
1000: else
1001: return getIconForType(optionPane.getMessageType());
1002: }
1003:
1004:
1011: protected Icon getIconForType(int messageType)
1012: {
1013: Icon tmp = null;
1014: switch (messageType)
1015: {
1016: case JOptionPane.ERROR_MESSAGE:
1017: tmp = errorIcon;
1018: break;
1019: case JOptionPane.INFORMATION_MESSAGE:
1020: tmp = infoIcon;
1021: break;
1022: case JOptionPane.WARNING_MESSAGE:
1023: tmp = warningIcon;
1024: break;
1025: case JOptionPane.QUESTION_MESSAGE:
1026: tmp = questionIcon;
1027: break;
1028: }
1029: return tmp;
1030:
1031:
1032: }
1033:
1034:
1039: protected int getInitialValueIndex()
1040: {
1041: Object[] buttons = getButtons();
1042:
1043: if (buttons == null)
1044: return -1;
1045:
1046: Object select = optionPane.getInitialValue();
1047:
1048: for (int i = 0; i < buttons.length; i++)
1049: {
1050: if (select == buttons[i])
1051: return i;
1052: }
1053: return 0;
1054: }
1055:
1056:
1063: protected int getMaxCharactersPerLineCount()
1064: {
1065: return optionPane.getMaxCharactersPerLineCount();
1066: }
1067:
1068:
1075: public Dimension getMaximumSize(JComponent c)
1076: {
1077: return getPreferredSize(c);
1078: }
1079:
1080:
1085: protected Object getMessage()
1086: {
1087: return optionPane.getMessage();
1088: }
1089:
1090:
1095: public Dimension getMinimumOptionPaneSize()
1096: {
1097: return minimumSize;
1098: }
1099:
1100:
1107: public Dimension getMinimumSize(JComponent c)
1108: {
1109: return getPreferredSize(c);
1110: }
1111:
1112:
1121: public Dimension getPreferredSize(JComponent c)
1122: {
1123: Dimension d = optionPane.getLayout().preferredLayoutSize(optionPane);
1124: Dimension d2 = getMinimumOptionPaneSize();
1125:
1126: int w = Math.max(d.width, d2.width);
1127: int h = Math.max(d.height, d2.height);
1128: return new Dimension(w, h);
1129: }
1130:
1131:
1136: protected boolean getSizeButtonsToSameWidth()
1137: {
1138: return true;
1139: }
1140:
1141:
1144: protected void installComponents()
1145: {
1146:
1147: hasCustomComponents = false;
1148: Container msg = createMessageArea();
1149: if (msg != null)
1150: {
1151: ((JComponent) msg).setBorder(messageBorder);
1152: msg.setForeground(messageForeground);
1153: messageAreaContainer = msg;
1154: optionPane.add(msg);
1155: }
1156:
1157:
1158:
1159:
1160:
1161: Container sep = createSeparator();
1162: if (sep != null)
1163: optionPane.add(sep);
1164:
1165: Container button = createButtonArea();
1166: if (button != null)
1167: {
1168: ((JComponent) button).setBorder(buttonBorder);
1169: buttonContainer = button;
1170: optionPane.add(button);
1171: }
1172:
1173: optionPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 11, 11));
1174: optionPane.invalidate();
1175: }
1176:
1177:
1180: protected void installDefaults()
1181: {
1182: LookAndFeel.installColorsAndFont(optionPane, "OptionPane.background",
1183: "OptionPane.foreground",
1184: "OptionPane.font");
1185: LookAndFeel.installBorder(optionPane, "OptionPane.border");
1186: optionPane.setOpaque(true);
1187:
1188: messageBorder = UIManager.getBorder("OptionPane.messageAreaBorder");
1189: messageForeground = UIManager.getColor("OptionPane.messageForeground");
1190: buttonBorder = UIManager.getBorder("OptionPane.buttonAreaBorder");
1191:
1192: minimumSize = UIManager.getDimension("OptionPane.minimumSize");
1193:
1194:
1195:
1196:
1197:
1203: }
1204:
1205:
1208: protected void installKeyboardActions()
1209: throws NotImplementedException
1210: {
1211:
1212: }
1213:
1214:
1217: protected void installListeners()
1218: {
1219: propertyChangeListener = createPropertyChangeListener();
1220:
1221: optionPane.addPropertyChangeListener(propertyChangeListener);
1222: }
1223:
1224:
1229: public void installUI(JComponent c)
1230: {
1231: if (c instanceof JOptionPane)
1232: {
1233: optionPane = (JOptionPane) c;
1234:
1235: installDefaults();
1236: installComponents();
1237: installListeners();
1238: installKeyboardActions();
1239: }
1240: }
1241:
1242:
1246: protected void resetInputValue()
1247: {
1248: if (optionPane.getWantsInput() && inputComponent != null)
1249: {
1250: Object output = null;
1251: if (inputComponent instanceof JTextField)
1252: output = ((JTextField) inputComponent).getText();
1253: else if (inputComponent instanceof JComboBox)
1254: output = ((JComboBox) inputComponent).getSelectedItem();
1255: else if (inputComponent instanceof JList)
1256: output = ((JList) inputComponent).getSelectedValue();
1257:
1258: if (output != null)
1259: optionPane.setInputValue(output);
1260: }
1261: }
1262:
1263:
1269: public void selectInitialValue(JOptionPane op)
1270: {
1271: if (inputComponent != null)
1272: {
1273: inputComponent.requestFocus();
1274: return;
1275: }
1276: if (initialFocusComponent != null)
1277: initialFocusComponent.requestFocus();
1278: }
1279:
1280:
1285: void resetSelectedValue()
1286: {
1287: if (inputComponent != null)
1288: {
1289: Object init = optionPane.getInitialSelectionValue();
1290: if (init == null)
1291: return;
1292: if (inputComponent instanceof JTextField)
1293: ((JTextField) inputComponent).setText((String) init);
1294: else if (inputComponent instanceof JComboBox)
1295: ((JComboBox) inputComponent).setSelectedItem(init);
1296: else if (inputComponent instanceof JList)
1297: {
1298:
1299: }
1300: }
1301: }
1302:
1303:
1306: protected void uninstallComponents()
1307: {
1308: optionPane.removeAll();
1309: buttonContainer = null;
1310: messageAreaContainer = null;
1311: }
1312:
1313:
1316: protected void uninstallDefaults()
1317: {
1318: optionPane.setFont(null);
1319: optionPane.setForeground(null);
1320: optionPane.setBackground(null);
1321:
1322: minimumSize = null;
1323:
1324: messageBorder = null;
1325: buttonBorder = null;
1326: messageForeground = null;
1327:
1328:
1329:
1330:
1336: }
1337:
1338:
1341: protected void uninstallKeyboardActions()
1342: throws NotImplementedException
1343: {
1344:
1345: }
1346:
1347:
1350: protected void uninstallListeners()
1351: {
1352: optionPane.removePropertyChangeListener(propertyChangeListener);
1353: propertyChangeListener = null;
1354: }
1355:
1356:
1361: public void uninstallUI(JComponent c)
1362: {
1363: uninstallKeyboardActions();
1364: uninstallListeners();
1365: uninstallComponents();
1366: uninstallDefaults();
1367:
1368: optionPane = null;
1369: }
1370: }