2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
23 import java.awt.event.*;
24 import java.awt.image.*;
25 import java.beans.PropertyChangeListener;
26 import java.beans.PropertyChangeSupport;
30 import jalview.datamodel.*;
31 import jalview.schemes.GraduatedColor;
39 public class FeatureRenderer
48 * global transparency for feature
50 float transparency = 1.0f;
56 Hashtable featureColours = new Hashtable();
58 // A higher level for grouping features of a
60 Hashtable featureGroups = new Hashtable();
62 // This is actually an Integer held in the hashtable,
63 // Retrieved using the key feature type
68 PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
73 * Creates a new FeatureRenderer object.
78 public FeatureRenderer(AlignmentPanel ap)
84 public class FeatureRendererSettings implements Cloneable
88 Hashtable featureGroups;
90 Hashtable featureColours;
94 Hashtable featureOrder;
96 public FeatureRendererSettings(String[] renderOrder,
97 Hashtable featureGroups, Hashtable featureColours,
98 float transparency, Hashtable featureOrder)
101 this.renderOrder = renderOrder;
102 this.featureGroups = featureGroups;
103 this.featureColours = featureColours;
104 this.transparency = transparency;
105 this.featureOrder = featureOrder;
108 public FeatureRendererSettings(FeatureRenderer fr)
110 this.renderOrder = fr.renderOrder;
111 this.featureGroups = fr.featureGroups;
112 this.featureColours = fr.featureColours;
113 this.transparency = fr.transparency;
114 this.featureOrder = fr.featureOrder;
118 public FeatureRendererSettings getSettings()
120 return new FeatureRendererSettings(this);
123 public void transferSettings(FeatureRendererSettings fr)
125 this.renderOrder = fr.renderOrder;
126 this.featureGroups = fr.featureGroups;
127 this.featureColours = fr.featureColours;
128 this.transparency = fr.transparency;
129 this.featureOrder = fr.featureOrder;
132 public void transferSettings(FeatureRenderer fr)
134 this.renderOrder = fr.renderOrder;
135 this.featureGroups = fr.featureGroups;
136 this.featureColours = fr.featureColours;
137 this.transparency = fr.transparency;
138 this.featureOrder = fr.featureOrder;
141 BufferedImage offscreenImage;
143 boolean offscreenRender = false;
145 public Color findFeatureColour(Color initialCol, SequenceI seq, int res)
147 return new Color(findFeatureColour(initialCol.getRGB(), seq, res));
151 * This is used by the Molecule Viewer and Overview to get the accurate
152 * colourof the rendered sequence
154 public int findFeatureColour(int initialCol, SequenceI seq, int column)
156 if (!av.showSequenceFeatures)
164 sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures();
165 if (sequenceFeatures != null)
167 sfSize = sequenceFeatures.length;
171 if (sequenceFeatures != lastSeq.getDatasetSequence()
172 .getSequenceFeatures())
174 sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures();
175 if (sequenceFeatures != null)
177 sfSize = sequenceFeatures.length;
181 if (sequenceFeatures == null || sfSize == 0)
186 if (jalview.util.Comparison.isGap(lastSeq.getCharAt(column)))
188 return Color.white.getRGB();
191 // Only bother making an offscreen image if transparency is applied
192 if (transparency != 1.0f && offscreenImage == null)
194 offscreenImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
197 currentColour = null;
199 offscreenRender = true;
201 if (offscreenImage != null)
203 offscreenImage.setRGB(0, 0, initialCol);
204 drawSequence(offscreenImage.getGraphics(), lastSeq, column, column, 0);
206 return offscreenImage.getRGB(0, 0);
210 drawSequence(null, lastSeq, lastSeq.findPosition(column), -1, -1);
212 if (currentColour == null)
218 return ((Integer) currentColour).intValue();
247 // SequenceFeature sf;
250 SequenceFeature[] sequenceFeatures;
252 int sfSize, sfindex, spos, epos;
255 * show scores as heights
257 protected boolean varyHeight = false;
259 synchronized public void drawSequence(Graphics g, SequenceI seq,
260 int start, int end, int y1)
263 if (seq.getDatasetSequence().getSequenceFeatures() == null
264 || seq.getDatasetSequence().getSequenceFeatures().length == 0)
271 fm = g.getFontMetrics();
274 if (av.featuresDisplayed == null || renderOrder == null
278 if (av.featuresDisplayed.size() < 1)
283 sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures();
288 || seq.getDatasetSequence().getSequenceFeatures() != sequenceFeatures)
291 sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures();
294 if (transparency != 1 && g != null)
296 Graphics2D g2 = (Graphics2D) g;
297 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
301 if (!offscreenRender)
303 spos = lastSeq.findPosition(start);
304 epos = lastSeq.findPosition(end);
307 sfSize = sequenceFeatures.length;
309 for (int renderIndex = 0; renderIndex < renderOrder.length; renderIndex++)
311 type = renderOrder[renderIndex];
313 if (type == null || !av.featuresDisplayed.containsKey(type))
318 // loop through all features in sequence to find
319 // current feature to render
320 for (sfindex = 0; sfindex < sfSize; sfindex++)
322 if (!sequenceFeatures[sfindex].type.equals(type))
327 if (featureGroups != null
328 && sequenceFeatures[sfindex].featureGroup != null
329 && sequenceFeatures[sfindex].featureGroup.length() != 0
331 .containsKey(sequenceFeatures[sfindex].featureGroup)
332 && !((Boolean) featureGroups
333 .get(sequenceFeatures[sfindex].featureGroup))
340 && (sequenceFeatures[sfindex].getBegin() > epos || sequenceFeatures[sfindex]
346 if (offscreenRender && offscreenImage == null)
348 if (sequenceFeatures[sfindex].begin <= start
349 && sequenceFeatures[sfindex].end >= start)
351 // this is passed out to the overview and other sequence renderers
352 // (e.g. molecule viewer) to get displayed colour for rendered
354 currentColour = new Integer(
355 getColour(sequenceFeatures[sfindex]).getRGB());
356 // used to be retreived from av.featuresDisplayed
357 // currentColour = av.featuresDisplayed
358 // .get(sequenceFeatures[sfindex].type);
362 else if (sequenceFeatures[sfindex].type.equals("disulfide bond"))
365 renderFeature(g, seq, seq
366 .findIndex(sequenceFeatures[sfindex].begin) - 1, seq
367 .findIndex(sequenceFeatures[sfindex].begin) - 1,
368 getColour(sequenceFeatures[sfindex])
369 // new Color(((Integer) av.featuresDisplayed
370 // .get(sequenceFeatures[sfindex].type)).intValue())
372 renderFeature(g, seq, seq
373 .findIndex(sequenceFeatures[sfindex].end) - 1, seq
374 .findIndex(sequenceFeatures[sfindex].end) - 1,
375 getColour(sequenceFeatures[sfindex])
376 // new Color(((Integer) av.featuresDisplayed
377 // .get(sequenceFeatures[sfindex].type)).intValue())
381 else if (showFeature(sequenceFeatures[sfindex]))
383 if (av.showSeqFeaturesHeight
384 && sequenceFeatures[sfindex].score != Float.NaN)
386 renderScoreFeature(g, seq, seq
387 .findIndex(sequenceFeatures[sfindex].begin) - 1, seq
388 .findIndex(sequenceFeatures[sfindex].end) - 1,
389 getColour(sequenceFeatures[sfindex]), start, end, y1,
390 normaliseScore(sequenceFeatures[sfindex]));
394 renderFeature(g, seq, seq
395 .findIndex(sequenceFeatures[sfindex].begin) - 1, seq
396 .findIndex(sequenceFeatures[sfindex].end) - 1,
397 getColour(sequenceFeatures[sfindex]), start, end, y1);
405 if (transparency != 1.0f && g != null)
407 Graphics2D g2 = (Graphics2D) g;
408 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
413 Hashtable minmax = new Hashtable();
416 * normalise a score against the max/min bounds for the feature type.
418 * @param sequenceFeature
419 * @return byte[] { signed, normalised signed (-127 to 127) or unsigned
422 private final byte[] normaliseScore(SequenceFeature sequenceFeature)
424 float[] mm = ((float[][]) minmax.get(sequenceFeature.type))[0];
425 final byte[] r = new byte[]
429 if (r[0] != 0 || mm[0] < 0.0)
432 r[1] = (byte) ((int) 128.0 + 127.0 * (sequenceFeature.score / mm[1]));
436 r[1] = (byte) ((int) 255.0 * (sequenceFeature.score / mm[1]));
446 void renderFeature(Graphics g, SequenceI seq, int fstart, int fend,
447 Color featureColour, int start, int end, int y1)
450 if (((fstart <= end) && (fend >= start)))
453 { // fix for if the feature we have starts before the sequence start,
454 fstart = start; // but the feature end is still valid!!
461 int pady = (y1 + av.charHeight) - av.charHeight / 5;
462 for (i = fstart; i <= fend; i++)
464 s = seq.getCharAt(i);
466 if (jalview.util.Comparison.isGap(s))
471 g.setColor(featureColour);
473 g.fillRect((i - start) * av.charWidth, y1, av.charWidth,
476 if (offscreenRender || !av.validCharWidth)
481 g.setColor(Color.white);
482 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
483 g.drawString(String.valueOf(s), charOffset
484 + (av.charWidth * (i - start)), pady);
490 void renderScoreFeature(Graphics g, SequenceI seq, int fstart, int fend,
491 Color featureColour, int start, int end, int y1, byte[] bs)
494 if (((fstart <= end) && (fend >= start)))
497 { // fix for if the feature we have starts before the sequence start,
498 fstart = start; // but the feature end is still valid!!
505 int pady = (y1 + av.charHeight) - av.charHeight / 5;
506 int ystrt = 0, yend = av.charHeight;
509 // signed - zero is always middle of residue line.
512 yend = av.charHeight * (128 - bs[1]) / 512;
513 ystrt = av.charHeight - yend / 2;
517 ystrt = av.charHeight / 2;
518 yend = av.charHeight * (bs[1] - 128) / 512;
523 yend = av.charHeight * bs[1] / 255;
524 ystrt = av.charHeight - yend;
527 for (i = fstart; i <= fend; i++)
529 s = seq.getCharAt(i);
531 if (jalview.util.Comparison.isGap(s))
536 g.setColor(featureColour);
537 int x = (i - start) * av.charWidth;
538 g.drawRect(x, y1, av.charWidth, av.charHeight);
539 g.fillRect(x, y1 + ystrt, av.charWidth, yend);
541 if (offscreenRender || !av.validCharWidth)
546 g.setColor(Color.black);
547 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
548 g.drawString(String.valueOf(s), charOffset
549 + (av.charWidth * (i - start)), pady);
555 boolean newFeatureAdded = false;
558 * Called when alignment in associated view has new/modified features to
559 * discover and display.
562 public void featuresAdded()
568 boolean findingFeatures = false;
571 * search the alignment for all new features, give them a colour and display
572 * them. Then fires a PropertyChangeEvent on the changeSupport object.
575 void findAllFeatures()
577 synchronized (firing)
579 if (firing.equals(Boolean.FALSE))
581 firing = Boolean.TRUE;
582 findAllFeatures(true); // add all new features as visible
583 changeSupport.firePropertyChange("changeSupport", null, null);
584 firing = Boolean.FALSE;
590 * Searches alignment for all features and updates colours
592 * @param newMadeVisible
593 * if true newly added feature types will be rendered immediatly
595 synchronized void findAllFeatures(boolean newMadeVisible)
597 newFeatureAdded = false;
601 newFeatureAdded = true;
605 findingFeatures = true;
607 if (av.featuresDisplayed == null)
609 av.featuresDisplayed = new Hashtable();
612 allfeatures = new Vector();
613 Vector oldfeatures = new Vector();
614 if (renderOrder != null)
616 for (int i = 0; i < renderOrder.length; i++)
618 if (renderOrder[i] != null)
620 oldfeatures.addElement(renderOrder[i]);
626 minmax = new Hashtable();
628 for (int i = 0; i < av.alignment.getHeight(); i++)
630 SequenceFeature[] features = av.alignment.getSequenceAt(i)
631 .getDatasetSequence().getSequenceFeatures();
633 if (features == null)
639 while (index < features.length)
641 if (!av.featuresDisplayed.containsKey(features[index].getType()))
644 if (featureGroups.containsKey(features[index].getType()))
646 boolean visible = ((Boolean) featureGroups
647 .get(features[index].featureGroup)).booleanValue();
656 if (!(features[index].begin == 0 && features[index].end == 0))
658 // If beginning and end are 0, the feature is for the whole sequence
659 // and we don't want to render the feature in the normal way
662 && !oldfeatures.contains(features[index].getType()))
664 // this is a new feature type on the alignment. Mark it for
666 av.featuresDisplayed.put(features[index].getType(),
667 new Integer(getColour(features[index].getType())
669 setOrder(features[index].getType(), 0);
673 if (!allfeatures.contains(features[index].getType()))
675 allfeatures.addElement(features[index].getType());
677 if (features[index].score != Float.NaN)
679 int nonpos = features[index].getBegin() >= 1 ? 0 : 1;
680 float[][] mm = (float[][]) minmax.get(features[index].getType());
685 minmax.put(features[index].getType(), mm);
687 if (mm[nonpos] == null)
689 mm[nonpos] = new float[]
690 { features[index].score, features[index].score };
695 if (mm[nonpos][0] > features[index].score)
697 mm[nonpos][0] = features[index].score;
699 if (mm[nonpos][1] < features[index].score)
701 mm[nonpos][1] = features[index].score;
708 updateRenderOrder(allfeatures);
709 findingFeatures = false;
712 protected Boolean firing = Boolean.FALSE;
715 * replaces the current renderOrder with the unordered features in
716 * allfeatures. The ordering of any types in both renderOrder and allfeatures
717 * is preserved, and all new feature types are rendered on top of the existing
718 * types, in the order given by getOrder or the order given in allFeatures.
719 * Note. this operates directly on the featureOrder hash for efficiency. TODO:
720 * eliminate the float storage for computing/recalling the persistent ordering
721 * New Cability: updates min/max for colourscheme range if its dynamic
725 private void updateRenderOrder(Vector allFeatures)
727 Vector allfeatures = new Vector(allFeatures);
728 String[] oldRender = renderOrder;
729 renderOrder = new String[allfeatures.size()];
730 Object mmrange, fc = null;
731 boolean initOrders = (featureOrder == null);
733 if (oldRender != null && oldRender.length > 0)
735 for (int j = 0; j < oldRender.length; j++)
737 if (oldRender[j] != null)
741 setOrder(oldRender[j], (1 - (1 + (float) j)
742 / (float) oldRender.length));
744 if (allfeatures.contains(oldRender[j]))
746 renderOrder[opos++] = oldRender[j]; // existing features always
747 // appear below new features
748 allfeatures.removeElement(oldRender[j]);
751 mmrange = minmax.get(oldRender[j]);
754 fc = featureColours.get(oldRender[j]);
755 if (fc != null && fc instanceof GraduatedColor
756 && ((GraduatedColor) fc).isAutoScale())
758 ((GraduatedColor) fc).updateBounds(
759 ((float[][]) mmrange)[0][0],
760 ((float[][]) mmrange)[0][1]);
768 if (allfeatures.size() == 0)
770 // no new features - leave order unchanged.
773 int i = allfeatures.size() - 1;
775 boolean sort = false;
776 String[] newf = new String[allfeatures.size()];
777 float[] sortOrder = new float[allfeatures.size()];
778 Enumeration en = allfeatures.elements();
779 // sort remaining elements
780 while (en.hasMoreElements())
782 newf[i] = en.nextElement().toString();
785 // update from new features minmax if necessary
786 mmrange = minmax.get(newf[i]);
789 fc = featureColours.get(newf[i]);
790 if (fc != null && fc instanceof GraduatedColor
791 && ((GraduatedColor) fc).isAutoScale())
793 ((GraduatedColor) fc).updateBounds(((float[][]) mmrange)[0][0],
794 ((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);
823 * get a feature style object for the given type string. Creates a
824 * java.awt.Color for a featureType with no existing colourscheme. TODO:
825 * replace return type with object implementing standard abstract colour/style
829 * @return java.awt.Color or GraduatedColor
831 public Object getFeatureStyle(String featureType)
833 Object fc = featureColours.get(featureType);
836 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();
837 Color col = ucs.createColourFromName(featureType);
838 featureColours.put(featureType, fc = col);
844 * return a nominal colour for this feature
847 * @return standard color, or maximum colour for graduated colourscheme
849 public Color getColour(String featureType)
851 Object fc = getFeatureStyle(featureType);
853 if (fc instanceof Color)
859 if (fc instanceof GraduatedColor)
861 return ((GraduatedColor) fc).getMaxColor();
864 throw new Error("Implementation Error: Unrecognised render object "
865 + fc.getClass() + " for features of type " + featureType);
869 * calculate the render colour for a specific feature using current feature
873 * @return render colour for the given feature
875 public Color getColour(SequenceFeature feature)
877 Object fc = getFeatureStyle(feature.getType());
878 if (fc instanceof Color)
884 if (fc instanceof GraduatedColor)
886 return ((GraduatedColor) fc).findColor(feature);
889 throw new Error("Implementation Error: Unrecognised render object "
890 + fc.getClass() + " for features of type " + feature.getType());
893 private boolean showFeature(SequenceFeature sequenceFeature)
895 Object fc = getFeatureStyle(sequenceFeature.type);
896 if (fc instanceof GraduatedColor)
898 return ((GraduatedColor) fc).isColored(sequenceFeature);
907 // // Feature Editing Dialog
908 // // Will be refactored in next release.
910 static String lastFeatureAdded;
912 static String lastFeatureGroupAdded;
914 static String lastDescriptionAdded;
918 int featureIndex = 0;
920 boolean amendFeatures(final SequenceI[] sequences,
921 final SequenceFeature[] features, boolean newFeatures,
922 final AlignmentPanel ap)
927 final JPanel bigPanel = new JPanel(new BorderLayout());
928 final JComboBox overlaps;
929 final JTextField name = new JTextField(25);
930 final JTextField source = new JTextField(25);
931 final JTextArea description = new JTextArea(3, 25);
932 final JSpinner start = new JSpinner();
933 final JSpinner end = new JSpinner();
934 start.setPreferredSize(new Dimension(80, 20));
935 end.setPreferredSize(new Dimension(80, 20));
936 final FeatureRenderer me = this;
937 final JLabel colour = new JLabel();
938 colour.setOpaque(true);
939 // colour.setBorder(BorderFactory.createEtchedBorder());
940 colour.setMaximumSize(new Dimension(30, 16));
941 colour.addMouseListener(new MouseAdapter()
943 FeatureColourChooser fcc = null;
945 public void mousePressed(MouseEvent evt)
947 if (fcol instanceof Color)
949 Color col = JColorChooser.showDialog(Desktop.desktop,
950 "Select Feature Colour", ((Color) fcol));
954 updateColourButton(bigPanel, colour, col);
962 final String type = features[featureIndex].getType();
963 fcc = new FeatureColourChooser(me, type);
964 fcc.setRequestFocusEnabled(true);
967 fcc.addActionListener(new ActionListener()
970 public void actionPerformed(ActionEvent e)
972 fcol = fcc.getLastColour();
974 setColour(type, fcol);
975 updateColourButton(bigPanel, colour, fcol);
983 JPanel tmp = new JPanel();
984 JPanel panel = new JPanel(new GridLayout(3, 1));
986 // /////////////////////////////////////
987 // /MULTIPLE FEATURES AT SELECTED RESIDUE
988 if (!newFeatures && features.length > 1)
990 panel = new JPanel(new GridLayout(4, 1));
992 tmp.add(new JLabel("Select Feature: "));
993 overlaps = new JComboBox();
994 for (int i = 0; i < features.length; i++)
996 overlaps.addItem(features[i].getType() + "/"
997 + features[i].getBegin() + "-" + features[i].getEnd()
998 + " (" + features[i].getFeatureGroup() + ")");
1003 overlaps.addItemListener(new ItemListener()
1005 public void itemStateChanged(ItemEvent e)
1007 int index = overlaps.getSelectedIndex();
1010 featureIndex = index;
1011 name.setText(features[index].getType());
1012 description.setText(features[index].getDescription());
1013 source.setText(features[index].getFeatureGroup());
1014 start.setValue(new Integer(features[index].getBegin()));
1015 end.setValue(new Integer(features[index].getEnd()));
1017 SearchResults highlight = new SearchResults();
1018 highlight.addResult(sequences[0], features[index].getBegin(),
1019 features[index].getEnd());
1021 ap.seqPanel.seqCanvas.highlightSearchResults(highlight);
1024 Object col = getFeatureStyle(name.getText());
1027 col = new jalview.schemes.UserColourScheme()
1028 .createColourFromName(name.getText());
1030 oldcol = fcol = col;
1031 updateColourButton(bigPanel, colour, col);
1038 // ////////////////////////////////////
1042 tmp.add(new JLabel("Name: ", JLabel.RIGHT));
1047 tmp.add(new JLabel("Group: ", JLabel.RIGHT));
1052 tmp.add(new JLabel("Colour: ", JLabel.RIGHT));
1054 colour.setPreferredSize(new Dimension(150, 15));
1055 colour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 9));
1056 colour.setForeground(Color.black);
1057 colour.setHorizontalAlignment(SwingConstants.CENTER);
1058 colour.setVerticalAlignment(SwingConstants.CENTER);
1059 colour.setHorizontalTextPosition(SwingConstants.CENTER);
1060 colour.setVerticalTextPosition(SwingConstants.CENTER);
1061 bigPanel.add(panel, BorderLayout.NORTH);
1063 panel = new JPanel();
1064 panel.add(new JLabel("Description: ", JLabel.RIGHT));
1065 description.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
1066 description.setLineWrap(true);
1067 panel.add(new JScrollPane(description));
1071 bigPanel.add(panel, BorderLayout.SOUTH);
1073 panel = new JPanel();
1074 panel.add(new JLabel(" Start:", JLabel.RIGHT));
1076 panel.add(new JLabel(" End:", JLabel.RIGHT));
1078 bigPanel.add(panel, BorderLayout.CENTER);
1082 bigPanel.add(panel, BorderLayout.CENTER);
1085 if (lastFeatureAdded == null)
1087 if (features[0].type != null)
1089 lastFeatureAdded = features[0].type;
1093 lastFeatureAdded = "feature_1";
1097 if (lastFeatureGroupAdded == null)
1099 if (features[0].featureGroup != null)
1101 lastFeatureGroupAdded = features[0].featureGroup;
1105 lastFeatureGroupAdded = "Jalview";
1111 name.setText(lastFeatureAdded);
1112 source.setText(lastFeatureGroupAdded);
1116 name.setText(features[0].getType());
1117 source.setText(features[0].getFeatureGroup());
1120 start.setValue(new Integer(features[0].getBegin()));
1121 end.setValue(new Integer(features[0].getEnd()));
1122 description.setText(features[0].getDescription());
1123 updateColourButton(bigPanel, colour,
1124 (oldcol = fcol = getFeatureStyle(name.getText())));
1128 options = new Object[]
1129 { "Amend", "Delete", "Cancel" };
1133 options = new Object[]
1137 String title = newFeatures ? "Create New Sequence Feature(s)"
1138 : "Amend/Delete Features for " + sequences[0].getName();
1140 int reply = JOptionPane.showInternalOptionDialog(Desktop.desktop,
1141 bigPanel, title, JOptionPane.YES_NO_CANCEL_OPTION,
1142 JOptionPane.QUESTION_MESSAGE, null, options, "OK");
1144 jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile();
1146 if (reply == JOptionPane.OK_OPTION && name.getText().length() > 0)
1148 // This ensures that the last sequence
1149 // is refreshed and new features are rendered
1151 lastFeatureAdded = name.getText().trim();
1152 lastFeatureGroupAdded = source.getText().trim();
1153 lastDescriptionAdded = description.getText().replaceAll("\n", " ");
1154 // TODO: determine if the null feature group is valid
1155 if (lastFeatureGroupAdded.length() < 1)
1156 lastFeatureGroupAdded = null;
1161 SequenceFeature sf = features[featureIndex];
1163 if (reply == JOptionPane.NO_OPTION)
1165 sequences[0].getDatasetSequence().deleteFeature(sf);
1167 else if (reply == JOptionPane.YES_OPTION)
1169 sf.type = lastFeatureAdded;
1170 sf.featureGroup = lastFeatureGroupAdded;
1171 sf.description = lastDescriptionAdded;
1173 setColour(sf.type, fcol);
1174 av.featuresDisplayed.put(sf.type, getColour(sf.type));
1178 sf.begin = ((Integer) start.getValue()).intValue();
1179 sf.end = ((Integer) end.getValue()).intValue();
1180 } catch (NumberFormatException ex)
1184 ffile.parseDescriptionHTML(sf, false);
1188 // NEW FEATURES ADDED
1190 if (reply == JOptionPane.OK_OPTION && lastFeatureAdded.length() > 0)
1192 for (int i = 0; i < sequences.length; i++)
1194 features[i].type = lastFeatureAdded;
1195 if (lastFeatureGroupAdded != null)
1196 features[i].featureGroup = lastFeatureGroupAdded;
1197 features[i].description = lastDescriptionAdded;
1198 sequences[i].addSequenceFeature(features[i]);
1199 ffile.parseDescriptionHTML(features[i], false);
1202 if (av.featuresDisplayed == null)
1204 av.featuresDisplayed = new Hashtable();
1207 if (lastFeatureGroupAdded != null)
1209 if (featureGroups == null)
1210 featureGroups = new Hashtable();
1211 featureGroups.put(lastFeatureGroupAdded, new Boolean(true));
1213 setColour(lastFeatureAdded, fcol);
1214 av.featuresDisplayed.put(lastFeatureAdded,
1215 getColour(lastFeatureAdded));
1217 findAllFeatures(false);
1219 ap.paintAlignment(true);
1229 ap.paintAlignment(true);
1235 * update the amend feature button dependent on the given style
1241 protected void updateColourButton(JPanel bigPanel, JLabel colour,
1245 colour.setIcon(null);
1246 colour.setToolTipText(null);
1249 if (col2 instanceof Color)
1251 colour.setBackground((Color) col2);
1255 colour.setBackground(bigPanel.getBackground());
1256 colour.setForeground(Color.black);
1257 FeatureSettings.renderGraduatedColor(colour, (GraduatedColor) col2);
1258 // colour.setForeground(colour.getBackground());
1262 public void setColour(String featureType, Object col)
1265 // Color _col = (col instanceof Color) ? ((Color) col) : (col instanceof
1266 // GraduatedColor) ? ((GraduatedColor) col).getMaxColor() : null;
1267 // Object c = featureColours.get(featureType);
1268 // if (c == null || c instanceof Color || (c instanceof GraduatedColor &&
1269 // !((GraduatedColor)c).getMaxColor().equals(_col)))
1271 featureColours.put(featureType, col);
1275 public void setTransparency(float value)
1277 transparency = value;
1280 public float getTransparency()
1282 return transparency;
1286 * Replace current ordering with new ordering
1289 * { String(Type), Colour(Type), Boolean(Displayed) }
1291 public void setFeaturePriority(Object[][] data)
1293 setFeaturePriority(data, true);
1299 * { String(Type), Colour(Type), Boolean(Displayed) }
1301 * when true current featureDisplay list will be cleared
1303 public void setFeaturePriority(Object[][] data, boolean visibleNew)
1307 if (av.featuresDisplayed != null)
1309 av.featuresDisplayed.clear();
1313 av.featuresDisplayed = new Hashtable();
1321 // The feature table will display high priority
1322 // features at the top, but theses are the ones
1323 // we need to render last, so invert the data
1324 renderOrder = new String[data.length];
1326 if (data.length > 0)
1328 for (int i = 0; i < data.length; i++)
1330 String type = data[i][0].toString();
1331 setColour(type, data[i][1]); // todo : typesafety - feature color
1333 if (((Boolean) data[i][2]).booleanValue())
1335 av.featuresDisplayed.put(type, new Integer(getColour(type)
1339 renderOrder[data.length - i - 1] = type;
1345 Hashtable featureOrder = null;
1348 * analogous to colour - store a normalized ordering for all feature types in
1349 * this rendering context.
1352 * Feature type string
1354 * normalized priority - 0 means always appears on top, 1 means
1357 public float setOrder(String type, float position)
1359 if (featureOrder == null)
1361 featureOrder = new Hashtable();
1363 featureOrder.put(type, new Float(position));
1368 * get the global priority (0 (top) to 1 (bottom))
1371 * @return [0,1] or -1 for a type without a priority
1373 public float getOrder(String type)
1375 if (featureOrder != null)
1377 if (featureOrder.containsKey(type))
1379 return ((Float) featureOrder.get(type)).floatValue();
1387 * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener)
1389 public void addPropertyChangeListener(PropertyChangeListener listener)
1391 changeSupport.addPropertyChangeListener(listener);
1396 * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.beans.PropertyChangeListener)
1398 public void removePropertyChangeListener(PropertyChangeListener listener)
1400 changeSupport.removePropertyChangeListener(listener);