String[] options = {"OK", "Cancel"};
int opt = JOptionPane.showOptionDialog(this, styleBox,
"Style Editor", JOptionPane.DEFAULT_OPTION,
JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
if (opt == 0) { // "OK" pressed
String name = styleBox.getStyleName();
// Only do anything if the user named the style
if (name != null) {
// See if the style already exists, in which case this
// is a change, not a creation
Style oldStyle = doc.getStyle(name);
if (oldStyle != null) {
// Redefine the Style and tell our document to
// repaint all Elements using this Style
styleBox.fillStyle(oldStyle);
doc.styleUpdated(oldStyle);
}
else {
// A new style has been specified. We'll add it to the document . . .
Style newStyle = doc.addStyle(name, null);
// Now fill the style with the values entered in the dialog
styleBox.fillStyle(newStyle);
// Add this Style so we can use it
addStyleToMenus(newStyle);
}
}
}
styleBox.clear();