2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 import java.util.concurrent.ConcurrentHashMap;
27 import java.awt.event.*;
28 import java.awt.image.*;
29 import java.beans.PropertyChangeListener;
30 import java.beans.PropertyChangeSupport;
34 import jalview.datamodel.*;
35 import jalview.schemes.GraduatedColor;
36 import jalview.util.MessageManager;
44 public class FeatureRenderer extends jalview.viewmodel.FeatureRenderer implements jalview.api.FeatureRenderer
53 * global transparency for feature
55 float transparency = 1.0f;
61 Map featureColours = new ConcurrentHashMap();
63 // A higher level for grouping features of a
65 Map featureGroups = new ConcurrentHashMap();
67 // This is actually an Integer held in the hashtable,
68 // Retrieved using the key feature type
73 PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
78 * Creates a new FeatureRenderer object.
83 public FeatureRenderer(AlignmentPanel ap)
87 if (ap != null && ap.seqPanel != null && ap.seqPanel.seqCanvas != null
88 && ap.seqPanel.seqCanvas.fr != null)
90 transferSettings(ap.seqPanel.seqCanvas.fr);
94 public class FeatureRendererSettings implements Cloneable
106 public FeatureRendererSettings(String[] renderOrder,
107 Hashtable featureGroups, Hashtable featureColours,
108 float transparency, Hashtable featureOrder)
111 this.renderOrder = renderOrder;
112 this.featureGroups = featureGroups;
113 this.featureColours = featureColours;
114 this.transparency = transparency;
115 this.featureOrder = featureOrder;
119 * create an independent instance of the feature renderer settings
123 public FeatureRendererSettings(FeatureRenderer fr)
126 featureGroups = new ConcurrentHashMap();
127 featureColours = new ConcurrentHashMap();
128 featureOrder = new ConcurrentHashMap();
129 if (fr.renderOrder != null)
131 this.renderOrder = new String[fr.renderOrder.length];
132 System.arraycopy(fr.renderOrder, 0, renderOrder, 0,
133 fr.renderOrder.length);
135 if (fr.featureGroups != null)
137 this.featureGroups = new ConcurrentHashMap(fr.featureGroups);
139 if (fr.featureColours != null)
141 this.featureColours = new ConcurrentHashMap(fr.featureColours);
143 Iterator en = fr.featureColours.keySet().iterator();
146 Object next = en.next();
147 Object val = featureColours.get(next);
148 if (val instanceof GraduatedColor)
151 .put(next, new GraduatedColor((GraduatedColor) val));
154 this.transparency = fr.transparency;
155 if (fr.featureOrder != null)
157 this.featureOrder = new ConcurrentHashMap(fr.featureOrder);
162 public FeatureRendererSettings getSettings()
164 return new FeatureRendererSettings(this);
167 public void transferSettings(FeatureRendererSettings fr)
169 this.renderOrder = fr.renderOrder;
170 this.featureGroups = fr.featureGroups;
171 this.featureColours = fr.featureColours;
172 this.transparency = fr.transparency;
173 this.featureOrder = fr.featureOrder;
177 * update from another feature renderer
182 public void transferSettings(jalview.api.FeatureRenderer _fr)
184 FeatureRenderer fr = (FeatureRenderer) _fr;
185 FeatureRendererSettings frs = new FeatureRendererSettings(fr);
186 this.renderOrder = frs.renderOrder;
187 this.featureGroups = frs.featureGroups;
188 this.featureColours = frs.featureColours;
189 this.transparency = frs.transparency;
190 this.featureOrder = frs.featureOrder;
191 if (av != null && av != fr.av)
193 // copy over the displayed feature settings
196 if (fr.av.featuresDisplayed != null)
198 // update display settings
199 if (av.featuresDisplayed == null)
201 av.featuresDisplayed = new Hashtable(fr.av.featuresDisplayed);
205 av.featuresDisplayed.clear();
206 Enumeration en = fr.av.featuresDisplayed.keys();
207 while (en.hasMoreElements())
209 av.featuresDisplayed.put(en.nextElement(), Boolean.TRUE);
218 BufferedImage offscreenImage;
220 boolean offscreenRender = false;
222 public Color findFeatureColour(Color initialCol, SequenceI seq, int res)
224 return new Color(findFeatureColour(initialCol.getRGB(), seq, res));
228 * This is used by the Molecule Viewer and Overview to get the accurate
229 * colourof the rendered sequence
231 public synchronized int findFeatureColour(int initialCol, SequenceI seq,
234 if (!av.showSequenceFeatures)
242 sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures();
243 if (sequenceFeatures != null)
245 sfSize = sequenceFeatures.length;
249 if (sequenceFeatures != lastSeq.getDatasetSequence()
250 .getSequenceFeatures())
252 sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures();
253 if (sequenceFeatures != null)
255 sfSize = sequenceFeatures.length;
259 if (sequenceFeatures == null || sfSize == 0)
264 if (jalview.util.Comparison.isGap(lastSeq.getCharAt(column)))
266 return Color.white.getRGB();
269 // Only bother making an offscreen image if transparency is applied
270 if (transparency != 1.0f && offscreenImage == null)
272 offscreenImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
275 currentColour = null;
276 // TODO: non-threadsafe - each rendering thread needs its own instance of
277 // the feature renderer - or this should be synchronized.
278 offscreenRender = true;
280 if (offscreenImage != null)
282 offscreenImage.setRGB(0, 0, initialCol);
283 drawSequence(offscreenImage.getGraphics(), lastSeq, column, column, 0);
285 return offscreenImage.getRGB(0, 0);
289 drawSequence(null, lastSeq, lastSeq.findPosition(column), -1, -1);
291 if (currentColour == null)
297 return ((Integer) currentColour).intValue();
326 // SequenceFeature sf;
329 SequenceFeature[] sequenceFeatures;
331 int sfSize, sfindex, spos, epos;
334 * show scores as heights
336 protected boolean varyHeight = false;
338 synchronized public void drawSequence(Graphics g, SequenceI seq,
339 int start, int end, int y1)
342 if (seq.getDatasetSequence().getSequenceFeatures() == null
343 || seq.getDatasetSequence().getSequenceFeatures().length == 0)
350 fm = g.getFontMetrics();
353 if (av.featuresDisplayed == null || renderOrder == null
357 if (av.featuresDisplayed.size() < 1)
362 sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures();
367 || seq.getDatasetSequence().getSequenceFeatures() != sequenceFeatures)
370 sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures();
373 if (transparency != 1 && g != null)
375 Graphics2D g2 = (Graphics2D) g;
376 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
380 if (!offscreenRender)
382 spos = lastSeq.findPosition(start);
383 epos = lastSeq.findPosition(end);
386 sfSize = sequenceFeatures.length;
388 for (int renderIndex = 0; renderIndex < renderOrder.length; renderIndex++)
390 type = renderOrder[renderIndex];
392 if (type == null || !av.featuresDisplayed.containsKey(type))
397 // loop through all features in sequence to find
398 // current feature to render
399 for (sfindex = 0; sfindex < sfSize; sfindex++)
401 if (!sequenceFeatures[sfindex].type.equals(type))
406 if (featureGroups != null
407 && sequenceFeatures[sfindex].featureGroup != null
408 && sequenceFeatures[sfindex].featureGroup.length() != 0
410 .containsKey(sequenceFeatures[sfindex].featureGroup)
411 && !((Boolean) featureGroups
412 .get(sequenceFeatures[sfindex].featureGroup))
419 && (sequenceFeatures[sfindex].getBegin() > epos || sequenceFeatures[sfindex]
425 if (offscreenRender && offscreenImage == null)
427 if (sequenceFeatures[sfindex].begin <= start
428 && sequenceFeatures[sfindex].end >= start)
430 // this is passed out to the overview and other sequence renderers
431 // (e.g. molecule viewer) to get displayed colour for rendered
433 currentColour = new Integer(
434 getColour(sequenceFeatures[sfindex]).getRGB());
435 // used to be retreived from av.featuresDisplayed
436 // currentColour = av.featuresDisplayed
437 // .get(sequenceFeatures[sfindex].type);
441 else if (sequenceFeatures[sfindex].type.equals("disulfide bond"))
444 renderFeature(g, seq,
445 seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
446 seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
447 getColour(sequenceFeatures[sfindex])
448 // new Color(((Integer) av.featuresDisplayed
449 // .get(sequenceFeatures[sfindex].type)).intValue())
451 renderFeature(g, seq,
452 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
453 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
454 getColour(sequenceFeatures[sfindex])
455 // new Color(((Integer) av.featuresDisplayed
456 // .get(sequenceFeatures[sfindex].type)).intValue())
460 else if (showFeature(sequenceFeatures[sfindex]))
462 if (av.showSeqFeaturesHeight
463 && sequenceFeatures[sfindex].score != Float.NaN)
465 renderScoreFeature(g, seq,
466 seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
467 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
468 getColour(sequenceFeatures[sfindex]), start, end, y1,
469 normaliseScore(sequenceFeatures[sfindex]));
473 renderFeature(g, seq,
474 seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
475 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
476 getColour(sequenceFeatures[sfindex]), start, end, y1);
484 if (transparency != 1.0f && g != null)
486 Graphics2D g2 = (Graphics2D) g;
487 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
492 Hashtable minmax = new Hashtable();
495 * normalise a score against the max/min bounds for the feature type.
497 * @param sequenceFeature
498 * @return byte[] { signed, normalised signed (-127 to 127) or unsigned
501 private final byte[] normaliseScore(SequenceFeature sequenceFeature)
503 float[] mm = ((float[][]) minmax.get(sequenceFeature.type))[0];
504 final byte[] r = new byte[]
508 if (r[0] != 0 || mm[0] < 0.0)
511 r[1] = (byte) ((int) 128.0 + 127.0 * (sequenceFeature.score / mm[1]));
515 r[1] = (byte) ((int) 255.0 * (sequenceFeature.score / mm[1]));
525 void renderFeature(Graphics g, SequenceI seq, int fstart, int fend,
526 Color featureColour, int start, int end, int y1)
529 if (((fstart <= end) && (fend >= start)))
532 { // fix for if the feature we have starts before the sequence start,
533 fstart = start; // but the feature end is still valid!!
540 int pady = (y1 + av.charHeight) - av.charHeight / 5;
541 for (i = fstart; i <= fend; i++)
543 s = seq.getCharAt(i);
545 if (jalview.util.Comparison.isGap(s))
550 g.setColor(featureColour);
552 g.fillRect((i - start) * av.charWidth, y1, av.charWidth,
555 if (offscreenRender || !av.validCharWidth)
560 g.setColor(Color.white);
561 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
562 g.drawString(String.valueOf(s), charOffset
563 + (av.charWidth * (i - start)), pady);
569 void renderScoreFeature(Graphics g, SequenceI seq, int fstart, int fend,
570 Color featureColour, int start, int end, int y1, byte[] bs)
573 if (((fstart <= end) && (fend >= start)))
576 { // fix for if the feature we have starts before the sequence start,
577 fstart = start; // but the feature end is still valid!!
584 int pady = (y1 + av.charHeight) - av.charHeight / 5;
585 int ystrt = 0, yend = av.charHeight;
588 // signed - zero is always middle of residue line.
591 yend = av.charHeight * (128 - bs[1]) / 512;
592 ystrt = av.charHeight - yend / 2;
596 ystrt = av.charHeight / 2;
597 yend = av.charHeight * (bs[1] - 128) / 512;
602 yend = av.charHeight * bs[1] / 255;
603 ystrt = av.charHeight - yend;
606 for (i = fstart; i <= fend; i++)
608 s = seq.getCharAt(i);
610 if (jalview.util.Comparison.isGap(s))
615 g.setColor(featureColour);
616 int x = (i - start) * av.charWidth;
617 g.drawRect(x, y1, av.charWidth, av.charHeight);
618 g.fillRect(x, y1 + ystrt, av.charWidth, yend);
620 if (offscreenRender || !av.validCharWidth)
625 g.setColor(Color.black);
626 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
627 g.drawString(String.valueOf(s), charOffset
628 + (av.charWidth * (i - start)), pady);
634 boolean newFeatureAdded = false;
637 * Called when alignment in associated view has new/modified features to
638 * discover and display.
641 public void featuresAdded()
647 boolean findingFeatures = false;
650 * search the alignment for all new features, give them a colour and display
651 * them. Then fires a PropertyChangeEvent on the changeSupport object.
654 void findAllFeatures()
656 synchronized (firing)
658 if (firing.equals(Boolean.FALSE))
660 firing = Boolean.TRUE;
661 findAllFeatures(true); // add all new features as visible
662 changeSupport.firePropertyChange("changeSupport", null, null);
663 firing = Boolean.FALSE;
669 * Searches alignment for all features and updates colours
671 * @param newMadeVisible
672 * if true newly added feature types will be rendered immediatly
674 synchronized void findAllFeatures(boolean newMadeVisible)
676 newFeatureAdded = false;
680 newFeatureAdded = true;
684 findingFeatures = true;
686 if (av.featuresDisplayed == null)
688 av.featuresDisplayed = new Hashtable();
691 allfeatures = new Vector();
692 Vector oldfeatures = new Vector();
693 if (renderOrder != null)
695 for (int i = 0; i < renderOrder.length; i++)
697 if (renderOrder[i] != null)
699 oldfeatures.addElement(renderOrder[i]);
705 minmax = new Hashtable();
707 AlignmentI alignment = av.getAlignment();
708 for (int i = 0; i < alignment.getHeight(); i++)
710 SequenceFeature[] features = alignment.getSequenceAt(i)
711 .getDatasetSequence().getSequenceFeatures();
713 if (features == null)
719 while (index < features.length)
721 if (!av.featuresDisplayed.containsKey(features[index].getType()))
724 if (featureGroups.containsKey(features[index].getType()))
726 boolean visible = ((Boolean) featureGroups
727 .get(features[index].featureGroup)).booleanValue();
736 if (!(features[index].begin == 0 && features[index].end == 0))
738 // If beginning and end are 0, the feature is for the whole sequence
739 // and we don't want to render the feature in the normal way
742 && !oldfeatures.contains(features[index].getType()))
744 // this is a new feature type on the alignment. Mark it for
746 av.featuresDisplayed.put(features[index].getType(),
747 new Integer(getColour(features[index].getType())
749 setOrder(features[index].getType(), 0);
753 if (!allfeatures.contains(features[index].getType()))
755 allfeatures.addElement(features[index].getType());
757 if (features[index].score != Float.NaN)
759 int nonpos = features[index].getBegin() >= 1 ? 0 : 1;
760 float[][] mm = (float[][]) minmax.get(features[index].getType());
765 minmax.put(features[index].getType(), mm);
767 if (mm[nonpos] == null)
769 mm[nonpos] = new float[]
770 { features[index].score, features[index].score };
775 if (mm[nonpos][0] > features[index].score)
777 mm[nonpos][0] = features[index].score;
779 if (mm[nonpos][1] < features[index].score)
781 mm[nonpos][1] = features[index].score;
788 updateRenderOrder(allfeatures);
789 findingFeatures = false;
792 protected Boolean firing = Boolean.FALSE;
795 * replaces the current renderOrder with the unordered features in
796 * allfeatures. The ordering of any types in both renderOrder and allfeatures
797 * is preserved, and all new feature types are rendered on top of the existing
798 * types, in the order given by getOrder or the order given in allFeatures.
799 * Note. this operates directly on the featureOrder hash for efficiency. TODO:
800 * eliminate the float storage for computing/recalling the persistent ordering
801 * New Cability: updates min/max for colourscheme range if its dynamic
805 private void updateRenderOrder(Vector allFeatures)
807 Vector allfeatures = new Vector(allFeatures);
808 String[] oldRender = renderOrder;
809 renderOrder = new String[allfeatures.size()];
810 Object mmrange, fc = null;
811 boolean initOrders = (featureOrder == null);
813 if (oldRender != null && oldRender.length > 0)
815 for (int j = 0; j < oldRender.length; j++)
817 if (oldRender[j] != null)
821 setOrder(oldRender[j], (1 - (1 + (float) j)
822 / (float) oldRender.length));
824 if (allfeatures.contains(oldRender[j]))
826 renderOrder[opos++] = oldRender[j]; // existing features always
827 // appear below new features
828 allfeatures.removeElement(oldRender[j]);
831 mmrange = minmax.get(oldRender[j]);
834 fc = featureColours.get(oldRender[j]);
835 if (fc != null && fc instanceof GraduatedColor
836 && ((GraduatedColor) fc).isAutoScale())
838 ((GraduatedColor) fc).updateBounds(
839 ((float[][]) mmrange)[0][0],
840 ((float[][]) mmrange)[0][1]);
848 if (allfeatures.size() == 0)
850 // no new features - leave order unchanged.
853 int i = allfeatures.size() - 1;
855 boolean sort = false;
856 String[] newf = new String[allfeatures.size()];
857 float[] sortOrder = new float[allfeatures.size()];
858 Enumeration en = allfeatures.elements();
859 // sort remaining elements
860 while (en.hasMoreElements())
862 newf[i] = en.nextElement().toString();
865 // update from new features minmax if necessary
866 mmrange = minmax.get(newf[i]);
869 fc = featureColours.get(newf[i]);
870 if (fc != null && fc instanceof GraduatedColor
871 && ((GraduatedColor) fc).isAutoScale())
873 ((GraduatedColor) fc).updateBounds(((float[][]) mmrange)[0][0],
874 ((float[][]) mmrange)[0][1]);
878 if (initOrders || !featureOrder.containsKey(newf[i]))
880 int denom = initOrders ? allfeatures.size() : featureOrder.size();
881 // new unordered feature - compute persistent ordering at head of
882 // existing features.
883 setOrder(newf[i], i / (float) denom);
885 // set order from newly found feature from persisted ordering.
886 sortOrder[i] = 2 - ((Float) featureOrder.get(newf[i])).floatValue();
889 // only sort if we need to
890 sort = sort || sortOrder[i] > sortOrder[i + 1];
894 if (iSize > 1 && sort)
896 jalview.util.QuickSort.sort(sortOrder, newf);
899 System.arraycopy(newf, 0, renderOrder, opos, newf.length);
903 * get a feature style object for the given type string. Creates a
904 * java.awt.Color for a featureType with no existing colourscheme. TODO:
905 * replace return type with object implementing standard abstract colour/style
909 * @return java.awt.Color or GraduatedColor
911 public Object getFeatureStyle(String featureType)
913 Object fc = featureColours.get(featureType);
916 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();
917 Color col = ucs.createColourFromName(featureType);
918 featureColours.put(featureType, fc = col);
924 * return a nominal colour for this feature
927 * @return standard color, or maximum colour for graduated colourscheme
929 public Color getColour(String featureType)
931 Object fc = getFeatureStyle(featureType);
933 if (fc instanceof Color)
939 if (fc instanceof GraduatedColor)
941 return ((GraduatedColor) fc).getMaxColor();
944 throw new Error("Implementation Error: Unrecognised render object "
945 + fc.getClass() + " for features of type " + featureType);
949 * calculate the render colour for a specific feature using current feature
953 * @return render colour for the given feature
955 public Color getColour(SequenceFeature feature)
957 Object fc = getFeatureStyle(feature.getType());
958 if (fc instanceof Color)
964 if (fc instanceof GraduatedColor)
966 return ((GraduatedColor) fc).findColor(feature);
969 throw new Error("Implementation Error: Unrecognised render object "
970 + fc.getClass() + " for features of type " + feature.getType());
973 private boolean showFeature(SequenceFeature sequenceFeature)
975 Object fc = getFeatureStyle(sequenceFeature.type);
976 if (fc instanceof GraduatedColor)
978 return ((GraduatedColor) fc).isColored(sequenceFeature);
987 // // Feature Editing Dialog
988 // // Will be refactored in next release.
990 static String lastFeatureAdded;
992 static String lastFeatureGroupAdded;
994 static String lastDescriptionAdded;
998 int featureIndex = 0;
1000 boolean amendFeatures(final SequenceI[] sequences,
1001 final SequenceFeature[] features, boolean newFeatures,
1002 final AlignmentPanel ap)
1007 final JPanel bigPanel = new JPanel(new BorderLayout());
1008 final JComboBox overlaps;
1009 final JTextField name = new JTextField(25);
1010 final JTextField source = new JTextField(25);
1011 final JTextArea description = new JTextArea(3, 25);
1012 final JSpinner start = new JSpinner();
1013 final JSpinner end = new JSpinner();
1014 start.setPreferredSize(new Dimension(80, 20));
1015 end.setPreferredSize(new Dimension(80, 20));
1016 final FeatureRenderer me = this;
1017 final JLabel colour = new JLabel();
1018 colour.setOpaque(true);
1019 // colour.setBorder(BorderFactory.createEtchedBorder());
1020 colour.setMaximumSize(new Dimension(30, 16));
1021 colour.addMouseListener(new MouseAdapter()
1023 FeatureColourChooser fcc = null;
1025 public void mousePressed(MouseEvent evt)
1027 if (fcol instanceof Color)
1029 Color col = JColorChooser.showDialog(Desktop.desktop,
1030 "Select Feature Colour", ((Color) fcol));
1034 updateColourButton(bigPanel, colour, col);
1042 final String type = features[featureIndex].getType();
1043 fcc = new FeatureColourChooser(me, type);
1044 fcc.setRequestFocusEnabled(true);
1047 fcc.addActionListener(new ActionListener()
1050 public void actionPerformed(ActionEvent e)
1052 fcol = fcc.getLastColour();
1054 setColour(type, fcol);
1055 updateColourButton(bigPanel, colour, fcol);
1063 JPanel tmp = new JPanel();
1064 JPanel panel = new JPanel(new GridLayout(3, 1));
1066 // /////////////////////////////////////
1067 // /MULTIPLE FEATURES AT SELECTED RESIDUE
1068 if (!newFeatures && features.length > 1)
1070 panel = new JPanel(new GridLayout(4, 1));
1072 tmp.add(new JLabel(MessageManager.getString("label.select_feature")));
1073 overlaps = new JComboBox();
1074 for (int i = 0; i < features.length; i++)
1076 overlaps.addItem(features[i].getType() + "/"
1077 + features[i].getBegin() + "-" + features[i].getEnd()
1078 + " (" + features[i].getFeatureGroup() + ")");
1083 overlaps.addItemListener(new ItemListener()
1085 public void itemStateChanged(ItemEvent e)
1087 int index = overlaps.getSelectedIndex();
1090 featureIndex = index;
1091 name.setText(features[index].getType());
1092 description.setText(features[index].getDescription());
1093 source.setText(features[index].getFeatureGroup());
1094 start.setValue(new Integer(features[index].getBegin()));
1095 end.setValue(new Integer(features[index].getEnd()));
1097 SearchResults highlight = new SearchResults();
1098 highlight.addResult(sequences[0], features[index].getBegin(),
1099 features[index].getEnd());
1101 ap.seqPanel.seqCanvas.highlightSearchResults(highlight);
1104 Object col = getFeatureStyle(name.getText());
1107 col = new jalview.schemes.UserColourScheme()
1108 .createColourFromName(name.getText());
1110 oldcol = fcol = col;
1111 updateColourButton(bigPanel, colour, col);
1118 // ////////////////////////////////////
1122 tmp.add(new JLabel(MessageManager.getString("label.name"), JLabel.RIGHT));
1127 tmp.add(new JLabel(MessageManager.getString("label.group") + ":",
1133 tmp.add(new JLabel(MessageManager.getString("label.colour"),
1136 colour.setPreferredSize(new Dimension(150, 15));
1137 colour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 9));
1138 colour.setForeground(Color.black);
1139 colour.setHorizontalAlignment(SwingConstants.CENTER);
1140 colour.setVerticalAlignment(SwingConstants.CENTER);
1141 colour.setHorizontalTextPosition(SwingConstants.CENTER);
1142 colour.setVerticalTextPosition(SwingConstants.CENTER);
1143 bigPanel.add(panel, BorderLayout.NORTH);
1145 panel = new JPanel();
1146 panel.add(new JLabel(MessageManager.getString("label.description"),
1148 description.setFont(JvSwingUtils.getTextAreaFont());
1149 description.setLineWrap(true);
1150 panel.add(new JScrollPane(description));
1154 bigPanel.add(panel, BorderLayout.SOUTH);
1156 panel = new JPanel();
1157 panel.add(new JLabel(MessageManager.getString("label.start"),
1160 panel.add(new JLabel(MessageManager.getString("label.end"),
1163 bigPanel.add(panel, BorderLayout.CENTER);
1167 bigPanel.add(panel, BorderLayout.CENTER);
1170 if (lastFeatureAdded == null)
1172 if (features[0].type != null)
1174 lastFeatureAdded = features[0].type;
1178 lastFeatureAdded = "feature_1";
1182 if (lastFeatureGroupAdded == null)
1184 if (features[0].featureGroup != null)
1186 lastFeatureGroupAdded = features[0].featureGroup;
1190 lastFeatureGroupAdded = "Jalview";
1196 name.setText(lastFeatureAdded);
1197 source.setText(lastFeatureGroupAdded);
1201 name.setText(features[0].getType());
1202 source.setText(features[0].getFeatureGroup());
1205 start.setValue(new Integer(features[0].getBegin()));
1206 end.setValue(new Integer(features[0].getEnd()));
1207 description.setText(features[0].getDescription());
1208 updateColourButton(bigPanel, colour,
1209 (oldcol = fcol = getFeatureStyle(name.getText())));
1213 options = new Object[]
1214 { "Amend", "Delete", "Cancel" };
1218 options = new Object[]
1222 String title = newFeatures ? "Create New Sequence Feature(s)"
1223 : "Amend/Delete Features for " + sequences[0].getName();
1225 int reply = JOptionPane.showInternalOptionDialog(Desktop.desktop,
1226 bigPanel, title, JOptionPane.YES_NO_CANCEL_OPTION,
1227 JOptionPane.QUESTION_MESSAGE, null, options, "OK");
1229 jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile();
1231 if (reply == JOptionPane.OK_OPTION && name.getText().length() > 0)
1233 // This ensures that the last sequence
1234 // is refreshed and new features are rendered
1236 lastFeatureAdded = name.getText().trim();
1237 lastFeatureGroupAdded = source.getText().trim();
1238 lastDescriptionAdded = description.getText().replaceAll("\n", " ");
1239 // TODO: determine if the null feature group is valid
1240 if (lastFeatureGroupAdded.length() < 1)
1241 lastFeatureGroupAdded = null;
1246 SequenceFeature sf = features[featureIndex];
1248 if (reply == JOptionPane.NO_OPTION)
1250 sequences[0].getDatasetSequence().deleteFeature(sf);
1252 else if (reply == JOptionPane.YES_OPTION)
1254 sf.type = lastFeatureAdded;
1255 sf.featureGroup = lastFeatureGroupAdded;
1256 sf.description = lastDescriptionAdded;
1258 setColour(sf.type, fcol);
1259 av.featuresDisplayed.put(sf.type, getColour(sf.type));
1263 sf.begin = ((Integer) start.getValue()).intValue();
1264 sf.end = ((Integer) end.getValue()).intValue();
1265 } catch (NumberFormatException ex)
1269 ffile.parseDescriptionHTML(sf, false);
1273 // NEW FEATURES ADDED
1275 if (reply == JOptionPane.OK_OPTION && lastFeatureAdded.length() > 0)
1277 for (int i = 0; i < sequences.length; i++)
1279 features[i].type = lastFeatureAdded;
1280 if (lastFeatureGroupAdded != null)
1281 features[i].featureGroup = lastFeatureGroupAdded;
1282 features[i].description = lastDescriptionAdded;
1283 sequences[i].addSequenceFeature(features[i]);
1284 ffile.parseDescriptionHTML(features[i], false);
1287 if (av.featuresDisplayed == null)
1289 av.featuresDisplayed = new Hashtable();
1292 if (lastFeatureGroupAdded != null)
1294 if (featureGroups == null)
1295 featureGroups = new Hashtable();
1296 featureGroups.put(lastFeatureGroupAdded, new Boolean(true));
1298 setColour(lastFeatureAdded, fcol);
1299 av.featuresDisplayed.put(lastFeatureAdded,
1300 getColour(lastFeatureAdded));
1302 findAllFeatures(false);
1304 ap.paintAlignment(true);
1314 ap.paintAlignment(true);
1320 * update the amend feature button dependent on the given style
1326 protected void updateColourButton(JPanel bigPanel, JLabel colour,
1330 colour.setIcon(null);
1331 colour.setToolTipText(null);
1334 if (col2 instanceof Color)
1336 colour.setBackground((Color) col2);
1340 colour.setBackground(bigPanel.getBackground());
1341 colour.setForeground(Color.black);
1342 FeatureSettings.renderGraduatedColor(colour, (GraduatedColor) col2);
1343 // colour.setForeground(colour.getBackground());
1347 public void setColour(String featureType, Object col)
1350 // Color _col = (col instanceof Color) ? ((Color) col) : (col instanceof
1351 // GraduatedColor) ? ((GraduatedColor) col).getMaxColor() : null;
1352 // Object c = featureColours.get(featureType);
1353 // if (c == null || c instanceof Color || (c instanceof GraduatedColor &&
1354 // !((GraduatedColor)c).getMaxColor().equals(_col)))
1356 featureColours.put(featureType, col);
1360 public void setTransparency(float value)
1362 transparency = value;
1365 public float getTransparency()
1367 return transparency;
1371 * Replace current ordering with new ordering
1374 * { String(Type), Colour(Type), Boolean(Displayed) }
1376 public void setFeaturePriority(Object[][] data)
1378 setFeaturePriority(data, true);
1384 * { String(Type), Colour(Type), Boolean(Displayed) }
1386 * when true current featureDisplay list will be cleared
1388 public void setFeaturePriority(Object[][] data, boolean visibleNew)
1392 if (av.featuresDisplayed != null)
1394 av.featuresDisplayed.clear();
1398 av.featuresDisplayed = new Hashtable();
1406 // The feature table will display high priority
1407 // features at the top, but theses are the ones
1408 // we need to render last, so invert the data
1409 renderOrder = new String[data.length];
1411 if (data.length > 0)
1413 for (int i = 0; i < data.length; i++)
1415 String type = data[i][0].toString();
1416 setColour(type, data[i][1]); // todo : typesafety - feature color
1418 if (((Boolean) data[i][2]).booleanValue())
1420 av.featuresDisplayed.put(type, new Integer(getColour(type)
1424 renderOrder[data.length - i - 1] = type;
1430 Map featureOrder = null;
1433 * analogous to colour - store a normalized ordering for all feature types in
1434 * this rendering context.
1437 * Feature type string
1439 * normalized priority - 0 means always appears on top, 1 means
1442 public float setOrder(String type, float position)
1444 if (featureOrder == null)
1446 featureOrder = new Hashtable();
1448 featureOrder.put(type, new Float(position));
1453 * get the global priority (0 (top) to 1 (bottom))
1456 * @return [0,1] or -1 for a type without a priority
1458 public float getOrder(String type)
1460 if (featureOrder != null)
1462 if (featureOrder.containsKey(type))
1464 return ((Float) featureOrder.get(type)).floatValue();
1472 * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener)
1474 public void addPropertyChangeListener(PropertyChangeListener listener)
1476 changeSupport.addPropertyChangeListener(listener);
1481 * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.beans.PropertyChangeListener)
1483 public void removePropertyChangeListener(PropertyChangeListener listener)
1485 changeSupport.removePropertyChangeListener(listener);