2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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 // this is passed out to the overview and other sequence renderers (e.g. molecule viewer) to get displayed colour for rendered sequence
353 currentColour = new Integer(getColour(sequenceFeatures[sfindex]).getRGB());
354 // used to be retreived from av.featuresDisplayed
355 // currentColour = av.featuresDisplayed
356 // .get(sequenceFeatures[sfindex].type);
361 else if (sequenceFeatures[sfindex].type.equals("disulfide bond"))
367 seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
368 seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
369 getColour(sequenceFeatures[sfindex])
370 //new Color(((Integer) av.featuresDisplayed
371 // .get(sequenceFeatures[sfindex].type)).intValue())
377 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
378 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
379 getColour(sequenceFeatures[sfindex])
380 //new Color(((Integer) av.featuresDisplayed
381 // .get(sequenceFeatures[sfindex].type)).intValue())
387 if (showFeature(sequenceFeatures[sfindex]))
389 if (av.showSeqFeaturesHeight
390 && sequenceFeatures[sfindex].score != Float.NaN)
392 renderScoreFeature(g, seq, seq
393 .findIndex(sequenceFeatures[sfindex].begin) - 1,
394 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
395 getColour(sequenceFeatures[sfindex]), start, end,
396 y1, normaliseScore(sequenceFeatures[sfindex]));
400 renderFeature(g, seq, seq
401 .findIndex(sequenceFeatures[sfindex].begin) - 1,
402 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
403 getColour(sequenceFeatures[sfindex]), start, end,
412 if (transparency != 1.0f && g != null)
414 Graphics2D g2 = (Graphics2D) g;
415 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
420 Hashtable minmax = new Hashtable();
423 * normalise a score against the max/min bounds for the feature type.
425 * @param sequenceFeature
426 * @return byte[] { signed, normalised signed (-127 to 127) or unsigned
429 private final byte[] normaliseScore(SequenceFeature sequenceFeature)
431 float[] mm = ((float[][]) minmax.get(sequenceFeature.type))[0];
432 final byte[] r = new byte[]
436 if (r[0] != 0 || mm[0] < 0.0)
439 r[1] = (byte) ((int) 128.0 + 127.0 * (sequenceFeature.score / mm[1]));
443 r[1] = (byte) ((int) 255.0 * (sequenceFeature.score / mm[1]));
453 void renderFeature(Graphics g, SequenceI seq, int fstart, int fend,
454 Color featureColour, int start, int end, int y1)
457 if (((fstart <= end) && (fend >= start)))
460 { // fix for if the feature we have starts before the sequence start,
461 fstart = start; // but the feature end is still valid!!
468 int pady = (y1 + av.charHeight) - av.charHeight / 5;
469 for (i = fstart; i <= fend; i++)
471 s = seq.getCharAt(i);
473 if (jalview.util.Comparison.isGap(s))
478 g.setColor(featureColour);
480 g.fillRect((i - start) * av.charWidth, y1, av.charWidth,
483 if (offscreenRender || !av.validCharWidth)
488 g.setColor(Color.white);
489 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
490 g.drawString(String.valueOf(s), charOffset
491 + (av.charWidth * (i - start)), pady);
497 void renderScoreFeature(Graphics g, SequenceI seq, int fstart, int fend,
498 Color featureColour, int start, int end, int y1, byte[] bs)
501 if (((fstart <= end) && (fend >= start)))
504 { // fix for if the feature we have starts before the sequence start,
505 fstart = start; // but the feature end is still valid!!
512 int pady = (y1 + av.charHeight) - av.charHeight / 5;
513 int ystrt = 0, yend = av.charHeight;
516 // signed - zero is always middle of residue line.
519 yend = av.charHeight * (128 - bs[1]) / 512;
520 ystrt = av.charHeight - yend / 2;
524 ystrt = av.charHeight / 2;
525 yend = av.charHeight * (bs[1] - 128) / 512;
530 yend = av.charHeight * bs[1] / 255;
531 ystrt = av.charHeight - yend;
534 for (i = fstart; i <= fend; i++)
536 s = seq.getCharAt(i);
538 if (jalview.util.Comparison.isGap(s))
543 g.setColor(featureColour);
544 int x = (i - start) * av.charWidth;
545 g.drawRect(x, y1, av.charWidth, av.charHeight);
546 g.fillRect(x, y1 + ystrt, av.charWidth, yend);
548 if (offscreenRender || !av.validCharWidth)
553 g.setColor(Color.black);
554 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
555 g.drawString(String.valueOf(s), charOffset
556 + (av.charWidth * (i - start)), pady);
562 boolean newFeatureAdded = false;
565 * Called when alignment in associated view has new/modified features to
566 * discover and display.
569 public void featuresAdded()
575 boolean findingFeatures = false;
578 * search the alignment for all new features, give them a colour and display
579 * them. Then fires a PropertyChangeEvent on the changeSupport object.
582 void findAllFeatures()
584 synchronized (firing)
586 if (firing.equals(Boolean.FALSE))
588 firing = Boolean.TRUE;
589 findAllFeatures(true); // add all new features as visible
590 changeSupport.firePropertyChange("changeSupport", null, null);
591 firing = Boolean.FALSE;
597 * Searches alignment for all features and updates colours
599 * @param newMadeVisible
600 * if true newly added feature types will be rendered
603 synchronized void findAllFeatures(boolean newMadeVisible)
605 newFeatureAdded = false;
609 newFeatureAdded = true;
613 findingFeatures = true;
615 if (av.featuresDisplayed == null)
617 av.featuresDisplayed = new Hashtable();
620 allfeatures = new Vector();
621 Vector oldfeatures = new Vector();
622 if (renderOrder != null)
624 for (int i = 0; i < renderOrder.length; i++)
626 if (renderOrder[i] != null)
628 oldfeatures.addElement(renderOrder[i]);
634 minmax = new Hashtable();
636 for (int i = 0; i < av.alignment.getHeight(); i++)
638 SequenceFeature[] features = av.alignment.getSequenceAt(i)
639 .getDatasetSequence().getSequenceFeatures();
641 if (features == null)
647 while (index < features.length)
649 if (!av.featuresDisplayed.containsKey(features[index].getType()))
652 if (featureGroups.containsKey(features[index].getType()))
654 boolean visible = ((Boolean) featureGroups
655 .get(features[index].featureGroup)).booleanValue();
664 if (!(features[index].begin == 0 && features[index].end == 0))
666 // If beginning and end are 0, the feature is for the whole sequence
667 // and we don't want to render the feature in the normal way
670 && !oldfeatures.contains(features[index].getType()))
672 // this is a new feature type on the alignment. Mark it for
674 av.featuresDisplayed.put(features[index].getType(),
675 new Integer(getColour(features[index].getType())
677 setOrder(features[index].getType(), 0);
681 if (!allfeatures.contains(features[index].getType()))
683 allfeatures.addElement(features[index].getType());
685 if (features[index].score != Float.NaN)
687 int nonpos= features[index].getBegin()>=1 ? 0 : 1;
688 float[][] mm = (float[][]) minmax.get(features[index].getType());
691 mm = new float[][] {null, null };
692 minmax.put(features[index].getType(), mm);
694 if (mm[nonpos]==null)
696 mm[nonpos] = new float[] { features[index].score, features[index].score };
701 if (mm[nonpos][0] > features[index].score)
703 mm[nonpos][0] = features[index].score;
705 if (mm[nonpos][1] < features[index].score)
707 mm[nonpos][1] = features[index].score;
714 updateRenderOrder(allfeatures);
715 findingFeatures = false;
718 protected Boolean firing = Boolean.FALSE;
721 * replaces the current renderOrder with the unordered features in
722 * allfeatures. The ordering of any types in both renderOrder and allfeatures
723 * is preserved, and all new feature types are rendered on top of the existing
724 * types, in the order given by getOrder or the order given in allFeatures.
725 * Note. this operates directly on the featureOrder hash for efficiency. TODO:
726 * eliminate the float storage for computing/recalling the persistent ordering
727 * New Cability: updates min/max for colourscheme range if its dynamic
730 private void updateRenderOrder(Vector allFeatures)
732 Vector allfeatures = new Vector(allFeatures);
733 String[] oldRender = renderOrder;
734 renderOrder = new String[allfeatures.size()];
735 Object mmrange,fc=null;
736 boolean initOrders = (featureOrder == null);
738 if (oldRender != null && oldRender.length > 0)
740 for (int j = 0; j < oldRender.length; j++)
742 if (oldRender[j] != null)
746 setOrder(oldRender[j], (1 - (1 + (float) j)
747 / (float) oldRender.length));
749 if (allfeatures.contains(oldRender[j]))
751 renderOrder[opos++] = oldRender[j]; // existing features always
752 // appear below new features
753 allfeatures.removeElement(oldRender[j]);
756 mmrange = minmax.get(oldRender[j]);
759 fc = featureColours.get(oldRender[j]);
760 if (fc!=null && fc instanceof GraduatedColor && ((GraduatedColor)fc).isAutoScale())
762 ((GraduatedColor) fc).updateBounds(((float[][])mmrange)[0][0],((float[][])mmrange)[0][1]);
770 if (allfeatures.size() == 0)
772 // no new features - leave order unchanged.
775 int i = allfeatures.size() - 1;
777 boolean sort = false;
778 String[] newf = new String[allfeatures.size()];
779 float[] sortOrder = new float[allfeatures.size()];
780 Enumeration en = allfeatures.elements();
781 // sort remaining elements
782 while (en.hasMoreElements())
784 newf[i] = en.nextElement().toString();
787 // update from new features minmax if necessary
788 mmrange = minmax.get(newf[i]);
791 fc = featureColours.get(newf[i]);
792 if (fc!=null && fc instanceof GraduatedColor && ((GraduatedColor)fc).isAutoScale())
794 ((GraduatedColor) fc).updateBounds(((float[][])mmrange)[0][0],((float[][])mmrange)[0][1]);
798 if (initOrders || !featureOrder.containsKey(newf[i]))
800 int denom = initOrders ? allfeatures.size() : featureOrder.size();
801 // new unordered feature - compute persistent ordering at head of
802 // existing features.
803 setOrder(newf[i], i / (float) denom);
805 // set order from newly found feature from persisted ordering.
806 sortOrder[i] = 2 - ((Float) featureOrder.get(newf[i])).floatValue();
809 // only sort if we need to
810 sort = sort || sortOrder[i] > sortOrder[i + 1];
814 if (iSize > 1 && sort)
816 jalview.util.QuickSort.sort(sortOrder, newf);
819 System.arraycopy(newf, 0, renderOrder, opos, newf.length);
822 public Color getColour(String featureType)
824 Object fc = featureColours.get(featureType);
827 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();
828 Color col = ucs.createColourFromName(featureType);
829 featureColours.put(featureType, col);
832 else if (fc instanceof Color)
838 if (fc instanceof GraduatedColor)
840 return ((GraduatedColor) fc).getMaxColor();
842 // TODO: raise an implementation error here.
843 return null; // Color.white;
848 * implement graduated colouring for features with scores
851 * @return render colour for the given feature
853 public Color getColour(SequenceFeature feature)
855 Object fc = featureColours.get(feature.type);
858 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();
859 Color col = ucs.createColourFromName(feature.type);
860 featureColours.put(feature.type, col);
863 else if (fc instanceof Color)
869 if (fc instanceof GraduatedColor)
871 return ((GraduatedColor) fc).findColor(feature);
873 // TODO: raise an implementation error here.
874 return null; // Color.white;
877 private boolean showFeature(SequenceFeature sequenceFeature)
879 Object fc = featureColours.get(sequenceFeature.type);
880 if (fc instanceof GraduatedColor)
882 return ((GraduatedColor) fc).isColored(sequenceFeature);
883 } else { return true; }
887 static String lastFeatureAdded;
889 static String lastFeatureGroupAdded;
891 static String lastDescriptionAdded;
893 int featureIndex = 0;
895 boolean amendFeatures(final SequenceI[] sequences,
896 final SequenceFeature[] features, boolean newFeatures,
897 final AlignmentPanel ap)
902 JPanel bigPanel = new JPanel(new BorderLayout());
903 final JComboBox overlaps;
904 final JTextField name = new JTextField(25);
905 final JTextField source = new JTextField(25);
906 final JTextArea description = new JTextArea(3, 25);
907 final JSpinner start = new JSpinner();
908 final JSpinner end = new JSpinner();
909 start.setPreferredSize(new Dimension(80, 20));
910 end.setPreferredSize(new Dimension(80, 20));
912 final JPanel colour = new JPanel();
913 colour.setBorder(BorderFactory.createEtchedBorder());
914 colour.setMaximumSize(new Dimension(40, 10));
915 colour.addMouseListener(new MouseAdapter()
917 public void mousePressed(MouseEvent evt)
919 // TODO: use featurecolourchooser here
920 Color col = JColorChooser.showDialog(Desktop.desktop,
921 "Select Feature Colour", colour.getBackground());
923 colour.setBackground(col);
928 JPanel tmp = new JPanel();
929 JPanel panel = new JPanel(new GridLayout(3, 1));
931 // /////////////////////////////////////
932 // /MULTIPLE FEATURES AT SELECTED RESIDUE
933 if (!newFeatures && features.length > 1)
935 panel = new JPanel(new GridLayout(4, 1));
937 tmp.add(new JLabel("Select Feature: "));
938 overlaps = new JComboBox();
939 for (int i = 0; i < features.length; i++)
941 overlaps.addItem(features[i].getType() + "/"
942 + features[i].getBegin() + "-" + features[i].getEnd()
943 + " (" + features[i].getFeatureGroup() + ")");
948 overlaps.addItemListener(new ItemListener()
950 public void itemStateChanged(ItemEvent e)
952 int index = overlaps.getSelectedIndex();
955 featureIndex = index;
956 name.setText(features[index].getType());
957 description.setText(features[index].getDescription());
958 source.setText(features[index].getFeatureGroup());
959 start.setValue(new Integer(features[index].getBegin()));
960 end.setValue(new Integer(features[index].getEnd()));
962 SearchResults highlight = new SearchResults();
963 highlight.addResult(sequences[0], features[index].getBegin(),
964 features[index].getEnd());
966 ap.seqPanel.seqCanvas.highlightSearchResults(highlight);
969 Color col = getColour(name.getText());
972 col = new jalview.schemes.UserColourScheme()
973 .createColourFromName(name.getText());
976 colour.setBackground(col);
983 // ////////////////////////////////////
987 tmp.add(new JLabel("Name: ", JLabel.RIGHT));
992 tmp.add(new JLabel("Group: ", JLabel.RIGHT));
997 tmp.add(new JLabel("Colour: ", JLabel.RIGHT));
999 colour.setPreferredSize(new Dimension(150, 15));
1001 bigPanel.add(panel, BorderLayout.NORTH);
1003 panel = new JPanel();
1004 panel.add(new JLabel("Description: ", JLabel.RIGHT));
1005 description.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
1006 description.setLineWrap(true);
1007 panel.add(new JScrollPane(description));
1011 bigPanel.add(panel, BorderLayout.SOUTH);
1013 panel = new JPanel();
1014 panel.add(new JLabel(" Start:", JLabel.RIGHT));
1016 panel.add(new JLabel(" End:", JLabel.RIGHT));
1018 bigPanel.add(panel, BorderLayout.CENTER);
1022 bigPanel.add(panel, BorderLayout.CENTER);
1025 if (lastFeatureAdded == null)
1027 if (features[0].type != null)
1029 lastFeatureAdded = features[0].type;
1033 lastFeatureAdded = "feature_1";
1037 if (lastFeatureGroupAdded == null)
1039 if (features[0].featureGroup != null)
1041 lastFeatureGroupAdded = features[0].featureGroup;
1045 lastFeatureGroupAdded = "Jalview";
1051 name.setText(lastFeatureAdded);
1052 source.setText(lastFeatureGroupAdded);
1056 name.setText(features[0].getType());
1057 source.setText(features[0].getFeatureGroup());
1060 start.setValue(new Integer(features[0].getBegin()));
1061 end.setValue(new Integer(features[0].getEnd()));
1062 description.setText(features[0].getDescription());
1063 colour.setBackground(getColour(name.getText()));
1068 options = new Object[]
1069 { "Amend", "Delete", "Cancel" };
1073 options = new Object[]
1077 String title = newFeatures ? "Create New Sequence Feature(s)"
1078 : "Amend/Delete Features for " + sequences[0].getName();
1080 int reply = JOptionPane.showInternalOptionDialog(Desktop.desktop,
1081 bigPanel, title, JOptionPane.YES_NO_CANCEL_OPTION,
1082 JOptionPane.QUESTION_MESSAGE, null, options, "OK");
1084 jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile();
1086 if (reply == JOptionPane.OK_OPTION && name.getText().length() > 0)
1088 // This ensures that the last sequence
1089 // is refreshed and new features are rendered
1091 lastFeatureAdded = name.getText().trim();
1092 lastFeatureGroupAdded = source.getText().trim();
1093 lastDescriptionAdded = description.getText().replaceAll("\n", " ");
1095 if (lastFeatureGroupAdded.length() < 1)
1096 lastFeatureGroupAdded = null;
1101 SequenceFeature sf = features[featureIndex];
1103 if (reply == JOptionPane.NO_OPTION)
1105 sequences[0].getDatasetSequence().deleteFeature(sf);
1107 else if (reply == JOptionPane.YES_OPTION)
1109 sf.type = lastFeatureAdded;
1110 sf.featureGroup = lastFeatureGroupAdded;
1111 sf.description = lastDescriptionAdded;
1113 setColour(sf.type, colour.getBackground());
1114 av.featuresDisplayed.put(sf.type, new Integer(colour
1115 .getBackground().getRGB()));
1119 sf.begin = ((Integer) start.getValue()).intValue();
1120 sf.end = ((Integer) end.getValue()).intValue();
1121 } catch (NumberFormatException ex)
1125 ffile.parseDescriptionHTML(sf, false);
1129 // NEW FEATURES ADDED
1131 if (reply == JOptionPane.OK_OPTION && lastFeatureAdded.length() > 0)
1133 for (int i = 0; i < sequences.length; i++)
1135 features[i].type = lastFeatureAdded;
1136 if (lastFeatureGroupAdded != null)
1137 features[i].featureGroup = lastFeatureGroupAdded;
1138 features[i].description = lastDescriptionAdded;
1139 sequences[i].addSequenceFeature(features[i]);
1140 ffile.parseDescriptionHTML(features[i], false);
1143 if (av.featuresDisplayed == null)
1145 av.featuresDisplayed = new Hashtable();
1148 if (lastFeatureGroupAdded != null)
1150 if (featureGroups == null)
1151 featureGroups = new Hashtable();
1152 featureGroups.put(lastFeatureGroupAdded, new Boolean(true));
1155 Color col = colour.getBackground();
1156 setColour(lastFeatureAdded, colour.getBackground());
1157 av.featuresDisplayed.put(lastFeatureAdded,
1158 new Integer(col.getRGB()));
1160 findAllFeatures(false);
1162 ap.paintAlignment(true);
1172 ap.paintAlignment(true);
1177 public void setColour(String featureType, Color col)
1179 Object c = featureColours.get(featureType);
1180 if (c == null || c instanceof Color || (c instanceof GraduatedColor && !((GraduatedColor)c).getMaxColor().equals(col)))
1182 featureColours.put(featureType, col);
1186 public void setTransparency(float value)
1188 transparency = value;
1191 public float getTransparency()
1193 return transparency;
1197 * Replace current ordering with new ordering
1200 * String(Type), Colour(Type), Boolean(Displayed) }
1202 public void setFeaturePriority(Object[][] data)
1204 setFeaturePriority(data, true);
1210 * String(Type), Colour(Type), Boolean(Displayed) }
1212 * when true current featureDisplay list will be cleared
1214 public void setFeaturePriority(Object[][] data, boolean visibleNew)
1218 if (av.featuresDisplayed != null)
1220 av.featuresDisplayed.clear();
1224 av.featuresDisplayed = new Hashtable();
1232 // The feature table will display high priority
1233 // features at the top, but theses are the ones
1234 // we need to render last, so invert the data
1235 renderOrder = new String[data.length];
1237 if (data.length > 0)
1239 for (int i = 0; i < data.length; i++)
1241 String type = data[i][0].toString();
1242 setColour(type, (Color) data[i][1]);
1243 if (((Boolean) data[i][2]).booleanValue())
1245 av.featuresDisplayed.put(type, new Integer(getColour(type)
1249 renderOrder[data.length - i - 1] = type;
1255 Hashtable featureOrder = null;
1258 * analogous to colour - store a normalized ordering for all feature types in
1259 * this rendering context.
1262 * Feature type string
1264 * normalized priority - 0 means always appears on top, 1 means
1267 public float setOrder(String type, float position)
1269 if (featureOrder == null)
1271 featureOrder = new Hashtable();
1273 featureOrder.put(type, new Float(position));
1278 * get the global priority (0 (top) to 1 (bottom))
1281 * @return [0,1] or -1 for a type without a priority
1283 public float getOrder(String type)
1285 if (featureOrder != null)
1287 if (featureOrder.containsKey(type))
1289 return ((Float) featureOrder.get(type)).floatValue();
1297 * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener)
1299 public void addPropertyChangeListener(PropertyChangeListener listener)
1301 changeSupport.addPropertyChangeListener(listener);
1306 * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.beans.PropertyChangeListener)
1308 public void removePropertyChangeListener(PropertyChangeListener listener)
1310 changeSupport.removePropertyChangeListener(listener);