From: amwaterhouse Date: Mon, 31 Oct 2005 15:56:03 +0000 (+0000) Subject: Display only selected features X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=32a503462f876bc1b5c556386ded6e682417d790;p=jalview.git Display only selected features --- diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index f315df6..372ecd7 100755 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -68,31 +68,74 @@ public class FeatureRenderer * @param width DOCUMENT ME! * @param height DOCUMENT ME! */ - public void drawSequence(Graphics g1, SequenceI seq, SequenceGroup[] sg, - int start, int end, int x1, int y1, int width, int height) + public void drawSequence(Graphics g, SequenceI seq, + int start, int end, int x1, int y1, int width, int height) { - if(seq.getSequenceFeatures()==null) - return; + if (seq.getDatasetSequence().getSequenceFeatures() == null) + return; - Enumeration e = null, e2; - String type; - if(featuresDisplayed!=null) - e = featuresDisplayed.elements(); - else - e = seq.getSequenceFeatures().elements(); - - Graphics2D g = (Graphics2D)g1; - g.setComposite( - AlphaComposite.getInstance( - AlphaComposite.SRC_OVER,transparency)); + if (transparency != 1) + { + Graphics2D g2 = (Graphics2D) g; + g2.setComposite( + AlphaComposite.getInstance( + AlphaComposite.SRC_OVER, transparency)); + } + Enumeration e, e2; + String type; + SequenceFeature sf; + if (featuresDisplayed != null) + { + e = featuresDisplayed.elements(); + while(e.hasMoreElements()) + { + type = e.nextElement().toString(); + e2 = seq.getDatasetSequence().getSequenceFeatures().elements(); + while(e2.hasMoreElements()) + { + sf = (SequenceFeature) e2.nextElement(); + if(!type.equals(sf.getType() ) ) + continue; + + if (sf.getBegin() > seq.getEnd()) + continue; + + renderFeature(g,seq, + seq.findIndex(sf.getBegin()) - 1, + seq.findIndex(sf.getEnd()) - 1, + type,start,end,x1,y1,width,height); + } + } + } + else + { + e = seq.getDatasetSequence().getSequenceFeatures().elements(); while (e.hasMoreElements()) { + sf = (SequenceFeature) e.nextElement(); + type = sf.getType(); + + if (sf.getBegin() > seq.getEnd()) + { + continue; + } + + renderFeature(g,seq, + seq.findIndex(sf.getBegin()) - 1, + seq.findIndex(sf.getEnd()) - 1, + type,start,end,x1,y1,width,height); + + } + } + + /* while (e.hasMoreElements()) + { SequenceFeature sf=null; if(featuresDisplayed!=null) { - e2 = seq.getSequenceFeatures().elements(); + e2 = seq.getDatasetSequence().getSequenceFeatures().elements(); type = e.nextElement().toString(); while(e2.hasMoreElements()) { @@ -120,64 +163,72 @@ public class FeatureRenderer int fstart = seq.findIndex(sf.getBegin()) - 1; int fend = seq.findIndex(sf.getEnd()) - 1; +*/ - if (((fstart <= end) && (fend >= start))) - { - if (fstart < start) - { // fix for if the feature we have starts before the sequence start, - fstart = start; // but the feature end is still valid!! - } - - if (fend >= end) - { - fend = end; - } - - if (fstart == fend) - { - g.setColor(getColour(type)); - g.fillRoundRect((fstart - start) * width, y1, width, - height, 4, 4); - g.setColor(Color.white); - - char s = seq.getSequence().charAt(fstart); - FontMetrics fm = g.getFontMetrics(); - int charOffset = (width - fm.charWidth(s)) / 2; - int pady = height / 5; - g.drawString(String.valueOf(s), - charOffset + x1 + (width * (fstart - start)), - (y1 + height) - pady); - } - else - { - for (int i = fstart; i <= fend; i++) - { - char s = seq.getSequence().charAt(i); - - if (jalview.util.Comparison.isGap(s)) - { - continue; - } - - g.setColor(getColour(type)); - g.fillRect((i - start) * width, y1, width, height); - - g.setColor(Color.white); - - FontMetrics fm = g.getFontMetrics(); - int charOffset = (width - fm.charWidth(s)) / 2; - int pady = height / 5; - g.drawString(String.valueOf(s), - charOffset + x1 + (width * (i - start)), - (y1 + height) - pady); - } - } - } + if(transparency!=1.0f) + { + Graphics2D g2 = (Graphics2D) g; + g2.setComposite( + AlphaComposite.getInstance( + AlphaComposite.SRC_OVER, 1.0f)); } - g.setComposite( - AlphaComposite.getInstance( - AlphaComposite.SRC_OVER,1.0f)); + } + void renderFeature(Graphics g, SequenceI seq, + int fstart, int fend, String type, int start, int end, int x1, int y1, int width, int height) + { + if (((fstart <= end) && (fend >= start))) + { + if (fstart < start) + { // fix for if the feature we have starts before the sequence start, + fstart = start; // but the feature end is still valid!! + } + + if (fend >= end) + { + fend = end; + } + + if (fstart == fend) + { + g.setColor(getColour(type)); + g.fillRoundRect((fstart - start) * width, y1, width, + height, 4, 4); + g.setColor(Color.white); + + char s = seq.getSequence().charAt(fstart); + FontMetrics fm = g.getFontMetrics(); + int charOffset = (width - fm.charWidth(s)) / 2; + int pady = height / 5; + g.drawString(String.valueOf(s), + charOffset + x1 + (width * (fstart - start)), + (y1 + height) - pady); + } + else + { + for (int i = fstart; i <= fend; i++) + { + char s = seq.getSequence().charAt(i); + + if (jalview.util.Comparison.isGap(s)) + { + continue; + } + + g.setColor(getColour(type)); + g.fillRect((i - start) * width, y1, width, height); + + g.setColor(Color.white); + + FontMetrics fm = g.getFontMetrics(); + int charOffset = (width - fm.charWidth(s)) / 2; + int pady = height / 5; + g.drawString(String.valueOf(s), + charOffset + x1 + (width * (i - start)), + (y1 + height) - pady); + } + } + } } public Color getColour(String featureType) diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index fd413e0..28cb295 100755 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -8,7 +8,6 @@ import java.util.*; import javax.swing.BorderFactory; import java.awt.event.*; import javax.swing.table.*; -import java.io.*; public class FeatureSettings extends JPanel { @@ -24,7 +23,7 @@ public class FeatureSettings extends JPanel av.alignment.getSequences(); final JInternalFrame frame = new JInternalFrame(); frame.setContentPane(this); - Desktop.addInternalFrame(frame, "Sequence Feature Settings", 500, 300); + Desktop.addInternalFrame(frame, "Sequence Feature Settings", 400, 300); Vector allFeatures = new Vector(); @@ -32,10 +31,9 @@ public class FeatureSettings extends JPanel Enumeration e; SequenceFeature sf; - for(int i=0; i< av.alignment.getHeight(); i++) { - features = av.alignment.getSequenceAt(i).getSequenceFeatures(); + features = av.alignment.getSequenceAt(i).getDatasetSequence().getSequenceFeatures(); if(features==null) continue; @@ -68,10 +66,18 @@ public class FeatureSettings extends JPanel Color col = fr.getColour(type); data[i][0]=type; data[i][1]=col; - data[i][2]= new Boolean(true); + if(fr.featuresDisplayed!=null) + data[i][2] = new Boolean(fr.featuresDisplayed.contains(type)); + else + data[i][2] = new Boolean(true); + originalData[i][0]=type; originalData[i][1]=col; - originalData[i][2]= new Boolean(true); + if(fr.featuresDisplayed!=null) + originalData[i][2] = new Boolean(fr.featuresDisplayed.contains(type)); + else + originalData[i][2] = new Boolean(true); + } final JSlider transparency = new JSlider(0,70,0); @@ -102,6 +108,8 @@ public class FeatureSettings extends JPanel table.setDefaultEditor(Color.class, new ColorEditor()); + table.getColumnModel().getColumn(0).setPreferredWidth(200); + table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.addMouseListener(new MouseAdapter()