dassources = resolved;
fetchDAS.setEnabled(false);
// cancelDAS.setEnabled(true); doDasFetch does this.
Runnable fetcher = new Runnable()
{
@Override
public void run()
{
doDasFeatureFetch(dassources, true, false);
}
};
if (block)
{
fetcher.run();
}
else
{
SwingUtilities.invokeLater(fetcher);
}
}
}
public void saveDAS_actionPerformed(ActionEvent e)
{
dassourceBrowser
.saveProperties(jalview.bin.Cache.applicationProperties);
}
public void complete()
{
fetchDAS.setEnabled(true);
cancelDAS.setEnabled(false);
dassourceBrowser.setGuiEnabled(true);
}
public void cancelDAS_actionPerformed(ActionEvent e)
{
if (dasFeatureFetcher != null)
{
dasFeatureFetcher.cancel();
}
complete();
}
public void noDasSourceActive()
{
complete();
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;
}
// ///////////////////////////////////////////////////////////////////////
// http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
// ///////////////////////////////////////////////////////////////////////
class FeatureTableModel extends AbstractTableModel
{
FeatureTableModel(Object[][] data)
{
this.data = data;
}
private String[] columnNames = {
MessageManager.getString("label.feature_type"),
MessageManager.getString("action.colour"),
MessageManager.getString("label.display") };
private Object[][] data;
public Object[][] getData()
{
return data;
}
public void setData(Object[][] data)
{
this.data = data;
}
@Override
public int getColumnCount()
{
return columnNames.length;
}
public Object[] getRow(int row)
{
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;
fireTableCellUpdated(row, col);
updateFeatureRenderer(data);
}
}
class ColorRenderer extends JLabel implements TableCellRenderer
{
javax.swing.border.Border unselectedBorder = null;
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);
}
@Override
public Component getTableCellRendererComponent(JTable tbl, Object color,
boolean isSelected, boolean hasFocus, int row, int column)
{
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,
tbl.getSelectionBackground());
}
setBorder(selectedBorder);
}
else
{
if (unselectedBorder == null)
{
unselectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5,
tbl.getBackground());
}
setBorder(unselectedBorder);
}
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(String.join(":", 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 FeatureIcon implements Icon
{
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;
JColorChooser colorChooser;
JDialog dialog;
protected static final String EDIT = "edit";
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,
// which is the editor from the user's point of view.
button = new JButton();
button.setActionCommand(EDIT);
button.addActionListener(this);
button.setBorderPainted(false);
// Set up the dialog that the button brings up.
colorChooser = new JColorChooser();
dialog = JColorChooser.createDialog(button,
MessageManager.getString("label.select_new_colour"), true, // modal
colorChooser, this, // OK button handler
null); // no CANCEL button handler
}
/**
* Handles events from the editor button and from the dialog's OK button.
*/
@Override
public void actionPerformed(ActionEvent e)
{
if (EDIT.equals(e.getActionCommand()))
{
// The user has clicked the cell, so
// bring up the dialog.
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.
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 = (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;
}
}