- AlignmentPanel ap;
-
- AlignViewport av;
-
- Color resBoxColour;
-
- /**
- * global transparency for feature
- */
- float transparency = 1.0f;
-
- FontMetrics fm;
-
- int charOffset;
-
- Map featureColours = new ConcurrentHashMap();
-
- // A higher level for grouping features of a
- // particular type
- Map featureGroups = new ConcurrentHashMap();
-
- // This is actually an Integer held in the hashtable,
- // Retrieved using the key feature type
- Object currentColour;
-
- String[] renderOrder;
-
- PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
-
- Vector allfeatures;
-
- /**
- * Creates a new FeatureRenderer object.
- *
- * @param av
- * DOCUMENT ME!
- */
- public FeatureRenderer(AlignmentPanel ap)
- {
- this.ap = ap;
- this.av = ap.av;
- if (ap != null && ap.seqPanel != null && ap.seqPanel.seqCanvas != null
- && ap.seqPanel.seqCanvas.fr != null)
- {
- transferSettings(ap.seqPanel.seqCanvas.fr);
- }
- }
-
- public class FeatureRendererSettings implements Cloneable
- {
- String[] renderOrder;
-
- Map featureGroups;
-
- Map featureColours;
-
- float transparency;
-
- Map featureOrder;
-
- public FeatureRendererSettings(String[] renderOrder,
- Hashtable featureGroups, Hashtable featureColours,
- float transparency, Hashtable featureOrder)
- {
- super();
- this.renderOrder = renderOrder;
- this.featureGroups = featureGroups;
- this.featureColours = featureColours;
- this.transparency = transparency;
- this.featureOrder = featureOrder;
- }
-
- /**
- * create an independent instance of the feature renderer settings
- *
- * @param fr
- */
- public FeatureRendererSettings(FeatureRenderer fr)
- {
- renderOrder = null;
- featureGroups = new ConcurrentHashMap();
- featureColours = new ConcurrentHashMap();
- featureOrder = new ConcurrentHashMap();
- if (fr.renderOrder != null)
- {
- this.renderOrder = new String[fr.renderOrder.length];
- System.arraycopy(fr.renderOrder, 0, renderOrder, 0,
- fr.renderOrder.length);
- }
- if (fr.featureGroups != null)
- {
- this.featureGroups = new ConcurrentHashMap(fr.featureGroups);
- }
- if (fr.featureColours != null)
- {
- this.featureColours = new ConcurrentHashMap(fr.featureColours);
- }
- Iterator en = fr.featureColours.keySet().iterator();
- while (en.hasNext())
- {
- Object next = en.next();
- Object val = featureColours.get(next);
- if (val instanceof GraduatedColor)
- {
- featureColours
- .put(next, new GraduatedColor((GraduatedColor) val));
- }
- }
- this.transparency = fr.transparency;
- if (fr.featureOrder != null)
- {
- this.featureOrder = new ConcurrentHashMap(fr.featureOrder);
- }
- }
- }
-
- public FeatureRendererSettings getSettings()
- {
- return new FeatureRendererSettings(this);
- }
-
- public void transferSettings(FeatureRendererSettings fr)
- {
- this.renderOrder = fr.renderOrder;
- this.featureGroups = fr.featureGroups;
- this.featureColours = fr.featureColours;
- this.transparency = fr.transparency;
- this.featureOrder = fr.featureOrder;
- }
- /**
- * update from another feature renderer
- * @param fr settings to copy
- */
- public void transferSettings(FeatureRenderer fr)
- {
- FeatureRendererSettings frs = new FeatureRendererSettings(fr);
- this.renderOrder = frs.renderOrder;
- this.featureGroups = frs.featureGroups;
- this.featureColours = frs.featureColours;
- this.transparency = frs.transparency;
- this.featureOrder = frs.featureOrder;
- if (av != null && av != fr.av)
- {
- // copy over the displayed feature settings
- if (fr.av != null)
- {
- if (fr.av.featuresDisplayed != null)
- {
- // update display settings
- if (av.featuresDisplayed == null)
- {
- av.featuresDisplayed = new Hashtable(fr.av.featuresDisplayed);
- }
- else
- {
- av.featuresDisplayed.clear();
- Enumeration en = fr.av.featuresDisplayed.keys();
- while (en.hasMoreElements())
- {
- av.featuresDisplayed.put(en.nextElement(), Boolean.TRUE);
- }
-
- }
- }
- }
- }
- }
-
- BufferedImage offscreenImage;
-
- boolean offscreenRender = false;
-
- public Color findFeatureColour(Color initialCol, SequenceI seq, int res)
- {
- return new Color(findFeatureColour(initialCol.getRGB(), seq, res));
- }
-
- /**
- * This is used by the Molecule Viewer and Overview to get the accurate
- * colourof the rendered sequence
- */
- public synchronized int findFeatureColour(int initialCol, SequenceI seq,
- int column)
- {
- if (!av.showSequenceFeatures)
- {
- return initialCol;
- }
-
- if (seq != lastSeq)
- {
- lastSeq = seq;
- sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures();
- if (sequenceFeatures != null)
- {
- sfSize = sequenceFeatures.length;
- }
- }
-
- if (sequenceFeatures != lastSeq.getDatasetSequence()
- .getSequenceFeatures())
- {
- sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures();
- if (sequenceFeatures != null)
- {
- sfSize = sequenceFeatures.length;
- }
- }
-
- if (sequenceFeatures == null || sfSize == 0)
- {
- return initialCol;
- }
-
- if (jalview.util.Comparison.isGap(lastSeq.getCharAt(column)))
- {
- return Color.white.getRGB();
- }
-
- // Only bother making an offscreen image if transparency is applied
- if (transparency != 1.0f && offscreenImage == null)
- {
- offscreenImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
- }
-
- currentColour = null;
- // TODO: non-threadsafe - each rendering thread needs its own instance of
- // the feature renderer - or this should be synchronized.
- offscreenRender = true;
-
- if (offscreenImage != null)
- {
- offscreenImage.setRGB(0, 0, initialCol);
- drawSequence(offscreenImage.getGraphics(), lastSeq, column, column, 0);
-
- return offscreenImage.getRGB(0, 0);
- }
- else
- {
- drawSequence(null, lastSeq, lastSeq.findPosition(column), -1, -1);
-
- if (currentColour == null)
- {
- return initialCol;
- }
- else
- {
- return ((Integer) currentColour).intValue();
- }
- }
-
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param g
- * DOCUMENT ME!
- * @param seq
- * DOCUMENT ME!
- * @param sg
- * DOCUMENT ME!
- * @param start
- * DOCUMENT ME!
- * @param end
- * DOCUMENT ME!
- * @param x1
- * DOCUMENT ME!
- * @param y1
- * DOCUMENT ME!
- * @param width
- * DOCUMENT ME!
- * @param height
- * DOCUMENT ME!
- */
- // String type;
- // SequenceFeature sf;
- SequenceI lastSeq;
-
- SequenceFeature[] sequenceFeatures;
-
- int sfSize, sfindex, spos, epos;
-
- /**
- * show scores as heights