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;
import javax.swing.JSlider;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
-import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
-import javax.swing.plaf.basic.BasicArrowButton;
/**
* A dialog where the user can configure colour scheme, and any filters, for one
return colourByPanel;
}
+ /**
+ * Shows a colour chooser dialog, and if a selection is made, updates the
+ * colour of the given panel
+ *
+ * @param colourPanel
+ * the panel whose background colour is being picked
+ * @param key
+ * message bundle key for the dialog title
+ */
private void showColourChooser(JPanel colourPanel, String key)
{
- Color col = JColorChooser.showDialog(this,
- MessageManager.getString(key), colourPanel.getBackground());
- if (col != null)
+ // TODO 'final' is (currently) required here for SwingJS to work
+ JColorChooser colorChooser = new JColorChooser();
+ colorChooser.setColor(colourPanel.getBackground());
+
+ ActionListener listener = new ActionListener()
{
- colourPanel.setBackground(col);
- colourPanel.setForeground(col);
- }
- colourPanel.repaint();
- colourChanged(true);
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ 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);
}
/**
*/
float minValue = min;
float maxValue = max;
- final int thresholdOption = threshold.getSelectedIndex();
+ int thresholdOption = threshold.getSelectedIndex();
if (thresholdIsMin.isSelected()
&& thresholdOption == ABOVE_THRESHOLD_OPTION)
{
{
orFilters.setSelected(true);
}
- featureFilters.getMatchers().forEach(matcher -> filters.add(matcher));
+ // avoid use of lambda expression to keep SwingJS happy
+ // featureFilters.getMatchers().forEach(item -> filters.add(item));
+ for (FeatureMatcherI matcher : featureFilters.getMatchers())
+ {
+ filters.add(matcher);
+ }
}
/*
* drop-down choice of attribute, with description as a tooltip
* if we can obtain it
*/
- final JComboBox<String> attCombo = populateAttributesDropdown(attNames,
+ JComboBox<String> attCombo = populateAttributesDropdown(attNames,
true, true);
String filterBy = setSelectedAttribute(attCombo, filter);
* disable pattern field for condition 'Present / NotPresent'
*/
Condition selectedCondition = (Condition) condCombo.getSelectedItem();
- if (!selectedCondition.needsAPattern())
- {
- patternField.setEnabled(false);
- }
+ patternField.setEnabled(selectedCondition.needsAPattern());
/*
* if a numeric condition is selected, show the value range
* as a tooltip on the value input field
*/
- setPatternTooltip(filterBy, selectedCondition, patternField);
+ setNumericHints(filterBy, selectedCondition, patternField);
/*
* add remove button if filter is populated (non-empty pattern)
if (!patternField.isEnabled()
|| (pattern != null && pattern.trim().length() > 0))
{
- // todo: gif for button drawing '-' or 'x'
- JButton removeCondition = new BasicArrowButton(SwingConstants.WEST);
+ JButton removeCondition = new JButton("\u2717"); // Dingbats cursive x
+ removeCondition.setPreferredSize(new Dimension(23, 17));
removeCondition
.setToolTipText(MessageManager.getString("label.delete_row"));
removeCondition.addActionListener(new ActionListener()
}
/**
- * If a numeric comparison condition is selected, retrieve the min-max range for
- * the value (score or attribute), and set it as a tooltip on the value file
+ * If a numeric comparison condition is selected, retrieves the min-max range
+ * for the value (score or attribute), and sets it as a tooltip on the value
+ * field. If the field is currently empty, then pre-populates it with
+ * <ul>
+ * <li>the minimum value, if condition is > or >=</li>
+ * <li>the maximum value, if condition is < or <=</li>
+ * </ul>
*
* @param attName
* @param selectedCondition
* @param patternField
*/
- private void setPatternTooltip(String attName,
+ private void setNumericHints(String attName,
Condition selectedCondition, JTextField patternField)
{
patternField.setToolTipText("");
float[] minMax = getMinMax(attName);
if (minMax != null)
{
- String tip = String.format("(%s - %s)",
- DECFMT_2_2.format(minMax[0]), DECFMT_2_2.format(minMax[1]));
+ String minFormatted = DECFMT_2_2.format(minMax[0]);
+ String maxFormatted = DECFMT_2_2.format(minMax[1]);
+ String tip = String.format("(%s - %s)", minFormatted, maxFormatted);
patternField.setToolTipText(tip);
+ if (patternField.getText().isEmpty())
+ {
+ if (selectedCondition == Condition.GE
+ || selectedCondition == Condition.GT)
+ {
+ patternField.setText(minFormatted);
+ }
+ else
+ {
+ if (selectedCondition == Condition.LE
+ || selectedCondition == Condition.LT)
+ {
+ patternField.setText(maxFormatted);
+ }
+ }
+ }
}
}
}
ItemListener listener = condCombo.getItemListeners()[0];
condCombo.removeItemListener(listener);
boolean condIsValid = false;
+
condCombo.removeAllItems();
for (Condition c : Condition.values())
{
- if ((c.isNumeric() && type != Datatype.Character)
+ if ((c.isNumeric() && type == Datatype.Number)
|| (!c.isNumeric() && type != Datatype.Number))
{
condCombo.addItem(c);
condCombo.setSelectedIndex(0);
}
- condCombo.addItemListener(listener);
-
/*
* clear pattern if it is now invalid for condition
*/
patternField.setText("");
}
}
+
+ /*
+ * restore the listener
+ */
+ condCombo.addItemListener(listener);
}
/**
Condition cond = (Condition) condCombo.getSelectedItem();
String pattern = valueField.getText().trim();
- setPatternTooltip(attName, cond, valueField);
+ setNumericHints(attName, cond, valueField);
if (pattern.length() == 0 && cond.needsAPattern())
{
+ valueField.setEnabled(true); // ensure pattern field is enabled!
return false;
}