X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fviewmodel%2Fseqfeatures%2FFeatureRendererModel.java;fp=src%2Fjalview%2Fviewmodel%2Fseqfeatures%2FFeatureRendererModel.java;h=d813fe29aa72c75c65118536e410b2ad7da5185b;hb=c956ba7509e394cf70dbf049abe5fbc967222144;hp=ee0721db5bc09266f1d7995d0a9a6e736357eda3;hpb=408b2821c8daf99245bf6358d06760701d90ddd8;p=jalview.git diff --git a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java index ee0721d..d813fe2 100644 --- a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java +++ b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java @@ -27,7 +27,8 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.renderer.seqfeatures.FeatureRenderer; -import jalview.schemes.GraduatedColor; +import jalview.schemes.FeatureColour; +import jalview.schemes.UserColourScheme; import java.awt.Color; import java.beans.PropertyChangeListener; @@ -51,28 +52,19 @@ public abstract class FeatureRendererModel implements */ protected float transparency = 1.0f; - protected Map featureColours = new ConcurrentHashMap(); + protected Map featureColours = new ConcurrentHashMap(); protected Map featureGroups = new ConcurrentHashMap(); - protected Object currentColour; - - /* - * feature types in ordering of rendering, where last means on top - */ protected String[] renderOrder; + Map featureOrder = null; + protected PropertyChangeSupport changeSupport = new PropertyChangeSupport( this); protected AlignViewportI av; - /* - * map holds per feature type, {{min, max}, {min, max}} feature score - * values for positional and non-positional features respectively - */ - private Map minmax = new Hashtable(); - @Override public AlignViewportI getViewport() { @@ -199,6 +191,8 @@ public abstract class FeatureRendererModel implements renderOrder = neworder; } + protected Map minmax = new Hashtable(); + public Map getMinMax() { return minmax; @@ -448,7 +442,6 @@ public abstract class FeatureRendererModel implements List allfeatures = new ArrayList(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) @@ -468,16 +461,13 @@ public abstract class FeatureRendererModel implements 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]); } } } @@ -501,15 +491,13 @@ public abstract class FeatureRendererModel implements 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]); } } } @@ -521,7 +509,7 @@ public abstract class FeatureRendererModel implements 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 @@ -539,22 +527,20 @@ public abstract class FeatureRendererModel implements /** * 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(col); + featureColours.put(featureType, fc); } return fc; } @@ -568,33 +554,14 @@ public abstract class FeatureRendererModel implements */ 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 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) @@ -603,26 +570,9 @@ public abstract class FeatureRendererModel implements } @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) @@ -635,8 +585,6 @@ public abstract class FeatureRendererModel implements return transparency; } - Map featureOrder = null; - /** * analogous to colour - store a normalized ordering for all feature types in * this rendering context. @@ -651,7 +599,7 @@ public abstract class FeatureRendererModel implements { if (featureOrder == null) { - featureOrder = new Hashtable(); + featureOrder = new Hashtable(); } featureOrder.put(type, new Float(position)); return position; @@ -669,14 +617,14 @@ public abstract class FeatureRendererModel implements { if (featureOrder.containsKey(type)) { - return ((Float) featureOrder.get(type)).floatValue(); + return featureOrder.get(type).floatValue(); } } return -1; } @Override - public Map getFeatureColours() + public Map getFeatureColours() { return featureColours; } @@ -709,7 +657,7 @@ public abstract class FeatureRendererModel implements * note visible feature ordering and colours before update */ List visibleFeatures = getDisplayedFeatureTypes(); - Map visibleColours = new HashMap( + Map visibleColours = new HashMap( getFeatureColours()); FeaturesDisplayedI av_featuresdisplayed = null; @@ -742,8 +690,7 @@ public abstract class FeatureRendererModel implements 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); @@ -868,9 +815,9 @@ public abstract class FeatureRendererModel implements { if (featureGroups != null) { - ArrayList gp = new ArrayList(); + List gp = new ArrayList(); - for (Object grp : featureGroups.keySet()) + for (String grp : featureGroups.keySet()) { Boolean state = featureGroups.get(grp); if (state.booleanValue() == visible) @@ -912,19 +859,19 @@ public abstract class FeatureRendererModel implements } @Override - public Hashtable getDisplayedFeatureCols() + public Map getDisplayedFeatureCols() { - Hashtable fcols = new Hashtable(); + Map fcols = new Hashtable(); if (getViewport().getFeaturesDisplayed() == null) { return fcols; } - Iterator en = getViewport().getFeaturesDisplayed() + Iterator 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; }