import jalview.util.Platform;
import jalview.util.dialogrunner.DialogRunnerI;
-public class JvOptionPane extends JOptionPane implements DialogRunnerI, PropertyChangeListener {
+public class JvOptionPane extends JOptionPane
+ implements DialogRunnerI, PropertyChangeListener
+{
private static final long serialVersionUID = -3019167117756785229L;
private static Object mockResponse = JvOptionPane.CANCEL_OPTION;
*/
List<Object> ourOptions;
- public JvOptionPane(final Component parent) {
+ public JvOptionPane(final Component parent)
+ {
this.parentComponent = Platform.isJS() ? this : parent;
}
- public static int showConfirmDialog(Component parentComponent, Object message) throws HeadlessException {
+ public static int showConfirmDialog(Component parentComponent,
+ Object message) throws HeadlessException
+ {
// only called by test
- return isInteractiveMode() ? JOptionPane.showConfirmDialog(parentComponent, message) : (int) getMockResponse();
+ return isInteractiveMode()
+ ? JOptionPane.showConfirmDialog(parentComponent, message)
+ : (int) getMockResponse();
}
/**
* @return
* @throws HeadlessException
*/
- public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType)
- throws HeadlessException {
- if (!isInteractiveMode()) {
+ public static int showConfirmDialog(Component parentComponent,
+ Object message, String title, int optionType)
+ throws HeadlessException
+ {
+ if (!isInteractiveMode())
+ {
return (int) getMockResponse();
}
- switch (optionType) {
+ switch (optionType)
+ {
case JvOptionPane.YES_NO_CANCEL_OPTION:
// FeatureRenderer amendFeatures ?? TODO ??
// Chimera close
// $FALL-THROUGH$
case JvOptionPane.OK_CANCEL_OPTION:
// will fall back to simple HTML
- return JOptionPane.showConfirmDialog(parentComponent, message, title, optionType);
+ return JOptionPane.showConfirmDialog(parentComponent, message, title,
+ optionType);
}
}
* @return
* @throws HeadlessException
*/
- public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType,
- int messageType) throws HeadlessException {
+ public static int showConfirmDialog(Component parentComponent,
+ Object message, String title, int optionType, int messageType)
+ throws HeadlessException
+ {
// JalviewServicesChanged
// PromptUserConfig raiseDialog
- return isInteractiveMode() ? JOptionPane.showConfirmDialog(parentComponent, message, title, optionType, messageType)
- : (int) getMockResponse();
+ return isInteractiveMode()
+ ? JOptionPane.showConfirmDialog(parentComponent, message, title,
+ optionType, messageType)
+ : (int) getMockResponse();
}
/**
* @return
* @throws HeadlessException
*/
- public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType,
- int messageType, Icon icon) throws HeadlessException {
+ public static int showConfirmDialog(Component parentComponent,
+ Object message, String title, int optionType, int messageType,
+ Icon icon) throws HeadlessException
+ {
// JvOptionPaneTest only
return isInteractiveMode()
- ? JOptionPane.showConfirmDialog(parentComponent, message, title, optionType, messageType, icon)
- : (int) getMockResponse();
+ ? JOptionPane.showConfirmDialog(parentComponent, message, title,
+ optionType, messageType, icon)
+ : (int) getMockResponse();
}
/**
* @param message
* @return
*/
- public static int showInternalConfirmDialog(Component parentComponent, Object message) {
+ public static int showInternalConfirmDialog(Component parentComponent,
+ Object message)
+ {
// JvOptionPaneTest only;
- return isInteractiveMode() ? JOptionPane.showInternalConfirmDialog(parentComponent, message)
- : (int) getMockResponse();
+ return isInteractiveMode()
+ ? JOptionPane.showInternalConfirmDialog(parentComponent,
+ message)
+ : (int) getMockResponse();
}
/**
* @param optionType
* @return
*/
- public static int showInternalConfirmDialog(Component parentComponent, String message, String title, int optionType) {
- if (!isInteractiveMode()) {
+ public static int showInternalConfirmDialog(Component parentComponent,
+ String message, String title, int optionType)
+ {
+ if (!isInteractiveMode())
+ {
return (int) getMockResponse();
}
- switch (optionType) {
+ switch (optionType)
+ {
case JvOptionPane.YES_NO_CANCEL_OPTION:
// ColourMenuHelper.addMenuItmers.offerRemoval TODO
case JvOptionPane.YES_NO_OPTION:
// Desktop.inputURLMenuItem
// WsPreferenses
- return JOptionPane.showConfirmDialog(parentComponent, message, title, optionType);
+ return JOptionPane.showConfirmDialog(parentComponent, message, title,
+ optionType);
}
}
* @param messageType
* @return
*/
- public static int showInternalConfirmDialog(Component parentComponent, Object message, String title, int optionType,
- int messageType) {
- if (!isInteractiveMode()) {
+ public static int showInternalConfirmDialog(Component parentComponent,
+ Object message, String title, int optionType, int messageType)
+ {
+ if (!isInteractiveMode())
+ {
return (int) getMockResponse();
}
- switch (optionType) {
+ switch (optionType)
+ {
case JvOptionPane.YES_NO_CANCEL_OPTION:
case JvOptionPane.YES_NO_OPTION:
// UserQuestionanaireCheck
default:
case JvOptionPane.OK_CANCEL_OPTION:
// will fall back to simple HTML
- return JOptionPane.showConfirmDialog(parentComponent, message, title, optionType, messageType);
+ return JOptionPane.showConfirmDialog(parentComponent, message, title,
+ optionType, messageType);
}
}
* @param icon
* @return
*/
- public static int showInternalConfirmDialog(Component parentComponent, Object message, String title, int optionType,
- int messageType, Icon icon) {
- if (!isInteractiveMode()) {
+ public static int showInternalConfirmDialog(Component parentComponent,
+ Object message, String title, int optionType, int messageType,
+ Icon icon)
+ {
+ if (!isInteractiveMode())
+ {
return (int) getMockResponse();
}
- switch (optionType) {
+ switch (optionType)
+ {
case JvOptionPane.YES_NO_CANCEL_OPTION:
case JvOptionPane.YES_NO_OPTION:
//$FALL-THROUGH$
default:
case JvOptionPane.OK_CANCEL_OPTION:
// Preferences editLink/newLink
- return JOptionPane.showConfirmDialog(parentComponent, message, title, optionType, messageType, icon);
+ return JOptionPane.showConfirmDialog(parentComponent, message, title,
+ optionType, messageType, icon);
}
}
* @return
* @throws HeadlessException
*/
- public static int showOptionDialog(Component parentComponent, String message, String title, int optionType,
- int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException {
- if (!isInteractiveMode()) {
+ public static int showOptionDialog(Component parentComponent,
+ String message, String title, int optionType, int messageType,
+ Icon icon, Object[] options, Object initialValue)
+ throws HeadlessException
+ {
+ if (!isInteractiveMode())
+ {
return (int) getMockResponse();
}
// two uses:
//
// 2) UserDefinedColors warning about saving over a name already defined
//
- return JOptionPane.showOptionDialog(parentComponent, message, title, optionType, messageType, icon, options,
- initialValue);
+ return JOptionPane.showOptionDialog(parentComponent, message, title,
+ optionType, messageType, icon, options, initialValue);
}
/**
* @param message
* @throws HeadlessException
*/
- public static void showMessageDialog(Component parentComponent, String message) throws HeadlessException {
- if (!isInteractiveMode()) {
+ public static void showMessageDialog(Component parentComponent,
+ String message) throws HeadlessException
+ {
+ if (!isInteractiveMode())
+ {
outputMessage(message);
return;
}
* @param messageType
* @throws HeadlessException
*/
- public static void showMessageDialog(Component parentComponent, String message, String title, int messageType)
- throws HeadlessException {
+ public static void showMessageDialog(Component parentComponent,
+ String message, String title, int messageType)
+ throws HeadlessException
+ {
// 30 implementations -- all just fine.
- if (!isInteractiveMode()) {
+ if (!isInteractiveMode())
+ {
outputMessage(message);
return;
}
- JOptionPane.showMessageDialog(parentComponent, getPrefix(messageType) + message, title, messageType);
+ JOptionPane.showMessageDialog(parentComponent,
+ getPrefix(messageType) + message, title, messageType);
}
/**
* @param icon
* @throws HeadlessException
*/
- public static void showMessageDialog(Component parentComponent, String message, String title, int messageType,
- Icon icon) throws HeadlessException {
+ public static void showMessageDialog(Component parentComponent,
+ String message, String title, int messageType, Icon icon)
+ throws HeadlessException
+ {
// test only
- if (!isInteractiveMode()) {
+ if (!isInteractiveMode())
+ {
outputMessage(message);
return;
}
- JOptionPane.showMessageDialog(parentComponent, message, title, messageType, icon);
+ JOptionPane.showMessageDialog(parentComponent, message, title,
+ messageType, icon);
}
/**
* was internal
*
*/
- public static void showInternalMessageDialog(Component parentComponent, Object message) {
+ public static void showInternalMessageDialog(Component parentComponent,
+ Object message)
+ {
// WsPreferences only
- if (!isInteractiveMode()) {
+ if (!isInteractiveMode())
+ {
outputMessage(message);
return;
}
* @param title
* @param messageType
*/
- public static void showInternalMessageDialog(Component parentComponent, String message, String title,
- int messageType) {
+ public static void showInternalMessageDialog(Component parentComponent,
+ String message, String title, int messageType)
+ {
// 41 references
- if (!isInteractiveMode()) {
+ if (!isInteractiveMode())
+ {
outputMessage(message);
return;
}
- JOptionPane.showMessageDialog(parentComponent, getPrefix(messageType) + message, title, messageType);
+ JOptionPane.showMessageDialog(parentComponent,
+ getPrefix(messageType) + message, title, messageType);
}
/**
* @param messageType
* @param icon
*/
- public static void showInternalMessageDialog(Component parentComponent, Object message, String title, int messageType,
- Icon icon) {
+ public static void showInternalMessageDialog(Component parentComponent,
+ Object message, String title, int messageType, Icon icon)
+ {
// test only
- if (!isInteractiveMode()) {
+ if (!isInteractiveMode())
+ {
outputMessage(message);
return;
}
- JOptionPane.showMessageDialog(parentComponent, message, title, messageType, icon);
+ JOptionPane.showMessageDialog(parentComponent, message, title,
+ messageType, icon);
}
/**
* @return
* @throws HeadlessException
*/
- public static String showInputDialog(Object message) throws HeadlessException {
+ public static String showInputDialog(Object message)
+ throws HeadlessException
+ {
// test only
- if (!isInteractiveMode()) {
+ if (!isInteractiveMode())
+ {
return getMockResponse().toString();
}
* @param initialSelectionValue
* @return
*/
- public static String showInputDialog(String message, String initialSelectionValue) {
- if (!isInteractiveMode()) {
+ public static String showInputDialog(String message,
+ String initialSelectionValue)
+ {
+ if (!isInteractiveMode())
+ {
return getMockResponse().toString();
}
* @param initialSelectionValue
* @return
*/
- public static String showInputDialog(Object message, Object initialSelectionValue) {
- if (!isInteractiveMode()) {
+ public static String showInputDialog(Object message,
+ Object initialSelectionValue)
+ {
+ if (!isInteractiveMode())
+ {
return getMockResponse().toString();
}
* @return
* @throws HeadlessException
*/
- public static String showInputDialog(Component parentComponent, String message) throws HeadlessException {
+ public static String showInputDialog(Component parentComponent,
+ String message) throws HeadlessException
+ {
// test only
- return isInteractiveMode() ? JOptionPane.showInputDialog(parentComponent, message) : getMockResponse().toString();
+ return isInteractiveMode()
+ ? JOptionPane.showInputDialog(parentComponent, message)
+ : getMockResponse().toString();
}
/**
* @param initialSelectionValue
* @return
*/
- public static String showInputDialog(Component parentComponent, String message, String initialSelectionValue) {
+ public static String showInputDialog(Component parentComponent,
+ String message, String initialSelectionValue)
+ {
// AnnotationPanel
- return isInteractiveMode() ? JOptionPane.showInputDialog(parentComponent, message, initialSelectionValue)
- : getMockResponse().toString();
+ return isInteractiveMode()
+ ? JOptionPane.showInputDialog(parentComponent, message,
+ initialSelectionValue)
+ : getMockResponse().toString();
}
/**
* @param initialSelectionValue
* @return
*/
- public static String showInputDialog(Component parentComponent, Object message, Object initialSelectionValue) {
+ public static String showInputDialog(Component parentComponent,
+ Object message, Object initialSelectionValue)
+ {
// AnnotationPanel
- return isInteractiveMode() ? JOptionPane.showInputDialog(parentComponent, message, initialSelectionValue)
- : getMockResponse().toString();
+ return isInteractiveMode()
+ ? JOptionPane.showInputDialog(parentComponent, message,
+ initialSelectionValue)
+ : getMockResponse().toString();
}
/**
* @return
* @throws HeadlessException
*/
- public static String showInputDialog(Component parentComponent, String message, String title, int messageType)
- throws HeadlessException {
+ public static String showInputDialog(Component parentComponent,
+ String message, String title, int messageType)
+ throws HeadlessException
+ {
// test only
- return isInteractiveMode() ? JOptionPane.showInputDialog(parentComponent, message, title, messageType)
- : getMockResponse().toString();
+ return isInteractiveMode()
+ ? JOptionPane.showInputDialog(parentComponent, message, title,
+ messageType)
+ : getMockResponse().toString();
}
/**
* @return
* @throws HeadlessException
*/
- public static Object showInputDialog(Component parentComponent, Object message, String title, int messageType,
- Icon icon, Object[] selectionValues, Object initialSelectionValue) throws HeadlessException {
+ public static Object showInputDialog(Component parentComponent,
+ Object message, String title, int messageType, Icon icon,
+ Object[] selectionValues, Object initialSelectionValue)
+ throws HeadlessException
+ {
// test only
return isInteractiveMode()
- ? JOptionPane.showInputDialog(parentComponent, message, title, messageType, icon, selectionValues,
- initialSelectionValue)
- : getMockResponse().toString();
+ ? JOptionPane.showInputDialog(parentComponent, message, title,
+ messageType, icon, selectionValues,
+ initialSelectionValue)
+ : getMockResponse().toString();
}
/**
* @param message
* @return
*/
- public static String showInternalInputDialog(Component parentComponent, String message) {
+ public static String showInternalInputDialog(Component parentComponent,
+ String message)
+ {
// test only
- return isInteractiveMode() ? JOptionPane.showInternalInputDialog(parentComponent, message)
- : getMockResponse().toString();
+ return isInteractiveMode()
+ ? JOptionPane.showInternalInputDialog(parentComponent, message)
+ : getMockResponse().toString();
}
/**
* @param messageType
* @return
*/
- public static String showInternalInputDialog(Component parentComponent, String message, String title,
- int messageType) {
+ public static String showInternalInputDialog(Component parentComponent,
+ String message, String title, int messageType)
+ {
// AlignFrame tabbedPane_mousePressed
return isInteractiveMode()
- ? JOptionPane.showInternalInputDialog(parentComponent, getPrefix(messageType) + message, title, messageType)
- : getMockResponse().toString();
+ ? JOptionPane.showInternalInputDialog(parentComponent,
+ getPrefix(messageType) + message, title, messageType)
+ : getMockResponse().toString();
}
/**
* @param initialSelectionValue
* @return
*/
- public static Object showInternalInputDialog(Component parentComponent, String message, String title, int messageType,
- Icon icon, Object[] selectionValues, Object initialSelectionValue) {
+ public static Object showInternalInputDialog(Component parentComponent,
+ String message, String title, int messageType, Icon icon,
+ Object[] selectionValues, Object initialSelectionValue)
+ {
// test only
- return isInteractiveMode() ? JOptionPane.showInternalInputDialog(parentComponent, message, title, messageType, icon,
- selectionValues, initialSelectionValue) : getMockResponse().toString();
+ return isInteractiveMode()
+ ? JOptionPane.showInternalInputDialog(parentComponent, message,
+ title, messageType, icon, selectionValues,
+ initialSelectionValue)
+ : getMockResponse().toString();
}
///////////// end of options ///////////////
- private static void outputMessage(Object message) {
+ private static void outputMessage(Object message)
+ {
System.out.println(">>> JOption Message : " + message.toString());
}
- public static Object getMockResponse() {
+ public static Object getMockResponse()
+ {
return mockResponse;
}
- public static void setMockResponse(Object mockOption) {
+ public static void setMockResponse(Object mockOption)
+ {
JvOptionPane.mockResponse = mockOption;
}
- public static void resetMock() {
+ public static void resetMock()
+ {
setMockResponse(JvOptionPane.CANCEL_OPTION);
setInteractiveMode(true);
}
- public static boolean isInteractiveMode() {
+ public static boolean isInteractiveMode()
+ {
return interactiveMode;
}
- public static void setInteractiveMode(boolean interactive) {
+ public static void setInteractiveMode(boolean interactive)
+ {
JvOptionPane.interactiveMode = interactive;
}
- private static String getPrefix(int messageType) {
+ private static String getPrefix(int messageType)
+ {
String prefix = "";
// JavaScript only
- if (Platform.isJS()) {
- switch (messageType) {
+ if (Platform.isJS())
+ {
+ switch (messageType)
+ {
case JvOptionPane.WARNING_MESSAGE:
prefix = "WARNING! ";
break;
* @param string2
* @return
*/
- public static JvOptionPane newOptionDialog() {
+ public static JvOptionPane newOptionDialog()
+ {
return new JvOptionPane(null);
}
- public static JvOptionPane newOptionDialog(Component parentComponent) {
+ public static JvOptionPane newOptionDialog(Component parentComponent)
+ {
return new JvOptionPane(parentComponent);
}
- public void showDialog(String message, String title, int optionType, int messageType, Icon icon, Object[] options,
- Object initialValue) {
- showDialog(message, title, optionType, messageType, icon, options, initialValue, true);
+ public void showDialog(String message, String title, int optionType,
+ int messageType, Icon icon, Object[] options, Object initialValue)
+ {
+ showDialog(message, title, optionType, messageType, icon, options,
+ initialValue, true);
}
- public void showDialog(Object message, String title, int optionType, int messageType, Icon icon, Object[] options,
- Object initialValue, boolean modal) {
- showDialog(message, title, optionType, messageType, icon, options, initialValue, modal, null);
+ public void showDialog(Object message, String title, int optionType,
+ int messageType, Icon icon, Object[] options, Object initialValue,
+ boolean modal)
+ {
+ showDialog(message, title, optionType, messageType, icon, options,
+ initialValue, modal, null);
}
- public void showDialog(Object message, String title, int optionType, int messageType, Icon icon, Object[] options,
- Object initialValue, boolean modal, JButton[] buttons) {
- if (!isInteractiveMode()) {
+ public void showDialog(Object message, String title, int optionType,
+ int messageType, Icon icon, Object[] options, Object initialValue,
+ boolean modal, JButton[] buttons)
+ {
+ if (!isInteractiveMode())
+ {
handleResponse(getMockResponse());
}
// two uses:
ourOptions = Arrays.asList(options);
- if (modal) {
+ if (modal)
+ {
boolean useButtons = false;
Object initialValueButton = null;
- NOTNULL: if (buttons != null) {
- if (buttons.length != options.length) {
- jalview.bin.Console.error("Supplied buttons array not the same length as supplied options array.");
+ NOTNULL: if (buttons != null)
+ {
+ if (buttons.length != options.length)
+ {
+ jalview.bin.Console.error(
+ "Supplied buttons array not the same length as supplied options array.");
break NOTNULL;
}
- int[] buttonActions = { JOptionPane.YES_OPTION, JOptionPane.NO_OPTION, JOptionPane.CANCEL_OPTION };
- for (int i = 0; i < options.length; i++) {
+ int[] buttonActions = { JOptionPane.YES_OPTION,
+ JOptionPane.NO_OPTION, JOptionPane.CANCEL_OPTION };
+ for (int i = 0; i < options.length; i++)
+ {
Object o = options[i];
- jalview.bin.Console.debug("Setting button " + i + " to '" + o.toString() + "'");
+ jalview.bin.Console.debug(
+ "Setting button " + i + " to '" + o.toString() + "'");
JButton jb = buttons[i];
if (o.equals(initialValue))
int buttonAction = buttonActions[i];
Callable<Void> action = callbacks.get(buttonAction);
jb.setText((String) o);
- jb.addActionListener(new ActionListener() {
+ jb.addActionListener(new ActionListener()
+ {
@Override
- public void actionPerformed(ActionEvent e) {
+ public void actionPerformed(ActionEvent e)
+ {
Object obj = e.getSource();
- if (obj == null || !(obj instanceof Component)) {
- jalview.bin.Console.debug("Could not find Component source of event object " + obj);
+ if (obj == null || !(obj instanceof Component))
+ {
+ jalview.bin.Console.debug(
+ "Could not find Component source of event object "
+ + obj);
return;
}
- Object joptionpaneObject = SwingUtilities.getAncestorOfClass(JOptionPane.class, (Component) obj);
- if (joptionpaneObject == null || !(joptionpaneObject instanceof JOptionPane)) {
- jalview.bin.Console.debug("Could not find JOptionPane ancestor of event object " + obj);
+ Object joptionpaneObject = SwingUtilities.getAncestorOfClass(
+ JOptionPane.class, (Component) obj);
+ if (joptionpaneObject == null
+ || !(joptionpaneObject instanceof JOptionPane))
+ {
+ jalview.bin.Console.debug(
+ "Could not find JOptionPane ancestor of event object "
+ + obj);
return;
}
JOptionPane joptionpane = (JOptionPane) joptionpaneObject;
boolean raiseParent = (parentComponent != null);
if (buttonAction == JOptionPane.CANCEL_OPTION)
raiseParent = false;
- if (optionType == JOptionPane.YES_NO_OPTION && buttonAction == JOptionPane.NO_OPTION)
+ if (optionType == JOptionPane.YES_NO_OPTION
+ && buttonAction == JOptionPane.NO_OPTION)
raiseParent = false;
- if (raiseParent) {
+ if (raiseParent)
+ {
parentComponent.requestFocus();
- if (parentComponent instanceof JInternalFrame) {
+ if (parentComponent instanceof JInternalFrame)
+ {
JInternalFrame jif = (JInternalFrame) parentComponent;
jif.show();
jif.moveToFront();
jif.grabFocus();
- } else if (parentComponent instanceof Window) {
+ }
+ else if (parentComponent instanceof Window)
+ {
Window w = (Window) parentComponent;
w.toFront();
w.requestFocus();
useButtons = true;
}
// use a JOptionPane as usual
- int response = JOptionPane.showOptionDialog(parentComponent, message, title, optionType, messageType, icon,
- useButtons ? buttons : options, useButtons ? initialValueButton : initialValue);
+ int response = JOptionPane.showOptionDialog(parentComponent, message,
+ title, optionType, messageType, icon,
+ useButtons ? buttons : options,
+ useButtons ? initialValueButton : initialValue);
/*
* In Java, the response is returned to this thread and handled here; (for
{
handleResponse(response);
}
- } else {
+ }
+ else
+ {
/*
* This is java similar to the swingjs handling, with the callbacks attached to
* the button press of the dialog. This means we can use a non-modal JDialog for
*/
JOptionPane joptionpane = new JOptionPane();
// Make button options
- int[] buttonActions = { JvOptionPane.YES_OPTION, JvOptionPane.NO_OPTION, JvOptionPane.CANCEL_OPTION };
+ int[] buttonActions = { JvOptionPane.YES_OPTION,
+ JvOptionPane.NO_OPTION, JvOptionPane.CANCEL_OPTION };
// we need the strings to make the buttons with actionEventListener
- if (options == null) {
+ if (options == null)
+ {
ArrayList<String> options_default = new ArrayList<>();
- options_default.add(UIManager.getString("OptionPane.yesButtonText"));
- if (optionType == JvOptionPane.YES_NO_OPTION || optionType == JvOptionPane.YES_NO_CANCEL_OPTION) {
- options_default.add(UIManager.getString("OptionPane.noButtonText"));
+ options_default
+ .add(UIManager.getString("OptionPane.yesButtonText"));
+ if (optionType == JvOptionPane.YES_NO_OPTION
+ || optionType == JvOptionPane.YES_NO_CANCEL_OPTION)
+ {
+ options_default
+ .add(UIManager.getString("OptionPane.noButtonText"));
}
- if (optionType == JvOptionPane.YES_NO_CANCEL_OPTION) {
- options_default.add(UIManager.getString("OptionPane.cancelButtonText"));
+ if (optionType == JvOptionPane.YES_NO_CANCEL_OPTION)
+ {
+ options_default
+ .add(UIManager.getString("OptionPane.cancelButtonText"));
}
options = options_default.toArray();
}
ArrayList<JButton> options_btns = new ArrayList<>();
Object initialValue_btn = null;
- if (!Platform.isJS()) // JalviewJS already uses callback, don't need to add them here
+ if (!Platform.isJS()) // JalviewJS already uses callback, don't need to
+ // add them here
{
- for (int i = 0; i < options.length && i < 3; i++) {
+ for (int i = 0; i < options.length && i < 3; i++)
+ {
Object o = options[i];
int buttonAction = buttonActions[i];
Callable<Void> action = callbacks.get(buttonAction);
JButton jb = new JButton();
jb.setText((String) o);
- jb.addActionListener(new ActionListener() {
+ jb.addActionListener(new ActionListener()
+ {
@Override
- public void actionPerformed(ActionEvent e) {
+ public void actionPerformed(ActionEvent e)
+ {
joptionpane.setValue(buttonAction);
if (action != null)
Executors.newSingleThreadExecutor().submit(action);
boolean raiseParent = (parentComponent != null);
if (buttonAction == JvOptionPane.CANCEL_OPTION)
raiseParent = false;
- if (optionType == JvOptionPane.YES_NO_OPTION && buttonAction == JvOptionPane.NO_OPTION)
+ if (optionType == JvOptionPane.YES_NO_OPTION
+ && buttonAction == JvOptionPane.NO_OPTION)
raiseParent = false;
- if (raiseParent) {
+ if (raiseParent)
+ {
parentComponent.requestFocus();
- if (parentComponent instanceof JInternalFrame) {
+ if (parentComponent instanceof JInternalFrame)
+ {
JInternalFrame jif = (JInternalFrame) parentComponent;
jif.show();
jif.moveToFront();
jif.grabFocus();
- } else if (parentComponent instanceof Window) {
+ }
+ else if (parentComponent instanceof Window)
+ {
Window w = (Window) parentComponent;
w.toFront();
w.requestFocus();
joptionpane.setMessageType(messageType);
joptionpane.setOptionType(optionType);
joptionpane.setIcon(icon);
- joptionpane.setOptions(Platform.isJS() ? options : options_btns.toArray());
- joptionpane.setInitialValue(Platform.isJS() ? initialValue : initialValue_btn);
+ joptionpane.setOptions(
+ Platform.isJS() ? options : options_btns.toArray());
+ joptionpane.setInitialValue(
+ Platform.isJS() ? initialValue : initialValue_btn);
JDialog dialog = joptionpane.createDialog(parentComponent, title);
dialog.setIconImage(WindowIcons.logoIcon.getImage());
- dialog.setModalityType(modal ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS);
+ dialog.setModalityType(modal ? ModalityType.APPLICATION_MODAL
+ : ModalityType.MODELESS);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
}
}
- public void showInternalDialog(JPanel mainPanel, String title, int yesNoCancelOption, int questionMessage, Icon icon,
- Object[] options, String initresponse) {
- if (!isInteractiveMode()) {
+ public void showInternalDialog(JPanel mainPanel, String title,
+ int yesNoCancelOption, int questionMessage, Icon icon,
+ Object[] options, String initresponse)
+ {
+ if (!isInteractiveMode())
+ {
handleResponse(getMockResponse());
}
ourOptions = Arrays.asList(options);
int response;
- if (parentComponent != this) {
+ if (parentComponent != this)
+ {
JInternalFrame jif = this.createInternalFrame(parentComponent, title);
jif.setFrameIcon(WindowIcons.logoIcon);
- jif.addInternalFrameListener(new InternalFrameListener() {
+ jif.addInternalFrameListener(new InternalFrameListener()
+ {
@Override
- public void internalFrameActivated(InternalFrameEvent arg0) {
+ public void internalFrameActivated(InternalFrameEvent arg0)
+ {
}
@Override
- public void internalFrameClosed(InternalFrameEvent arg0) {
+ public void internalFrameClosed(InternalFrameEvent arg0)
+ {
JvOptionPane.this.internalDialogHandleResponse();
}
@Override
- public void internalFrameClosing(InternalFrameEvent arg0) {
+ public void internalFrameClosing(InternalFrameEvent arg0)
+ {
}
@Override
- public void internalFrameDeactivated(InternalFrameEvent arg0) {
+ public void internalFrameDeactivated(InternalFrameEvent arg0)
+ {
}
@Override
- public void internalFrameDeiconified(InternalFrameEvent arg0) {
+ public void internalFrameDeiconified(InternalFrameEvent arg0)
+ {
}
@Override
- public void internalFrameIconified(InternalFrameEvent arg0) {
+ public void internalFrameIconified(InternalFrameEvent arg0)
+ {
}
@Override
- public void internalFrameOpened(InternalFrameEvent arg0) {
+ public void internalFrameOpened(InternalFrameEvent arg0)
+ {
}
});
jif.setVisible(true);
startModal(jif);
return;
- } else {
+ }
+ else
+ {
JDialog dialog = this.createDialog(parentComponent, title);
dialog.setIconImage(WindowIcons.logoIcon.getImage());
dialog.setVisible(true); // blocking
}
}
- private void internalDialogHandleResponse() {
+ private void internalDialogHandleResponse()
+ {
String responseString = (String) this.getValue();
int response = ourOptions.indexOf(responseString);
* }
*/
@Override
- public JvOptionPane setResponseHandler(Object response, Callable<Void> action) {
+ public JvOptionPane setResponseHandler(Object response,
+ Callable<Void> action)
+ {
callbacks.put(response, action);
return this;
}
* showDialogOnTop will create a dialog that (attempts to) come to top of OS
* desktop windows
*/
- public static int showDialogOnTop(String label, String actionString, int JOPTIONPANE_OPTION,
- int JOPTIONPANE_MESSAGETYPE) {
+ public static int showDialogOnTop(String label, String actionString,
+ int JOPTIONPANE_OPTION, int JOPTIONPANE_MESSAGETYPE)
+ {
// Ensure Jalview window is brought to front (primarily for Quit
// confirmation window to be visible)
dialogParent.setIconImage(WindowIcons.logoIcon.getImage());
dialogParent.setAlwaysOnTop(true);
- int answer = JOptionPane.showConfirmDialog(dialogParent, label, actionString, JOPTIONPANE_OPTION,
- JOPTIONPANE_MESSAGETYPE);
+ int answer = JOptionPane.showConfirmDialog(dialogParent, label,
+ actionString, JOPTIONPANE_OPTION, JOPTIONPANE_MESSAGETYPE);
dialogParent.setAlwaysOnTop(false);
dialogParent.dispose();
return answer;
}
- public void showDialogOnTopAsync(String label, String actionString, int JOPTIONPANE_OPTION,
- int JOPTIONPANE_MESSAGETYPE, Icon icon, Object[] options, Object initialValue, boolean modal) {
+ public void showDialogOnTopAsync(String label, String actionString,
+ int JOPTIONPANE_OPTION, int JOPTIONPANE_MESSAGETYPE, Icon icon,
+ Object[] options, Object initialValue, boolean modal)
+ {
JFrame frame = new JFrame();
frame.setIconImage(WindowIcons.logoIcon.getImage());
- showDialogOnTopAsync(frame, label, actionString, JOPTIONPANE_OPTION, JOPTIONPANE_MESSAGETYPE, icon, options,
- initialValue, modal);
+ showDialogOnTopAsync(frame, label, actionString, JOPTIONPANE_OPTION,
+ JOPTIONPANE_MESSAGETYPE, icon, options, initialValue, modal);
}
- public void showDialogOnTopAsync(JFrame dialogParent, Object label, String actionString, int JOPTIONPANE_OPTION,
- int JOPTIONPANE_MESSAGETYPE, Icon icon, Object[] options, Object initialValue, boolean modal) {
- showDialogOnTopAsync(dialogParent, label, actionString, JOPTIONPANE_OPTION, JOPTIONPANE_MESSAGETYPE, icon, options,
- initialValue, modal, null);
+ public void showDialogOnTopAsync(JFrame dialogParent, Object label,
+ String actionString, int JOPTIONPANE_OPTION,
+ int JOPTIONPANE_MESSAGETYPE, Icon icon, Object[] options,
+ Object initialValue, boolean modal)
+ {
+ showDialogOnTopAsync(dialogParent, label, actionString,
+ JOPTIONPANE_OPTION, JOPTIONPANE_MESSAGETYPE, icon, options,
+ initialValue, modal, null);
}
- public void showDialogOnTopAsync(JFrame dialogParent, Object label, String actionString, int JOPTIONPANE_OPTION,
- int JOPTIONPANE_MESSAGETYPE, Icon icon, Object[] options, Object initialValue, boolean modal, JButton[] buttons) {
+ public void showDialogOnTopAsync(JFrame dialogParent, Object label,
+ String actionString, int JOPTIONPANE_OPTION,
+ int JOPTIONPANE_MESSAGETYPE, Icon icon, Object[] options,
+ Object initialValue, boolean modal, JButton[] buttons)
+ {
// Ensure Jalview window is brought to front (primarily for Quit
// confirmation window to be visible)
dialogParent.setAlwaysOnTop(true);
parentComponent = dialogParent;
- showDialog(label, actionString, JOPTIONPANE_OPTION, JOPTIONPANE_MESSAGETYPE, icon, options, initialValue, modal,
- buttons);
+ showDialog(label, actionString, JOPTIONPANE_OPTION,
+ JOPTIONPANE_MESSAGETYPE, icon, options, initialValue, modal,
+ buttons);
dialogParent.setAlwaysOnTop(false);
dialogParent.dispose();
}
/**
- * JalviewJS signals option selection by a property change event for the option
- * e.g. "OK". This methods responds to that by running the response action that
- * corresponds to that option.
+ * JalviewJS signals option selection by a property change event for the
+ * option e.g. "OK". This methods responds to that by running the response
+ * action that corresponds to that option.
*
* @param evt
*/
@Override
- public void propertyChange(PropertyChangeEvent evt) {
+ public void propertyChange(PropertyChangeEvent evt)
+ {
Object newValue = evt.getNewValue();
int ourOption = ourOptions.indexOf(newValue);
- if (ourOption >= 0) {
+ if (ourOption >= 0)
+ {
handleResponse(ourOption);
- } else {
+ }
+ else
+ {
// try our luck..
handleResponse(newValue);
}
}
@Override
- public void handleResponse(Object response) {
+ public void handleResponse(Object response)
+ {
/*
* this test is for NaN in Chrome
*/
- if (response != null && !response.equals(response)) {
+ if (response != null && !response.equals(response))
+ {
return;
}
Callable<Void> action = callbacks.get(response);
- if (action != null) {
- try {
+ if (action != null)
+ {
+ try
+ {
action.call();
- } catch (Exception e) {
+ } catch (Exception e)
+ {
e.printStackTrace();
}
if (parentComponent != null)
/**
* Create a non-modal confirm dialog
*/
- public JDialog createDialog(Component parentComponent, Object message, String title, int optionType, int messageType,
- Icon icon, Object[] options, Object initialValue, boolean modal) {
- return createDialog(parentComponent, message, title, optionType, messageType, icon, options, initialValue, modal,
- null);
+ public JDialog createDialog(Component parentComponent, Object message,
+ String title, int optionType, int messageType, Icon icon,
+ Object[] options, Object initialValue, boolean modal)
+ {
+ return createDialog(parentComponent, message, title, optionType,
+ messageType, icon, options, initialValue, modal, null);
}
- public JDialog createDialog(Component parentComponent, Object message, String title, int optionType, int messageType,
- Icon icon, Object[] options, Object initialValue, boolean modal, JButton[] buttons) {
+ public JDialog createDialog(Component parentComponent, Object message,
+ String title, int optionType, int messageType, Icon icon,
+ Object[] options, Object initialValue, boolean modal,
+ JButton[] buttons)
+ {
JButton[] optionsButtons = null;
Object initialValueButton = null;
JOptionPane joptionpane = new JOptionPane();
// Make button options
- int[] buttonActions = { JOptionPane.YES_OPTION, JOptionPane.NO_OPTION, JOptionPane.CANCEL_OPTION };
+ int[] buttonActions = { JOptionPane.YES_OPTION, JOptionPane.NO_OPTION,
+ JOptionPane.CANCEL_OPTION };
// we need the strings to make the buttons with actionEventListener
- if (options == null) {
+ if (options == null)
+ {
ArrayList<String> options_default = new ArrayList<>();
options_default.add(UIManager.getString("OptionPane.yesButtonText"));
- if (optionType == JOptionPane.YES_NO_OPTION || optionType == JOptionPane.YES_NO_CANCEL_OPTION) {
+ if (optionType == JOptionPane.YES_NO_OPTION
+ || optionType == JOptionPane.YES_NO_CANCEL_OPTION)
+ {
options_default.add(UIManager.getString("OptionPane.noButtonText"));
}
- if (optionType == JOptionPane.YES_NO_CANCEL_OPTION) {
- options_default.add(UIManager.getString("OptionPane.cancelButtonText"));
+ if (optionType == JOptionPane.YES_NO_CANCEL_OPTION)
+ {
+ options_default
+ .add(UIManager.getString("OptionPane.cancelButtonText"));
}
options = options_default.toArray();
}
if (!Platform.isJS()) // JalviewJS already uses callback, don't need to
// add them here
{
- if (((optionType == JOptionPane.YES_OPTION || optionType == JOptionPane.NO_OPTION
- || optionType == JOptionPane.CANCEL_OPTION || optionType == JOptionPane.OK_OPTION
- || optionType == JOptionPane.DEFAULT_OPTION) && options.length < 1)
- || ((optionType == JOptionPane.YES_NO_OPTION || optionType == JOptionPane.OK_CANCEL_OPTION)
- && options.length < 2)
- || (optionType == JOptionPane.YES_NO_CANCEL_OPTION && options.length < 3)) {
- jalview.bin.Console.debug("JvOptionPane: not enough options for dialog type");
+ if (((optionType == JOptionPane.YES_OPTION
+ || optionType == JOptionPane.NO_OPTION
+ || optionType == JOptionPane.CANCEL_OPTION
+ || optionType == JOptionPane.OK_OPTION
+ || optionType == JOptionPane.DEFAULT_OPTION)
+ && options.length < 1)
+ || ((optionType == JOptionPane.YES_NO_OPTION
+ || optionType == JOptionPane.OK_CANCEL_OPTION)
+ && options.length < 2)
+ || (optionType == JOptionPane.YES_NO_CANCEL_OPTION
+ && options.length < 3))
+ {
+ jalview.bin.Console
+ .debug("JvOptionPane: not enough options for dialog type");
}
optionsButtons = new JButton[options.length];
- for (int i = 0; i < options.length && i < 3; i++) {
+ for (int i = 0; i < options.length && i < 3; i++)
+ {
Object o = options[i];
int buttonAction = buttonActions[i];
Callable<Void> action = callbacks.get(buttonAction);
JButton jb;
- if (buttons != null && buttons.length > i && buttons[i] != null) {
+ if (buttons != null && buttons.length > i && buttons[i] != null)
+ {
jb = buttons[i];
- } else {
+ }
+ else
+ {
jb = new JButton();
}
jb.setText((String) o);
- jb.addActionListener(new ActionListener() {
+ jb.addActionListener(new ActionListener()
+ {
@Override
- public void actionPerformed(ActionEvent e) {
+ public void actionPerformed(ActionEvent e)
+ {
joptionpane.setValue(buttonAction);
if (action != null)
Executors.newSingleThreadExecutor().submit(action);
boolean raiseParent = (parentComponent != null);
if (buttonAction == JOptionPane.CANCEL_OPTION)
raiseParent = false;
- if (optionType == JOptionPane.YES_NO_OPTION && buttonAction == JOptionPane.NO_OPTION)
+ if (optionType == JOptionPane.YES_NO_OPTION
+ && buttonAction == JOptionPane.NO_OPTION)
raiseParent = false;
- if (raiseParent) {
+ if (raiseParent)
+ {
parentComponent.requestFocus();
- if (parentComponent instanceof JInternalFrame) {
+ if (parentComponent instanceof JInternalFrame)
+ {
JInternalFrame jif = (JInternalFrame) parentComponent;
jif.show();
jif.moveToFront();
jif.grabFocus();
- } else if (parentComponent instanceof Window) {
+ }
+ else if (parentComponent instanceof Window)
+ {
Window w = (Window) parentComponent;
w.toFront();
w.requestFocus();
joptionpane.setOptionType(optionType);
joptionpane.setIcon(icon);
joptionpane.setOptions(Platform.isJS() ? options : optionsButtons);
- joptionpane.setInitialValue(Platform.isJS() ? initialValue : initialValueButton);
+ joptionpane.setInitialValue(
+ Platform.isJS() ? initialValue : initialValueButton);
JDialog dialog = joptionpane.createDialog(parentComponent, title);
dialog.setIconImage(WindowIcons.logoIcon.getImage());
- dialog.setModalityType(modal ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS);
+ dialog.setModalityType(
+ modal ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
return dialog;
}
*
* returns true if button was found
*/
- public static boolean clickButton(JFrame frame, int buttonType) {
+ public static boolean clickButton(JFrame frame, int buttonType)
+ {
return false;
}
* the JInternalFrame and sizes it according to the JInternalFrame's preferred
* size.
*
- * @param f The JInternalFrame to make modal.
+ * @param f
+ * The JInternalFrame to make modal.
*/
- private static void startModal(JInternalFrame f) {
+ private static void startModal(JInternalFrame f)
+ {
// We need to add an additional glasspane-like component directly
// below the frame, which intercepts all mouse events that are not
// directed at the frame itself.
JLayeredPane lp = JLayeredPane.getLayeredPaneAbove(f);
lp.setLayer(modalInterceptor, JLayeredPane.MODAL_LAYER.intValue());
modalInterceptor.setBounds(0, 0, lp.getWidth(), lp.getHeight());
- modalInterceptor.addMouseListener(new MouseAdapter() {
+ modalInterceptor.addMouseListener(new MouseAdapter()
+ {
});
- modalInterceptor.addMouseMotionListener(new MouseMotionAdapter() {
+ modalInterceptor.addMouseMotionListener(new MouseMotionAdapter()
+ {
});
lp.add(modalInterceptor);
f.toFront();
// We need to explicitly dispatch events when we are blocking the event
// dispatch thread.
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
- try {
- while (!f.isClosed()) {
- if (EventQueue.isDispatchThread()) {
+ try
+ {
+ while (!f.isClosed())
+ {
+ if (EventQueue.isDispatchThread())
+ {
// The getNextEventMethod() issues wait() when no
// event is available, so we don't need do explicitly wait().
AWTEvent ev = queue.getNextEvent();
((MenuComponent) ev.getSource()).dispatchEvent(ev);
// Other events are ignored as per spec in
// EventQueue.dispatchEvent
- } else {
+ }
+ else
+ {
// Give other threads a chance to become active.
Thread.yield();
}
}
- } catch (InterruptedException ex) {
+ } catch (InterruptedException ex)
+ {
// If we get interrupted, then leave the modal state.
- } finally {
+ } finally
+ {
// Clean up the modal interceptor.
lp.remove(modalInterceptor);