must specify .CA
[jalview.git] / src / jalview / appletgui / OverviewPanel.java
index 47c781b..7265489 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) 2007 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
@@ -26,6 +26,7 @@ public class OverviewPanel
     extends Panel implements Runnable, MouseMotionListener, MouseListener\r
 {\r
   Image miniMe;\r
+  Image offscreen;\r
   AlignViewport av;\r
   AlignmentPanel ap;\r
   float scalew = 1f;\r
@@ -42,7 +43,6 @@ public class OverviewPanel
   SequenceRenderer sr;\r
   FeatureRenderer fr;\r
 \r
-\r
   Frame nullFrame;\r
 \r
   public OverviewPanel(AlignmentPanel ap)\r
@@ -53,29 +53,31 @@ public class OverviewPanel
     nullFrame = new Frame();\r
     nullFrame.addNotify();\r
 \r
-\r
     sr = new SequenceRenderer(av);\r
     sr.graphics = nullFrame.getGraphics();\r
-    sr.renderGaps( false );\r
+    sr.renderGaps = false;\r
+    sr.forOverview = true;\r
     fr = new FeatureRenderer(av);\r
-    fr.drawText = false;\r
-\r
-\r
+    fr.overview = true;\r
 \r
     // scale the initial size of overviewpanel to shape of alignment\r
     float initialScale = (float) av.alignment.getWidth() /\r
         (float) av.alignment.getHeight();\r
 \r
-    if(av.vconsensus==null)\r
-          graphHeight = 0;\r
+    if (av.hconsensus == null)\r
+    {\r
+      graphHeight = 0;\r
+    }\r
 \r
     if (av.alignment.getWidth() > av.alignment.getHeight())\r
     {\r
       // wider\r
       width = 400;\r
       sequencesHeight = (int) (400f / initialScale);\r
-      if(sequencesHeight<40)\r
-              sequencesHeight = 40;\r
+      if (sequencesHeight < 40)\r
+      {\r
+        sequencesHeight = 40;\r
+      }\r
     }\r
     else\r
     {\r
@@ -110,22 +112,23 @@ public class OverviewPanel
 \r
   }\r
 \r
-\r
   public void mouseEntered(MouseEvent evt)\r
   {}\r
+\r
   public void mouseExited(MouseEvent evt)\r
   {}\r
+\r
   public void mouseClicked(MouseEvent evt)\r
   {}\r
+\r
   public void mouseMoved(MouseEvent evt)\r
   {}\r
+\r
   public void mousePressed(MouseEvent evt)\r
   {\r
     boxX = evt.getX();\r
     boxY = evt.getY();\r
-\r
     checkValid();\r
-    repaint();\r
   }\r
 \r
   public void mouseReleased(MouseEvent evt)\r
@@ -133,8 +136,6 @@ public class OverviewPanel
     boxX = evt.getX();\r
     boxY = evt.getY();\r
     checkValid();\r
-    ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()),\r
-                         (int) (boxY / scaleh / av.getCharHeight()));\r
   }\r
 \r
   public void mouseDragged(MouseEvent evt)\r
@@ -142,11 +143,6 @@ public class OverviewPanel
     boxX = evt.getX();\r
     boxY = evt.getY();\r
     checkValid();\r
-    ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()),\r
-                         (int) (boxY / scaleh / av.getCharHeight()));\r
-\r
-    repaint();\r
-    ap.repaint();\r
   }\r
 \r
   void checkValid()\r
@@ -156,7 +152,7 @@ public class OverviewPanel
       boxY = 0;\r
     }\r
 \r
-    if (boxY > sequencesHeight - boxHeight)\r
+    if (boxY > (sequencesHeight - boxHeight))\r
     {\r
       boxY = sequencesHeight - boxHeight + 1;\r
     }\r
@@ -166,10 +162,37 @@ public class OverviewPanel
       boxX = 0;\r
     }\r
 \r
