JAL-3058 refactored raising JColorChooser for JS compatibility
[jalview.git] / src / jalview / gui / FeatureTypeSettings.java
index fa9833b..5169dfb 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,9 +57,7 @@ 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.JDialog;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JRadioButton;
@@ -111,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;
 
@@ -126,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
@@ -142,29 +141,29 @@ 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();
 
-  private JPanel singleColour = new JPanel();
+  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();
 
@@ -196,7 +195,7 @@ public class FeatureTypeSettings extends JalviewDialog
   /*
    * filters for the currently selected feature type
    */
-  private List<FeatureMatcherI> filters;
+  List<FeatureMatcherI> filters;
 
   // set white normally, black to debug layout
   private Color debugBorderColour = Color.white;
@@ -759,7 +758,6 @@ public class FeatureTypeSettings extends JalviewDialog
           showColourChooser(singleColour, "label.select_colour");
         }
       }
-
     });
     
     singleColour.setFont(JvSwingUtils.getLabelFont());
@@ -843,29 +841,21 @@ public class FeatureTypeSettings extends JalviewDialog
    * @param key
    *          message bundle key for the dialog title
    */
-  private void showColourChooser(JPanel colourPanel, String key)
+  void showColourChooser(JPanel colourPanel, String key)
   {
-    // TODO 'final' is (currently) required here for SwingJS to work
-    JColorChooser colorChooser = new JColorChooser(); 
-    colorChooser.setColor(colourPanel.getBackground());
-
-    ActionListener listener = new ActionListener()
+    ColourChooserListener listener = new ColourChooserListener()
     {
       @Override
-      public void actionPerformed(ActionEvent e)
+      public void colourSelected(Color col)
       {
-        Color col = colorChooser.getColor();
         colourPanel.setBackground(col);
         colourPanel.setForeground(col);
         colourPanel.repaint();
         colourChanged(true);
       }
     };
-
-    JDialog dialog = JColorChooser.createDialog(this,
-            MessageManager.getString(key), true, colorChooser, listener,
-            null);
-    dialog.setVisible(true);
+    JalviewColourChooser.showColourChooser(this, MessageManager.getString(key),
+            colourPanel.getBackground(), listener);
   }
 
   /**
@@ -1552,7 +1542,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,