JAL-3187 fix for JAL-3533 on CDS/Protein tabbed feature settings
[jalview.git] / src / jalview / gui / SplitFrame.java
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