Formatted source
[jalview.git] / src / jalview / gui / AnnotationLabels.java
index f2603ea..1b9fd8f 100755 (executable)
@@ -1,44 +1,45 @@
-\r
 /*\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
-\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.gui;\r
 \r
-import javax.swing.*;\r
-import java.awt.event.*;\r
 import java.awt.*;\r
+import java.awt.event.*;\r
 import java.awt.image.*;\r
+import javax.swing.*;\r
+\r
 import jalview.datamodel.*;\r
-import jalview.io.FormatAdapter;\r
 \r
-public class AnnotationLabels extends JPanel implements MouseListener, MouseMotionListener, ActionListener\r
+public class AnnotationLabels\r
+    extends JPanel implements MouseListener,\r
+    MouseMotionListener, ActionListener\r
 {\r
-  boolean active = false;\r
-  Image image;\r
-  AlignmentPanel ap ;\r
-  boolean resizing = false;\r
-  int oldY, mouseX;\r
   static String ADDNEW = "Add New Row";\r
   static String HIDE = "Hide This Row";\r
   static String DELETE = "Delete This Row";\r
-  static String SHOWALL="Show All Hidden Rows";\r
-  static String OUTPUT_TEXT="Show Values In Textbox";\r
+  static String SHOWALL = "Show All Hidden Rows";\r
+  static String OUTPUT_TEXT = "Show Values In Textbox";\r
+  boolean active = false;\r
+  Image image;\r
+  AlignmentPanel ap;\r
+  boolean resizing = false;\r
+  int oldY;\r
+  int mouseX;\r
   int selectedRow = 0;\r
   int scrollOffset = 0;\r
 \r
@@ -48,8 +49,11 @@ public class AnnotationLabels extends JPanel implements MouseListener, MouseMoti
 \r
     java.net.URL url = getClass().getResource("/images/idwidth.gif");\r
     Image temp = null;\r
+\r
     if (url != null)\r
+    {\r
       temp = java.awt.Toolkit.getDefaultToolkit().createImage(url);\r
+    }\r
 \r
     try\r
     {\r
@@ -57,9 +61,12 @@ public class AnnotationLabels extends JPanel implements MouseListener, MouseMoti
       mt.addImage(temp, 0);\r
       mt.waitForID(0);\r
     }\r
-    catch (Exception ex) {}\r
+    catch (Exception ex)\r
+    {\r
+    }\r
 \r
-    BufferedImage bi = new BufferedImage(temp.getHeight(this), temp.getWidth(this),\r
+    BufferedImage bi = new BufferedImage(temp.getHeight(this),\r
+                                         temp.getWidth(this),\r
                                          BufferedImage.TYPE_INT_RGB);\r
     Graphics2D g = (Graphics2D) bi.getGraphics();\r
     g.rotate(Math.toRadians(90));\r
@@ -80,126 +87,175 @@ public class AnnotationLabels extends JPanel implements MouseListener, MouseMoti
   {\r
     AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();\r
 \r
-    if(evt.getActionCommand().equals(ADDNEW))\r
+    if (evt.getActionCommand().equals(ADDNEW))\r
     {\r
-      String label = JOptionPane.showInputDialog(this, "Label for annotation");\r
-      if(label==null)\r
+      String label = JOptionPane.showInputDialog(this,\r
+                                                 "Label for annotation");\r
+\r
+      if (label == null)\r
+      {\r
         label = "";\r
-      ap.av.alignment.addAnnotation(new AlignmentAnnotation\r
-                                      (label,\r
-                                       "New description",\r
-                                       new Annotation[ap.av.alignment.getWidth()]));\r
+      }\r
+\r
+      ap.av.alignment.addAnnotation(new AlignmentAnnotation(label,\r
+          "New description",\r
+          new Annotation[ap.av.alignment.getWidth()]));\r
+    }\r
+    else if (evt.getActionCommand().equals(HIDE))\r
+    {\r
+      aa[selectedRow].visible = false;\r
+\r
+      if (aa[selectedRow].label.equals("Conservation"))\r
+      {\r
+        ap.av.showConservation = false;\r
+      }\r
+\r
+      if (aa[selectedRow].label.equals("Quality"))\r
+      {\r
+        ap.av.showQuality = false;\r
+      }\r
+\r
+      if (aa[selectedRow].label.equals("Consensus"))\r
+      {\r
+        ap.av.showIdentity = false;\r
+      }\r
+    }\r
+    else if (evt.getActionCommand().equals(DELETE))\r
+    {\r
+      ap.av.alignment.deleteAnnotation(aa[selectedRow]);\r
+    }\r
+    else if (evt.getActionCommand().equals(SHOWALL))\r
+    {\r
+      for (int i = 0; i < aa.length; i++)\r
+      {\r
+        aa[i].visible = true;\r
+      }\r
+    }\r
+    else if (evt.getActionCommand().equals(OUTPUT_TEXT))\r
+    {\r
+      CutAndPasteTransfer cap = new CutAndPasteTransfer();\r
+      Desktop.addInternalFrame(cap,\r
+                               ap.alignFrame.getTitle() + " - " +\r
+                               aa[selectedRow].label, 500,\r
+                               100);\r
+      cap.setText(aa[selectedRow].toString());\r
     }\r
-   else if(evt.getActionCommand().equals(HIDE))\r
-   {\r
-     aa[selectedRow].visible = false;\r
-     if(aa[selectedRow].label.equals("Conservation"))\r
-       ap.av.showConservation = false;\r
-     if(aa[selectedRow].label.equals("Quality"))\r
-       ap.av.showQuality = false;\r
-     if(aa[selectedRow].label.equals("Consensus"))\r
-       ap.av.showIdentity = false;\r
-   }\r
-   else if(evt.getActionCommand().equals(DELETE))\r
-   {\r
-     ap.av.alignment.deleteAnnotation(aa[selectedRow]);\r
-   }\r
-   else if(evt.getActionCommand().equals(SHOWALL))\r
-   {\r
-       for(int i=0; i<aa.length; i++)\r
-         aa[i].visible = true;\r
-   }\r
-   else if(evt.getActionCommand().equals(OUTPUT_TEXT))\r
-   {\r
-     CutAndPasteTransfer cap = new CutAndPasteTransfer();\r
-     Desktop.addInternalFrame(cap, ap.alignFrame.getTitle()+" - "+ aa[selectedRow].label, 500, 100);\r
-     cap.setText( aa[selectedRow].toString() );\r
-   }\r
-\r
-   ap.annotationPanel.adjustPanelHeight();\r
-   ap.repaint();\r
 \r
+    ap.annotationPanel.adjustPanelHeight();\r
+    ap.repaint();\r
   }\r
 \r
   public void mousePressed(MouseEvent evt)\r
   {\r
     int y = evt.getY() - scrollOffset;\r
 \r
-      AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();\r
-       if(aa==null || aa.length==0)\r
-       {\r
-            JPopupMenu pop = new JPopupMenu("Annotations");\r
-            JMenuItem item = new JMenuItem(ADDNEW);\r
-            item.addActionListener(this);\r
-            pop.add(item);\r
-            pop.show(this, evt.getX(), evt.getY());\r
-            return;\r
-       }\r
-\r
-       int height = 0;\r
-       for (int i = 0; i < aa.length; i++)\r
-       {\r
-         if(!aa[i].visible)\r
-           continue;\r
-\r
-         height += aa[i].height;\r
-         if(y<height)\r
-         {\r
-           selectedRow = i;\r
-           break;\r
-         }\r
-       }\r
+    AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();\r
 \r
+    if ( (aa == null) || (aa.length == 0))\r
+    {\r
       JPopupMenu pop = new JPopupMenu("Annotations");\r
       JMenuItem item = new JMenuItem(ADDNEW);\r
       item.addActionListener(this);\r
       pop.add(item);\r
-      item = new JMenuItem(HIDE);\r
-      item.addActionListener(this);\r
-      pop.add(item);\r
-      item = new JMenuItem(DELETE);\r
-      item.addActionListener(this);\r
-      pop.add(item);\r
-      item = new JMenuItem(SHOWALL);\r
-      item.addActionListener(this);\r
-      pop.add(item);\r
-      item = new JMenuItem(OUTPUT_TEXT);\r
-      item.addActionListener(this);\r
-      pop.add(item);\r
       pop.show(this, evt.getX(), evt.getY());\r
 \r
+      return;\r
+    }\r
+\r
+    int height = 0;\r
+\r
+    for (int i = 0; i < aa.length; i++)\r
+    {\r
+      if (!aa[i].visible)\r
+      {\r
+        continue;\r
+      }\r
+\r
+      height += aa[i].height;\r
+\r
+      if (y < height)\r
+      {\r
+        selectedRow = i;\r
+\r
+        break;\r
+      }\r
+    }\r
+\r
+    JPopupMenu pop = new JPopupMenu("Annotations");\r
+    JMenuItem item = new JMenuItem(ADDNEW);\r
+    item.addActionListener(this);\r
+    pop.add(item);\r
+    item = new JMenuItem(HIDE);\r
+    item.addActionListener(this);\r
+    pop.add(item);\r
+    item = new JMenuItem(DELETE);\r
+    item.addActionListener(this);\r
+    pop.add(item);\r
+    item = new JMenuItem(SHOWALL);\r
+    item.addActionListener(this);\r
+    pop.add(item);\r
+    item = new JMenuItem(OUTPUT_TEXT);\r
+    item.addActionListener(this);\r
+    pop.add(item);\r
+    pop.show(this, evt.getX(), evt.getY());\r
+\r
     oldY = evt.getY();\r
   }\r
 \r
-  public void mouseReleased(MouseEvent evt){ active = false; repaint(); }\r
-  public void mouseEntered(MouseEvent evt) { active = true;  repaint();}\r
-  public void mouseExited(MouseEvent evt)  { active = false; repaint();}\r
+  public void mouseReleased(MouseEvent evt)\r
+  {\r
+    active = false;\r
+    repaint();\r
+  }\r
+\r
+  public void mouseEntered(MouseEvent evt)\r
+  {\r
+    active = true;\r
+    repaint();\r
+  }\r
+\r
+  public void mouseExited(MouseEvent evt)\r
+  {\r
+    active = false;\r
+    repaint();\r
+  }\r
+\r
   public void mouseDragged(MouseEvent evt)\r
   {\r
     active = true;\r
+\r
     Dimension d = ap.annotationScroller.getPreferredSize();\r
     int dif = evt.getY() - oldY;\r
 \r
     dif /= ap.av.charHeight;\r
     dif *= ap.av.charHeight;\r
 \r
-    if(d.height-dif>20)\r
+    if ( (d.height - dif) > 20)\r
     {\r
-      ap.annotationScroller.setPreferredSize(new Dimension(d.width,d.height - dif));\r
+      ap.annotationScroller.setPreferredSize(new Dimension(d.width,\r
+          d.height - dif));\r
       d = ap.annotationSpaceFillerHolder.getPreferredSize();\r
-      ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(d.width,d.height - dif));\r
+      ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(\r
+          d.width, d.height - dif));\r
       ap.repaint();\r
     }\r
+\r
     ap.addNotify();\r
   }\r
 \r
-  public void mouseMoved(MouseEvent evt)   {}\r
-  public void mouseClicked(MouseEvent evt) {}\r
+  public void mouseMoved(MouseEvent evt)\r
+  {\r
+  }\r
+\r
+  public void mouseClicked(MouseEvent evt)\r
+  {\r
+  }\r
 \r
   public void paintComponent(Graphics g1)\r
   {\r
-    Graphics2D g = (Graphics2D)g1;\r
-    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);\r
+    Graphics2D g = (Graphics2D) g1;\r
+    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,\r
+                       RenderingHints.VALUE_ANTIALIAS_ON);\r
 \r
     drawComponent(g);\r
   }\r
@@ -208,48 +264,56 @@ public class AnnotationLabels extends JPanel implements MouseListener, MouseMoti
   {\r
     FontMetrics fm = g.getFontMetrics(g.getFont());\r
     g.setColor(Color.white);\r
-    g.fillRect(0,0, getWidth(), getHeight());\r
+    g.fillRect(0, 0, getWidth(), getHeight());\r
 \r
     g.translate(0, scrollOffset);\r
     g.setColor(Color.black);\r
 \r
-   AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();\r
-   int y = g.getFont().getSize();\r
-   int x = 0;\r
-\r
-   if(aa!=null)\r
-   for(int i=0; i<aa.length; i++)\r
-   {\r
-     if(!aa[i].visible)\r
-       continue;\r
-\r
-     x = getWidth() - fm.stringWidth(aa[i].label)-3;\r
-\r
-     if(aa[i].isGraph)\r
-       y+=(aa[i].height/3);\r
-\r
-     g.drawString(aa[i].label, x, y);\r
-\r
-     if(aa[i].isGraph)\r
-       y+=(2*aa[i].height/3);\r
-    else\r
-       y+=aa[i].height;\r
-   }\r
-\r
-   if (active)\r
-   {\r
-     if (image != null)\r
-       g.drawImage(image, 2, 0, this);\r
-   }\r
-\r
-   if (aa == null || aa.length<1)\r
-   {\r
-     g.drawString("Right click", 2, 8);\r
-     g.drawString("to add annotation", 2, 18);\r
-   }\r
+    AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();\r
+    int y = g.getFont().getSize();\r
+    int x = 0;\r
 \r
+    if (aa != null)\r
+    {\r
+      for (int i = 0; i < aa.length; i++)\r
+      {\r
+        if (!aa[i].visible)\r
+        {\r
+          continue;\r
+        }\r
+\r
+        x = getWidth() - fm.stringWidth(aa[i].label) - 3;\r
+\r
+        if (aa[i].isGraph)\r
+        {\r
+          y += (aa[i].height / 3);\r
+        }\r
+\r
+        g.drawString(aa[i].label, x, y);\r
+\r
+        if (aa[i].isGraph)\r
+        {\r
+          y += ( (2 * aa[i].height) / 3);\r
+        }\r
+        else\r
+        {\r
+          y += aa[i].height;\r
+        }\r
+      }\r
+    }\r
 \r
+    if (active)\r
+    {\r
+      if (image != null)\r
+      {\r
+        g.drawImage(image, 2, 0, this);\r
+      }\r
+    }\r
 \r
+    if ( (aa == null) || (aa.length < 1))\r
+    {\r
+      g.drawString("Right click", 2, 8);\r
+      g.drawString("to add annotation", 2, 18);\r
+    }\r
   }\r
-\r
 }\r