+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * 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 Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.viewmodel.seqfeatures;
import jalview.api.AlignViewportI;
+import jalview.api.FeatureColourI;
import jalview.api.FeaturesDisplayedI;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.SequenceFeature;
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;
+ /*
+ * feature types in ordering of rendering, where last means on top
+ */
protected String[] renderOrder;
protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
protected AlignmentViewport av;
+ /*
+ * map holds per feature type, {{min, max}, {min, max}} feature score
+ * values for positional and non-positional features respectively
+ */
+ private Map<String, float[][]> minmax = new Hashtable<String, float[][]>();
+
+ @Override
public AlignViewportI getViewport()
{
return av;
}
if (!fdi.isRegistered(featureType))
{
- pushFeatureType(Arrays.asList(new String[]
- { featureType }));
+ pushFeatureType(Arrays.asList(new String[] { featureType }));
}
fdi.setVisible(featureType);
}
types.toArray(neworder);
if (renderOrder != null)
{
- System.arraycopy(neworder,0,neworder,renderOrder.length,ts);
+ System.arraycopy(neworder, 0, neworder, renderOrder.length, ts);
System.arraycopy(renderOrder, 0, neworder, 0, renderOrder.length);
}
renderOrder = neworder;
}
- protected Hashtable minmax = new Hashtable();
-
- public Hashtable getMinMax()
+ public Map<String, float[][]> getMinMax()
{
return minmax;
}
*/
protected final byte[] normaliseScore(SequenceFeature sequenceFeature)
{
- float[] mm = ((float[][]) minmax.get(sequenceFeature.type))[0];
- final byte[] r = new byte[]
- { 0, (byte) 255 };
+ float[] mm = minmax.get(sequenceFeature.type)[0];
+ final byte[] r = new byte[] { 0, (byte) 255 };
if (mm != null)
{
if (r[0] != 0 || mm[0] < 0.0)
{
ArrayList<SequenceFeature> tmp = new ArrayList<SequenceFeature>();
SequenceFeature[] features = sequence.getSequenceFeatures();
+
if (features != null)
{
for (int i = 0; i < features.length; i++)
}
if (minmax == null)
{
- minmax = new Hashtable();
+ minmax = new Hashtable<String, float[][]>();
}
AlignmentI alignment = av.getAlignment();
for (int i = 0; i < alignment.getHeight(); i++)
{
SequenceI asq = alignment.getSequenceAt(i);
- SequenceI dasq = asq.getDatasetSequence();
- SequenceFeature[] features = dasq != null ? dasq
- .getSequenceFeatures() : asq.getSequenceFeatures();
+ SequenceFeature[] features = asq.getSequenceFeatures();
if (features == null)
{
{
allfeatures.add(features[index].getType());
}
- if (features[index].score != Float.NaN)
+ if (!Float.isNaN(features[index].score))
{
int nonpos = features[index].getBegin() >= 1 ? 0 : 1;
- float[][] mm = (float[][]) minmax.get(features[index].getType());
+ float[][] mm = minmax.get(features[index].getType());
if (mm == null)
{
- mm = new float[][]
- { null, null };
+ mm = new float[][] { null, null };
minmax.put(features[index].getType(), mm);
}
if (mm[nonpos] == null)
{
- mm[nonpos] = new float[]
- { features[index].score, features[index].score };
+ mm[nonpos] = new float[] { features[index].score,
+ features[index].score };
}
else
{
if (initOrders)
{
- setOrder(oldRender[j], (1 - (1 + (float) j)
- / oldRender.length));
+ setOrder(oldRender[j], (1 - (1 + (float) j) / oldRender.length));
}
if (allfeatures.contains(oldRender[j]))
{
* @param featureType
* @return java.awt.Color or GraduatedColor
*/
+ @Override
public Object getFeatureStyle(String featureType)
{
Object fc = featureColours.get(featureType);
}
/**
- * return a nominal colour for this feature
- *
- * @param featureType
- * @return standard color, or maximum colour for graduated colourscheme
- */
- public Color getColour(String featureType)
- {
- Object fc = getFeatureStyle(featureType);
-
- if (fc instanceof Color)
- {
- return (Color) fc;
- }
- else
- {
- if (fc instanceof GraduatedColor)
- {
- return ((GraduatedColor) fc).getMaxColor();
- }
- }
- throw new Error("Implementation Error: Unrecognised render object "
- + fc.getClass() + " for features of type " + featureType);
- }
-
- /**
* calculate the render colour for a specific feature using current feature
* settings.
*
return av.getFeaturesDisplayed().isVisible(type);
}
+ @Override
public void setColour(String featureType, Object col)
{
// overwrite
// Object c = featureColours.get(featureType);
// if (c == null || c instanceof Color || (c instanceof GraduatedColor &&
// !((GraduatedColor)c).getMaxColor().equals(_col)))
+ if (col instanceof FeatureColourI)
{
- featureColours.put(featureType, col);
+ if (((FeatureColourI) col).isGraduatedColour())
+ {
+ col = new GraduatedColor((FeatureColourI) col);
+ }
+ else
+ {
+ col = ((FeatureColourI) col).getColour();
+ }
}
+ featureColours.put(featureType, col);
}
public void setTransparency(float value)
@Override
public Map<String, Object> getFeatureColours()
{
- return new ConcurrentHashMap<String, Object>(featureColours);
+ return featureColours;
}
/**
*
* @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;
}
/**
changeSupport.removePropertyChangeListener(listener);
}
- public Set getAllFeatureColours()
+ public Set<String> getAllFeatureColours()
{
return featureColours.keySet();
}
return renderOrder != null;
}
+ /**
+ * Returns feature types in ordering of rendering, where last means on top
+ */
public List<String> getRenderOrder()
{
if (renderOrder == null)
{
- return Arrays.asList(new String[]
- {});
+ return Arrays.asList(new String[] {});
}
return Arrays.asList(renderOrder);
}
while (en.hasNext())
{
String col = en.next();
- fcols.put(col, getColour(col));
+ fcols.put(col, featureColours.get(col));
}
return fcols;
}
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;
}
}