From 1d37661bae76ec6d499ff50a88ea249b8b33430e Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 9 Feb 2006 16:48:57 +0000 Subject: [PATCH] Feature Settings added to Applet --- src/jalview/appletgui/AlignFrame.java | 26 +++- src/jalview/appletgui/FeatureSettings.java | 178 ++++++++++++++++++++++++++++ 2 files changed, 202 insertions(+), 2 deletions(-) create mode 100755 src/jalview/appletgui/FeatureSettings.java diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index bd49198..fbe21b5 100755 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -203,6 +203,10 @@ public class AlignFrame extends Frame implements ActionListener, } viewport.showSequenceFeatures = true; + viewMenu.addSeparator(); + viewMenu.add(sequenceFeatures); + viewMenu.add(featureSettings); + alignPanel.repaint(); @@ -289,6 +293,10 @@ public void itemStateChanged(ItemEvent evt) renderGapsMenuItem_actionPerformed(); else if(evt.getSource()==annotationPanelMenuItem) annotationPanelMenuItem_actionPerformed(); + else if(evt.getSource()==sequenceFeatures) + { viewport.showSequenceFeatures(sequenceFeatures.getState()); + alignPanel.seqPanel.seqCanvas.repaint(); + } else if(evt.getSource()==conservationMenuItem) conservationMenuItem_actionPerformed(); else if(evt.getSource()==abovePIDThreshold) @@ -346,6 +354,8 @@ public void itemStateChanged(ItemEvent evt) findMenuItem_actionPerformed(); else if(evt.getSource()==font) font_actionPerformed(); + else if(evt.getSource()==featureSettings) + featureSettings_actionPerformed(); else if(evt.getSource()==overviewMenuItem) overviewMenuItem_actionPerformed(); else if(evt.getSource()==noColourmenuItem) @@ -1116,6 +1126,11 @@ public void itemStateChanged(ItemEvent evt) alignPanel.setAnnotationVisible(annotationPanelMenuItem.getState()); } + public void featureSettings_actionPerformed() + { + new FeatureSettings(viewport, alignPanel); + } + public void overviewMenuItem_actionPerformed() { if (alignPanel.overviewPanel != null) @@ -1904,6 +1919,11 @@ public void itemStateChanged(ItemEvent evt) seqLimits.setState(true); seqLimits.setLabel("Show Sequence Limits"); seqLimits.addItemListener(this); + featureSettings.setLabel("Feature Settings..."); + featureSettings.addActionListener(this); + sequenceFeatures.setLabel("Sequence Features"); + sequenceFeatures.addItemListener(this); + sequenceFeatures.setState(true); alignFrameMenuBar.add(fileMenu); alignFrameMenuBar.add(editMenu); @@ -1936,7 +1956,7 @@ public void itemStateChanged(ItemEvent evt) searchMenu.add(findMenuItem); viewMenu.add(font); viewMenu.addSeparator(); - viewMenu.add(seqLimits); + viewMenu.add(seqLimits); viewMenu.addSeparator(); viewMenu.add(wrapMenuItem); viewMenu.add(scaleAbove); @@ -1948,7 +1968,7 @@ public void itemStateChanged(ItemEvent evt) viewMenu.add(colourTextMenuItem); viewMenu.add(renderGapsMenuItem); viewMenu.add(annotationPanelMenuItem); - viewMenu.addSeparator(); + viewMenu.addSeparator(); viewMenu.add(overviewMenuItem); colourMenu.add(applyToAllGroups); colourMenu.addSeparator(); @@ -2057,6 +2077,8 @@ public void itemStateChanged(ItemEvent evt) PopupMenu filePopup, editPopup, searchPopup, viewPopup, colourPopup, calculatePopup, helpPopup; + MenuItem featureSettings = new MenuItem(); + CheckboxMenuItem sequenceFeatures = new CheckboxMenuItem(); public void mousePressed(MouseEvent evt) { diff --git a/src/jalview/appletgui/FeatureSettings.java b/src/jalview/appletgui/FeatureSettings.java new file mode 100755 index 0000000..e01615a --- /dev/null +++ b/src/jalview/appletgui/FeatureSettings.java @@ -0,0 +1,178 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ +package jalview.appletgui; + +import jalview.datamodel.*; +import java.awt.*; +import java.util.*; +import java.awt.event.*; + + +public class FeatureSettings extends Panel implements ItemListener, + MouseListener, MouseMotionListener +{ + final FeatureRenderer fr; + final AlignmentPanel ap; + final AlignViewport av; + final Frame frame; + + public FeatureSettings(AlignViewport av, final AlignmentPanel ap) + { + this.ap = ap; + this.av = av; + fr = ap.seqPanel.seqCanvas.getFeatureRenderer(); + + setTableData(); + + frame = new Frame(); + frame.add(this); + int height = this.getComponentCount()*50; + if (height>400) + height = 400; + + jalview.bin.JalviewLite.addFrame(frame, "Feature Settings", 200, + height); + } + + void setTableData() + { + Vector allFeatures = new Vector(); + Vector features; + Enumeration e; + SequenceFeature sf; + + for (int i = 0; i < av.alignment.getHeight(); i++) + { + features = av.alignment.getSequenceAt(i).getSequenceFeatures(); + if (features == null) + continue; + + e = features.elements(); + while (e.hasMoreElements()) + { + sf = (SequenceFeature) e.nextElement(); + if (!allFeatures.contains(sf.getType())) + { + allFeatures.addElement(sf.getType()); + } + } + } + + 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(); + } + + 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); + } + else if(height < 0) + { + comp = this.getComponent(0); + } + else + { + comp = this.getComponentAt(evt.getX(), + evt.getY() + + evt.getComponent().getLocation().y); + } + + if(comp!=null && comp instanceof Checkbox) + target = (Checkbox)comp; + + if (selectedCheck != null && target != null && selectedCheck != target) + { + int targetIndex = -1; + for(int i=0; i