import jalview.util.Comparison;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
public float[][] findDistances(AlignmentView seqData)
{
int nofeats = 0;
- List<String> dft = Arrays.asList(fr.getDisplayedFeatureTypes());
+ List<String> dft = fr.getDisplayedFeatureTypes();
- if (dft != null)
- {
- nofeats = dft.size();
- }
+ nofeats = dft.size();
SequenceI[] sequenceString = seqData.getVisibleAlignment(
Comparison.GapChars.charAt(0)).getSequencesArray();
return true;
}
+ @Override
public String toString()
{
return "Score between sequences based on hamming distance between binary vectors marking features displayed at each column";
*/
package jalview.api;
+import java.util.List;
+
/**
* prototype abstract controller for a Jalview alignment view
*
* @param typ
* list of feature names or null to use currently displayed features
*/
- void sortAlignmentByFeatureScore(String[] typ);
+ void sortAlignmentByFeatureScore(List<String> typ);
/**
* sort the alignment or current selection by distribution of the given set of
* @param typ
* list of feature names or null to use currently displayed features
*/
- void sortAlignmentByFeatureDensity(String[] typ);
+ void sortAlignmentByFeatureDensity(List<String> typ);
/**
* add a features file of some kind to the current view
boolean isTransparencyAvailable();
/**
- * get current displayed types
+ * get current displayed types, in ordering of rendering (on top last)
*
- * @return
+ * @return a (possibly empty) list of feature types
*/
- String[] getDisplayedFeatureTypes();
+ List<String> getDisplayedFeatureTypes();
/**
* get current displayed groups
*
- * @return
+ * @return a (possibly empty) list of feature groups
*/
- String[] getDisplayedFeatureGroups();
+ List<String> getDisplayedFeatureGroups();
/**
* display all features of these types
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.util.Arrays;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
@Override
public void actionPerformed(ActionEvent e)
{
- me.ap.alignFrame.avc
- .sortAlignmentByFeatureScore(new String[] { type });
+ me.ap.alignFrame.avc.sortAlignmentByFeatureScore(Arrays
+ .asList(new String[] { type }));
}
});
@Override
public void actionPerformed(ActionEvent e)
{
- me.ap.alignFrame.avc
- .sortAlignmentByFeatureDensity(new String[] { type });
+ me.ap.alignFrame.avc.sortAlignmentByFeatureDensity(Arrays
+ .asList(new String[] { type }));
}
});
import jalview.util.MessageManager;
import java.awt.Color;
-import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
}
@Override
- public void sortAlignmentByFeatureDensity(String[] typ)
+ public void sortAlignmentByFeatureDensity(List<String> typ)
{
sortBy(typ, "Sort by Density", AlignmentSorter.FEATURE_DENSITY);
}
- protected void sortBy(String[] typ, String methodText, final String method)
+ protected void sortBy(List<String> typ, String methodText,
+ final String method)
{
FeatureRenderer fr = alignPanel.getFeatureRenderer();
- if (typ == null)
+ if (typ == null && fr != null)
{
- typ = fr == null ? null : fr.getDisplayedFeatureTypes();
+ typ = fr.getDisplayedFeatureTypes();
}
- String gps[] = null;
- gps = fr == null ? null : fr.getDisplayedFeatureGroups();
- if (typ != null)
+ List<String> gps = null;
+ if (fr != null)
{
- List<String> types = new ArrayList<String>();
- for (String displayed : typ)
- {
- if (displayed != null)
- {
- types.add(displayed);
- }
- }
- typ = new String[types.size()];
- types.toArray(typ);
- }
- if (gps != null)
- {
- List<String> grps = new ArrayList<String>();
-
- for (int i = 0; i < gps.length; i++)
- {
- if (gps[i] != null)
- {
- grps.add(gps[i]);
- }
- }
- gps = new String[grps.size()];
- grps.toArray(gps);
+ gps = fr.getDisplayedFeatureGroups();
}
AlignmentI al = viewport.getAlignment();
}
@Override
- public void sortAlignmentByFeatureScore(String[] typ)
+ public void sortAlignmentByFeatureScore(List<String> typ)
{
sortBy(typ, "Sort by Feature Score", AlignmentSorter.FEATURE_SCORE);
}
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.util.Arrays;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
table.addMouseListener(new MouseAdapter()
{
+ @Override
public void mousePressed(MouseEvent evt)
{
selectedRow = table.rowAtPoint(evt.getPoint());
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);
-
+ Object[][] data = ((FeatureTableModel) table.getModel())
+ .getData();
+ Object[] temp = data[selectedRow];
+ data[selectedRow] = data[newRow];
+ data[newRow] = temp;
+ updateFeatureRenderer(data);
+ table.repaint();
selectedRow = newRow;
}
}
final FeatureSettings fs = this;
fr.addPropertyChangeListener(change = new PropertyChangeListener()
{
+ @Override
public void propertyChange(PropertyChangeEvent evt)
{
if (!fs.resettingTable && !fs.handlingUpdate)
frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
{
+ @Override
public void internalFrameClosed(
javax.swing.event.InternalFrameEvent evt)
{
scr.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
- me.af.avc.sortAlignmentByFeatureScore(new String[] { type });
+ me.af.avc.sortAlignmentByFeatureScore(Arrays
+ .asList(new String[] { type }));
}
});
dens.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
- me.af.avc.sortAlignmentByFeatureDensity(new String[] { type });
+ me.af.avc.sortAlignmentByFeatureDensity(Arrays
+ .asList(new String[] { type }));
}
});
{
JColorChooser colorChooser;
+ @Override
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == mxcol)
check.setFont(new Font("Serif", Font.BOLD, 12));
check.addItemListener(new ItemListener()
{
+ @Override
public void itemStateChanged(ItemEvent evt)
{
fr.setGroupVisibility(check.getText(), check.isSelected());
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;
invert.setText(MessageManager.getString("label.invert_selection"));
invert.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
invertSelection();
optimizeOrder.setText(MessageManager.getString("label.optimise_order"));
optimizeOrder.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
orderByAvWidth();
.setText(MessageManager.getString("label.seq_sort_by_score"));
sortByScore.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
af.avc.sortAlignmentByFeatureScore(null);
.getString("label.sequence_sort_by_density"));
sortByDens.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
af.avc.sortAlignmentByFeatureDensity(null);
help.setText(MessageManager.getString("action.help"));
help.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
try
help.setText(MessageManager.getString("action.help"));
help.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
try
cancel.setText(MessageManager.getString("action.cancel"));
cancel.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
fr.setTransparency(originalTransparency);
ok.setText(MessageManager.getString("action.ok"));
ok.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
close();
loadColours.setText(MessageManager.getString("label.load_colours"));
loadColours.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
load();
saveColours.setText(MessageManager.getString("label.save_colours"));
saveColours.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
save();
});
transparency.addChangeListener(new ChangeListener()
{
+ @Override
public void stateChanged(ChangeEvent evt)
{
fr.setTransparency((100 - transparency.getValue()) / 100f);
fetchDAS.setText(MessageManager.getString("label.fetch_das_features"));
fetchDAS.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
fetchDAS_actionPerformed(e);
saveDAS.setText(MessageManager.getString("action.save_as_default"));
saveDAS.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
saveDAS_actionPerformed(e);
cancelDAS.setText(MessageManager.getString("action.cancel_fetch"));
cancelDAS.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
cancelDAS_actionPerformed(e);
Runnable fetcher = new Runnable()
{
+ @Override
public void run()
{
doDasFeatureFetch(dassources, true, false);
this.data = data;
}
+ @Override
public int getColumnCount()
{
return columnNames.length;
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;
setVerticalTextPosition(SwingConstants.CENTER);
}
+ @Override
public Component getTableCellRendererComponent(JTable table,
Object color, boolean isSelected, boolean hasFocus, int row,
int column)
}
}
+ @Override
public int getIconWidth()
{
return width;
}
+ @Override
public int getIconHeight()
{
return height;
}
+ @Override
public void paintIcon(Component c, Graphics g, int x, int y)
{
/**
* Handles events from the editor button and from the dialog's OK button.
*/
+ @Override
public void actionPerformed(ActionEvent e)
{
}
// Implement the one CellEditor method that AbstractCellEditor doesn't.
+ @Override
public Object getCellEditorValue()
{
if (currentColor == null)
}
// Implement the one method defined by TableCellEditor.
+ @Override
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column)
{
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
+import jalview.viewmodel.seqfeatures.FeatureRendererModel;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
-public class FeatureRenderer extends
- jalview.viewmodel.seqfeatures.FeatureRendererModel
+public class FeatureRenderer extends FeatureRendererModel
{
FontMetrics fm;
BufferedImage offscreenImage;
+ @Override
public Color findFeatureColour(Color initialCol, SequenceI seq, int res)
{
return new Color(findFeatureColour(initialCol.getRGB(), seq, res));
* discover and display.
*
*/
+ @Override
public void featuresAdded()
{
lastSeq = null;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
protected Object currentColour;
+ /*
+ * ordering of rendering, where last means on top
+ */
protected String[] renderOrder;
protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
protected AlignmentViewport av;
+ @Override
public AlignViewportI getViewport()
{
return av;
* @param featureType
* @return java.awt.Color or GraduatedColor
*/
+ @Override
public Object getFeatureStyle(String featureType)
{
Object fc = featureColours.get(featureType);
return av.getFeaturesDisplayed().isVisible(type);
}
+ @Override
public void setColour(String featureType, Object col)
{
// overwrite
*
* @param data
* { String(Type), Colour(Type), Boolean(Displayed) }
+ * @return true if any visible features have been reordered, else false
*/
- public void setFeaturePriority(Object[][] data)
+ public boolean setFeaturePriority(Object[][] data)
{
- setFeaturePriority(data, true);
+ return setFeaturePriority(data, true);
}
/**
+ * Sets the priority order for features
*
* @param data
* { String(Type), Colour(Type), Boolean(Displayed) }
* @param visibleNew
* when true current featureDisplay list will be cleared
+ * @return true if any visible features have been reordered or recoloured,
+ * else false (i.e. no need to repaint)
*/
- public void setFeaturePriority(Object[][] data, boolean visibleNew)
+ public boolean setFeaturePriority(Object[][] data, boolean visibleNew)
{
+ /*
+ * note visible feature ordering and colours before update
+ */
+ List<String> visibleFeatures = getDisplayedFeatureTypes();
+ Map<String, Object> visibleColours = new HashMap<String, Object>(
+ getFeatureColours());
+
FeaturesDisplayedI av_featuresdisplayed = null;
if (visibleNew)
{
}
if (data == null)
{
- return;
+ return false;
}
// The feature table will display high priority
- // features at the top, but theses are the ones
+ // features at the top, but these are the ones
// we need to render last, so invert the data
renderOrder = new String[data.length];
}
}
+ /*
+ * get the new visible ordering and return true if it has changed
+ * order or any colour has changed
+ */
+ List<String> reorderedVisibleFeatures = getDisplayedFeatureTypes();
+ if (!visibleFeatures.equals(reorderedVisibleFeatures))
+ {
+ /*
+ * the list of ordered visible features has changed
+ */
+ return true;
+ }
+
+ /*
+ * return true if any feature colour has changed
+ */
+ for (String feature : visibleFeatures)
+ {
+ if (visibleColours.get(feature) != getFeatureStyle(feature))
+ {
+ return true;
+ }
+ }
+ return false;
}
/**
return av.getFeaturesDisplayed();
}
+ /**
+ * Returns a (possibly empty) list of visible feature types, in render order
+ * (last is on top)
+ */
@Override
- public String[] getDisplayedFeatureTypes()
+ public List<String> getDisplayedFeatureTypes()
{
- String[] typ = null;
- typ = getRenderOrder().toArray(new String[0]);
+ List<String> typ = getRenderOrder();
+ List<String> displayed = new ArrayList<String>();
FeaturesDisplayedI feature_disp = av.getFeaturesDisplayed();
if (feature_disp != null)
{
synchronized (feature_disp)
{
- for (int i = 0; i < typ.length; i++)
+ for (String type : typ)
{
- if (!feature_disp.isVisible(typ[i]))
+ if (feature_disp.isVisible(type))
{
- typ[i] = null;
+ displayed.add(type);
}
}
}
}
- return typ;
+ return displayed;
}
@Override
- public String[] getDisplayedFeatureGroups()
+ public List<String> getDisplayedFeatureGroups()
{
- String[] gps = null;
- ArrayList<String> _gps = new ArrayList<String>();
- Iterator en = getFeatureGroups().iterator();
- int g = 0;
+ List<String> _gps = new ArrayList<String>();
boolean valid = false;
- while (en.hasNext())
+ for (String gp : getFeatureGroups())
{
- String gp = (String) en.next();
if (checkGroupVisibility(gp, false))
{
valid = true;
}
else
{
- gps = new String[_gps.size()];
- _gps.toArray(gps);
+ // gps = new String[_gps.size()];
+ // _gps.toArray(gps);
}
}
- return gps;
+ return _gps;
}
}
alf.getFeatureRenderer().setVisible("sf3");
alf.getFeatureRenderer().findAllFeatures(true);
AssertJUnit.assertEquals("Number of feature types", 3, alf
- .getFeatureRenderer().getDisplayedFeatureTypes().length);
+ .getFeatureRenderer().getDisplayedFeatureTypes().size());
AssertJUnit.assertTrue(alf.getCurrentView().areFeaturesDisplayed());
FeatureScoreModel fsm = new FeatureScoreModel();
AssertJUnit.assertTrue(fsm.configureFromAlignmentView(alf