BoldFont upperCase
[jalview.git] / src / jalview / appletgui / OverviewPanel.java
index 57150c3..cbbfcff 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
@@ -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
@@ -56,9 +57,10 @@ public class OverviewPanel
 \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
+    fr.overview = true;\r
 \r
 \r
 \r
@@ -123,9 +125,7 @@ public class OverviewPanel
   {\r
     boxX = evt.getX();\r
     boxY = evt.getY();\r
-\r
     checkValid();\r
-    repaint();\r
   }\r
 \r
   public void mouseReleased(MouseEvent evt)\r
@@ -133,8 +133,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,34 +140,56 @@ 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
   {\r
     if (boxY < 0)\r
     {\r
-      boxY = 0;\r
+        boxY = 0;\r
     }\r
 \r
-    if (boxY > sequencesHeight - boxHeight)\r
+    if (boxY > (sequencesHeight - boxHeight))\r
     {\r
-      boxY = sequencesHeight - boxHeight + 1;\r
+        boxY = sequencesHeight - boxHeight + 1;\r
     }\r
 \r
     if (boxX < 0)\r
     {\r
-      boxX = 0;\r
+        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.repaint();\r
   }\r
 \r
   /**\r
@@ -184,8 +204,10 @@ public class OverviewPanel
     }\r
 \r
     if (av.showSequenceFeatures)\r
-      fr.featuresDisplayed = ap.seqPanel.seqCanvas.getFeatureRenderer().featuresDisplayed;\r
-\r
+   {\r
+     fr.featureGroups = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups;\r
+     fr.featureColours = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours;\r
+   }\r
 \r
     resizing = true;\r
 \r
@@ -195,11 +217,10 @@ 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
@@ -212,6 +233,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
@@ -227,25 +253,93 @@ 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(lastrow);\r
+\r
+         seq = av.alignment.getSequenceAt(index);\r
+        }\r
+        else\r
+        {\r
+          hiddenRow = true;\r
         }\r
+      }\r
+      else\r
+        seq = av.alignment.getSequenceAt(lastrow);\r
 \r
-        if (av.conservation != null)\r
+        for (col = 0; col < width; col++)\r
+        {\r
+          if ( (int) (col * sampleCol) == lastcol && (int) (row * sampleRow) == lastrow)\r
+          {\r
+            sameCol ++;\r
+            continue;\r
+          }\r
+\r
+          lastcol = (int) (col * sampleCol);\r
+\r
+          if (seq.getLength() > lastcol)\r
+          {\r
+            color = sr.getResidueBoxColour(\r
+                seq, lastcol);\r
+\r
+            if (av.showSequenceFeatures)\r
+              color = fr.findFeatureColour(color, seq, lastcol);\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
+          if (sameCol == 1 && sameRow == 1)\r
+            mg.drawLine(xstart, ystart, xstart, ystart);\r
+          else\r
+            mg.fillRect(xstart, ystart, sameCol, sameRow);\r
+\r
+          xstart = col;\r
+          sameCol = 1;\r
+      }\r
+      lastrow = (int)(row*sampleRow);\r
+      ystart = row;\r
+      sameRow = 1;\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
@@ -255,28 +349,8 @@ public class OverviewPanel
                                        (int) (col * sampleCol) + 1);\r
           mg.translate( -col, -sequencesHeight);\r
         }\r
-\r
-        lastrow = (int)(row*sampleRow);\r
-        lastcol = (int)(col*sampleCol);\r
-\r
-        if(av.alignment.getSequenceAt(lastrow).getLength()>lastcol)\r
-        {\r
-          color = sr.findSequenceColour(av.alignment.getSequenceAt(lastrow), lastcol);\r
-\r
-\r
-          if (av.showSequenceFeatures)\r
-            color = fr.findFeatureColour(color,\r
-                                        av.alignment.getSequenceAt(lastrow),\r
-                                         lastcol);\r
-        }\r
-\r
-        mg.setColor(color);\r
-        mg.drawLine(col,row,col,row);\r
-\r
       }\r
     }\r
-\r
-\r
     System.gc();\r
 \r
     resizing = false;\r
@@ -288,21 +362,50 @@ public class OverviewPanel
       resizeAgain = false;\r
       updateOverviewImage();\r
     }\r
-  }\r
+}\r
 \r
   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
+      boxWidth = (int) ( (endRes - startRes + 1) * av.getCharWidth() * scalew);\r
+    else\r
+      boxWidth = (int) ( (endRes - startRes + 1) * av.getCharWidth() * scalew);\r
+\r
+    boxHeight = (int) ( (endSeq - startSeq) * av.getCharHeight() * scaleh);\r
+\r
     repaint();\r
   }\r
 \r
@@ -313,9 +416,14 @@ 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
+      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
     else\r
     {\r
@@ -326,10 +434,6 @@ public class OverviewPanel
       g.drawString("Recalculating", 5, sequencesHeight / 2);\r
       g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20);\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