Use textColourChooser
authoramwaterhouse <Andrew Waterhouse>
Tue, 21 Nov 2006 12:18:01 +0000 (12:18 +0000)
committeramwaterhouse <Andrew Waterhouse>
Tue, 21 Nov 2006 12:18:01 +0000 (12:18 +0000)
src/jalview/gui/AlignFrame.java
src/jalview/gui/PopupMenu.java

index 6899626..8fafb34 100755 (executable)
@@ -1959,112 +1959,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
 
   public void textColour_actionPerformed(ActionEvent e)
   {
-    int original1 = viewport.textColour.getRGB();
-    int original2 = viewport.textColour2.getRGB();
-    int thresh = viewport.thresholdTextColour;
-    final JSlider slider = new JSlider(0, 750, viewport.thresholdTextColour);
-    final JButton col1 = new JButton("DARK");
-    col1.setBackground(viewport.textColour);
-    col1.setForeground(viewport.textColour);
-    final JButton col2 = new JButton("LIGHT");
-    col2.setBackground(viewport.textColour2);
-    col2.setForeground(viewport.textColour2);
-    final JPanel bigpanel = new JPanel(new BorderLayout());
-    JPanel panel = new JPanel();
-    bigpanel.add(panel, BorderLayout.CENTER);
-    bigpanel.add(new JLabel(
-      "<html><i>Select a dark and light text colour, then set the threshold to"
-     +"<br>switch between colours, based on background colour</i></html>"),
-                 BorderLayout.NORTH);
-    panel.add(col1);
-    panel.add(slider);
-    panel.add(col2);
-
-    col1.addActionListener(new ActionListener()
-        {
-          public void actionPerformed(ActionEvent e)
-          {
-            Color col = JColorChooser.showDialog(bigpanel,
-                                                 "Select Colour for Text",
-                                                 viewport.textColour);
-            if (col != null)
-            {
-              viewport.textColour = col;
-              col1.setBackground(col);
-              col1.setForeground(col);
-              if(viewport.colourAppliesToAllGroups)
-                setGroupTextColour();
-            }
-            alignPanel.repaint();
-          }
-        });
-
-    col2.addActionListener(new ActionListener()
-    {
-      public void actionPerformed(ActionEvent e)
-      {
-        Color col = JColorChooser.showDialog(bigpanel,
-                                             "Select Colour for Text",
-                                             viewport.textColour);
-        if (col != null)
-        {
-          viewport.textColour2 = col;
-          col2.setBackground(col);
-          col2.setForeground(col);
-          if(viewport.colourAppliesToAllGroups)
-                setGroupTextColour();
-        }
-        alignPanel.repaint();
-      }
-    });
-
-
-    slider.addChangeListener(new ChangeListener()
-    {
-      public void stateChanged(ChangeEvent evt)
-      {
-        viewport.thresholdTextColour = slider.getValue();
-        if(viewport.colourAppliesToAllGroups)
-                setGroupTextColour();
-        alignPanel.repaint();
-      }
-    });
-
-    int reply = JOptionPane.showInternalOptionDialog(this,
-                                                 bigpanel,
-                                                 "Adjust Foreground Text Colour Threshold",
-                                                 JOptionPane.OK_CANCEL_OPTION,
-                                                 JOptionPane.QUESTION_MESSAGE,
-                                                 null,
-                                                 null, null);
-
-    if(reply==JOptionPane.CANCEL_OPTION)
-    {
-      viewport.textColour = new Color(original1);
-      viewport.textColour2 = new Color(original2);
-      viewport.thresholdTextColour = thresh;
-    }
+    new TextColourChooser().chooseColour(alignPanel, null);
   }
 
-  void setGroupTextColour()
-  {
-    if(viewport.alignment.getGroups()==null)
-      return;
-
-    Vector groups = viewport.alignment.getGroups();
-
-    for(int i=0; i<groups.size(); i++)
-    {
-      SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
-      sg.textColour = viewport.textColour;
-      sg.textColour2 = viewport.textColour2;
-      sg.thresholdTextColour = viewport.thresholdTextColour;
-    }
-
-
-  }
-
-
   /**
    * DOCUMENT ME!
    *
index 206a969..f0d307b 100755 (executable)
@@ -1360,86 +1360,8 @@ public class PopupMenu extends JPopupMenu
 \r
   public void textColour_actionPerformed(ActionEvent e)\r
   {\r
-    final SequenceGroup sg = getGroup();\r
-\r
-    int original1 = sg.textColour.getRGB();\r
-    int original2 = sg.textColour2.getRGB();\r
-    int thresh = sg.thresholdTextColour;\r
-    final JSlider slider = new JSlider(0, 750,sg.thresholdTextColour);\r
-    final JButton col1 = new JButton("DARK");\r
-    col1.setBackground(sg.textColour);\r
-    col1.setForeground(sg.textColour);\r
-    final JButton col2 = new JButton("LIGHT");\r
-    col2.setBackground(sg.textColour2);\r
-    col2.setForeground(sg.textColour2);\r
-    final JPanel bigpanel = new JPanel(new BorderLayout());\r
-    JPanel panel = new JPanel();\r
-    bigpanel.add(panel, BorderLayout.CENTER);\r
-    bigpanel.add(new JLabel(\r
-      "<html><i>Select a dark and light text colour, then set the threshold to"\r
-     +"<br>switch between colours, based on background colour</i></html>"),\r
-                 BorderLayout.NORTH);\r
-    panel.add(col1);\r
-    panel.add(slider);\r
-    panel.add(col2);\r
-\r
-    col1.addActionListener(new ActionListener()\r
-        {\r
-          public void actionPerformed(ActionEvent e)\r
-          {\r
-            Color col = JColorChooser.showDialog(bigpanel,\r
-                                                 "Select Colour for Text",\r
-                                                 sg.textColour);\r
-            if (col != null)\r
-            {\r
-              sg.textColour = col;\r
-              col1.setBackground(col);\r
-              col1.setForeground(col);\r
-            }\r
-            ap.repaint();\r
-          }\r
-        });\r
-\r
-    col2.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        Color col = JColorChooser.showDialog(bigpanel,\r
-                                             "Select Colour for Text",\r
-                                             sg.textColour);\r
-        if (col != null)\r
-        {\r
-          sg.textColour2 = col;\r
-          col2.setBackground(col);\r
-          col2.setForeground(col);\r
-        }\r
-        ap.repaint();\r
-      }\r
-    });\r
-\r
-\r
-    slider.addChangeListener(new ChangeListener()\r
-    {\r
-      public void stateChanged(ChangeEvent evt)\r
-      {\r
-        sg.thresholdTextColour = slider.getValue();\r
-        ap.repaint();\r
-      }\r
-    });\r
-\r
-    int reply = JOptionPane.showInternalOptionDialog(Desktop.desktop,\r
-                                                 bigpanel,\r
-                                                 "Adjust Foreground Text Colour Threshold",\r
-                                                 JOptionPane.OK_CANCEL_OPTION,\r
-                                                 JOptionPane.QUESTION_MESSAGE,\r
-                                                 null,\r
-                                                 null, null);\r
-\r
-    if(reply==JOptionPane.CANCEL_OPTION)\r
-    {\r
-      sg.textColour = new Color(original1);\r
-      sg.textColour2 = new Color(original2);\r
-      sg.thresholdTextColour = thresh;\r
-    }\r
+    SequenceGroup sg = getGroup();\r
+    if (sg != null)\r
+      new TextColourChooser().chooseColour(ap, sg);\r
   }\r
 }\r