JAL-3048 JAL-3056 reinstate save/load project, colour scheme dialogs in Jalview-BH/JAL-3026
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 1 Nov 2018 10:01:53 +0000 (10:01 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 1 Nov 2018 10:01:53 +0000 (10:01 +0000)
JS

src/jalview/gui/Desktop.java
src/jalview/gui/FeatureSettings.java
src/jalview/gui/UserDefinedColours.java
src/jalview/jbgui/GDesktop.java
src/jalview/jbgui/GUserDefinedColours.java

index ceea332..96f0bf3 100644 (file)
@@ -1647,13 +1647,10 @@ public class Desktop extends jalview.jbgui.GDesktop
 
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager.getString("label.save_state"));
-
-    int value = chooser.showSaveDialog(this);
-
-    if (value == JalviewFileChooser.APPROVE_OPTION)
+    int option = chooser.showSaveDialog(this);
+    if (option == JalviewFileChooser.APPROVE_OPTION)
     {
-      final Desktop me = this;
-      final java.io.File choice = chooser.getSelectedFile();
+      File choice = chooser.getSelectedFile();
       setProjectFile(choice);
 
       new Thread(new Runnable()
@@ -1682,7 +1679,7 @@ public class Desktop extends jalview.jbgui.GDesktop
             Cache.log.error(
                     "Problems whilst trying to save to " + choice.getName(),
                     ex);
-            JvOptionPane.showMessageDialog(me,
+            JvOptionPane.showMessageDialog(Desktop.this,
                     MessageManager.formatMessage(
                             "label.error_whilst_saving_current_state_to",
                             new Object[]
@@ -1693,10 +1690,10 @@ public class Desktop extends jalview.jbgui.GDesktop
           setProgressBar(null, choice.hashCode());
         }
       }).start();
-    }
+      }
   }
 
-  private void setProjectFile(File choice)
+  void setProjectFile(File choice)
   {
     this.projectFile = choice;
   }
@@ -1720,45 +1717,48 @@ public class Desktop extends jalview.jbgui.GDesktop
             "Jalview Project");
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager.getString("label.restore_state"));
-
-    int value = chooser.showOpenDialog(this);
-
-    if (value == JalviewFileChooser.APPROVE_OPTION)
+    chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
     {
-      final File selectedFile = chooser.getSelectedFile();
-      setProjectFile(selectedFile);
-      final String choice = selectedFile.getAbsolutePath();
-      Cache.setProperty("LAST_DIRECTORY", selectedFile.getParent());
-      new Thread(new Runnable()
+      @Override
+      public void run()
       {
-        @Override
-        public void run()
+        File selectedFile = chooser.getSelectedFile();
+        setProjectFile(selectedFile);
+        final String choice = selectedFile.getAbsolutePath();
+        Cache.setProperty("LAST_DIRECTORY", selectedFile.getParent());
+        new Thread(new Runnable()
         {
-          setProgressBar(MessageManager.formatMessage(
-                  "label.loading_jalview_project", new Object[]
-                  { choice }), choice.hashCode());
-          try
-          {
-            new Jalview2XML().loadJalviewAlign(choice);
-          } catch (OutOfMemoryError oom)
+          @Override
+          public void run()
           {
-            new OOMWarning("Whilst loading project from " + choice, oom);
-          } catch (Exception ex)
-          {
-            Cache.log.error(
-                    "Problems whilst loading project from " + choice, ex);
-            JvOptionPane.showMessageDialog(Desktop.desktop,
-                    MessageManager.formatMessage(
-                            "label.error_whilst_loading_project_from",
-                            new Object[]
-                            { choice }),
-                    MessageManager.getString("label.couldnt_load_project"),
-                    JvOptionPane.WARNING_MESSAGE);
+            setProgressBar(MessageManager.formatMessage(
+                    "label.loading_jalview_project", new Object[]
+                    { choice }), choice.hashCode());
+            try
+            {
+              new Jalview2XML().loadJalviewAlign(choice);
+            } catch (OutOfMemoryError oom)
+            {
+              new OOMWarning("Whilst loading project from " + choice, oom);
+            } catch (Exception ex)
+            {
+              Cache.log.error(
+                      "Problems whilst loading project from " + choice, ex);
+              JvOptionPane.showMessageDialog(Desktop.desktop,
+                      MessageManager.formatMessage(
+                              "label.error_whilst_loading_project_from",
+                              new Object[]
+                              { choice }),
+                      MessageManager.getString("label.couldnt_load_project"),
+                      JvOptionPane.WARNING_MESSAGE);
+            }
+            setProgressBar(null, choice.hashCode());
           }
-          setProgressBar(null, choice.hashCode());
-        }
-      }).start();
-    }
+        }).start();
+      }
+    });
+    
+    chooser.showOpenDialog(this);
   }
 
   @Override
