From be86b041dfcb2aa138e0d78b68fa1a9f6f714eec Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 3 Dec 2018 10:37:35 +0000 Subject: [PATCH] JAL-3058 provide cancel callback method for colour chooser --- src/jalview/gui/JalviewColourChooser.java | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/jalview/gui/JalviewColourChooser.java b/src/jalview/gui/JalviewColourChooser.java index e0c4eeb..6dc8a2b 100644 --- a/src/jalview/gui/JalviewColourChooser.java +++ b/src/jalview/gui/JalviewColourChooser.java @@ -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); } /** -- 1.7.10.2