Merge branch 'JAL-3048dialogRunner2' into Jalview-BH/JAL-3026-JAL-3063-JAXB
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 18 Dec 2018 17:58:39 +0000 (17:58 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 18 Dec 2018 17:58:39 +0000 (17:58 +0000)
26 files changed:
resources/lang/Messages.properties
resources/lang/Messages_es.properties
src/jalview/gui/AlignExportOptions.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignViewport.java
src/jalview/gui/AnnotationLabels.java
src/jalview/gui/Desktop.java
src/jalview/gui/EditNameDialog.java
src/jalview/gui/FeatureEditor.java
src/jalview/gui/FeatureSettings.java
src/jalview/gui/ImageExporter.java
src/jalview/gui/JvOptionPane.java
src/jalview/gui/LineartOptions.java
src/jalview/gui/PopupMenu.java
src/jalview/gui/TextColourChooser.java
src/jalview/gui/UserDefinedColours.java
src/jalview/io/HtmlSvgOutput.java
src/jalview/io/JalviewFileChooser.java
src/jalview/util/dialogrunner/DialogRunner.java [deleted file]
src/jalview/util/dialogrunner/DialogRunnerI.java
src/jalview/util/dialogrunner/Response.java [deleted file]
src/jalview/util/dialogrunner/RunResponse.java [deleted file]
test/jalview/util/dialogrunner/DialogRunnerTest.java
test/jalview/util/dialogrunner/ResponseTest.java [deleted file]
test/jalview/util/dialogrunner/RunResponseTest.java [deleted file]
utils/test/JalviewJSTest.java

index b29edec..fde0b1c 100644 (file)
@@ -1019,7 +1019,7 @@ label.pca_recalculating = Recalculating PCA
 label.pca_calculating = Calculating PCA
 label.select_foreground_colour = Choose foreground colour
 label.select_colour_for_text = Select Colour for Text
-label.adjunst_foreground_text_colour_threshold = Adjust Foreground Text Colour Threshold
+label.adjust_foreground_text_colour_threshold = Adjust Foreground Text Colour Threshold
 label.select_subtree_colour = Select Sub-Tree Colour
 label.create_new_sequence_features = Create New Sequence Feature(s)
 label.amend_delete_features = Amend/Delete Features for {0}
index d1b763d..8b7fd0d 100644 (file)
@@ -944,7 +944,7 @@ label.pca_recalculating = Recalculando ACP
 label.pca_calculating = Calculando ACP
 label.select_foreground_colour = Escoger color del primer plano
 label.select_colour_for_text = Seleccione el color del texto
-label.adjunst_foreground_text_colour_threshold = Ajustar el umbral del color del texto en primer plano
+label.adjust_foreground_text_colour_threshold = Ajustar el umbral del color del texto en primer plano
 label.select_subtree_colour = Seleccioanr el color del sub-árbol
 label.create_new_sequence_features = Crear nueva(s) característica(s) de secuencia
 label.amend_delete_features = Arrelgar/Borrar características de {0}
index ecf89cc..70601c9 100644 (file)
@@ -24,7 +24,6 @@ import jalview.api.AlignExportSettingsI;
 import jalview.api.AlignViewportI;
 import jalview.io.FileFormatI;
 import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
 
 import java.awt.BorderLayout;
 import java.awt.FlowLayout;
@@ -120,9 +119,9 @@ public class AlignExportOptions extends JPanel
    * 
    * @param action
    */
-  public void setResponseAction(RunResponse action)
+  public void setResponseAction(Object response, Runnable action)
   {
-    dialog.addResponse(action);
+    dialog.setResponseHandler(response, action);
   }
 
   /**
index f2ff1d4..7183f7f 100644 (file)
@@ -89,7 +89,6 @@ import jalview.schemes.ResidueColourScheme;
 import jalview.schemes.TCoffeeColourScheme;
 import jalview.util.ImageMaker.TYPE;
 import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.viewmodel.ViewportRanges;
 import jalview.ws.DBRefFetcher;
@@ -1246,7 +1245,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
 
     AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
-    RunResponse cancelAction = new RunResponse(JvOptionPane.CANCEL_OPTION)
+    Runnable cancelAction = new Runnable()
     {
       @Override
       public void run()
@@ -1254,7 +1253,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         lastSaveSuccessful = false;
       }
     };
-    RunResponse outputAction = new RunResponse(JvOptionPane.OK_OPTION)
+    Runnable outputAction = new Runnable()
     {
       @Override
       public void run()
@@ -1299,8 +1298,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     {
       AlignExportOptions choices = new AlignExportOptions(
               alignPanel.getAlignViewport(), format, options);
-      choices.setResponseAction(outputAction);
-      choices.setResponseAction(cancelAction);
+      choices.setResponseAction(0, outputAction);
+      choices.setResponseAction(1, cancelAction);
       choices.showDialog();
     }
     else
@@ -1322,7 +1321,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     FileFormatI fileFormat = FileFormats.getInstance()
             .forName(fileFormatName);
     AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
-    RunResponse outputAction = new RunResponse(JvOptionPane.OK_OPTION)
+    Runnable outputAction = new Runnable()
     {
       @Override
       public void run()
@@ -1359,7 +1358,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     {
       AlignExportOptions choices = new AlignExportOptions(
               alignPanel.getAlignViewport(), fileFormat, options);
-      choices.setResponseAction(outputAction);
+      choices.setResponseAction(0, outputAction);
       choices.showDialog();
     }
     else
@@ -1472,9 +1471,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             MessageManager.getString("label.load_jalview_annotations"));
     chooser.setToolTipText(
             MessageManager.getString("label.load_jalview_annotations"));
-    chooser.addResponse(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+    chooser.setResponseHandler(0, new Runnable()
     {
-
       @Override
       public void run()
       {
@@ -1482,7 +1480,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
         loadJalviewDataFile(chooser.getSelectedFile(), null, null, null);
       }
-
     });
 
     chooser.showOpenDialog(this);
@@ -3966,8 +3963,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     chooser.setToolTipText(
             MessageManager.getString("label.load_tree_file"));
 
-    chooser.addResponse(new jalview.util.dialogrunner.RunResponse(
-            JalviewFileChooser.APPROVE_OPTION)
+    chooser.setResponseHandler(0,new Runnable()
     {
       @Override
       public void run()
@@ -3997,7 +3993,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                   JvOptionPane.WARNING_MESSAGE);
         }
       }
-    }).showOpenDialog(this);
+    });
+    chooser.showOpenDialog(this);
   }
 
   public TreePanel showNewickTree(NewickFile nf, String treeTitle)
@@ -5697,21 +5694,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     chooser.setDialogTitle(MessageManager.getString("label.load_vcf_file"));
     chooser.setToolTipText(MessageManager.getString("label.load_vcf_file"));
     final AlignFrame us = this;
-    chooser.addResponse(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+    chooser.setResponseHandler(0, new Runnable()
     {
       @Override
       public void run()
       {
-
-        {
-          String choice = chooser.getSelectedFile().getPath();
-          Cache.setProperty("LAST_DIRECTORY", choice);
-          SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
-          new VCFLoader(choice).loadVCF(seqs, us);
-        }
-
+        String choice = chooser.getSelectedFile().getPath();
+        Cache.setProperty("LAST_DIRECTORY", choice);
+        SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
+        new VCFLoader(choice).loadVCF(seqs, us);
       };
-    }).showOpenDialog(null);
+    });
+    chooser.showOpenDialog(null);
 
   }
 
index ee61308..62a3698 100644 (file)
@@ -48,7 +48,6 @@ import jalview.structure.SelectionSource;
 import jalview.structure.StructureSelectionManager;
 import jalview.structure.VamsasSource;
 import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.ws.params.AutoCalcSetting;
 
@@ -771,21 +770,21 @@ public class AlignViewport extends AlignmentViewport
      * in reverse order)
      */
     JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop)
