getVisibleIdWidth() for making images
[jalview.git] / src / jalview / gui / AlignmentPanel.java
index 2451a96..366a36d 100755 (executable)
@@ -1,6 +1,6 @@
 /*\r
  * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Copyright (C) 2006 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
@@ -161,7 +161,6 @@ public class AlignmentPanel extends GAlignmentPanel
             if(!av.cursorMode)\r
             {\r
               alignFrame.cut_actionPerformed(null);\r
-              seqPanel.seqCanvas.repaint();\r
             }\r
             else\r
               seqPanel.deleteGapAtCursor(evt.isControlDown() || evt.isShiftDown());\r
@@ -236,6 +235,38 @@ public class AlignmentPanel extends GAlignmentPanel
               ex.printStackTrace();\r
             }\r
             break;\r
+          case KeyEvent.VK_H:\r
+          {\r
+            boolean toggleSeqs = !evt.isControlDown();\r
+            boolean toggleCols = !evt.isShiftDown();\r
+\r
+            boolean hide = false;\r
+\r
+            SequenceGroup sg = av.getSelectionGroup();\r
+            if(toggleSeqs)\r
+             {\r
+               if(sg != null && sg.getSize(false) != av.alignment.getHeight())\r
+               {\r
+                 alignFrame.hideSelSequences_actionPerformed(null);\r
+                 hide = true;\r
+               }\r
+               else if (!(toggleCols && av.colSel.getSelected().size() > 0))\r
+                 alignFrame.showAllSeqs_actionPerformed(null);\r
+             }\r
+\r
+             if (toggleCols)\r
+             {\r
+               if(av.colSel.getSelected().size() > 0)\r
+               {\r
+                 alignFrame.hideSelColumns_actionPerformed(null);\r
+                 if(!toggleSeqs)\r
+                   av.selectionGroup = sg;\r
+               }\r
+               else if(!hide)\r
+                 alignFrame.showAllColumns_actionPerformed(null);\r
+             }\r
+            break;\r
+          }\r
 \r
         }\r
       }\r
@@ -441,6 +472,7 @@ public class AlignmentPanel extends GAlignmentPanel
             height));\r
 \r
         annotationPanel.repaint();\r
+        repaint();\r
       }\r
     });\r
   }\r
@@ -766,7 +798,7 @@ public class AlignmentPanel extends GAlignmentPanel
   public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)\r
       throws PrinterException\r
   {\r
-    int idWidth = calculateIdWidth().width + 4;\r
+    int idWidth = getVisibleIdWidth();\r
     FontMetrics fm = getFontMetrics(av.getFont());\r
     int scaleHeight = av.charHeight + fm.getDescent();\r
 \r
@@ -778,6 +810,8 @@ public class AlignmentPanel extends GAlignmentPanel
     /// How many sequences and residues can we fit on a printable page?\r
     int totalRes = (pwidth - idWidth) / av.getCharWidth();\r
 \r
+    System.out.println(totalRes);\r
+\r
     int totalSeq = (int) ( (pheight - scaleHeight) / av.getCharHeight()) -\r
         1;\r
 \r
@@ -921,7 +955,7 @@ public class AlignmentPanel extends GAlignmentPanel
         + hgap\r
         + annotationHeight;\r
 \r
-    int idWidth = calculateIdWidth().width + 4;\r
+    int idWidth = getVisibleIdWidth();\r
 \r
     int maxwidth = av.alignment.getWidth();\r
     if (av.hasHiddenColumns)\r
@@ -994,6 +1028,13 @@ public class AlignmentPanel extends GAlignmentPanel
     }\r
   }\r
 \r
+  int getVisibleIdWidth()\r
+  {\r
+    return\r
+        idPanel.getWidth() > 0 ? idPanel.getWidth() :\r
+        calculateIdWidth().width + 4;\r
+  }\r
+\r
   void makeAlignmentImage(int type, File file)\r
   {\r
     int maxwidth = av.alignment.getWidth();\r
@@ -1001,11 +1042,7 @@ public class AlignmentPanel extends GAlignmentPanel
       maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);\r
 \r
     int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30;\r
-    int width = idPanel.getWidth() + (maxwidth * av.charWidth);\r
-    if (idPanel.getWidth() == 0)\r
-    {\r
-      width += calculateIdWidth().getWidth() + 4;\r
-    }\r
+    int width = getVisibleIdWidth() + (maxwidth * av.charWidth);\r
 \r
     if (av.getWrapAlignment())\r
     {\r
@@ -1016,7 +1053,7 @@ public class AlignmentPanel extends GAlignmentPanel
         width = alignFrame.getWidth() - 22;\r
       }\r
       else\r
-        width = seqPanel.getWidth() + idPanel.getWidth();\r
+        width = seqPanel.getWidth() + getVisibleIdWidth();\r
 \r
     }\r
     else if (av.getShowAnnotation())\r
@@ -1096,7 +1133,7 @@ public class AlignmentPanel extends GAlignmentPanel
   {\r
     ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS\r
     //////////////////////////////////////////////\r
-    int idWidth = calculateIdWidth().width + 4;\r
+    int idWidth = getVisibleIdWidth();\r
     FontMetrics fm = getFontMetrics(av.getFont());\r
     int scaleHeight = av.charHeight + fm.getDescent();\r
 \r
@@ -1226,8 +1263,7 @@ public class AlignmentPanel extends GAlignmentPanel
     if (System.getProperty("java.awt.headless") != null\r
               && System.getProperty("java.awt.headless").equals("true"))\r
     {\r
-      int idWidth = calculateIdWidth().width + 4;\r
-      seqPanelWidth = alignFrame.getWidth() - idWidth;\r
+      seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth();\r
     }\r
 \r
     int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(\r