39 |
|
|
40 |
import java.awt.Component; |
import java.awt.Component; |
41 |
import java.awt.Dialog; |
import java.awt.Dialog; |
42 |
|
import java.awt.Dimension; |
43 |
import java.awt.Frame; |
import java.awt.Frame; |
44 |
import javax.accessibility.Accessible; |
import javax.accessibility.Accessible; |
45 |
import javax.accessibility.AccessibleContext; |
import javax.accessibility.AccessibleContext; |
46 |
import javax.accessibility.AccessibleRole; |
import javax.accessibility.AccessibleRole; |
47 |
import javax.swing.Icon; |
import javax.swing.Icon; |
48 |
|
import javax.swing.JInternalFrame; |
49 |
|
import javax.swing.event.InternalFrameAdapter; |
50 |
|
import javax.swing.event.InternalFrameEvent; |
51 |
import javax.swing.plaf.OptionPaneUI; |
import javax.swing.plaf.OptionPaneUI; |
52 |
|
|
53 |
|
|
64 |
*/ |
*/ |
65 |
protected class AccessibleJOptionPane extends JComponent.AccessibleJComponent |
protected class AccessibleJOptionPane extends JComponent.AccessibleJComponent |
66 |
{ |
{ |
67 |
|
/** DOCUMENT ME! */ |
68 |
private static final long serialVersionUID = 686071432213084821L; |
private static final long serialVersionUID = 686071432213084821L; |
69 |
|
|
70 |
/** |
/** |
85 |
} |
} |
86 |
} |
} |
87 |
|
|
88 |
|
/** DOCUMENT ME! */ |
89 |
private static final long serialVersionUID = 5231143276678566796L; |
private static final long serialVersionUID = 5231143276678566796L; |
90 |
|
|
91 |
/** The value returned when cancel option is selected. */ |
/** The value returned when cancel option is selected. */ |
379 |
dialog.getContentPane().add(this); |
dialog.getContentPane().add(this); |
380 |
dialog.setModal(true); |
dialog.setModal(true); |
381 |
dialog.setResizable(false); |
dialog.setResizable(false); |
382 |
|
dialog.invalidate(); |
383 |
|
dialog.repaint(); |
384 |
|
|
385 |
return dialog; |
return dialog; |
386 |
} |
} |
402 |
String title) |
String title) |
403 |
throws RuntimeException |
throws RuntimeException |
404 |
{ |
{ |
405 |
// FIXME: implement. |
JDesktopPane toUse = getDesktopPaneForComponent(parentComponent); |
406 |
return null; |
if (toUse == null) |
407 |
|
throw new RuntimeException("parentComponent does not have a valid parent"); |
408 |
|
|
409 |
|
JInternalFrame frame = new JInternalFrame(title); |
410 |
|
|
411 |
|
inputValue = UNINITIALIZED_VALUE; |
412 |
|
value = UNINITIALIZED_VALUE; |
413 |
|
|
414 |
|
frame.setClosable(true); |
415 |
|
toUse.add(frame); |
416 |
|
|
417 |
|
// FIXME: JLayeredPane broken? See bug # 16576 |
418 |
|
// frame.setLayer(JLayeredPane.MODAL_LAYER); |
419 |
|
return frame; |
420 |
} |
} |
421 |
|
|
422 |
/** |
/** |
442 |
*/ |
*/ |
443 |
public static JDesktopPane getDesktopPaneForComponent(Component parentComponent) |
public static JDesktopPane getDesktopPaneForComponent(Component parentComponent) |
444 |
{ |
{ |
445 |
return (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class, parentComponent); |
return (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class, |
446 |
|
parentComponent); |
447 |
} |
} |
448 |
|
|
449 |
/** |
/** |
456 |
*/ |
*/ |
457 |
public static Frame getFrameForComponent(Component parentComponent) |
public static Frame getFrameForComponent(Component parentComponent) |
458 |
{ |
{ |
459 |
return (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parentComponent); |
return (Frame) SwingUtilities.getAncestorOfClass(Frame.class, |
460 |
|
parentComponent); |
461 |
} |
} |
462 |
|
|
463 |
/** |
/** |
845 |
{ |
{ |
846 |
JOptionPane pane = new JOptionPane(message); |
JOptionPane pane = new JOptionPane(message); |
847 |
JDialog dialog = pane.createDialog(parentComponent, "Select an Option"); |
JDialog dialog = pane.createDialog(parentComponent, "Select an Option"); |
848 |
|
|
849 |
dialog.pack(); |
dialog.pack(); |
850 |
dialog.show(); |
dialog.show(); |
851 |
|
|
1088 |
} |
} |
1089 |
|
|
1090 |
/** |
/** |
1091 |
* DOCUMENT ME! |
* This method shows an internal confirmation dialog with the given message. |
1092 |
|
* The internal frame dialog will be placed in the first JDesktopPane |
1093 |
|
* ancestor of the given parentComponent. This method will return the value |
1094 |
|
* selected. |
1095 |
* |
* |
1096 |
* @param parentComponent DOCUMENT ME! |
* @param parentComponent The parent to find a JDesktopPane in. |
1097 |
* @param message DOCUMENT ME! |
* @param message The message to display. |
1098 |
* |
* |
1099 |
* @return DOCUMENT ME! |
* @return The value selected. |
1100 |
*/ |
*/ |
1101 |
public static int showInternalConfirmDialog(Component parentComponent, |
public static int showInternalConfirmDialog(Component parentComponent, |
1102 |
Object message) |
Object message) |
1103 |
{ |
{ |
1104 |
// FIXME: implement |
JOptionPane pane = new JOptionPane(message); |
1105 |
return 0; |
JInternalFrame frame = pane.createInternalFrame(parentComponent, null); |
1106 |
|
|
1107 |
|
startModal(frame, pane); |
1108 |
|
|
1109 |
|
return ((Integer) pane.getValue()).intValue(); |
1110 |
} |
} |
1111 |
|
|
1112 |
/** |
/** |
1113 |
* DOCUMENT ME! |
* This method shows an internal confirmation dialog with the given message, |
1114 |
|
* optionType and title. The internal frame dialog will be placed in the |
1115 |
|
* first JDesktopPane ancestor of the given parentComponent. This method |
1116 |
|
* will return the selected value. |
1117 |
* |
* |
1118 |
* @param parentComponent DOCUMENT ME! |
* @param parentComponent The parent to find a JDesktopPane in. |
1119 |
* @param message DOCUMENT ME! |
* @param message The message to display. |
1120 |
* @param title DOCUMENT ME! |
* @param title The title to display. |
1121 |
* @param optionType DOCUMENT ME! |
* @param optionType The option type. |
1122 |
* |
* |
1123 |
* @return DOCUMENT ME! |
* @return The selected value. |
1124 |
*/ |
*/ |
1125 |
public static int showInternalConfirmDialog(Component parentComponent, |
public static int showInternalConfirmDialog(Component parentComponent, |
1126 |
Object message, String title, |
Object message, String title, |
1127 |
int optionType) |
int optionType) |
1128 |
{ |
{ |
1129 |
// FIXME: implement |
JOptionPane pane = new JOptionPane(message, PLAIN_MESSAGE, optionType); |
1130 |
return 0; |
JInternalFrame frame = pane.createInternalFrame(parentComponent, title); |
1131 |
|
|
1132 |
|
startModal(frame, pane); |
1133 |
|
|
1134 |
|
return ((Integer) pane.getValue()).intValue(); |
1135 |
} |
} |
1136 |
|
|
1137 |
/** |
/** |
1138 |
* DOCUMENT ME! |
* This method shows an internal confirmation dialog with the given message, |
1139 |
|
* title, optionTypes and icon for the given message type. The internal |
1140 |
|
* confirmation dialog will be placed in the first instance of |
1141 |
|
* JDesktopPane ancestor of the given parentComponent. |
1142 |
* |
* |
1143 |
* @param parentComponent DOCUMENT ME! |
* @param parentComponent The component to find a JDesktopPane in. |
1144 |
* @param message DOCUMENT ME! |
* @param message The message to display. |
1145 |
* @param title DOCUMENT ME! |
* @param title The title of the dialog. |
1146 |
* @param optionType DOCUMENT ME! |
* @param optionType The option type. |
1147 |
* @param messageType DOCUMENT ME! |
* @param messageType The message type. |
1148 |
* |
* |
1149 |
* @return DOCUMENT ME! |
* @return The selected value. |
1150 |
*/ |
*/ |
1151 |
public static int showInternalConfirmDialog(Component parentComponent, |
public static int showInternalConfirmDialog(Component parentComponent, |
1152 |
Object message, String title, |
Object message, String title, |
1153 |
int optionType, int messageType) |
int optionType, int messageType) |
1154 |
{ |
{ |
1155 |
// FIXME: implement |
JOptionPane pane = new JOptionPane(message, messageType, optionType); |
1156 |
return 0; |
JInternalFrame frame = pane.createInternalFrame(parentComponent, title); |
1157 |
|
|
1158 |
|
startModal(frame, pane); |
1159 |
|
|
1160 |
|
return ((Integer) pane.getValue()).intValue(); |
1161 |
} |
} |
1162 |
|
|
1163 |
/** |
/** |
1164 |
* DOCUMENT ME! |
* This method shows an internal confirmation dialog with the given message, |
1165 |
|
* title, option type, message type, and icon. The internal frame dialog |
1166 |
|
* will be placed in the first JDesktopPane ancestor that is found in the |
1167 |
|
* given parentComponent. This method returns the selected value. |
1168 |
* |
* |
1169 |
* @param parentComponent DOCUMENT ME! |
* @param parentComponent The parent to find a JDesktopPane in. |
1170 |
* @param message DOCUMENT ME! |
* @param message The message to display. |
1171 |
* @param title DOCUMENT ME! |
* @param title The title to display. |
1172 |
* @param optionType DOCUMENT ME! |
* @param optionType The option type. |
1173 |
* @param messageType DOCUMENT ME! |
* @param messageType The message type. |
1174 |
* @param icon DOCUMENT ME! |
* @param icon The icon to display. |
1175 |
* |
* |
1176 |
* @return DOCUMENT ME! |
* @return The selected value. |
1177 |
*/ |
*/ |
1178 |
public static int showInternalConfirmDialog(Component parentComponent, |
public static int showInternalConfirmDialog(Component parentComponent, |
1179 |
Object message, String title, |
Object message, String title, |
1180 |
int optionType, int messageType, |
int optionType, int messageType, |
1181 |
Icon icon) |
Icon icon) |
1182 |
{ |
{ |
1183 |
// FIXME: implement |
JOptionPane pane = new JOptionPane(message, messageType, optionType, icon); |
1184 |
return 0; |
JInternalFrame frame = pane.createInternalFrame(parentComponent, title); |
1185 |
|
|
1186 |
|
startModal(frame, pane); |
1187 |
|
|
1188 |
|
return ((Integer) pane.getValue()).intValue(); |
1189 |
} |
} |
1190 |
|
|
1191 |
/** |
/** |
1192 |
* DOCUMENT ME! |
* This method shows an internal input dialog with the given message. The |
1193 |
|
* internal frame dialog will be placed in the first JDesktopPane ancestor |
1194 |
|
* of the given parent component. This method returns the value input by |
1195 |
|
* the user. |
1196 |
* |
* |
1197 |
* @param parentComponent DOCUMENT ME! |
* @param parentComponent The parent to find a JDesktopPane in. |
1198 |
* @param message DOCUMENT ME! |
* @param message The message to display. |
1199 |
* |
* |
1200 |
* @return DOCUMENT ME! |
* @return The user selected value. |
1201 |
*/ |
*/ |
1202 |
public static String showInternalInputDialog(Component parentComponent, |
public static String showInternalInputDialog(Component parentComponent, |
1203 |
Object message) |
Object message) |
1204 |
{ |
{ |
1205 |
// FIXME: implement |
JOptionPane pane = new JOptionPane(message); |
1206 |
return null; |
pane.setWantsInput(true); |
1207 |
|
JInternalFrame frame = pane.createInternalFrame(parentComponent, null); |
1208 |
|
|
1209 |
|
startModal(frame, pane); |
1210 |
|
|
1211 |
|
return (String) pane.getInputValue(); |
1212 |
} |
} |
1213 |
|
|
1214 |
/** |
/** |
1215 |
* DOCUMENT ME! |
* This method shows an internal input dialog with the given message, title |
1216 |
|
* and message type. The internal input dialog will be placed in the first |
1217 |
|
* JDesktopPane ancestor found in the given parent component. This method |
1218 |
|
* will return the input value given by the user. |
1219 |
* |
* |
1220 |
* @param parentComponent DOCUMENT ME! |
* @param parentComponent The component to find a JDesktopPane in. |
1221 |
* @param message DOCUMENT ME! |
* @param message The message to display. |
1222 |
* @param title DOCUMENT ME! |
* @param title The title to display. |
1223 |
* @param messageType DOCUMENT ME! |
* @param messageType The message type. |
1224 |
* |
* |
1225 |
* @return DOCUMENT ME! |
* @return The user input value. |
1226 |
*/ |
*/ |
1227 |
public static String showInternalInputDialog(Component parentComponent, |
public static String showInternalInputDialog(Component parentComponent, |
1228 |
Object message, String title, |
Object message, String title, |
1229 |
int messageType) |
int messageType) |
1230 |
{ |
{ |
1231 |
// FIXME: implement |
JOptionPane pane = new JOptionPane(message, messageType); |
1232 |
return null; |
pane.setWantsInput(true); |
1233 |
|
JInternalFrame frame = pane.createInternalFrame(parentComponent, title); |
1234 |
|
|
1235 |
|
startModal(frame, pane); |
1236 |
|
|
1237 |
|
return (String) pane.getInputValue(); |
1238 |
} |
} |
1239 |
|
|
1240 |
/** |
/** |
1241 |
* DOCUMENT ME! |
* This method shows an internal input dialog with the given message, title |
1242 |
|
* message type, icon, selection value list and initial selection value. |
1243 |
|
* The internal frame dialog will be placed in the first JDesktopPane |
1244 |
|
* ancestor found in the given parent component. This method returns the |
1245 |
|
* input value from the user. |
1246 |
* |
* |
1247 |
* @param parentComponent DOCUMENT ME! |
* @param parentComponent The parent to find a JDesktopPane in. |
1248 |
* @param message DOCUMENT ME! |
* @param message The message to display. |
1249 |
* @param title DOCUMENT ME! |
* @param title The title to display. |
1250 |
* @param messageType DOCUMENT ME! |
* @param messageType The message type. |
1251 |
* @param icon DOCUMENT ME! |
* @param icon The icon to display. |
1252 |
* @param selectionValues DOCUMENT ME! |
* @param selectionValues The selection value list. |
1253 |
* @param initialSelectionValue DOCUMENT ME! |
* @param initialSelectionValue The initial selection value. |
1254 |
* |
* |
1255 |
* @return DOCUMENT ME! |
* @return The user input value. |
1256 |
*/ |
*/ |
1257 |
public static Object showInternalInputDialog(Component parentComponent, |
public static Object showInternalInputDialog(Component parentComponent, |
1258 |
Object message, String title, |
Object message, String title, |
1260 |
Object[] selectionValues, |
Object[] selectionValues, |
1261 |
Object initialSelectionValue) |
Object initialSelectionValue) |
1262 |
{ |
{ |
1263 |
// FIXME: implement |
JOptionPane pane = new JOptionPane(message, messageType); |
1264 |
return null; |
pane.setWantsInput(true); |
1265 |
|
pane.setIcon(icon); |
1266 |
|
pane.setSelectionValues(selectionValues); |
1267 |
|
pane.setInitialSelectionValue(initialSelectionValue); |
1268 |
|
JInternalFrame frame = pane.createInternalFrame(parentComponent, title); |
1269 |
|
|
1270 |
|
startModal(frame, pane); |
1271 |
|
|
1272 |
|
return (String) pane.getInputValue(); |
1273 |
} |
} |
1274 |
|
|
1275 |
/** |
/** |
1276 |
* DOCUMENT ME! |
* This method shows an internal message dialog with the given message. The |
1277 |
|
* internal frame dialog will be placed in the first JDesktopPane ancestor |
1278 |
|
* found in the given parent component. |
1279 |
* |
* |
1280 |
* @param parentComponent DOCUMENT ME! |
* @param parentComponent The component to find a JDesktopPane in. |
1281 |
* @param message DOCUMENT ME! |
* @param message The message to display. |
1282 |
*/ |
*/ |
1283 |
public static void showInternalMessageDialog(Component parentComponent, |
public static void showInternalMessageDialog(Component parentComponent, |
1284 |
Object message) |
Object message) |
1285 |
{ |
{ |
1286 |
// FIXME: implement |
JOptionPane pane = new JOptionPane(message); |
1287 |
|
JInternalFrame frame = pane.createInternalFrame(parentComponent, null); |
1288 |
|
|
1289 |
|
startModal(frame, pane); |
1290 |
} |
} |
1291 |
|
|
1292 |
/** |
/** |
1293 |
* DOCUMENT ME! |
* This method shows an internal message dialog with the given message, |
1294 |
|
* title and message type. The internal message dialog is placed in the |
1295 |
|
* first JDesktopPane ancestor found in the given parent component. |
1296 |
* |
* |
1297 |
* @param parentComponent DOCUMENT ME! |
* @param parentComponent The parent component to find a JDesktopPane in. |
1298 |
* @param message DOCUMENT ME! |
* @param message The message to display. |
1299 |
* @param title DOCUMENT ME! |
* @param title The title to display. |
1300 |
* @param messageType DOCUMENT ME! |
* @param messageType The message type. |
1301 |
*/ |
*/ |
1302 |
public static void showInternalMessageDialog(Component parentComponent, |
public static void showInternalMessageDialog(Component parentComponent, |
1303 |
Object message, String title, |
Object message, String title, |
1304 |
int messageType) |
int messageType) |
1305 |
{ |
{ |
1306 |
// FIXME: implement |
JOptionPane pane = new JOptionPane(message, messageType); |
1307 |
|
JInternalFrame frame = pane.createInternalFrame(parentComponent, title); |
1308 |
|
|
1309 |
|
startModal(frame, pane); |
1310 |
} |
} |
1311 |
|
|
1312 |
/** |
/** |
1313 |
* DOCUMENT ME! |
* This method shows an internal message dialog with the given message, |
1314 |
|
* title, message type and icon. The internal message dialog is placed in |
1315 |
|
* the first JDesktopPane ancestor found in the given parent component. |
1316 |
* |
* |
1317 |
* @param parentComponent DOCUMENT ME! |
* @param parentComponent The component to find a JDesktopPane in. |
1318 |
* @param message DOCUMENT ME! |
* @param message The message to display. |
1319 |
* @param title DOCUMENT ME! |
* @param title The title to display. |
1320 |
* @param messageType DOCUMENT ME! |
* @param messageType The message type. |
1321 |
* @param icon DOCUMENT ME! |
* @param icon The icon to display. |
1322 |
*/ |
*/ |
1323 |
public static void showInternalMessageDialog(Component parentComponent, |
public static void showInternalMessageDialog(Component parentComponent, |
1324 |
Object message, String title, |
Object message, String title, |
1325 |
int messageType, Icon icon) |
int messageType, Icon icon) |
1326 |
{ |
{ |
1327 |
// FIXME: implement |
JOptionPane pane = new JOptionPane(message, messageType); |
1328 |
|
pane.setIcon(icon); |
1329 |
|
JInternalFrame frame = pane.createInternalFrame(parentComponent, title); |
1330 |
|
|
1331 |
|
startModal(frame, pane); |
1332 |
} |
} |
1333 |
|
|
1334 |
/** |
/** |
1335 |
* DOCUMENT ME! |
* This method displays an internal option dialog with the given message, |
1336 |
|
* title, option type, message type, icon, option list, and initial option |
1337 |
|
* value. The internal option dialog is placed in the first JDesktopPane |
1338 |
|
* ancestor found in the parent component. This method returns the option |
1339 |
|
* selected. |
1340 |
* |
* |
1341 |
* @param parentComponent DOCUMENT ME! |
* @param parentComponent The parent to find a JDesktopPane in. |
1342 |
* @param message DOCUMENT ME! |
* @param message The message displayed. |
1343 |
* @param title DOCUMENT ME! |
* @param title The title displayed. |
1344 |
* @param optionType DOCUMENT ME! |
* @param optionType The option type. |
1345 |
* @param messageType DOCUMENT ME! |
* @param messageType The message type. |
1346 |
* @param icon DOCUMENT ME! |
* @param icon The icon to display. |
1347 |
* @param options DOCUMENT ME! |
* @param options The array of options. |
1348 |
* @param initialValue DOCUMENT ME! |
* @param initialValue The initial value selected. |
1349 |
* |
* |
1350 |
* @return DOCUMENT ME! |
* @return The option that was selected. |
1351 |
*/ |
*/ |
1352 |
public static int showInternalOptionDialog(Component parentComponent, |
public static int showInternalOptionDialog(Component parentComponent, |
1353 |
Object message, String title, |
Object message, String title, |
1355 |
Icon icon, Object[] options, |
Icon icon, Object[] options, |
1356 |
Object initialValue) |
Object initialValue) |
1357 |
{ |
{ |
1358 |
// FIXME: implement |
JOptionPane pane = new JOptionPane(message, messageType, optionType, icon, |
1359 |
return 0; |
options, initialValue); |
1360 |
|
|
1361 |
|
JInternalFrame frame = pane.createInternalFrame(parentComponent, title); |
1362 |
|
|
1363 |
|
startModal(frame, pane); |
1364 |
|
|
1365 |
|
return ((Integer) pane.getValue()).intValue(); |
1366 |
} |
} |
1367 |
|
|
1368 |
/** |
/** |
1444 |
{ |
{ |
1445 |
JOptionPane pane = new JOptionPane(message, messageType, optionType, icon, |
JOptionPane pane = new JOptionPane(message, messageType, optionType, icon, |
1446 |
options, initialValue); |
options, initialValue); |
1447 |
|
|
1448 |
JDialog dialog = pane.createDialog(parentComponent, title); |
JDialog dialog = pane.createDialog(parentComponent, title); |
1449 |
dialog.pack(); |
dialog.pack(); |
1450 |
dialog.show(); |
dialog.show(); |
1501 |
} |
} |
1502 |
return false; |
return false; |
1503 |
} |
} |
1504 |
|
|
1505 |
|
/** |
1506 |
|
* This helper method makes the JInternalFrame wait until it is notified by |
1507 |
|
* an InternalFrameClosing event. This method also adds the given |
1508 |
|
* JOptionPane to the JInternalFrame and sizes it according to the |
1509 |
|
* JInternalFrame's preferred size. |
1510 |
|
* |
1511 |
|
* @param f The JInternalFrame to make modal. |
1512 |
|
* @param pane The JOptionPane to add to the JInternalFrame. |
1513 |
|
*/ |
1514 |
|
private static void startModal(JInternalFrame f, JOptionPane pane) |
1515 |
|
{ |
1516 |
|
f.getContentPane().add(pane); |
1517 |
|
f.pack(); |
1518 |
|
f.show(); |
1519 |
|
|
1520 |
|
Dimension pref = f.getPreferredSize(); |
1521 |
|
f.setBounds(0, 0, pref.width, pref.height); |
1522 |
|
|
1523 |
|
synchronized (f) |
1524 |
|
{ |
1525 |
|
final JInternalFrame tmp = f; |
1526 |
|
tmp.toFront(); |
1527 |
|
|
1528 |
|
f.addInternalFrameListener(new InternalFrameAdapter() |
1529 |
|
{ |
1530 |
|
public void internalFrameClosed(InternalFrameEvent e) |
1531 |
|
{ |
1532 |
|
synchronized (tmp) |
1533 |
|
{ |
1534 |
|
tmp.removeInternalFrameListener(this); |
1535 |
|
tmp.notifyAll(); |
1536 |
|
} |
1537 |
|
} |
1538 |
|
}); |
1539 |
|
try |
1540 |
|
{ |
1541 |
|
while (! f.isClosed()) |
1542 |
|
f.wait(); |
1543 |
|
} |
1544 |
|
catch (InterruptedException ignored) |
1545 |
|
{ |
1546 |
|
} |
1547 |
|
} |
1548 |
|
} |
1549 |
} |
} |