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;
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;
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();
{
if (minColour.isEnabled())
{
- minColour_actionPerformed();
+ showColourChooser(minColour, "label.select_colour_minimum_value");
}
}
});
{
if (maxColour.isEnabled())
{
- maxColour_actionPerformed();
+ showColourChooser(maxColour, "label.select_colour_maximum_value");
}
}
});
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
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;
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())
{
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
@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);
return;
}
break;
- case "javax.swing.ColorChooserDialog":
- switch (name)
- {
- case "SelectedColor":
- onDialogReturn(val);
- return;
- }
- break;
case "javax.swing.JFileChooser":
switch (name)
{
dialogData[0] = value;
((Runnable) dialogData[1]).run();
break;
- case "label.select_feature_colour":
- ((FeatureRenderer) dialogData[1]).processColorDialog((Color) value);
- break;
+ default:
}
}
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;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
+import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
{
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
{
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
*
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,
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;
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;
/*
* the view panel to update when settings change
*/
- private final AlignmentViewPanel ap;
+ final AlignmentViewPanel ap;
private final String featureType;
* 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
/*
* 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<String> 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();
/*
* filters for the currently selected feature type
*/
- private List<FeatureMatcherI> filters;
+ List<FeatureMatcherI> filters;
// set white normally, black to debug layout
private Color debugBorderColour = Color.white;
showColourChooser(singleColour, "label.select_colour");
}
}
-
});
singleColour.setFont(JvSwingUtils.getLabelFont());
* @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);
}
/**
* @param condCombo
* @param patternField
*/
- private void populateConditions(String attName, Condition cond,
+ void populateConditions(String attName, Condition cond,
JComboBox<Condition> condCombo, JTextField patternField)
{
Datatype type = FeatureAttributes.getInstance().getDatatype(featureType,
--- /dev/null
+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);
+ }
+}
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;
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;
@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);
}
/**
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;
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;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JColorChooser;
+import javax.swing.JDialog;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
}
/**
- * 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);
}
/**
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;
@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
{
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
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;
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;
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;
@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
package jalview.gui;
import jalview.datamodel.SequenceGroup;
+import jalview.gui.JalviewColourChooser.ColourChooserListener;
import jalview.util.MessageManager;
import java.awt.BorderLayout;
@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);
}
});
@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);
}
});
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;
*/
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