From: gmungoc Date: Thu, 5 Jul 2018 08:03:39 +0000 (+0100) Subject: JAL-3058 refactored raising JColorChooser for JS compatibility X-Git-Tag: Release_2_11_4_0~45^2~18^2~585^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=217274a8e9ea2ae20d5a6d21989b8b16840ca6f0;p=jalview.git JAL-3058 refactored raising JColorChooser for JS compatibility --- diff --git a/src/jalview/gui/AnnotationColourChooser.java b/src/jalview/gui/AnnotationColourChooser.java index 384635b..b547214 100644 --- a/src/jalview/gui/AnnotationColourChooser.java +++ b/src/jalview/gui/AnnotationColourChooser.java @@ -24,6 +24,7 @@ import jalview.bin.Cache; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.GraphLine; import jalview.datamodel.SequenceGroup; +import jalview.gui.JalviewColourChooser.ColourChooserListener; import jalview.schemes.AnnotationColourGradient; import jalview.schemes.ColourSchemeI; import jalview.util.MessageManager; @@ -42,7 +43,6 @@ import java.util.Vector; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JCheckBox; -import javax.swing.JColorChooser; import javax.swing.JComboBox; import javax.swing.JInternalFrame; import javax.swing.JLayeredPane; @@ -63,9 +63,9 @@ public class AnnotationColourChooser extends AnnotationRowFilter private JCheckBox useOriginalColours = new JCheckBox(); - private JPanel minColour = new JPanel(); + JPanel minColour = new JPanel(); - private JPanel maxColour = new JPanel(); + JPanel maxColour = new JPanel(); private JCheckBox thresholdIsMin = new JCheckBox(); @@ -174,7 +174,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter { if (minColour.isEnabled()) { - minColour_actionPerformed(); + showColourChooser(minColour, "label.select_colour_minimum_value"); } } }); @@ -189,7 +189,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter { if (maxColour.isEnabled()) { - maxColour_actionPerformed(); + showColourChooser(maxColour, "label.select_colour_maximum_value"); } } }); @@ -288,30 +288,21 @@ public class AnnotationColourChooser extends AnnotationRowFilter Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red)); } - public void minColour_actionPerformed() + protected void showColourChooser(JPanel colourPanel, String titleKey) { - Color col = JColorChooser.showDialog(this, - MessageManager.getString("label.select_colour_minimum_value"), - minColour.getBackground()); - if (col != null) + String ttl = MessageManager.getString(titleKey); + ColourChooserListener listener = new ColourChooserListener() { - minColour.setBackground(col); - } - minColour.repaint(); - updateView(); - } - - public void maxColour_actionPerformed() - { - Color col = JColorChooser.showDialog(this, - MessageManager.getString("label.select_colour_maximum_value"), - maxColour.getBackground()); - if (col != null) - { - maxColour.setBackground(col); - } - maxColour.repaint(); - updateView(); + @Override + public void colourSelected(Color c) + { + colourPanel.setBackground(c); + colourPanel.repaint(); + updateView(); + } + }; + JalviewColourChooser.showColourChooser(Desktop.getDesktop(), ttl, + colourPanel.getBackground(), listener); } @Override diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index bf8c709..49d4554 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -25,8 +25,10 @@ import jalview.datamodel.Annotation; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceI; +import jalview.gui.JalviewColourChooser.ColourChooserListener; import jalview.renderer.AnnotationRenderer; import jalview.renderer.AwtRenderPanelI; +import jalview.schemes.FeatureColour; import jalview.schemes.ResidueProperties; import jalview.util.Comparison; import jalview.util.MessageManager; @@ -341,12 +343,12 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, else if (action.equals(COLOUR)) { final Annotation[] fAnot = anot; - JColorChooser colorChooser = new JColorChooser(); - colorChooser.setColor(Color.black); - String title = MessageManager.getString("label.select_foreground_colour"); - ActionListener listener = new ActionListener() { + String title = MessageManager + .getString("label.select_foreground_colour"); + ColourChooserListener listener = new ColourChooserListener() + { @Override - public void actionPerformed(ActionEvent e) + public void colourSelected(Color c) { HiddenColumns hiddenColumns = av.getAlignment().getHiddenColumns(); for (int index : av.getColumnSelection().getSelected()) @@ -357,12 +359,12 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, { fAnot[index] = new Annotation("", "", ' ', 0); } - fAnot[index].colour = colorChooser.getColor(); + fAnot[index].colour = c; } }}; }; - JDialog dialog = JColorChooser.createDialog(this, title, true, colorChooser, listener, null); - dialog.setVisible(true); + JalviewColourChooser.showColourChooser(this, + title, Color.black, listener); } else // HELIX, SHEET or STEM diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 1400fcf..305d592 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -2455,6 +2455,7 @@ public class Desktop extends jalview.jbgui.GDesktop @Override public void propertyChange(PropertyChangeEvent event) { + // TODO this is obsolete with JAL-3048 - delete? Object val = event.getNewValue(); String name = event.getPropertyName(); System.out.println(name); @@ -2478,14 +2479,6 @@ public class Desktop extends jalview.jbgui.GDesktop return; } break; - case "javax.swing.ColorChooserDialog": - switch (name) - { - case "SelectedColor": - onDialogReturn(val); - return; - } - break; case "javax.swing.JFileChooser": switch (name) { @@ -2511,9 +2504,7 @@ public class Desktop extends jalview.jbgui.GDesktop dialogData[0] = value; ((Runnable) dialogData[1]).run(); break; - case "label.select_feature_colour": - ((FeatureRenderer) dialogData[1]).processColorDialog((Color) value); - break; + default: } } diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index 3b9c622..fc3dcc6 100644 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -25,6 +25,7 @@ import jalview.datamodel.SearchResults; import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; +import jalview.gui.JalviewColourChooser.ColourChooserListener; import jalview.io.FeaturesFile; import jalview.schemes.FeatureColour; import jalview.util.ColorUtils; @@ -48,6 +49,7 @@ import java.util.List; import javax.swing.JColorChooser; import javax.swing.JComboBox; +import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -194,13 +196,18 @@ public class FeatureRenderer { if (fcol.isSimpleColour()) { - // BH 2018 JavaScript-compatible color dialog - Desktop.desktop.dialogData = new Object[] { - "label.select_feature_colour", this, mainPanel, colour }; - Desktop.desktop - .onDialogReturn(JColorChooser.showDialog(Desktop.desktop, - MessageManager.getString("label.select_feature_colour"), - fcol.getColour())); + String title = MessageManager + .getString("label.select_feature_colour"); + ColourChooserListener listener = new ColourChooserListener() + { + @Override + public void colourSelected(Color c) + { + updateColourButton(mainPanel, colour, new FeatureColour(c)); + }; + }; + JalviewColourChooser.showColourChooser(Desktop.getDesktop(), + title, fcol.getColour(), listener); } else { @@ -499,17 +506,6 @@ public class FeatureRenderer return true; } - void processColorDialog(Color col) - { - JPanel mainPanel = (JPanel) Desktop.desktop.dialogData[2]; - JLabel colour = (JLabel) Desktop.desktop.dialogData[3]; - if (col != null) - { - fcol = new FeatureColour(col); - updateColourButton(mainPanel, colour, fcol); - } - } - /** * Show a warning message if the entered type is one that is currently hidden * diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 5709ab5..6fb6123 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -1628,9 +1628,9 @@ public class FeatureSettings extends JPanel int rowSelected = 0; - public ColorEditor(FeatureSettings me) + public ColorEditor(FeatureSettings fs) { - this.me = me; + this.me = fs; // Set up the editor (from the table's point of view), // which is a button. // This button brings up the color chooser dialog, diff --git a/src/jalview/gui/FeatureTypeSettings.java b/src/jalview/gui/FeatureTypeSettings.java index fa9833b..5169dfb 100644 --- a/src/jalview/gui/FeatureTypeSettings.java +++ b/src/jalview/gui/FeatureTypeSettings.java @@ -29,6 +29,7 @@ import jalview.datamodel.features.FeatureMatcher; import jalview.datamodel.features.FeatureMatcherI; import jalview.datamodel.features.FeatureMatcherSet; import jalview.datamodel.features.FeatureMatcherSetI; +import jalview.gui.JalviewColourChooser.ColourChooserListener; import jalview.schemes.FeatureColour; import jalview.util.ColorUtils; import jalview.util.MessageManager; @@ -56,9 +57,7 @@ import javax.swing.BoxLayout; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JCheckBox; -import javax.swing.JColorChooser; import javax.swing.JComboBox; -import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; @@ -111,7 +110,7 @@ public class FeatureTypeSettings extends JalviewDialog /* * the view panel to update when settings change */ - private final AlignmentViewPanel ap; + final AlignmentViewPanel ap; private final String featureType; @@ -126,7 +125,7 @@ public class FeatureTypeSettings extends JalviewDialog * set flag to true when setting values programmatically, * to avoid invocation of action handlers */ - private boolean adjusting = false; + boolean adjusting = false; /* * minimum of the value range for graduated colour @@ -142,29 +141,29 @@ public class FeatureTypeSettings extends JalviewDialog /* * scale factor for conversion between absolute min-max and slider */ - private float scaleFactor; + float scaleFactor; /* * radio button group, to select what to colour by: * simple colour, by category (text), or graduated */ - private JRadioButton simpleColour = new JRadioButton(); + JRadioButton simpleColour = new JRadioButton(); - private JRadioButton byCategory = new JRadioButton(); + JRadioButton byCategory = new JRadioButton(); - private JRadioButton graduatedColour = new JRadioButton(); + JRadioButton graduatedColour = new JRadioButton(); - private JPanel singleColour = new JPanel(); + JPanel singleColour = new JPanel(); - private JPanel minColour = new JPanel(); + JPanel minColour = new JPanel(); - private JPanel maxColour = new JPanel(); + JPanel maxColour = new JPanel(); private JComboBox threshold = new JComboBox<>(); - private JSlider slider = new JSlider(); + JSlider slider = new JSlider(); - private JTextField thresholdValue = new JTextField(20); + JTextField thresholdValue = new JTextField(20); private JCheckBox thresholdIsMin = new JCheckBox(); @@ -196,7 +195,7 @@ public class FeatureTypeSettings extends JalviewDialog /* * filters for the currently selected feature type */ - private List filters; + List filters; // set white normally, black to debug layout private Color debugBorderColour = Color.white; @@ -759,7 +758,6 @@ public class FeatureTypeSettings extends JalviewDialog showColourChooser(singleColour, "label.select_colour"); } } - }); singleColour.setFont(JvSwingUtils.getLabelFont()); @@ -843,29 +841,21 @@ public class FeatureTypeSettings extends JalviewDialog * @param key * message bundle key for the dialog title */ - private void showColourChooser(JPanel colourPanel, String key) + void showColourChooser(JPanel colourPanel, String key) { - // TODO 'final' is (currently) required here for SwingJS to work - JColorChooser colorChooser = new JColorChooser(); - colorChooser.setColor(colourPanel.getBackground()); - - ActionListener listener = new ActionListener() + ColourChooserListener listener = new ColourChooserListener() { @Override - public void actionPerformed(ActionEvent e) + public void colourSelected(Color col) { - Color col = colorChooser.getColor(); colourPanel.setBackground(col); colourPanel.setForeground(col); colourPanel.repaint(); colourChanged(true); } }; - - JDialog dialog = JColorChooser.createDialog(this, - MessageManager.getString(key), true, colorChooser, listener, - null); - dialog.setVisible(true); + JalviewColourChooser.showColourChooser(this, MessageManager.getString(key), + colourPanel.getBackground(), listener); } /** @@ -1552,7 +1542,7 @@ public class FeatureTypeSettings extends JalviewDialog * @param condCombo * @param patternField */ - private void populateConditions(String attName, Condition cond, + void populateConditions(String attName, Condition cond, JComboBox condCombo, JTextField patternField) { Datatype type = FeatureAttributes.getInstance().getDatatype(featureType, diff --git a/src/jalview/gui/JalviewColourChooser.java b/src/jalview/gui/JalviewColourChooser.java new file mode 100644 index 0000000..e0c4eeb --- /dev/null +++ b/src/jalview/gui/JalviewColourChooser.java @@ -0,0 +1,81 @@ +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 + * to a listener + */ +public class JalviewColourChooser +{ + public interface ColourChooserListener + { + void colourSelected(Color c); + } + + /** + * Shows a colour chooser dialog with the given parent component, title, and + * (optionally) initially selected colour. The chosen colour is passed back to + * the listener. There is no action if the dialog is cancelled. + * + * @param parent + * @param title + * @param initialColour + * @param listener + */ + public static void showColourChooser(Component parent, String title, + Color initialColour, ColourChooserListener listener) + { + JColorChooser colorChooser = new JColorChooser(); + if (initialColour != null) + { + 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); + } + + /** + * A convenience method that shows a colour chooser, with initial colour the + * background of the given 'paintable', and updates its background colour and + * repaints it after a colour selection is made + * + * @param parent + * @param title + * @param paintable + */ + public static void showColourChooser(Component parent, String title, + JComponent paintable) + { + ColourChooserListener listener = new ColourChooserListener() + { + @Override + public void colourSelected(Color c) + { + paintable.setBackground(c); + paintable.repaint(); + } + }; + JalviewColourChooser.showColourChooser(parent, title, + paintable.getBackground(), listener); + } +} diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java index 7ceceee..d2f789f 100644 --- a/src/jalview/gui/PCAPanel.java +++ b/src/jalview/gui/PCAPanel.java @@ -27,8 +27,10 @@ import jalview.api.analysis.SimilarityParamsI; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentView; +import jalview.datamodel.Annotation; import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceI; +import jalview.gui.JalviewColourChooser.ColourChooserListener; import jalview.jbgui.GPCAPanel; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; @@ -48,6 +50,7 @@ import java.awt.print.PrinterJob; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JColorChooser; +import javax.swing.JDialog; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; import javax.swing.event.InternalFrameAdapter; @@ -210,15 +213,18 @@ public class PCAPanel extends GPCAPanel @Override public void bgcolour_actionPerformed(ActionEvent e) { - Color col = JColorChooser.showDialog(this, - MessageManager.getString("label.select_background_colour"), - rc.bgColour); - - if (col != null) + String ttl = MessageManager.getString("label.select_background_colour"); + ColourChooserListener listener = new ColourChooserListener() { - rc.bgColour = col; - } - rc.repaint(); + @Override + public void colourSelected(Color c) + { + rc.bgColour = c; + rc.repaint(); + } + }; + JalviewColourChooser.showColourChooser(this, ttl, rc.bgColour, + listener); } /** diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index ed3d29a..8f082c1 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -38,6 +38,7 @@ import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.gui.ColourMenuHelper.ColourChangeListener; +import jalview.gui.JalviewColourChooser.ColourChooserListener; import jalview.io.FileFormatI; import jalview.io.FileFormats; import jalview.io.FormatAdapter; @@ -45,6 +46,7 @@ import jalview.io.SequenceAnnotationReport; import jalview.schemes.Blosum62ColourScheme; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemes; +import jalview.schemes.FeatureColour; import jalview.schemes.PIDColourScheme; import jalview.util.GroupUrlLink; import jalview.util.GroupUrlLink.UrlStringTooLongException; @@ -70,6 +72,7 @@ import java.util.Vector; import javax.swing.JCheckBoxMenuItem; import javax.swing.JColorChooser; +import javax.swing.JDialog; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; @@ -1859,24 +1862,23 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! + * Offers a colour chooser and sets the selected colour as the group outline */ protected void outline_actionPerformed() { - SequenceGroup sg = getGroup(); - Color col = JColorChooser.showDialog(this, - MessageManager.getString("label.select_outline_colour"), - Color.BLUE); - - if (col != null) + String title = MessageManager + .getString("label.select_outline_colour"); + ColourChooserListener listener = new ColourChooserListener() { - sg.setOutlineColour(col); - } - - refresh(); + @Override + public void colourSelected(Color c) + { + getGroup().setOutlineColour(c); + refresh(); + }; + }; + JalviewColourChooser.showColourChooser(Desktop.getDesktop(), + title, Color.BLUE, listener); } /** diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 019b29e..aeac55f 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -23,6 +23,7 @@ package jalview.gui; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.bin.Cache; import jalview.gui.Help.HelpId; +import jalview.gui.JalviewColourChooser.ColourChooserListener; import jalview.gui.StructureViewer.ViewerType; import jalview.io.FileFormatI; import jalview.io.JalviewFileChooser; @@ -1047,27 +1048,17 @@ public class Preferences extends GPreferences @Override public void minColour_actionPerformed(JPanel panel) { - Color col = JColorChooser.showDialog(this, + JalviewColourChooser.showColourChooser(this, MessageManager.getString("label.select_colour_minimum_value"), - minColour.getBackground()); - if (col != null) - { - panel.setBackground(col); - } - panel.repaint(); + panel); } @Override public void maxColour_actionPerformed(JPanel panel) { - Color col = JColorChooser.showDialog(this, + JalviewColourChooser.showColourChooser(this, MessageManager.getString("label.select_colour_maximum_value"), - maxColour.getBackground()); - if (col != null) - { - panel.setBackground(col); - } - panel.repaint(); + panel); } @Override @@ -1075,28 +1066,18 @@ public class Preferences extends GPreferences { if (!useLegacyGap.isSelected()) { - Color col = JColorChooser.showDialog(this, + JalviewColourChooser.showColourChooser(this, MessageManager.getString("label.select_gap_colour"), - gapColour.getBackground()); - if (col != null) - { - gap.setBackground(col); - } - gap.repaint(); + gap); } } @Override public void hiddenColour_actionPerformed(JPanel hidden) { - Color col = JColorChooser.showDialog(this, + JalviewColourChooser.showColourChooser(this, MessageManager.getString("label.select_hidden_colour"), - hiddenColour.getBackground()); - if (col != null) - { - hidden.setBackground(col); - } - hidden.repaint(); + hidden); } @Override diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index 9ed08b8..2d3b3b5 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -27,6 +27,7 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; +import jalview.gui.JalviewColourChooser.ColourChooserListener; import jalview.gui.StructureViewer.ViewerType; import jalview.gui.ViewSelectionMenu.ViewSetProvider; import jalview.io.DataSourceType; @@ -35,6 +36,7 @@ import jalview.io.JalviewFileView; import jalview.jbgui.GStructureViewer; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemes; +import jalview.schemes.FeatureColour; import jalview.structure.StructureMapping; import jalview.structures.models.AAStructureBindingModel; import jalview.util.MessageManager; @@ -58,6 +60,7 @@ import java.util.Vector; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JColorChooser; +import javax.swing.JDialog; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; @@ -812,13 +815,16 @@ public abstract class StructureViewerBase extends GStructureViewer @Override public void background_actionPerformed(ActionEvent actionEvent) { - Color col = JColorChooser.showDialog(this, - MessageManager.getString("label.select_background_colour"), - null); - if (col != null) + String ttl = MessageManager + .getString("label.select_background_colour"); + ColourChooserListener listener = new ColourChooserListener() { - getBinding().setBackgroundColour(col); - } + @Override + public void colourSelected(Color c) + { + getBinding().setBackgroundColour(c); + } + }; } @Override diff --git a/src/jalview/gui/TextColourChooser.java b/src/jalview/gui/TextColourChooser.java index 53e2dee..a1b3caf 100644 --- a/src/jalview/gui/TextColourChooser.java +++ b/src/jalview/gui/TextColourChooser.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.datamodel.SequenceGroup; +import jalview.gui.JalviewColourChooser.ColourChooserListener; import jalview.util.MessageManager; import java.awt.BorderLayout; @@ -101,14 +102,18 @@ public class TextColourChooser @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); } }); @@ -117,14 +122,18 @@ 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); } }); diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 7dc1a99..b83dc12 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -27,6 +27,7 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.datamodel.SequenceNode; +import jalview.gui.JalviewColourChooser.ColourChooserListener; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; import jalview.schemes.UserColourScheme; @@ -841,15 +842,17 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, */ void chooseSubtreeColour() { - Color col = JColorChooser.showDialog(this, - MessageManager.getString("label.select_subtree_colour"), - highlightNode.color); - if (col != null) - { - setColor(highlightNode, col); - PaintRefresher.Refresh(tp, ap.av.getSequenceSetId()); - repaint(); - } + String ttl = MessageManager.getString("label.select_subtree_colour"); + ColourChooserListener listener = new ColourChooserListener() { + @Override + public void colourSelected(Color c) + { + setColor(highlightNode, c); + PaintRefresher.Refresh(tp, ap.av.getSequenceSetId()); + repaint(); + } + }; + JalviewColourChooser.showColourChooser(this, ttl, highlightNode.color, listener); } @Override