}
}
}
if (msg instanceof String) {
JosmEditorPane pane = new JosmEditorPane("text/html", (String) msg);
pane.setEditable(false);
pane.setOpaque(false);
msg = pane;
}
final JOptionPane pane = new JOptionPane(
msg,
messageType,
JOptionPane.DEFAULT_OPTION,
icon,
buttons.toArray(),
defaultButton
);
pane.getValue();
final JDialog dialog = new JDialog(
JOptionPane.getFrameForComponent(parentComponent),
title,
ModalityType.DOCUMENT_MODAL
);
dialog.setContentPane(pane);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
pane.setValue(JOptionPane.CLOSED_OPTION);
super.windowClosed(e);
}
@Override
public void windowOpened(WindowEvent e) {
if (defaultOption != null && options != null && options.length > 0) {
int i;
for (i=0; i<options.length;i++) {
if (options[i] == defaultOption) {
break;
}
}
if (i >= options.length) {
buttons.get(0).requestFocusInWindow();
}
buttons.get(i).requestFocusInWindow();
} else {
buttons.get(0).requestFocusInWindow();
}
}
});
dialog.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0), "close");
dialog.getRootPane().getActionMap().put("close", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
pane.setValue(JOptionPane.CLOSED_OPTION);
dialog.setVisible(false);
}}
);
if (options != null) {
for (int i=0; i < options.length;i++) {
final DefaultAction action = new DefaultAction(dialog, pane, i);
buttons.get(i).addActionListener(action);
buttons.get(i).getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), "enter");
buttons.get(i).getActionMap().put("enter", action);
}
} else {
final DefaultAction action = new DefaultAction(dialog, pane, 0);
buttons.get(0).addActionListener(action);
buttons.get(0).getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), "enter");
buttons.get(0).getActionMap().put("enter", action);
}
dialog.pack();
WindowGeometry.centerOnScreen(dialog.getSize()).applySafe(dialog);
if (helpTopic != null) {
HelpUtil.setHelpContext(dialog.getRootPane(), helpTopic);
}
dialog.setVisible(true);
return (Integer)pane.getValue();
}