Merge branch 'feature/JAL-3143ensemblJSON' into
[jalview.git] / src / jalview / gui / FeatureTypeSettings.java
index 55bc519..a6b986e 100644 (file)
@@ -29,6 +29,7 @@ import jalview.datamodel.features.FeatureMatcher;
 import jalview.datamodel.features.FeatureMatcherI;
 import jalview.datamodel.features.FeatureMatcherSet;
 import jalview.datamodel.features.FeatureMatcherSetI;
+import jalview.gui.JalviewColourChooser.ColourChooserListener;
 import jalview.schemes.FeatureColour;
 import jalview.util.ColorUtils;
 import jalview.util.MessageManager;
@@ -56,18 +57,15 @@ import javax.swing.BoxLayout;
 import javax.swing.ButtonGroup;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
-import javax.swing.JColorChooser;
 import javax.swing.JComboBox;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JRadioButton;
 import javax.swing.JSlider;
 import javax.swing.JTextField;
-import javax.swing.SwingConstants;
 import javax.swing.border.LineBorder;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
-import javax.swing.plaf.basic.BasicArrowButton;
 
 /**
  * A dialog where the user can configure colour scheme, and any filters, for one
@@ -112,7 +110,7 @@ public class FeatureTypeSettings extends JalviewDialog
   /*
    * the view panel to update when settings change
    */
-  private final AlignmentViewPanel ap;
+  final AlignmentViewPanel ap;
 
   private final String featureType;
 
@@ -127,7 +125,7 @@ public class FeatureTypeSettings extends JalviewDialog
    * set flag to true when setting values programmatically,
    * to avoid invocation of action handlers
    */
-  private boolean adjusting = false;
+  boolean adjusting = false;
 
   /*
    * minimum of the value range for graduated colour
@@ -143,34 +141,33 @@ public class FeatureTypeSettings extends JalviewDialog
   /*
    * scale factor for conversion between absolute min-max and slider
    */
-  private float scaleFactor;
+  float scaleFactor;
 
   /*
    * radio button group, to select what to colour by:
    * simple colour, by category (text), or graduated
    */
-  private JRadioButton simpleColour = new JRadioButton();
+  JRadioButton simpleColour = new JRadioButton();
 
-  private JRadioButton byCategory = new JRadioButton();
+  JRadioButton byCategory = new JRadioButton();
 
-  private JRadioButton graduatedColour = new JRadioButton();
+  JRadioButton graduatedColour = new JRadioButton();
 
-  /**
-   * colours and filters are shown in tabbed view or single content pane
-   */
-  JPanel coloursPanel, filtersPanel;
+  JPanel coloursPanel;
+  
+  JPanel filtersPanel;
 
   JPanel singleColour = new JPanel();
 
-  private JPanel minColour = new JPanel();
+  JPanel minColour = new JPanel();
 
-  private JPanel maxColour = new JPanel();
+  JPanel maxColour = new JPanel();
 
   private JComboBox<String> threshold = new JComboBox<>();
 
-  private JSlider slider = new JSlider();
+  JSlider slider = new JSlider();
 
-  private JTextField thresholdValue = new JTextField(20);
+  JTextField thresholdValue = new JTextField(20);
 
   private JCheckBox thresholdIsMin = new JCheckBox();
 
@@ -202,7 +199,7 @@ public class FeatureTypeSettings extends JalviewDialog
   /*
    * filters for the currently selected feature type
    */
-  private List<FeatureMatcherI> filters;
+  List<FeatureMatcherI> filters;
 
   private JPanel chooseFiltersPanel;
 
@@ -231,9 +228,9 @@ public class FeatureTypeSettings extends JalviewDialog
       return;
     }
     
-    updateColoursTab();
+    updateColoursPanel();
     
-    updateFiltersTab();
+    updateFiltersPanel();
     
     adjusting = false;
     
@@ -243,15 +240,14 @@ public class FeatureTypeSettings extends JalviewDialog
             .formatMessage("label.display_settings_for", new String[]
             { theType });
     initDialogFrame(this, true, false, title, 500, 500);
-    
     waitForInput();
   }
 
   /**
-   * Configures the widgets on the Colours tab according to the current feature
+   * Configures the widgets on the Colours panel according to the current feature
    * colour scheme
    */
-  private void updateColoursTab()
+  private void updateColoursPanel()
   {
     FeatureColourI fc = fr.getFeatureColours().get(featureType);
 
@@ -403,13 +399,13 @@ public class FeatureTypeSettings extends JalviewDialog
     };
 
     /*
-     * first panel/tab: colour options
+     * first panel: colour options
      */
     JPanel coloursPanel = initialiseColoursPanel();
     this.add(coloursPanel, BorderLayout.NORTH);
 
     /*
-     * second panel/tab: filter options
+     * second panel: filter options
      */
     JPanel filtersPanel = initialiseFiltersPanel();
     this.add(filtersPanel, BorderLayout.CENTER);
