X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureRenderer.java;h=a1de62e32e04b55c9a784222d380eaad92610fe4;hb=5c57814f95e73a63e012479651b919fdc4099f53;hp=65d5f55848cc29277e8caecdfd8a16f4e0a66aa8;hpb=7c021ccc154d959f50d01090ee6a93abd79912a3;p=jalview.git diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index 65d5f55..a1de62e 100755 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -32,12 +32,13 @@ import jalview.datamodel.*; /** * DOCUMENT ME! - * + * * @author $author$ * @version $Revision$ */ public class FeatureRenderer { + AlignmentPanel ap; AlignViewport av; Color resBoxColour; float transparency = 1.0f; @@ -48,7 +49,7 @@ public class FeatureRenderer // A higher level for grouping features of a // particular type - Hashtable featureGroups = null; + Hashtable featureGroups = new Hashtable(); // This is actually an Integer held in the hashtable, // Retrieved using the key feature type @@ -57,24 +58,28 @@ public class FeatureRenderer String[] renderOrder; PropertyChangeSupport changeSupport=new PropertyChangeSupport(this); + Vector allfeatures; + /** * Creates a new FeatureRenderer object. - * + * * @param av * DOCUMENT ME! */ - public FeatureRenderer(AlignViewport av) + public FeatureRenderer(AlignmentPanel ap) { - this.av = av; + this.ap = ap; + this.av = ap.av; } + public void transferSettings(FeatureRenderer fr) { - renderOrder = fr.renderOrder; - featureGroups = fr.featureGroups; - featureColours = fr.featureColours; - transparency = fr.transparency; - featureOrder = fr.featureOrder; + this.renderOrder = fr.renderOrder; + this.featureGroups = fr.featureGroups; + this.featureColours = fr.featureColours; + this.transparency = fr.transparency; + this.featureOrder = fr.featureOrder; } BufferedImage offscreenImage; @@ -100,21 +105,21 @@ public class FeatureRenderer { lastSeq = seq; sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures(); - if (sequenceFeatures!=null) + if (sequenceFeatures!=null) { sfSize = sequenceFeatures.length; } } - + if (sequenceFeatures!=lastSeq.getDatasetSequence().getSequenceFeatures()) { sequenceFeatures = lastSeq.getDatasetSequence().getSequenceFeatures(); if (sequenceFeatures != null) { sfSize = sequenceFeatures.length; - } + } } - - if (sequenceFeatures == null) + + if (sequenceFeatures == null || sfSize==0) { return initialCol; } @@ -165,7 +170,7 @@ public class FeatureRenderer /** * DOCUMENT ME! - * + * * @param g * DOCUMENT ME! * @param seq @@ -191,9 +196,10 @@ public class FeatureRenderer SequenceFeature[] sequenceFeatures; int sfSize, sfindex, spos, epos; - public void drawSequence(Graphics g, SequenceI seq, + synchronized public void drawSequence(Graphics g, SequenceI seq, int start, int end, int y1) { + if (seq.getDatasetSequence().getSequenceFeatures() == null || seq.getDatasetSequence().getSequenceFeatures().length == 0) { @@ -216,7 +222,6 @@ public class FeatureRenderer } sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures(); - sfSize = sequenceFeatures.length; } if (lastSeq == null || seq != lastSeq @@ -224,7 +229,6 @@ public class FeatureRenderer { lastSeq = seq; sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures(); - sfSize = sequenceFeatures.length; } if (transparency != 1 && g != null) @@ -241,6 +245,7 @@ public class FeatureRenderer epos = lastSeq.findPosition(end); } + sfSize = sequenceFeatures.length; String type; for (int renderIndex = 0; renderIndex < renderOrder.length; renderIndex++) { @@ -255,10 +260,6 @@ public class FeatureRenderer // current feature to render for (sfindex = 0; sfindex < sfSize; sfindex++) { - if (sequenceFeatures.length <= sfindex) - { - continue; - } if (!sequenceFeatures[sfindex].type.equals(type)) { continue; @@ -267,7 +268,8 @@ public class FeatureRenderer if (featureGroups != null && sequenceFeatures[sfindex].featureGroup != null && - featureGroups.containsKey(sequenceFeatures[sfindex].featureGroup) + sequenceFeatures[sfindex].featureGroup.length()!=0 + && featureGroups.containsKey(sequenceFeatures[sfindex].featureGroup) && ! ( (Boolean) featureGroups.get(sequenceFeatures[sfindex]. featureGroup)). @@ -393,20 +395,23 @@ public class FeatureRenderer /** * search the alignment for all new features, give them a colour and display * them. Then fires a PropertyChangeEvent on the changeSupport object. - * + * */ - synchronized void findAllFeatures() + void findAllFeatures() { - findAllFeatures(true); // add all new features as visible - if (!newFeatureAdded && !firing) { - firing=true; - changeSupport.firePropertyChange("changeSupport",null,null); - firing=false; + synchronized (firing) + { + if (firing.equals(Boolean.FALSE)) { + firing=Boolean.TRUE; + findAllFeatures(true); // add all new features as visible + changeSupport.firePropertyChange("changeSupport",null,null); + firing=Boolean.FALSE; + } } } /** * Searches alignment for all features and updates colours - * + * * @param newMadeVisible * if true newly added feature types will be rendered immediatly */ @@ -426,9 +431,9 @@ public class FeatureRenderer av.featuresDisplayed = new Hashtable(); } - Vector allfeatures = new Vector(); + allfeatures = new Vector(); Vector oldfeatures = new Vector(); - if (renderOrder!=null) + if (renderOrder!=null) { for (int i=0; i0) { - for (int j=0; i1 && sort) jalview.util.QuickSort.sort(sortOrder, newf); sortOrder=null; System.arraycopy(newf, 0, renderOrder, opos, newf.length); } public Color getColour(String featureType) { - Color colour = (Color) featureColours.get(featureType); - if (colour == null) + if (!featureColours.containsKey(featureType)) { jalview.schemes.UserColourScheme ucs = new - jalview.schemes.UserColourScheme(); - featureColours.put(featureType, - colour=ucs.createColourFromName(featureType)); + jalview.schemes.UserColourScheme(); + Color col = ucs.createColourFromName(featureType); + featureColours.put(featureType, col); + return col; } - return colour; + else + return (Color) featureColours.get(featureType); } static String lastFeatureAdded; static String lastFeatureGroupAdded; static String lastDescriptionAdded; - public boolean createNewFeatures(SequenceI[] sequences, - SequenceFeature[] features) - { - return amendFeatures(sequences, features, true, null); - } - int featureIndex = 0; boolean amendFeatures(final SequenceI[] sequences, final SequenceFeature[] features, boolean newFeatures, final AlignmentPanel ap) { + + featureIndex = 0; + JPanel bigPanel = new JPanel(new BorderLayout()); - final JComboBox name = new JComboBox(); - final JComboBox source = new JComboBox(); + final JComboBox overlaps; + final JTextField name = new JTextField(25); + final JTextField source = new JTextField(25); final JTextArea description = new JTextArea(3, 25); final JSpinner start = new JSpinner(); final JSpinner end = new JSpinner(); start.setPreferredSize(new Dimension(80, 20)); end.setPreferredSize(new Dimension(80, 20)); + final JPanel colour = new JPanel(); colour.setBorder(BorderFactory.createEtchedBorder()); colour.setMaximumSize(new Dimension(40, 10)); @@ -592,27 +611,93 @@ public class FeatureRenderer { public void mousePressed(MouseEvent evt) { - colour.setBackground( - JColorChooser.showDialog(Desktop.desktop, - "Select Feature Colour", - colour.getBackground())); + Color col = JColorChooser.showDialog(Desktop.desktop, + "Select Feature Colour", + colour.getBackground()); + if (col != null) + colour.setBackground(col); + } }); - JPanel panel = new JPanel(new GridLayout(3, 2)); - panel.add(new JLabel("Sequence Feature Name: ", JLabel.RIGHT)); - panel.add(name); - panel.add(new JLabel("Feature Group: ", JLabel.RIGHT)); - panel.add(source); - panel.add(new JLabel("Feature Colour: ", JLabel.RIGHT)); JPanel tmp = new JPanel(); + JPanel panel = new JPanel(new GridLayout(3, 1)); + + /////////////////////////////////////// + ///MULTIPLE FEATURES AT SELECTED RESIDUE + if(!newFeatures && features.length>1) + { + panel = new JPanel(new GridLayout(4, 1)); + tmp = new JPanel(); + tmp.add(new JLabel("Select Feature: ")); + overlaps = new JComboBox(); + for(int i=0; i0) { // This ensures that the last sequence // is refreshed and new features are rendered lastSeq = null; - lastFeatureAdded = name.getSelectedItem().toString(); - lastFeatureGroupAdded = source.getSelectedItem().toString(); + lastFeatureAdded = name.getText().trim(); + lastFeatureGroupAdded = source.getText().trim(); lastDescriptionAdded = description.getText().replaceAll("\n", " "); + + if(lastFeatureGroupAdded.length()<1) + lastFeatureGroupAdded = null; } if (!newFeatures) @@ -800,7 +815,11 @@ public class FeatureRenderer sf.type = lastFeatureAdded; sf.featureGroup = lastFeatureGroupAdded; sf.description = lastDescriptionAdded; + setColour(sf.type, colour.getBackground()); + av.featuresDisplayed.put(sf.type, + new Integer(colour.getBackground().getRGB())); + try { sf.begin = ( (Integer) start.getValue()).intValue(); @@ -812,16 +831,16 @@ public class FeatureRenderer ffile.parseDescriptionHTML(sf, false); } } - else + else //NEW FEATURES ADDED { if (reply == JOptionPane.OK_OPTION - && name.getSelectedItem() != null - && source.getSelectedItem() != null) + && lastFeatureAdded.length()>0) { for (int i = 0; i < sequences.length; i++) { features[i].type = lastFeatureAdded; - features[i].featureGroup = lastFeatureGroupAdded; + if (lastFeatureGroupAdded!=null) + features[i].featureGroup = lastFeatureGroupAdded; features[i].description = lastDescriptionAdded; sequences[i].addSequenceFeature(features[i]); ffile.parseDescriptionHTML(features[i], false); @@ -832,20 +851,22 @@ public class FeatureRenderer av.featuresDisplayed = new Hashtable(); } - if (featureGroups == null) + if (lastFeatureGroupAdded != null) { - featureGroups = new Hashtable(); + if (featureGroups == null) + featureGroups = new Hashtable(); + featureGroups.put(lastFeatureGroupAdded, new Boolean(true)); } - featureGroups.put(lastFeatureGroupAdded, new Boolean(true)); - Color col = colour.getBackground(); setColour(lastFeatureAdded, colour.getBackground()); + av.featuresDisplayed.put(lastFeatureAdded, + new Integer(col.getRGB())); - av.featuresDisplayed.put(lastFeatureGroupAdded, - new Integer(col.getRGB())); + findAllFeatures(false); + + ap.paintAlignment(true); - findAllFeatures(); return true; } @@ -855,10 +876,7 @@ public class FeatureRenderer } } - if (name.getSelectedIndex() == -1) - { - findAllFeatures(); - } + ap.paintAlignment(true); return true; } @@ -886,7 +904,7 @@ public class FeatureRenderer setFeaturePriority(data, true); } /** - * + * * @param data { String(Type), Colour(Type), Boolean(Displayed) } * @param visibleNew when true current featureDisplay list will be cleared */ @@ -903,11 +921,11 @@ public class FeatureRenderer av.featuresDisplayed = new Hashtable(); } } - if (data==null) + if (data==null) { return; } - + // The feature table will display high priority // features at the top, but theses are the ones // we need to render last, so invert the data @@ -933,7 +951,7 @@ public class FeatureRenderer /** * analogous to colour - store a normalized ordering for all feature types in * this rendering context. - * + * * @param type * Feature type string * @param position @@ -942,7 +960,7 @@ public class FeatureRenderer */ public float setOrder(String type, float position) { - if (featureOrder==null) + if (featureOrder==null) { featureOrder = new Hashtable(); } @@ -951,12 +969,12 @@ public class FeatureRenderer } /** * get the global priority (0 (top) to 1 (bottom)) - * + * * @param type * @return [0,1] or -1 for a type without a priority */ public float getOrder(String type) { - if (featureOrder!=null) + if (featureOrder!=null) { if (featureOrder.containsKey(type)) {