X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FFeatureRenderer.java;h=83a8340256bdcac6172ef3ba31b6136e30589305;hb=52fd681e0f239e20df19fd7560d4b999104ba222;hp=fae19e84fb0e0e0ef8b48da6d8bf000846f6d57c;hpb=449001e7a8c9aad77117daa36567f3e8313646ea;p=jalview.git diff --git a/src/jalview/appletgui/FeatureRenderer.java b/src/jalview/appletgui/FeatureRenderer.java index fae19e8..83a8340 100755 --- a/src/jalview/appletgui/FeatureRenderer.java +++ b/src/jalview/appletgui/FeatureRenderer.java @@ -33,21 +33,18 @@ import java.util.*; public class FeatureRenderer { AlignViewport av; - SequenceGroup currentSequenceGroup = null; - SequenceGroup[] allGroups = null; - Graphics graphics; - // The following vector holds the features which are - // to be added, in the correct order or rendering - Vector featuresDisplayed; // A higher level for grouping features of a - // paritcular type + // particular type Hashtable featureGroups = null; - Color currentColour = null; + // This is actually an Integer held in the hashtable, + // Retrieved using the key feature type + Object currentColour; + + String [] renderOrder; - boolean drawText = true; FontMetrics fm; int charOffset; @@ -62,7 +59,79 @@ public class FeatureRenderer initColours(); } - //boolean highlightTransparent = true; + + public void transferSettings(FeatureRenderer fr) + { + renderOrder = fr.renderOrder; + featureGroups = fr.featureGroups; + featureColours = fr.featureColours; + } + + + public Color findFeatureColour(Color initialCol, SequenceI seq, int i) + { + overview = true; + if(!av.showSequenceFeatures) + return initialCol; + + lastSequence = seq; + sequenceFeatures = lastSequence.getSequenceFeatures(); + if(sequenceFeatures==null) + return initialCol; + + sfSize = sequenceFeatures.length; + + if(jalview.util.Comparison.isGap(lastSequence.getCharAt(i))) + return Color.white; + + currentColour = null; + + drawSequence(null, lastSequence, lastSequence.findPosition(i), -1,-1, -1, -1); + + if(currentColour==null) + return initialCol; + + return new Color( ((Integer)currentColour).intValue() ); + } + + /** + * This is used by the Molecule Viewer to get the accurate colour + * of the rendered sequence + */ + boolean overview = false; + + int white = Color.white.getRGB(); + public int findFeatureColour(int initialCol, int seqIndex, int column) + { + if(!av.showSequenceFeatures) + return initialCol; + + if(seqIndex!=lastSequenceIndex) + { + lastSequence = av.alignment.getSequenceAt(seqIndex); + lastSequenceIndex = seqIndex; + sequenceFeatures = lastSequence.getSequenceFeatures(); + if(sequenceFeatures==null) + return initialCol; + + sfSize = sequenceFeatures.length; + } + + + if(jalview.util.Comparison.isGap(lastSequence.getCharAt(column))) + return Color.white.getRGB(); + + currentColour = null; + + drawSequence(null, lastSequence, lastSequence.findPosition(column), -1,-1, -1, -1); + + if(currentColour==null) + return initialCol; + + return ((Integer)currentColour).intValue(); + } + + /** * DOCUMENT ME! * @@ -76,88 +145,118 @@ public class FeatureRenderer * @param width DOCUMENT ME! * @param height DOCUMENT ME! */ + // String type; + // SequenceFeature sf; + int lastSequenceIndex=-1; + SequenceI lastSequence; + SequenceFeature [] sequenceFeatures; + int sfSize, sfindex, spos, epos; + public void drawSequence(Graphics g, SequenceI seq, - int start, int end, int x1, int y1, int width, int height) + int start, int end, int y1, int width, int height) { - fm = g.getFontMetrics(); - - if(seq.getSequenceFeatures()==null) - return; + if ( seq.getSequenceFeatures() == null + || seq.getSequenceFeatures().length==0) + return; - Enumeration e = null, e2; - String type; - if(featuresDisplayed!=null) - e = featuresDisplayed.elements(); - else - e = seq.getSequenceFeatures().elements(); + if (av.featuresDisplayed == null || renderOrder==null) + { + findAllFeatures(); + if(av.featuresDisplayed.size()<1) + return; - while (e.hasMoreElements()) + sequenceFeatures = seq.getSequenceFeatures(); + sfSize = sequenceFeatures.length; + } + if(lastSequence==null || seq!=lastSequence) + { + lastSequence = seq; + sequenceFeatures = seq.getSequenceFeatures(); + sfSize = sequenceFeatures.length; + } + if(!overview) + { + spos = lastSequence.findPosition(start); + epos = lastSequence.findPosition(end); + if(g!=null) + fm = g.getFontMetrics(); + } + String type; + for(int renderIndex=0; renderIndex epos + || sequenceFeatures[sfindex].getEnd() < spos)) + continue; - if (sf.getBegin() > seq.getEnd()) + if (overview) + { + if (sequenceFeatures[sfindex].begin <= start && + sequenceFeatures[sfindex].end >= start) { - continue; + currentColour = av.featuresDisplayed.get(sequenceFeatures[sfindex]. + type); } - if (type.equals("disulfide bond")) - { + } + else if (sequenceFeatures[sfindex].type.equals("disulfide bond")) + { - renderFeature(g, seq, - seq.findIndex(sf.getBegin()) - 1, - seq.findIndex(sf.getBegin()) - 1, - type, start, end, x1, y1, width, height); - renderFeature(g, seq, - seq.findIndex(sf.getEnd()) - 1, - seq.findIndex(sf.getEnd()) - 1, - type, start, end, x1, y1, width, height); + renderFeature(g, seq, + seq.findIndex(sequenceFeatures[sfindex].begin) - 1, + seq.findIndex(sequenceFeatures[sfindex].begin) - 1, + new Color( ( (Integer) av.featuresDisplayed.get( + sequenceFeatures[sfindex].type)).intValue()), + start, end, y1, width, height); + renderFeature(g, seq, + seq.findIndex(sequenceFeatures[sfindex].end) - 1, + seq.findIndex(sequenceFeatures[sfindex].end) - 1, + new Color( ( (Integer) av.featuresDisplayed.get( + sequenceFeatures[sfindex].type)).intValue()), + start, end, y1, width, height); - } - else - renderFeature(g, seq, - seq.findIndex(sf.getBegin()) - 1, - seq.findIndex(sf.getEnd()) - 1, - type, start, end, x1, y1, width, height); + } + else + renderFeature(g, seq, + seq.findIndex(sequenceFeatures[sfindex].begin) - 1, + seq.findIndex(sequenceFeatures[sfindex].end) - 1, + getColour(sequenceFeatures[sfindex].type), + start, end, y1, width, height); + } } } + + char s; + int i; void renderFeature(Graphics g, SequenceI seq, - int fstart, int fend, String type, int start, int end, - int x1, int y1, int width, int height) + int fstart, int fend, Color featureColour, int start, int end, int y1, int width, int height) { - if ( ( (fstart <= end) && (fend >= start))) + + if (((fstart <= end) && (fend >= start))) { if (fstart < start) { // fix for if the feature we have starts before the sequence start, @@ -168,97 +267,107 @@ public class FeatureRenderer { fend = end; } - for (int i = fstart; i <= fend; i++) - { - char s = seq.getSequence().charAt(i); - if (jalview.util.Comparison.isGap(s)) + for (i = fstart; i <= fend; i++) { - continue; - } + s = seq.getSequence().charAt(i); - currentColour = getColour(type); + if (jalview.util.Comparison.isGap(s)) + { + continue; + } - g.setColor(currentColour); + g.setColor(featureColour); - g.fillRect( (i - start) * width, y1, width, height); + g.fillRect( (i - start) * width, y1, width, height); - if (drawText) - { g.setColor(Color.white); charOffset = (width - fm.charWidth(s)) / 2; g.drawString(String.valueOf(s), - charOffset + x1 + (width * (i - start)), - (y1 + height) - height / 5); + charOffset + (width * (i - start)), + (y1 + height) - height / 5); //pady = height / 5; + } - } } } - Image offscreen; - Frame nullframe; - public Color findFeatureColour(Color initialCol, SequenceI seq, int i) + void findAllFeatures() { - currentColour = initialCol; - if(offscreen == null) + av.featuresDisplayed = new Hashtable(); + Vector allfeatures = new Vector(); + for (int i = 0; i < av.alignment.getHeight(); i++) { - nullframe = new Frame(); - nullframe.addNotify(); - offscreen = nullframe.createImage(1, 1); - } + SequenceFeature [] features = av.alignment.getSequenceAt(i).getSequenceFeatures(); - drawSequence(offscreen.getGraphics(), seq, i, i, 0, 0, 1, 1); - return currentColour; - } + if (features == null) + continue; + int index = 0; + while (index < features.length) + { + if (!av.featuresDisplayed.containsKey(features[index].getType())) + { + av.featuresDisplayed.put(features[index].getType(), + new Integer( getColour(features[index].getType()).getRGB()) ); + allfeatures.addElement(features[index].getType()); + } + index++; + } + } + renderOrder = new String[allfeatures.size()]; + Enumeration en = allfeatures.elements(); + int i = allfeatures.size()-1; + while(en.hasMoreElements()) + { + renderOrder[i] = en.nextElement().toString(); + i--; + } + } public Color getColour(String featureType) { return (Color)featureColours.get(featureType); } - public void setColour(String featureType, Color col) - { - featureColours.put(featureType, col); - } - public void addNewFeature(String name, Color col) { + setColour(name, col); - if (featuresDisplayed == null) - featuresDisplayed = new Vector(); - featuresDisplayed.insertElementAt(name, 0); - } + if(av.featuresDisplayed==null) + av.featuresDisplayed = new Hashtable(); - /* public void setTransparency(float value) - { - transparency = value; + av.featuresDisplayed.put(name, "NOGROUP"); } - public float getTransparency() + public void setColour(String featureType, Color col) { - return transparency; - }*/ + featureColours.put(featureType, col); + } public void setFeaturePriority(Object [][] data) { - // The feature table will display high priority - // features at the top, but theses are the ones - // we need to render last, so invert the data - if(featuresDisplayed!=null) - featuresDisplayed.removeAllElements(); - else - featuresDisplayed = new Vector(); - - for(int i=data.length-1; i>-1; i--) - { - String type = data[i][0].toString(); - setColour(type, (Color)data[i][1]); - if( ((Boolean)data[i][2]).booleanValue() ) - featuresDisplayed.addElement(type); - } + // The feature table will display high priority + // features at the top, but theses are the ones + // we need to render last, so invert the data + if(av.featuresDisplayed!=null) + av.featuresDisplayed.clear(); + + renderOrder = new String[data.length]; + + if (data.length > 0) + for (int i = 0; i < data.length; i++) + { + String type = data[i][0].toString(); + setColour(type, (Color) data[i][1]); + if ( ( (Boolean) data[i][2]).booleanValue()) + { + av.featuresDisplayed.put(type, new Integer(getColour(type).getRGB())); + } + + renderOrder[data.length - i - 1] = type; + } } Hashtable featureColours = new Hashtable();