JAL-360 JAL-3975 update parent for text colour dialog - doesn't seem to help but...
[jalview.git] / src / jalview / gui / TextColourChooser.java
index 91e05c6..f9ff337 100644 (file)
@@ -20,9 +20,6 @@
  */
 package jalview.gui;
 
-import jalview.datamodel.SequenceGroup;
-import jalview.util.MessageManager;
-
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Dimension;
@@ -32,13 +29,16 @@ import java.util.HashMap;
 import java.util.Map;
 
 import javax.swing.BorderFactory;
-import javax.swing.JColorChooser;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JSlider;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 
+import jalview.datamodel.SequenceGroup;
+import jalview.gui.JalviewColourChooser.ColourChooserListener;
+import jalview.util.MessageManager;
+
 public class TextColourChooser
 {
   AlignmentPanel ap;
@@ -64,7 +64,8 @@ public class TextColourChooser
    * @param sequenceGroup
    *          the SequenceGroup context (only for group pop-menu option)
    */
-  public void chooseColour(AlignmentPanel alignPanel, SequenceGroup sequenceGroup)
+  public void chooseColour(AlignmentPanel alignPanel,
+          SequenceGroup sequenceGroup)
   {
     this.ap = alignPanel;
     this.sg = sequenceGroup;
@@ -83,31 +84,36 @@ public class TextColourChooser
     col2.setToolTipText(MessageManager.getString("label.light_colour"));
     col2.setBackground(original2);
     final JPanel bigpanel = new JPanel(new BorderLayout());
-    JPanel panel = new JPanel();
+    JPanel panel = new JPanel(new BorderLayout());
     bigpanel.add(panel, BorderLayout.CENTER);
     bigpanel.add(
-            new JLabel(
-                    "<html>"
-                            + MessageManager
-                                    .getString("label.select_dark_light_set_threshold")
-                            + "</html>"), BorderLayout.NORTH);
-    panel.add(col1);
-    panel.add(slider);
-    panel.add(col2);
+            new JLabel("<html>"
+                    + MessageManager.getString(
+                            "label.select_dark_light_set_threshold")
+                    + "</html>"),
+            BorderLayout.NORTH);
+    panel.add(col1, BorderLayout.WEST);
+    panel.add(slider, BorderLayout.CENTER);
+    panel.add(col2, BorderLayout.EAST);
 
     col1.addMouseListener(new MouseAdapter()
     {
       @Override
       public void mousePressed(MouseEvent e)
       {
-        Color col = JColorChooser.showDialog(bigpanel,
-                MessageManager.getString("label.select_colour_for_text"),
-                col1.getBackground());
-        if (col != null)
+        String ttl = MessageManager
+                .getString("label.select_colour_for_text");
+        ColourChooserListener listener = new ColourChooserListener()
         {
-          colour1Changed(col);
-          col1.setBackground(col);
-        }
+          @Override
+          public void colourSelected(Color c)
+          {
+            colour1Changed(c);
+            col1.setBackground(c);
+          }
+        };
+        JalviewColourChooser.showColourChooser(bigpanel, ttl,
+                col1.getBackground(), listener);
       }
     });
 
@@ -116,14 +122,19 @@ public class TextColourChooser
       @Override
       public void mousePressed(MouseEvent e)
       {
-        Color col = JColorChooser.showDialog(bigpanel,
-                MessageManager.getString("label.select_colour_for_text"),
-                col2.getBackground());
-        if (col != null)
+        String ttl = MessageManager
+                .getString("label.select_colour_for_text");
+        ColourChooserListener listener = new ColourChooserListener()
         {
-          colour2Changed(col);
-          col2.setBackground(col);
-        }
+          @Override
+          public void colourSelected(Color c)
+          {
+            colour2Changed(c);
+            col2.setBackground(c);
+          }
+        };
+        JalviewColourChooser.showColourChooser(bigpanel, ttl,
+                col2.getBackground(), listener);
       }
     });
 
@@ -136,19 +147,23 @@ public class TextColourChooser
       }
     });
 
-    int reply = JvOptionPane
-            .showInternalOptionDialog(
-                    alignPanel,
-                    bigpanel,
-                    MessageManager
-                            .getString("label.adjunst_foreground_text_colour_threshold"),
-                    JvOptionPane.OK_CANCEL_OPTION,
-                    JvOptionPane.QUESTION_MESSAGE, null, null, null);
-
-    if (reply == JvOptionPane.CANCEL_OPTION)
+    Object[] options = new Object[] { MessageManager.getString("action.ok"),
+        MessageManager.getString("action.cancel") };
+    String title = MessageManager
+            .getString("label.adjust_foreground_text_colour_threshold");
+    Runnable action = new Runnable() // response for 1 = Cancel
     {
-      restoreInitialSettings();
-    }
+      @Override
+      public void run()
+      {
+        restoreInitialSettings();
+      }
+    };
+    JvOptionPane.newOptionDialog(alignPanel.alignFrame)
+            .setResponseHandler(1, action).showInternalDialog(bigpanel,
+                    title, JvOptionPane.YES_NO_CANCEL_OPTION,
+                    JvOptionPane.PLAIN_MESSAGE, null, options,
+                    MessageManager.getString("action.ok"));
   }
 
   /**
@@ -179,6 +194,8 @@ public class TextColourChooser
       group.textColour2 = groupColour2.get(group);
       group.thresholdTextColour = groupThreshold.get(group);
     }
+
+    ap.paintAlignment(false, false);
   }
 
   /**
@@ -186,9 +203,9 @@ public class TextColourChooser
    */
   protected void saveInitialSettings()
   {
-    groupColour1 = new HashMap<SequenceGroup, Color>();
-    groupColour2 = new HashMap<SequenceGroup, Color>();
-    groupThreshold = new HashMap<SequenceGroup, Integer>();
+    groupColour1 = new HashMap<>();
+    groupColour2 = new HashMap<>();
+    groupThreshold = new HashMap<>();
 
     if (sg == null)
     {
@@ -239,7 +256,7 @@ public class TextColourChooser
       sg.textColour = col;
     }
 
-    ap.paintAlignment(true);
+    ap.paintAlignment(false, false);
   }
 
   void colour2Changed(Color col)
@@ -257,7 +274,7 @@ public class TextColourChooser
       sg.textColour2 = col;
     }
 
-    ap.paintAlignment(true);
+    ap.paintAlignment(false, false);
   }
 
   void thresholdChanged(int value)
@@ -275,7 +292,7 @@ public class TextColourChooser
       sg.thresholdTextColour = value;
     }
 
-    ap.paintAlignment(true);
+    ap.paintAlignment(false, false);
   }
 
   void setGroupTextColour()