@@ -826,17 +822,31 @@ public class FeatureTypeSettings extends JalviewDialog
     return colourByPanel;
   }
 
-  private void showColourChooser(JPanel colourPanel, String key)
+  /**
+   * Shows a colour chooser dialog, and if a selection is made, updates the
+   * colour of the given panel
+   * 
+   * @param colourPanel
+   *          the panel whose background colour is being picked
+   * @param key
+   *          message bundle key for the dialog title
+   */
+  void showColourChooser(JPanel colourPanel, String key)
   {
-    Color col = JColorChooser.showDialog(this,
-            MessageManager.getString(key), colourPanel.getBackground());
-    if (col != null)
+    ColourChooserListener listener = new ColourChooserListener()
     {
-      colourPanel.setBackground(col);
-      colourPanel.setForeground(col);
-    }
-    colourPanel.repaint();
-    colourChanged(true);
+      @Override
+      public void colourSelected(Color col)
+      {
+        colourPanel.setBackground(col);
+        colourPanel.setForeground(col);
+        colourPanel.repaint();
+        colourChanged(true);
+      }
+    };
+    JalviewColourChooser.showColourChooser(this,
+            MessageManager.getString(key), colourPanel.getBackground(),
+            listener);
   }
 
   /**
@@ -870,7 +880,7 @@ public class FeatureTypeSettings extends JalviewDialog
     fr.setColour(featureType, acg);
     ap.paintAlignment(updateStructsAndOverview, updateStructsAndOverview);
 
-    updateColoursTab();
+    updateColoursPanel();
   }
 
   /**
@@ -933,7 +943,7 @@ public class FeatureTypeSettings extends JalviewDialog
      */
     float minValue = min;
     float maxValue = max;
-    final int thresholdOption = threshold.getSelectedIndex();
+    int thresholdOption = threshold.getSelectedIndex();
     if (thresholdIsMin.isSelected()
             && thresholdOption == ABOVE_THRESHOLD_OPTION)
     {
@@ -1208,7 +1218,7 @@ public class FeatureTypeSettings extends JalviewDialog
    * for adding a condition. This should be called after a filter has been
    * removed, added or amended.
    */
-  private void updateFiltersTab()
+  private void updateFiltersPanel()
   {
     /*
      * clear the panel and list of filter conditions
@@ -1232,7 +1242,12 @@ public class FeatureTypeSettings extends JalviewDialog
       {
         orFilters.setSelected(true);
       }
-      featureFilters.getMatchers().forEach(matcher -> filters.add(matcher));
+      // avoid use of lambda expression to keep SwingJS happy
+      // featureFilters.getMatchers().forEach(item -> filters.add(item));
+      for (FeatureMatcherI matcher : featureFilters.getMatchers())
+      {
+        filters.add(matcher);
+      }
     }
 
     /*
@@ -1310,8 +1325,8 @@ public class FeatureTypeSettings extends JalviewDialog
      * drop-down choice of attribute, with description as a tooltip 
      * if we can obtain it
      */
-    final JComboBox<String> attCombo = populateAttributesDropdown(attNames,
-            true, true);
+    JComboBox<String> attCombo = populateAttributesDropdown(attNames, true,
+            true);
     String filterBy = setSelectedAttribute(attCombo, filter);
 
     JComboBox<Condition> condCombo = new JComboBox<>();
@@ -1412,8 +1427,8 @@ public class FeatureTypeSettings extends JalviewDialog
     if (!patternField.isEnabled()
             || (pattern != null && pattern.trim().length() > 0))
     {
-      // todo: gif for button drawing '-' or 'x'
-      JButton removeCondition = new BasicArrowButton(SwingConstants.WEST);
+      JButton removeCondition = new JButton("\u2717"); // Dingbats cursive x
+      removeCondition.setPreferredSize(new Dimension(23, 17));
       removeCondition
               .setToolTipText(MessageManager.getString("label.delete_row"));
       removeCondition.addActionListener(new ActionListener()
@@ -1517,7 +1532,7 @@ public class FeatureTypeSettings extends JalviewDialog
    * @param condCombo
    * @param patternField
    */
-  private void populateConditions(String attName, Condition cond,
+  void populateConditions(String attName, Condition cond,
           JComboBox<Condition> condCombo, JTextField patternField)
   {
     Datatype type = FeatureAttributes.getInstance().getDatatype(featureType,
@@ -1738,6 +1753,6 @@ public class FeatureTypeSettings extends JalviewDialog
     fr.setFeatureFilter(featureType, combined.isEmpty() ? null : combined);
     ap.paintAlignment(true, true);
 
-    updateFiltersTab();
+    updateFiltersPanel();
   }
 }