1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
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:
60: import ;
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: import ;
82: import ;
83: import ;
84: import ;
85:
86:
89: public class BasicOptionPaneUI extends OptionPaneUI
90: {
91:
94: static class OptionPaneCloseAction
95: extends AbstractAction
96: {
97:
98: public void actionPerformed(ActionEvent event)
99: {
100: JOptionPane op = (JOptionPane) event.getSource();
101: op.setValue(new Integer(JOptionPane.CLOSED_OPTION));
102: }
103:
104: }
105:
106:
114: public class ButtonActionListener implements ActionListener
115: {
116:
117: protected int buttonIndex;
118:
119:
124: public ButtonActionListener(int buttonIndex)
125: {
126: this.buttonIndex = buttonIndex;
127: }
128:
129:
134: public void actionPerformed(ActionEvent e)
135: {
136: Object value = new Integer(JOptionPane.CLOSED_OPTION);
137: Object[] options = optionPane.getOptions();
138: if (options != null)
139: value = new Integer(buttonIndex);
140: else
141: {
142: String text = ((JButton) e.getSource()).getText();
143: if (text.equals(OK_STRING))
144: value = new Integer(JOptionPane.OK_OPTION);
145: if (text.equals(CANCEL_STRING))
146: value = new Integer(JOptionPane.CANCEL_OPTION);
147: if (text.equals(YES_STRING))
148: value = new Integer(JOptionPane.YES_OPTION);
149: if (text.equals(NO_STRING))
150: value = new Integer(JOptionPane.NO_OPTION);
151: }
152: optionPane.setValue(value);
153: resetInputValue();
154:
155: Window owner = SwingUtilities.windowForComponent(optionPane);
156:
157: if (owner instanceof JDialog)
158: ((JDialog) owner).dispose();
159:
160:
161: JInternalFrame inf = (JInternalFrame) SwingUtilities.getAncestorOfClass(
162: JInternalFrame.class, optionPane);
163: if (inf != null)
164: {
165: try
166: {
167: inf.setClosed(true);
168: }
169: catch (PropertyVetoException pve)
170: {
171:
172: }
173: }
174: }
175: }
176:
177:
186: public static class ButtonAreaLayout implements LayoutManager
187: {
188:
189: protected boolean centersChildren = true;
190:
191:
192: protected int padding;
193:
194:
195: protected boolean syncAllWidths;
196:
197:
198: private transient int widthOfWidestButton;
199:
200:
201: private transient int tallestButton;
202:
203:
210: public ButtonAreaLayout(boolean syncAllWidths, int padding)
211: {
212: this.syncAllWidths = syncAllWidths;
213: this.padding = padding;
214: }
215:
216:
222: public void addLayoutComponent(String string, Component comp)
223: {
224:
225: }
226:
227:
232: public boolean getCentersChildren()
233: {
234: return centersChildren;
235: }
236:
237:
242: public int getPadding()
243: {
244: return padding;
245: }
246:
247:
253: public boolean getSyncAllWidths()
254: {
255: return syncAllWidths;
256: }
257:
258:
263: public void layoutContainer(Container container)
264: {
265: Component[] buttonList = container.getComponents();
266: int x = container.getInsets().left;
267: if (getCentersChildren())
268: x += (int) ((double) (container.getSize().width) / 2
269: - (double) (buttonRowLength(container)) / 2);
270: for (int i = 0; i < buttonList.length; i++)
271: {
272: Dimension dims = buttonList[i].getPreferredSize();
273: if (syncAllWidths)
274: {
275: buttonList[i].setBounds(x, 0, widthOfWidestButton, dims.height);
276: x += widthOfWidestButton + getPadding();
277: }
278: else
279: {
280: buttonList[i].setBounds(x, 0, dims.width, dims.height);
281: x += dims.width + getPadding();
282: }
283: }
284: }
285:
286:
294: private int buttonRowLength(Container c)
295: {
296: Component[] buttonList = c.getComponents();
297:
298: int buttonLength = 0;
299: int widest = 0;
300: int tallest = 0;
301:
302: for (int i = 0; i < buttonList.length; i++)
303: {
304: Dimension dims = buttonList[i].getPreferredSize();
305: buttonLength += dims.width + getPadding();
306: widest = Math.max(widest, dims.width);
307: tallest = Math.max(tallest, dims.height);
308: }
309:
310: widthOfWidestButton = widest;
311: tallestButton = tallest;
312:
313: int width;
314: if (getSyncAllWidths())
315: width = widest * buttonList.length
316: + getPadding() * (buttonList.length - 1);
317: else
318: width = buttonLength;
319:
320: Insets insets = c.getInsets();
321: width += insets.left + insets.right;
322:
323: return width;
324: }
325:
326:
333: public Dimension minimumLayoutSize(Container c)
334: {
335: return preferredLayoutSize(c);
336: }
337:
338:
345: public Dimension preferredLayoutSize(Container c)
346: {
347: int w = buttonRowLength(c);
348:
349: return new Dimension(w, tallestButton);
350: }
351:
352:
358: public void removeLayoutComponent(Component c)
359: {
360:
361: }
362:
363:
368: public void setCentersChildren(boolean newValue)
369: {
370: centersChildren = newValue;
371: }
372:
373:
378: public void setPadding(int newPadding)
379: {
380: padding = newPadding;
381: }
382:
383:
388: public void setSyncAllWidths(boolean newValue)
389: {
390: syncAllWidths = newValue;
391: }
392: }
393:
394:
401: public class PropertyChangeHandler implements PropertyChangeListener
402: {
403:
409: public void propertyChange(PropertyChangeEvent e)
410: {
411: String property = e.getPropertyName();
412: if (property.equals(JOptionPane.ICON_PROPERTY)
413: || property.equals(JOptionPane.INITIAL_SELECTION_VALUE_PROPERTY)
414: || property.equals(JOptionPane.INITIAL_VALUE_PROPERTY)
415: || property.equals(JOptionPane.MESSAGE_PROPERTY)
416: || property.equals(JOptionPane.MESSAGE_TYPE_PROPERTY)
417: || property.equals(JOptionPane.OPTION_TYPE_PROPERTY)
418: || property.equals(JOptionPane.OPTIONS_PROPERTY)
419: || property.equals(JOptionPane.WANTS_INPUT_PROPERTY))
420: {
421: uninstallComponents();
422: installComponents();
423: optionPane.validate();
424: }
425: }
426: }
427:
428:
431: public static final int MinimumWidth = 262;
432:
433:
436: public static final int MinimumHeight = 90;
437:
438:
439: protected boolean hasCustomComponents;
440:
441:
442:
443:
444:
445:
446:
451: protected Component initialFocusComponent;
452:
453:
454: protected JComponent inputComponent;
455:
456:
457: protected Dimension minimumSize;
458:
459:
460: protected PropertyChangeListener propertyChangeListener;
461:
462:
463: protected JOptionPane optionPane;
464:
465:
466: private static final int ICON_SIZE = 36;
467:
468:
469: private static final String OK_STRING = "OK";
470:
471:
472: private static final String YES_STRING = "Yes";
473:
474:
475: private static final String NO_STRING = "No";
476:
477:
478: private static final String CANCEL_STRING = "Cancel";
479:
480:
482: transient Container messageAreaContainer;
483:
484:
486: transient Container buttonContainer;
487:
488:
492: private static class MessageIcon implements Icon
493: {
494:
499: public int getIconWidth()
500: {
501: return ICON_SIZE;
502: }
503:
504:
509: public int getIconHeight()
510: {
511: return ICON_SIZE;
512: }
513:
514:
523: public void paintIcon(Component c, Graphics g, int x, int y)
524: {
525:
526: }
527: }
528:
529:
530: private static MessageIcon errorIcon = new MessageIcon()
531: {
532: public void paintIcon(Component c, Graphics g, int x, int y)
533: {
534: Polygon oct = new Polygon(new int[] { 0, 0, 9, 27, 36, 36, 27, 9 },
535: new int[] { 9, 27, 36, 36, 27, 9, 0, 0 }, 8);
536: g.translate(x, y);
537:
538: Color saved = g.getColor();
539: g.setColor(Color.RED);
540:
541: g.fillPolygon(oct);
542:
543: g.setColor(Color.BLACK);
544: g.drawRect(13, 16, 10, 4);
545:
546: g.setColor(saved);
547: g.translate(-x, -y);
548: }
549: };
550:
551:
552: private static MessageIcon infoIcon = new MessageIcon()
553: {
554: public void paintIcon(Component c, Graphics g, int x, int y)
555: {
556: g.translate(x, y);
557: Color saved = g.getColor();
558:
559:
560: g.setColor(Color.RED);
561:
562: g.fillOval(0, 0, ICON_SIZE, ICON_SIZE);
563:
564: g.setColor(Color.BLACK);
565: g.drawOval(16, 6, 4, 4);
566:
567: Polygon bottomI = new Polygon(new int[] { 15, 15, 13, 13, 23, 23, 21, 21 },
568: new int[] { 12, 28, 28, 30, 30, 28, 28, 12 },
569: 8);
570: g.drawPolygon(bottomI);
571:
572: g.setColor(saved);
573: g.translate(-x, -y);
574: }
575: };
576:
577:
578: private static MessageIcon warningIcon = new MessageIcon()
579: {
580: public void paintIcon(Component c, Graphics g, int x, int y)
581: {
582: g.translate(x, y);
583: Color saved = g.getColor();
584: g.setColor(Color.YELLOW);
585:
586: Polygon triangle = new Polygon(new int[] { 0, 18, 36 },
587: new int[] { 36, 0, 36 }, 3);
588: g.fillPolygon(triangle);
589:
590: g.setColor(Color.BLACK);
591:
592: Polygon excl = new Polygon(new int[] { 15, 16, 20, 21 },
593: new int[] { 8, 26, 26, 8 }, 4);
594: g.drawPolygon(excl);
595: g.drawOval(16, 30, 4, 4);
596:
597: g.setColor(saved);
598: g.translate(-x, -y);
599: }
600: };
601:
602:
603: private static MessageIcon questionIcon = new MessageIcon()
604: {
605: public void paintIcon(Component c, Graphics g, int x, int y)
606: {
607: g.translate(x, y);
608: Color saved = g.getColor();
609: g.setColor(Color.GREEN);
610:
611: g.fillRect(0, 0, ICON_SIZE, ICON_SIZE);
612:
613: g.setColor(Color.BLACK);
614:
615: g.drawOval(11, 2, 16, 16);
616: g.drawOval(14, 5, 10, 10);
617:
618: g.setColor(Color.GREEN);
619: g.fillRect(0, 10, ICON_SIZE, ICON_SIZE - 10);
620:
621: g.setColor(Color.BLACK);
622:
623: g.drawLine(11, 10, 14, 10);
624:
625: g.drawLine(24, 10, 17, 22);
626: g.drawLine(27, 10, 20, 22);
627: g.drawLine(17, 22, 20, 22);
628:
629: g.drawOval(17, 25, 3, 3);
630:
631: g.setColor(saved);
632: g.translate(-x, -y);
633: }
634: };
635:
636:
639: public BasicOptionPaneUI()
640: {
641:
642: }
643:
644:
655: protected void addButtonComponents(Container container, Object[] buttons,
656: int initialIndex)
657: {
658: if (buttons == null)
659: return;
660: for (int i = 0; i < buttons.length; i++)
661: {
662: if (buttons[i] != null)
663: {
664: Component toAdd;
665: if (buttons[i] instanceof Component)
666: toAdd = (Component) buttons[i];
667: else
668: {
669: if (buttons[i] instanceof Icon)
670: toAdd = new JButton((Icon) buttons[i]);
671: else
672: toAdd = new JButton(buttons[i].toString());
673: hasCustomComponents = true;
674: }
675: if (toAdd instanceof JButton)
676: ((JButton) toAdd).addActionListener(createButtonActionListener(i));
677: if (i == initialIndex)
678: initialFocusComponent = toAdd;
679: container.add(toAdd);
680: }
681: }
682: selectInitialValue(optionPane);
683: }
684:
685:
690: protected void addIcon(Container top)
691: {
692: JLabel iconLabel = null;
693: Icon icon = getIcon();
694: if (icon != null)
695: {
696: iconLabel = new JLabel(icon);
697: configureLabel(iconLabel);
698: top.add(iconLabel, BorderLayout.WEST);
699: }
700: }
701:
702:
708: private static GridBagConstraints createConstraints()
709: {
710: GridBagConstraints constraints = new GridBagConstraints();
711: constraints.gridx = GridBagConstraints.REMAINDER;
712: constraints.gridy = GridBagConstraints.REMAINDER;
713: constraints.gridwidth = 0;
714: constraints.anchor = GridBagConstraints.LINE_START;
715: constraints.fill = GridBagConstraints.NONE;
716: constraints.insets = new Insets(0, 0, 3, 0);
717:
718: return constraints;
719: }
720:
721:
737: protected void addMessageComponents(Container container,
738: GridBagConstraints cons, Object msg,
739: int maxll, boolean internallyCreated)
740: {
741: if (msg == null)
742: return;
743: hasCustomComponents = internallyCreated;
744: if (msg instanceof Object[])
745: {
746: Object[] arr = (Object[]) msg;
747: for (int i = 0; i < arr.length; i++)
748: addMessageComponents(container, cons, arr[i], maxll,
749: internallyCreated);
750: return;
751: }
752: else if (msg instanceof Component)
753: {
754: container.add((Component) msg, cons);
755: cons.gridy++;
756: }
757: else if (msg instanceof Icon)
758: {
759: JLabel label = new JLabel((Icon) msg);
760: configureLabel(label);
761: container.add(label, cons);
762: cons.gridy++;
763: }
764: else
765: {
766:
767:
768:
769:
770:
771: if (msg.toString().length() > maxll || msg.toString().contains("\n"))
772: {
773: Box tmp = new Box(BoxLayout.Y_AXIS);
774: burstStringInto(tmp, msg.toString(), maxll);
775: addMessageComponents(container, cons, tmp, maxll, true);
776: }
777: else
778: {
779: JLabel label = new JLabel(msg.toString());
780: configureLabel(label);
781: addMessageComponents(container, cons, label, maxll, true);
782: }
783: }
784: }
785:
786:
794: protected void burstStringInto(Container c, String d, int maxll)
795: {
796: if (d == null || c == null)
797: return;
798:
799: int newlineIndex = d.indexOf('\n');
800: String line;
801: String remainder;
802: if (newlineIndex >= 0 && newlineIndex < maxll)
803: {
804: line = d.substring(0, newlineIndex);
805: remainder = d.substring(newlineIndex + 1);
806: }
807: else
808: {
809: line = d.substring(0, maxll);
810: remainder = d.substring(maxll);
811: }
812: JLabel label = new JLabel(line);
813: configureLabel(label);
814: c.add(label);
815:
816:
817: if (remainder.length() == 0)
818: return;
819:
820:
821: if (remainder.length() > maxll || remainder.contains("\n"))
822: burstStringInto(c, remainder, maxll);
823: else
824: {
825:
826: JLabel l = new JLabel(remainder);
827: configureLabel(l);
828: c.add(l);
829: }
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: Border b = UIManager.getBorder("OptionPane.buttonAreaBorder");
866: if (b != null)
867: buttonPanel.setBorder(b);
868:
869: buttonPanel.setLayout(createLayoutManager());
870: addButtonComponents(buttonPanel, getButtons(), getInitialValueIndex());
871:
872: return buttonPanel;
873: }
874:
875:
880: protected LayoutManager createLayoutManager()
881: {
882: return new ButtonAreaLayout(getSizeButtonsToSameWidth(), 6);
883: }
884:
885:
890: protected Container createMessageArea()
891: {
892: JPanel messageArea = new JPanel();
893: Border messageBorder = UIManager.getBorder("OptionPane.messageAreaBorder");
894: if (messageBorder != null)
895: messageArea.setBorder(messageBorder);
896:
897: messageArea.setLayout(new BorderLayout());
898: addIcon(messageArea);
899:
900: JPanel rightSide = new JPanel();
901: rightSide.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
902: rightSide.setLayout(new GridBagLayout());
903: GridBagConstraints con = createConstraints();
904:
905: addMessageComponents(rightSide, con, getMessage(),
906: getMaxCharactersPerLineCount(), false);
907:
908: if (optionPane.getWantsInput())
909: {
910: Object[] selection = optionPane.getSelectionValues();
911:
912: if (selection == null)
913: inputComponent = new JTextField(15);
914: else if (selection.length < 20)
915: inputComponent = new JComboBox(selection);
916: else
917: inputComponent = new JList(selection);
918: if (inputComponent != null)
919: {
920: addMessageComponents(rightSide, con, inputComponent,
921: getMaxCharactersPerLineCount(), false);
922: resetSelectedValue();
923: selectInitialValue(optionPane);
924: }
925: }
926:
927: messageArea.add(rightSide, BorderLayout.CENTER);
928:
929: return messageArea;
930: }
931:
932:
938: protected PropertyChangeListener createPropertyChangeListener()
939: {
940: return new PropertyChangeHandler();
941: }
942:
943:
949: protected Container createSeparator()
950: {
951:
952:
953:
954: return null;
955: }
956:
957:
964: public static ComponentUI createUI(JComponent x)
965: {
966: return new BasicOptionPaneUI();
967: }
968:
969:
975: protected Object[] getButtons()
976: {
977: if (optionPane.getOptions() != null)
978: return optionPane.getOptions();
979: switch (optionPane.getOptionType())
980: {
981: case JOptionPane.YES_NO_OPTION:
982: return new Object[] { YES_STRING, NO_STRING };
983: case JOptionPane.YES_NO_CANCEL_OPTION:
984: return new Object[] { YES_STRING, NO_STRING, CANCEL_STRING };
985: case JOptionPane.OK_CANCEL_OPTION:
986: return new Object[] { OK_STRING, CANCEL_STRING };
987: case JOptionPane.DEFAULT_OPTION:
988: return (optionPane.getWantsInput()) ?
989: new Object[] { OK_STRING, CANCEL_STRING } :
990: (optionPane.getMessageType() == JOptionPane.QUESTION_MESSAGE) ?
991: new Object[] { YES_STRING, NO_STRING, CANCEL_STRING } :
992:
993: new Object[] { OK_STRING };
994: }
995: return null;
996: }
997:
998:
1004: protected Icon getIcon()
1005: {
1006: if (optionPane.getIcon() != null)
1007: return optionPane.getIcon();
1008: else
1009: return getIconForType(optionPane.getMessageType());
1010: }
1011:
1012:
1019: protected Icon getIconForType(int messageType)
1020: {
1021: Icon tmp = null;
1022: switch (messageType)
1023: {
1024: case JOptionPane.ERROR_MESSAGE:
1025: tmp = errorIcon;
1026: break;
1027: case JOptionPane.INFORMATION_MESSAGE:
1028: tmp = infoIcon;
1029: break;
1030: case JOptionPane.WARNING_MESSAGE:
1031: tmp = warningIcon;
1032: break;
1033: case JOptionPane.QUESTION_MESSAGE:
1034: tmp = questionIcon;
1035: break;
1036: }
1037: return tmp;
1038:
1039:
1040: }
1041:
1042:
1047: protected int getInitialValueIndex()
1048: {
1049: Object[] buttons = getButtons();
1050:
1051: if (buttons == null)
1052: return -1;
1053:
1054: Object select = optionPane.getInitialValue();
1055:
1056: for (int i = 0; i < buttons.length; i++)
1057: {
1058: if (select == buttons[i])
1059: return i;
1060: }
1061: return 0;
1062: }
1063:
1064:
1071: protected int getMaxCharactersPerLineCount()
1072: {
1073: return optionPane.getMaxCharactersPerLineCount();
1074: }
1075:
1076:
1083: public Dimension getMaximumSize(JComponent c)
1084: {
1085: return getPreferredSize(c);
1086: }
1087:
1088:
1093: protected Object getMessage()
1094: {
1095: return optionPane.getMessage();
1096: }
1097:
1098:
1103: public Dimension getMinimumOptionPaneSize()
1104: {
1105: return minimumSize;
1106: }
1107:
1108:
1115: public Dimension getMinimumSize(JComponent c)
1116: {
1117: return getPreferredSize(c);
1118: }
1119:
1120:
1129: public Dimension getPreferredSize(JComponent c)
1130: {
1131: Dimension d = optionPane.getLayout().preferredLayoutSize(optionPane);
1132: Dimension d2 = getMinimumOptionPaneSize();
1133:
1134: int w = Math.max(d.width, d2.width);
1135: int h = Math.max(d.height, d2.height);
1136: return new Dimension(w, h);
1137: }
1138:
1139:
1144: protected boolean getSizeButtonsToSameWidth()
1145: {
1146: return true;
1147: }
1148:
1149:
1152: protected void installComponents()
1153: {
1154:
1155: optionPane.add(createMessageArea());
1156:
1157:
1158:
1159: Container sep = createSeparator();
1160: if (sep != null)
1161: optionPane.add(sep);
1162:
1163:
1164: optionPane.add(createButtonArea());
1165: }
1166:
1167:
1170: protected void installDefaults()
1171: {
1172: LookAndFeel.installColorsAndFont(optionPane, "OptionPane.background",
1173: "OptionPane.foreground",
1174: "OptionPane.font");
1175: LookAndFeel.installBorder(optionPane, "OptionPane.border");
1176: optionPane.setOpaque(true);
1177:
1178: minimumSize = UIManager.getDimension("OptionPane.minimumSize");
1179:
1180:
1181:
1182:
1183:
1189: }
1190:
1191:
1194: protected void installKeyboardActions()
1195: {
1196:
1197: Object[] bindings =
1198: (Object[]) SharedUIDefaults.get("OptionPane.windowBindings");
1199: InputMap inputMap = LookAndFeel.makeComponentInputMap(optionPane,
1200: bindings);
1201: SwingUtilities.replaceUIInputMap(optionPane,
1202: JComponent.WHEN_IN_FOCUSED_WINDOW,
1203: inputMap);
1204:
1205:
1206: SwingUtilities.replaceUIActionMap(optionPane, getActionMap());
1207: }
1208:
1209:
1215: private ActionMap getActionMap()
1216: {
1217: ActionMap am = (ActionMap) UIManager.get("OptionPane.actionMap");
1218: if (am == null)
1219: {
1220: am = createDefaultActions();
1221: UIManager.getLookAndFeelDefaults().put("OptionPane.actionMap", am);
1222: }
1223: return am;
1224: }
1225:
1226: private ActionMap createDefaultActions()
1227: {
1228: ActionMapUIResource am = new ActionMapUIResource();
1229: Action action = new OptionPaneCloseAction();
1230:
1231: am.put("close", action);
1232: return am;
1233: }
1234:
1235:
1238: protected void installListeners()
1239: {
1240: propertyChangeListener = createPropertyChangeListener();
1241:
1242: optionPane.addPropertyChangeListener(propertyChangeListener);
1243: }
1244:
1245:
1250: public void installUI(JComponent c)
1251: {
1252: if (c instanceof JOptionPane)
1253: {
1254: optionPane = (JOptionPane) c;
1255:
1256: installDefaults();
1257: installComponents();
1258: installListeners();
1259: installKeyboardActions();
1260: }
1261: }
1262:
1263:
1267: protected void resetInputValue()
1268: {
1269: if (optionPane.getWantsInput() && inputComponent != null)
1270: {
1271: Object output = null;
1272: if (inputComponent instanceof JTextField)
1273: output = ((JTextField) inputComponent).getText();
1274: else if (inputComponent instanceof JComboBox)
1275: output = ((JComboBox) inputComponent).getSelectedItem();
1276: else if (inputComponent instanceof JList)
1277: output = ((JList) inputComponent).getSelectedValue();
1278:
1279: if (output != null)
1280: optionPane.setInputValue(output);
1281: }
1282: }
1283:
1284:
1290: public void selectInitialValue(JOptionPane op)
1291: {
1292: if (inputComponent != null)
1293: {
1294: inputComponent.requestFocus();
1295: return;
1296: }
1297: if (initialFocusComponent != null)
1298: initialFocusComponent.requestFocus();
1299: }
1300:
1301:
1306: void resetSelectedValue()
1307: {
1308: if (inputComponent != null)
1309: {
1310: Object init = optionPane.getInitialSelectionValue();
1311: if (init == null)
1312: return;
1313: if (inputComponent instanceof JTextField)
1314: ((JTextField) inputComponent).setText((String) init);
1315: else if (inputComponent instanceof JComboBox)
1316: ((JComboBox) inputComponent).setSelectedItem(init);
1317: else if (inputComponent instanceof JList)
1318: {
1319:
1320: }
1321: }
1322: }
1323:
1324:
1327: protected void uninstallComponents()
1328: {
1329: optionPane.removeAll();
1330: buttonContainer = null;
1331: messageAreaContainer = null;
1332: }
1333:
1334:
1337: protected void uninstallDefaults()
1338: {
1339: optionPane.setFont(null);
1340: optionPane.setForeground(null);
1341: optionPane.setBackground(null);
1342:
1343: minimumSize = null;
1344:
1345:
1346:
1347:
1353: }
1354:
1355:
1358: protected void uninstallKeyboardActions()
1359: {
1360: SwingUtilities.replaceUIInputMap(optionPane, JComponent.
1361: WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
1362: SwingUtilities.replaceUIActionMap(optionPane, null);
1363: }
1364:
1365:
1368: protected void uninstallListeners()
1369: {
1370: optionPane.removePropertyChangeListener(propertyChangeListener);
1371: propertyChangeListener = null;
1372: }
1373:
1374:
1379: public void uninstallUI(JComponent c)
1380: {
1381: uninstallKeyboardActions();
1382: uninstallListeners();
1383: uninstallComponents();
1384: uninstallDefaults();
1385:
1386: optionPane = null;
1387: }
1388:
1389:
1395: private void configureLabel(JLabel l)
1396: {
1397: Color c = UIManager.getColor("OptionPane.messageForeground");
1398: if (c != null)
1399: l.setForeground(c);
1400: Font f = UIManager.getFont("OptionPane.messageFont");
1401: if (f != null)
1402: l.setFont(f);
1403: }
1404: }