+ public void setDialog(JDialog d)
+ {
+ dialog = d;
+ }
+
+ public JDialog getDialog()
+ {
+ return dialog;
+ }
+
+ /**
+ * 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)
+ {
+ return showDialogOnTop(null, label, actionString, JOPTIONPANE_OPTION,
+ JOPTIONPANE_MESSAGETYPE);
+ }
+
+ public static int showDialogOnTop(Component dialogParentComponent,
+ String label, String actionString, int JOPTIONPANE_OPTION,
+ int JOPTIONPANE_MESSAGETYPE)
+ {
+ if (!isInteractiveMode())
+ {
+ return (int) getMockResponse();
+ }
+ // Ensure Jalview window is brought to front (primarily for Quit
+ // confirmation window to be visible)
+
+ // This method of raising the Jalview window is broken in java
+ // jalviewDesktop.setVisible(true);
+ // jalviewDesktop.toFront();
+
+ // A better hack which works is to create a new JFrame parent with
+ // setAlwaysOnTop(true)
+ JFrame dialogParent = new JFrame();
+ if (dialogParentComponent == null)
+ {
+ dialogParent.setIconImages(ChannelProperties.getIconList());
+ dialogParent.setAlwaysOnTop(true);
+ }
+
+ int answer = JOptionPane.showConfirmDialog(
+ dialogParentComponent == null ? dialogParent
+ : dialogParentComponent,
+ label, actionString, JOPTIONPANE_OPTION,
+ JOPTIONPANE_MESSAGETYPE);
+
+ if (dialogParentComponent == null)
+ {
+ 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)
+ {
+ JFrame frame = new JFrame();
+ frame.setIconImages(ChannelProperties.getIconList());
+ 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, JButton[] buttons)
+ {
+ showDialogOnTopAsync(dialogParent, label, actionString,
+ JOPTIONPANE_OPTION, JOPTIONPANE_MESSAGETYPE, icon, options,
+ initialValue, modal, buttons, true);
+ }
+
+ 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,
+ boolean dispose)
+ {
+ if (!isInteractiveMode())
+ {
+ handleResponse(getMockResponse());
+ return;
+ }
+ // Ensure Jalview window is brought to front (primarily for Quit
+ // confirmation window to be visible)
+
+ // This method of raising the Jalview window is broken in java
+ // jalviewDesktop.setVisible(true);
+ // jalviewDesktop.toFront();
+
+ // A better hack which works is to create a new JFrame parent with
+ // setAlwaysOnTop(true)
+ dialogParent.setAlwaysOnTop(true);
+ parentComponent = dialogParent;
+
+ showDialog(label, actionString, JOPTIONPANE_OPTION,
+ JOPTIONPANE_MESSAGETYPE, icon, options, initialValue, modal,
+ buttons);
+
+ if (dispose)
+ {
+ dialogParent.setAlwaysOnTop(false);
+ dialogParent.dispose();
+ }
+ }
+