JAL-3058 provide cancel callback method for colour chooser
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 3 Dec 2018 10:37:35 +0000 (10:37 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 3 Dec 2018 10:37:35 +0000 (10:37 +0000)
src/jalview/gui/JalviewColourChooser.java

index e0c4eeb..6dc8a2b 100644 (file)
@@ -1,16 +1,12 @@
 package jalview.gui;
 
-import jalview.gui.JalviewColourChooser.ColourChooserListener;
-
 import java.awt.Color;
 import java.awt.Component;
-import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 
 import javax.swing.JColorChooser;
 import javax.swing.JComponent;
 import javax.swing.JDialog;
-import javax.swing.JPanel;
 
 /**
  * A helper class that shows a JColorChooser and passes the selected colour back
@@ -21,6 +17,8 @@ public class JalviewColourChooser
   public interface ColourChooserListener
   {
     void colourSelected(Color c);
+    
+    default void cancel() {};
   }
 
   /**
@@ -41,17 +39,11 @@ public class JalviewColourChooser
     {
       colorChooser.setColor(initialColour);
     }
-    ActionListener al = new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        listener.colourSelected(colorChooser.getColor());
-      };
-    };
-    JDialog dialog = JColorChooser.createDialog(parent, title, true,
-            colorChooser, al, null);
-    dialog.setVisible(true);
+    ActionListener onChoose = evt -> listener.colourSelected(colorChooser.getColor());
+    ActionListener onCancel = evt -> listener.cancel();
+       JDialog dialog = JColorChooser.createDialog(parent, title, true, colorChooser,
+               onChoose, onCancel);
+       dialog.setVisible(true);
   }
 
   /**