/** #154030 - Creates JDialog around JOptionPane. The body is copied from JOptionPane.createDialog *becauseweneedAPPLICATION_MODALtypeofdialogonJDK6.
*/ publicstatic JDialog createJOptionDialog(final JOptionPane pane, String title) { final JDialog dialog = new JDialog(null, title, Dialog.ModalityType.APPLICATION_MODAL); if(sourceFolder != null) {
dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
}
Util.initIcons(dialog);
Container contentPane = dialog.getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(pane, BorderLayout.CENTER);
dialog.setResizable(false);
dialog.pack();
dialog.setLocationRelativeTo(null);
WindowAdapter adapter = new WindowAdapter() {
privateboolean gotFocus = false;
@Override publicvoid windowClosing(WindowEvent we) { // Options importing might still be in progress, so do nothing // and let the OptionsImportingTask close the dialog when it is done. if(sourceFolder != null) { return;
}
pane.setValue(null);
}
@Override publicvoid windowGainedFocus(WindowEvent we) { // Once window gets focus, set initial focus if (!gotFocus) {
pane.selectInitialValue();
gotFocus = true;
}
}
};
dialog.addWindowListener(adapter);
dialog.addWindowFocusListener(adapter);
dialog.addComponentListener(new ComponentAdapter() {
@Override publicvoid componentShown(ComponentEvent ce) { // reset value to ensure closing works properly
pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
}
});
pane.addPropertyChangeListener(new PropertyChangeListener() {
@Override publicvoid propertyChange(PropertyChangeEvent event) { // Let the defaultCloseOperation handle the closing // if the user closed the window without selecting a button // (newValue = null in that case). If the user chose the "Yes" // button then do the import. Otherwise, close the dialog. if (dialog.isVisible() && event.getSource() == pane &&
(event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) &&
event.getNewValue() != null &&
event.getNewValue() != JOptionPane.UNINITIALIZED_VALUE) { if (Integer.valueOf(JOptionPane.YES_OPTION).equals(pane.getValue())) { // IOException from CopyFiles constructor created this error dialog // most probably because netbeans.import could not be located, // so discard the error dialog, stop the importing task and return if(pane.getMessageType() == JOptionPane.ERROR_MESSAGE) {
dialog.setVisible(false);
task.done(); return;
}
((JButton) pane.getOptions()[0]).setEnabled(false);
((JButton) pane.getOptions()[1]).setEnabled(false);
progressBar.setVisible(true);
task = new OptionsImportingTask(dialog);
task.execute();
} else {
dialog.setVisible(false);
}
}
}
}); return dialog;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.