From 449001e7a8c9aad77117daa36567f3e8313646ea Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Wed, 15 Feb 2006 15:18:21 +0000 Subject: [PATCH] Feature Groups added --- src/jalview/appletgui/FeatureRenderer.java | 21 +++++ src/jalview/appletgui/FeatureSettings.java | 140 ++++++++++++++++++---------- 2 files changed, 110 insertions(+), 51 deletions(-) diff --git a/src/jalview/appletgui/FeatureRenderer.java b/src/jalview/appletgui/FeatureRenderer.java index 091a127..fae19e8 100755 --- a/src/jalview/appletgui/FeatureRenderer.java +++ b/src/jalview/appletgui/FeatureRenderer.java @@ -41,6 +41,10 @@ public class FeatureRenderer // to be added, in the correct order or rendering Vector featuresDisplayed; + // A higher level for grouping features of a + // paritcular type + Hashtable featureGroups = null; + Color currentColour = null; boolean drawText = true; @@ -113,6 +117,14 @@ public class FeatureRenderer if(sf==null) continue; + if(featureGroups!=null + && sf.getFeatureGroup()!=null + && featureGroups.containsKey(sf.getFeatureGroup()) + && !((Boolean)featureGroups.get(sf.getFeatureGroup())).booleanValue()) + { + continue; + } + if (sf.getBegin() > seq.getEnd()) { @@ -211,6 +223,15 @@ public class FeatureRenderer featureColours.put(featureType, col); } + public void addNewFeature(String name, Color col) + { + setColour(name, col); + if (featuresDisplayed == null) + featuresDisplayed = new Vector(); + featuresDisplayed.insertElementAt(name, 0); + } + + /* public void setTransparency(float value) { transparency = value; diff --git a/src/jalview/appletgui/FeatureSettings.java b/src/jalview/appletgui/FeatureSettings.java index 4d0f25e..30d57e0 100755 --- a/src/jalview/appletgui/FeatureSettings.java +++ b/src/jalview/appletgui/FeatureSettings.java @@ -31,6 +31,8 @@ public class FeatureSettings extends Panel implements ItemListener, final AlignmentPanel ap; final AlignViewport av; final Frame frame; + Panel groupPanel; + Panel featurePanel = new Panel(); public FeatureSettings(AlignViewport av, final AlignmentPanel ap) { @@ -40,9 +42,22 @@ public class FeatureSettings extends Panel implements ItemListener, setTableData(); + this.setLayout(new BorderLayout()); + ScrollPane sp = new ScrollPane(); + sp.add(featurePanel); + add(sp, BorderLayout.CENTER); + if(groupPanel!=null) + { + sp = new ScrollPane(); + sp.add(groupPanel); + + add(sp, BorderLayout.NORTH); + sp.validate(); + sp.setSize( 100, 55); + } frame = new Frame(); frame.add(this); - int height = this.getComponentCount()*50; + int height = featurePanel.getComponentCount()*50 ; if (height>400) height = 400; @@ -52,70 +67,92 @@ public class FeatureSettings extends Panel implements ItemListener, void setTableData() { + if(fr.featureGroups==null) + fr.featureGroups = new Hashtable(); + else + fr.featureGroups.clear(); + Vector allFeatures = new Vector(); - Vector features; - Enumeration e; + Enumeration tmpfeatures; SequenceFeature sf; for (int i = 0; i < av.alignment.getHeight(); i++) { - features = av.alignment.getSequenceAt(i).getSequenceFeatures(); - if (features == null) + if (av.alignment.getSequenceAt(i).getSequenceFeatures() == null) continue; - e = features.elements(); - while (e.hasMoreElements()) + tmpfeatures = av.alignment.getSequenceAt(i).getSequenceFeatures().elements(); + while (tmpfeatures.hasMoreElements()) { - sf = (SequenceFeature) e.nextElement(); + sf = (SequenceFeature) tmpfeatures.nextElement(); if (!allFeatures.contains(sf.getType())) { allFeatures.addElement(sf.getType()); + Color col = fr.getColour(sf.getType()); + boolean displayed = true; + if (fr.featuresDisplayed != null) + displayed = fr.featuresDisplayed.contains(sf.getType()); + + Checkbox check = new Checkbox(sf.getType(), displayed); + check.addMouseListener(this); + check.addMouseMotionListener(this); + check.setBackground(col); + check.addItemListener(this); + featurePanel.add(check); + } + if(sf.getFeatureGroup()!=null + && !fr.featureGroups.containsKey(sf.getFeatureGroup())) + { + fr.featureGroups.put(sf.getFeatureGroup(), new Boolean(true)); + if(groupPanel==null) + groupPanel = new Panel(); + + Checkbox check = new Checkbox(sf.getFeatureGroup(), true); + check.setFont(new Font("Serif", Font.BOLD, 12)); + check.addItemListener(this); + groupPanel.add(check); } } } - int fSize = allFeatures.size(); - - String type; - this.setLayout(new GridLayout(fSize, 2, 10,5)); - - for (int i = 0; i < fSize; i++) - { - type = allFeatures.elementAt(i).toString(); - Color col = fr.getColour(type); - boolean displayed = true; - if(fr.featuresDisplayed!=null) - displayed = fr.featuresDisplayed.contains(type); - - Checkbox check = new Checkbox(type, displayed); - check.addMouseListener(this); - check.addMouseMotionListener(this); - check.setBackground(col); - check.addItemListener(this); - add(check); - } - validate(); + featurePanel.setLayout(new GridLayout(allFeatures.size(), 2, 10,5)); + featurePanel.validate(); } public void itemStateChanged(ItemEvent evt) { - Component [] comps = this.getComponents(); - int cSize = comps.length; - - Object [][] data = new Object[cSize][3]; - - for(int i=0; i this.getSize().height) { - comp = this.getComponent(this.getComponentCount()-1); + comp = featurePanel.getComponent(featurePanel.getComponentCount()-1); } else if(height < 0) { - comp = this.getComponent(0); + comp = featurePanel.getComponent(0); } else { - comp = this.getComponentAt(evt.getX(), + comp = featurePanel.getComponentAt(evt.getX(), evt.getY() + evt.getComponent().getLocation().y); } @@ -159,16 +197,16 @@ public class FeatureSettings extends Panel implements ItemListener, if (selectedCheck != null && target != null && selectedCheck != target) { int targetIndex = -1; - for(int i=0; i