import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.renderer.seqfeatures.FeatureRenderer;
-import jalview.schemes.GraduatedColor;
-import jalview.viewmodel.AlignmentViewport;
+import jalview.schemes.Colour;
+import jalview.schemes.FeatureColour;
+import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
import java.awt.Color;
import java.beans.PropertyChangeListener;
*/
protected float transparency = 1.0f;
- protected Map<String, Object> featureColours = new ConcurrentHashMap<String, Object>();
+ protected Map<String, FeatureColourI> featureColours = new ConcurrentHashMap<String, FeatureColourI>();
protected Map<String, Boolean> featureGroups = new ConcurrentHashMap<String, Boolean>();
- protected Object currentColour;
-
- /*
- * feature types in ordering of rendering, where last means on top
- */
protected String[] renderOrder;
+ Map<String, Float> featureOrder = null;
+
protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
this);
- protected AlignmentViewport av;
+ protected AlignViewportI av;
/*
* map holds per feature type, {{min, max}, {min, max}} feature score
List<String> allfeatures = new ArrayList<String>(allFeatures);
String[] oldRender = renderOrder;
renderOrder = new String[allfeatures.size()];
- Object mmrange, fc = null;
boolean initOrders = (featureOrder == null);
int opos = 0;
if (oldRender != null && oldRender.length > 0)
allfeatures.remove(oldRender[j]);
if (minmax != null)
{
- mmrange = minmax.get(oldRender[j]);
+ float[][] mmrange = minmax.get(oldRender[j]);
if (mmrange != null)
{
- fc = featureColours.get(oldRender[j]);
- if (fc != null && fc instanceof GraduatedColor
- && ((GraduatedColor) fc).isAutoScale())
+ FeatureColourI fc = featureColours.get(oldRender[j]);
+ if (fc != null && !fc.isSimpleColour() && fc.isAutoScaled())
{
- ((GraduatedColor) fc).updateBounds(
- ((float[][]) mmrange)[0][0],
- ((float[][]) mmrange)[0][1]);
+ fc.updateBounds(mmrange[0][0], mmrange[0][1]);
}
}
}
if (minmax != null)
{
// update from new features minmax if necessary
- mmrange = minmax.get(newf[i]);
+ float[][] mmrange = minmax.get(newf[i]);
if (mmrange != null)
{
- fc = featureColours.get(newf[i]);
- if (fc != null && fc instanceof GraduatedColor
- && ((GraduatedColor) fc).isAutoScale())
+ FeatureColourI fc = featureColours.get(newf[i]);
+ if (fc != null && !fc.isSimpleColour() && fc.isAutoScaled())
{
- ((GraduatedColor) fc).updateBounds(((float[][]) mmrange)[0][0],
- ((float[][]) mmrange)[0][1]);
+ fc.updateBounds(mmrange[0][0], mmrange[0][1]);
}
}
}
setOrder(newf[i], i / (float) denom);
}
// set order from newly found feature from persisted ordering.
- sortOrder[i] = 2 - ((Float) featureOrder.get(newf[i])).floatValue();
+ sortOrder[i] = 2 - featureOrder.get(newf[i]).floatValue();
if (i < iSize)
{
// only sort if we need to
/**
* get a feature style object for the given type string. Creates a
- * java.awt.Color for a featureType with no existing colourscheme. TODO:
- * replace return type with object implementing standard abstract colour/style
- * interface
+ * java.awt.Color for a featureType with no existing colourscheme.
*
* @param featureType
- * @return java.awt.Color or GraduatedColor
+ * @return
*/
@Override
- public Object getFeatureStyle(String featureType)
+ public FeatureColourI getFeatureStyle(String featureType)
{
- Object fc = featureColours.get(featureType);
+ FeatureColourI fc = featureColours.get(featureType);
if (fc == null)
{
- jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();
- Color col = ucs.createColourFromName(featureType);
- featureColours.put(featureType, fc = col);
+ Color col = UserColourScheme.createColourFromName(featureType);
+ fc = new FeatureColour(new Colour(col));
+ featureColours.put(featureType, fc);
}
return fc;
}
*/
public Color getColour(SequenceFeature feature)
{
- Object fc = getFeatureStyle(feature.getType());
- if (fc instanceof Color)
- {
- return (Color) fc;
- }
- else
- {
- if (fc instanceof GraduatedColor)
- {
- return ((GraduatedColor) fc).findColor(feature);
- }
- }
- throw new Error("Implementation Error: Unrecognised render object "
- + fc.getClass() + " for features of type " + feature.getType());
+ FeatureColourI fc = getFeatureStyle(feature.getType());
+ return ColorUtils.getColor(fc.getColor(feature));
}
protected boolean showFeature(SequenceFeature sequenceFeature)
{
- Object fc = getFeatureStyle(sequenceFeature.type);
- if (fc instanceof GraduatedColor)
- {
- return ((GraduatedColor) fc).isColored(sequenceFeature);
- }
- else
- {
- return true;
- }
+ FeatureColourI fc = getFeatureStyle(sequenceFeature.type);
+ return fc.isColored(sequenceFeature);
}
protected boolean showFeatureOfType(String type)
}
@Override
- public void setColour(String featureType, Object col)
+ public void setColour(String featureType, FeatureColourI col)
{
- // overwrite
- // Color _col = (col instanceof Color) ? ((Color) col) : (col instanceof
- // GraduatedColor) ? ((GraduatedColor) col).getMaxColor() : null;
- // Object c = featureColours.get(featureType);
- // if (c == null || c instanceof Color || (c instanceof GraduatedColor &&
- // !((GraduatedColor)c).getMaxColor().equals(_col)))
- if (col instanceof FeatureColourI)
- {
- if (((FeatureColourI) col).isGraduatedColour())
- {
- col = new GraduatedColor((FeatureColourI) col);
- }
- else
- {
- col = ((FeatureColourI) col).getColour();
- }
- }
- featureColours.put(featureType, col);
+ featureColours.put(featureType, col);
}
public void setTransparency(float value)
return transparency;
}
- Map featureOrder = null;
-
/**
* analogous to colour - store a normalized ordering for all feature types in
* this rendering context.
{
if (featureOrder == null)
{
- featureOrder = new Hashtable();
+ featureOrder = new Hashtable<String, Float>();
}
featureOrder.put(type, new Float(position));
return position;
{
if (featureOrder.containsKey(type))
{
- return ((Float) featureOrder.get(type)).floatValue();
+ return featureOrder.get(type).floatValue();
}
}
return -1;
}
@Override
- public Map<String, Object> getFeatureColours()
+ public Map<String, FeatureColourI> getFeatureColours()
{
return featureColours;
}
* note visible feature ordering and colours before update
*/
List<String> visibleFeatures = getDisplayedFeatureTypes();
- Map<String, Object> visibleColours = new HashMap<String, Object>(
+ Map<String, FeatureColourI> visibleColours = new HashMap<String, FeatureColourI>(
getFeatureColours());
FeaturesDisplayedI av_featuresdisplayed = null;
for (int i = 0; i < data.length; i++)
{
String type = data[i][0].toString();
- setColour(type, data[i][1]); // todo : typesafety - feature color
- // interface object
+ setColour(type, (FeatureColourI) data[i][1]);
if (((Boolean) data[i][2]).booleanValue())
{
av_featuresdisplayed.setVisible(type);
return renderOrder != null;
}
- /**
- * Returns feature types in ordering of rendering, where last means on top
- */
public List<String> getRenderOrder()
{
if (renderOrder == null)
* @return list of groups
*/
@Override
- public List getGroups(boolean visible)
+ public List<String> getGroups(boolean visible)
{
if (featureGroups != null)
{
- ArrayList gp = new ArrayList();
+ List<String> gp = new ArrayList<String>();
- for (Object grp : featureGroups.keySet())
+ for (String grp : featureGroups.keySet())
{
Boolean state = featureGroups.get(grp);
if (state.booleanValue() == visible)
}
@Override
- public Hashtable getDisplayedFeatureCols()
+ public Map<String, FeatureColourI> getDisplayedFeatureCols()
{
- Hashtable fcols = new Hashtable();
+ Map<String, FeatureColourI> fcols = new Hashtable<String, FeatureColourI>();
if (getViewport().getFeaturesDisplayed() == null)
{
return fcols;
}
- Iterator<String> en = getViewport().getFeaturesDisplayed()
+ Iterator<String> features = getViewport().getFeaturesDisplayed()
.getVisibleFeatures();
- while (en.hasNext())
+ while (features.hasNext())
{
- String col = en.next();
- fcols.put(col, featureColours.get(col));
+ String feature = features.next();
+ fcols.put(feature, getFeatureStyle(feature));
}
return fcols;
}
return av.getFeaturesDisplayed();
}
- /**
- * Returns a (possibly empty) list of visible feature types, in render order
- * (last is on top)
- */
@Override
public List<String> getDisplayedFeatureTypes()
{