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 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;
176 * update from another feature renderer
177 * @param fr settings to copy
179 public void transferSettings(FeatureRenderer fr)
181 FeatureRendererSettings frs = new FeatureRendererSettings(fr);
182 this.renderOrder = frs.renderOrder;
183 this.featureGroups = frs.featureGroups;
184 this.featureColours = frs.featureColours;
185 this.transparency = frs.transparency;
186 this.featureOrder = frs.featureOrder;
187 if (av != null && av != fr.av)
189 // copy over the displayed feature settings
192 if (fr.av.featuresDisplayed != null)
194 // update display settings
195 if (av.featuresDisplayed == null)
197 av.featuresDisplayed = new Hashtable(fr.av.featuresDisplayed);
201 av.featuresDisplayed.clear();
202 Enumeration en = fr.av.featuresDisplayed.keys();
203 while (en.hasMoreElements())
205 av.featuresDisplayed.put(en.nextElement(), Boolean.TRUE);
214 BufferedImage offscreenImage;
216 boolean offscreenRender = false;
218 public Color findFeatureColour(Color initialCol, SequenceI seq, int res)
220 return new Color(findFeatureColour(initialCol.getRGB(), seq, res));
224 * This is used by the Molecule Viewer and Overview to get the accurate
225 * colourof the rendered sequence
227 public synchronized int findFeatureColour(int initialCol, SequenceI seq,
230 if (!av.showSequenceFeatures)
238 sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures();
239 if (sequenceFeatures != null)
241 sfSize = sequenceFeatures.length;
245 if (sequenceFeatures != lastSeq.getDatasetSequence()
246 .getSequenceFeatures())
248 sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures();
249 if (sequenceFeatures != null)
251 sfSize = sequenceFeatures.length;
255 if (sequenceFeatures == null || sfSize == 0)
260 if (jalview.util.Comparison.isGap(lastSeq.getCharAt(column)))
262 return Color.white.getRGB();
265 // Only bother making an offscreen image if transparency is applied
266 if (transparency != 1.0f && offscreenImage == null)
268 offscreenImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
271 currentColour = null;
272 // TODO: non-threadsafe - each rendering thread needs its own instance of
273 // the feature renderer - or this should be synchronized.
274 offscreenRender = true;
276 if (offscreenImage != null)
278 offscreenImage.setRGB(0, 0, initialCol);
279 drawSequence(offscreenImage.getGraphics(), lastSeq, column, column, 0);
281 return offscreenImage.getRGB(0, 0);
285 drawSequence(null, lastSeq, lastSeq.findPosition(column), -1, -1);
287 if (currentColour == null)
293 return ((Integer) currentColour).intValue();
322 // SequenceFeature sf;
325 SequenceFeature[] sequenceFeatures;
327 int sfSize, sfindex, spos, epos;
330 * show scores as heights
332 protected boolean varyHeight = false;
334 synchronized public void drawSequence(Graphics g, SequenceI seq,
335 int start, int end, int y1)
338 if (seq.getDatasetSequence().getSequenceFeatures() == null
339 || seq.getDatasetSequence().getSequenceFeatures().length == 0)
346 fm = g.getFontMetrics();
349 if (av.featuresDisplayed == null || renderOrder == null
353 if (av.featuresDisplayed.size() < 1)
358 sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures();
363 || seq.getDatasetSequence().getSequenceFeatures() != sequenceFeatures)
366 sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures();
369 if (transparency != 1 && g != null)
371 Graphics2D g2 = (Graphics2D) g;
372 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
376 if (!offscreenRender)
378 spos = lastSeq.findPosition(start);
379 epos = lastSeq.findPosition(end);
382 sfSize = sequenceFeatures.length;
384 for (int renderIndex = 0; renderIndex < renderOrder.length; renderIndex++)
386 type = renderOrder[renderIndex];
388 if (type == null || !av.featuresDisplayed.containsKey(type))
393 // loop through all features in sequence to find
394 // current feature to render
395 for (sfindex = 0; sfindex < sfSize; sfindex++)
397 if (!sequenceFeatures[sfindex].type.equals(type))
402 if (featureGroups != null
403 && sequenceFeatures[sfindex].featureGroup != null
404 && sequenceFeatures[sfindex].featureGroup.length() != 0
406 .containsKey(sequenceFeatures[sfindex].featureGroup)
407 && !((Boolean) featureGroups
408 .get(sequenceFeatures[sfindex].featureGroup))
415 && (sequenceFeatures[sfindex].getBegin() > epos || sequenceFeatures[sfindex]
421 if (offscreenRender && offscreenImage == null)
423 if (sequenceFeatures[sfindex].begin <= start
424 && sequenceFeatures[sfindex].end >= start)
426 // this is passed out to the overview and other sequence renderers
427 // (e.g. molecule viewer) to get displayed colour for rendered
429 currentColour = new Integer(
430 getColour(sequenceFeatures[sfindex]).getRGB());
431 // used to be retreived from av.featuresDisplayed
432 // currentColour = av.featuresDisplayed
433 // .get(sequenceFeatures[sfindex].type);
437 else if (sequenceFeatures[sfindex].type.equals("disulfide bond"))
440 renderFeature(g, seq,
441 seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
442 seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
443 getColour(sequenceFeatures[sfindex])
444 // new Color(((Integer) av.featuresDisplayed
445 // .get(sequenceFeatures[sfindex].type)).intValue())
447 renderFeature(g, seq,
448 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
449 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
450 getColour(sequenceFeatures[sfindex])
451 // new Color(((Integer) av.featuresDisplayed
452 // .get(sequenceFeatures[sfindex].type)).intValue())
456 else if (showFeature(sequenceFeatures[sfindex]))
458 if (av.showSeqFeaturesHeight
459 && sequenceFeatures[sfindex].score != Float.NaN)
461 renderScoreFeature(g, seq,
462 seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
463 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
464 getColour(sequenceFeatures[sfindex]), start, end, y1,
465 normaliseScore(sequenceFeatures[sfindex]));
469 renderFeature(g, seq,
470 seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
471 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
472 getColour(sequenceFeatures[sfindex]), start, end, y1);
480 if (transparency != 1.0f && g != null)
482 Graphics2D g2 = (Graphics2D) g;
483 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
488 Hashtable minmax = new Hashtable();
491 * normalise a score against the max/min bounds for the feature type.
493 * @param sequenceFeature
494 * @return byte[] { signed, normalised signed (-127 to 127) or unsigned
497 private final byte[] normaliseScore(SequenceFeature sequenceFeature)
499 float[] mm = ((float[][]) minmax.get(sequenceFeature.type))[0];
500 final byte[] r = new byte[]
504 if (r[0] != 0 || mm[0] < 0.0)
507 r[1] = (byte) ((int) 128.0 + 127.0 * (sequenceFeature.score / mm[1]));
511 r[1] = (byte) ((int) 255.0 * (sequenceFeature.score / mm[1]));
521 void renderFeature(Graphics g, SequenceI seq, int fstart, int fend,
522 Color featureColour, int start, int end, int y1)
525 if (((fstart <= end) && (fend >= start)))
528 { // fix for if the feature we have starts before the sequence start,
529 fstart = start; // but the feature end is still valid!!
536 int pady = (y1 + av.charHeight) - av.charHeight / 5;
537 for (i = fstart; i <= fend; i++)
539 s = seq.getCharAt(i);
541 if (jalview.util.Comparison.isGap(s))
546 g.setColor(featureColour);
548 g.fillRect((i - start) * av.charWidth, y1, av.charWidth,
551 if (offscreenRender || !av.validCharWidth)
556 g.setColor(Color.white);
557 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
558 g.drawString(String.valueOf(s), charOffset
559 + (av.charWidth * (i - start)), pady);
565 void renderScoreFeature(Graphics g, SequenceI seq, int fstart, int fend,
566 Color featureColour, int start, int end, int y1, byte[] bs)
569 if (((fstart <= end) && (fend >= start)))
572 { // fix for if the feature we have starts before the sequence start,
573 fstart = start; // but the feature end is still valid!!
580 int pady = (y1 + av.charHeight) - av.charHeight / 5;
581 int ystrt = 0, yend = av.charHeight;
584 // signed - zero is always middle of residue line.
587 yend = av.charHeight * (128 - bs[1]) / 512;
588 ystrt = av.charHeight - yend / 2;
592 ystrt = av.charHeight / 2;
593 yend = av.charHeight * (bs[1] - 128) / 512;
598 yend = av.charHeight * bs[1] / 255;
599 ystrt = av.charHeight - yend;
602 for (i = fstart; i <= fend; i++)
604 s = seq.getCharAt(i);
606 if (jalview.util.Comparison.isGap(s))
611 g.setColor(featureColour);
612 int x = (i - start) * av.charWidth;
613 g.drawRect(x, y1, av.charWidth, av.charHeight);
614 g.fillRect(x, y1 + ystrt, av.charWidth, yend);
616 if (offscreenRender || !av.validCharWidth)
621 g.setColor(Color.black);
622 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
623 g.drawString(String.valueOf(s), charOffset
624 + (av.charWidth * (i - start)), pady);
630 boolean newFeatureAdded = false;
633 * Called when alignment in associated view has new/modified features to
634 * discover and display.
637 public void featuresAdded()
643 boolean findingFeatures = false;
646 * search the alignment for all new features, give them a colour and display
647 * them. Then fires a PropertyChangeEvent on the changeSupport object.
650 void findAllFeatures()
652 synchronized (firing)
654 if (firing.equals(Boolean.FALSE))
656 firing = Boolean.TRUE;
657 findAllFeatures(true); // add all new features as visible
658 changeSupport.firePropertyChange("changeSupport", null, null);
659 firing = Boolean.FALSE;
665 * Searches alignment for all features and updates colours
667 * @param newMadeVisible
668 * if true newly added feature types will be rendered immediatly
670 synchronized void findAllFeatures(boolean newMadeVisible)
672 newFeatureAdded = false;
676 newFeatureAdded = true;
680 findingFeatures = true;
682 if (av.featuresDisplayed == null)
684 av.featuresDisplayed = new Hashtable();
687 allfeatures = new Vector();
688 Vector oldfeatures = new Vector();
689 if (renderOrder != null)
691 for (int i = 0; i < renderOrder.length; i++)
693 if (renderOrder[i] != null)
695 oldfeatures.addElement(renderOrder[i]);
701 minmax = new Hashtable();
703 AlignmentI alignment = av.getAlignment();
704 for (int i = 0; i < alignment.getHeight(); i++)
706 SequenceFeature[] features = alignment.getSequenceAt(i)
707 .getDatasetSequence().getSequenceFeatures();
709 if (features == null)
715 while (index < features.length)
717 if (!av.featuresDisplayed.containsKey(features[index].getType()))
720 if (featureGroups.containsKey(features[index].getType()))
722 boolean visible = ((Boolean) featureGroups
723 .get(features[index].featureGroup)).booleanValue();
732 if (!(features[index].begin == 0 && features[index].end == 0))
734 // If beginning and end are 0, the feature is for the whole sequence
735 // and we don't want to render the feature in the normal way
738 && !oldfeatures.contains(features[index].getType()))
740 // this is a new feature type on the alignment. Mark it for
742 av.featuresDisplayed.put(features[index].getType(),
743 new Integer(getColour(features[index].getType())
745 setOrder(features[index].getType(), 0);
749 if (!allfeatures.contains(features[index].getType()))
751 allfeatures.addElement(features[index].getType());
753 if (features[index].score != Float.NaN)
755 int nonpos = features[index].getBegin() >= 1 ? 0 : 1;
756 float[][] mm = (float[][]) minmax.get(features[index].getType());
761 minmax.put(features[index].getType(), mm);
763 if (mm[nonpos] == null)
765 mm[nonpos] = new float[]
766 { features[index].score, features[index].score };
771 if (mm[nonpos][0] > features[index].score)
773 mm[nonpos][0] = features[index].score;
775 if (mm[nonpos][1] < features[index].score)
777 mm[nonpos][1] = features[index].score;
784 updateRenderOrder(allfeatures);
785 findingFeatures = false;
788 protected Boolean firing = Boolean.FALSE;
791 * replaces the current renderOrder with the unordered features in
792 * allfeatures. The ordering of any types in both renderOrder and allfeatures
793 * is preserved, and all new feature types are rendered on top of the existing
794 * types, in the order given by getOrder or the order given in allFeatures.
795 * Note. this operates directly on the featureOrder hash for efficiency. TODO:
796 * eliminate the float storage for computing/recalling the persistent ordering
797 * New Cability: updates min/max for colourscheme range if its dynamic
801 private void updateRenderOrder(Vector allFeatures)
803 Vector allfeatures = new Vector(allFeatures);
804 String[] oldRender = renderOrder;
805 renderOrder = new String[allfeatures.size()];
806 Object mmrange, fc = null;
807 boolean initOrders = (featureOrder == null);
809 if (oldRender != null && oldRender.length > 0)
811 for (int j = 0; j < oldRender.length; j++)
813 if (oldRender[j] != null)
817 setOrder(oldRender[j], (1 - (1 + (float) j)
818 / (float) oldRender.length));
820 if (allfeatures.contains(oldRender[j]))
822 renderOrder[opos++] = oldRender[j]; // existing features always
823 // appear below new features
824 allfeatures.removeElement(oldRender[j]);
827 mmrange = minmax.get(oldRender[j]);
830 fc = featureColours.get(oldRender[j]);
831 if (fc != null && fc instanceof GraduatedColor
832 && ((GraduatedColor) fc).isAutoScale())
834 ((GraduatedColor) fc).updateBounds(
835 ((float[][]) mmrange)[0][0],
836 ((float[][]) mmrange)[0][1]);
844 if (allfeatures.size() == 0)
846 // no new features - leave order unchanged.
849 int i = allfeatures.size() - 1;
851 boolean sort = false;
852 String[] newf = new String[allfeatures.size()];
853 float[] sortOrder = new float[allfeatures.size()];
854 Enumeration en = allfeatures.elements();
855 // sort remaining elements
856 while (en.hasMoreElements())
858 newf[i] = en.nextElement().toString();
861 // update from new features minmax if necessary
862 mmrange = minmax.get(newf[i]);
865 fc = featureColours.get(newf[i]);
866 if (fc != null && fc instanceof GraduatedColor
867 && ((GraduatedColor) fc).isAutoScale())
869 ((GraduatedColor) fc).updateBounds(((float[][]) mmrange)[0][0],
870 ((float[][]) mmrange)[0][1]);
874 if (initOrders || !featureOrder.containsKey(newf[i]))
876 int denom = initOrders ? allfeatures.size() : featureOrder.size();
877 // new unordered feature - compute persistent ordering at head of
878 // existing features.
879 setOrder(newf[i], i / (float) denom);
881 // set order from newly found feature from persisted ordering.
882 sortOrder[i] = 2 - ((Float) featureOrder.get(newf[i])).floatValue();
885 // only sort if we need to
886 sort = sort || sortOrder[i] > sortOrder[i + 1];
890 if (iSize > 1 && sort)
892 jalview.util.QuickSort.sort(sortOrder, newf);
895 System.arraycopy(newf, 0, renderOrder, opos, newf.length);
899 * get a feature style object for the given type string. Creates a
900 * java.awt.Color for a featureType with no existing colourscheme. TODO:
901 * replace return type with object implementing standard abstract colour/style
905 * @return java.awt.Color or GraduatedColor
907 public Object getFeatureStyle(String featureType)
909 Object fc = featureColours.get(featureType);
912 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();
913 Color col = ucs.createColourFromName(featureType);
914 featureColours.put(featureType, fc = col);
920 * return a nominal colour for this feature
923 * @return standard color, or maximum colour for graduated colourscheme
925 public Color getColour(String featureType)
927 Object fc = getFeatureStyle(featureType);
929 if (fc instanceof Color)
935 if (fc instanceof GraduatedColor)
937 return ((GraduatedColor) fc).getMaxColor();
940 throw new Error("Implementation Error: Unrecognised render object "
941 + fc.getClass() + " for features of type " + featureType);
945 * calculate the render colour for a specific feature using current feature
949 * @return render colour for the given feature
951 public Color getColour(SequenceFeature feature)
953 Object fc = getFeatureStyle(feature.getType());
954 if (fc instanceof Color)
960 if (fc instanceof GraduatedColor)
962 return ((GraduatedColor) fc).findColor(feature);
965 throw new Error("Implementation Error: Unrecognised render object "
966 + fc.getClass() + " for features of type " + feature.getType());
969 private boolean showFeature(SequenceFeature sequenceFeature)
971 Object fc = getFeatureStyle(sequenceFeature.type);
972 if (fc instanceof GraduatedColor)
974 return ((GraduatedColor) fc).isColored(sequenceFeature);
983 // // Feature Editing Dialog
984 // // Will be refactored in next release.
986 static String lastFeatureAdded;
988 static String lastFeatureGroupAdded;
990 static String lastDescriptionAdded;
994 int featureIndex = 0;
996 boolean amendFeatures(final SequenceI[] sequences,
997 final SequenceFeature[] features, boolean newFeatures,
998 final AlignmentPanel ap)
1003 final JPanel bigPanel = new JPanel(new BorderLayout());
1004 final JComboBox overlaps;
1005 final JTextField name = new JTextField(25);
1006 final JTextField source = new JTextField(25);
1007 final JTextArea description = new JTextArea(3, 25);
1008 final JSpinner start = new JSpinner();
1009 final JSpinner end = new JSpinner();
1010 start.setPreferredSize(new Dimension(80, 20));
1011 end.setPreferredSize(new Dimension(80, 20));
1012 final FeatureRenderer me = this;
1013 final JLabel colour = new JLabel();
1014 colour.setOpaque(true);
1015 // colour.setBorder(BorderFactory.createEtchedBorder());
1016 colour.setMaximumSize(new Dimension(30, 16));
1017 colour.addMouseListener(new MouseAdapter()
1019 FeatureColourChooser fcc = null;
1021 public void mousePressed(MouseEvent evt)
1023 if (fcol instanceof Color)
1025 Color col = JColorChooser.showDialog(Desktop.desktop,
1026 "Select Feature Colour", ((Color) fcol));
1030 updateColourButton(bigPanel, colour, col);
1038 final String type = features[featureIndex].getType();
1039 fcc = new FeatureColourChooser(me, type);
1040 fcc.setRequestFocusEnabled(true);
1043 fcc.addActionListener(new ActionListener()
1046 public void actionPerformed(ActionEvent e)
1048 fcol = fcc.getLastColour();
1050 setColour(type, fcol);
1051 updateColourButton(bigPanel, colour, fcol);
1059 JPanel tmp = new JPanel();
1060 JPanel panel = new JPanel(new GridLayout(3, 1));
1062 // /////////////////////////////////////
1063 // /MULTIPLE FEATURES AT SELECTED RESIDUE
1064 if (!newFeatures && features.length > 1)
1066 panel = new JPanel(new GridLayout(4, 1));
1068 tmp.add(new JLabel(MessageManager.getString("label.select_feature")));
1069 overlaps = new JComboBox();
1070 for (int i = 0; i < features.length; i++)
1072 overlaps.addItem(features[i].getType() + "/"
1073 + features[i].getBegin() + "-" + features[i].getEnd()
1074 + " (" + features[i].getFeatureGroup() + ")");
1079 overlaps.addItemListener(new ItemListener()
1081 public void itemStateChanged(ItemEvent e)
1083 int index = overlaps.getSelectedIndex();
1086 featureIndex = index;
1087 name.setText(features[index].getType());
1088 description.setText(features[index].getDescription());
1089 source.setText(features[index].getFeatureGroup());
1090 start.setValue(new Integer(features[index].getBegin()));
1091 end.setValue(new Integer(features[index].getEnd()));
1093 SearchResults highlight = new SearchResults();
1094 highlight.addResult(sequences[0], features[index].getBegin(),
1095 features[index].getEnd());
1097 ap.seqPanel.seqCanvas.highlightSearchResults(highlight);
1100 Object col = getFeatureStyle(name.getText());
1103 col = new jalview.schemes.UserColourScheme()
1104 .createColourFromName(name.getText());
1106 oldcol = fcol = col;
1107 updateColourButton(bigPanel, colour, col);
1114 // ////////////////////////////////////
1118 tmp.add(new JLabel(MessageManager.getString("label.name"), JLabel.RIGHT));
1123 tmp.add(new JLabel(MessageManager.getString("label.group")+":", JLabel.RIGHT));
1128 tmp.add(new JLabel(MessageManager.getString("label.colour"), JLabel.RIGHT));
1130 colour.setPreferredSize(new Dimension(150, 15));
1131 colour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 9));
1132 colour.setForeground(Color.black);
1133 colour.setHorizontalAlignment(SwingConstants.CENTER);
1134 colour.setVerticalAlignment(SwingConstants.CENTER);
1135 colour.setHorizontalTextPosition(SwingConstants.CENTER);
1136 colour.setVerticalTextPosition(SwingConstants.CENTER);
1137 bigPanel.add(panel, BorderLayout.NORTH);
1139 panel = new JPanel();
1140 panel.add(new JLabel(MessageManager.getString("label.description"), JLabel.RIGHT));
1141 description.setFont(JvSwingUtils.getTextAreaFont());
1142 description.setLineWrap(true);
1143 panel.add(new JScrollPane(description));
1147 bigPanel.add(panel, BorderLayout.SOUTH);
1149 panel = new JPanel();
1150 panel.add(new JLabel(MessageManager.getString("label.start"), JLabel.RIGHT));
1152 panel.add(new JLabel(MessageManager.getString("label.end"), JLabel.RIGHT));
1154 bigPanel.add(panel, BorderLayout.CENTER);
1158 bigPanel.add(panel, BorderLayout.CENTER);
1161 if (lastFeatureAdded == null)
1163 if (features[0].type != null)
1165 lastFeatureAdded = features[0].type;
1169 lastFeatureAdded = "feature_1";
1173 if (lastFeatureGroupAdded == null)
1175 if (features[0].featureGroup != null)
1177 lastFeatureGroupAdded = features[0].featureGroup;
1181 lastFeatureGroupAdded = "Jalview";
1187 name.setText(lastFeatureAdded);
1188 source.setText(lastFeatureGroupAdded);
1192 name.setText(features[0].getType());
1193 source.setText(features[0].getFeatureGroup());
1196 start.setValue(new Integer(features[0].getBegin()));
1197 end.setValue(new Integer(features[0].getEnd()));
1198 description.setText(features[0].getDescription());
1199 updateColourButton(bigPanel, colour,
1200 (oldcol = fcol = getFeatureStyle(name.getText())));
1204 options = new Object[]
1205 { "Amend", "Delete", "Cancel" };
1209 options = new Object[]
1213 String title = newFeatures ? "Create New Sequence Feature(s)"
1214 : "Amend/Delete Features for " + sequences[0].getName();
1216 int reply = JOptionPane.showInternalOptionDialog(Desktop.desktop,
1217 bigPanel, title, JOptionPane.YES_NO_CANCEL_OPTION,
1218 JOptionPane.QUESTION_MESSAGE, null, options, "OK");
1220 jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile();
1222 if (reply == JOptionPane.OK_OPTION && name.getText().length() > 0)
1224 // This ensures that the last sequence
1225 // is refreshed and new features are rendered
1227 lastFeatureAdded = name.getText().trim();
1228 lastFeatureGroupAdded = source.getText().trim();
1229 lastDescriptionAdded = description.getText().replaceAll("\n", " ");
1230 // TODO: determine if the null feature group is valid
1231 if (lastFeatureGroupAdded.length() < 1)
1232 lastFeatureGroupAdded = null;
1237 SequenceFeature sf = features[featureIndex];
1239 if (reply == JOptionPane.NO_OPTION)
1241 sequences[0].getDatasetSequence().deleteFeature(sf);
1243 else if (reply == JOptionPane.YES_OPTION)
1245 sf.type = lastFeatureAdded;
1246 sf.featureGroup = lastFeatureGroupAdded;
1247 sf.description = lastDescriptionAdded;
1249 setColour(sf.type, fcol);
1250 av.featuresDisplayed.put(sf.type, getColour(sf.type));
1254 sf.begin = ((Integer) start.getValue()).intValue();
1255 sf.end = ((Integer) end.getValue()).intValue();
1256 } catch (NumberFormatException ex)
1260 ffile.parseDescriptionHTML(sf, false);
1264 // NEW FEATURES ADDED
1266 if (reply == JOptionPane.OK_OPTION && lastFeatureAdded.length() > 0)
1268 for (int i = 0; i < sequences.length; i++)
1270 features[i].type = lastFeatureAdded;
1271 if (lastFeatureGroupAdded != null)
1272 features[i].featureGroup = lastFeatureGroupAdded;
1273 features[i].description = lastDescriptionAdded;
1274 sequences[i].addSequenceFeature(features[i]);
1275 ffile.parseDescriptionHTML(features[i], false);
1278 if (av.featuresDisplayed == null)
1280 av.featuresDisplayed = new Hashtable();
1283 if (lastFeatureGroupAdded != null)
1285 if (featureGroups == null)
1286 featureGroups = new Hashtable();
1287 featureGroups.put(lastFeatureGroupAdded, new Boolean(true));
1289 setColour(lastFeatureAdded, fcol);
1290 av.featuresDisplayed.put(lastFeatureAdded,
1291 getColour(lastFeatureAdded));
1293 findAllFeatures(false);
1295 ap.paintAlignment(true);
1305 ap.paintAlignment(true);
1311 * update the amend feature button dependent on the given style
1317 protected void updateColourButton(JPanel bigPanel, JLabel colour,
1321 colour.setIcon(null);
1322 colour.setToolTipText(null);
1325 if (col2 instanceof Color)
1327 colour.setBackground((Color) col2);
1331 colour.setBackground(bigPanel.getBackground());
1332 colour.setForeground(Color.black);
1333 FeatureSettings.renderGraduatedColor(colour, (GraduatedColor) col2);
1334 // colour.setForeground(colour.getBackground());
1338 public void setColour(String featureType, Object col)
1341 // Color _col = (col instanceof Color) ? ((Color) col) : (col instanceof
1342 // GraduatedColor) ? ((GraduatedColor) col).getMaxColor() : null;
1343 // Object c = featureColours.get(featureType);
1344 // if (c == null || c instanceof Color || (c instanceof GraduatedColor &&
1345 // !((GraduatedColor)c).getMaxColor().equals(_col)))
1347 featureColours.put(featureType, col);
1351 public void setTransparency(float value)
1353 transparency = value;
1356 public float getTransparency()
1358 return transparency;
1362 * Replace current ordering with new ordering
1365 * { String(Type), Colour(Type), Boolean(Displayed) }
1367 public void setFeaturePriority(Object[][] data)
1369 setFeaturePriority(data, true);
1375 * { String(Type), Colour(Type), Boolean(Displayed) }
1377 * when true current featureDisplay list will be cleared
1379 public void setFeaturePriority(Object[][] data, boolean visibleNew)
1383 if (av.featuresDisplayed != null)
1385 av.featuresDisplayed.clear();
1389 av.featuresDisplayed = new Hashtable();
1397 // The feature table will display high priority
1398 // features at the top, but theses are the ones
1399 // we need to render last, so invert the data
1400 renderOrder = new String[data.length];
1402 if (data.length > 0)
1404 for (int i = 0; i < data.length; i++)
1406 String type = data[i][0].toString();
1407 setColour(type, data[i][1]); // todo : typesafety - feature color
1409 if (((Boolean) data[i][2]).booleanValue())
1411 av.featuresDisplayed.put(type, new Integer(getColour(type)
1415 renderOrder[data.length - i - 1] = type;
1421 Map featureOrder = null;
1424 * analogous to colour - store a normalized ordering for all feature types in
1425 * this rendering context.
1428 * Feature type string
1430 * normalized priority - 0 means always appears on top, 1 means
1433 public float setOrder(String type, float position)
1435 if (featureOrder == null)
1437 featureOrder = new Hashtable();
1439 featureOrder.put(type, new Float(position));
1444 * get the global priority (0 (top) to 1 (bottom))
1447 * @return [0,1] or -1 for a type without a priority
1449 public float getOrder(String type)
1451 if (featureOrder != null)
1453 if (featureOrder.containsKey(type))
1455 return ((Float) featureOrder.get(type)).floatValue();
1463 * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener)
1465 public void addPropertyChangeListener(PropertyChangeListener listener)
1467 changeSupport.addPropertyChangeListener(listener);
1472 * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.beans.PropertyChangeListener)
1474 public void removePropertyChangeListener(PropertyChangeListener listener)
1476 changeSupport.removePropertyChangeListener(listener);