X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FFeatureSettings.java;h=0963b310575470461cb778dcc12cc43978f3cb03;hb=833fafa77f2f63bea98ce1d6e1e4ee3e46e7bd53;hp=0b645f23e24c9a135732b6ae90fdc51d1f645586;hpb=fc1e2dffbb79532ce2fb7d5e034c5137484fd569;p=jalview.git
diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java
old mode 100755
new mode 100644
index 0b645f2..0963b31
--- a/src/jalview/gui/FeatureSettings.java
+++ b/src/jalview/gui/FeatureSettings.java
@@ -1,41 +1,104 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
- * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This file is part of Jalview.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.gui;
-import java.io.*;
-import java.util.*;
-
-import java.awt.*;
-import java.awt.event.*;
+import jalview.api.FeatureColourI;
+import jalview.api.FeatureSettingsControllerI;
+import jalview.bin.Cache;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
+import jalview.gui.Help.HelpId;
+import jalview.io.JalviewFileChooser;
+import jalview.io.JalviewFileView;
+import jalview.schemabinding.version2.JalviewUserColours;
+import jalview.schemes.FeatureColour;
+import jalview.util.Format;
+import jalview.util.MessageManager;
+import jalview.util.Platform;
+import jalview.util.QuickSort;
+import jalview.viewmodel.AlignmentViewport;
+import jalview.ws.dbsources.das.api.jalviewSourceI;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.GridLayout;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionAdapter;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
-
-import javax.swing.*;
-import javax.swing.event.*;
-import javax.swing.table.*;
-
-import jalview.analysis.AlignmentSorter;
-import jalview.commands.OrderCommand;
-import jalview.datamodel.*;
-import jalview.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.help.HelpSetException;
+import javax.swing.AbstractCellEditor;
+import javax.swing.BorderFactory;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JColorChooser;
+import javax.swing.JDialog;
+import javax.swing.JInternalFrame;
+import javax.swing.JLabel;
+import javax.swing.JLayeredPane;
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JScrollPane;
+import javax.swing.JSlider;
+import javax.swing.JTabbedPane;
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.table.TableCellEditor;
+import javax.swing.table.TableCellRenderer;
public class FeatureSettings extends JPanel
+ implements FeatureSettingsControllerI
{
DasSourceBrowser dassourceBrowser;
@@ -51,6 +114,8 @@ public class FeatureSettings extends JPanel
Object[][] originalData;
+ private float originalTransparency;
+
final JInternalFrame frame;
JScrollPane scrollPane = new JScrollPane();
@@ -61,14 +126,24 @@ public class FeatureSettings extends JPanel
JSlider transparency = new JSlider();
- JPanel transPanel = new JPanel(new FlowLayout());
+ JPanel transPanel = new JPanel(new GridLayout(1, 2));
+ private static final int MIN_WIDTH = 400;
+
+ private static final int MIN_HEIGHT = 400;
+
+ /**
+ * Constructor
+ *
+ * @param af
+ */
public FeatureSettings(AlignFrame af)
{
this.af = af;
fr = af.getFeatureRenderer();
-
- transparency.setMaximum(100 - (int) (fr.transparency * 100));
+ // allow transparency to be recovered
+ transparency.setMaximum(100
+ - (int) ((originalTransparency = fr.getTransparency()) * 100));
try
{
@@ -78,75 +153,122 @@ public class FeatureSettings extends JPanel
ex.printStackTrace();
}
- table = new JTable();
+ table = new JTable()
+ {
+ @Override
+ public String getToolTipText(MouseEvent e)
+ {
+ if (table.columnAtPoint(e.getPoint()) == 0)
+ {
+ /*
+ * Tooltip for feature name only
+ */
+ return JvSwingUtils.wrapTooltip(true, MessageManager
+ .getString("label.feature_settings_click_drag"));
+ }
+ return null;
+ }
+ };
table.getTableHeader().setFont(new Font("Verdana", Font.PLAIN, 12));
table.setFont(new Font("Verdana", Font.PLAIN, 12));
table.setDefaultRenderer(Color.class, new ColorRenderer());
- table.setDefaultEditor(Color.class, new ColorEditor());
+ table.setDefaultEditor(Color.class, new ColorEditor(this));
+ table.setDefaultEditor(FeatureColour.class, new ColorEditor(this));
+ table.setDefaultRenderer(FeatureColour.class, new ColorRenderer());
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.addMouseListener(new MouseAdapter()
{
+ @Override
public void mousePressed(MouseEvent evt)
{
selectedRow = table.rowAtPoint(evt.getPoint());
- if (javax.swing.SwingUtilities.isRightMouseButton(evt))
+ if (evt.isPopupTrigger())
+ {
+ popupSort(selectedRow, (String) table.getValueAt(selectedRow, 0),
+ table.getValueAt(selectedRow, 1), fr.getMinMax(),
+ evt.getX(), evt.getY());
+ }
+ else if (evt.getClickCount() == 2)
+ {
+ boolean invertSelection = evt.isAltDown();
+ boolean toggleSelection = Platform.isControlDown(evt);
+ boolean extendSelection = evt.isShiftDown();
+ fr.ap.alignFrame.avc.markColumnsContainingFeatures(
+ invertSelection, extendSelection, toggleSelection,
+ (String) table.getValueAt(selectedRow, 0));
+ }
+ }
+
+ // isPopupTrigger fires on mouseReleased on Windows
+ @Override
+ public void mouseReleased(MouseEvent evt)
+ {
+ selectedRow = table.rowAtPoint(evt.getPoint());
+ if (evt.isPopupTrigger())
{
- popupSort((String)table.getValueAt(selectedRow, 0), evt.getX(), evt.getY());
+ popupSort(selectedRow, (String) table.getValueAt(selectedRow, 0),
+ table.getValueAt(selectedRow, 1), fr.getMinMax(),
+ evt.getX(), evt.getY());
}
}
});
table.addMouseMotionListener(new MouseMotionAdapter()
{
+ @Override
public void mouseDragged(MouseEvent evt)
{
int newRow = table.rowAtPoint(evt.getPoint());
if (newRow != selectedRow && selectedRow != -1 && newRow != -1)
{
- Object[] temp = new Object[3];
- temp[0] = table.getValueAt(selectedRow, 0);
- temp[1] = table.getValueAt(selectedRow, 1);
- temp[2] = table.getValueAt(selectedRow, 2);
-
- table.setValueAt(table.getValueAt(newRow, 0), selectedRow, 0);
- table.setValueAt(table.getValueAt(newRow, 1), selectedRow, 1);
- table.setValueAt(table.getValueAt(newRow, 2), selectedRow, 2);
-
- table.setValueAt(temp[0], newRow, 0);
- table.setValueAt(temp[1], newRow, 1);
- table.setValueAt(temp[2], newRow, 2);
-
+ /*
+ * reposition 'selectedRow' to 'newRow' (the dragged to location)
+ * this could be more than one row away for a very fast drag action
+ * so just swap it with adjacent rows until we get it there
+ */
+ Object[][] data = ((FeatureTableModel) table.getModel())
+ .getData();
+ int direction = newRow < selectedRow ? -1 : 1;
+ for (int i = selectedRow; i != newRow; i += direction)
+ {
+ Object[] temp = data[i];
+ data[i] = data[i + direction];
+ data[i + direction] = temp;
+ }
+ updateFeatureRenderer(data);
+ table.repaint();
selectedRow = newRow;
}
}
});
-
+ // table.setToolTipText(JvSwingUtils.wrapTooltip(true,
+ // MessageManager.getString("label.feature_settings_click_drag")));
scrollPane.setViewportView(table);
- dassourceBrowser = new DasSourceBrowser();
+ dassourceBrowser = new DasSourceBrowser(this);
dasSettingsPane.add(dassourceBrowser, BorderLayout.CENTER);
- if (af.getViewport().featuresDisplayed == null
- || fr.renderOrder == null)
+ if (af.getViewport().isShowSequenceFeatures() || !fr.hasRenderOrder())
{
fr.findAllFeatures(true); // display everything!
}
- setTableData();
+ discoverAllFeatureData();
final PropertyChangeListener change;
final FeatureSettings fs = this;
fr.addPropertyChangeListener(change = new PropertyChangeListener()
{
+ @Override
public void propertyChange(PropertyChangeEvent evt)
{
if (!fs.resettingTable && !fs.handlingUpdate)
{
fs.handlingUpdate = true;
fs.resetTable(null); // new groups may be added with new seuqence
- // feature types only
+ // feature types only
fs.handlingUpdate = false;
}
}
@@ -155,44 +277,198 @@ public class FeatureSettings extends JPanel
frame = new JInternalFrame();
frame.setContentPane(this);
- Desktop.addInternalFrame(frame, "Sequence Feature Settings", 400, 450);
- frame
- .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
+ if (Platform.isAMac())
+ {
+ Desktop.addInternalFrame(frame,
+ MessageManager.getString("label.sequence_feature_settings"),
+ 475, 480);
+ }
+ else
+ {
+ Desktop.addInternalFrame(frame,
+ MessageManager.getString("label.sequence_feature_settings"),
+ 400, 450);
+ }
+ frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
+
+ frame.addInternalFrameListener(
+ new javax.swing.event.InternalFrameAdapter()
{
+ @Override
public void internalFrameClosed(
javax.swing.event.InternalFrameEvent evt)
{
fr.removePropertyChangeListener(change);
+ dassourceBrowser.fs = null;
};
});
frame.setLayer(JLayeredPane.PALETTE_LAYER);
}
- protected void popupSort(final String type, int x, int y)
+ protected void popupSort(final int selectedRow, final String type,
+ final Object typeCol, final Map minmax, int x,
+ int y)
{
- JPopupMenu men = new JPopupMenu();
- men.setName("Sort by "+type);
- JMenuItem scr = new JMenuItem("Score");
+ final FeatureColourI featureColour = (FeatureColourI) typeCol;
+
+ JPopupMenu men = new JPopupMenu(MessageManager
+ .formatMessage("label.settings_for_param", new String[]
+ { type }));
+ JMenuItem scr = new JMenuItem(
+ MessageManager.getString("label.sort_by_score"));
men.add(scr);
- final FeatureSettings me=this;
- scr.addActionListener(new ActionListener() {
+ final FeatureSettings me = this;
+ scr.addActionListener(new ActionListener()
+ {
+ @Override
public void actionPerformed(ActionEvent e)
{
- me.sortByScore(new String[] {type});
+ me.af.avc
+ .sortAlignmentByFeatureScore(Arrays.asList(new String[]
+ { type }));
}
-
+
});
- JMenuItem dens = new JMenuItem("Density");
- dens.addActionListener(new ActionListener() {
+ JMenuItem dens = new JMenuItem(
+ MessageManager.getString("label.sort_by_density"));
+ dens.addActionListener(new ActionListener()
+ {
+ @Override
public void actionPerformed(ActionEvent e)
{
- me.sortByDens(new String[] { type });
+ me.af.avc
+ .sortAlignmentByFeatureDensity(Arrays.asList(new String[]
+ { type }));
}
-
+
});
men.add(dens);
+ if (minmax != null)
+ {
+ final float[][] typeMinMax = minmax.get(type);
+ /*
+ * final JCheckBoxMenuItem chb = new JCheckBoxMenuItem("Vary Height"); //
+ * this is broken at the moment and isn't that useful anyway!
+ * chb.setSelected(minmax.get(type) != null); chb.addActionListener(new
+ * ActionListener() {
+ *
+ * public void actionPerformed(ActionEvent e) {
+ * chb.setState(chb.getState()); if (chb.getState()) { minmax.put(type,
+ * null); } else { minmax.put(type, typeMinMax); } }
+ *
+ * });
+ *
+ * men.add(chb);
+ */
+ if (typeMinMax != null && typeMinMax[0] != null)
+ {
+ // if (table.getValueAt(row, column));
+ // graduated colourschemes for those where minmax exists for the
+ // positional features
+ final JCheckBoxMenuItem mxcol = new JCheckBoxMenuItem(
+ "Graduated Colour");
+ mxcol.setSelected(!featureColour.isSimpleColour());
+ men.add(mxcol);
+ mxcol.addActionListener(new ActionListener()
+ {
+ JColorChooser colorChooser;
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ if (e.getSource() == mxcol)
+ {
+ if (featureColour.isSimpleColour())
+ {
+ FeatureColourChooser fc = new FeatureColourChooser(me.fr,
+ type);
+ fc.addActionListener(this);
+ }
+ else
+ {
+ // bring up simple color chooser
+ colorChooser = new JColorChooser();
+ JDialog dialog = JColorChooser.createDialog(me,
+ "Select new Colour", true, // modal
+ colorChooser, this, // OK button handler
+ null); // no CANCEL button handler
+ colorChooser.setColor(featureColour.getMaxColour());
+ dialog.setVisible(true);
+ }
+ }
+ else
+ {
+ if (e.getSource() instanceof FeatureColourChooser)
+ {
+ FeatureColourChooser fc = (FeatureColourChooser) e
+ .getSource();
+ table.setValueAt(fc.getLastColour(), selectedRow, 1);
+ table.validate();
+ }
+ else
+ {
+ // probably the color chooser!
+ table.setValueAt(new FeatureColour(colorChooser.getColor()),
+ selectedRow, 1);
+ table.validate();
+ me.updateFeatureRenderer(
+ ((FeatureTableModel) table.getModel()).getData(),
+ false);
+ }
+ }
+ }
+
+ });
+ }
+ }
+ JMenuItem selCols = new JMenuItem(
+ MessageManager.getString("label.select_columns_containing"));
+ selCols.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent arg0)
+ {
+ fr.ap.alignFrame.avc.markColumnsContainingFeatures(false, false,
+ false, type);
+ }
+ });
+ JMenuItem clearCols = new JMenuItem(MessageManager
+ .getString("label.select_columns_not_containing"));
+ clearCols.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent arg0)
+ {
+ fr.ap.alignFrame.avc.markColumnsContainingFeatures(true, false,
+ false, type);
+ }
+ });
+ JMenuItem hideCols = new JMenuItem(
+ MessageManager.getString("label.hide_columns_containing"));
+ hideCols.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent arg0)
+ {
+ fr.ap.alignFrame.hideFeatureColumns(type, true);
+ }
+ });
+ JMenuItem hideOtherCols = new JMenuItem(
+ MessageManager.getString("label.hide_columns_not_containing"));
+ hideOtherCols.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent arg0)
+ {
+ fr.ap.alignFrame.hideFeatureColumns(type, false);
+ }
+ });
+ men.add(selCols);
+ men.add(clearCols);
+ men.add(hideCols);
+ men.add(hideOtherCols);
men.show(table, x, y);
}
@@ -202,58 +478,26 @@ public class FeatureSettings extends JPanel
private boolean handlingUpdate = false;
/**
- * contains a float[3] for each feature type string. created by setTableData
+ * holds {featureCount, totalExtent} for each feature type
*/
- Hashtable typeWidth = null;
+ Map typeWidth = null;
- synchronized public void setTableData()
+ @Override
+ synchronized public void discoverAllFeatureData()
{
- if (fr.featureGroups == null)
- {
- fr.featureGroups = new Hashtable();
- }
- Vector allFeatures = new Vector();
- Vector allGroups = new Vector();
- SequenceFeature[] tmpfeatures;
- String group;
- for (int i = 0; i < af.getViewport().alignment.getHeight(); i++)
- {
- if (af.getViewport().alignment.getSequenceAt(i).getDatasetSequence()
- .getSequenceFeatures() == null)
- {
- continue;
- }
-
- tmpfeatures = af.getViewport().alignment.getSequenceAt(i)
- .getDatasetSequence().getSequenceFeatures();
+ Set allGroups = new HashSet();
+ AlignmentI alignment = af.getViewport().getAlignment();
- int index = 0;
- while (index < tmpfeatures.length)
+ for (int i = 0; i < alignment.getHeight(); i++)
+ {
+ SequenceI seq = alignment.getSequenceAt(i);
+ for (String group : seq.getFeatures().getFeatureGroups(true))
{
- if (tmpfeatures[index].begin == 0 && tmpfeatures[index].end == 0)
+ if (group != null && !allGroups.contains(group))
{
- index++;
- continue;
- }
-
- if (tmpfeatures[index].getFeatureGroup() != null)
- {
- group = tmpfeatures[index].featureGroup;
- if (!allGroups.contains(group))
- {
- allGroups.addElement(group);
- if (group != null)
- {
- checkGroupState(group);
- }
- }
- }
-
- if (!allFeatures.contains(tmpfeatures[index].getType()))
- {
- allFeatures.addElement(tmpfeatures[index].getType());
+ allGroups.add(group);
+ checkGroupState(group);
}
- index++;
}
}
@@ -263,217 +507,272 @@ public class FeatureSettings extends JPanel
}
/**
+ * Synchronise gui group list and check visibility of group
*
* @param group
- * @return true if group has been seen before and is already added to set.
+ * @return true if group is visible
*/
private boolean checkGroupState(String group)
{
- boolean visible;
- if (fr.featureGroups.containsKey(group))
- {
- visible = ((Boolean) fr.featureGroups.get(group)).booleanValue();
- }
- else
- {
- visible = true; // new group is always made visible
- }
-
- if (groupPanel == null)
- {
- groupPanel = new JPanel();
- }
+ boolean visible = fr.checkGroupVisibility(group, true);
- boolean alreadyAdded = false;
for (int g = 0; g < groupPanel.getComponentCount(); g++)
{
if (((JCheckBox) groupPanel.getComponent(g)).getText().equals(group))
{
- alreadyAdded = true;
((JCheckBox) groupPanel.getComponent(g)).setSelected(visible);
- break;
+ return visible;
}
}
- if (alreadyAdded)
- {
-
- return true;
- }
-
- fr.featureGroups.put(group, new Boolean(visible));
final String grp = group;
final JCheckBox check = new JCheckBox(group, visible);
check.setFont(new Font("Serif", Font.BOLD, 12));
+ check.setToolTipText(group);
check.addItemListener(new ItemListener()
{
+ @Override
public void itemStateChanged(ItemEvent evt)
{
- fr.featureGroups.put(check.getText(), new Boolean(check
- .isSelected()));
- af.alignPanel.seqPanel.seqCanvas.repaint();
+ fr.setGroupVisibility(check.getText(), check.isSelected());
+ af.alignPanel.getSeqPanel().seqCanvas.repaint();
if (af.alignPanel.overviewPanel != null)
{
af.alignPanel.overviewPanel.updateOverviewImage();
}
- resetTable(new String[]
- { grp });
+ resetTable(new String[] { grp });
}
});
groupPanel.add(check);
- return false;
+ return visible;
}
boolean resettingTable = false;
synchronized void resetTable(String[] groupChanged)
{
- if (resettingTable == true)
+ if (resettingTable)
{
return;
}
resettingTable = true;
- typeWidth = new Hashtable();
+ typeWidth = new Hashtable();
// TODO: change avWidth calculation to 'per-sequence' average and use long
// rather than float
- float[] avWidth = null;
- SequenceFeature[] tmpfeatures;
- String group = null, type;
- Vector visibleChecks = new Vector();
- // Find out which features should be visible depending on which groups
- // are selected / deselected
- // and recompute average width ordering
- for (int i = 0; i < af.getViewport().alignment.getHeight(); i++)
+ Set displayableTypes = new HashSet();
+ Set foundGroups = new HashSet();
+
+ /*
+ * determine which feature types may be visible depending on
+ * which groups are selected, and recompute average width data
+ */
+ for (int i = 0; i < af.getViewport().getAlignment().getHeight(); i++)
{
- tmpfeatures = af.getViewport().alignment.getSequenceAt(i)
- .getDatasetSequence().getSequenceFeatures();
- if (tmpfeatures == null)
- {
- continue;
- }
+ SequenceI seq = af.getViewport().getAlignment().getSequenceAt(i);
- int index = 0;
- while (index < tmpfeatures.length)
+ /*
+ * get the sequence's groups for positional features
+ * and keep track of which groups are visible
+ */
+ Set groups = seq.getFeatures().getFeatureGroups(true);
+ Set visibleGroups = new HashSet();
+ for (String group : groups)
{
- group = tmpfeatures[index].featureGroup;
-
- if (tmpfeatures[index].begin == 0 && tmpfeatures[index].end == 0)
- {
- index++;
- continue;
- }
-
- if (group == null || fr.featureGroups.get(group) == null
- || ((Boolean) fr.featureGroups.get(group)).booleanValue())
- {
- if (group != null)
- checkGroupState(group);
- type = tmpfeatures[index].getType();
- if (!visibleChecks.contains(type))
- {
- visibleChecks.addElement(type);
- }
- }
- if (!typeWidth.containsKey(tmpfeatures[index].getType()))
- {
- typeWidth.put(tmpfeatures[index].getType(),
- avWidth = new float[3]);
- }
- else
- {
- avWidth = (float[]) typeWidth.get(tmpfeatures[index].getType());
- }
- avWidth[0]++;
- if (tmpfeatures[index].getBegin() > tmpfeatures[index].getEnd())
+ if (group == null || checkGroupState(group))
{
- avWidth[1] += 1 + tmpfeatures[index].getBegin()
- - tmpfeatures[index].getEnd();
+ visibleGroups.add(group);
}
- else
+ }
+ foundGroups.addAll(groups);
+
+ /*
+ * get distinct feature types for visible groups
+ * record distinct visible types, and their count and total length
+ */
+ Set types = seq.getFeatures().getFeatureTypesForGroups(true,
+ visibleGroups.toArray(new String[visibleGroups.size()]));
+ for (String type : types)
+ {
+ displayableTypes.add(type);
+ float[] avWidth = typeWidth.get(type);
+ if (avWidth == null)
{
- avWidth[1] += 1 + tmpfeatures[index].getEnd()
- - tmpfeatures[index].getBegin();
+ avWidth = new float[2];
+ typeWidth.put(type, avWidth);
}
- index++;
+ // todo this could include features with a non-visible group
+ // - do we greatly care?
+ // todo should we include non-displayable features here, and only
+ // update when features are added?
+ avWidth[0] += seq.getFeatures().getFeatureCount(true, type);
+ avWidth[1] += seq.getFeatures().getTotalFeatureLength(type);
}
}
- int fSize = visibleChecks.size();
- Object[][] data = new Object[fSize][3];
+ Object[][] data = new Object[displayableTypes.size()][3];
int dataIndex = 0;
- if (fr.renderOrder != null)
+ if (fr.hasRenderOrder())
{
if (!handlingUpdate)
+ {
fr.findAllFeatures(groupChanged != null); // prod to update
- // colourschemes. but don't
- // affect display
- // First add the checks in the previous render order,
- // in case the window has been closed and reopened
- for (int ro = fr.renderOrder.length - 1; ro > -1; ro--)
+ // colourschemes. but don't
+ // affect display
+ // First add the checks in the previous render order,
+ // in case the window has been closed and reopened
+ }
+ List frl = fr.getRenderOrder();
+ for (int ro = frl.size() - 1; ro > -1; ro--)
{
- type = fr.renderOrder[ro];
+ String type = frl.get(ro);
- if (!visibleChecks.contains(type))
+ if (!displayableTypes.contains(type))
{
continue;
}
data[dataIndex][0] = type;
- data[dataIndex][1] = fr.getColour(type);
- data[dataIndex][2] = new Boolean(af.getViewport().featuresDisplayed
- .containsKey(type));
+ data[dataIndex][1] = fr.getFeatureStyle(type);
+ data[dataIndex][2] = new Boolean(
+ af.getViewport().getFeaturesDisplayed().isVisible(type));
dataIndex++;
- visibleChecks.removeElement(type);
+ displayableTypes.remove(type);
}
}
- fSize = visibleChecks.size();
- for (int i = 0; i < fSize; i++)
+ /*
+ * process any extra features belonging only to
+ * a group which was just selected
+ */
+ while (!displayableTypes.isEmpty())
{
- // These must be extra features belonging to the group
- // which was just selected
- type = visibleChecks.elementAt(i).toString();
+ String type = displayableTypes.iterator().next();
data[dataIndex][0] = type;
- data[dataIndex][1] = fr.getColour(type);
+ data[dataIndex][1] = fr.getFeatureStyle(type);
if (data[dataIndex][1] == null)
{
// "Colour has been updated in another view!!"
- fr.renderOrder = null;
+ fr.clearRenderOrder();
return;
}
data[dataIndex][2] = new Boolean(true);
dataIndex++;
+ displayableTypes.remove(type);
}
if (originalData == null)
{
originalData = new Object[data.length][3];
- System.arraycopy(data, 0, originalData, 0, data.length);
+ for (int i = 0; i < data.length; i++)
+ {
+ System.arraycopy(data[i], 0, originalData[i], 0, 3);
+ }
+ }
+ else
+ {
+ updateOriginalData(data);
}
table.setModel(new FeatureTableModel(data));
table.getColumnModel().getColumn(0).setPreferredWidth(200);
- if (groupPanel != null)
- {
- groupPanel.setLayout(new GridLayout(fr.featureGroups.size() / 4 + 1,
- 4));
-
- groupPanel.validate();
- bigPanel.add(groupPanel, BorderLayout.NORTH);
- }
+ groupPanel.setLayout(
+ new GridLayout(fr.getFeatureGroupsSize() / 4 + 1, 4));
+ pruneGroups(foundGroups);
+ groupPanel.validate();
updateFeatureRenderer(data, groupChanged != null);
resettingTable = false;
}
/**
+ * Updates 'originalData' (used for restore on Cancel) if we detect that
+ * changes have been made outwith this dialog
+ *
+ * - a new feature type added (and made visible)
+ * - a feature colour changed (in the Amend Features dialog)
+ *
+ *
+ * @param foundData
+ */
+ protected void updateOriginalData(Object[][] foundData)
+ {
+ // todo LinkedHashMap instead of Object[][] would be nice
+
+ Object[][] currentData = ((FeatureTableModel) table.getModel())
+ .getData();
+ for (Object[] row : foundData)
+ {
+ String type = (String) row[0];
+ boolean found = false;
+ for (Object[] current : currentData)
+ {
+ if (type.equals(current[0]))
+ {
+ found = true;
+ /*
+ * currently dependent on object equality here;
+ * really need an equals method on FeatureColour
+ */
+ if (!row[1].equals(current[1]))
+ {
+ /*
+ * feature colour has changed externally - update originalData
+ */
+ for (Object[] original : originalData)
+ {
+ if (type.equals(original[0]))
+ {
+ original[1] = row[1];
+ break;
+ }
+ }
+ }
+ break;
+ }
+ }
+ if (!found)
+ {
+ /*
+ * new feature detected - add to original data (on top)
+ */
+ Object[][] newData = new Object[originalData.length + 1][3];
+ for (int i = 0; i < originalData.length; i++)
+ {
+ System.arraycopy(originalData[i], 0, newData[i + 1], 0, 3);
+ }
+ newData[0] = row;
+ originalData = newData;
+ }
+ }
+ }
+
+ /**
+ * Remove from the groups panel any checkboxes for groups that are not in the
+ * foundGroups set. This enables removing a group from the display when the
+ * last feature in that group is deleted.
+ *
+ * @param foundGroups
+ */
+ protected void pruneGroups(Set foundGroups)
+ {
+ for (int g = 0; g < groupPanel.getComponentCount(); g++)
+ {
+ JCheckBox checkbox = (JCheckBox) groupPanel.getComponent(g);
+ if (!foundGroups.contains(checkbox.getText()))
+ {
+ groupPanel.remove(checkbox);
+ }
+ }
+ }
+
+ /**
* reorder data based on the featureRenderers global priority list.
*
* @param data
@@ -486,23 +785,28 @@ public class FeatureSettings extends JPanel
{
order[i] = fr.getOrder(data[i][0].toString());
if (order[i] < 0)
+ {
order[i] = fr.setOrder(data[i][0].toString(), i / order.length);
+ }
if (i > 1)
+ {
sort = sort || order[i - 1] > order[i];
+ }
}
if (sort)
+ {
jalview.util.QuickSort.sort(order, data);
+ }
}
void load()
{
- JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
- .getProperty("LAST_DIRECTORY"), new String[]
- { "fc" }, new String[]
- { "Sequence Feature Colours" }, "Sequence Feature Colours");
- chooser.setFileView(new jalview.io.JalviewFileView());
- chooser.setDialogTitle("Load Feature Colours");
- chooser.setToolTipText("Load");
+ JalviewFileChooser chooser = new JalviewFileChooser("fc",
+ "Sequence Feature Colours");
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle(
+ MessageManager.getString("label.load_feature_colours"));
+ chooser.setToolTipText(MessageManager.getString("action.load"));
int value = chooser.showOpenDialog(this);
@@ -512,17 +816,63 @@ public class FeatureSettings extends JPanel
try
{
- InputStreamReader in = new InputStreamReader(new FileInputStream(
- file), "UTF-8");
+ InputStreamReader in = new InputStreamReader(
+ new FileInputStream(file), "UTF-8");
- jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours();
- jucs = (jalview.binding.JalviewUserColours) jucs.unmarshal(in);
+ JalviewUserColours jucs = JalviewUserColours.unmarshal(in);
for (int i = jucs.getColourCount() - 1; i >= 0; i--)
{
String name;
- fr.setColour(name = jucs.getColour(i).getName(), new Color(
- Integer.parseInt(jucs.getColour(i).getRGB(), 16)));
+ jalview.schemabinding.version2.Colour newcol = jucs.getColour(i);
+ if (newcol.hasMax())
+ {
+ Color mincol = null, maxcol = null;
+ try
+ {
+ mincol = new Color(Integer.parseInt(newcol.getMinRGB(), 16));
+ maxcol = new Color(Integer.parseInt(newcol.getRGB(), 16));
+
+ } catch (Exception e)
+ {
+ Cache.log.warn("Couldn't parse out graduated feature color.",
+ e);
+ }
+ FeatureColourI gcol = new FeatureColour(mincol, maxcol,
+ newcol.getMin(), newcol.getMax());
+ if (newcol.hasAutoScale())
+ {
+ gcol.setAutoScaled(newcol.getAutoScale());
+ }
+ if (newcol.hasColourByLabel())
+ {
+ gcol.setColourByLabel(newcol.getColourByLabel());
+ }
+ if (newcol.hasThreshold())
+ {
+ gcol.setThreshold(newcol.getThreshold());
+ }
+ if (newcol.getThreshType().length() > 0)
+ {
+ String ttyp = newcol.getThreshType();
+ if (ttyp.equalsIgnoreCase("ABOVE"))
+ {
+ gcol.setAboveThreshold(true);
+ }
+ if (ttyp.equalsIgnoreCase("BELOW"))
+ {
+ gcol.setBelowThreshold(true);
+ }
+ }
+ fr.setColour(name = newcol.getName(), gcol);
+ }
+ else
+ {
+ Color color = new Color(
+ Integer.parseInt(jucs.getColour(i).getRGB(), 16));
+ fr.setColour(name = jucs.getColour(i).getName(),
+ new FeatureColour(color));
+ }
fr.setOrder(name, (i == 0) ? 0 : i / jucs.getColourCount());
}
if (table != null)
@@ -543,44 +893,60 @@ public class FeatureSettings extends JPanel
void save()
{
- JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
- .getProperty("LAST_DIRECTORY"), new String[]
- { "fc" }, new String[]
- { "Sequence Feature Colours" }, "Sequence Feature Colours");
- chooser.setFileView(new jalview.io.JalviewFileView());
- chooser.setDialogTitle("Save Feature Colour Scheme");
- chooser.setToolTipText("Save");
+ JalviewFileChooser chooser = new JalviewFileChooser("fc",
+ "Sequence Feature Colours");
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle(
+ MessageManager.getString("label.save_feature_colours"));
+ chooser.setToolTipText(MessageManager.getString("action.save"));
int value = chooser.showSaveDialog(this);
if (value == JalviewFileChooser.APPROVE_OPTION)
{
String choice = chooser.getSelectedFile().getPath();
- jalview.binding.JalviewUserColours ucs = new jalview.binding.JalviewUserColours();
+ jalview.schemabinding.version2.JalviewUserColours ucs = new jalview.schemabinding.version2.JalviewUserColours();
ucs.setSchemeName("Sequence Features");
try
{
PrintWriter out = new PrintWriter(new OutputStreamWriter(
new FileOutputStream(choice), "UTF-8"));
- Enumeration e = fr.featureColours.keys();
- float[] sortOrder = new float[fr.featureColours.size()];
- String[] sortTypes = new String[fr.featureColours.size()];
+ Set fr_colours = fr.getAllFeatureColours();
+ Iterator e = fr_colours.iterator();
+ float[] sortOrder = new float[fr_colours.size()];
+ String[] sortTypes = new String[fr_colours.size()];
int i = 0;
- while (e.hasMoreElements())
+ while (e.hasNext())
{
- sortTypes[i] = e.nextElement().toString();
+ sortTypes[i] = e.next();
sortOrder[i] = fr.getOrder(sortTypes[i]);
i++;
}
- jalview.util.QuickSort.sort(sortOrder, sortTypes);
+ QuickSort.sort(sortOrder, sortTypes);
sortOrder = null;
for (i = 0; i < sortTypes.length; i++)
{
- jalview.binding.Colour col = new jalview.binding.Colour();
+ jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();
col.setName(sortTypes[i]);
- col.setRGB(jalview.util.Format.getHexString(fr.getColour(col
- .getName())));
+ FeatureColourI fcol = fr.getFeatureStyle(sortTypes[i]);
+ if (fcol.isSimpleColour())
+ {
+ col.setRGB(Format.getHexString(fcol.getColour()));
+ }
+ else
+ {
+ col.setRGB(Format.getHexString(fcol.getMaxColour()));
+ col.setMin(fcol.getMin());
+ col.setMax(fcol.getMax());
+ col.setMinRGB(
+ jalview.util.Format.getHexString(fcol.getMinColour()));
+ col.setAutoScale(fcol.isAutoScaled());
+ col.setThreshold(fcol.getThreshold());
+ col.setColourByLabel(fcol.isColourByLabel());
+ col.setThreshType(fcol.isAboveThreshold() ? "ABOVE"
+ : (fcol.isBelowThreshold() ? "BELOW" : "NONE"));
+ }
ucs.addColour(col);
}
ucs.marshal(out);
@@ -605,7 +971,9 @@ public class FeatureSettings extends JPanel
public void orderByAvWidth()
{
if (table == null || table.getModel() == null)
+ {
return;
+ }
Object[][] data = ((FeatureTableModel) table.getModel()).getData();
float[] width = new float[data.length];
float[] awidth;
@@ -613,12 +981,12 @@ public class FeatureSettings extends JPanel
int num = 0;
for (int i = 0; i < data.length; i++)
{
- awidth = (float[]) typeWidth.get(data[i][0]);
+ awidth = typeWidth.get(data[i][0]);
if (awidth[0] > 0)
{
width[i] = awidth[1] / awidth[0];// *awidth[0]*awidth[2]; - better
- // weight - but have to make per
- // sequence, too (awidth[2])
+ // weight - but have to make per
+ // sequence, too (awidth[2])
// if (width[i]==1) // hack to distinguish single width sequences.
num++;
}
@@ -627,7 +995,9 @@ public class FeatureSettings extends JPanel
width[i] = 0;
}
if (max < width[i])
+ {
max = width[i];
+ }
}
boolean sort = false;
for (int i = 0; i < width.length; i++)
@@ -647,11 +1017,15 @@ public class FeatureSettings extends JPanel
fr.setOrder(data[i][0].toString(), width[i]); // store for later
}
if (i > 0)
+ {
sort = sort || width[i - 1] > width[i];
+ }
}
if (sort)
+ {
jalview.util.QuickSort.sort(width, data);
- // update global priority order
+ // update global priority order
+ }
updateFeatureRenderer(data, false);
table.repaint();
@@ -673,10 +1047,19 @@ public class FeatureSettings extends JPanel
updateFeatureRenderer(data, true);
}
+ /**
+ * Update the priority order of features; only repaint if this changed the
+ * order of visible features
+ *
+ * @param data
+ * @param visibleNew
+ */
private void updateFeatureRenderer(Object[][] data, boolean visibleNew)
{
- fr.setFeaturePriority(data, visibleNew);
- af.alignPanel.paintAlignment(true);
+ if (fr.setFeaturePriority(data, visibleNew))
+ {
+ af.alignPanel.paintAlignment(true);
+ }
}
int selectedRow = -1;
@@ -714,10 +1097,14 @@ public class FeatureSettings extends JPanel
JButton cancelDAS = new JButton();
JButton optimizeOrder = new JButton();
+
JButton sortByScore = new JButton();
+
JButton sortByDens = new JButton();
- JPanel transbuttons = new JPanel(new BorderLayout());
+ JButton help = new JButton();
+
+ JPanel transbuttons = new JPanel(new GridLayout(5, 1));
private void jbInit() throws Exception
{
@@ -725,73 +1112,121 @@ public class FeatureSettings extends JPanel
settingsPane.setLayout(borderLayout2);
dasSettingsPane.setLayout(borderLayout3);
bigPanel.setLayout(borderLayout4);
- invert.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
- invert.setText("Invert Selection");
+
+ groupPanel = new JPanel();
+ bigPanel.add(groupPanel, BorderLayout.NORTH);
+
+ invert.setFont(JvSwingUtils.getLabelFont());
+ invert.setText(MessageManager.getString("label.invert_selection"));
invert.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
invertSelection();
}
});
- optimizeOrder.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
- optimizeOrder.setText("Optimise Order");
+ optimizeOrder.setFont(JvSwingUtils.getLabelFont());
+ optimizeOrder.setText(MessageManager.getString("label.optimise_order"));
optimizeOrder.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
orderByAvWidth();
}
});
- sortByScore.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
- sortByScore.setText("Seq sort by Score");
+ sortByScore.setFont(JvSwingUtils.getLabelFont());
+ sortByScore
+ .setText(MessageManager.getString("label.seq_sort_by_score"));
sortByScore.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
- sortByScore(null);
+ af.avc.sortAlignmentByFeatureScore(null);
}
});
- sortByDens.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
- sortByDens.setText("Seq Sort by density");
+ sortByDens.setFont(JvSwingUtils.getLabelFont());
+ sortByDens.setText(
+ MessageManager.getString("label.sequence_sort_by_density"));
sortByDens.addActionListener(new ActionListener()
{
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ af.avc.sortAlignmentByFeatureDensity(null);
+ }
+ });
+ help.setFont(JvSwingUtils.getLabelFont());
+ help.setText(MessageManager.getString("action.help"));
+ help.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ try
+ {
+ Help.showHelpWindow(HelpId.SequenceFeatureSettings);
+ } catch (HelpSetException e1)
+ {
+ e1.printStackTrace();
+ }
+ }
+ });
+ help.setFont(JvSwingUtils.getLabelFont());
+ help.setText(MessageManager.getString("action.help"));
+ help.addActionListener(new ActionListener()
+ {
+ @Override
public void actionPerformed(ActionEvent e)
{
- sortByDens(null);
+ try
+ {
+ Help.showHelpWindow(HelpId.SequenceFeatureSettings);
+ } catch (HelpSetException e1)
+ {
+ e1.printStackTrace();
+ }
}
- }); cancel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
- cancel.setText("Cancel");
+ });
+ cancel.setFont(JvSwingUtils.getLabelFont());
+ cancel.setText(MessageManager.getString("action.cancel"));
cancel.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
+ fr.setTransparency(originalTransparency);
updateFeatureRenderer(originalData);
close();
}
});
- ok.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
- ok.setText("OK");
+ ok.setFont(JvSwingUtils.getLabelFont());
+ ok.setText(MessageManager.getString("action.ok"));
ok.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
close();
}
});
- loadColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
- loadColours.setText("Load Colours");
+ loadColours.setFont(JvSwingUtils.getLabelFont());
+ loadColours.setText(MessageManager.getString("label.load_colours"));
loadColours.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
load();
}
});
- saveColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
- saveColours.setText("Save Colours");
+ saveColours.setFont(JvSwingUtils.getLabelFont());
+ saveColours.setText(MessageManager.getString("label.save_colours"));
saveColours.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
save();
@@ -799,25 +1234,30 @@ public class FeatureSettings extends JPanel
});
transparency.addChangeListener(new ChangeListener()
{
+ @Override
public void stateChanged(ChangeEvent evt)
{
- fr.setTransparency((float) (100 - transparency.getValue()) / 100f);
+ fr.setTransparency((100 - transparency.getValue()) / 100f);
af.alignPanel.paintAlignment(true);
}
});
transparency.setMaximum(70);
- fetchDAS.setText("Fetch DAS Features");
+ transparency.setToolTipText(
+ MessageManager.getString("label.transparency_tip"));
+ fetchDAS.setText(MessageManager.getString("label.fetch_das_features"));
fetchDAS.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
fetchDAS_actionPerformed(e);
}
});
- saveDAS.setText("Save as default");
+ saveDAS.setText(MessageManager.getString("action.save_as_default"));
saveDAS.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
saveDAS_actionPerformed(e);
@@ -826,28 +1266,34 @@ public class FeatureSettings extends JPanel
dasButtonPanel.setBorder(BorderFactory.createEtchedBorder());
dasSettingsPane.setBorder(null);
cancelDAS.setEnabled(false);
- cancelDAS.setText("Cancel Fetch");
+ cancelDAS.setText(MessageManager.getString("action.cancel_fetch"));
cancelDAS.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
cancelDAS_actionPerformed(e);
}
});
this.add(tabbedPane, java.awt.BorderLayout.CENTER);
- tabbedPane.addTab("Feature Settings", settingsPane);
- tabbedPane.addTab("DAS Settings", dasSettingsPane);
+ tabbedPane.addTab(MessageManager.getString("label.feature_settings"),
+ settingsPane);
+ tabbedPane.addTab(MessageManager.getString("label.das_settings"),
+ dasSettingsPane);
bigPanel.add(transPanel, java.awt.BorderLayout.SOUTH);
+ transbuttons.add(optimizeOrder);
+ transbuttons.add(invert);
+ transbuttons.add(sortByScore);
+ transbuttons.add(sortByDens);
+ transbuttons.add(help);
+ JPanel sliderPanel = new JPanel();
+ sliderPanel.add(transparency);
transPanel.add(transparency);
- transbuttons.add(invert, java.awt.BorderLayout.NORTH);
- transbuttons.add(optimizeOrder, java.awt.BorderLayout.SOUTH);
transPanel.add(transbuttons);
buttonPanel.add(ok);
buttonPanel.add(cancel);
buttonPanel.add(loadColours);
buttonPanel.add(saveColours);
- buttonPanel.add(sortByScore);
- buttonPanel.add(sortByDens);
bigPanel.add(scrollPane, java.awt.BorderLayout.CENTER);
dasSettingsPane.add(dasButtonPanel, java.awt.BorderLayout.SOUTH);
dasButtonPanel.add(fetchDAS);
@@ -857,119 +1303,13 @@ public class FeatureSettings extends JPanel
settingsPane.add(buttonPanel, java.awt.BorderLayout.SOUTH);
}
- protected void sortByDens(String[] typ)
- {
- sortBy(typ, "Sort by Density", AlignmentSorter.FEATURE_DENSITY);
- }
- protected void sortBy(String[] typ, String methodText, final String method) {
- if (typ==null)
- {
- typ = getDisplayedFeatureTypes();
- }
- String gps[]=null;
- gps = getDisplayedFeatureGroups();
- if (typ!=null)
- {
- for (int i=0;i selectedSources = dassourceBrowser
+ .getSelectedSources();
doDasFeatureFetch(selectedSources, true, true);
}
@@ -980,12 +1320,12 @@ public class FeatureSettings extends JPanel
* @param checkDbRefs
* @param promptFetchDbRefs
*/
- private void doDasFeatureFetch(Vector selectedSources,
+ private void doDasFeatureFetch(List selectedSources,
boolean checkDbRefs, boolean promptFetchDbRefs)
{
SequenceI[] dataset, seqs;
int iSize;
- AlignViewport vp = af.getViewport();
+ AlignmentViewport vp = af.getViewport();
if (vp.getSelectionGroup() != null
&& vp.getSelectionGroup().getSize() > 0)
{
@@ -1019,51 +1359,72 @@ public class FeatureSettings extends JPanel
{
dassourceBrowser.initDasSources();
}
+
/**
- * examine the current list of das sources and return any matching the given nicknames in sources
- * @param sources Vector of Strings to resolve to DAS source nicknames.
+ * examine the current list of das sources and return any matching the given
+ * nicknames in sources
+ *
+ * @param sources
+ * Vector of Strings to resolve to DAS source nicknames.
* @return sources that are present in source list.
*/
- public Vector resolveSourceNicknames(Vector sources)
+ public List resolveSourceNicknames(Vector sources)
{
- return dassourceBrowser.resolveSourceNicknames(sources);
+ return dassourceBrowser.sourceRegistry.resolveSourceNicknames(sources);
}
+
/**
- * get currently selected das sources. ensure you have called initDasSources before calling this.
+ * get currently selected das sources. ensure you have called initDasSources
+ * before calling this.
+ *
* @return vector of selected das source nicknames
*/
- public Vector getSelectedSources()
+ public Vector getSelectedSources()
{
return dassourceBrowser.getSelectedSources();
}
+
/**
* properly initialise DAS fetcher and then initiate a new thread to fetch
* features from the named sources (rather than any turned on by default)
*
* @param sources
+ * @param block
+ * if true then runs in same thread, otherwise passes to the Swing
+ * executor
*/
- public void fetchDasFeatures(Vector sources)
+ public void fetchDasFeatures(Vector sources, boolean block)
{
initDasSources();
- Vector resolved = resolveSourceNicknames(sources);
+ List resolved = dassourceBrowser.sourceRegistry
+ .resolveSourceNicknames(sources);
if (resolved.size() == 0)
{
resolved = dassourceBrowser.getSelectedSources();
}
if (resolved.size() > 0)
{
- final Vector dassources = resolved;
- SwingUtilities.invokeLater(new Runnable()
+ final List 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);
+ }
}
}
@@ -1077,6 +1438,8 @@ public class FeatureSettings extends JPanel
{
fetchDAS.setEnabled(true);
cancelDAS.setEnabled(false);
+ dassourceBrowser.setGuiEnabled(true);
+
}
public void cancelDAS_actionPerformed(ActionEvent e)
@@ -1085,18 +1448,16 @@ 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);
}
// ///////////////////////////////////////////////////////////////////////
@@ -1109,8 +1470,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;
@@ -1124,6 +1487,7 @@ public class FeatureSettings extends JPanel
this.data = data;
}
+ @Override
public int getColumnCount()
{
return columnNames.length;
@@ -1134,31 +1498,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;
@@ -1174,23 +1544,48 @@ 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)
- {
- Color newColor = (Color) color;
- setBackground(newColor);
+ @Override
+ public Component getTableCellRendererComponent(JTable tbl, Object color,
+ boolean isSelected, boolean hasFocus, int row, int column)
+ {
+ FeatureColourI cellColour = (FeatureColourI) color;
+ // JLabel comp = new JLabel();
+ // comp.
+ setOpaque(true);
+ // comp.
+ // setBounds(getBounds());
+ Color newColor;
+ 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);
+ newColor = cellColour.getColour();
+ setBackground(newColor);
+ }
if (isSelected)
{
if (selectedBorder == null)
{
selectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5,
- table.getSelectionBackground());
+ tbl.getSelectionBackground());
}
setBorder(selectedBorder);
}
@@ -1199,22 +1594,185 @@ 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;
+ String tt = "";
+ String tx = "";
+ if (gcol.isAboveThreshold())
+ {
+ thr = true;
+ tx += ">";
+ tt += "Thresholded (Above " + gcol.getThreshold() + ") ";
+ }
+ if (gcol.isBelowThreshold())
+ {
+ thr = true;
+ tx += "<";
+ tt += "Thresholded (Below " + gcol.getThreshold() + ") ";
+ }
+ if (gcol.isColourByLabel())
+ {
+ tt = "Coloured by label text. " + tt;
+ if (thr)
+ {
+ tx += " ";
+ }
+ tx += "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);
+ if (tt.length() > 0)
+ {
+ if (comp.getToolTipText() == null)
+ {
+ comp.setToolTipText(tt);
+ }
+ else
+ {
+ comp.setToolTipText(tt + " " + comp.getToolTipText());
+ }
+ }
+ }
+}
+
+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
+class ColorEditor extends AbstractCellEditor
+ implements TableCellEditor, ActionListener
{
- Color currentColor;
+ FeatureSettings me;
+
+ FeatureColourI currentColor;
+
+ FeatureColourChooser chooser;
+
+ String type;
JButton button;
@@ -1224,8 +1782,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,
@@ -1244,6 +1805,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)
{
@@ -1251,31 +1813,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;
}
}