Feature Settings added to Applet
authoramwaterhouse <Andrew Waterhouse>
Thu, 9 Feb 2006 16:48:57 +0000 (16:48 +0000)
committeramwaterhouse <Andrew Waterhouse>
Thu, 9 Feb 2006 16:48:57 +0000 (16:48 +0000)
src/jalview/appletgui/AlignFrame.java
src/jalview/appletgui/FeatureSettings.java [new file with mode: 0755]

index bd49198..fbe21b5 100755 (executable)
@@ -203,6 +203,10 @@ public class AlignFrame extends Frame implements ActionListener,
       }\r
 \r
       viewport.showSequenceFeatures = true;\r
+      viewMenu.addSeparator();\r
+      viewMenu.add(sequenceFeatures);\r
+      viewMenu.add(featureSettings);\r
+\r
 \r
       alignPanel.repaint();\r
 \r
@@ -289,6 +293,10 @@ public void itemStateChanged(ItemEvent evt)
             renderGapsMenuItem_actionPerformed();\r
     else if(evt.getSource()==annotationPanelMenuItem)\r
             annotationPanelMenuItem_actionPerformed();\r
+      else if(evt.getSource()==sequenceFeatures)\r
+       {     viewport.showSequenceFeatures(sequenceFeatures.getState());\r
+            alignPanel.seqPanel.seqCanvas.repaint();\r
+        }\r
       else if(evt.getSource()==conservationMenuItem)\r
             conservationMenuItem_actionPerformed();\r
       else if(evt.getSource()==abovePIDThreshold)\r
@@ -346,6 +354,8 @@ public void itemStateChanged(ItemEvent evt)
             findMenuItem_actionPerformed();\r
     else if(evt.getSource()==font)\r
             font_actionPerformed();\r
+    else if(evt.getSource()==featureSettings)\r
+            featureSettings_actionPerformed();\r
     else if(evt.getSource()==overviewMenuItem)\r
             overviewMenuItem_actionPerformed();\r
     else if(evt.getSource()==noColourmenuItem)\r
@@ -1116,6 +1126,11 @@ public void itemStateChanged(ItemEvent evt)
     alignPanel.setAnnotationVisible(annotationPanelMenuItem.getState());\r
   }\r
 \r
