2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 import java.awt.event.*;
25 import java.awt.image.*;
26 import java.beans.PropertyChangeListener;
27 import java.beans.PropertyChangeSupport;
31 import jalview.datamodel.*;
32 import jalview.schemes.GraduatedColor;
40 public class FeatureRenderer
49 * global transparency for feature
51 float transparency = 1.0f;
57 Hashtable featureColours = new Hashtable();
59 // A higher level for grouping features of a
61 Hashtable featureGroups = new Hashtable();
63 // This is actually an Integer held in the hashtable,
64 // Retrieved using the key feature type
69 PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
74 * Creates a new FeatureRenderer object.
79 public FeatureRenderer(AlignmentPanel ap)
85 public class FeatureRendererSettings implements Cloneable
89 Hashtable featureGroups;
91 Hashtable featureColours;
95 Hashtable featureOrder;
97 public FeatureRendererSettings(String[] renderOrder,
98 Hashtable featureGroups, Hashtable featureColours,
99 float transparency, Hashtable featureOrder)
102 this.renderOrder = renderOrder;
103 this.featureGroups = featureGroups;
104 this.featureColours = featureColours;
105 this.transparency = transparency;
106 this.featureOrder = featureOrder;
109 public FeatureRendererSettings(FeatureRenderer fr)
111 this.renderOrder = fr.renderOrder;
112 this.featureGroups = fr.featureGroups;
113 this.featureColours = fr.featureColours;
114 this.transparency = fr.transparency;
115 this.featureOrder = fr.featureOrder;
119 public FeatureRendererSettings getSettings()
121 return new FeatureRendererSettings(this);
124 public void transferSettings(FeatureRendererSettings fr)
126 this.renderOrder = fr.renderOrder;
127 this.featureGroups = fr.featureGroups;
128 this.featureColours = fr.featureColours;
129 this.transparency = fr.transparency;
130 this.featureOrder = fr.featureOrder;
133 public void transferSettings(FeatureRenderer fr)
135 this.renderOrder = fr.renderOrder;
136 this.featureGroups = fr.featureGroups;
137 this.featureColours = fr.featureColours;
138 this.transparency = fr.transparency;
139 this.featureOrder = fr.featureOrder;
142 BufferedImage offscreenImage;
144 boolean offscreenRender = false;
146 public Color findFeatureColour(Color initialCol, SequenceI seq, int res)
148 return new Color(findFeatureColour(initialCol.getRGB(), seq, res));
152 * This is used by the Molecule Viewer and Overview to get the accurate
153 * colourof the rendered sequence
155 public int findFeatureColour(int initialCol, SequenceI seq, int column)
157 if (!av.showSequenceFeatures)
165 sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures();
166 if (sequenceFeatures != null)
168 sfSize = sequenceFeatures.length;
172 if (sequenceFeatures != lastSeq.getDatasetSequence()
173 .getSequenceFeatures())
175 sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures();
176 if (sequenceFeatures != null)
178 sfSize = sequenceFeatures.length;
182 if (sequenceFeatures == null || sfSize == 0)
187 if (jalview.util.Comparison.isGap(lastSeq.getCharAt(column)))
189 return Color.white.getRGB();
192 // Only bother making an offscreen image if transparency is applied
193 if (transparency != 1.0f && offscreenImage == null)
195 offscreenImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
198 currentColour = null;
200 offscreenRender = true;
202 if (offscreenImage != null)
204 offscreenImage.setRGB(0, 0, initialCol);
205 drawSequence(offscreenImage.getGraphics(), lastSeq, column, column, 0);
207 return offscreenImage.getRGB(0, 0);
211 drawSequence(null, lastSeq, lastSeq.findPosition(column), -1, -1);
213 if (currentColour == null)
219 return ((Integer) currentColour).intValue();
248 // SequenceFeature sf;
251 SequenceFeature[] sequenceFeatures;
253 int sfSize, sfindex, spos, epos;
256 * show scores as heights
258 protected boolean varyHeight = false;
260 synchronized public void drawSequence(Graphics g, SequenceI seq,
261 int start, int end, int y1)
264 if (seq.getDatasetSequence().getSequenceFeatures() == null
265 || seq.getDatasetSequence().getSequenceFeatures().length == 0)
272 fm = g.getFontMetrics();
275 if (av.featuresDisplayed == null || renderOrder == null
279 if (av.featuresDisplayed.size() < 1)
284 sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures();
289 || seq.getDatasetSequence().getSequenceFeatures() != sequenceFeatures)
292 sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures();
295 if (transparency != 1 && g != null)
297 Graphics2D g2 = (Graphics2D) g;
298 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
302 if (!offscreenRender)
304 spos = lastSeq.findPosition(start);
305 epos = lastSeq.findPosition(end);
308 sfSize = sequenceFeatures.length;
310 for (int renderIndex = 0; renderIndex < renderOrder.length; renderIndex++)
312 type = renderOrder[renderIndex];
314 if (type == null || !av.featuresDisplayed.containsKey(type))
319 // loop through all features in sequence to find
320 // current feature to render
321 for (sfindex = 0; sfindex < sfSize; sfindex++)
323 if (!sequenceFeatures[sfindex].type.equals(type))
328 if (featureGroups != null
329 && sequenceFeatures[sfindex].featureGroup != null
330 && sequenceFeatures[sfindex].featureGroup.length() != 0
332 .containsKey(sequenceFeatures[sfindex].featureGroup)
333 && !((Boolean) featureGroups
334 .get(sequenceFeatures[sfindex].featureGroup))
341 && (sequenceFeatures[sfindex].getBegin() > epos || sequenceFeatures[sfindex]
347 if (offscreenRender && offscreenImage == null)
349 if (sequenceFeatures[sfindex].begin <= start
350 && sequenceFeatures[sfindex].end >= start)
352 currentColour = av.featuresDisplayed
353 .get(sequenceFeatures[sfindex].type);
356 else if (sequenceFeatures[sfindex].type.equals("disulfide bond"))
362 seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
363 seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
364 new Color(((Integer) av.featuresDisplayed
365 .get(sequenceFeatures[sfindex].type)).intValue()),
370 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
371 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
372 new Color(((Integer) av.featuresDisplayed
373 .get(sequenceFeatures[sfindex].type)).intValue()),
378 if (showFeature(sequenceFeatures[sfindex]))
380 if (av.showSeqFeaturesHeight
381 && sequenceFeatures[sfindex].score != Float.NaN)
383 renderScoreFeature(g, seq, seq
384 .findIndex(sequenceFeatures[sfindex].begin) - 1,
385 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
386 getColour(sequenceFeatures[sfindex]), start, end,
387 y1, normaliseScore(sequenceFeatures[sfindex]));
391 renderFeature(g, seq, seq
392 .findIndex(sequenceFeatures[sfindex].begin) - 1,
393 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
394 getColour(sequenceFeatures[sfindex]), start, end,
403 if (transparency != 1.0f && g != null)
405 Graphics2D g2 = (Graphics2D) g;
406 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
411 Hashtable minmax = new Hashtable();
414 * normalise a score against the max/min bounds for the feature type.
416 * @param sequenceFeature
417 * @return byte[] { signed, normalised signed (-127 to 127) or unsigned
420 private final byte[] normaliseScore(SequenceFeature sequenceFeature)
422 float[] mm = ((float[][]) minmax.get(sequenceFeature.type))[0];
423 final byte[] r = new byte[]
427 if (r[0] != 0 || mm[0] < 0.0)
430 r[1] = (byte) ((int) 128.0 + 127.0 * (sequenceFeature.score / mm[1]));
434 r[1] = (byte) ((int) 255.0 * (sequenceFeature.score / mm[1]));
444 void renderFeature(Graphics g, SequenceI seq, int fstart, int fend,
445 Color featureColour, int start, int end, int y1)
448 if (((fstart <= end) && (fend >= start)))
451 { // fix for if the feature we have starts before the sequence start,
452 fstart = start; // but the feature end is still valid!!
459 int pady = (y1 + av.charHeight) - av.charHeight / 5;
460 for (i = fstart; i <= fend; i++)
462 s = seq.getCharAt(i);
464 if (jalview.util.Comparison.isGap(s))
469 g.setColor(featureColour);
471 g.fillRect((i - start) * av.charWidth, y1, av.charWidth,
474 if (offscreenRender || !av.validCharWidth)
479 g.setColor(Color.white);
480 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
481 g.drawString(String.valueOf(s), charOffset
482 + (av.charWidth * (i - start)), pady);
488 void renderScoreFeature(Graphics g, SequenceI seq, int fstart, int fend,
489 Color featureColour, int start, int end, int y1, byte[] bs)
492 if (((fstart <= end) && (fend >= start)))
495 { // fix for if the feature we have starts before the sequence start,
496 fstart = start; // but the feature end is still valid!!
503 int pady = (y1 + av.charHeight) - av.charHeight / 5;
504 int ystrt = 0, yend = av.charHeight;
507 // signed - zero is always middle of residue line.
510 yend = av.charHeight * (128 - bs[1]) / 512;
511 ystrt = av.charHeight - yend / 2;
515 ystrt = av.charHeight / 2;
516 yend = av.charHeight * (bs[1] - 128) / 512;
521 yend = av.charHeight * bs[1] / 255;
522 ystrt = av.charHeight - yend;
525 for (i = fstart; i <= fend; i++)
527 s = seq.getCharAt(i);
529 if (jalview.util.Comparison.isGap(s))
534 g.setColor(featureColour);
535 int x = (i - start) * av.charWidth;
536 g.drawRect(x, y1, av.charWidth, av.charHeight);
537 g.fillRect(x, y1 + ystrt, av.charWidth, yend);
539 if (offscreenRender || !av.validCharWidth)
544 g.setColor(Color.black);
545 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
546 g.drawString(String.valueOf(s), charOffset
547 + (av.charWidth * (i - start)), pady);
553 boolean newFeatureAdded = false;
556 * Called when alignment in associated view has new/modified features to
557 * discover and display.
560 public void featuresAdded()
566 boolean findingFeatures = false;
569 * search the alignment for all new features, give them a colour and display
570 * them. Then fires a PropertyChangeEvent on the changeSupport object.
573 void findAllFeatures()
575 synchronized (firing)
577 if (firing.equals(Boolean.FALSE))
579 firing = Boolean.TRUE;
580 findAllFeatures(true); // add all new features as visible
581 changeSupport.firePropertyChange("changeSupport", null, null);
582 firing = Boolean.FALSE;
588 * Searches alignment for all features and updates colours
590 * @param newMadeVisible
591 * if true newly added feature types will be rendered
594 synchronized void findAllFeatures(boolean newMadeVisible)
596 newFeatureAdded = false;
600 newFeatureAdded = true;
604 findingFeatures = true;
606 if (av.featuresDisplayed == null)
608 av.featuresDisplayed = new Hashtable();
611 allfeatures = new Vector();
612 Vector oldfeatures = new Vector();
613 if (renderOrder != null)
615 for (int i = 0; i < renderOrder.length; i++)
617 if (renderOrder[i] != null)
619 oldfeatures.addElement(renderOrder[i]);
625 minmax = new Hashtable();
627 for (int i = 0; i < av.alignment.getHeight(); i++)
629 SequenceFeature[] features = av.alignment.getSequenceAt(i)
630 .getDatasetSequence().getSequenceFeatures();
632 if (features == null)
638 while (index < features.length)
640 if (!av.featuresDisplayed.containsKey(features[index].getType()))
643 if (featureGroups.containsKey(features[index].getType()))
645 boolean visible = ((Boolean) featureGroups
646 .get(features[index].featureGroup)).booleanValue();
655 if (!(features[index].begin == 0 && features[index].end == 0))
657 // If beginning and end are 0, the feature is for the whole sequence
658 // and we don't want to render the feature in the normal way
661 && !oldfeatures.contains(features[index].getType()))
663 // this is a new feature type on the alignment. Mark it for
665 av.featuresDisplayed.put(features[index].getType(),
666 new Integer(getColour(features[index].getType())
668 setOrder(features[index].getType(), 0);
672 if (!allfeatures.contains(features[index].getType()))
674 allfeatures.addElement(features[index].getType());
676 if (features[index].score != Float.NaN)
678 int nonpos= features[index].getBegin()>=1 ? 0 : 1;
679 float[][] mm = (float[][]) minmax.get(features[index].getType());
682 mm = new float[][] {null, null };
683 minmax.put(features[index].getType(), mm);
685 if (mm[nonpos]==null)
687 mm[nonpos] = new float[] { features[index].score, features[index].score };
692 if (mm[nonpos][0] > features[index].score)
694 mm[nonpos][0] = features[index].score;
696 if (mm[nonpos][1] < features[index].score)
698 mm[nonpos][1] = features[index].score;
705 updateRenderOrder(allfeatures);
706 findingFeatures = false;
709 protected Boolean firing = Boolean.FALSE;
712 * replaces the current renderOrder with the unordered features in
713 * allfeatures. The ordering of any types in both renderOrder and allfeatures
714 * is preserved, and all new feature types are rendered on top of the existing
715 * types, in the order given by getOrder or the order given in allFeatures.
716 * Note. this operates directly on the featureOrder hash for efficiency. TODO:
717 * eliminate the float storage for computing/recalling the persistent ordering
721 private void updateRenderOrder(Vector allFeatures)
723 Vector allfeatures = new Vector(allFeatures);
724 String[] oldRender = renderOrder;
725 renderOrder = new String[allfeatures.size()];
726 boolean initOrders = (featureOrder == null);
728 if (oldRender != null && oldRender.length > 0)
730 for (int j = 0; j < oldRender.length; j++)
732 if (oldRender[j] != null)
736 setOrder(oldRender[j], (1 - (1 + (float) j)
737 / (float) oldRender.length));
739 if (allfeatures.contains(oldRender[j]))
741 renderOrder[opos++] = oldRender[j]; // existing features always
742 // appear below new features
743 allfeatures.removeElement(oldRender[j]);
748 if (allfeatures.size() == 0)
750 // no new features - leave order unchanged.
753 int i = allfeatures.size() - 1;
755 boolean sort = false;
756 String[] newf = new String[allfeatures.size()];
757 float[] sortOrder = new float[allfeatures.size()];
758 Enumeration en = allfeatures.elements();
759 // sort remaining elements
760 while (en.hasMoreElements())
762 newf[i] = en.nextElement().toString();
763 if (initOrders || !featureOrder.containsKey(newf[i]))
765 int denom = initOrders ? allfeatures.size() : featureOrder.size();
766 // new unordered feature - compute persistent ordering at head of
767 // existing features.
768 setOrder(newf[i], i / (float) denom);
770 // set order from newly found feature from persisted ordering.
771 sortOrder[i] = 2 - ((Float) featureOrder.get(newf[i])).floatValue();
774 // only sort if we need to
775 sort = sort || sortOrder[i] > sortOrder[i + 1];
779 if (iSize > 1 && sort)
780 jalview.util.QuickSort.sort(sortOrder, newf);
782 System.arraycopy(newf, 0, renderOrder, opos, newf.length);
785 public Color getColour(String featureType)
787 Object fc = featureColours.get(featureType);
790 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();
791 Color col = ucs.createColourFromName(featureType);
792 featureColours.put(featureType, col);
795 else if (fc instanceof Color)
801 if (fc instanceof GraduatedColor)
803 return ((GraduatedColor) fc).getMinColor();
805 // TODO: raise an implementation error here.
806 return null; // Color.white;
811 * implement graduated colouring for features with scores
814 * @return render colour for the given feature
816 public Color getColour(SequenceFeature feature)
818 Object fc = featureColours.get(feature.type);
821 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();
822 Color col = ucs.createColourFromName(feature.type);
823 featureColours.put(feature.type, col);
826 else if (fc instanceof Color)
832 if (fc instanceof GraduatedColor)
834 return ((GraduatedColor) fc).findColor(feature);
836 // TODO: raise an implementation error here.
837 return null; // Color.white;
840 private boolean showFeature(SequenceFeature sequenceFeature)
842 Object fc = featureColours.get(sequenceFeature.type);
843 if (fc instanceof GraduatedColor)
845 return ((GraduatedColor) fc).isColored(sequenceFeature);
846 } else { return true; }
850 static String lastFeatureAdded;
852 static String lastFeatureGroupAdded;
854 static String lastDescriptionAdded;
856 int featureIndex = 0;
858 boolean amendFeatures(final SequenceI[] sequences,
859 final SequenceFeature[] features, boolean newFeatures,
860 final AlignmentPanel ap)
865 JPanel bigPanel = new JPanel(new BorderLayout());
866 final JComboBox overlaps;
867 final JTextField name = new JTextField(25);
868 final JTextField source = new JTextField(25);
869 final JTextArea description = new JTextArea(3, 25);
870 final JSpinner start = new JSpinner();
871 final JSpinner end = new JSpinner();
872 start.setPreferredSize(new Dimension(80, 20));
873 end.setPreferredSize(new Dimension(80, 20));
875 final JPanel colour = new JPanel();
876 colour.setBorder(BorderFactory.createEtchedBorder());
877 colour.setMaximumSize(new Dimension(40, 10));
878 colour.addMouseListener(new MouseAdapter()
880 public void mousePressed(MouseEvent evt)
882 // TODO: use featurecolourchooser here
883 Color col = JColorChooser.showDialog(Desktop.desktop,
884 "Select Feature Colour", colour.getBackground());
886 colour.setBackground(col);
891 JPanel tmp = new JPanel();
892 JPanel panel = new JPanel(new GridLayout(3, 1));
894 // /////////////////////////////////////
895 // /MULTIPLE FEATURES AT SELECTED RESIDUE
896 if (!newFeatures && features.length > 1)
898 panel = new JPanel(new GridLayout(4, 1));
900 tmp.add(new JLabel("Select Feature: "));
901 overlaps = new JComboBox();
902 for (int i = 0; i < features.length; i++)
904 overlaps.addItem(features[i].getType() + "/"
905 + features[i].getBegin() + "-" + features[i].getEnd()
906 + " (" + features[i].getFeatureGroup() + ")");
911 overlaps.addItemListener(new ItemListener()
913 public void itemStateChanged(ItemEvent e)
915 int index = overlaps.getSelectedIndex();
918 featureIndex = index;
919 name.setText(features[index].getType());
920 description.setText(features[index].getDescription());
921 source.setText(features[index].getFeatureGroup());
922 start.setValue(new Integer(features[index].getBegin()));
923 end.setValue(new Integer(features[index].getEnd()));
925 SearchResults highlight = new SearchResults();
926 highlight.addResult(sequences[0], features[index].getBegin(),
927 features[index].getEnd());
929 ap.seqPanel.seqCanvas.highlightSearchResults(highlight);
932 Color col = getColour(name.getText());
935 col = new jalview.schemes.UserColourScheme()
936 .createColourFromName(name.getText());
939 colour.setBackground(col);
946 // ////////////////////////////////////
950 tmp.add(new JLabel("Name: ", JLabel.RIGHT));
955 tmp.add(new JLabel("Group: ", JLabel.RIGHT));
960 tmp.add(new JLabel("Colour: ", JLabel.RIGHT));
962 colour.setPreferredSize(new Dimension(150, 15));
964 bigPanel.add(panel, BorderLayout.NORTH);
966 panel = new JPanel();
967 panel.add(new JLabel("Description: ", JLabel.RIGHT));
968 description.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
969 description.setLineWrap(true);
970 panel.add(new JScrollPane(description));
974 bigPanel.add(panel, BorderLayout.SOUTH);
976 panel = new JPanel();
977 panel.add(new JLabel(" Start:", JLabel.RIGHT));
979 panel.add(new JLabel(" End:", JLabel.RIGHT));
981 bigPanel.add(panel, BorderLayout.CENTER);
985 bigPanel.add(panel, BorderLayout.CENTER);
988 if (lastFeatureAdded == null)
990 if (features[0].type != null)
992 lastFeatureAdded = features[0].type;
996 lastFeatureAdded = "feature_1";
1000 if (lastFeatureGroupAdded == null)
1002 if (features[0].featureGroup != null)
1004 lastFeatureGroupAdded = features[0].featureGroup;
1008 lastFeatureGroupAdded = "Jalview";
1014 name.setText(lastFeatureAdded);
1015 source.setText(lastFeatureGroupAdded);
1019 name.setText(features[0].getType());
1020 source.setText(features[0].getFeatureGroup());
1023 start.setValue(new Integer(features[0].getBegin()));
1024 end.setValue(new Integer(features[0].getEnd()));
1025 description.setText(features[0].getDescription());
1026 colour.setBackground(getColour(name.getText()));
1031 options = new Object[]
1032 { "Amend", "Delete", "Cancel" };
1036 options = new Object[]
1040 String title = newFeatures ? "Create New Sequence Feature(s)"
1041 : "Amend/Delete Features for " + sequences[0].getName();
1043 int reply = JOptionPane.showInternalOptionDialog(Desktop.desktop,
1044 bigPanel, title, JOptionPane.YES_NO_CANCEL_OPTION,
1045 JOptionPane.QUESTION_MESSAGE, null, options, "OK");
1047 jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile();
1049 if (reply == JOptionPane.OK_OPTION && name.getText().length() > 0)
1051 // This ensures that the last sequence
1052 // is refreshed and new features are rendered
1054 lastFeatureAdded = name.getText().trim();
1055 lastFeatureGroupAdded = source.getText().trim();
1056 lastDescriptionAdded = description.getText().replaceAll("\n", " ");
1058 if (lastFeatureGroupAdded.length() < 1)
1059 lastFeatureGroupAdded = null;
1064 SequenceFeature sf = features[featureIndex];
1066 if (reply == JOptionPane.NO_OPTION)
1068 sequences[0].getDatasetSequence().deleteFeature(sf);
1070 else if (reply == JOptionPane.YES_OPTION)
1072 sf.type = lastFeatureAdded;
1073 sf.featureGroup = lastFeatureGroupAdded;
1074 sf.description = lastDescriptionAdded;
1076 setColour(sf.type, colour.getBackground());
1077 av.featuresDisplayed.put(sf.type, new Integer(colour
1078 .getBackground().getRGB()));
1082 sf.begin = ((Integer) start.getValue()).intValue();
1083 sf.end = ((Integer) end.getValue()).intValue();
1084 } catch (NumberFormatException ex)
1088 ffile.parseDescriptionHTML(sf, false);
1092 // NEW FEATURES ADDED
1094 if (reply == JOptionPane.OK_OPTION && lastFeatureAdded.length() > 0)
1096 for (int i = 0; i < sequences.length; i++)
1098 features[i].type = lastFeatureAdded;
1099 if (lastFeatureGroupAdded != null)
1100 features[i].featureGroup = lastFeatureGroupAdded;
1101 features[i].description = lastDescriptionAdded;
1102 sequences[i].addSequenceFeature(features[i]);
1103 ffile.parseDescriptionHTML(features[i], false);
1106 if (av.featuresDisplayed == null)
1108 av.featuresDisplayed = new Hashtable();
1111 if (lastFeatureGroupAdded != null)
1113 if (featureGroups == null)
1114 featureGroups = new Hashtable();
1115 featureGroups.put(lastFeatureGroupAdded, new Boolean(true));
1118 Color col = colour.getBackground();
1119 setColour(lastFeatureAdded, colour.getBackground());
1120 av.featuresDisplayed.put(lastFeatureAdded,
1121 new Integer(col.getRGB()));
1123 findAllFeatures(false);
1125 ap.paintAlignment(true);
1135 ap.paintAlignment(true);
1140 public void setColour(String featureType, Color col)
1142 Object c = featureColours.get(featureType);
1143 if (c == null || c instanceof Color || (c instanceof GraduatedColor && !((GraduatedColor)c).getMaxColor().equals(col)))
1145 featureColours.put(featureType, col);
1149 public void setTransparency(float value)
1151 transparency = value;
1154 public float getTransparency()
1156 return transparency;
1160 * Replace current ordering with new ordering
1163 * String(Type), Colour(Type), Boolean(Displayed) }
1165 public void setFeaturePriority(Object[][] data)
1167 setFeaturePriority(data, true);
1173 * String(Type), Colour(Type), Boolean(Displayed) }
1175 * when true current featureDisplay list will be cleared
1177 public void setFeaturePriority(Object[][] data, boolean visibleNew)
1181 if (av.featuresDisplayed != null)
1183 av.featuresDisplayed.clear();
1187 av.featuresDisplayed = new Hashtable();
1195 // The feature table will display high priority
1196 // features at the top, but theses are the ones
1197 // we need to render last, so invert the data
1198 renderOrder = new String[data.length];
1200 if (data.length > 0)
1202 for (int i = 0; i < data.length; i++)
1204 String type = data[i][0].toString();
1205 setColour(type, (Color) data[i][1]);
1206 if (((Boolean) data[i][2]).booleanValue())
1208 av.featuresDisplayed.put(type, new Integer(getColour(type)
1212 renderOrder[data.length - i - 1] = type;
1218 Hashtable featureOrder = null;
1221 * analogous to colour - store a normalized ordering for all feature types in
1222 * this rendering context.
1225 * Feature type string
1227 * normalized priority - 0 means always appears on top, 1 means
1230 public float setOrder(String type, float position)
1232 if (featureOrder == null)
1234 featureOrder = new Hashtable();
1236 featureOrder.put(type, new Float(position));
1241 * get the global priority (0 (top) to 1 (bottom))
1244 * @return [0,1] or -1 for a type without a priority
1246 public float getOrder(String type)
1248 if (featureOrder != null)
1250 if (featureOrder.containsKey(type))
1252 return ((Float) featureOrder.get(type)).floatValue();
1260 * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener)
1262 public void addPropertyChangeListener(PropertyChangeListener listener)
1264 changeSupport.addPropertyChangeListener(listener);
1269 * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.beans.PropertyChangeListener)
1271 public void removePropertyChangeListener(PropertyChangeListener listener)
1273 changeSupport.removePropertyChangeListener(listener);