JAL-3010 tidy placement of 'Apply to sub-types' checkbox
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 4 Jun 2018 08:02:44 +0000 (09:02 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 4 Jun 2018 08:02:44 +0000 (09:02 +0100)
src/jalview/gui/FeatureTypeSettings.java

index e412274..b938b7a 100644 (file)
@@ -219,16 +219,10 @@ public class FeatureTypeSettings extends JalviewDialog
   private final List<String> subTypes;
 
   /*
-   * if selected, filter settings are also applied to any 
-   * feature sub-types in the Sequence Ontology
-   */
-  private JCheckBox applyFiltersToSubtypes;
-
-  /*
    * if selected, colour settings are also applied to any 
    * feature sub-types in the Sequence Ontology
    */
-  private JCheckBox applyColourToSubtypes;
+  private JCheckBox applyToSubtypes;
 
   /**
    * Constructor
@@ -787,12 +781,7 @@ public class FeatureTypeSettings extends JalviewDialog
      */
     if (!subTypes.isEmpty())
     {
-      JPanel toSubtypes = new JPanel(new FlowLayout(FlowLayout.RIGHT));
-      toSubtypes.setBackground(Color.WHITE);
-      applyColourToSubtypes = new JCheckBox("Apply also to child terms");
-      applyColourToSubtypes.setToolTipText(getSubtypesTooltip());
-      toSubtypes.add(applyColourToSubtypes);
-      colourByPanel.add(toSubtypes);
+      colourByPanel.add(initSubtypesPanel());
     }
 
     /*
@@ -892,6 +881,23 @@ public class FeatureTypeSettings extends JalviewDialog
     return colourByPanel;
   }
 
+  /**
+   * Constructs and returns a panel with a checkbox for the option to apply any
+   * changes also to sub-types of the feature type
+   * 
+   * @return
+   */
+  protected JPanel initSubtypesPanel()
+  {
+    JPanel toSubtypes = new JPanel(new FlowLayout(FlowLayout.LEFT));
+    toSubtypes.setBackground(Color.WHITE);
+    applyToSubtypes = new JCheckBox(
+            "Apply changes also to sub-types of " + featureType);
+    applyToSubtypes.setToolTipText(getSubtypesTooltip());
+    toSubtypes.add(applyToSubtypes);
+    return toSubtypes;
+  }
+
   private void showColourChooser(JPanel colourPanel, String key)
   {
     Color col = JColorChooser.showDialog(this,
@@ -934,7 +940,7 @@ public class FeatureTypeSettings extends JalviewDialog
      * save the colour, and set on subtypes if selected
      */
     fr.setColour(featureType, acg);
-    if (applyColourToSubtypes.isSelected())
+    if (applyToSubtypes.isSelected())
     {
       for (String child : subTypes)
       {
@@ -1238,11 +1244,24 @@ public class FeatureTypeSettings extends JalviewDialog
   {
     filters = new ArrayList<>();
 
+    JPanel outerPanel = new JPanel();
+    outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.Y_AXIS));
+    outerPanel.setBackground(Color.white);
+
+    /*
+     * option to apply colour to sub-types as well (if there are any)
+     */
+    if (!subTypes.isEmpty())
+    {
+      outerPanel.add(initSubtypesPanel());
+    }
+
     JPanel filtersPanel = new JPanel();
     filtersPanel.setLayout(new BoxLayout(filtersPanel, BoxLayout.Y_AXIS));
     filtersPanel.setBackground(Color.white);
     JvSwingUtils.createTitledBorder(filtersPanel,
             MessageManager.getString("label.filters"), true);
+    outerPanel.add(filtersPanel);
 
     JPanel andOrPanel = initialiseAndOrPanel();
     filtersPanel.add(andOrPanel);
@@ -1255,7 +1274,7 @@ public class FeatureTypeSettings extends JalviewDialog
     chooseFiltersPanel.setBackground(Color.white);
     filtersPanel.add(chooseFiltersPanel);
 
-    return filtersPanel;
+    return outerPanel;
   }
 
   /**
@@ -1292,20 +1311,6 @@ public class FeatureTypeSettings extends JalviewDialog
     panel1.add(andFilters);
     panel1.add(orFilters);
 
-    /*
-     * add an 'Apply to child terms' checkbox if there are any child terms
-     */
-    applyFiltersToSubtypes = new JCheckBox("Apply also to child terms");
-    if (!subTypes.isEmpty())
-    {
-      JPanel panel2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
-      panel2.setBackground(Color.white);
-      andOrPanel.add(panel2, BorderLayout.EAST);
-      String tooltip = getSubtypesTooltip();
-      applyFiltersToSubtypes.setToolTipText(tooltip);
-      panel2.add(applyFiltersToSubtypes);
-    }
-
     return andOrPanel;
   }
 
@@ -1318,7 +1323,7 @@ public class FeatureTypeSettings extends JalviewDialog
   protected String getSubtypesTooltip()
   {
     StringBuilder sb = new StringBuilder(20 * subTypes.size());
-    sb.append("Apply filters also to child terms" + ":"); // todo i18n
+    sb.append("Apply settings also to" + ":"); // todo i18n
     for (String child : subTypes)
     {
       sb.append("<br>").append(child);
@@ -1871,7 +1876,7 @@ public class FeatureTypeSettings extends JalviewDialog
      * (note this might now be an empty filter with no conditions)
      */
     fr.setFeatureFilter(featureType, combined.isEmpty() ? null : combined);
-    if (applyFiltersToSubtypes.isSelected())
+    if (applyToSubtypes.isSelected())
     {
       for (String child : subTypes)
       {