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 implements jalview.api.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;
109 * create an independent instance of the feature renderer settings
113 public FeatureRendererSettings(FeatureRenderer fr)
116 featureGroups = new Hashtable();
117 featureColours = new Hashtable();
118 featureOrder = new Hashtable();
119 if (fr.renderOrder != null)
121 this.renderOrder = new String[fr.renderOrder.length];
122 System.arraycopy(fr.renderOrder, 0, renderOrder, 0,
125 if (fr.featureGroups != null)
127 this.featureGroups = new Hashtable(fr.featureGroups);
129 if (fr.featureColours != null)
131 this.featureColours = new Hashtable(fr.featureColours);
133 Enumeration en = fr.featureColours.keys();
134 while (en.hasMoreElements())
136 Object next = en.nextElement();
137 Object val = featureColours.get(next);
138 if (val instanceof GraduatedColor)
141 .put(next, new GraduatedColor((GraduatedColor) val));
144 this.transparency = fr.transparency;
145 if (fr.featureOrder != null)
147 this.featureOrder = new Hashtable(fr.featureOrder);
152 public FeatureRendererSettings getSettings()
154 return new FeatureRendererSettings(this);
157 public void transferSettings(FeatureRendererSettings fr)
159 this.renderOrder = fr.renderOrder;
160 this.featureGroups = fr.featureGroups;
161 this.featureColours = fr.featureColours;
162 this.transparency = fr.transparency;
163 this.featureOrder = fr.featureOrder;
166 public void transferSettings(FeatureRenderer fr)
168 this.renderOrder = fr.renderOrder;
169 this.featureGroups = fr.featureGroups;
170 this.featureColours = fr.featureColours;
171 this.transparency = fr.transparency;
172 this.featureOrder = fr.featureOrder;
175 BufferedImage offscreenImage;
177 boolean offscreenRender = false;
179 public Color findFeatureColour(Color initialCol, SequenceI seq, int res)
181 return new Color(findFeatureColour(initialCol.getRGB(), seq, res));
185 * This is used by the Molecule Viewer and Overview to get the accurate
186 * colourof the rendered sequence
188 public int findFeatureColour(int initialCol, SequenceI seq, int column)
190 if (!av.showSequenceFeatures)
198 sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures();
199 if (sequenceFeatures != null)
201 sfSize = sequenceFeatures.length;
205 if (sequenceFeatures != lastSeq.getDatasetSequence()
206 .getSequenceFeatures())
208 sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures();
209 if (sequenceFeatures != null)
211 sfSize = sequenceFeatures.length;
215 if (sequenceFeatures == null || sfSize == 0)
220 if (jalview.util.Comparison.isGap(lastSeq.getCharAt(column)))
222 return Color.white.getRGB();
225 // Only bother making an offscreen image if transparency is applied
226 if (transparency != 1.0f && offscreenImage == null)
228 offscreenImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
231 currentColour = null;
233 offscreenRender = true;
235 if (offscreenImage != null)
237 offscreenImage.setRGB(0, 0, initialCol);
238 drawSequence(offscreenImage.getGraphics(), lastSeq, column, column, 0);
240 return offscreenImage.getRGB(0, 0);
244 drawSequence(null, lastSeq, lastSeq.findPosition(column), -1, -1);
246 if (currentColour == null)
252 return ((Integer) currentColour).intValue();
281 // SequenceFeature sf;
284 SequenceFeature[] sequenceFeatures;
286 int sfSize, sfindex, spos, epos;
289 * show scores as heights
291 protected boolean varyHeight = false;
293 synchronized public void drawSequence(Graphics g, SequenceI seq,
294 int start, int end, int y1)
297 if (seq.getDatasetSequence().getSequenceFeatures() == null
298 || seq.getDatasetSequence().getSequenceFeatures().length == 0)
305 fm = g.getFontMetrics();
308 if (av.featuresDisplayed == null || renderOrder == null
312 if (av.featuresDisplayed.size() < 1)
317 sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures();
322 || seq.getDatasetSequence().getSequenceFeatures() != sequenceFeatures)
325 sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures();
328 if (transparency != 1 && g != null)
330 Graphics2D g2 = (Graphics2D) g;
331 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
335 if (!offscreenRender)
337 spos = lastSeq.findPosition(start);
338 epos = lastSeq.findPosition(end);
341 sfSize = sequenceFeatures.length;
343 for (int renderIndex = 0; renderIndex < renderOrder.length; renderIndex++)
345 type = renderOrder[renderIndex];
347 if (type == null || !av.featuresDisplayed.containsKey(type))
352 // loop through all features in sequence to find
353 // current feature to render
354 for (sfindex = 0; sfindex < sfSize; sfindex++)
356 if (!sequenceFeatures[sfindex].type.equals(type))
361 if (featureGroups != null
362 && sequenceFeatures[sfindex].featureGroup != null
363 && sequenceFeatures[sfindex].featureGroup.length() != 0
365 .containsKey(sequenceFeatures[sfindex].featureGroup)
366 && !((Boolean) featureGroups
367 .get(sequenceFeatures[sfindex].featureGroup))
374 && (sequenceFeatures[sfindex].getBegin() > epos || sequenceFeatures[sfindex]
380 if (offscreenRender && offscreenImage == null)
382 if (sequenceFeatures[sfindex].begin <= start
383 && sequenceFeatures[sfindex].end >= start)
385 // this is passed out to the overview and other sequence renderers
386 // (e.g. molecule viewer) to get displayed colour for rendered
388 currentColour = new Integer(
389 getColour(sequenceFeatures[sfindex]).getRGB());
390 // used to be retreived from av.featuresDisplayed
391 // currentColour = av.featuresDisplayed
392 // .get(sequenceFeatures[sfindex].type);
396 else if (sequenceFeatures[sfindex].type.equals("disulfide bond"))
399 renderFeature(g, seq, seq
400 .findIndex(sequenceFeatures[sfindex].begin) - 1, seq
401 .findIndex(sequenceFeatures[sfindex].begin) - 1,
402 getColour(sequenceFeatures[sfindex])
403 // new Color(((Integer) av.featuresDisplayed
404 // .get(sequenceFeatures[sfindex].type)).intValue())
406 renderFeature(g, seq, seq
407 .findIndex(sequenceFeatures[sfindex].end) - 1, seq
408 .findIndex(sequenceFeatures[sfindex].end) - 1,
409 getColour(sequenceFeatures[sfindex])
410 // new Color(((Integer) av.featuresDisplayed
411 // .get(sequenceFeatures[sfindex].type)).intValue())
415 else if (showFeature(sequenceFeatures[sfindex]))
417 if (av.showSeqFeaturesHeight
418 && sequenceFeatures[sfindex].score != Float.NaN)
420 renderScoreFeature(g, seq, seq
421 .findIndex(sequenceFeatures[sfindex].begin) - 1, seq
422 .findIndex(sequenceFeatures[sfindex].end) - 1,
423 getColour(sequenceFeatures[sfindex]), start, end, y1,
424 normaliseScore(sequenceFeatures[sfindex]));
428 renderFeature(g, seq, seq
429 .findIndex(sequenceFeatures[sfindex].begin) - 1, seq
430 .findIndex(sequenceFeatures[sfindex].end) - 1,
431 getColour(sequenceFeatures[sfindex]), start, end, y1);
439 if (transparency != 1.0f && g != null)
441 Graphics2D g2 = (Graphics2D) g;
442 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
447 Hashtable minmax = new Hashtable();
450 * normalise a score against the max/min bounds for the feature type.
452 * @param sequenceFeature
453 * @return byte[] { signed, normalised signed (-127 to 127) or unsigned
456 private final byte[] normaliseScore(SequenceFeature sequenceFeature)
458 float[] mm = ((float[][]) minmax.get(sequenceFeature.type))[0];
459 final byte[] r = new byte[]
463 if (r[0] != 0 || mm[0] < 0.0)
466 r[1] = (byte) ((int) 128.0 + 127.0 * (sequenceFeature.score / mm[1]));
470 r[1] = (byte) ((int) 255.0 * (sequenceFeature.score / mm[1]));
480 void renderFeature(Graphics g, SequenceI seq, int fstart, int fend,
481 Color featureColour, int start, int end, int y1)
484 if (((fstart <= end) && (fend >= start)))
487 { // fix for if the feature we have starts before the sequence start,
488 fstart = start; // but the feature end is still valid!!
495 int pady = (y1 + av.charHeight) - av.charHeight / 5;
496 for (i = fstart; i <= fend; i++)
498 s = seq.getCharAt(i);
500 if (jalview.util.Comparison.isGap(s))
505 g.setColor(featureColour);
507 g.fillRect((i - start) * av.charWidth, y1, av.charWidth,
510 if (offscreenRender || !av.validCharWidth)
515 g.setColor(Color.white);
516 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
517 g.drawString(String.valueOf(s), charOffset
518 + (av.charWidth * (i - start)), pady);
524 void renderScoreFeature(Graphics g, SequenceI seq, int fstart, int fend,
525 Color featureColour, int start, int end, int y1, byte[] bs)
528 if (((fstart <= end) && (fend >= start)))
531 { // fix for if the feature we have starts before the sequence start,
532 fstart = start; // but the feature end is still valid!!
539 int pady = (y1 + av.charHeight) - av.charHeight / 5;
540 int ystrt = 0, yend = av.charHeight;
543 // signed - zero is always middle of residue line.
546 yend = av.charHeight * (128 - bs[1]) / 512;
547 ystrt = av.charHeight - yend / 2;
551 ystrt = av.charHeight / 2;
552 yend = av.charHeight * (bs[1] - 128) / 512;
557 yend = av.charHeight * bs[1] / 255;
558 ystrt = av.charHeight - yend;
561 for (i = fstart; i <= fend; i++)
563 s = seq.getCharAt(i);
565 if (jalview.util.Comparison.isGap(s))
570 g.setColor(featureColour);
571 int x = (i - start) * av.charWidth;
572 g.drawRect(x, y1, av.charWidth, av.charHeight);
573 g.fillRect(x, y1 + ystrt, av.charWidth, yend);
575 if (offscreenRender || !av.validCharWidth)
580 g.setColor(Color.black);
581 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
582 g.drawString(String.valueOf(s), charOffset
583 + (av.charWidth * (i - start)), pady);
589 boolean newFeatureAdded = false;
592 * Called when alignment in associated view has new/modified features to
593 * discover and display.
596 public void featuresAdded()
602 boolean findingFeatures = false;
605 * search the alignment for all new features, give them a colour and display
606 * them. Then fires a PropertyChangeEvent on the changeSupport object.
609 void findAllFeatures()
611 synchronized (firing)
613 if (firing.equals(Boolean.FALSE))
615 firing = Boolean.TRUE;
616 findAllFeatures(true); // add all new features as visible
617 changeSupport.firePropertyChange("changeSupport", null, null);
618 firing = Boolean.FALSE;
624 * Searches alignment for all features and updates colours
626 * @param newMadeVisible
627 * if true newly added feature types will be rendered immediatly
629 synchronized void findAllFeatures(boolean newMadeVisible)
631 newFeatureAdded = false;
635 newFeatureAdded = true;
639 findingFeatures = true;
641 if (av.featuresDisplayed == null)
643 av.featuresDisplayed = new Hashtable();
646 allfeatures = new Vector();
647 Vector oldfeatures = new Vector();
648 if (renderOrder != null)
650 for (int i = 0; i < renderOrder.length; i++)
652 if (renderOrder[i] != null)
654 oldfeatures.addElement(renderOrder[i]);
660 minmax = new Hashtable();
662 for (int i = 0; i < av.alignment.getHeight(); i++)
664 SequenceFeature[] features = av.alignment.getSequenceAt(i)
665 .getDatasetSequence().getSequenceFeatures();
667 if (features == null)
673 while (index < features.length)
675 if (!av.featuresDisplayed.containsKey(features[index].getType()))
678 if (featureGroups.containsKey(features[index].getType()))
680 boolean visible = ((Boolean) featureGroups
681 .get(features[index].featureGroup)).booleanValue();
690 if (!(features[index].begin == 0 && features[index].end == 0))
692 // If beginning and end are 0, the feature is for the whole sequence
693 // and we don't want to render the feature in the normal way
696 && !oldfeatures.contains(features[index].getType()))
698 // this is a new feature type on the alignment. Mark it for
700 av.featuresDisplayed.put(features[index].getType(),
701 new Integer(getColour(features[index].getType())
703 setOrder(features[index].getType(), 0);
707 if (!allfeatures.contains(features[index].getType()))
709 allfeatures.addElement(features[index].getType());
711 if (features[index].score != Float.NaN)
713 int nonpos = features[index].getBegin() >= 1 ? 0 : 1;
714 float[][] mm = (float[][]) minmax.get(features[index].getType());
719 minmax.put(features[index].getType(), mm);
721 if (mm[nonpos] == null)
723 mm[nonpos] = new float[]
724 { features[index].score, features[index].score };
729 if (mm[nonpos][0] > features[index].score)
731 mm[nonpos][0] = features[index].score;
733 if (mm[nonpos][1] < features[index].score)
735 mm[nonpos][1] = features[index].score;
742 updateRenderOrder(allfeatures);
743 findingFeatures = false;
746 protected Boolean firing = Boolean.FALSE;
749 * replaces the current renderOrder with the unordered features in
750 * allfeatures. The ordering of any types in both renderOrder and allfeatures
751 * is preserved, and all new feature types are rendered on top of the existing
752 * types, in the order given by getOrder or the order given in allFeatures.
753 * Note. this operates directly on the featureOrder hash for efficiency. TODO:
754 * eliminate the float storage for computing/recalling the persistent ordering
755 * New Cability: updates min/max for colourscheme range if its dynamic
759 private void updateRenderOrder(Vector allFeatures)
761 Vector allfeatures = new Vector(allFeatures);
762 String[] oldRender = renderOrder;
763 renderOrder = new String[allfeatures.size()];
764 Object mmrange, fc = null;
765 boolean initOrders = (featureOrder == null);
767 if (oldRender != null && oldRender.length > 0)
769 for (int j = 0; j < oldRender.length; j++)
771 if (oldRender[j] != null)
775 setOrder(oldRender[j], (1 - (1 + (float) j)
776 / (float) oldRender.length));
778 if (allfeatures.contains(oldRender[j]))
780 renderOrder[opos++] = oldRender[j]; // existing features always
781 // appear below new features
782 allfeatures.removeElement(oldRender[j]);
785 mmrange = minmax.get(oldRender[j]);
788 fc = featureColours.get(oldRender[j]);
789 if (fc != null && fc instanceof GraduatedColor
790 && ((GraduatedColor) fc).isAutoScale())
792 ((GraduatedColor) fc).updateBounds(
793 ((float[][]) mmrange)[0][0],
794 ((float[][]) mmrange)[0][1]);
802 if (allfeatures.size() == 0)
804 // no new features - leave order unchanged.
807 int i = allfeatures.size() - 1;
809 boolean sort = false;
810 String[] newf = new String[allfeatures.size()];
811 float[] sortOrder = new float[allfeatures.size()];
812 Enumeration en = allfeatures.elements();
813 // sort remaining elements
814 while (en.hasMoreElements())
816 newf[i] = en.nextElement().toString();
819 // update from new features minmax if necessary
820 mmrange = minmax.get(newf[i]);
823 fc = featureColours.get(newf[i]);
824 if (fc != null && fc instanceof GraduatedColor
825 && ((GraduatedColor) fc).isAutoScale())
827 ((GraduatedColor) fc).updateBounds(((float[][]) mmrange)[0][0],
828 ((float[][]) mmrange)[0][1]);
832 if (initOrders || !featureOrder.containsKey(newf[i]))
834 int denom = initOrders ? allfeatures.size() : featureOrder.size();
835 // new unordered feature - compute persistent ordering at head of
836 // existing features.
837 setOrder(newf[i], i / (float) denom);
839 // set order from newly found feature from persisted ordering.
840 sortOrder[i] = 2 - ((Float) featureOrder.get(newf[i])).floatValue();
843 // only sort if we need to
844 sort = sort || sortOrder[i] > sortOrder[i + 1];
848 if (iSize > 1 && sort)
850 jalview.util.QuickSort.sort(sortOrder, newf);
853 System.arraycopy(newf, 0, renderOrder, opos, newf.length);
857 * get a feature style object for the given type string. Creates a
858 * java.awt.Color for a featureType with no existing colourscheme. TODO:
859 * replace return type with object implementing standard abstract colour/style
863 * @return java.awt.Color or GraduatedColor
865 public Object getFeatureStyle(String featureType)
867 Object fc = featureColours.get(featureType);
870 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();
871 Color col = ucs.createColourFromName(featureType);
872 featureColours.put(featureType, fc = col);
878 * return a nominal colour for this feature
881 * @return standard color, or maximum colour for graduated colourscheme
883 public Color getColour(String featureType)
885 Object fc = getFeatureStyle(featureType);
887 if (fc instanceof Color)
893 if (fc instanceof GraduatedColor)
895 return ((GraduatedColor) fc).getMaxColor();
898 throw new Error("Implementation Error: Unrecognised render object "
899 + fc.getClass() + " for features of type " + featureType);
903 * calculate the render colour for a specific feature using current feature
907 * @return render colour for the given feature
909 public Color getColour(SequenceFeature feature)
911 Object fc = getFeatureStyle(feature.getType());
912 if (fc instanceof Color)
918 if (fc instanceof GraduatedColor)
920 return ((GraduatedColor) fc).findColor(feature);
923 throw new Error("Implementation Error: Unrecognised render object "
924 + fc.getClass() + " for features of type " + feature.getType());
927 private boolean showFeature(SequenceFeature sequenceFeature)
929 Object fc = getFeatureStyle(sequenceFeature.type);
930 if (fc instanceof GraduatedColor)
932 return ((GraduatedColor) fc).isColored(sequenceFeature);
941 // // Feature Editing Dialog
942 // // Will be refactored in next release.
944 static String lastFeatureAdded;
946 static String lastFeatureGroupAdded;
948 static String lastDescriptionAdded;
952 int featureIndex = 0;
954 boolean amendFeatures(final SequenceI[] sequences,
955 final SequenceFeature[] features, boolean newFeatures,
956 final AlignmentPanel ap)
961 final JPanel bigPanel = new JPanel(new BorderLayout());
962 final JComboBox overlaps;
963 final JTextField name = new JTextField(25);
964 final JTextField source = new JTextField(25);
965 final JTextArea description = new JTextArea(3, 25);
966 final JSpinner start = new JSpinner();
967 final JSpinner end = new JSpinner();
968 start.setPreferredSize(new Dimension(80, 20));
969 end.setPreferredSize(new Dimension(80, 20));
970 final FeatureRenderer me = this;
971 final JLabel colour = new JLabel();
972 colour.setOpaque(true);
973 // colour.setBorder(BorderFactory.createEtchedBorder());
974 colour.setMaximumSize(new Dimension(30, 16));
975 colour.addMouseListener(new MouseAdapter()
977 FeatureColourChooser fcc = null;
979 public void mousePressed(MouseEvent evt)
981 if (fcol instanceof Color)
983 Color col = JColorChooser.showDialog(Desktop.desktop,
984 "Select Feature Colour", ((Color) fcol));
988 updateColourButton(bigPanel, colour, col);
996 final String type = features[featureIndex].getType();
997 fcc = new FeatureColourChooser(me, type);
998 fcc.setRequestFocusEnabled(true);
1001 fcc.addActionListener(new ActionListener()
1004 public void actionPerformed(ActionEvent e)
1006 fcol = fcc.getLastColour();
1008 setColour(type, fcol);
1009 updateColourButton(bigPanel, colour, fcol);
1017 JPanel tmp = new JPanel();
1018 JPanel panel = new JPanel(new GridLayout(3, 1));
1020 // /////////////////////////////////////
1021 // /MULTIPLE FEATURES AT SELECTED RESIDUE
1022 if (!newFeatures && features.length > 1)
1024 panel = new JPanel(new GridLayout(4, 1));
1026 tmp.add(new JLabel("Select Feature: "));
1027 overlaps = new JComboBox();
1028 for (int i = 0; i < features.length; i++)
1030 overlaps.addItem(features[i].getType() + "/"
1031 + features[i].getBegin() + "-" + features[i].getEnd()
1032 + " (" + features[i].getFeatureGroup() + ")");
1037 overlaps.addItemListener(new ItemListener()
1039 public void itemStateChanged(ItemEvent e)
1041 int index = overlaps.getSelectedIndex();
1044 featureIndex = index;
1045 name.setText(features[index].getType());
1046 description.setText(features[index].getDescription());
1047 source.setText(features[index].getFeatureGroup());
1048 start.setValue(new Integer(features[index].getBegin()));
1049 end.setValue(new Integer(features[index].getEnd()));
1051 SearchResults highlight = new SearchResults();
1052 highlight.addResult(sequences[0], features[index].getBegin(),
1053 features[index].getEnd());
1055 ap.seqPanel.seqCanvas.highlightSearchResults(highlight);
1058 Object col = getFeatureStyle(name.getText());
1061 col = new jalview.schemes.UserColourScheme()
1062 .createColourFromName(name.getText());
1064 oldcol = fcol = col;
1065 updateColourButton(bigPanel, colour, col);
1072 // ////////////////////////////////////
1076 tmp.add(new JLabel("Name: ", JLabel.RIGHT));
1081 tmp.add(new JLabel("Group: ", JLabel.RIGHT));
1086 tmp.add(new JLabel("Colour: ", JLabel.RIGHT));
1088 colour.setPreferredSize(new Dimension(150, 15));
1089 colour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 9));
1090 colour.setForeground(Color.black);
1091 colour.setHorizontalAlignment(SwingConstants.CENTER);
1092 colour.setVerticalAlignment(SwingConstants.CENTER);
1093 colour.setHorizontalTextPosition(SwingConstants.CENTER);
1094 colour.setVerticalTextPosition(SwingConstants.CENTER);
1095 bigPanel.add(panel, BorderLayout.NORTH);
1097 panel = new JPanel();
1098 panel.add(new JLabel("Description: ", JLabel.RIGHT));
1099 description.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
1100 description.setLineWrap(true);
1101 panel.add(new JScrollPane(description));
1105 bigPanel.add(panel, BorderLayout.SOUTH);
1107 panel = new JPanel();
1108 panel.add(new JLabel(" Start:", JLabel.RIGHT));
1110 panel.add(new JLabel(" End:", JLabel.RIGHT));
1112 bigPanel.add(panel, BorderLayout.CENTER);
1116 bigPanel.add(panel, BorderLayout.CENTER);
1119 if (lastFeatureAdded == null)
1121 if (features[0].type != null)
1123 lastFeatureAdded = features[0].type;
1127 lastFeatureAdded = "feature_1";
1131 if (lastFeatureGroupAdded == null)
1133 if (features[0].featureGroup != null)
1135 lastFeatureGroupAdded = features[0].featureGroup;
1139 lastFeatureGroupAdded = "Jalview";
1145 name.setText(lastFeatureAdded);
1146 source.setText(lastFeatureGroupAdded);
1150 name.setText(features[0].getType());
1151 source.setText(features[0].getFeatureGroup());
1154 start.setValue(new Integer(features[0].getBegin()));
1155 end.setValue(new Integer(features[0].getEnd()));
1156 description.setText(features[0].getDescription());
1157 updateColourButton(bigPanel, colour,
1158 (oldcol = fcol = getFeatureStyle(name.getText())));
1162 options = new Object[]
1163 { "Amend", "Delete", "Cancel" };
1167 options = new Object[]
1171 String title = newFeatures ? "Create New Sequence Feature(s)"
1172 : "Amend/Delete Features for " + sequences[0].getName();
1174 int reply = JOptionPane.showInternalOptionDialog(Desktop.desktop,
1175 bigPanel, title, JOptionPane.YES_NO_CANCEL_OPTION,
1176 JOptionPane.QUESTION_MESSAGE, null, options, "OK");
1178 jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile();
1180 if (reply == JOptionPane.OK_OPTION && name.getText().length() > 0)
1182 // This ensures that the last sequence
1183 // is refreshed and new features are rendered
1185 lastFeatureAdded = name.getText().trim();
1186 lastFeatureGroupAdded = source.getText().trim();
1187 lastDescriptionAdded = description.getText().replaceAll("\n", " ");
1188 // TODO: determine if the null feature group is valid
1189 if (lastFeatureGroupAdded.length() < 1)
1190 lastFeatureGroupAdded = null;
1195 SequenceFeature sf = features[featureIndex];
1197 if (reply == JOptionPane.NO_OPTION)
1199 sequences[0].getDatasetSequence().deleteFeature(sf);
1201 else if (reply == JOptionPane.YES_OPTION)
1203 sf.type = lastFeatureAdded;
1204 sf.featureGroup = lastFeatureGroupAdded;
1205 sf.description = lastDescriptionAdded;
1207 setColour(sf.type, fcol);
1208 av.featuresDisplayed.put(sf.type, getColour(sf.type));
1212 sf.begin = ((Integer) start.getValue()).intValue();
1213 sf.end = ((Integer) end.getValue()).intValue();
1214 } catch (NumberFormatException ex)
1218 ffile.parseDescriptionHTML(sf, false);
1222 // NEW FEATURES ADDED
1224 if (reply == JOptionPane.OK_OPTION && lastFeatureAdded.length() > 0)
1226 for (int i = 0; i < sequences.length; i++)
1228 features[i].type = lastFeatureAdded;
1229 if (lastFeatureGroupAdded != null)
1230 features[i].featureGroup = lastFeatureGroupAdded;
1231 features[i].description = lastDescriptionAdded;
1232 sequences[i].addSequenceFeature(features[i]);
1233 ffile.parseDescriptionHTML(features[i], false);
1236 if (av.featuresDisplayed == null)
1238 av.featuresDisplayed = new Hashtable();
1241 if (lastFeatureGroupAdded != null)
1243 if (featureGroups == null)
1244 featureGroups = new Hashtable();
1245 featureGroups.put(lastFeatureGroupAdded, new Boolean(true));
1247 setColour(lastFeatureAdded, fcol);
1248 av.featuresDisplayed.put(lastFeatureAdded,
1249 getColour(lastFeatureAdded));
1251 findAllFeatures(false);
1253 ap.paintAlignment(true);
1263 ap.paintAlignment(true);
1269 * update the amend feature button dependent on the given style
1275 protected void updateColourButton(JPanel bigPanel, JLabel colour,
1279 colour.setIcon(null);
1280 colour.setToolTipText(null);
1283 if (col2 instanceof Color)
1285 colour.setBackground((Color) col2);
1289 colour.setBackground(bigPanel.getBackground());
1290 colour.setForeground(Color.black);
1291 FeatureSettings.renderGraduatedColor(colour, (GraduatedColor) col2);
1292 // colour.setForeground(colour.getBackground());
1296 public void setColour(String featureType, Object col)
1299 // Color _col = (col instanceof Color) ? ((Color) col) : (col instanceof
1300 // GraduatedColor) ? ((GraduatedColor) col).getMaxColor() : null;
1301 // Object c = featureColours.get(featureType);
1302 // if (c == null || c instanceof Color || (c instanceof GraduatedColor &&
1303 // !((GraduatedColor)c).getMaxColor().equals(_col)))
1305 featureColours.put(featureType, col);
1309 public void setTransparency(float value)
1311 transparency = value;
1314 public float getTransparency()
1316 return transparency;
1320 * Replace current ordering with new ordering
1323 * { String(Type), Colour(Type), Boolean(Displayed) }
1325 public void setFeaturePriority(Object[][] data)
1327 setFeaturePriority(data, true);
1333 * { String(Type), Colour(Type), Boolean(Displayed) }
1335 * when true current featureDisplay list will be cleared
1337 public void setFeaturePriority(Object[][] data, boolean visibleNew)
1341 if (av.featuresDisplayed != null)
1343 av.featuresDisplayed.clear();
1347 av.featuresDisplayed = new Hashtable();
1355 // The feature table will display high priority
1356 // features at the top, but theses are the ones
1357 // we need to render last, so invert the data
1358 renderOrder = new String[data.length];
1360 if (data.length > 0)
1362 for (int i = 0; i < data.length; i++)
1364 String type = data[i][0].toString();
1365 setColour(type, data[i][1]); // todo : typesafety - feature color
1367 if (((Boolean) data[i][2]).booleanValue())
1369 av.featuresDisplayed.put(type, new Integer(getColour(type)
1373 renderOrder[data.length - i - 1] = type;
1379 Hashtable featureOrder = null;
1382 * analogous to colour - store a normalized ordering for all feature types in
1383 * this rendering context.
1386 * Feature type string
1388 * normalized priority - 0 means always appears on top, 1 means
1391 public float setOrder(String type, float position)
1393 if (featureOrder == null)
1395 featureOrder = new Hashtable();
1397 featureOrder.put(type, new Float(position));
1402 * get the global priority (0 (top) to 1 (bottom))
1405 * @return [0,1] or -1 for a type without a priority
1407 public float getOrder(String type)
1409 if (featureOrder != null)
1411 if (featureOrder.containsKey(type))
1413 return ((Float) featureOrder.get(type)).floatValue();
1421 * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener)
1423 public void addPropertyChangeListener(PropertyChangeListener listener)
1425 changeSupport.addPropertyChangeListener(listener);
1430 * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.beans.PropertyChangeListener)
1432 public void removePropertyChangeListener(PropertyChangeListener listener)
1434 changeSupport.removePropertyChangeListener(listener);