From: gmungoc Date: Tue, 7 Nov 2017 16:40:05 +0000 (+0000) Subject: JAL-2069 choice of no / min / max colour if 'no attribute value' X-Git-Tag: Release_2_11_0~142 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=6c98f6ff6f04d53b93e4e260e45d26008f6bd0a7;p=jalview.git JAL-2069 choice of no / min / max colour if 'no attribute value' --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 35ead5e..4626c39 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -274,6 +274,7 @@ label.chimera_missing = Chimera structure viewer not found.
Please enter the label.chimera_failed = Error opening Chimera - is it installed?\nCheck path in Preferences, Structure label.min_colour = Minimum Colour label.max_colour = Maximum Colour +label.no_colour = No Colour label.use_original_colours = Use Original Colours label.threshold_minmax = Threshold is min/max label.represent_group_with = Represent Group with {0} @@ -281,8 +282,9 @@ label.selection = Selection label.group_colour = Group Colour label.sequence = Sequence label.view_pdb_structure = View PDB Structure -label.min = Min: -label.max = Max: +label.min_value = Min value: +label.max_value = Max value: +label.no_value = No value: label.new_feature = New Feature label.match_case = Match Case label.view_alignment_editor = View in alignment editor @@ -1346,6 +1348,4 @@ label.score = Score label.attribute = Attribute label.colour_by_label = Colour by label label.variable_colour = Variable colour -label.no_colour = No colour: -label.select_no_value_colour = Select colour when no value label.select_new_colour = Select new colour diff --git a/src/jalview/appletgui/FeatureColourChooser.java b/src/jalview/appletgui/FeatureColourChooser.java index 5a073c6..0d85c60 100644 --- a/src/jalview/appletgui/FeatureColourChooser.java +++ b/src/jalview/appletgui/FeatureColourChooser.java @@ -198,8 +198,8 @@ public class FeatureColourChooser extends Panel implements ActionListener, private void jbInit() throws Exception { - Label minLabel = new Label(MessageManager.getString("label.min")), - maxLabel = new Label(MessageManager.getString("label.max")); + Label minLabel = new Label(MessageManager.getString("label.min_value")); + Label maxLabel = new Label(MessageManager.getString("label.max_value")); minLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); maxLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); // minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); diff --git a/src/jalview/gui/FeatureColourChooser.java b/src/jalview/gui/FeatureColourChooser.java index 3fc3116..ddfa162 100644 --- a/src/jalview/gui/FeatureColourChooser.java +++ b/src/jalview/gui/FeatureColourChooser.java @@ -47,9 +47,7 @@ import javax.swing.JCheckBox; import javax.swing.JColorChooser; import javax.swing.JComboBox; import javax.swing.JLabel; -import javax.swing.JMenuItem; import javax.swing.JPanel; -import javax.swing.JPopupMenu; import javax.swing.JRadioButton; import javax.swing.JSlider; import javax.swing.JTextField; @@ -83,7 +81,7 @@ public class FeatureColourChooser extends JalviewDialog private JPanel maxColour = new JPanel(); - private JPanel noColour = new JPanel(); + private Color noColour; private JComboBox threshold = new JComboBox<>(); @@ -117,6 +115,13 @@ public class FeatureColourChooser extends JalviewDialog private ActionListener changeColourAction; + private ActionListener changeMinMaxAction; + + /* + * choice of option for 'colour for no value' + */ + private JComboBox noValueCombo; + /* * choice of attribute (if any) for 'colour by text' */ @@ -155,7 +160,7 @@ public class FeatureColourChooser extends JalviewDialog String title = MessageManager .formatMessage("label.graduated_color_for_params", new String[] { theType }); - initDialogFrame(this, true, blocking, title, 450, 300); + initDialogFrame(this, true, blocking, title, 470, 300); slider.addChangeListener(new ChangeListener() { @@ -226,7 +231,6 @@ public class FeatureColourChooser extends JalviewDialog } minColour.setBackground(oldminColour = cs.getMinColour()); maxColour.setBackground(oldmaxColour = cs.getMaxColour()); - noColour.setBackground(oldNoColour = cs.getNoColour()); adjusting = true; try @@ -265,7 +269,7 @@ public class FeatureColourChooser extends JalviewDialog String attributeName = cs.getAttributeName(); valueAttributeCombo.setSelectedItem(attributeName); valueAttributeCombo.setEnabled(true); - setAttributeMinMax(attributeName); + updateMinMax(); } else { @@ -300,7 +304,8 @@ public class FeatureColourChooser extends JalviewDialog this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.setBackground(Color.white); - changeColourAction = new ActionListener() { + changeColourAction = new ActionListener() + { @Override public void actionPerformed(ActionEvent e) { @@ -308,6 +313,16 @@ public class FeatureColourChooser extends JalviewDialog } }; + changeMinMaxAction = new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + updateMinMax(); + changeColour(true); + } + }; + /* * this panel * detailsPanel @@ -341,6 +356,31 @@ public class FeatureColourChooser extends JalviewDialog } /** + * Updates the min-max range for a change in choice of Colour by Score, or + * Colour by Attribute (value) + */ + protected void updateMinMax() + { + float[] minMax = null; + if (byScore.isSelected()) + { + minMax = fr.getMinMax().get(type)[0]; + } + else if (byAttributeValue.isSelected()) + { + String attName = (String) valueAttributeCombo.getSelectedItem(); + minMax = FeatureAttributes.getInstance().getMinMax(type, attName); + } + if (minMax != null) + { + min = minMax[0]; + max = minMax[1]; + scaleFactor = (max == min) ? 1f : 100f / (max - min); + slider.setValue((int) (min * scaleFactor)); + } + } + + /** * Lay out fields for graduated colour by value * * @return @@ -362,17 +402,15 @@ public class FeatureColourChooser extends JalviewDialog byScore.setText(MessageManager.getString("label.score")); byWhatPanel.add(byScore); - byScore.addActionListener(changeColourAction); + byScore.addActionListener(changeMinMaxAction); - byAttributeValue.setText(MessageManager -.getString("label.attribute")); - byAttributeValue.addActionListener(changeColourAction); + byAttributeValue.setText(MessageManager.getString("label.attribute")); + byAttributeValue.addActionListener(changeMinMaxAction); byWhatPanel.add(byAttributeValue); List attNames = FeatureAttributes.getInstance().getAttributes( type); - valueAttributeCombo = populateAttributesDropdown(type, attNames, - true); + valueAttributeCombo = populateAttributesDropdown(type, attNames, true); /* * if no numeric atttibutes found, disable colour by attribute value @@ -424,44 +462,24 @@ public class FeatureColourChooser extends JalviewDialog }); maxColour.setBorder(new LineBorder(Color.black)); - noColour.setFont(JvSwingUtils.getLabelFont()); - noColour.setBorder(BorderFactory.createLineBorder(Color.black)); - noColour.setPreferredSize(new Dimension(40, 20)); - noColour.setToolTipText("Colour if feature has no attribute value"); - noColour.addMouseListener(new MouseAdapter() + noValueCombo = new JComboBox<>(); + noValueCombo.addItem(MessageManager.getString("label.no_colour")); + noValueCombo.addItem(MessageManager.getString("label.min_colour")); + noValueCombo.addItem(MessageManager.getString("label.max_colour")); + noValueCombo.addItemListener(new ItemListener() { @Override - public void mousePressed(MouseEvent e) - { - if (e.isPopupTrigger()) // Mac: mouseReleased - { - showNoColourPopup(e); - return; - } - if (noColour.isEnabled()) - { - noColour_actionPerformed(); - } - } - - @Override - public void mouseReleased(MouseEvent e) + public void itemStateChanged(ItemEvent e) { - if (e.isPopupTrigger()) // Windows: mouseReleased - { - showNoColourPopup(e); - e.consume(); - return; - } + setNoValueColour(); } }); - noColour.setBorder(new LineBorder(Color.black)); - JLabel minText = new JLabel(MessageManager.getString("label.min")); + JLabel minText = new JLabel(MessageManager.getString("label.min_value")); minText.setFont(JvSwingUtils.getLabelFont()); - JLabel maxText = new JLabel(MessageManager.getString("label.max")); + JLabel maxText = new JLabel(MessageManager.getString("label.max_value")); maxText.setFont(JvSwingUtils.getLabelFont()); - JLabel noText = new JLabel(MessageManager.getString("label.no_colour")); + JLabel noText = new JLabel(MessageManager.getString("label.no_value")); noText.setFont(JvSwingUtils.getLabelFont()); colourRangePanel.add(minText); @@ -469,7 +487,7 @@ public class FeatureColourChooser extends JalviewDialog colourRangePanel.add(maxText); colourRangePanel.add(maxColour); colourRangePanel.add(noText); - colourRangePanel.add(noColour); + colourRangePanel.add(noValueCombo); /* * third row - threshold options and value @@ -510,8 +528,8 @@ public class FeatureColourChooser extends JalviewDialog slider.setEnabled(false); slider.setOpaque(false); slider.setPreferredSize(new Dimension(100, 32)); - slider.setToolTipText( - MessageManager.getString("label.adjust_threshold")); + slider.setToolTipText(MessageManager + .getString("label.adjust_threshold")); thresholdValue.setEnabled(false); thresholdValue.setColumns(7); @@ -526,8 +544,8 @@ public class FeatureColourChooser extends JalviewDialog isMinMaxPanel.setBackground(Color.white); byValuePanel.add(isMinMaxPanel); thresholdIsMin.setBackground(Color.white); - thresholdIsMin - .setText(MessageManager.getString("label.threshold_minmax")); + thresholdIsMin.setText(MessageManager + .getString("label.threshold_minmax")); thresholdIsMin.setToolTipText(MessageManager .getString("label.toggle_absolute_relative_display_threshold")); thresholdIsMin.addActionListener(changeColourAction); @@ -537,42 +555,25 @@ public class FeatureColourChooser extends JalviewDialog } /** - * Show a popup menu with options to make 'no value colour' the same as Min - * Colour or Max Colour - * - * @param evt + * Action on user choice of no / min / max colour when there is no value to + * colour by */ - protected void showNoColourPopup(MouseEvent evt) + protected void setNoValueColour() { - JPopupMenu pop = new JPopupMenu(); - - JMenuItem copyMin = new JMenuItem( - MessageManager.getString("label.min_colour")); - copyMin.addActionListener((new ActionListener() + int i = noValueCombo.getSelectedIndex(); + if (i == 0) { - @Override - public void actionPerformed(ActionEvent e) - { - noColour.setBackground(minColour.getBackground()); - changeColour(true); - } - })); - pop.add(copyMin); - - JMenuItem copyMax = new JMenuItem( - MessageManager.getString("label.max_colour")); - copyMax.addActionListener((new ActionListener() + noColour = null; + } + else if (i == 1) { - @Override - public void actionPerformed(ActionEvent e) - { - noColour.setBackground(maxColour.getBackground()); - changeColour(true); - } - })); - pop.add(copyMax); - - pop.show(noColour, evt.getX(), evt.getY()); + noColour = minColour.getBackground(); + } + else if (i == 2) + { + noColour = maxColour.getBackground(); + } + changeColour(true); } /** @@ -664,24 +665,6 @@ public class FeatureColourChooser extends JalviewDialog } /** - * Action on clicking the 'no colour' - open a colour chooser dialog, and set - * the selected colour (if the user does not cancel out of the dialog) - */ - protected void noColour_actionPerformed() - { - Color col = JColorChooser.showDialog(this, - MessageManager.getString("label.select_no_value_colour"), - noColour.getBackground()); - if (col != null) - { - noColour.setBackground(col); - noColour.setForeground(col); - } - noColour.repaint(); - changeColour(true); - } - - /** * Constructs and sets the selected colour options as the colour for the * feature type, and repaints the alignment, and optionally the Overview * and/or structure viewer if open @@ -723,7 +706,7 @@ public class FeatureColourChooser extends JalviewDialog { acg = new FeatureColour(oldminColour = minColour.getBackground(), oldmaxColour = maxColour.getBackground(), - oldNoColour = noColour.getBackground(), min, max); + oldNoColour = noColour, min, max); } String attribute = null; textAttributeCombo.setEnabled(false); @@ -800,25 +783,21 @@ public class FeatureColourChooser extends JalviewDialog { maxColour.setEnabled(false); minColour.setEnabled(false); - noColour.setEnabled(false); + noValueCombo.setEnabled(false); maxColour.setBackground(this.getBackground()); maxColour.setForeground(this.getBackground()); minColour.setBackground(this.getBackground()); minColour.setForeground(this.getBackground()); - noColour.setBackground(this.getBackground()); - noColour.setForeground(this.getBackground()); } else { maxColour.setEnabled(true); minColour.setEnabled(true); - noColour.setEnabled(true); + noValueCombo.setEnabled(true); maxColour.setBackground(oldmaxColour); maxColour.setForeground(oldmaxColour); minColour.setBackground(oldminColour); minColour.setForeground(oldminColour); - noColour.setBackground(oldNoColour); - noColour.setForeground(oldNoColour); } /* @@ -976,8 +955,7 @@ public class FeatureColourChooser extends JalviewDialog @Override public void itemStateChanged(ItemEvent e) { - setAttributeMinMax(attCombo.getSelectedItem().toString()); - changeColour(true); + changeMinMaxAction.actionPerformed(null); } }); @@ -991,21 +969,4 @@ public class FeatureColourChooser extends JalviewDialog return attCombo; } - /** - * Updates the min-max range and scale to be that for the given attribute name - * - * @param attributeName - */ - protected void setAttributeMinMax(String attributeName) - { - float[] minMax = FeatureAttributes.getInstance().getMinMax(type, - attributeName); - if (minMax != null) - { - min = minMax[0]; - max = minMax[1]; - scaleFactor = (max == min) ? 1f : 100f / (max - min); - } - } - }