2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 import java.awt.event.*;
25 import java.awt.image.*;
26 import java.beans.PropertyChangeListener;
27 import java.beans.PropertyChangeSupport;
31 import jalview.datamodel.*;
32 import jalview.schemes.GraduatedColor;
33 import jalview.util.FeatureColourI;
41 public class FeatureRenderer
50 * global transparency for feature
52 float transparency = 1.0f;
58 Hashtable featureColours = new Hashtable();
60 // A higher level for grouping features of a
62 Hashtable featureGroups = new Hashtable();
64 // This is actually an Integer held in the hashtable,
65 // Retrieved using the key feature type
70 PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
75 * Creates a new FeatureRenderer object.
80 public FeatureRenderer(AlignmentPanel ap)
86 public class FeatureRendererSettings implements Cloneable
90 Hashtable featureGroups;
92 Hashtable featureColours;
96 Hashtable featureOrder;
98 public FeatureRendererSettings(String[] renderOrder,
99 Hashtable featureGroups, Hashtable featureColours,
100 float transparency, Hashtable featureOrder)
103 this.renderOrder = renderOrder;
104 this.featureGroups = featureGroups;
105 this.featureColours = featureColours;
106 this.transparency = transparency;
107 this.featureOrder = featureOrder;
110 public FeatureRendererSettings(FeatureRenderer fr)
112 this.renderOrder = fr.renderOrder;
113 this.featureGroups = fr.featureGroups;
114 this.featureColours = fr.featureColours;
115 this.transparency = fr.transparency;
116 this.featureOrder = fr.featureOrder;
120 public FeatureRendererSettings getSettings()
122 return new FeatureRendererSettings(this);
125 public void transferSettings(FeatureRendererSettings fr)
127 this.renderOrder = fr.renderOrder;
128 this.featureGroups = fr.featureGroups;
129 this.featureColours = fr.featureColours;
130 this.transparency = fr.transparency;
131 this.featureOrder = fr.featureOrder;
134 public void transferSettings(FeatureRenderer fr)
136 this.renderOrder = fr.renderOrder;
137 this.featureGroups = fr.featureGroups;
138 this.featureColours = fr.featureColours;
139 this.transparency = fr.transparency;
140 this.featureOrder = fr.featureOrder;
143 BufferedImage offscreenImage;
145 boolean offscreenRender = false;
147 public Color findFeatureColour(Color initialCol, SequenceI seq, int res)
149 return new Color(findFeatureColour(initialCol.getRGB(), seq, res));
153 * This is used by the Molecule Viewer and Overview to get the accurate
154 * colourof the rendered sequence
156 public int findFeatureColour(int initialCol, SequenceI seq, int column)
158 if (!av.showSequenceFeatures)
166 sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures();
167 if (sequenceFeatures != null)
169 sfSize = sequenceFeatures.length;
173 if (sequenceFeatures != lastSeq.getDatasetSequence()
174 .getSequenceFeatures())
176 sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures();
177 if (sequenceFeatures != null)
179 sfSize = sequenceFeatures.length;
183 if (sequenceFeatures == null || sfSize == 0)
188 if (jalview.util.Comparison.isGap(lastSeq.getCharAt(column)))
190 return Color.white.getRGB();
193 // Only bother making an offscreen image if transparency is applied
194 if (transparency != 1.0f && offscreenImage == null)
196 offscreenImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
199 currentColour = null;
201 offscreenRender = true;
203 if (offscreenImage != null)
205 offscreenImage.setRGB(0, 0, initialCol);
206 drawSequence(offscreenImage.getGraphics(), lastSeq, column, column, 0);
208 return offscreenImage.getRGB(0, 0);
212 drawSequence(null, lastSeq, lastSeq.findPosition(column), -1, -1);
214 if (currentColour == null)
220 return ((Integer) currentColour).intValue();
249 // SequenceFeature sf;
252 SequenceFeature[] sequenceFeatures;
254 int sfSize, sfindex, spos, epos;
257 * show scores as heights
259 protected boolean varyHeight = false;
261 synchronized public void drawSequence(Graphics g, SequenceI seq,
262 int start, int end, int y1)
265 if (seq.getDatasetSequence().getSequenceFeatures() == null
266 || seq.getDatasetSequence().getSequenceFeatures().length == 0)
273 fm = g.getFontMetrics();
276 if (av.featuresDisplayed == null || renderOrder == null
280 if (av.featuresDisplayed.size() < 1)
285 sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures();
290 || seq.getDatasetSequence().getSequenceFeatures() != sequenceFeatures)
293 sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures();
296 if (transparency != 1 && g != null)
298 Graphics2D g2 = (Graphics2D) g;
299 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
303 if (!offscreenRender)
305 spos = lastSeq.findPosition(start);
306 epos = lastSeq.findPosition(end);
309 sfSize = sequenceFeatures.length;
311 for (int renderIndex = 0; renderIndex < renderOrder.length; renderIndex++)
313 type = renderOrder[renderIndex];
315 if (type == null || !av.featuresDisplayed.containsKey(type))
320 // loop through all features in sequence to find
321 // current feature to render
322 for (sfindex = 0; sfindex < sfSize; sfindex++)
324 if (!sequenceFeatures[sfindex].type.equals(type))
329 if (featureGroups != null
330 && sequenceFeatures[sfindex].featureGroup != null
331 && sequenceFeatures[sfindex].featureGroup.length() != 0
333 .containsKey(sequenceFeatures[sfindex].featureGroup)
334 && !((Boolean) featureGroups
335 .get(sequenceFeatures[sfindex].featureGroup))
342 && (sequenceFeatures[sfindex].getBegin() > epos || sequenceFeatures[sfindex]
348 if (offscreenRender && offscreenImage == null)
350 if (sequenceFeatures[sfindex].begin <= start
351 && sequenceFeatures[sfindex].end >= start)
353 // this is passed out to the overview and other sequence renderers (e.g. molecule viewer) to get displayed colour for rendered sequence
354 currentColour = new Integer(getColour(sequenceFeatures[sfindex]).getRGB());
355 // used to be retreived from av.featuresDisplayed
356 // currentColour = av.featuresDisplayed
357 // .get(sequenceFeatures[sfindex].type);
362 else if (sequenceFeatures[sfindex].type.equals("disulfide bond"))
368 seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
369 seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
370 getColour(sequenceFeatures[sfindex])
371 //new Color(((Integer) av.featuresDisplayed
372 // .get(sequenceFeatures[sfindex].type)).intValue())
378 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
379 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
380 getColour(sequenceFeatures[sfindex])
381 //new Color(((Integer) av.featuresDisplayed
382 // .get(sequenceFeatures[sfindex].type)).intValue())
388 if (showFeature(sequenceFeatures[sfindex]))
390 if (av.showSeqFeaturesHeight
391 && sequenceFeatures[sfindex].score != Float.NaN)
393 renderScoreFeature(g, seq, seq
394 .findIndex(sequenceFeatures[sfindex].begin) - 1,
395 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
396 getColour(sequenceFeatures[sfindex]), start, end,
397 y1, normaliseScore(sequenceFeatures[sfindex]));
401 renderFeature(g, seq, seq
402 .findIndex(sequenceFeatures[sfindex].begin) - 1,
403 seq.findIndex(sequenceFeatures[sfindex].end) - 1,
404 getColour(sequenceFeatures[sfindex]), start, end,
413 if (transparency != 1.0f && g != null)
415 Graphics2D g2 = (Graphics2D) g;
416 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
421 Hashtable minmax = new Hashtable();
424 * normalise a score against the max/min bounds for the feature type.
426 * @param sequenceFeature
427 * @return byte[] { signed, normalised signed (-127 to 127) or unsigned
430 private final byte[] normaliseScore(SequenceFeature sequenceFeature)
432 float[] mm = ((float[][]) minmax.get(sequenceFeature.type))[0];
433 final byte[] r = new byte[]
437 if (r[0] != 0 || mm[0] < 0.0)
440 r[1] = (byte) ((int) 128.0 + 127.0 * (sequenceFeature.score / mm[1]));
444 r[1] = (byte) ((int) 255.0 * (sequenceFeature.score / mm[1]));
454 void renderFeature(Graphics g, SequenceI seq, int fstart, int fend,
455 Color featureColour, int start, int end, int y1)
458 if (((fstart <= end) && (fend >= start)))
461 { // fix for if the feature we have starts before the sequence start,
462 fstart = start; // but the feature end is still valid!!
469 int pady = (y1 + av.charHeight) - av.charHeight / 5;
470 for (i = fstart; i <= fend; i++)
472 s = seq.getCharAt(i);
474 if (jalview.util.Comparison.isGap(s))
479 g.setColor(featureColour);
481 g.fillRect((i - start) * av.charWidth, y1, av.charWidth,
484 if (offscreenRender || !av.validCharWidth)
489 g.setColor(Color.white);
490 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
491 g.drawString(String.valueOf(s), charOffset
492 + (av.charWidth * (i - start)), pady);
498 void renderScoreFeature(Graphics g, SequenceI seq, int fstart, int fend,
499 Color featureColour, int start, int end, int y1, byte[] bs)
502 if (((fstart <= end) && (fend >= start)))
505 { // fix for if the feature we have starts before the sequence start,
506 fstart = start; // but the feature end is still valid!!
513 int pady = (y1 + av.charHeight) - av.charHeight / 5;
514 int ystrt = 0, yend = av.charHeight;
517 // signed - zero is always middle of residue line.
520 yend = av.charHeight * (128 - bs[1]) / 512;
521 ystrt = av.charHeight - yend / 2;
525 ystrt = av.charHeight / 2;
526 yend = av.charHeight * (bs[1] - 128) / 512;
531 yend = av.charHeight * bs[1] / 255;
532 ystrt = av.charHeight - yend;
535 for (i = fstart; i <= fend; i++)
537 s = seq.getCharAt(i);
539 if (jalview.util.Comparison.isGap(s))
544 g.setColor(featureColour);
545 int x = (i - start) * av.charWidth;
546 g.drawRect(x, y1, av.charWidth, av.charHeight);
547 g.fillRect(x, y1 + ystrt, av.charWidth, yend);
549 if (offscreenRender || !av.validCharWidth)
554 g.setColor(Color.black);
555 charOffset = (av.charWidth - fm.charWidth(s)) / 2;
556 g.drawString(String.valueOf(s), charOffset
557 + (av.charWidth * (i - start)), pady);
563 boolean newFeatureAdded = false;
566 * Called when alignment in associated view has new/modified features to
567 * discover and display.
570 public void featuresAdded()
576 boolean findingFeatures = false;
579 * search the alignment for all new features, give them a colour and display
580 * them. Then fires a PropertyChangeEvent on the changeSupport object.
583 void findAllFeatures()
585 synchronized (firing)
587 if (firing.equals(Boolean.FALSE))
589 firing = Boolean.TRUE;
590 findAllFeatures(true); // add all new features as visible
591 changeSupport.firePropertyChange("changeSupport", null, null);
592 firing = Boolean.FALSE;
598 * Searches alignment for all features and updates colours
600 * @param newMadeVisible
601 * if true newly added feature types will be rendered
604 synchronized void findAllFeatures(boolean newMadeVisible)
606 newFeatureAdded = false;
610 newFeatureAdded = true;
614 findingFeatures = true;
616 if (av.featuresDisplayed == null)
618 av.featuresDisplayed = new Hashtable();
621 allfeatures = new Vector();
622 Vector oldfeatures = new Vector();
623 if (renderOrder != null)
625 for (int i = 0; i < renderOrder.length; i++)
627 if (renderOrder[i] != null)
629 oldfeatures.addElement(renderOrder[i]);
635 minmax = new Hashtable();
637 for (int i = 0; i < av.alignment.getHeight(); i++)
639 SequenceFeature[] features = av.alignment.getSequenceAt(i)
640 .getDatasetSequence().getSequenceFeatures();
642 if (features == null)
648 while (index < features.length)
650 if (!av.featuresDisplayed.containsKey(features[index].getType()))
653 if (featureGroups.containsKey(features[index].getType()))
655 boolean visible = ((Boolean) featureGroups
656 .get(features[index].featureGroup)).booleanValue();
665 if (!(features[index].begin == 0 && features[index].end == 0))
667 // If beginning and end are 0, the feature is for the whole sequence
668 // and we don't want to render the feature in the normal way
671 && !oldfeatures.contains(features[index].getType()))
673 // this is a new feature type on the alignment. Mark it for
675 av.featuresDisplayed.put(features[index].getType(),
676 new Integer(getColour(features[index].getType())
678 setOrder(features[index].getType(), 0);
682 if (!allfeatures.contains(features[index].getType()))
684 allfeatures.addElement(features[index].getType());
686 if (features[index].score != Float.NaN)
688 int nonpos= features[index].getBegin()>=1 ? 0 : 1;
689 float[][] mm = (float[][]) minmax.get(features[index].getType());
692 mm = new float[][] {null, null };
693 minmax.put(features[index].getType(), mm);
695 if (mm[nonpos]==null)
697 mm[nonpos] = new float[] { features[index].score, features[index].score };
702 if (mm[nonpos][0] > features[index].score)
704 mm[nonpos][0] = features[index].score;
706 if (mm[nonpos][1] < features[index].score)
708 mm[nonpos][1] = features[index].score;
715 updateRenderOrder(allfeatures);
716 findingFeatures = false;
719 protected Boolean firing = Boolean.FALSE;
722 * replaces the current renderOrder with the unordered features in
723 * allfeatures. The ordering of any types in both renderOrder and allfeatures
724 * is preserved, and all new feature types are rendered on top of the existing
725 * types, in the order given by getOrder or the order given in allFeatures.
726 * Note. this operates directly on the featureOrder hash for efficiency. TODO:
727 * eliminate the float storage for computing/recalling the persistent ordering
728 * New Cability: updates min/max for colourscheme range if its dynamic
731 private void updateRenderOrder(Vector allFeatures)
733 Vector allfeatures = new Vector(allFeatures);
734 String[] oldRender = renderOrder;
735 renderOrder = new String[allfeatures.size()];
736 Object mmrange,fc=null;
737 boolean initOrders = (featureOrder == null);
739 if (oldRender != null && oldRender.length > 0)
741 for (int j = 0; j < oldRender.length; j++)
743 if (oldRender[j] != null)
747 setOrder(oldRender[j], (1 - (1 + (float) j)
748 / (float) oldRender.length));
750 if (allfeatures.contains(oldRender[j]))
752 renderOrder[opos++] = oldRender[j]; // existing features always
753 // appear below new features
754 allfeatures.removeElement(oldRender[j]);
757 mmrange = minmax.get(oldRender[j]);
760 fc = featureColours.get(oldRender[j]);
761 if (fc!=null && fc instanceof GraduatedColor && ((GraduatedColor)fc).isAutoScale())
763 ((GraduatedColor) fc).updateBounds(((float[][])mmrange)[0][0],((float[][])mmrange)[0][1]);
771 if (allfeatures.size() == 0)
773 // no new features - leave order unchanged.
776 int i = allfeatures.size() - 1;
778 boolean sort = false;
779 String[] newf = new String[allfeatures.size()];
780 float[] sortOrder = new float[allfeatures.size()];
781 Enumeration en = allfeatures.elements();
782 // sort remaining elements
783 while (en.hasMoreElements())
785 newf[i] = en.nextElement().toString();
788 // update from new features minmax if necessary
789 mmrange = minmax.get(newf[i]);
792 fc = featureColours.get(newf[i]);
793 if (fc!=null && fc instanceof GraduatedColor && ((GraduatedColor)fc).isAutoScale())
795 ((GraduatedColor) fc).updateBounds(((float[][])mmrange)[0][0],((float[][])mmrange)[0][1]);
799 if (initOrders || !featureOrder.containsKey(newf[i]))
801 int denom = initOrders ? allfeatures.size() : featureOrder.size();
802 // new unordered feature - compute persistent ordering at head of
803 // existing features.
804 setOrder(newf[i], i / (float) denom);
806 // set order from newly found feature from persisted ordering.
807 sortOrder[i] = 2 - ((Float) featureOrder.get(newf[i])).floatValue();
810 // only sort if we need to
811 sort = sort || sortOrder[i] > sortOrder[i + 1];
815 if (iSize > 1 && sort)
817 jalview.util.QuickSort.sort(sortOrder, newf);
820 System.arraycopy(newf, 0, renderOrder, opos, newf.length);
823 * get a feature style object for the given type string.
824 * Creates a java.awt.Color for a featureType with no existing
826 * TODO: replace return type with object implementing standard abstract colour/style interface
828 * @return java.awt.Color or GraduatedColor
830 public Object getFeatureStyle(String featureType) {
831 Object fc = featureColours.get(featureType);
834 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();
835 Color col = ucs.createColourFromName(featureType);
836 featureColours.put(featureType, fc = col);
841 * return a nominal colour for this feature
843 * @return standard color, or maximum colour for graduated colourscheme
845 public Color getColour(String featureType)
847 Object fc = getFeatureStyle(featureType);
849 if (fc instanceof Color)
855 if (fc instanceof GraduatedColor)
857 return ((GraduatedColor) fc).getMaxColor();
860 throw new Error("Implementation Error: Unrecognised render object "+fc.getClass()+" for features of type "+featureType);
864 * calculate the render colour for a specific feature using current feature settings.
867 * @return render colour for the given feature
869 public Color getColour(SequenceFeature feature)
871 Object fc = getFeatureStyle(feature.getType());
872 if (fc instanceof Color)
878 if (fc instanceof GraduatedColor)
880 return ((GraduatedColor) fc).findColor(feature);
883 throw new Error("Implementation Error: Unrecognised render object "+fc.getClass()+" for features of type "+feature.getType());
885 private boolean showFeature(SequenceFeature sequenceFeature)
887 Object fc = getFeatureStyle(sequenceFeature.type);
888 if (fc instanceof GraduatedColor)
890 return ((GraduatedColor) fc).isColored(sequenceFeature);
891 } else { return true; }
895 static String lastFeatureAdded;
897 static String lastFeatureGroupAdded;
899 static String lastDescriptionAdded;
901 int featureIndex = 0;
903 boolean amendFeatures(final SequenceI[] sequences,
904 final SequenceFeature[] features, boolean newFeatures,
905 final AlignmentPanel ap)
910 final JPanel bigPanel = new JPanel(new BorderLayout());
911 final JComboBox overlaps;
912 final JTextField name = new JTextField(25);
913 final JTextField source = new JTextField(25);
914 final JTextArea description = new JTextArea(3, 25);
915 final JSpinner start = new JSpinner();
916 final JSpinner end = new JSpinner();
917 start.setPreferredSize(new Dimension(80, 20));
918 end.setPreferredSize(new Dimension(80, 20));
919 final FeatureRenderer me = this;
920 final JLabel colour = new JLabel();
921 colour.setOpaque(true);
922 //colour.setBorder(BorderFactory.createEtchedBorder());
923 colour.setMaximumSize(new Dimension(30, 16));
924 colour.addMouseListener(new MouseAdapter()
926 FeatureColourChooser fcc =null;
927 public void mousePressed(MouseEvent evt)
929 if (fcol instanceof Color)
931 Color col = JColorChooser.showDialog(Desktop.desktop,
932 "Select Feature Colour", ((Color)fcol));
936 updateColourButton(bigPanel,colour,col);
941 final String type = features[featureIndex].getType();
942 fcc = new FeatureColourChooser(me, type);
943 fcc.setRequestFocusEnabled(true);
946 fcc.addActionListener(new ActionListener() {
948 public void actionPerformed(ActionEvent e)
950 fcol = fcc.getLastColour();
952 setColour(type, fcol);
953 updateColourButton(bigPanel,colour,fcol);
962 JPanel tmp = new JPanel();
963 JPanel panel = new JPanel(new GridLayout(3, 1));
965 // /////////////////////////////////////
966 // /MULTIPLE FEATURES AT SELECTED RESIDUE
967 if (!newFeatures && features.length > 1)
969 panel = new JPanel(new GridLayout(4, 1));
971 tmp.add(new JLabel("Select Feature: "));
972 overlaps = new JComboBox();
973 for (int i = 0; i < features.length; i++)
975 overlaps.addItem(features[i].getType() + "/"
976 + features[i].getBegin() + "-" + features[i].getEnd()
977 + " (" + features[i].getFeatureGroup() + ")");
982 overlaps.addItemListener(new ItemListener()
984 public void itemStateChanged(ItemEvent e)
986 int index = overlaps.getSelectedIndex();
989 featureIndex = index;
990 name.setText(features[index].getType());
991 description.setText(features[index].getDescription());
992 source.setText(features[index].getFeatureGroup());
993 start.setValue(new Integer(features[index].getBegin()));
994 end.setValue(new Integer(features[index].getEnd()));
996 SearchResults highlight = new SearchResults();
997 highlight.addResult(sequences[0], features[index].getBegin(),
998 features[index].getEnd());
1000 ap.seqPanel.seqCanvas.highlightSearchResults(highlight);
1003 Object col = getFeatureStyle(name.getText());
1006 col = new jalview.schemes.UserColourScheme()
1007 .createColourFromName(name.getText());
1009 oldcol = fcol = col;
1010 updateColourButton(bigPanel, colour,col);
1017 // ////////////////////////////////////
1021 tmp.add(new JLabel("Name: ", JLabel.RIGHT));
1026 tmp.add(new JLabel("Group: ", JLabel.RIGHT));
1031 tmp.add(new JLabel("Colour: ", JLabel.RIGHT));
1033 colour.setPreferredSize(new Dimension(150, 15));
1035 bigPanel.add(panel, BorderLayout.NORTH);
1037 panel = new JPanel();
1038 panel.add(new JLabel("Description: ", JLabel.RIGHT));
1039 description.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
1040 description.setLineWrap(true);
1041 panel.add(new JScrollPane(description));
1045 bigPanel.add(panel, BorderLayout.SOUTH);
1047 panel = new JPanel();
1048 panel.add(new JLabel(" Start:", JLabel.RIGHT));
1050 panel.add(new JLabel(" End:", JLabel.RIGHT));
1052 bigPanel.add(panel, BorderLayout.CENTER);
1056 bigPanel.add(panel, BorderLayout.CENTER);
1059 if (lastFeatureAdded == null)
1061 if (features[0].type != null)
1063 lastFeatureAdded = features[0].type;
1067 lastFeatureAdded = "feature_1";
1071 if (lastFeatureGroupAdded == null)
1073 if (features[0].featureGroup != null)
1075 lastFeatureGroupAdded = features[0].featureGroup;
1079 lastFeatureGroupAdded = "Jalview";
1085 name.setText(lastFeatureAdded);
1086 source.setText(lastFeatureGroupAdded);
1090 name.setText(features[0].getType());
1091 source.setText(features[0].getFeatureGroup());
1094 start.setValue(new Integer(features[0].getBegin()));
1095 end.setValue(new Integer(features[0].getEnd()));
1096 description.setText(features[0].getDescription());
1097 updateColourButton(bigPanel, colour, (oldcol = fcol = getFeatureStyle(name.getText())));
1101 options = new Object[]
1102 { "Amend", "Delete", "Cancel" };
1106 options = new Object[]
1110 String title = newFeatures ? "Create New Sequence Feature(s)"
1111 : "Amend/Delete Features for " + sequences[0].getName();
1113 int reply = JOptionPane.showInternalOptionDialog(Desktop.desktop,
1114 bigPanel, title, JOptionPane.YES_NO_CANCEL_OPTION,
1115 JOptionPane.QUESTION_MESSAGE, null, options, "OK");
1117 jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile();
1119 if (reply == JOptionPane.OK_OPTION && name.getText().length() > 0)
1121 // This ensures that the last sequence
1122 // is refreshed and new features are rendered
1124 lastFeatureAdded = name.getText().trim();
1125 lastFeatureGroupAdded = source.getText().trim();
1126 lastDescriptionAdded = description.getText().replaceAll("\n", " ");
1128 if (lastFeatureGroupAdded.length() < 1)
1129 lastFeatureGroupAdded = null;
1134 SequenceFeature sf = features[featureIndex];
1136 if (reply == JOptionPane.NO_OPTION)
1138 sequences[0].getDatasetSequence().deleteFeature(sf);
1140 else if (reply == JOptionPane.YES_OPTION)
1142 sf.type = lastFeatureAdded;
1143 sf.featureGroup = lastFeatureGroupAdded;
1144 sf.description = lastDescriptionAdded;
1146 setColour(sf.type, fcol);
1147 av.featuresDisplayed.put(sf.type, getColour(sf.type));
1151 sf.begin = ((Integer) start.getValue()).intValue();
1152 sf.end = ((Integer) end.getValue()).intValue();
1153 } catch (NumberFormatException ex)
1157 ffile.parseDescriptionHTML(sf, false);
1161 // NEW FEATURES ADDED
1163 if (reply == JOptionPane.OK_OPTION && lastFeatureAdded.length() > 0)
1165 for (int i = 0; i < sequences.length; i++)
1167 features[i].type = lastFeatureAdded;
1168 if (lastFeatureGroupAdded != null)
1169 features[i].featureGroup = lastFeatureGroupAdded;
1170 features[i].description = lastDescriptionAdded;
1171 sequences[i].addSequenceFeature(features[i]);
1172 ffile.parseDescriptionHTML(features[i], false);
1175 if (av.featuresDisplayed == null)
1177 av.featuresDisplayed = new Hashtable();
1180 if (lastFeatureGroupAdded != null)
1182 if (featureGroups == null)
1183 featureGroups = new Hashtable();
1184 featureGroups.put(lastFeatureGroupAdded, new Boolean(true));
1186 setColour(lastFeatureAdded, fcol);
1187 av.featuresDisplayed.put(lastFeatureAdded, getColour(lastFeatureAdded));
1189 findAllFeatures(false);
1191 ap.paintAlignment(true);
1201 ap.paintAlignment(true);
1207 * update the amend feature button dependent on the given style
1212 protected void updateColourButton(JPanel bigPanel, JLabel colour, Object col2)
1215 colour.setIcon(null);
1216 colour.setToolTipText(null);
1218 if (col2 instanceof Color) {
1219 colour.setBackground((Color)col2);
1221 colour.setBackground(bigPanel.getBackground());
1222 colour.setForeground(bigPanel.getForeground());
1223 FeatureSettings.renderGraduatedColor(colour, (GraduatedColor) col2);
1224 //colour.setForeground(colour.getBackground());
1228 public void setColour(String featureType, Object col)
1231 // Color _col = (col instanceof Color) ? ((Color) col) : (col instanceof GraduatedColor) ? ((GraduatedColor) col).getMaxColor() : null;
1232 // Object c = featureColours.get(featureType);
1233 // if (c == null || c instanceof Color || (c instanceof GraduatedColor && !((GraduatedColor)c).getMaxColor().equals(_col)))
1235 featureColours.put(featureType, col);
1239 public void setTransparency(float value)
1241 transparency = value;
1244 public float getTransparency()
1246 return transparency;
1250 * Replace current ordering with new ordering
1253 * String(Type), Colour(Type), Boolean(Displayed) }
1255 public void setFeaturePriority(Object[][] data)
1257 setFeaturePriority(data, true);
1263 * String(Type), Colour(Type), Boolean(Displayed) }
1265 * when true current featureDisplay list will be cleared
1267 public void setFeaturePriority(Object[][] data, boolean visibleNew)
1271 if (av.featuresDisplayed != null)
1273 av.featuresDisplayed.clear();
1277 av.featuresDisplayed = new Hashtable();
1285 // The feature table will display high priority
1286 // features at the top, but theses are the ones
1287 // we need to render last, so invert the data
1288 renderOrder = new String[data.length];
1290 if (data.length > 0)
1292 for (int i = 0; i < data.length; i++)
1294 String type = data[i][0].toString();
1295 setColour(type, data[i][1]); // todo : typesafety - feature color interface object
1296 if (((Boolean) data[i][2]).booleanValue())
1298 av.featuresDisplayed.put(type, new Integer(getColour(type)
1302 renderOrder[data.length - i - 1] = type;
1308 Hashtable featureOrder = null;
1311 * analogous to colour - store a normalized ordering for all feature types in
1312 * this rendering context.
1315 * Feature type string
1317 * normalized priority - 0 means always appears on top, 1 means
1320 public float setOrder(String type, float position)
1322 if (featureOrder == null)
1324 featureOrder = new Hashtable();
1326 featureOrder.put(type, new Float(position));
1331 * get the global priority (0 (top) to 1 (bottom))
1334 * @return [0,1] or -1 for a type without a priority
1336 public float getOrder(String type)
1338 if (featureOrder != null)
1340 if (featureOrder.containsKey(type))
1342 return ((Float) featureOrder.get(type)).floatValue();
1350 * @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener)
1352 public void addPropertyChangeListener(PropertyChangeListener listener)
1354 changeSupport.addPropertyChangeListener(listener);
1359 * @see java.beans.PropertyChangeSupport#removePropertyChangeListener(java.beans.PropertyChangeListener)
1361 public void removePropertyChangeListener(PropertyChangeListener listener)
1363 changeSupport.removePropertyChangeListener(listener);