dassources = resolved;
+ fetchDAS.setEnabled(false);
+ // cancelDAS.setEnabled(true); doDasFetch does this.
+ Runnable fetcher = new Runnable()
{
+ @Override
public void run()
{
- fetchDAS.setEnabled(false);
- cancelDAS.setEnabled(true);
doDasFeatureFetch(dassources, true, false);
}
- });
+ };
+ if (block)
+ {
+ fetcher.run();
+ }
+ else
+ {
+ SwingUtilities.invokeLater(fetcher);
+ }
}
}
@@ -1121,6 +1897,8 @@ public class FeatureSettings extends JPanel
{
fetchDAS.setEnabled(true);
cancelDAS.setEnabled(false);
+ dassourceBrowser.setGuiEnabled(true);
+
}
public void cancelDAS_actionPerformed(ActionEvent e)
@@ -1129,18 +1907,61 @@ public class FeatureSettings extends JPanel
{
dasFeatureFetcher.cancel();
}
- fetchDAS.setEnabled(true);
- cancelDAS.setEnabled(false);
+ complete();
}
public void noDasSourceActive()
{
complete();
- JOptionPane.showInternalConfirmDialog(Desktop.desktop,
- "No das sources were selected.\n"
- + "Please select some sources and\n" + " try again.",
- "No Sources Selected", JOptionPane.DEFAULT_OPTION,
- JOptionPane.INFORMATION_MESSAGE);
+ JvOptionPane.showInternalConfirmDialog(Desktop.desktop,
+ MessageManager.getString("label.no_das_sources_selected_warn"),
+ MessageManager.getString("label.no_das_sources_selected_title"),
+ JvOptionPane.DEFAULT_OPTION, JvOptionPane.INFORMATION_MESSAGE);
+ }
+
+ /**
+ * Answers true unless a numeric condition has been selected with a
+ * non-numeric value. Sets the value field to RED with a tooltip if in error.
+ *
+ * If the pattern entered is empty, this method returns false, but does not
+ * mark the field as invalid. This supports selecting an attribute for a new
+ * condition before a match pattern has been entered.
+ *
+ * @param value
+ * @param condCombo
+ */
+ protected boolean validateFilter(JTextField value,
+ JComboBox condCombo)
+ {
+ if (value == null || condCombo == null)
+ {
+ return true; // fields not populated
+ }
+
+ Condition cond = (Condition) condCombo.getSelectedItem();
+ value.setBackground(Color.white);
+ value.setToolTipText("");
+ String v1 = value.getText().trim();
+ if (v1.length() == 0)
+ {
+ return false;
+ }
+
+ if (cond.isNumeric())
+ {
+ try
+ {
+ Float.valueOf(v1);
+ } catch (NumberFormatException e)
+ {
+ value.setBackground(Color.red);
+ value.setToolTipText(MessageManager
+ .getString("label.numeric_required"));
+ return false;
+ }
+ }
+
+ return true;
}
// ///////////////////////////////////////////////////////////////////////
@@ -1153,8 +1974,10 @@ public class FeatureSettings extends JPanel
this.data = data;
}
- private String[] columnNames =
- { "Feature Type", "Colour", "Display" };
+ private String[] columnNames = {
+ MessageManager.getString("label.feature_type"),
+ MessageManager.getString("action.colour"),
+ MessageManager.getString("label.display") };
private Object[][] data;
@@ -1168,6 +1991,7 @@ public class FeatureSettings extends JPanel
this.data = data;
}
+ @Override
public int getColumnCount()
{
return columnNames.length;
@@ -1178,31 +2002,37 @@ public class FeatureSettings extends JPanel
return data[row];
}
+ @Override
public int getRowCount()
{
return data.length;
}
+ @Override
public String getColumnName(int col)
{
return columnNames[col];
}
+ @Override
public Object getValueAt(int row, int col)
{
return data[row][col];
}
+ @Override
public Class getColumnClass(int c)
{
return getValueAt(0, c).getClass();
}
+ @Override
public boolean isCellEditable(int row, int col)
{
return col == 0 ? false : true;
}
+ @Override
public void setValueAt(Object value, int row, int col)
{
data[row][col] = value;
@@ -1218,23 +2048,41 @@ public class FeatureSettings extends JPanel
javax.swing.border.Border selectedBorder = null;
+ final String baseTT = "Click to edit, right/apple click for menu.";
+
public ColorRenderer()
{
setOpaque(true); // MUST do this for background to show up.
+ setHorizontalTextPosition(SwingConstants.CENTER);
+ setVerticalTextPosition(SwingConstants.CENTER);
}
- public Component getTableCellRendererComponent(JTable table,
- Object color, boolean isSelected, boolean hasFocus, int row,
- int column)
+ @Override
+ public Component getTableCellRendererComponent(JTable tbl, Object color,
+ boolean isSelected, boolean hasFocus, int row, int column)
{
- Color newColor = (Color) color;
- setBackground(newColor);
+ FeatureColourI cellColour = (FeatureColourI) color;
+ setOpaque(true);
+ setToolTipText(baseTT);
+ setBackground(tbl.getBackground());
+ if (!cellColour.isSimpleColour())
+ {
+ Rectangle cr = tbl.getCellRect(row, column, false);
+ FeatureSettings.renderGraduatedColor(this, cellColour,
+ (int) cr.getWidth(), (int) cr.getHeight());
+ }
+ else
+ {
+ this.setText("");
+ this.setIcon(null);
+ setBackground(cellColour.getColour());
+ }
if (isSelected)
{
if (selectedBorder == null)
{
selectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5,
- table.getSelectionBackground());
+ tbl.getSelectionBackground());
}
setBorder(selectedBorder);
}
@@ -1243,22 +2091,201 @@ public class FeatureSettings extends JPanel
if (unselectedBorder == null)
{
unselectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5,
- table.getBackground());
+ tbl.getBackground());
}
setBorder(unselectedBorder);
}
- setToolTipText("RGB value: " + newColor.getRed() + ", "
- + newColor.getGreen() + ", " + newColor.getBlue());
return this;
}
}
+
+ /**
+ * update comp using rendering settings from gcol
+ *
+ * @param comp
+ * @param gcol
+ */
+ public static void renderGraduatedColor(JLabel comp, FeatureColourI gcol)
+ {
+ int w = comp.getWidth(), h = comp.getHeight();
+ if (w < 20)
+ {
+ w = (int) comp.getPreferredSize().getWidth();
+ h = (int) comp.getPreferredSize().getHeight();
+ if (w < 20)
+ {
+ w = 80;
+ h = 12;
+ }
+ }
+ renderGraduatedColor(comp, gcol, w, h);
+ }
+
+ public static void renderGraduatedColor(JLabel comp, FeatureColourI gcol,
+ int w, int h)
+ {
+ boolean thr = false;
+ StringBuilder tt = new StringBuilder();
+ StringBuilder tx = new StringBuilder();
+
+ if (gcol.isColourByAttribute())
+ {
+ tx.append(gcol.getAttributeName());
+ }
+ else if (!gcol.isColourByLabel())
+ {
+ tx.append(MessageManager.getString("label.score"));
+ }
+ tx.append(" ");
+ if (gcol.isAboveThreshold())
+ {
+ thr = true;
+ tx.append(">");
+ tt.append("Thresholded (Above ").append(gcol.getThreshold())
+ .append(") ");
+ }
+ if (gcol.isBelowThreshold())
+ {
+ thr = true;
+ tx.append("<");
+ tt.append("Thresholded (Below ").append(gcol.getThreshold())
+ .append(") ");
+ }
+ if (gcol.isColourByLabel())
+ {
+ tt.append("Coloured by label text. ").append(tt);
+ if (thr)
+ {
+ tx.append(" ");
+ }
+ if (!gcol.isColourByAttribute())
+ {
+ tx.append("Label");
+ }
+ comp.setIcon(null);
+ }
+ else
+ {
+ Color newColor = gcol.getMaxColour();
+ comp.setBackground(newColor);
+ // System.err.println("Width is " + w / 2);
+ Icon ficon = new FeatureIcon(gcol, comp.getBackground(), w, h, thr);
+ comp.setIcon(ficon);
+ // tt+="RGB value: Max (" + newColor.getRed() + ", "
+ // + newColor.getGreen() + ", " + newColor.getBlue()
+ // + ")\nMin (" + minCol.getRed() + ", " + minCol.getGreen()
+ // + ", " + minCol.getBlue() + ")");
+ }
+ comp.setHorizontalAlignment(SwingConstants.CENTER);
+ comp.setText(tx.toString());
+ if (tt.length() > 0)
+ {
+ if (comp.getToolTipText() == null)
+ {
+ comp.setToolTipText(tt.toString());
+ }
+ else
+ {
+ comp.setToolTipText(tt.append(" ").append(comp.getToolTipText())
+ .toString());
+ }
+ }
+ }
}
-class ColorEditor extends AbstractCellEditor implements TableCellEditor,
- ActionListener
+class FeatureIcon implements Icon
{
- Color currentColor;
+ FeatureColourI gcol;
+
+ Color backg;
+
+ boolean midspace = false;
+
+ int width = 50, height = 20;
+
+ int s1, e1; // start and end of midpoint band for thresholded symbol
+
+ Color mpcolour = Color.white;
+
+ FeatureIcon(FeatureColourI gfc, Color bg, int w, int h, boolean mspace)
+ {
+ gcol = gfc;
+ backg = bg;
+ width = w;
+ height = h;
+ midspace = mspace;
+ if (midspace)
+ {
+ s1 = width / 3;
+ e1 = s1 * 2;
+ }
+ else
+ {
+ s1 = width / 2;
+ e1 = s1;
+ }
+ }
+
+ @Override
+ public int getIconWidth()
+ {
+ return width;
+ }
+
+ @Override
+ public int getIconHeight()
+ {
+ return height;
+ }
+
+ @Override
+ public void paintIcon(Component c, Graphics g, int x, int y)
+ {
+
+ if (gcol.isColourByLabel())
+ {
+ g.setColor(backg);
+ g.fillRect(0, 0, width, height);
+ // need an icon here.
+ g.setColor(gcol.getMaxColour());
+
+ g.setFont(new Font("Verdana", Font.PLAIN, 9));
+
+ // g.setFont(g.getFont().deriveFont(
+ // AffineTransform.getScaleInstance(
+ // width/g.getFontMetrics().stringWidth("Label"),
+ // height/g.getFontMetrics().getHeight())));
+
+ g.drawString(MessageManager.getString("label.label"), 0, 0);
+
+ }
+ else
+ {
+ Color minCol = gcol.getMinColour();
+ g.setColor(minCol);
+ g.fillRect(0, 0, s1, height);
+ if (midspace)
+ {
+ g.setColor(Color.white);
+ g.fillRect(s1, 0, e1 - s1, height);
+ }
+ g.setColor(gcol.getMaxColour());
+ g.fillRect(0, e1, width - e1, height);
+ }
+ }
+}
+
+class ColorEditor extends AbstractCellEditor
+ implements TableCellEditor, ActionListener
+{
+ FeatureSettings me;
+
+ FeatureColourI currentColor;
+
+ FeatureColourChooser chooser;
+
+ String type;
JButton button;
@@ -1268,8 +2295,11 @@ class ColorEditor extends AbstractCellEditor implements TableCellEditor,
protected static final String EDIT = "edit";
- public ColorEditor()
+ int selectedRow = 0;
+
+ public ColorEditor(FeatureSettings me)
{
+ this.me = me;
// Set up the editor (from the table's point of view),
// which is a button.
// This button brings up the color chooser dialog,
@@ -1280,7 +2310,8 @@ class ColorEditor extends AbstractCellEditor implements TableCellEditor,
button.setBorderPainted(false);
// Set up the dialog that the button brings up.
colorChooser = new JColorChooser();
- dialog = JColorChooser.createDialog(button, "Select new Colour", true, // modal
+ dialog = JColorChooser.createDialog(button,
+ MessageManager.getString("label.select_new_colour"), true, // modal
colorChooser, this, // OK button handler
null); // no CANCEL button handler
}
@@ -1288,6 +2319,7 @@ class ColorEditor extends AbstractCellEditor implements TableCellEditor,
/**
* Handles events from the editor button and from the dialog's OK button.
*/
+ @Override
public void actionPerformed(ActionEvent e)
{
@@ -1295,31 +2327,73 @@ class ColorEditor extends AbstractCellEditor implements TableCellEditor,
{
// The user has clicked the cell, so
// bring up the dialog.
- button.setBackground(currentColor);
- colorChooser.setColor(currentColor);
- dialog.setVisible(true);
-
+ if (currentColor.isSimpleColour())
+ {
+ // bring up simple color chooser
+ button.setBackground(currentColor.getColour());
+ colorChooser.setColor(currentColor.getColour());
+ dialog.setVisible(true);
+ }
+ else
+ {
+ // bring up graduated chooser.
+ chooser = new FeatureColourChooser(me.fr, type);
+ chooser.setRequestFocusEnabled(true);
+ chooser.requestFocus();
+ chooser.addActionListener(this);
+ }
// Make the renderer reappear.
fireEditingStopped();
}
else
{ // User pressed dialog's "OK" button.
- currentColor = colorChooser.getColor();
+ if (currentColor.isSimpleColour())
+ {
+ currentColor = new FeatureColour(colorChooser.getColor());
+ }
+ else
+ {
+ currentColor = chooser.getLastColour();
+ }
+ me.table.setValueAt(getCellEditorValue(), selectedRow, 1);
+ fireEditingStopped();
+ me.table.validate();
}
}
// Implement the one CellEditor method that AbstractCellEditor doesn't.
+ @Override
public Object getCellEditorValue()
{
return currentColor;
}
// Implement the one method defined by TableCellEditor.
+ @Override
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column)
{
- currentColor = (Color) value;
+ currentColor = (FeatureColourI) value;
+ this.selectedRow = row;
+ type = me.table.getValueAt(row, 0).toString();
+ button.setOpaque(true);
+ button.setBackground(me.getBackground());
+ if (!currentColor.isSimpleColour())
+ {
+ JLabel btn = new JLabel();
+ btn.setSize(button.getSize());
+ FeatureSettings.renderGraduatedColor(btn, currentColor);
+ button.setBackground(btn.getBackground());
+ button.setIcon(btn.getIcon());
+ button.setText(btn.getText());
+ }
+ else
+ {
+ button.setText("");
+ button.setIcon(null);
+ button.setBackground(currentColor.getColour());
+ }
return button;
}
}