merge from 2_4_Release branch
[jalview.git] / src / jalview / appletgui / FeatureSettings.java
index 6670d2f..4649786 100755 (executable)
@@ -1,17 +1,17 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
- *
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
+ * Copyright (C) 2008 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
@@ -25,19 +25,28 @@ import java.awt.event.*;
 
 import jalview.datamodel.*;
 
-public class FeatureSettings
-    extends Panel implements ItemListener,
-    MouseListener, MouseMotionListener, ActionListener, AdjustmentListener
+public class FeatureSettings extends Panel implements ItemListener,
+        MouseListener, MouseMotionListener, ActionListener,
+        AdjustmentListener
 {
   FeatureRenderer fr;
+
   AlignmentPanel ap;
+
   AlignViewport av;
+
   Frame frame;
+
   Panel groupPanel;
+
   Panel featurePanel = new Panel();
+
   ScrollPane scrollPane;
+
   boolean alignmentHasFeatures = false;
+
   Image linkImage;
+
   Scrollbar transparency;
 
   public FeatureSettings(final AlignmentPanel ap)
@@ -48,7 +57,7 @@ public class FeatureSettings
     fr = ap.seqPanel.seqCanvas.getFeatureRenderer();
 
     transparency = new Scrollbar(Scrollbar.HORIZONTAL,
-                                 100 - (int) (fr.transparency * 100), 1, 1, 100);
+            100 - (int) (fr.transparency * 100), 1, 1, 100);
 
     if (fr.transparencySetter != null)
     {
@@ -95,8 +104,9 @@ public class FeatureSettings
     }
     else
     {
-      tPanel.add(new Label("Transparency not available in this web browser"),
-                 BorderLayout.CENTER);
+      tPanel.add(
+              new Label("Transparency not available in this web browser"),
+              BorderLayout.CENTER);
     }
 
     lowerPanel.add(tPanel, BorderLayout.SOUTH);
@@ -105,8 +115,8 @@ public class FeatureSettings
 
     if (groupPanel != null)
     {
-      groupPanel.setLayout(
-          new GridLayout(fr.featureGroups.size() / 4 + 1, 4));
+      groupPanel.setLayout(new GridLayout(fr.featureGroups.size() / 4 + 1,
+              4));
       groupPanel.validate();
 
       add(groupPanel, BorderLayout.NORTH);
@@ -118,22 +128,21 @@ public class FeatureSettings
     {
       public void windowClosing(WindowEvent e)
       {
-        if (me.av.featureSettings==me)
+        if (me.av.featureSettings == me)
         {
           me.av.featureSettings = null;
           me.ap = null;
           me.av = null;
         }
       }
-    }
-    );
+    });
     int height = featurePanel.getComponentCount() * 50 + 60;
 
     height = Math.max(200, height);
     height = Math.min(400, height);
     int width = 300;
     jalview.bin.JalviewLite.addFrame(frame, "Feature Settings", width,
-                                     height);
+            height);
   }
 
   public void paint(Graphics g)
@@ -150,10 +159,11 @@ public class FeatureSettings
     if (alignmentHasFeatures)
     {
       rebuildGroups();
-      
+
     }
     resetTable(false);
   }
+
   /**
    * rebuilds the group panel
    */
@@ -163,21 +173,21 @@ public class FeatureSettings
     if (groupPanel == null)
     {
       groupPanel = new Panel();
-    } else {
+    }
+    else
+    {
       rdrw = true;
       groupPanel.removeAll();
     }
-    
+
     Enumeration gps = fr.featureGroups.keys();
     while (gps.hasMoreElements())
     {
       String group = (String) gps.nextElement();
       Boolean vis = (Boolean) fr.featureGroups.get(group);
-      Checkbox check = new MyCheckbox(
-              group,
-              vis.booleanValue(),
-              (fr.featureLinks != null && fr.featureLinks.containsKey(group))
-        );    
+      Checkbox check = new MyCheckbox(group, vis.booleanValue(),
+              (fr.featureLinks != null && fr.featureLinks
+                      .containsKey(group)));
       check.addMouseListener(this);
       check.setFont(new Font("Serif", Font.BOLD, 12));
       check.addItemListener(this);
@@ -189,8 +199,8 @@ public class FeatureSettings
     }
   }
 