-    if (boxX > width - boxWidth)\r
+    if (boxX > (width - boxWidth))\r
     {\r
+      if (av.hasHiddenColumns)\r
+      {\r
+        //Try smallest possible box\r
+        boxWidth = (int) ( (av.endRes - av.startRes + 1) *\r
+                          av.getCharWidth() * scalew);\r
+      }\r
       boxX = width - boxWidth;\r
     }\r
+\r
+    int col = (int) (boxX / scalew / av.getCharWidth());\r
+    int row = (int) (boxY / scaleh / av.getCharHeight());\r
+\r
+    if (av.hasHiddenColumns)\r
+    {\r
+      if (!av.getColumnSelection().isVisible(col))\r
+      {\r
+        return;\r
+      }\r
+\r
+      col = av.getColumnSelection().findColumnPosition(col);\r
+    }\r
+\r
+    if (av.hasHiddenRows)\r
+    {\r
+      row = av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(row);\r
+    }\r
+\r
+    ap.setScrollValues(col, row);\r
+    ap.paintAlignment(false);\r
   }\r
 \r
   /**\r
@@ -179,18 +202,17 @@ public class OverviewPanel
   {\r
     if (resizing)\r
     {\r
-        resizeAgain = true;\r
-        return;\r
+      resizeAgain = true;\r
+      return;\r
     }\r
 \r
     if (av.showSequenceFeatures)\r
-   {\r
-     fr.featuresDisplayed = ap.seqPanel.seqCanvas.getFeatureRenderer().\r
-         featuresDisplayed;\r
-     fr.featureGroups = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups;\r
-     fr.featureColours = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours;\r
-   }\r
-\r
+    {\r
+      fr.featureGroups = ap.seqPanel.seqCanvas.getFeatureRenderer().\r
+          featureGroups;\r
+      fr.featureColours = ap.seqPanel.seqCanvas.getFeatureRenderer().\r
+          featureColours;\r
+    }\r
 \r
     resizing = true;\r
 \r
@@ -200,16 +222,15 @@ public class OverviewPanel
       sequencesHeight = getSize().height - graphHeight;\r
     }\r
     setSize(new Dimension(width, sequencesHeight + graphHeight));\r
-    setBoxPosition();\r
 \r
     Thread thread = new Thread(this);\r
     thread.start();\r
-        repaint();\r
+    repaint();\r
   }\r
 \r
   // This is set true if the user resizes whilst\r
   // the overview is being calculated\r
-    boolean resizeAgain = false;\r
+  boolean resizeAgain = false;\r
 \r
   public void run()\r
   {\r
@@ -217,6 +238,11 @@ public class OverviewPanel
     int alwidth = av.alignment.getWidth();\r
     int alheight = av.alignment.getHeight();\r
 \r
+    if (av.showSequenceFeatures)\r
+    {\r
+      fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());\r
+    }\r
+\r
     if (getSize().width > 0 && getSize().height > 0)\r
     {\r
       width = getSize().width;\r
@@ -232,63 +258,121 @@ public class OverviewPanel
     scaleh = (float) sequencesHeight / (float) fullsizeHeight;\r
 \r
     miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);\r
+    offscreen = nullFrame.createImage(width, sequencesHeight + graphHeight);\r
 \r
     Graphics mg = miniMe.getGraphics();\r
     float sampleCol = (float) alwidth / (float) width;\r
     float sampleRow = (float) alheight / (float) sequencesHeight;\r
 \r
-    int lastcol=-1, lastrow=-1;\r
+    int lastcol = 0, lastrow = 0;\r
+    int xstart = 0, ystart = 0;\r
     Color color = Color.yellow;\r
-    int row, col;\r
-    for (col = 0; col < width; col++)\r
+    int row, col, sameRow = 0, sameCol = 0;\r
+    jalview.datamodel.SequenceI seq;\r
+    boolean hiddenRow = false;\r
+    for (row = 0; row <= sequencesHeight; row++)\r
     {\r
-      for (row = 0; row < sequencesHeight; row++)\r
+      if ( (int) (row * sampleRow) == lastrow)\r
+      {\r
+        sameRow++;\r
+        continue;\r
+      }\r
+\r
+      hiddenRow = false;\r
+      if (av.hasHiddenRows)\r
       {\r
-        if((int)(col*sampleCol) == lastcol && (int)(row*sampleRow)==lastrow)\r
+        seq = av.alignment.getHiddenSequences().getHiddenSequence(lastrow);\r
+        if (seq == null)\r
         {\r
-          mg.drawLine(col, row, col, row);\r
-          continue;\r
+          int index =\r
+              av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(\r
+              lastrow);\r
+\r
+          seq = av.alignment.getSequenceAt(index);\r
         }\r
+        else\r
+        {\r
+          hiddenRow = true;\r
+        }\r
+      }\r
+      else\r
+      {\r
+        seq = av.alignment.getSequenceAt(lastrow);\r
+      }\r
 \r
-        if (av.conservation != null)\r
+      for (col = 0; col < width; col++)\r
+      {\r
+        if ( (int) (col * sampleCol) == lastcol &&\r
+            (int) (row * sampleRow) == lastrow)\r
         {\r
-          mg.translate(col, sequencesHeight);\r
-          ap.annotationPanel.drawGraph(mg, av.conservation,\r
-                                       (int) (sampleCol) + 1,\r
-                                       graphHeight,\r
-                                       (int) (col * sampleCol),\r
-                                       (int) (col * sampleCol) + 1);\r
-          mg.translate( -col, -sequencesHeight);\r
+          sameCol++;\r
+          continue;\r
         }\r
 \r
-        lastrow = (int)(row*sampleRow);\r
-        lastcol = (int)(col*sampleCol);\r
+        lastcol = (int) (col * sampleCol);\r
 \r
-        if(av.alignment.getSequenceAt(lastrow).getLength()>lastcol)\r
+        if (seq.getLength() > lastcol)\r
         {\r
-          color = sr.findSequenceColour(av.alignment.getSequenceAt(lastrow), lastcol);\r
-\r
+          color = sr.getResidueBoxColour(\r
+              seq, lastcol);\r
 \r
           if (av.showSequenceFeatures)\r
-            color = fr.findFeatureColour(color,\r
-                                        av.alignment.getSequenceAt(lastrow),\r
-                                         lastcol);\r
+          {\r
+            color = fr.findFeatureColour(color, seq, lastcol);\r
+          }\r
+        }\r
+        else\r
+        {\r
+          color = Color.white; //White\r
+        }\r
+\r
+        if (hiddenRow ||\r
+            (av.hasHiddenColumns && !av.getColumnSelection().isVisible(lastcol)))\r
+        {\r
+          color = color.darker().darker();\r
         }\r
 \r
         mg.setColor(color);\r
-        mg.drawLine(col,row,col,row);\r
+        if (sameCol == 1 && sameRow == 1)\r
+        {\r
+          mg.drawLine(xstart, ystart, xstart, ystart);\r
+        }\r
+        else\r
+        {\r
+          mg.fillRect(xstart, ystart, sameCol, sameRow);\r
+        }\r
 \r
+        xstart = col;\r
+        sameCol = 1;\r
       }\r
+      lastrow = (int) (row * sampleRow);\r
+      ystart = row;\r
+      sameRow = 1;\r
     }\r
 \r
-\r
+    if (av.conservation != null)\r
+    {\r
+      for (col = 0; col < width; col++)\r
+      {\r
+        lastcol = (int) (col * sampleCol);\r
+        {\r
+          mg.translate(col, sequencesHeight);\r
+          ap.annotationPanel.drawGraph(mg, av.conservation,\r
+                                       (int) (sampleCol) + 1,\r
+                                       graphHeight,\r
+                                       (int) (col * sampleCol),\r
+                                       (int) (col * sampleCol) + 1);\r
+          mg.translate( -col, -sequencesHeight);\r
+        }\r
+      }\r
+    }\r
     System.gc();\r
 \r
     resizing = false;\r
 \r
     setBoxPosition();\r
 \r
-    if(resizeAgain)\r
+    if (resizeAgain)\r
     {\r
       resizeAgain = false;\r
       updateOverviewImage();\r
@@ -298,16 +382,49 @@ public class OverviewPanel
   public void setBoxPosition()\r
   {\r
     int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();\r
-    int fullsizeHeight = av.alignment.getHeight() * av.getCharHeight();\r
+    int fullsizeHeight = (av.alignment.getHeight()\r
+                          + av.alignment.getHiddenSequences().getSize()) *\r
+        av.getCharHeight();\r
+\r
+    int startRes = av.getStartRes();\r
+    int endRes = av.getEndRes();\r
+\r
+    if (av.hasHiddenColumns)\r
+    {\r
+      startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);\r
+      endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);\r
+    }\r
+\r
+    int startSeq = av.startSeq;\r
+    int endSeq = av.endSeq;\r
+\r
+    if (av.hasHiddenRows)\r
+    {\r
+      startSeq =\r
+          av.alignment.getHiddenSequences().adjustForHiddenSeqs(startSeq);\r
+\r
+      endSeq =\r
+          av.alignment.getHiddenSequences().adjustForHiddenSeqs(endSeq);\r
+\r
+    }\r
 \r
     scalew = (float) width / (float) fullsizeWidth;\r
     scaleh = (float) sequencesHeight / (float) fullsizeHeight;\r
 \r
-    boxX = (int) (av.getStartRes() * av.getCharWidth() * scalew);\r
-    boxY = (int) (av.getStartSeq() * av.getCharHeight() * scaleh);\r
-    boxWidth = (int) ( (av.getEndRes() - av.getStartRes() + 1) *\r
-                      av.getCharWidth() * scalew);\r
-    boxHeight = (int) (av.getEndSeq() * av.getCharHeight() * scaleh) - boxY;\r
+    boxX = (int) (startRes * av.getCharWidth() * scalew);\r
+    boxY = (int) (startSeq * av.getCharHeight() * scaleh);\r
+\r
+    if (av.hasHiddenColumns)\r
+    {\r
+      boxWidth = (int) ( (endRes - startRes + 1) * av.getCharWidth() * scalew);\r
+    }\r
+    else\r
+    {\r
+      boxWidth = (int) ( (endRes - startRes + 1) * av.getCharWidth() * scalew);\r
+    }\r
+\r
+    boxHeight = (int) ( (endSeq - startSeq) * av.getCharHeight() * scaleh);\r
+\r
     repaint();\r
   }\r
 \r
@@ -318,23 +435,15 @@ public class OverviewPanel
 \r
   public void paint(Graphics g)\r
   {\r
+    Graphics og = offscreen.getGraphics();\r
     if (miniMe != null)\r
     {\r
-      g.drawImage(miniMe, 0, 0, this);\r
-    }\r
-    else\r
-    {\r
-      g.setColor(Color.white);\r
-      g.fillRect(0, 0, getSize().width, getSize().height);\r
-      g.setColor(Color.black);\r
-      g.setFont(new Font("Verdana", Font.BOLD, 15));\r
-      g.drawString("Recalculating", 5, sequencesHeight / 2);\r
-      g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20);\r
+      og.drawImage(miniMe, 0, 0, this);\r
+      og.setColor(Color.red);\r
+      og.drawRect(boxX, boxY, boxWidth, boxHeight);\r
+      og.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);\r
+      g.drawImage(offscreen, 0, 0, this);\r
     }\r
-\r
-    g.setColor(Color.red);\r
-    g.drawRect(boxX, boxY, boxWidth, boxHeight);\r
-    g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);\r
   }\r
 \r
 }\r