From: gmungoc Date: Mon, 3 Dec 2018 10:37:35 +0000 (+0000) Subject: JAL-3058 provide cancel callback method for colour chooser X-Git-Tag: Release_2_11_4_0~45^2~18^2~361^2~2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=be86b041dfcb2aa138e0d78b68fa1a9f6f714eec;p=jalview.git JAL-3058 provide cancel callback method for colour chooser --- 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); } /**