index a0bd69e..ea3a667 100644 (file)
@@ -22,7 +22,6 @@ package jalview.gui;
 
 import jalview.api.FeatureColourI;
 import jalview.api.FeatureSettingsControllerI;
-import jalview.bin.Jalview;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.features.FeatureMatcher;
@@ -39,13 +38,13 @@ import jalview.schemabinding.version2.MatcherSet;
 import jalview.schemes.FeatureColour;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
+import jalview.util.dialogrunner.RunResponse;
 import jalview.viewmodel.seqfeatures.FeatureRendererModel.FeatureSettingsBean;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Dimension;
-import java.awt.FlowLayout;
 import java.awt.Font;
 import java.awt.Graphics;
 import java.awt.GridLayout;
@@ -874,23 +873,20 @@ public class FeatureSettings extends JPanel
    */
   void load()
   {
-    // TODO: JAL-3048 relies on Castor XML parsing: not needed for JS-jalview core
-    // functionalty
-
     JalviewFileChooser chooser = new JalviewFileChooser("fc",
             SEQUENCE_FEATURE_COLOURS);
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(
             MessageManager.getString("label.load_feature_colours"));
     chooser.setToolTipText(MessageManager.getString("action.load"));
-
-    int value = chooser.showOpenDialog(this);
-
-    if (value == JalviewFileChooser.APPROVE_OPTION)
-    {
-      File file = chooser.getSelectedFile();
-      load(file);
-    }
+    chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION){
+
+               @Override
+               public void run() {
+                     File file = chooser.getSelectedFile();
+                     load(file);
+               }});
+    chooser.showOpenDialog(this);
   }
 
   /**
@@ -959,20 +955,18 @@ public class FeatureSettings extends JPanel
    */
   void save()
   {
-    // TODO: JAL-3048 not needed for Jalview-JS - save colours
     JalviewFileChooser chooser = new JalviewFileChooser("fc",
             SEQUENCE_FEATURE_COLOURS);
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(
             MessageManager.getString("label.save_feature_colours"));
     chooser.setToolTipText(MessageManager.getString("action.save"));
-
-    int value = chooser.showSaveDialog(this);
-
-    if (value == JalviewFileChooser.APPROVE_OPTION)
-    {
-      save(chooser.getSelectedFile());
-    }
+    int option = chooser.showSaveDialog(this);
+       if (option == JalviewFileChooser.APPROVE_OPTION) 
+       {
+         File file = chooser.getSelectedFile();
+         save(file);
+       }
   }
 
   /**
@@ -1345,14 +1339,8 @@ public class FeatureSettings extends JPanel
     JPanel buttonPanel = new JPanel();
     buttonPanel.add(ok);
     buttonPanel.add(cancel);
-    if (!Jalview.isJS())
-    {
-      /*
-       * no save/load XML in JalviewJS for now
-       */
-      buttonPanel.add(loadColours);
-      buttonPanel.add(saveColours);
-    }
+    buttonPanel.add(loadColours);
+    buttonPanel.add(saveColours);
     bigPanel.add(scrollPane, BorderLayout.CENTER);
     settingsPane.add(bigPanel, BorderLayout.CENTER);
     settingsPane.add(buttonPanel, BorderLayout.SOUTH);
index 704cfea..bee1b14 100755 (executable)
@@ -34,6 +34,7 @@ import jalview.schemes.UserColourScheme;
 import jalview.util.ColorUtils;
 import jalview.util.Format;
 import jalview.util.MessageManager;