+  public void featureSettings_actionPerformed()\r
+  {\r
+    new FeatureSettings(viewport, alignPanel);\r
+  }\r
+\r
   public void overviewMenuItem_actionPerformed()\r
   {\r
     if (alignPanel.overviewPanel != null)\r
@@ -1904,6 +1919,11 @@ public void itemStateChanged(ItemEvent evt)
           seqLimits.setState(true);\r
     seqLimits.setLabel("Show Sequence Limits");\r
     seqLimits.addItemListener(this);\r
+    featureSettings.setLabel("Feature Settings...");\r
+    featureSettings.addActionListener(this);\r
+    sequenceFeatures.setLabel("Sequence Features");\r
+    sequenceFeatures.addItemListener(this);\r
+    sequenceFeatures.setState(true);\r
 \r
     alignFrameMenuBar.add(fileMenu);\r
         alignFrameMenuBar.add(editMenu);\r
@@ -1936,7 +1956,7 @@ public void itemStateChanged(ItemEvent evt)
         searchMenu.add(findMenuItem);\r
         viewMenu.add(font);\r
         viewMenu.addSeparator();\r
-        viewMenu.add(seqLimits);\r
+    viewMenu.add(seqLimits);\r
         viewMenu.addSeparator();\r
     viewMenu.add(wrapMenuItem);\r
         viewMenu.add(scaleAbove);\r
@@ -1948,7 +1968,7 @@ public void itemStateChanged(ItemEvent evt)
         viewMenu.add(colourTextMenuItem);\r
         viewMenu.add(renderGapsMenuItem);\r
         viewMenu.add(annotationPanelMenuItem);\r
-        viewMenu.addSeparator();\r
+    viewMenu.addSeparator();\r
         viewMenu.add(overviewMenuItem);\r
         colourMenu.add(applyToAllGroups);\r
         colourMenu.addSeparator();\r
@@ -2057,6 +2077,8 @@ public void itemStateChanged(ItemEvent evt)
 \r
   PopupMenu filePopup, editPopup, searchPopup,\r
       viewPopup, colourPopup, calculatePopup, helpPopup;\r
+  MenuItem featureSettings = new MenuItem();\r
+  CheckboxMenuItem sequenceFeatures = new CheckboxMenuItem();\r
 \r
   public void mousePressed(MouseEvent evt)\r
   {\r
diff --git a/src/jalview/appletgui/FeatureSettings.java b/src/jalview/appletgui/FeatureSettings.java
new file mode 100755 (executable)
index 0000000..e01615a
--- /dev/null
@@ -0,0 +1,178 @@
+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+ */\r
+package jalview.appletgui;\r
+\r
+import jalview.datamodel.*;\r
+import java.awt.*;\r
+import java.util.*;\r
+import java.awt.event.*;\r
+\r
+\r
+public class FeatureSettings extends Panel implements ItemListener,\r
+    MouseListener, MouseMotionListener\r
+{\r
+  final FeatureRenderer fr;\r
+  final AlignmentPanel ap;\r
+  final AlignViewport av;\r
+  final Frame frame;\r
+\r
+  public FeatureSettings(AlignViewport av, final AlignmentPanel ap)\r
+  {\r
+    this.ap = ap;\r
+    this.av = av;\r
+    fr = ap.seqPanel.seqCanvas.getFeatureRenderer();\r
+\r
+    setTableData();\r
+\r
+    frame = new Frame();\r
+    frame.add(this);\r
+    int height = this.getComponentCount()*50;\r
+    if (height>400)\r
+      height = 400;\r
+\r
+    jalview.bin.JalviewLite.addFrame(frame, "Feature Settings", 200,\r
+                                     height);\r
+  }\r
+\r
+  void setTableData()\r
+  {\r
+    Vector allFeatures = new Vector();\r
+    Vector features;\r
+    Enumeration e;\r
+    SequenceFeature sf;\r
+\r
+    for (int i = 0; i < av.alignment.getHeight(); i++)\r
+    {\r
+      features = av.alignment.getSequenceAt(i).getSequenceFeatures();\r
+      if (features == null)\r
+        continue;\r
+\r
+      e = features.elements();\r
+      while (e.hasMoreElements())\r
+      {\r
+        sf = (SequenceFeature) e.nextElement();\r
+        if (!allFeatures.contains(sf.getType()))\r
+        {\r
+          allFeatures.addElement(sf.getType());\r
+        }\r
+      }\r
+    }\r
+\r
+    int fSize = allFeatures.size();\r
+\r
+    String type;\r
+    this.setLayout(new GridLayout(fSize, 2, 10,5));\r
+\r
+    for (int i = 0; i < fSize; i++)\r
+    {\r
+      type = allFeatures.elementAt(i).toString();\r
+      Color col = fr.getColour(type);\r
+      boolean displayed = true;\r
+      if(fr.featuresDisplayed!=null)\r
+        displayed = fr.featuresDisplayed.contains(type);\r
+\r
+      Checkbox check = new Checkbox(type, displayed);\r
+      check.addMouseListener(this);\r
+      check.addMouseMotionListener(this);\r
+      check.setBackground(col);\r
+      check.addItemListener(this);\r
+      add(check);\r
+    }\r
+    validate();\r
+  }\r
+\r
+  public void itemStateChanged(ItemEvent evt)\r
+  {\r
+    Component [] comps = this.getComponents();\r
+    int cSize = comps.length;\r
+\r
+    Object [][] data = new Object[cSize][3];\r
+\r
+    for(int i=0; i<cSize; i++)\r
+    {\r
+      Checkbox check = (Checkbox)comps[i];\r
+      data[i][0] = check.getLabel();\r
+      data[i][1] = fr.getColour(check.getLabel());\r
+      data[i][2] = new Boolean(check.getState());\r
+    }\r
+\r
+    fr.setFeaturePriority(data);\r
+    ap.seqPanel.seqCanvas.repaint();\r
+  }\r
+\r
+  Checkbox selectedCheck;\r
+  boolean dragging = false;\r
+\r
+  public void mousePressed(MouseEvent evt)\r
+  {\r
+    selectedCheck = (Checkbox)evt.getSource();\r
+  }\r
+\r
+  public void mouseDragged(MouseEvent evt)\r
+  {\r
+      dragging = true;\r
+  }\r
+\r
+  public void mouseReleased(MouseEvent evt)\r
+  {\r
+    Component comp = null;\r
+    Checkbox  target = null;\r
+\r
+    int height = evt.getY()+evt.getComponent().getLocation().y;\r
+\r
+    if(height > this.getSize().height)\r
+     {\r
+       comp = this.getComponent(this.getComponentCount()-1);\r
+     }\r
+     else if(height < 0)\r
+     {\r
+       comp = this.getComponent(0);\r
+     }\r
+     else\r
+     {\r
+       comp = this.getComponentAt(evt.getX(),\r
+                                  evt.getY() +\r
+                                  evt.getComponent().getLocation().y);\r
+     }\r
+\r
+    if(comp!=null && comp instanceof Checkbox)\r
+      target = (Checkbox)comp;\r
+\r
+    if (selectedCheck != null && target != null && selectedCheck != target)\r
+    {\r
+      int targetIndex = -1;\r
+      for(int i=0; i<this.getComponentCount(); i++)\r
+      {\r
+          if(target==this.getComponent(i))\r
+          { targetIndex = i; break; }\r
+      }\r
+\r
+\r
+      this.remove(selectedCheck);\r
+      this.add(selectedCheck, targetIndex);\r
+      validate();\r
+    }\r
+  }\r
+\r
+\r
+  public void mouseEntered(MouseEvent evt){}\r
+  public void mouseExited(MouseEvent evt){}\r
+  public void mouseClicked(MouseEvent evt){}\r
+  public void mouseMoved(MouseEvent evt){}\r
+}\r