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;
private JPanel maxColour = new JPanel();
- private JPanel noColour = new JPanel();
+ private Color noColour;
private JComboBox<String> threshold = new JComboBox<>();
private ActionListener changeColourAction;
+ private ActionListener changeMinMaxAction;
+
+ /*
+ * choice of option for 'colour for no value'
+ */
+ private JComboBox<String> noValueCombo;
+
/*
* choice of attribute (if any) for 'colour by text'
*/
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()
{
}
minColour.setBackground(oldminColour = cs.getMinColour());
maxColour.setBackground(oldmaxColour = cs.getMaxColour());
- noColour.setBackground(oldNoColour = cs.getNoColour());
adjusting = true;
try
String attributeName = cs.getAttributeName();
valueAttributeCombo.setSelectedItem(attributeName);
valueAttributeCombo.setEnabled(true);
- setAttributeMinMax(attributeName);
+ updateMinMax();
}
else
{
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
this.setBackground(Color.white);
- changeColourAction = new ActionListener() {
+ changeColourAction = new ActionListener()
+ {
@Override
public void actionPerformed(ActionEvent e)
{
}
};
+ changeMinMaxAction = new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ updateMinMax();
+ changeColour(true);
+ }
+ };
+
/*
* this panel
* detailsPanel
}
/**
+ * 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
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<String> 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
});
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);
colourRangePanel.add(maxText);
colourRangePanel.add(maxColour);
colourRangePanel.add(noText);
- colourRangePanel.add(noColour);
+ colourRangePanel.add(noValueCombo);
/*
* third row - threshold options and value
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);
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);
}
/**
- * 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);
}
/**
}
/**
- * 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
{
acg = new FeatureColour(oldminColour = minColour.getBackground(),
oldmaxColour = maxColour.getBackground(),
- oldNoColour = noColour.getBackground(), min, max);
+ oldNoColour = noColour, min, max);
}
String attribute = null;
textAttributeCombo.setEnabled(false);
{
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);
}
/*
@Override
public void itemStateChanged(ItemEvent e)
{
- setAttributeMinMax(attCombo.getSelectedItem().toString());
- changeColour(true);
+ changeMinMaxAction.actionPerformed(null);
}
});
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);
- }
- }
-
}