/*\r
* Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
*\r
* This program is free software; you can redistribute it and/or\r
* modify it under the terms of the GNU General Public License\r
FontMetrics fm;\r
int charOffset;\r
\r
+ Hashtable featureColours = new Hashtable();\r
+\r
+\r
// A higher level for grouping features of a\r
// particular type\r
Hashtable featureGroups = null;\r
\r
-\r
// This is actually an Integer held in the hashtable,\r
// Retrieved using the key feature type\r
Object currentColour;\r
\r
String [] renderOrder;\r
\r
-\r
/**\r
* Creates a new FeatureRenderer object.\r
*\r
public FeatureRenderer(AlignViewport av)\r
{\r
this.av = av;\r
- initColours();\r
}\r
\r
public void transferSettings(FeatureRenderer fr)\r
boolean offscreenRender = false;\r
public Color findFeatureColour(Color initialCol, SequenceI seq, int res)\r
{\r
- int seqindex = av.alignment.findIndex(seq);\r
-\r
return new Color( findFeatureColour (initialCol.getRGB(),\r
- seqindex, res ));\r
+ seq, res ));\r
}\r
\r
/**\r
- * This is used by the Molecule Viewer to get the accurate colour\r
- * of the rendered sequence\r
+ * This is used by the Molecule Viewer and Overview to\r
+ * get the accurate colourof the rendered sequence\r
*/\r
- public int findFeatureColour(int initialCol, int seqIndex, int column)\r
+ public int findFeatureColour(int initialCol, SequenceI seq, int column)\r
{\r
if(!av.showSequenceFeatures)\r
return initialCol;\r
\r
- if(seqIndex!=lastSequenceIndex)\r
+ if(seq!=lastSeq)\r
{\r
- lastSequence = av.alignment.getSequenceAt(seqIndex);\r
- lastSequenceIndex = seqIndex;\r
- sequenceFeatures = lastSequence.getDatasetSequence().getSequenceFeatures();\r
+ lastSeq = seq;\r
+ sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures();\r
if(sequenceFeatures==null)\r
return initialCol;\r
\r
sfSize = sequenceFeatures.length;\r
}\r
\r
- if(jalview.util.Comparison.isGap(lastSequence.getCharAt(column)))\r
+ if(jalview.util.Comparison.isGap(lastSeq.getCharAt(column)))\r
return Color.white.getRGB();\r
\r
\r
{\r
offscreenImage.setRGB(0,0,initialCol);\r
drawSequence(offscreenImage.getGraphics(),\r
- lastSequence,\r
+ lastSeq,\r
column,column,0);\r
\r
return offscreenImage.getRGB(0,0);\r
else\r
{\r
drawSequence(null,\r
- lastSequence,\r
- lastSequence.findPosition(column),\r
+ lastSeq,\r
+ lastSeq.findPosition(column),\r
-1, -1);\r
\r
if (currentColour == null)\r
*/\r
// String type;\r
// SequenceFeature sf;\r
- int lastSequenceIndex=-1;\r
- SequenceI lastSequence;\r
+ SequenceI lastSeq;\r
SequenceFeature [] sequenceFeatures;\r
int sfSize, sfindex, spos, epos;\r
\r
|| seq.getDatasetSequence().getSequenceFeatures().length==0)\r
return;\r
\r
-\r
if(g!=null)\r
fm = g.getFontMetrics();\r
\r
\r
- if (av.featuresDisplayed == null || renderOrder==null)\r
+ if (av.featuresDisplayed == null\r
+ || renderOrder==null\r
+ || newFeatureAdded)\r
{\r
findAllFeatures();\r
if(av.featuresDisplayed.size()<1)\r
sfSize = sequenceFeatures.length;\r
}\r
\r
- if(lastSequence==null || seq!=lastSequence)\r
+ if(lastSeq==null || seq!=lastSeq)\r
{\r
- lastSequence = seq;\r
+ lastSeq = seq;\r
sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures();\r
sfSize = sequenceFeatures.length;\r
}\r
\r
if(!offscreenRender)\r
{\r
- spos = lastSequence.findPosition(start);\r
- epos = lastSequence.findPosition(end);\r
+ spos = lastSeq.findPosition(start);\r
+ epos = lastSeq.findPosition(end);\r
}\r
\r
\r
for(int renderIndex=0; renderIndex<renderOrder.length; renderIndex++)\r
{\r
type = renderOrder[renderIndex];\r
+\r
if(!av.featuresDisplayed.containsKey(type))\r
continue;\r
\r
}\r
}\r
\r
- synchronized void findAllFeatures()\r
+\r
+ boolean newFeatureAdded = false;\r
+\r
+ public void featuresAdded()\r
{\r
- av.featuresDisplayed = new Hashtable();\r
+ findAllFeatures();\r
+ }\r
+\r
+ boolean findingFeatures = false;\r
+ synchronized void findAllFeatures()\r
+ {\r
+ newFeatureAdded = false;\r
+\r
+ if(findingFeatures)\r
+ {\r
+ newFeatureAdded = true;\r
+ return;\r
+ }\r
+\r
+ findingFeatures = true;\r
+ jalview.schemes.UserColourScheme ucs = new\r
+ jalview.schemes.UserColourScheme();\r
+\r
+ if(av.featuresDisplayed==null)\r
+ av.featuresDisplayed = new Hashtable();\r
+\r
+ av.featuresDisplayed.clear();\r
+\r
Vector allfeatures = new Vector();\r
for (int i = 0; i < av.alignment.getHeight(); i++)\r
{\r
// and we don't want to render the feature in the normal way\r
\r
if (getColour(features[index].getType()) == null)\r
- createRandomColour(features[index].getType());\r
+ {\r
+ featureColours.put(features[index].getType(),\r
+ ucs.createColourFromName(features[index].\r
+ getType()));\r
+ }\r
\r
av.featuresDisplayed.put(features[index].getType(),\r
new Integer(getColour(features[index].\r
renderOrder[i] = en.nextElement().toString();\r
i--;\r
}\r
+\r
+ findingFeatures = false;\r
}\r
\r
public Color getColour(String featureType)\r
\r
}\r
\r
- Hashtable featureColours = new Hashtable();\r
- void initColours()\r
- {\r
- featureColours.put("active site", new Color(255, 75, 0));\r
- featureColours.put("binding site", new Color(245, 85, 0));\r
- featureColours.put("calcium-binding region", new Color(235, 95, 0));\r
- featureColours.put("chain", new Color(225, 105, 0));\r
- featureColours.put("coiled-coil region", new Color(215, 115, 0));\r
- featureColours.put("compositionally biased region", new Color(205, 125, 0));\r
- featureColours.put("cross-link", new Color(195, 135, 0));\r
- featureColours.put("disulfide bond", new Color(230,230,0));\r
- featureColours.put("DNA-binding region", new Color(175, 155, 0));\r
- featureColours.put("domain", new Color(165, 165, 0));\r
- featureColours.put("glycosylation site", new Color(155, 175, 0));\r
- featureColours.put("helix", new Color(145, 185, 0));\r
- featureColours.put("initiator methionine", new Color(135, 195, 5));\r
- featureColours.put("lipid moiety-binding region", new Color(125, 205, 15));\r
- featureColours.put("metal ion-binding site", new Color(115, 215, 25));\r
- featureColours.put("modified residue", new Color(105, 225, 35));\r
- featureColours.put("mutagenesis site", new Color(95, 235, 45));\r
- featureColours.put("non-consecutive residues", new Color(85, 245, 55));\r
- featureColours.put("non-terminal residue", new Color(75, 255, 65));\r
- featureColours.put("nucleotide phosphate-binding region",new Color(65, 245, 75));\r
- featureColours.put("peptide", new Color(55, 235, 85));\r
- featureColours.put("propeptide", new Color(45, 225, 95));\r
- featureColours.put("region of interest", new Color(35, 215, 105));\r
- featureColours.put("repeat", new Color(25, 205, 115));\r
- featureColours.put("selenocysteine", new Color(15, 195, 125));\r
- featureColours.put("sequence conflict", new Color(5, 185, 135));\r
- featureColours.put("sequence variant", new Color(0, 175, 145));\r
- featureColours.put("short sequence motif", new Color(0, 165, 155));\r
- featureColours.put("signal peptide", new Color(0, 155, 165));\r
- featureColours.put("site", new Color(0, 145, 175));\r
- featureColours.put("splice variant", new Color(0, 135, 185));\r
- featureColours.put("strand", new Color(0, 125, 195));\r
- featureColours.put("topological domain", new Color(0, 115, 205));\r
- featureColours.put("transit peptide", new Color(0, 105, 215));\r
- featureColours.put("transmembrane region", new Color(0, 95, 225));\r
- featureColours.put("turn", new Color(0, 85, 235));\r
- featureColours.put("unsure residue", new Color(0, 75, 245));\r
- featureColours.put("zinc finger region", new Color(0, 65, 255));\r
- }\r
\r
- public Color createRandomColour(String name)\r
- {\r
- Random rg = new Random(System.currentTimeMillis());\r
- Color color = new Color( (int) (Math.random() * 255),\r
- (int) (Math.random() * 255),\r
- (int) (Math.random() * 255));\r
- featureColours.put(name, color); // java 1.2 here ?\r
-\r
- return color;\r
- }\r
\r
\r
}\r