+import jalview.util.dialogrunner.RunResponse;
 
 import java.awt.Color;
 import java.awt.Font;
@@ -87,7 +88,7 @@ public class UserDefinedColours extends GUserDefinedColours
    * flag is true if the colour scheme has been changed since the
    * dialog was opened, or the changes last saved to file
    */
-  boolean changed;
+  boolean changedButNotSaved;
 
   JInternalFrame frame;
 
@@ -261,7 +262,7 @@ public class UserDefinedColours extends GUserDefinedColours
       button.setForeground(ColorUtils.brighterThan(newColour));
     }
 
-    changed = true;
+    changedButNotSaved = true;
   }
 
   /**
@@ -482,7 +483,7 @@ public class UserDefinedColours extends GUserDefinedColours
   {
     // BH 2018 no warning in JavaScript TODO
     
-    if (/** @j2sNative true || */ !changed)
+    if (/** @j2sNative true || */ !changedButNotSaved)
     {
       return;
     }
@@ -501,20 +502,20 @@ public class UserDefinedColours extends GUserDefinedColours
               question, title, JvOptionPane.DEFAULT_OPTION,
               JvOptionPane.PLAIN_MESSAGE, null, options, options[0]);
 
-      boolean saved = false;
       if (response == 0)
       {
         /*
-         * prompt to save changes to file
+         * prompt to save changes to file; if done,
+         * resets 'changed' flag to false
          */
-        saved = savebutton_actionPerformed();
+        savebutton_actionPerformed();
       }
 
       /*
        * if user chooses not to save (either in this dialog or in the
        * save as dialogs), treat this as a new user defined colour scheme
        */
-      if (!saved)
+      if (changedButNotSaved)
       {
         /*
          * clear scheme name and re-apply as an anonymous scheme
@@ -635,53 +636,51 @@ public class UserDefinedColours extends GUserDefinedColours
   {
     upperCaseButtons = new ArrayList<>();
     lowerCaseButtons = new ArrayList<>();
-    // TODO: JAL-3048 requires Castor dependency for Jalview-JS
     JalviewFileChooser chooser = new JalviewFileChooser("jc",
             "Jalview User Colours");
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(
             MessageManager.getString("label.load_colour_scheme"));
     chooser.setToolTipText(MessageManager.getString("action.load"));
-
-    int value = chooser.showOpenDialog(this);
-
-    if (value != JalviewFileChooser.APPROVE_OPTION)
-    {
-      return;
-    }
-    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.response(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.showOpenDialog(this);
   }
 
   /**
@@ -725,12 +724,10 @@ public class UserDefinedColours extends GUserDefinedColours
    * <li>Don't apply the changes if the currently selected scheme is different,
    * to allow a new scheme to be configured and saved but not applied</li>
    * </ul>
-   * Returns true if the scheme is saved to file, false if it is not
-   * 
-   * @return
+   * If the scheme is saved to file, the 'changed' flag field is reset to false.
    */
   @Override
-  protected boolean savebutton_actionPerformed()
+  protected void savebutton_actionPerformed()
   {
     String name = schemeName.getText().trim();
     if (name.length() < 1)
@@ -740,7 +737,6 @@ public class UserDefinedColours extends GUserDefinedColours
                       .getString("label.user_colour_scheme_must_have_name"),
               MessageManager.getString("label.no_name_colour_scheme"),
               JvOptionPane.WARNING_MESSAGE);
-      return false;
     }
 
     if (ColourSchemes.getInstance().nameExists(name))
@@ -754,10 +750,8 @@ public class UserDefinedColours extends GUserDefinedColours
               JvOptionPane.YES_NO_OPTION);
       if (reply != JvOptionPane.YES_OPTION)
       {
-        return false;
       }
     }
-    // TODO: JAL-3048 saveas, also requires Castor dependency for Jalview-JS
 
     JalviewFileChooser chooser = new JalviewFileChooser("jc",
             "Jalview User Colours");