-  //This routine adds and removes checkboxes depending on
-  //Group selection states
+  // This routine adds and removes checkboxes depending on
+  // Group selection states
   void resetTable(boolean groupsChanged)
   {
     SequenceFeature[] tmpfeatures;
@@ -210,8 +220,8 @@ public class FeatureSettings
       {
         group = tmpfeatures[index].featureGroup;
 
-        if (group == null || fr.featureGroups.get(group) == null ||
-            ( (Boolean) fr.featureGroups.get(group)).booleanValue())
+        if (group == null || fr.featureGroups.get(group) == null
+                || ((Boolean) fr.featureGroups.get(group)).booleanValue())
         {
           type = tmpfeatures[index].getType();
           if (!visibleChecks.contains(type))
@@ -226,8 +236,8 @@ public class FeatureSettings
     Component[] comps;
     int cSize = featurePanel.getComponentCount();
     Checkbox check;
-    //This will remove any checkboxes which shouldn't be
-    //visible
+    // This will remove any checkboxes which shouldn't be
+    // visible
     for (int i = 0; i < cSize; i++)
     {
       comps = featurePanel.getComponents();
@@ -242,8 +252,8 @@ public class FeatureSettings
 
     if (fr.renderOrder != null)
     {
-      //First add the checks in the previous render order,
-      //in case the window has been closed and reopened
+      // First add the checks in the previous render order,
+      // in case the window has been closed and reopened
       for (int ro = fr.renderOrder.length - 1; ro > -1; ro--)
       {
         String item = fr.renderOrder[ro];
@@ -268,8 +278,8 @@ public class FeatureSettings
       addCheck(groupsChanged, en.nextElement().toString());
     }
 
-    featurePanel.setLayout(new GridLayout(featurePanel.getComponentCount(), 1,
-                                          10, 5));
+    featurePanel.setLayout(new GridLayout(featurePanel.getComponentCount(),
+            1, 10, 5));
     featurePanel.validate();
 
     if (scrollPane != null)
@@ -279,10 +289,15 @@ public class FeatureSettings
 
     itemStateChanged(null);
   }
+
   /**
    * update the checklist of feature types with the given type
-   * @param groupsChanged true means if the type is not in the display list then it will be added and displayed
-   * @param type feature type to be checked for in the list.
+   * 
+   * @param groupsChanged
+   *                true means if the type is not in the display list then it
+   *                will be added and displayed
+   * @param type
+   *                feature type to be checked for in the list.
    */
   void addCheck(boolean groupsChanged, String type)
   {
@@ -308,11 +323,10 @@ public class FeatureSettings
         selected = true;
       }
 
-      check = new MyCheckbox(type,
-                             selected,
-                             (fr.featureLinks != null &&
-                              fr.featureLinks.containsKey(type))
-          );
+      check = new MyCheckbox(
+              type,
+              selected,
+              (fr.featureLinks != null && fr.featureLinks.containsKey(type)));
 
       check.addMouseListener(this);
       check.addMouseMotionListener(this);
@@ -345,11 +359,12 @@ public class FeatureSettings
   {
     if (evt != null)
     {
-      //Is the source a top level featureGroup?
+      // Is the source a top level featureGroup?
       Checkbox source = (Checkbox) evt.getSource();
       if (fr.featureGroups.containsKey(source.getLabel()))
       {
-        fr.featureGroups.put(source.getLabel(), new Boolean(source.getState()));
+        fr.featureGroups.put(source.getLabel(), new Boolean(source
+                .getState()));
         ap.seqPanel.seqCanvas.repaint();
         if (ap.overviewPanel != null)
         {
@@ -388,6 +403,7 @@ public class FeatureSettings
   }
 
   MyCheckbox selectedCheck;
+
   boolean dragging = false;
 
   public void mousePressed(MouseEvent evt)
@@ -396,8 +412,7 @@ public class FeatureSettings
     selectedCheck = (MyCheckbox) evt.getSource();
 
     if (fr.featureLinks != null
-        && fr.featureLinks.containsKey(selectedCheck.getLabel())
-        )
+            && fr.featureLinks.containsKey(selectedCheck.getLabel()))
     {
       if (evt.getX() > selectedCheck.stringWidth + 20)
       {
@@ -409,7 +424,7 @@ public class FeatureSettings
 
   public void mouseDragged(MouseEvent evt)
   {
-    if ( ( (Component) evt.getSource()).getParent() != featurePanel)
+    if (((Component) evt.getSource()).getParent() != featurePanel)
     {
       return;
     }
@@ -418,7 +433,7 @@ public class FeatureSettings
 
   public void mouseReleased(MouseEvent evt)
   {
-    if ( ( (Component) evt.getSource()).getParent() != featurePanel)
+    if (((Component) evt.getSource()).getParent() != featurePanel)
     {
       return;
     }
@@ -431,7 +446,8 @@ public class FeatureSettings
     if (height > featurePanel.getSize().height)
     {
 
-      comp = featurePanel.getComponent(featurePanel.getComponentCount() - 1);
+      comp = featurePanel
+              .getComponent(featurePanel.getComponentCount() - 1);
     }
     else if (height < 0)
     {
@@ -439,9 +455,8 @@ public class FeatureSettings
     }
     else
     {
-      comp = featurePanel.getComponentAt(evt.getX(),
-                                         evt.getY() +
-                                         evt.getComponent().getLocation().y);
+      comp = featurePanel.getComponentAt(evt.getX(), evt.getY()
+              + evt.getComponent().getLocation().y);
     }
 
     if (comp != null && comp instanceof Checkbox)
@@ -449,9 +464,7 @@ public class FeatureSettings
       target = (Checkbox) comp;
     }
 
-    if (selectedCheck != null
-        && target != null
-        && selectedCheck != target)
+    if (selectedCheck != null && target != null && selectedCheck != target)
     {
       int targetIndex = -1;
       for (int i = 0; i < featurePanel.getComponentCount(); i++)
@@ -479,24 +492,26 @@ public class FeatureSettings
   }
 
   public void mouseEntered(MouseEvent evt)
-  {}
+  {
+  }
 
   public void mouseExited(MouseEvent evt)
-  {}
+  {
+  }
 
   public void mouseClicked(MouseEvent evt)
   {
     MyCheckbox check = (MyCheckbox) evt.getSource();
 
     if (fr.featureLinks != null
-        && fr.featureLinks.containsKey(check.getLabel()))
+            && fr.featureLinks.containsKey(check.getLabel()))
     {
       if (evt.getX() > check.stringWidth + 20)
       {
         evt.consume();
         String link = fr.featureLinks.get(check.getLabel()).toString();
-        ap.alignFrame.showURL(link.substring(link.indexOf("|") + 1),
-                              link.substring(0, link.indexOf("|")));
+        ap.alignFrame.showURL(link.substring(link.indexOf("|") + 1), link
+                .substring(0, link.indexOf("|")));
       }
     }
 
@@ -507,26 +522,28 @@ public class FeatureSettings
 
     if (evt.getClickCount() > 1)
     {
-      new UserDefinedColours(this, check.getLabel(),
-                             fr.getColour(check.getLabel()));
+      new UserDefinedColours(this, check.getLabel(), fr.getColour(check
+              .getLabel()));
     }
   }
 
   public void mouseMoved(MouseEvent evt)
-  {}
+  {
+  }
 
   public void adjustmentValueChanged(AdjustmentEvent evt)
   {
-    fr.transparency = ( (float) (100 - transparency.getValue()) / 100f);
+    fr.transparency = ((float) (100 - transparency.getValue()) / 100f);
     ap.seqPanel.seqCanvas.repaint();
 
   }
 
-  class MyCheckbox
-      extends Checkbox
+  class MyCheckbox extends Checkbox
   {
     public int stringWidth;
+
     boolean hasLink;
+
     public MyCheckbox(String label, boolean checked, boolean haslink)
     {
       super(label, checked);
@@ -540,9 +557,8 @@ public class FeatureSettings
     {
       if (hasLink)
       {
-        g.drawImage(linkImage, stringWidth + 25, (
-            getSize().height - linkImage.getHeight(this)) / 2,
-                    this);
+        g.drawImage(linkImage, stringWidth + 25,
+                (getSize().height - linkImage.getHeight(this)) / 2, this);
       }
     }
   }