JAL-3187 fix for JAL-3533 on CDS/Protein tabbed feature settings
authorJim Procter <jprocter@issues.jalview.org>
Mon, 17 Feb 2020 14:45:18 +0000 (14:45 +0000)
committerJim Procter <jprocter@issues.jalview.org>
Mon, 17 Feb 2020 14:45:18 +0000 (14:45 +0000)
resources/lang/Messages.properties
src/jalview/api/SplitContainerI.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/FeatureSettings.java
src/jalview/gui/SplitFrame.java

index 470cd4b..042ce28 100644 (file)
@@ -228,6 +228,7 @@ label.nucleotide = Nucleotide
 label.protein = Protein
 label.nucleotides = Nucleotides
 label.proteins = Proteins
+label.CDS = CDS
 label.to_new_alignment = To New Alignment
 label.to_this_alignment = Add To This Alignment
 label.apply_colour_to_all_groups = Apply Colour To All Groups
@@ -765,6 +766,7 @@ label.generating_features_for_params = Generating features for - {0}
 label.generating_annotations_for_params = Generating annotations for - {0}
 label.varna_params = VARNA - {0}
 label.sequence_feature_settings = Sequence Feature Settings
+label.sequence_feature_settings_for = Sequence Feature Settings for {0}
 label.sequence_feature_settings_for_view = Sequence Feature Settings for view "{0}"
 label.pairwise_aligned_sequences = Pairwise Aligned Sequences
 label.original_data_for_params = Original Data for {0}
index 66d8bd1..d68aa36 100644 (file)
@@ -76,10 +76,15 @@ public interface SplitContainerI
           FeatureSettingsControllerGuiI featureSettings);
 
   /**
-   * Request to close all feature settings originating from a particular panel
+   * Request to close all feature settings originating from a particular panel.
    * 
    * @param featureSettings
+   * @param closeContainingFrame
+   *                               - if false then the tab containing the feature
+   *                               settings will be 'reset' ready for a new
+   *                               feature settings
    */
-  void closeFeatureSettings(FeatureSettingsControllerI featureSettings);
+  void closeFeatureSettings(FeatureSettingsControllerI featureSettings,
+          boolean closeContainingFrame);
 
 }
index 2559a91..5413c4b 100644 (file)
@@ -3195,7 +3195,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     if (featureSettings != null)
     {
-      featureSettings.close();
+      featureSettings.closeOldSettings();
       featureSettings = null;
     }
     if (!showSeqFeatures.isSelected())
index 4b0a0bc..2fbbdf2 100644 (file)
@@ -1123,8 +1123,25 @@ public class FeatureSettings extends JPanel
     table.repaint();
   }
 
+  /**
+   * close ourselves but leave any existing UI handlers (e.g a CDS/Protein tabbed
+   * feature settings dialog) intact
+   */
+  public void closeOldSettings()
+  {
+    closeDialog(false);
+  }
+
+  /**
+   * close the feature settings dialog (and any containing frame)
+   */
   public void close()
   {
+    closeDialog(true);
+  }
+
+  private void closeDialog(boolean closeContainingFrame)
+  {
     try
     {
       if (frame != null)
index 513303f..5117e3d 100644 (file)
@@ -869,29 +869,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI
               "Feature Settings for CDS and Protein Views");
       featureSettingsPanels.setOpaque(true);
       featureSettingsUI.setContentPane(featureSettingsPanels);
-      JPanel dummyDNA = new JPanel(),dummyProtein=new JPanel();
-      FocusListener fl1 = new FocusListener()
-      {
-
-        @Override
-        public void focusLost(FocusEvent e)
-        {
-          // TODO Auto-generated method stub
-
-        }
-
-        @Override
-        public void focusGained(FocusEvent e)
-        {
-          int tab = featureSettingsPanels.getSelectedIndex();
-          getAlignFrames().get(tab).showFeatureSettingsUI();
-        }
-      };
-      dummyDNA.addFocusListener(fl1);
-      dummyProtein.addFocusListener(fl1);
-      
-      featureSettingsPanels.addTab("CDS", dummyDNA);
-      featureSettingsPanels.addTab("Protein", dummyProtein);
+      createDummyTabs();
     }
     if (featureSettingsPanels
             .indexOfTabComponent((Component) featureSettings) > -1)
@@ -967,19 +945,97 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI
     }
   }
 
+  /*
+   * for materialising feature settings for a tab when clicked on
+   */
+  private FocusListener fl1 = new FocusListener()
+  {
+
+    @Override
+    public void focusLost(FocusEvent e)
+    {
+      // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void focusGained(FocusEvent e)
+    {
+      int tab = featureSettingsPanels.getSelectedIndex();
+      getAlignFrames().get(tab).showFeatureSettingsUI();
+    }
+  };
+
+  /**
+   * tab names for feature settings
+   */
+  private String[] tabName = new String[] {
+      MessageManager.getString("label.CDS"),
+      MessageManager.getString("label.Protein") };
+
+  /**
+   * create placeholder tabs which materialise the feature settings for a given
+   * view. Also reinitialises any tabs containing stale feature settings
+   */
+  private void createDummyTabs()
+  {
+    for (int tabIndex = 0; tabIndex < 2; tabIndex++)
+    {
+      JPanel dummyTab = new JPanel();
+      dummyTab.addFocusListener(fl1);
+      featureSettingsPanels.addTab(tabName[tabIndex], dummyTab);
+    }
+  }
+
+  private void replaceWithDummyTab(FeatureSettingsControllerI toClose)
+  {
+    Component dummyTab = null;
+    for (int tabIndex = 0; tabIndex < 2; tabIndex++)
+    {
+      if (featureSettingsPanels.getTabCount() > tabIndex)
+    {
+        dummyTab = featureSettingsPanels.getTabComponentAt(tabIndex);
+        if (dummyTab instanceof FeatureSettingsControllerGuiI
+                && !dummyTab.isVisible())
+      {
+          featureSettingsPanels.removeTabAt(tabIndex);
+          // close the feature Settings tab
+          ((FeatureSettingsControllerGuiI) dummyTab)
+                  .featureSettings_isClosed();
+          // create a dummy tab in its place
+        dummyTab = new JPanel();
+        dummyTab.addFocusListener(fl1);
+          featureSettingsPanels.insertTab(tabName[tabIndex], null, dummyTab,
+                  MessageManager.formatMessage(
+                          "label.sequence_feature_settings_for",
+                          tabName[tabIndex]),
+                  tabIndex);
+      }
+    }
+    }
+  }
+
   @Override
   public void closeFeatureSettings(
-          FeatureSettingsControllerI featureSettings)
+          FeatureSettingsControllerI featureSettings,
+          boolean closeContainingFrame)
   {
     if (featureSettingsUI != null)
     {
-      try
+      if (closeContainingFrame)
       {
-        featureSettingsUI.setClosed(true);
-      } catch (Exception x)
+        try
+        {
+          featureSettingsUI.setClosed(true);
+        } catch (Exception x)
+        {
+        }
+        featureSettingsUI = null;
+      }
+      else
       {
+        replaceWithDummyTab(featureSettings);
       }
-      featureSettingsUI = null;
     }
   }
 }
\ No newline at end of file