-            .addResponse(new RunResponse(0)
+            .setResponseHandler(0, new Runnable()
             {
               @Override
               public void run()
               {
                   addDataToAlignment(al);
               }
-            }).addResponse(new RunResponse(1)
+            }).setResponseHandler(1, new Runnable()
             {
               @Override
               public void run()
               {
                 us.openLinkedAlignmentAs(al, title, true);
               }
-            }).addResponse(new RunResponse(2)
+            }).setResponseHandler(2, new Runnable()
             {
               @Override
               public void run()
index 294b8db..6ea4c57 100755 (executable)
@@ -34,7 +34,6 @@ import jalview.io.FormatAdapter;
 import jalview.util.Comparison;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
-import jalview.util.dialogrunner.RunResponse;
 
 import java.awt.Color;
 import java.awt.Cursor;
@@ -292,7 +291,7 @@ public class AnnotationLabels extends JPanel
             annotation.description, name, description);
 
     dialog.showDialog(ap.alignFrame, title,
-            new RunResponse(JvOptionPane.OK_OPTION)
+            new Runnable()
             {
               @Override
               public void run()
index 320ebc2..a927741 100644 (file)
@@ -46,7 +46,6 @@ import jalview.util.ImageMaker.TYPE;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.util.UrlConstants;
-import jalview.util.dialogrunner.RunResponse;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.ws.params.ParamManager;
 import jalview.ws.utils.UrlDownloadClient;
@@ -89,7 +88,6 @@ import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.ListIterator;
-import java.util.StringTokenizer;
 import java.util.Vector;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -1125,9 +1123,8 @@ public class Desktop extends jalview.jbgui.GDesktop
             MessageManager.getString("label.open_local_file"));
     chooser.setToolTipText(MessageManager.getString("action.open"));
 
-    chooser.addResponse(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+    chooser.setResponseHandler(0, new Runnable()
     {
-
       @Override
       public void run()
       {
@@ -1156,7 +1153,8 @@ public class Desktop extends jalview.jbgui.GDesktop
         new FileLoader().LoadFile(viewport, selectedFile,
                 DataSourceType.FILE, format);
       }
-    }).showOpenDialog(this);
+    });
+    chooser.showOpenDialog(this);
   }
 
   /**
@@ -1206,7 +1204,7 @@ public class Desktop extends jalview.jbgui.GDesktop
 
     Object[] options = new Object[] { MessageManager.getString("action.ok"),
         MessageManager.getString("action.cancel") };
-    RunResponse action = new RunResponse(JvOptionPane.OK_OPTION) {
+    Runnable action = new Runnable() {
       @Override
       public void run()
       {
@@ -1262,7 +1260,7 @@ public class Desktop extends jalview.jbgui.GDesktop
       }};
     String dialogOption = MessageManager
             .getString("label.input_alignment_from_url");
-    JvOptionPane.newOptionDialog(desktop).addResponse(action)
+    JvOptionPane.newOptionDialog(desktop).setResponseHandler(0, action)
             .showInternalDialog(panel, dialogOption,
                     JvOptionPane.YES_NO_CANCEL_OPTION,
                     JvOptionPane.PLAIN_MESSAGE, null, options,
@@ -1745,7 +1743,7 @@ public class Desktop extends jalview.jbgui.GDesktop
             "Jalview Project");
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager.getString("label.restore_state"));
-    chooser.addResponse(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
+    chooser.setResponseHandler(0, new Runnable()
     {
       @Override
       public void run()
index bbb7a20..8aaebc8 100644 (file)
@@ -21,7 +21,6 @@
 package jalview.gui;
 
 import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
 
 import java.awt.FlowLayout;
 import java.awt.Font;
@@ -107,18 +106,16 @@ public class EditNameDialog
   }
 
   /**
-   * Shows the dialog, and runs the response action if OK is selected. Note the
-   * RunResponse should be constructed to act on dialog return value
-   * JvOptionPane.OK_OPTION.
+   * Shows the dialog, and runs the response action if OK is selected
    * 
    * @param action
    */
   public void showDialog(JComponent parent, String title,
-          RunResponse action)
+                 Runnable action)
   {
     Object[] options = new Object[] { MessageManager.getString("action.ok"),
         MessageManager.getString("action.cancel") };
-    JvOptionPane.newOptionDialog(parent).addResponse(action)
+    JvOptionPane.newOptionDialog(parent).setResponseHandler(0, action)
             .showInternalDialog(panel, title,
                     JvOptionPane.YES_NO_CANCEL_OPTION,
                     JvOptionPane.PLAIN_MESSAGE, null, options,
index d75404a..d547c58 100644 (file)
@@ -10,7 +10,6 @@ import jalview.io.FeaturesFile;
 import jalview.schemes.FeatureColour;
 import jalview.util.ColorUtils;
 import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
@@ -406,18 +405,18 @@ public class FeatureEditor
    */
   public void showDialog()
   {
-    RunResponse okAction = forCreate ? getCreateAction() : getAmendAction();
-    RunResponse cancelAction = getCancelAction();
+         Runnable okAction = forCreate ? getCreateAction() : getAmendAction();
+         Runnable cancelAction = getCancelAction();
 
     /*
      * set dialog action handlers for OK (create/Amend) and Cancel options
      * also for Delete if applicable (when amending features)
      */
     JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop)
-            .addResponse(okAction).addResponse(cancelAction);
+            .setResponseHandler(0, okAction).setResponseHandler(2, cancelAction);
     if (!forCreate)
     {
-      dialog.addResponse(getDeleteAction());
+      dialog.setResponseHandler(1, getDeleteAction());
     }
 
     String title = null;
@@ -453,9 +452,9 @@ public class FeatureEditor
    * 
    * @return
    */
-  protected RunResponse getCancelAction()
+  protected Runnable getCancelAction()
   {
-    RunResponse okAction = new RunResponse(JvOptionPane.CANCEL_OPTION)
+       Runnable okAction = new Runnable()
     {
       @Override
       public void run()
@@ -477,9 +476,9 @@ public class FeatureEditor
    * 
    * @return
    */
-  protected RunResponse getCreateAction()
+  protected Runnable getCreateAction()
   {
-    RunResponse okAction = new RunResponse(JvOptionPane.OK_OPTION)
+       Runnable okAction = new Runnable()
     {
       boolean useLastDefaults = features.get(0).getType() == null;
 
@@ -535,9 +534,9 @@ public class FeatureEditor
    * 
    * @return
    */
-  protected RunResponse getDeleteAction()
+  protected Runnable getDeleteAction()
   {
-    RunResponse deleteAction = new RunResponse(JvOptionPane.NO_OPTION)
+         Runnable deleteAction = new Runnable()
     {
       public void run()
       {
@@ -637,9 +636,9 @@ public class FeatureEditor
    * 
    * @return
    */
-  protected RunResponse getAmendAction()
+  protected Runnable getAmendAction()
   {
-    RunResponse okAction = new RunResponse(JvOptionPane.OK_OPTION)
+       Runnable okAction = new Runnable()
     {
       boolean useLastDefaults = features.get(0).getType() == null;
   
index ea0d914..27676d5 100644 (file)
@@ -36,7 +36,6 @@ import jalview.io.JalviewFileView;
 import jalview.schemes.FeatureColour;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
-import jalview.util.dialogrunner.RunResponse;
 import jalview.viewmodel.seqfeatures.FeatureRendererModel.FeatureSettingsBean;
 import jalview.xml.binding.jalview.JalviewUserColours;
 import jalview.xml.binding.jalview.JalviewUserColours.Colour;
@@ -902,13 +901,15 @@ public class FeatureSettings extends JPanel
     chooser.setDialogTitle(
             MessageManager.getString("label.load_feature_colours"));
     chooser.setToolTipText(MessageManager.getString("action.load"));
-    chooser.addResponse(new RunResponse(JalviewFileChooser.APPROVE_OPTION){
-
-               @Override
-               public void run() {
-                     File file = chooser.getSelectedFile();
-                     load(file);
-               }});
+    chooser.setResponseHandler(0, new Runnable()
+    {
+         @Override
+         public void run() 
+         {
+           File file = chooser.getSelectedFile();
+               load(file);
+         }
+       });
     chooser.showOpenDialog(this);
   }
 
index 51d7d82..a43eef0 100644 (file)
@@ -7,15 +7,12 @@ import jalview.io.JalviewFileView;
 import jalview.util.ImageMaker;
 import jalview.util.ImageMaker.TYPE;
 import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
 
 import java.awt.Component;
 import java.awt.Graphics;
 import java.io.File;
 import java.util.concurrent.atomic.AtomicBoolean;
 
-import javax.swing.JOptionPane;
-
 /**
  * A class that marshals steps in exporting a view in image graphics format
  * <ul>
@@ -138,7 +135,7 @@ public class ImageExporter
             && !Jalview.isHeadlessMode())
     {
       final File chosenFile = file;
-      RunResponse okAction = new RunResponse(JOptionPane.OK_OPTION)
+      Runnable okAction = new Runnable()
       {
         @Override
         public void run()
@@ -149,7 +146,7 @@ public class ImageExporter
       };
       LineartOptions epsOption = new LineartOptions(TYPE.EPS.getName(),
               textSelected);
-      epsOption.setResponseAction(new RunResponse(JOptionPane.NO_OPTION)
+      epsOption.setResponseAction(1, new Runnable()
       {
         @Override
         public void run()
@@ -159,7 +156,7 @@ public class ImageExporter
                   imageType.getName()), messageId);
         }
       });
-      epsOption.setResponseAction(okAction);
+      epsOption.setResponseAction(0, okAction);
       epsOption.showDialog();
       /* no code here - JalviewJS cannot execute it */
     }
index a141e14..2290b52 100644 (file)
 
 package jalview.gui;
 
-import jalview.util.dialogrunner.DialogRunner;
+import jalview.bin.Jalview;
 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.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.swing.Icon;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 
-public class JvOptionPane extends JOptionPane
-        implements DialogRunnerI, PropertyChangeListener
+public class JvOptionPane extends JOptionPane implements DialogRunnerI,
+    PropertyChangeListener
 {
-  // BH 2018 no changes needed here.
-
   private static final long serialVersionUID = -3019167117756785229L;
 
   private static Object mockResponse = JvOptionPane.CANCEL_OPTION;
@@ -49,10 +48,17 @@ public class JvOptionPane extends JOptionPane
 
   private Component parentComponent;
 
-  public JvOptionPane(final Component parentComponent)
+  private Map<Object, Runnable> callbacks = new HashMap<>();
+
+  /*
+   * JalviewJS reports user choice in the dialog as the selected
+   * option (text); this list allows conversion to index (int)
+   */
+  List<Object> ourOptions;
+  
+  public JvOptionPane(final Component parent)
   {
-    
-    this.parentComponent = parentComponent;
+    this.parentComponent = Jalview.isJS() ? this : parent;
   }
 
   public static int showConfirmDialog(Component parentComponent,
@@ -704,18 +710,17 @@ public class JvOptionPane extends JOptionPane
     return interactiveMode;
   }
 
-  public static void setInteractiveMode(boolean interactiveMode)
+  public static void setInteractiveMode(boolean interactive)
   {
-    JvOptionPane.interactiveMode = interactiveMode;
+    JvOptionPane.interactiveMode = interactive;
   }
 
-  @SuppressWarnings("unused")
   private static String getPrefix(int messageType)
   {
-    String prefix = ""; // JavaScript only
-
-    if (/** @j2sNative true || */
-    false)
+    String prefix = ""; 
+    
+    // JavaScript only
+    if (Jalview.isJS())
     {
       switch (messageType)
       {
@@ -732,9 +737,6 @@ public class JvOptionPane extends JOptionPane
     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
@@ -761,7 +763,7 @@ public class JvOptionPane extends JOptionPane
 
     if (!isInteractiveMode())
     {
-      runner.firstRun((int) getMockResponse());
+      handleResponse(getMockResponse());
     }
     // two uses:
     //
@@ -777,25 +779,20 @@ public class JvOptionPane extends JOptionPane
     //
     // 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,
+    
+    int response = JOptionPane.showOptionDialog(parentComponent, message, title,
             optionType, messageType, icon, options, initialValue);
-    /**
-     * @j2sNative
+    
+    /*
+     * In Java, the response is returned to this thread and handled here;
+     * (for Javascript, see propertyChange)
      */
+    if (!Jalview.isJS())
     {
-      runner.firstRun(response);
+      handleResponse(response);
     }
-
   }
 
   public void showInternalDialog(JPanel mainPanel, String title,
@@ -804,66 +801,73 @@ public class JvOptionPane extends JOptionPane
   {
     if (!isInteractiveMode())
     {
-      runner.firstRun((int) getMockResponse());
+      handleResponse(getMockResponse());
     }
-    Component parent;
-    /**
-     * @j2sNative parent = this;
-     */
-    {
-      parent = parentComponent;
-    }
-    ourOptions = Arrays.asList(options);
     
+    ourOptions = Arrays.asList(options);
     int response;
-    if (parent!=this) {
-
-      response = JOptionPane.showInternalOptionDialog(parent, mainPanel,
+    if (parentComponent != this) 
+    {
+      response = JOptionPane.showInternalOptionDialog(parentComponent, mainPanel,
               title, yesNoCancelOption, questionMessage, icon, options,
               initresponse);
     }
     else
     {
-      response = JOptionPane.showOptionDialog(parent, mainPanel, title,
+      response = JOptionPane.showOptionDialog(parentComponent, mainPanel, title,
               yesNoCancelOption, questionMessage, icon, options,
               initresponse);
     }
-    /**
-     * @j2sNative
-     */
+    if (!Jalview.isJS())
     {
-      runner.firstRun(response);
+      handleResponse(response);
     }
-    
   }
+    
   @Override
-  public JvOptionPane addResponse(RunResponse action)
+  public JvOptionPane setResponseHandler(Object response, Runnable action)
   {
-
-    runner.addResponse(action);
-    return this;
-  }
-
-  public JvOptionPane defaultResponse(Runnable runnable)
-  {
-    runner.setDefaultResponse(runnable);
+       callbacks.put(response,  action);
     return this;
   }
 
+  /**
+   * 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)
   {
-    int ourOption = ourOptions.indexOf(evt.getNewValue());
-    if (ourOption == -1)
+    Object newValue = evt.getNewValue();
+       int ourOption = ourOptions.indexOf(newValue);
+    if (ourOption >= 0)
     {
-      // try our luck..
-      runner.run(evt.getNewValue());
+      handleResponse(ourOption);
     }
     else
     {
-      runner.run(ourOption);
+      // try our luck..
+      handleResponse(newValue);
     }
   }
 
-
+  @Override
+  public void handleResponse(Object response)
+  {
+    /*
+        * this test is for NaN in Chrome
+        */
+    if (response != null && !response.equals(response))
+    {
+      return;
+    }
+    Runnable action = callbacks.get(response);
+    if (action != null)
+    {
+      action.run();
+    }
+  }
 }
index 765a1ac..d55733c 100644 (file)
@@ -22,7 +22,6 @@ package jalview.gui;
 
 import jalview.bin.Cache;
 import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
 
 import java.awt.FlowLayout;
 import java.awt.event.ActionEvent;
@@ -96,9 +95,9 @@ public class LineartOptions extends JPanel
    * 
    * @param action
    */
-  public void setResponseAction(RunResponse action)
+  public void setResponseAction(Object response, Runnable action)
   {
-    dialog.addResponse(action);
+    dialog.setResponseHandler(response, action);
   }
 
   /**
index 5a12a02..5f58d51 100644 (file)
@@ -53,7 +53,6 @@ import jalview.util.GroupUrlLink.UrlStringTooLongException;
 import jalview.util.MessageManager;
 import jalview.util.StringUtils;
 import jalview.util.UrlLink;
-import jalview.util.dialogrunner.RunResponse;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
@@ -73,7 +72,6 @@ import java.util.TreeMap;
 import java.util.Vector;
 
 import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JComponent;
 import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
 import javax.swing.JMenu;
@@ -1808,7 +1806,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
             MessageManager.getString("label.group_description"));
     dialog.showDialog(ap.alignFrame,
             MessageManager.getString("label.edit_group_name_description"),
-            new RunResponse(JvOptionPane.OK_OPTION)
+            new Runnable()
             {
               @Override
               public void run()
@@ -1849,7 +1847,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
     dialog.showDialog(ap.alignFrame,
             MessageManager.getString(
                     "label.edit_sequence_name_description"),
-            new RunResponse(JvOptionPane.OK_OPTION)
+            new Runnable()
             {
               @Override
               public void run()
@@ -2130,7 +2128,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
               null, MessageManager.getString("label.edit_sequence"), null);
       dialog.showDialog(ap.alignFrame,
               MessageManager.getString("label.edit_sequence"),
-              new RunResponse(JvOptionPane.OK_OPTION)
+              new Runnable()
               {
                 @Override
                 public void run()
index 1eba84c..5d22abb 100644 (file)
@@ -23,7 +23,6 @@ package jalview.gui;
 import jalview.datamodel.SequenceGroup;
 import jalview.gui.JalviewColourChooser.ColourChooserListener;
 import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
@@ -149,8 +148,8 @@ public class TextColourChooser
     Object[] options = new Object[] { MessageManager.getString("action.ok"),
         MessageManager.getString("action.cancel") };
     String title = MessageManager
-            .getString("label.adjunst_foreground_text_colour_threshold");
-    RunResponse action = new RunResponse(JvOptionPane.NO_OPTION) // Cancel
+            .getString("label.adjust_foreground_text_colour_threshold");
+    Runnable action = new Runnable() // response for 1 = Cancel
     {
       @Override
       public void run()
@@ -158,7 +157,7 @@ public class TextColourChooser
         restoreInitialSettings();
       }
     };
-    JvOptionPane.newOptionDialog(alignPanel).addResponse(action)
+    JvOptionPane.newOptionDialog(alignPanel).setResponseHandler(1, action)
             .showInternalDialog(bigpanel, title,
                     JvOptionPane.YES_NO_CANCEL_OPTION,
                     JvOptionPane.PLAIN_MESSAGE, null, options,
index f1ff128..04266be 100755 (executable)
@@ -32,7 +32,6 @@ import jalview.schemes.UserColourScheme;
 import jalview.util.ColorUtils;
 import jalview.util.Format;
 import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
 import jalview.xml.binding.jalview.JalviewUserColours;
 import jalview.xml.binding.jalview.JalviewUserColours.Colour;
 import jalview.xml.binding.jalview.ObjectFactory;
@@ -645,43 +644,46 @@ public class UserDefinedColours extends GUserDefinedColours
     chooser.setDialogTitle(
             MessageManager.getString("label.load_colour_scheme"));
     chooser.setToolTipText(MessageManager.getString("action.load"));
-    chooser.addResponse(new RunResponse(JalviewFileChooser.APPROVE_OPTION) {
-               @Override
-               public void run() {
-                   File choice = chooser.getSelectedFile();
-                   Cache.setProperty(LAST_DIRECTORY, choice.getParent());
-
-                   UserColourScheme ucs = ColourSchemeLoader
-                           .loadColourScheme(choice.getAbsolutePath());
-                   Color[] colors = ucs.getColours();
-                   schemeName.setText(ucs.getSchemeName());
-
-                   if (ucs.getLowerCaseColours() != null)
-                   {
-                     caseSensitive.setSelected(true);
-                     lcaseColour.setEnabled(true);
-                     resetButtonPanel(true);
-                     for (int i = 0; i < lowerCaseButtons.size(); i++)
-                     {
-                       JButton button = lowerCaseButtons.get(i);
-                       button.setBackground(ucs.getLowerCaseColours()[i]);
-                     }
-                   }
-                   else
-                   {
-                     caseSensitive.setSelected(false);
-                     lcaseColour.setEnabled(false);
-                     resetButtonPanel(false);
-                   }
-
-                   for (int i = 0; i < upperCaseButtons.size(); i++)
-                   {
-                     JButton button = upperCaseButtons.get(i);
-                     button.setBackground(colors[i]);
-                   }
-
-                   addNewColourScheme(choice.getPath());
-               }});
+    chooser.setResponseHandler(0, new Runnable() 
+    {
+         @Override
+         public void run() 
+         {
+           File choice = chooser.getSelectedFile();
+           Cache.setProperty(LAST_DIRECTORY, choice.getParent());
+
+           UserColourScheme ucs = ColourSchemeLoader
+                   .loadColourScheme(choice.getAbsolutePath());
+           Color[] colors = ucs.getColours();
+           schemeName.setText(ucs.getSchemeName());
+
+           if (ucs.getLowerCaseColours() != null)
+               {
+                  caseSensitive.setSelected(true);
+                  lcaseColour.setEnabled(true);
+                  resetButtonPanel(true);
+                  for (int i = 0; i < lowerCaseButtons.size(); i++)
+                  {
+                    JButton button = lowerCaseButtons.get(i);
+                    button.setBackground(ucs.getLowerCaseColours()[i]);
+                  }
+                }
+                else
+                {
+                  caseSensitive.setSelected(false);
+                  lcaseColour.setEnabled(false);
+                  resetButtonPanel(false);
+                }
+
+                for (int i = 0; i < upperCaseButtons.size(); i++)
+                {
+                  JButton button = upperCaseButtons.get(i);
+                  button.setBackground(colors[i]);
+                }
+
+                addNewColourScheme(choice.getPath());
+          }
+       });
     
     chooser.showOpenDialog(this);
   }
index d653e4b..b8241c8 100644 (file)
@@ -26,7 +26,6 @@ import jalview.gui.LineartOptions;
 import jalview.gui.OOMWarning;
 import jalview.math.AlignmentDimension;
 import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
 
 import java.awt.Graphics;
 import java.awt.print.PrinterException;
@@ -35,8 +34,6 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.concurrent.atomic.AtomicBoolean;
 
-import javax.swing.JOptionPane;
-
 import org.jfree.graphics2d.svg.SVGGraphics2D;
 import org.jfree.graphics2d.svg.SVGHints;
 
@@ -214,7 +211,7 @@ public class HtmlSvgOutput extends HTMLOutput
       /*
        * configure the action to run on OK in the dialog
        */
-      RunResponse okAction = new RunResponse(JOptionPane.OK_OPTION)
+      Runnable okAction = new Runnable()
       {
         @Override
         public void run()
@@ -229,7 +226,7 @@ public class HtmlSvgOutput extends HTMLOutput
       if (renderStyle.equalsIgnoreCase("Prompt each time") && !isHeadless())
       {
         LineartOptions svgOption = new LineartOptions("HTML", textOption);
-        svgOption.setResponseAction(new RunResponse(JOptionPane.NO_OPTION)
+        svgOption.setResponseAction(1, new Runnable()
         {
           @Override
           public void run()
@@ -239,7 +236,7 @@ public class HtmlSvgOutput extends HTMLOutput
                     getDescription()));
           }
         });
-        svgOption.setResponseAction(okAction);
+        svgOption.setResponseAction(0, okAction);
         svgOption.showDialog();
         /* no code here - JalviewJS cannot execute it */
       }
index 2419bef..7909d0c 100755 (executable)
@@ -25,10 +25,7 @@ import jalview.bin.Cache;
 import jalview.gui.JvOptionPane;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
-import jalview.util.dialogrunner.DialogRunner;
 import jalview.util.dialogrunner.DialogRunnerI;
-import jalview.util.dialogrunner.Response;
-import jalview.util.dialogrunner.RunResponse;
 
 import java.awt.Component;
 import java.awt.Dimension;
@@ -41,6 +38,7 @@ import java.beans.PropertyChangeListener;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
@@ -61,11 +59,15 @@ import javax.swing.plaf.basic.BasicFileChooserUI;
  * @author AMW
  *
  */
-public class JalviewFileChooser extends JFileChooser
-        implements PropertyChangeListener, DialogRunnerI<JalviewFileChooser>
+public class JalviewFileChooser extends JFileChooser implements DialogRunnerI,
+    PropertyChangeListener
 {
-  DialogRunner<JalviewFileChooser> runner = new DialogRunner<>(this);
+  private static final long serialVersionUID = 1L;
+
+  private Map<Object, Runnable> callbacks;
   
+  File selectedFile = null;
+
   /**
    * Factory method to return a file chooser that offers readable alignment file
    * formats
@@ -146,7 +148,7 @@ public class JalviewFileChooser extends JFileChooser
   }
 
   JalviewFileChooser(String dir, String[] extensions, String[] descs,
-          String selected, boolean allFiles)
+          String selected, boolean acceptAny)
   {
     super(safePath(dir));
     if (extensions.length == descs.length)
@@ -156,7 +158,7 @@ public class JalviewFileChooser extends JFileChooser
       {
         formats.add(new String[] { extensions[i], descs[i] });
       }
-      init(formats, selected, allFiles);
+      init(formats, selected, acceptAny);
     }
     else
     {
@@ -165,18 +167,6 @@ public class JalviewFileChooser extends JFileChooser
     }
   }
 
-  @Override
-  public void propertyChange(PropertyChangeEvent evt)
-  {
-    // TODO other properties need runners...
-    switch (evt.getPropertyName())
-    {
-    case "SelectedFile": 
-      runner.run(APPROVE_OPTION);
-      break;
-    }
-  }
-
   private static File safePath(String dir)
   {
     if (dir == null)
@@ -200,14 +190,13 @@ public class JalviewFileChooser extends JFileChooser
   @Override
   public int showOpenDialog(Component parent)
   {
-    runner.resetResponses();
     int value = super.showOpenDialog(this);
-    /**
-     * @j2sNative
+    
+    /*
+     * code below here is not reached in JalviewJS, instead
+     * propertyChange() is called for dialog action
      */
-    {
-      runner.firstRun(value);
-    }
+    handleResponse(value);
     return value;
   }
 
@@ -216,17 +205,17 @@ public class JalviewFileChooser extends JFileChooser
    * @param formats
    *          a list of {extensions, description} for each file format
    * @param selected
-   * @param allFiles
+   * @param acceptAny
    *          if true, 'any format' option is included
    */
-  void init(List<String[]> formats, String selected, boolean allFiles)
+  void init(List<String[]> formats, String selected, boolean acceptAny)
   {
 
     JalviewFileFilter chosen = null;
 
     // SelectAllFilter needs to be set first before adding further
     // file filters to fix bug on Mac OSX
-    setAcceptAllFileFilterUsed(allFiles);
+    setAcceptAllFileFilterUsed(acceptAny);
 
     for (String[] format : formats)
     {
@@ -317,18 +306,12 @@ public class JalviewFileChooser extends JFileChooser
     }
     return null;
   }
-  
-  File ourselectedFile = null;
 
   @Override
   public File getSelectedFile()
   {
-    File selfile = super.getSelectedFile();
-    if (selfile == null && ourselectedFile != null)
-    {
-      return ourselectedFile;
-    }
-    return selfile;
+    File f = super.getSelectedFile();
+    return f == null ? selectedFile : f;
   }
 
   @Override
@@ -357,9 +340,9 @@ public class JalviewFileChooser extends JFileChooser
       return;
     }
 
-    ourselectedFile = getSelectedFile();
+    selectedFile = getSelectedFile();
 
-    if (ourselectedFile == null)
+    if (selectedFile == null)
     {
       // Workaround for Java 9,10 on OSX - no selected file, but there is a
       // filename typed in
@@ -368,7 +351,7 @@ public class JalviewFileChooser extends JFileChooser
         String filename = ((BasicFileChooserUI) getUI()).getFileName();
         if (filename != null && filename.length() > 0)
         {
-          ourselectedFile = new File(getCurrentDirectory(), filename);
+          selectedFile = new File(getCurrentDirectory(), filename);
         }
       } catch (Throwable x)
       {
@@ -380,7 +363,8 @@ public class JalviewFileChooser extends JFileChooser
       // THE
       // USER PROMPTED FOR A NEW FILENAME
     }
-    if (ourselectedFile == null)
+
+    if (selectedFile == null)
     {
       return;
     }
@@ -389,22 +373,21 @@ public class JalviewFileChooser extends JFileChooser
     {
       JalviewFileFilter jvf = (JalviewFileFilter) getFileFilter();
 
-      if (!jvf.accept(ourselectedFile))
+      if (!jvf.accept(selectedFile))
       {
         String withExtension = getSelectedFile().getName() + "."
                 + jvf.getAcceptableExtension();
-        ourselectedFile = (new File(getCurrentDirectory(), withExtension));
-        setSelectedFile(ourselectedFile);
+        selectedFile = (new File(getCurrentDirectory(), withExtension));
+        setSelectedFile(selectedFile);
       }
     }
 
-    if (ourselectedFile.exists())
+    if (selectedFile.exists())
     {
       int confirm = JvOptionPane.showConfirmDialog(this,
               MessageManager.getString("label.overwrite_existing_file"),
               MessageManager.getString("label.file_already_exists"),
               JvOptionPane.YES_NO_OPTION);
-
       if (confirm != JvOptionPane.YES_OPTION)
       {
         return;
@@ -436,13 +419,13 @@ public class JalviewFileChooser extends JFileChooser
 
   class RecentlyOpened extends JPanel
   {
+    private static final long serialVersionUID = 1L;
     JList<String> list;
 
-    public RecentlyOpened()
+    RecentlyOpened()
     {
-
       setPreferredSize(new Dimension(300,100));
-      String historyItems = jalview.bin.Cache.getProperty("RECENT_FILE");
+      String historyItems = Cache.getProperty("RECENT_FILE");
       StringTokenizer st;
       Vector<String> recent = new Vector<>();
 
@@ -508,9 +491,48 @@ public class JalviewFileChooser extends JFileChooser
   }
 
   @Override
-  public JalviewFileChooser addResponse(RunResponse action)
+  public DialogRunnerI setResponseHandler(Object response, Runnable action)
   {
-    return runner.addResponse(action);
+       callbacks.put(response,  action);
+       return this;
   }
 
+  @Override
+  public void handleResponse(Object response)
+  {
+    /*
+        * this test is for NaN in Chrome
+        */
+    if (response != null && !response.equals(response))
+    {
+      return;
+    }
+    Runnable action = callbacks.get(response);
+    if (action != null)
+    {
+      action.run();
+    }
+  }
+
+  /**
+   * JalviewJS signals file selection by a property change event
+   * for property "SelectedFile".  This methods responds to that by
+   * running the response action for 'OK' in the dialog.
+   * 
+   * @param evt
+   */
+  @Override
+  public void propertyChange(PropertyChangeEvent evt)
+  {
+    // TODO other properties need runners...
+    switch (evt.getPropertyName())
+    {
+    /*
+     * property name here matches that used in JFileChooser.js
+     */
+    case "SelectedFile": 
+      handleResponse(APPROVE_OPTION);
+      break;
+    }
+  }
 }
diff --git a/src/jalview/util/dialogrunner/DialogRunner.java b/src/jalview/util/dialogrunner/DialogRunner.java
deleted file mode 100644 (file)
index 05a63c7..0000000
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
- *
- * This file is part of Jalview.
- *
- * Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3
- * of the License, or (at your option) any later version.
- *
- * Jalview is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.util.dialogrunner;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * daft gymnastics to allow Dialogs to extend from a Swing class and use this
- * class to implement chained Response run() definition and execution.
- * 
- * There is probably a better way of doing this.
- * 
- * @author jprocter
- *
- * @param <T>
- *          the actual dialog that will be shown - which will also initiate the
- *          response chain.
- */
-public class DialogRunner<T extends DialogRunnerI> implements DialogRunnerI
-{
-
-  private Map<Response, List<RunResponse>> callbacks = new java.util.HashMap<>();
-
-  public T dialog;
-
-  public DialogRunner(T ourDialog)
-  {
-    dialog = ourDialog;
-  }
-
-  /**
-   * clear all 'was ran' flags so responses can be called again, and firstRun will
-   * trigger response execution
-   */
-  public void resetResponses()
-  {
-    for (List<RunResponse> lr : callbacks.values())
-    {
-      for (RunResponse response : lr)
-      {
-        response.reset();
-      }
-    }
-    responses.clear();
-    if (defaultResponse != null)
-    {
-      defaultResponse.reset();
-    }
-    firstRunWasCalled = false;
-  }
-
-  @Override
-  public T addResponse(RunResponse action)
-  {
-    return addResponse(false, action);
-  }
-
-  /**
-   * insert a response at the beginning of the chain for the action. Useful to add
-   * pre-action validations local to the Dialog class
-   * 
-   * @param action
-   * @return
-   */
-  public T firstResponse(RunResponse action)
-  {
-    return addResponse(true, action);
-  }
-
-  protected T addResponse(boolean prePend, RunResponse action)
-  {
-    List<RunResponse> laction = callbacks.get(action.ourTrigger);
-    if (laction == null)
-    {
-      laction = new ArrayList<>();
-      callbacks.put(action.ourTrigger, laction);
-    }
-    if (prePend)
-    {
-      laction.add(0,action);
-    } else {
-      laction.add(action);
-    }
-    return dialog;
-  }
-
-  /**
-   * 
-   * @param action
-   * @return true if action is a registered callback
-   */
-  public boolean isRegistered(RunResponse action)
-  {
-    List<RunResponse> resp = callbacks.get(action.ourTrigger);
-    if (resp != null)
-    {
-      for (RunResponse r : resp)
-      {
-        if (r == action)
-        {
-          return true;
-        }
-      }
-    }
-    return false;
-  }
-  /**
-   * handle a response
-   * 
-   * @param responseCode
-   */
-  public void run(int responseCode)
-  {
-    run(new Response(responseCode));
-  }
-
-  public void run(String responseString)
-  {
-    run(new Response(responseString));
-  }
-
-  public void run(Object responseObj)
-  {
-    run(new Response(responseObj));
-  }
-
-  /**
-   * start of response handling.
-   * 
-   * @param responseCode
-   */
-  public void firstRun(int responseCode)
-  {
-    doFirstRun(new Response(responseCode));
-  }
-
-  public void firstRun(String responseString)
-  {
-    doFirstRun(new Response(responseString));
-  }
-
-  public void firstRun(Object responseObj)
-  {
-    if (responseObj != null && !responseObj.equals(responseObj))
-    {
-      // NaN is an object in Chrome - catch this weirdness
-      // this so we don't cause issues later
-      return;
-    }
-    doFirstRun(new Response(responseObj));
-  }
-
-
-  boolean firstRunWasCalled = false;
-
-  private void doFirstRun(Response response)
-  {
-    if (firstRunWasCalled)
-    {
-      return;
-    }
-    firstRunWasCalled = true;
-    run(response);
-  }
-
-  private void run(Response response)
-  {
-    if (response.objresp != null
-            && !response.objresp.equals(response.objresp))
-    {
-      // NaN is an object in Chrome - catch this weirdness
-      // this so we don't cause issues later
-      return;
-    }
-    responses.add(response);
-    
-    List<RunResponse> laction = response.isNull() ? null : callbacks.get(response);
-
-    if (laction == null)
-    {
-      if (defaultResponse != null)
-      {
-        defaultResponse.ourTrigger = response;
-        defaultResponse.wasRun = true;
-        defaultResponse.run();
-      }
-      else
-      {
-        System.err.println("Doing nothing for " + response);
-      }
-      return;
-    }
-    boolean wasRun = false;
-    int num = 0;
-    for (RunResponse action : laction)
-    {
-      num++;
-      // find next action to execute
-      if (!action.wasRun)
-      {
-        System.err
-                .println("Executing action (" + num + ") for " + response);
-        wasRun = true;
-        action.wasRun = true;
-        action.run();
-        if (action.returned != null)
-        {
-          run(action.returned);
-        }
-        break;
-      }
-    }
-    if (!wasRun)
-    {
-      System.err.println("Did nothing for " + response);
-    }
-  }
-
-  List<Response> responses = new ArrayList<>();
-
-  RunResponse defaultResponse = null;
-
-  /**
-   * Convenience wrapper for setting default response to a runnable
-   * 
-   * @param runnable
-   */
-  public void setDefaultResponse(Runnable runnable)
-  {
-    defaultResponse = new RunResponse(runnable)
-    {
-      @Override
-      public void run()
-      {
-        runnable.run();
-      }
-    };
-  }
-
-  /**
-   * Default responses are called once, with ourTrigger set to the unHandled
-   * response received
-   * 
-   * @param runnable
-   */
-  public void setDefaultResponse(RunResponse runnable)
-  {
-    defaultResponse = runnable;
-  }
-}
index 758d421..0cb90c2 100644 (file)
 package jalview.util.dialogrunner;
 
 /**
- * functional pattern for blocking dialog response handling
+ * An interface for blocking dialog response handling. This is motivated by
+ * JalviewJS - when running as Javascript, there is only a single thread, and
+ * blocking dialogs have to be responsible for performing any actions required
+ * for user responses.
  * 
  * @author jprocter
  *
  */
-public interface DialogRunnerI<T extends DialogRunnerI>
-{
+public interface DialogRunnerI {
 
-  /**
-   * Adds a new response for this dialog, and returns the dialog (this), to allow chaining, eg.
-   * <pre>
-   * dialog.addResponse(newRunResponse(OK_PRessed) { run()...})
-   *     .addResponse(new RunResponse(CANCEL_PRESSED);
-   * </pre>
-   * 
-   * @param action
-   * @return the dialog
-   */
-  T addResponse(RunResponse action);
+       /**
+        * Sets the action to be performed when the dialog returns the given response.
+        * Note this also handles <code>int</code>-valued responses, which will be
+        * converted to <code>Integer</code> when this method is invoked.
+        * 
+        * @param response
+        * @param action
+        * @return
+        */
+       DialogRunnerI setResponseHandler(Object response, Runnable action);
+
+       /**
+        * Runs the registered handler (if any) for the given response. The default
+        * action is to do nothing. Typically an action will be need on 'OK' or other
+        * positive selection in the dialog. An action might in some cases also be
+        * needed for a 'Cancel' response.
+        * 
+        * @param response
+        * @return
+        */
+       default void handleResponse(Object response) {
+       }
 }
diff --git a/src/jalview/util/dialogrunner/Response.java b/src/jalview/util/dialogrunner/Response.java
deleted file mode 100644 (file)
index f168e20..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
- *
- * This file is part of Jalview.
- *
- * Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3
- * of the License, or (at your option) any later version.
- *
- * Jalview is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.util.dialogrunner;
-
-public class Response
-{
-  int type = 0; // int = 0, String = 1, Object = 2;
-
-  int intresp;
-
-  String stringresp;
-
-  Object objresp;
-
-  public Response(int response)
-  {
-    type = 0;
-    intresp = response;
-  }
-
-  public Response(String response)
-  {
-    type = 1;
-    stringresp = response;
-  }
-
-  public Response(Object response)
-  {
-    if (response instanceof String)
-    {
-      type = 1;
-      stringresp = (String) response;
-      return;
-    }
-    if (response instanceof Integer)
-    {
-      type = 0;
-      intresp = ((Integer) response).intValue();
-      return;
-    }
-    objresp = response;
-    type = 2;
-  }
-
-  @Override
-  public boolean equals(Object obj)
-  {
-    if (obj == null || !(obj instanceof Response))
-    {
-      return false;
-    }
-    ;
-    if (((Response) obj).type == type)
-    {
-      switch (type)
-      {
-      case 0:
-        return ((((Response) obj).intresp) == intresp);
-      case 1:
-        return (((Response) obj).stringresp.equals(stringresp));
-      case 2:
-        return (((Response) obj).objresp).equals(objresp);
-      }
-    }
-    return false;
-  }
-
-  @Override
-  public int hashCode()
-  {
-    switch (type)
-    {
-    case 0:
-      return Integer.valueOf(intresp).hashCode();
-    case 1:
-      return stringresp.hashCode();
-    case 2:
-      return objresp.hashCode();
-    }
-    return super.hashCode();
-  }
-
-  @Override
-  public String toString()
-  {
-    switch (type)
-    {
-    case 0:
-      return "DialogRunner int: " + intresp;
-    case 1:
-      return "DialogRunner str: '" + stringresp + "'";
-    case 2:
-      return "DialogRunner obj: " + String.valueOf(objresp);
-    }
-    return "Unconfigured response.";
-  }
-
-  /**
-   * null response - triggers the default response
-   * @return
-   */
-  public boolean isNull()
-  {
-    return (type==2 && objresp==null) || (type==1 && (stringresp==null || stringresp.equals("")));
-  }
-}
\ No newline at end of file
diff --git a/src/jalview/util/dialogrunner/RunResponse.java b/src/jalview/util/dialogrunner/RunResponse.java
deleted file mode 100644 (file)
index 3fd56c4..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
- *
- * This file is part of Jalview.
- *
- * Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3
- * of the License, or (at your option) any later version.
- *
- * Jalview is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.util.dialogrunner;
-
-/**
- * A Runnable that is kind of like a future, that allows a sequence of Runabbles
- * to be conditionally executed by DialogRunner
- * 
- * @author jprocter
- *
- */
-public abstract class RunResponse implements Runnable
-{
-  /**
-   * Response that triggers the Run method
-   */
-  public Response ourTrigger;
-
-  /**
-   * set by run() on exit
-   */
-  public Response returned = null;
-
-  /**
-   * set by dialog runner
-   */
-  public boolean wasRun = false;
-
-  public RunResponse(int trigger)
-  {
-    ourTrigger = new Response(trigger);
-  }
-
-  public RunResponse(Object trigger)
-  {
-    ourTrigger = new Response(trigger);
-  }
-
-  public RunResponse(String trigger)
-  {
-    ourTrigger = new Response(trigger);
-  }
-
-  public void reset()
-  {
-    wasRun = false;
-    returned = null;
-
-  }
-
-  @Override
-  public String toString()
-  {
-    return "Runner for " + ourTrigger;
-  }
-}
index ec61551..c2d8129 100644 (file)
@@ -1,129 +1,4 @@
 package jalview.util.dialogrunner;
 
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
 public class DialogRunnerTest
-{
-  public class MockDialog implements DialogRunnerI<MockDialog>
-  {
-    DialogRunner<MockDialog> runner = new DialogRunner<>(this);
-
-    @Override
-    public MockDialog addResponse(RunResponse action)
-    {
-      return runner.addResponse(action);
-    }
-
-    public void doDialog(String resp)
-    {
-      runner.firstRun(resp);
-    }
-  }
-
-  MockDialog dialog = new MockDialog();
-
-  @Test
-  public void testDialogRunner()
-  {
-    RunResponse ok, cancel, help, ineed;
-    final Response ooh = new Response("OOOOoooOOOOH!"),
-            r_ok = new Response("OK"), r_cancel = new Response("CANCEL"),
-            r_done = new Response("DONE"), r_help = new Response("HELP"),
-            r_ddoit = new Response("DIDNT DOIT"),
-            r_needsb = new Response("I NEED SOMEBODY");
-
-    ok = new RunResponse("OK")
-    {
-
-      @Override
-      public void run()
-      {
-        returned = new Response("DONE");
-      }
-    };
-    final RunResponse befok = new RunResponse("OK")
-    {
-
-      @Override
-      public void run()
-      {
-        returned = new Response("OK");
-      }
-    };
-
-    cancel = new RunResponse("CANCEL")
-    {
-      @Override
-      public void run()
-      {
-        returned = r_ddoit;
-      }
-    };
-    help = new RunResponse("HELP")
-    {
-      @Override
-      public void run()
-      {
-        returned = r_needsb;
-
-      }
-    };
-    ineed = new RunResponse(r_needsb)
-    {
-      @Override
-      public void run()
-      {
-        returned = ooh;
-      }
-    };
-
-    Assert.assertFalse(dialog.runner.isRegistered(ok));
-
-       dialog.addResponse(ok).addResponse(cancel).addResponse(help).addResponse(ineed);
-
-    Assert.assertTrue(dialog.runner.isRegistered(ok));
-
-    Assert.assertFalse(dialog.runner.firstRunWasCalled);
-    dialog.doDialog("OK");
-    // OK called, nothing else.
-    Assert.assertTrue(dialog.runner.firstRunWasCalled);
-    Assert.assertTrue(ok.wasRun);
-    Assert.assertEquals(ok.returned, r_done);
-    Assert.assertFalse(cancel.wasRun);
-    Assert.assertEquals(dialog.runner.responses.size(), 2);
-
-    // do it again - check it doesn't trigger again
-    ok.wasRun = false;
-    dialog.doDialog("OK");
-    Assert.assertFalse(ok.wasRun);
-
-    // reset - everything false/null
-    dialog.runner.resetResponses();
-    Assert.assertFalse(dialog.runner.firstRunWasCalled);
-    Assert.assertFalse(ok.wasRun);
-    Assert.assertNull(ok.returned);
-    Assert.assertEquals(dialog.runner.responses.size(), 0);
-
-    // cancel called ..
-    dialog.doDialog("HELP");
-    Assert.assertTrue(dialog.runner.firstRunWasCalled);
-    Assert.assertFalse(ok.wasRun);
-    Assert.assertEquals(ineed.returned, ooh);
-    Assert.assertEquals(dialog.runner.responses.size(), 3);
-
-    // TODO: test prepend and chained execution of tasks for a response.
-    Assert.assertFalse(dialog.runner.isRegistered(befok));
-    dialog.runner.firstResponse(befok);
-
-    Assert.assertTrue(dialog.runner.isRegistered(befok));
-    Assert.assertTrue(dialog.runner.isRegistered(ok));
-
-    dialog.runner.resetResponses();
-
-    dialog.doDialog("OK");
-    Assert.assertTrue(befok.wasRun);
-    Assert.assertTrue(ok.wasRun);
-    Assert.assertEquals(dialog.runner.responses.size(), 3);
-  }
-}
+{}
diff --git a/test/jalview/util/dialogrunner/ResponseTest.java b/test/jalview/util/dialogrunner/ResponseTest.java
deleted file mode 100644 (file)
index d722b1a..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
- *
- * This file is part of Jalview.
- *
- * Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3
- * of the License, or (at your option) any later version.
- *
- * Jalview is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.util.dialogrunner;
-
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-public class ResponseTest
-{
-  @Test
-  public void testResonse() {
-    Response intr=new Response(1),intrCopy=new Response(1);
-    Response strr=new Response("1"),strrcopy=new Response("1");
-    Response objr=new Response(Double.valueOf(1d));
-    Assert.assertTrue(intr.equals(intrCopy));
-    Assert.assertTrue(strr.equals(strrcopy));
-    Assert.assertFalse(intr.equals(strr));
-    Assert.assertFalse(intr.equals(objr));
-    Assert.assertFalse(strr.equals(objr));
-    Assert.assertEquals(intr.toString(), "DialogRunner int: 1");
-    Assert.assertEquals(strr.toString(), "DialogRunner str: '1'");
-    Assert.assertEquals(objr.toString(), "DialogRunner obj: 1.0");
-  }
-}
diff --git a/test/jalview/util/dialogrunner/RunResponseTest.java b/test/jalview/util/dialogrunner/RunResponseTest.java
deleted file mode 100644 (file)
index ff86675..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-package jalview.util.dialogrunner;
-
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-public class RunResponseTest
-{
-  @Test
-  public void testRunResponse()
-  {
-
-    RunResponse rr = new RunResponse("OK")
-    {
-      @Override
-      public void run()
-      {
-        returned = new Response("DONE");
-      }
-    };
-    Assert.assertEquals(rr.ourTrigger, new Response("OK"));
-    Assert.assertNotEquals(rr.ourTrigger, new Response("NOTOK"));
-    Assert.assertNull(rr.returned);
-    Assert.assertFalse(rr.wasRun);
-    // trivial ..
-    rr.wasRun = true;
-    rr.run();
-    Assert.assertTrue(rr.wasRun);
-
-    Assert.assertEquals(rr.returned, new Response("DONE"));
-    rr.reset();
-    Assert.assertNull(rr.returned);
-    Assert.assertFalse(rr.wasRun);
-
-    Assert.assertEquals(rr.toString(), "Runner for " + new Response("OK"));
-
-    // just test the other constructors
-    RunResponse rr12 = new RunResponse(12)
-    {
-      @Override
-      public void run()
-      {
-        returned = new Response("DONE");
-      }
-    };
-    RunResponse rrpi = new RunResponse(new Double(3.142))
-    {
-      @Override
-      public void run()
-      {
-        returned = new Response("DONE");
-      }
-    };
-    Assert.assertEquals(rr12.ourTrigger, new Response(12));
-    Assert.assertEquals(rrpi.ourTrigger,
-            new Response(Double.valueOf(3.142)));
-}
-}
index a2026a8..4059c6a 100644 (file)
@@ -9,6 +9,7 @@ import java.awt.MediaTracker;
 import java.io.File;
 import java.text.DecimalFormat;
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
 
 import javax.swing.ImageIcon;
@@ -35,9 +36,16 @@ public class JalviewJSTest extends JPanel
 {
   public static void main(String[] args)
   {
-    new JalviewJSTest().doTest2();
+    new JalviewJSTest().doTest3();
   }
 
+  void doTest3() 
+  {
+           System.out.println("Mungo".toLowerCase(Locale.getDefault()));
+           System.out.println("Mungo".toLowerCase(Locale.ENGLISH));
+    System.out.println("Mungo".toLowerCase(Locale.ROOT));
+  }
+  
   void doTest2() {
          Map<File, String> map = new HashMap<>();
          File f1 = new File("/var/folders/y/xyz");