package jalview.gui;
+import jalview.util.dialogrunner.DialogRunner;
+import jalview.util.dialogrunner.DialogRunnerI;
+import jalview.util.dialogrunner.RunResponse;
+
import java.awt.Component;
import java.awt.HeadlessException;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.Arrays;
+import java.util.List;
import javax.swing.Icon;
import javax.swing.JOptionPane;
public class JvOptionPane extends JOptionPane
+ implements DialogRunnerI, PropertyChangeListener
{
// BH 2018 no changes needed here.
private static boolean interactiveMode = true;
+ private Component parentComponent;
+
+ public JvOptionPane(final Component parentComponent)
+ {
+
+ this.parentComponent = parentComponent;
+ }
+
public static int showConfirmDialog(Component parentComponent,
Object message) throws HeadlessException
{
throws HeadlessException
{
if (!isInteractiveMode())
+ {
return (int) getMockResponse();
+ }
switch (optionType)
{
case JvOptionPane.YES_NO_CANCEL_OPTION:
String message, String title, int optionType)
{
if (!isInteractiveMode())
+ {
return (int) getMockResponse();
+ }
switch (optionType)
{
case JvOptionPane.YES_NO_CANCEL_OPTION:
Object message, String title, int optionType, int messageType)
{
if (!isInteractiveMode())
+ {
return (int) getMockResponse();
+ }
switch (optionType)
{
case JvOptionPane.YES_NO_CANCEL_OPTION:
Icon icon)
{
if (!isInteractiveMode())
+ {
return (int) getMockResponse();
+ }
switch (optionType)
{
case JvOptionPane.YES_NO_CANCEL_OPTION:
throws HeadlessException
{
if (!isInteractiveMode())
+ {
return (int) getMockResponse();
+ }
// two uses:
//
// TODO
return prefix;
}
+ DialogRunner<JvOptionPane> runner = new DialogRunner(this);
+
+ private List<Object> ourOptions;
+ /**
+ * create a new option dialog that can be used to register responses - along
+ * lines of showOptionDialog
+ *
+ * @param desktop
+ * @param question
+ * @param string
+ * @param defaultOption
+ * @param plainMessage
+ * @param object
+ * @param options
+ * @param string2
+ * @return
+ */
+ 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)
+ {
+
+ if (!isInteractiveMode())
+ {
+ runner.firstRun((int) getMockResponse());
+ }
+ // two uses:
+ //
+ // TODO
+ //
+ // 1) AlignViewport for openLinkedAlignment
+ //
+ // Show a dialog with the option to open and link (cDNA <-> protein) as a
+ // new
+ // alignment, either as a standalone alignment or in a split frame. Returns
+ // true if the new alignment was opened, false if not, because the user
+ // declined the offer.
+ //
+ // 2) UserDefinedColors warning about saving over a name already defined
+ //
+ Component parent;
+ /**
+ * @j2sNative
+ * parent = this;
+ */
+ {
+ parent = parentComponent;
+ }
+ ;
+ ourOptions = Arrays.asList(options);
+ int response = JOptionPane.showOptionDialog(parent, message, title,
+ optionType, messageType, icon, options, initialValue);
+ /**
+ * @j2sNative
+ */
+ {
+ runner.firstRun(response);
+ }
+
+ }
+
+ @Override
+ public JvOptionPane response(RunResponse action)
+ {
+
+ runner.response(action);
+ return this;
+ }
+
+ public JvOptionPane defaultResponse(Runnable runnable)
+ {
+ runner.setDefaultResponse(runnable);
+ return this;
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ int ourOption = ourOptions.indexOf(evt.getNewValue());
+ if (ourOption == -1)
+ {
+ // try our luck..
+ runner.run(evt.getNewValue());
+ }
+ else
+ {
+ runner.run(ourOption);
+ }
+ }
+
}