@@ -767,31 +761,26 @@ public class UserDefinedColours extends GUserDefinedColours
     chooser.setDialogTitle(
             MessageManager.getString("label.save_colour_scheme"));
     chooser.setToolTipText(MessageManager.getString("action.save"));
-
-    int value = chooser.showSaveDialog(this);
-
-    if (value != JalviewFileChooser.APPROVE_OPTION)
-    {
-      return false;
-    }
-
-    File file = chooser.getSelectedFile();
-    UserColourScheme updatedScheme = addNewColourScheme(file.getPath());
-    saveToFile(file);
-    changed = false;
-
-    /*
-     * changes saved - apply to alignment if we are changing 
-     * the currently selected colour scheme; also make the updated
-     * colours the 'backout' scheme on Cancel
-     */
-    if (oldColourScheme != null
-            && name.equals(oldColourScheme.getSchemeName()))
-    {
-      oldColourScheme = updatedScheme;
-      applyButton_actionPerformed();
+    int option = chooser.showSaveDialog(this);
+    if (option == JalviewFileChooser.APPROVE_OPTION) 
+    {
+         File file = chooser.getSelectedFile();
+         UserColourScheme updatedScheme = addNewColourScheme(file.getPath());
+         saveToFile(file);
+         changedButNotSaved = false;
+
+         /*
+          * changes saved - apply to alignment if we are changing 
+          * the currently selected colour scheme; also make the updated
+          * colours the 'backout' scheme on Cancel
+          */
+         if (oldColourScheme != null
+                 && name.equals(oldColourScheme.getSchemeName()))
+         {
+           oldColourScheme = updatedScheme;
+           applyButton_actionPerformed();
+         }
     }
-    return true;
   }
 
   /**
index 4b4d28d..e66214f 100755 (executable)
@@ -441,13 +441,10 @@ public class GDesktop extends JFrame
     desktopMenubar.add(windowMenu);
     FileMenu.add(inputMenu);
     FileMenu.add(inputSequence);
-    if (!Jalview.isJS())
-    {
-      FileMenu.addSeparator();
-      FileMenu.add(saveState);
-      FileMenu.add(loadState);
-    }
-    FileMenu.addSeparator();
+       FileMenu.addSeparator();
+       FileMenu.add(saveState);
+       FileMenu.add(loadState);
+       FileMenu.addSeparator();
     FileMenu.add(quit);
     HelpMenu.add(aboutMenuItem);
     HelpMenu.add(documentationMenuItem);
index 1b2b069..359f787 100755 (executable)
@@ -75,7 +75,7 @@ public class GUserDefinedColours extends JPanel
 
   JLabel jLabel1 = new JLabel();
 
-  protected JTextField schemeName = new JTextField();
+  public JTextField schemeName = new JTextField();
 
   BorderLayout borderLayout1 = new BorderLayout();
 
@@ -103,9 +103,9 @@ public class GUserDefinedColours extends JPanel
 
   protected JPanel casePanel = new JPanel();
 
-  protected JCheckBox caseSensitive = new JCheckBox();
+  public JCheckBox caseSensitive = new JCheckBox();
 
-  protected JCheckBox lcaseColour = new JCheckBox();
+  public JCheckBox lcaseColour = new JCheckBox();
 
   protected List<JButton> selectedButtons;
 
@@ -231,10 +231,7 @@ public class GUserDefinedColours extends JPanel
     okCancelPanel.add(applyButton);
     okCancelPanel.add(okButton);
     okCancelPanel.add(cancelButton);
-    if (!Jalview.isJS())
-    {
-      lowerPanel.add(saveLoadPanel, java.awt.BorderLayout.NORTH);
-    }
+    lowerPanel.add(saveLoadPanel, java.awt.BorderLayout.NORTH);
     lowerPanel.add(okCancelPanel, java.awt.BorderLayout.SOUTH);
 
     namePanel.add(schemeName, java.awt.BorderLayout.CENTER);
@@ -290,9 +287,8 @@ public class GUserDefinedColours extends JPanel
   {
   }
 
-  protected boolean savebutton_actionPerformed()
+  protected void savebutton_actionPerformed()
   {
-    return false;
   }
 
   /**