X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureRenderer.java;h=b643efbfeab1aa14cfa8321694f0c588ece4678f;hb=d8d676a2af8f486688b1c1778466c52500a65f81;hp=c59ec1d34de071d39f97795e610146f7e63dfeb7;hpb=4f1f764c09427cd63c3e355fa729da86735a8194;p=jalview.git diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index c59ec1d..b643efb 100755 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -38,6 +38,7 @@ import jalview.datamodel.*; */ 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 @@ -65,18 +66,57 @@ public class FeatureRenderer * @param av * DOCUMENT ME! */ - public FeatureRenderer(AlignViewport av) + public FeatureRenderer(AlignmentPanel ap) { - this.av = av; + this.ap = ap; + this.av = ap.av; } + public class FeatureRendererSettings implements Cloneable { + String[] renderOrder; + Hashtable featureGroups; + Hashtable featureColours; + float transparency; + Hashtable featureOrder; + public FeatureRendererSettings(String[] renderOrder, + Hashtable featureGroups, Hashtable featureColours, + float transparency, Hashtable featureOrder) + { + super(); + this.renderOrder = renderOrder; + this.featureGroups = featureGroups; + this.featureColours = featureColours; + this.transparency = transparency; + this.featureOrder = featureOrder; + } + public FeatureRendererSettings(FeatureRenderer fr) + { + this.renderOrder = fr.renderOrder; + this.featureGroups = fr.featureGroups; + this.featureColours = fr.featureColours; + this.transparency = fr.transparency; + this.featureOrder = fr.featureOrder; + } + } + public FeatureRendererSettings getSettings() + { + return new FeatureRendererSettings(this); + } + public void transferSettings(FeatureRendererSettings fr) + { + this.renderOrder = fr.renderOrder; + this.featureGroups = fr.featureGroups; + this.featureColours = fr.featureColours; + this.transparency = fr.transparency; + this.featureOrder = fr.featureOrder; + } 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; @@ -116,7 +156,7 @@ public class FeatureRenderer } } - if (sequenceFeatures == null) + if (sequenceFeatures == null || sfSize==0) { return initialCol; } @@ -193,9 +233,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) { @@ -218,7 +259,6 @@ public class FeatureRenderer } sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures(); - sfSize = sequenceFeatures.length; } if (lastSeq == null || seq != lastSeq @@ -226,7 +266,6 @@ public class FeatureRenderer { lastSeq = seq; sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures(); - sfSize = sequenceFeatures.length; } if (transparency != 1 && g != null) @@ -243,6 +282,7 @@ public class FeatureRenderer epos = lastSeq.findPosition(end); } + sfSize = sequenceFeatures.length; String type; for (int renderIndex = 0; renderIndex < renderOrder.length; renderIndex++) { @@ -257,10 +297,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; @@ -269,7 +305,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)). @@ -397,13 +434,16 @@ public class FeatureRenderer * them. Then fires a PropertyChangeEvent on the changeSupport object. * */ - synchronized void findAllFeatures() + void findAllFeatures() { - findAllFeatures(true); // add all new features as visible - if (!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; + } } } /** @@ -455,6 +495,20 @@ public class FeatureRenderer { if (!av.featuresDisplayed.containsKey(features[index].getType())) { + + if(featureGroups.containsKey(features[index].getType())) + { + boolean visible = ( (Boolean) featureGroups.get( + features[index].featureGroup)).booleanValue(); + + if(!visible) + { + index++; + continue; + } + } + + if (! (features[index].begin == 0 && features[index].end == 0)) { // If beginning and end are 0, the feature is for the whole sequence @@ -480,7 +534,7 @@ public class FeatureRenderer updateRenderOrder(allfeatures); findingFeatures = false; } - protected boolean firing=false; + protected Boolean firing=Boolean.FALSE; /** * replaces the current renderOrder with the unordered features in allfeatures. * The ordering of any types in both renderOrder and allfeatures is preserved, @@ -552,7 +606,7 @@ public class FeatureRenderer } public Color getColour(String featureType) { - if (featureColours.get(featureType) == null) + if (!featureColours.containsKey(featureType)) { jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(); @@ -568,19 +622,12 @@ public class FeatureRenderer 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) { - findAllFeatures(); featureIndex = 0; @@ -601,10 +648,12 @@ 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); + } }); @@ -803,7 +852,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(); @@ -815,16 +868,16 @@ public class FeatureRenderer ffile.parseDescriptionHTML(sf, false); } } - else + else //NEW FEATURES ADDED { if (reply == JOptionPane.OK_OPTION - && name.getText() != null - && source.getText() != 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); @@ -835,22 +888,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)); } - Color col = colour.getBackground(); setColour(lastFeatureAdded, colour.getBackground()); - - if(lastFeatureGroupAdded!=null) - { - featureGroups.put(lastFeatureGroupAdded, new Boolean(true)); - av.featuresDisplayed.put(lastFeatureGroupAdded, + av.featuresDisplayed.put(lastFeatureAdded, new Integer(col.getRGB())); - } - findAllFeatures(); + + findAllFeatures(false); + + ap.paintAlignment(true); + return true; } @@ -860,7 +913,7 @@ public class FeatureRenderer } } - findAllFeatures(); + ap.paintAlignment(true); return true; }