Sequence label colour stored for each sequence group
authorjprocter <Jim Procter>
Fri, 18 Jul 2008 13:31:02 +0000 (13:31 +0000)
committerjprocter <Jim Procter>
Fri, 18 Jul 2008 13:31:02 +0000 (13:31 +0000)
src/jalview/appletgui/AlignViewport.java
src/jalview/appletgui/AlignmentPanel.java
src/jalview/appletgui/TreeCanvas.java

index 193c9b0..33a73d3 100755 (executable)
@@ -1449,4 +1449,21 @@ public class AlignViewport
     return centreColumnLabels;
   }
 
+  public void updateSequenceIdColours()
+  {
+    Vector groups = alignment.getGroups();
+    for (int ig=0,igSize=groups.size(); ig<igSize; ig++)
+    {
+      SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
+      if (sg.idColour!=null)
+      {
+        Vector sqs = sg.getSequences(hiddenRepSequences);
+        for (int s=0,sSize=sqs.size();s<sSize;s++)
+        {
+          this.setSequenceColour((SequenceI) sqs.elementAt(s), sg.idColour);
+        } 
+      }
+    }
+  }
+
 }
index 2b9e4e6..6b292e9 100755 (executable)
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\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
- * 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
-package jalview.appletgui;\r
-\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-\r
-import jalview.datamodel.*;\r
-\r
-public class AlignmentPanel\r
-    extends Panel implements AdjustmentListener\r
-{\r
-\r
-  public AlignViewport av;\r
-  OverviewPanel overviewPanel;\r
-  SeqPanel seqPanel;\r
-  IdPanel idPanel;\r
-  IdwidthAdjuster idwidthAdjuster;\r
-  public AlignFrame alignFrame;\r
-  ScalePanel scalePanel;\r
-  AnnotationPanel annotationPanel;\r
-  AnnotationLabels alabels;\r
-\r
-  // this value is set false when selection area being dragged\r
-  boolean fastPaint = true;\r
-\r
-  public AlignmentPanel(AlignFrame af, final AlignViewport av)\r
-  {\r
-    try\r
-    {\r
-      jbInit();\r
-    }\r
-    catch (Exception e)\r
-    {\r
-      e.printStackTrace();\r
-    }\r
-\r
-    alignFrame = af;\r
-    this.av = av;\r
-    seqPanel = new SeqPanel(av, this);\r
-    idPanel = new IdPanel(av, this);\r
-    scalePanel = new ScalePanel(av, this);\r
-    idwidthAdjuster = new IdwidthAdjuster(this);\r
-    annotationPanel = new AnnotationPanel(this);\r
-\r
-    sequenceHolderPanel.add(annotationPanel, BorderLayout.SOUTH);\r
-\r
-    alabels = new AnnotationLabels(this);\r
-\r
-    setAnnotationVisible(av.showAnnotation);\r
-\r
-    idPanelHolder.add(idPanel, BorderLayout.CENTER);\r
-    idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);\r
-    annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);\r
-    scalePanelHolder.add(scalePanel, BorderLayout.CENTER);\r
-    seqPanelHolder.add(seqPanel, BorderLayout.CENTER);\r
-\r
-    fontChanged();\r
-    setScrollValues(0, 0);\r
-\r
-    hscroll.addAdjustmentListener(this);\r
-    vscroll.addAdjustmentListener(this);\r
-\r
-    addComponentListener(new ComponentAdapter()\r
-    {\r
-      public void componentResized(ComponentEvent evt)\r
-      {\r
-        setScrollValues(av.getStartRes(), av.getStartSeq());\r
-        repaint();\r
-      }\r
-    });\r
-\r
-    Dimension d = calculateIdWidth();\r
-    idPanel.idCanvas.setSize(d);\r
-\r
-    hscrollFillerPanel.setSize(d.width, annotationPanel.getSize().height);\r
-\r
-    idPanel.idCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height);\r
-    annotationSpaceFillerHolder.setSize(d.width,\r
-                                        annotationPanel.getSize().height);\r
-    alabels.setSize(d.width, annotationPanel.getSize().height);\r
-\r
-    final AlignmentPanel ap = this;\r
-    av.addPropertyChangeListener(new java.beans.PropertyChangeListener()\r
-    {\r
-      public void propertyChange(java.beans.PropertyChangeEvent evt)\r
-      {\r
-        if (evt.getPropertyName().equals("alignment"))\r
-        {\r
-          PaintRefresher.Refresh(ap,\r
-                                 av.getSequenceSetId(),\r
-                                 true,\r
-                                 true);\r
-          alignmentChanged();\r
-        }\r
-      }\r
-    });\r
-\r
-  }\r
-\r
-  public SequenceRenderer getSequenceRenderer()\r
-  {\r
-    return seqPanel.seqCanvas.sr;\r
-  }\r
-\r
-  public FeatureRenderer getFeatureRenderer()\r
-  {\r
-    return seqPanel.seqCanvas.fr;\r
-  }\r
-\r
-  public void alignmentChanged()\r
-  {\r
-    av.alignmentChanged(this);\r
-\r
-    if (overviewPanel != null)\r
-    {\r
-      overviewPanel.updateOverviewImage();\r
-    }\r
-\r
-    alignFrame.updateEditMenuBar();\r
-\r
-    repaint();\r
-  }\r
-\r
-  public void fontChanged()\r
-  {\r
-    // set idCanvas bufferedImage to null\r
-    // to prevent drawing old image\r
-    idPanel.idCanvas.image = null;\r
-    FontMetrics fm = getFontMetrics(av.getFont());\r
-\r
-    scalePanel.setSize(new Dimension(10, av.charHeight + fm.getDescent()));\r
-    idwidthAdjuster.setSize(new Dimension(10, av.charHeight + fm.getDescent()));\r
-\r
-    annotationPanel.image = null;\r
-    int ap = annotationPanel.adjustPanelHeight();\r
-    annotationPanel.repaint();\r
-    Dimension d = calculateIdWidth();\r
-    d.setSize(d.width + 4, seqPanel.seqCanvas.getSize().height);\r
-    alabels.setSize(d.width + 4, ap);\r
-    idPanel.idCanvas.setSize(d);\r
-    hscrollFillerPanel.setSize(d);\r
-\r
-    validate();\r
-    repaint();\r
-\r
-    if (overviewPanel != null)\r
-    {\r
-      overviewPanel.updateOverviewImage();\r
-    }\r
-  }\r
-\r
-  public void setIdWidth(int w, int h)\r
-  {\r
-    idPanel.idCanvas.setSize(w, h);\r
-    idPanelHolder.setSize(w, idPanelHolder.getSize().height);\r
-    alabels.setSize(w, alabels.getSize().height);\r
-    validate();\r
-  }\r
-\r
-  Dimension calculateIdWidth()\r
-  {\r
-    if (av.nullFrame == null)\r
-    {\r
-      av.nullFrame = new Frame();\r
-      av.nullFrame.addNotify();\r
-    }\r
-\r
-    Graphics g = av.nullFrame.getGraphics();\r
-\r
-    FontMetrics fm = g.getFontMetrics(av.font);\r
-    AlignmentI al = av.getAlignment();\r
-\r
-    int i = 0;\r
-    int idWidth = 0;\r
-    String id;\r
-    while (i < al.getHeight() && al.getSequenceAt(i) != null)\r
-    {\r
-      SequenceI s = al.getSequenceAt(i);\r
-      id = s.getDisplayId(av.getShowJVSuffix());\r
-\r
-      if (fm.stringWidth(id) > idWidth)\r
-      {\r
-        idWidth = fm.stringWidth(id);\r
-      }\r
-      i++;\r
-    }\r
-\r
-    // Also check annotation label widths\r
-    i = 0;\r
-    if (al.getAlignmentAnnotation() != null)\r
-    {\r
-      fm = g.getFontMetrics(av.nullFrame.getFont());\r
-      while (i < al.getAlignmentAnnotation().length)\r
-      {\r
-        String label = al.getAlignmentAnnotation()[i].label;\r
-        if (fm.stringWidth(label) > idWidth)\r
-        {\r
-          idWidth = fm.stringWidth(label);\r
-        }\r
-        i++;\r
-      }\r
-    }\r
-\r
-    return new Dimension(idWidth, idPanel.idCanvas.getSize().height);\r
-  }\r
-\r
-  public void highlightSearchResults(SearchResults results)\r
-  {\r
-    seqPanel.seqCanvas.highlightSearchResults(results);\r
-\r
-    // do we need to scroll the panel?\r
-    if (results != null)\r
-    {\r
-      SequenceI seq = results.getResultSequence(0);\r
-      int seqIndex = av.alignment.findIndex(seq);\r
-      int start = seq.findIndex(results.getResultStart(0)) - 1;\r
-      int end = seq.findIndex(results.getResultEnd(0)) - 1;\r
-\r
-      if (!av.wrapAlignment)\r
-      {\r
-        if ( (av.getStartRes() > end) || (av.getEndRes() < start) ||\r
-            ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))\r
-        {\r
-          if (start > av.alignment.getWidth() - hextent)\r
-          {\r
-            start = av.alignment.getWidth() - hextent;\r
-            if (start < 0)\r
-            {\r
-              start = 0;\r
-            }\r
-          }\r
-          if (seqIndex > av.alignment.getHeight() - vextent)\r
-          {\r
-            seqIndex = av.alignment.getHeight() - vextent;\r
-            if (seqIndex < 0)\r
-            {\r
-              seqIndex = 0;\r
-            }\r
-          }\r
-          setScrollValues(start, seqIndex);\r
-        }\r
-      }\r
-      else\r
-      {\r
-        scrollToWrappedVisible(start);\r
-      }\r
-    }\r
-\r
-    repaint();\r
-  }\r
-\r
-  void scrollToWrappedVisible(int res)\r
-  {\r
-    int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.\r
-        getSize().width);\r
-    if (res <= av.getStartRes() || res >= (av.getStartRes() + cwidth))\r
-    {\r
-      vscroll.setValue(res / cwidth);\r
-      av.startRes = vscroll.getValue() * cwidth;\r
-    }\r
-  }\r
-\r
-  public OverviewPanel getOverviewPanel()\r
-  {\r
-    return overviewPanel;\r
-  }\r
-\r
-  public void setOverviewPanel(OverviewPanel op)\r
-  {\r
-    overviewPanel = op;\r
-  }\r
-\r
-  public void setAnnotationVisible(boolean b)\r
-  {\r
-    if (!av.wrapAlignment)\r
-    {\r
-      annotationSpaceFillerHolder.setVisible(b);\r
-      annotationPanel.setVisible(b);\r
-    }\r
-    validate();\r
-    repaint();\r
-  }\r
-\r
-  public void setWrapAlignment(boolean wrap)\r
-  {\r
-    av.startSeq = 0;\r
-    av.startRes = 0;\r
-    scalePanelHolder.setVisible(!wrap);\r
-\r
-    hscroll.setVisible(!wrap);\r
-    idwidthAdjuster.setVisible(!wrap);\r
-\r
-    if (wrap)\r
-    {\r
-      annotationPanel.setVisible(false);\r
-      annotationSpaceFillerHolder.setVisible(false);\r
-    }\r
-    else if (av.showAnnotation)\r
-    {\r
-      annotationPanel.setVisible(true);\r
-      annotationSpaceFillerHolder.setVisible(true);\r
-    }\r
-\r
-    idSpaceFillerPanel1.setVisible(!wrap);\r
-\r
-    fontChanged(); //This is so that the scalePanel is resized correctly\r
-\r
-    validate();\r
-    repaint();\r
-\r
-  }\r
-\r
-  int hextent = 0;\r
-  int vextent = 0;\r
-\r
-  // return value is true if the scroll is valid\r
-  public boolean scrollUp(boolean up)\r
-  {\r
-    if (up)\r
-    {\r
-      if (vscroll.getValue() < 1)\r
-      {\r
-        return false;\r
-      }\r
-      setScrollValues(hscroll.getValue(), vscroll.getValue() - 1);\r
-    }\r
-    else\r
-    {\r
-      if (vextent + vscroll.getValue() >= av.getAlignment().getHeight())\r
-      {\r
-        return false;\r
-      }\r
-      setScrollValues(hscroll.getValue(), vscroll.getValue() + 1);\r
-    }\r
-\r
-    repaint();\r
-    return true;\r
-  }\r
-\r
-  public boolean scrollRight(boolean right)\r
-  {\r
-    if (!right)\r
-    {\r
-      if (hscroll.getValue() < 1)\r
-      {\r
-        return false;\r
-      }\r
-      setScrollValues(hscroll.getValue() - 1, vscroll.getValue());\r
-    }\r
-    else\r
-    {\r
-      if (hextent + hscroll.getValue() >= av.getAlignment().getWidth())\r
-      {\r
-        return false;\r
-      }\r
-      setScrollValues(hscroll.getValue() + 1, vscroll.getValue());\r
-    }\r
-\r
-    repaint();\r
-    return true;\r
-  }\r
-\r
-  public void setScrollValues(int x, int y)\r
-  {\r
-    int width = av.alignment.getWidth();\r
-    int height = av.alignment.getHeight();\r
-\r
-    if (av.hasHiddenColumns)\r
-    {\r
-      width = av.getColumnSelection().findColumnPosition(width);\r
-    }\r
-\r
-    av.setStartRes(x);\r
-    av.setEndRes( (x + (seqPanel.seqCanvas.getSize().width / av.charWidth)) - 1);\r
-\r
-    hextent = seqPanel.seqCanvas.getSize().width / av.charWidth;\r
-    vextent = seqPanel.seqCanvas.getSize().height / av.charHeight;\r
-\r
-    if (hextent > width)\r
-    {\r
-      hextent = width;\r
-    }\r
-\r
-    if (vextent > height)\r
-    {\r
-      vextent = height;\r
-    }\r
-\r
-    if ( (hextent + x) > width)\r
-    {\r
-      x = width - hextent;\r
-    }\r
-\r
-    if ( (vextent + y) > height)\r
-    {\r
-      y = height - vextent;\r
-    }\r
-\r
-    if (y < 0)\r
-    {\r
-      y = 0;\r
-    }\r
-\r
-    if (x < 0)\r
-    {\r
-      x = 0;\r
-    }\r
-\r
-    av.setStartSeq(y);\r
-\r
-    int endSeq = y + vextent;\r
-    if (endSeq > av.alignment.getHeight())\r
-    {\r
-      endSeq = av.alignment.getHeight();\r
-    }\r
-\r
-    av.setEndSeq(endSeq);\r
-    hscroll.setValues(x, hextent, 0, width);\r
-    vscroll.setValues(y, vextent, 0, height);\r
-\r
-    if (overviewPanel != null)\r
-    {\r
-      overviewPanel.setBoxPosition();\r
-    }\r
-\r
-  }\r
-\r
-  public void adjustmentValueChanged(AdjustmentEvent evt)\r
-  {\r
-    int oldX = av.getStartRes();\r
-    int oldY = av.getStartSeq();\r
-\r
-    if (evt == null || evt.getSource() == hscroll)\r
-    {\r
-      int x = hscroll.getValue();\r
-      av.setStartRes(x);\r
-      av.setEndRes(x + seqPanel.seqCanvas.getSize().width / av.getCharWidth() -\r
-                   1);\r
-    }\r
-\r
-    if (evt == null || evt.getSource() == vscroll)\r
-    {\r
-      int offy = vscroll.getValue();\r
-      if (av.getWrapAlignment())\r
-      {\r
-        int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.\r
-            seqCanvas.getSize().width);\r
-        av.setStartRes(vscroll.getValue() * rowSize);\r
-        av.setEndRes( (vscroll.getValue() + 1) * rowSize);\r
-      }\r
-      else\r
-      {\r
-        av.setStartSeq(offy);\r
-        av.setEndSeq(offy +\r
-                     seqPanel.seqCanvas.getSize().height / av.getCharHeight());\r
-      }\r
-    }\r
-\r
-    if (overviewPanel != null)\r
-    {\r
-      overviewPanel.setBoxPosition();\r
-    }\r
-\r
-    int scrollX = av.startRes - oldX;\r
-    int scrollY = av.startSeq - oldY;\r
-\r
-    if (av.getWrapAlignment() || !fastPaint || av.MAC)\r
-    {\r
-      repaint();\r
-    }\r
-    else\r
-    {\r
-      // Make sure we're not trying to draw a panel\r
-      // larger than the visible window\r
-      if (scrollX > av.endRes - av.startRes)\r
-      {\r
-        scrollX = av.endRes - av.startRes;\r
-      }\r
-      else if (scrollX < av.startRes - av.endRes)\r
-      {\r
-        scrollX = av.startRes - av.endRes;\r
-      }\r
-\r
-      idPanel.idCanvas.fastPaint(scrollY);\r
-      seqPanel.seqCanvas.fastPaint(scrollX,\r
-                                   scrollY);\r
-\r
-      scalePanel.repaint();\r
-      if (av.getShowAnnotation())\r
-      {\r
-        annotationPanel.fastPaint(av.getStartRes() - oldX);\r
-      }\r
-    }\r
-\r
-  }\r
-\r
-  public void paintAlignment(boolean updateOverview)\r
-  {\r
-    repaint();\r
-\r
-    if(updateOverview)\r
-    {\r
-      jalview.structure.StructureSelectionManager.getStructureSelectionManager()\r
-          .sequenceColoursChanged(this);\r
-\r
-      if (overviewPanel != null)\r
-      {\r
-        overviewPanel.updateOverviewImage();\r
-      }\r
-    }\r
-  }\r
-\r
-  public void update(Graphics g)\r
-  {\r
-    paint(g);\r
-  }\r
-\r
-  public void paint(Graphics g)\r
-  {\r
-    invalidate();\r
-    Dimension d = idPanel.idCanvas.getSize();\r
-    idPanel.idCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height);\r
-    annotationSpaceFillerHolder.setSize(d.width,\r
-                                        annotationPanel.getSize().height);\r
-\r
-    alabels.setSize(d.width, annotationPanel.getSize().height);\r
-\r
-    if (av.getWrapAlignment())\r
-    {\r
-      int maxwidth = av.alignment.getWidth();\r
-\r
-      if (av.hasHiddenColumns)\r
-      {\r
-        maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;\r
-      }\r
-\r
-      int canvasWidth = seqPanel.seqCanvas.getWrappedCanvasWidth\r
-          (seqPanel.seqCanvas.getSize().width);\r
-\r
-      if (canvasWidth > 0)\r
-      {\r
-        int max = maxwidth / canvasWidth;\r
-        vscroll.setMaximum(max);\r
-        vscroll.setUnitIncrement(1);\r
-        vscroll.setVisibleAmount(1);\r
-      }\r
-    }\r
-    else\r
-    {\r
-      setScrollValues(av.getStartRes(), av.getStartSeq());\r
-    }\r
-\r
-    alabels.repaint();\r
-\r
-    seqPanel.seqCanvas.repaint();\r
-    scalePanel.repaint();\r
-    annotationPanel.repaint();\r
-    idPanel.idCanvas.repaint();\r
-  }\r
-\r
-  protected Panel sequenceHolderPanel = new Panel();\r
-  protected Scrollbar vscroll = new Scrollbar();\r
-  protected Scrollbar hscroll = new Scrollbar();\r
-  protected Panel seqPanelHolder = new Panel();\r
-  BorderLayout borderLayout1 = new BorderLayout();\r
-  BorderLayout borderLayout3 = new BorderLayout();\r
-  protected Panel scalePanelHolder = new Panel();\r
-  protected Panel idPanelHolder = new Panel();\r
-  BorderLayout borderLayout5 = new BorderLayout();\r
-  protected Panel idSpaceFillerPanel1 = new Panel();\r
-  public Panel annotationSpaceFillerHolder = new Panel();\r
-  BorderLayout borderLayout6 = new BorderLayout();\r
-  BorderLayout borderLayout7 = new BorderLayout();\r
-  Panel hscrollHolder = new Panel();\r
-  BorderLayout borderLayout10 = new BorderLayout();\r
-  protected Panel hscrollFillerPanel = new Panel();\r
-  BorderLayout borderLayout11 = new BorderLayout();\r
-  BorderLayout borderLayout4 = new BorderLayout();\r
-  BorderLayout borderLayout2 = new BorderLayout();\r
-\r
-  private void jbInit()\r
-      throws Exception\r
-  {\r
-    //  idPanelHolder.setPreferredSize(new Dimension(70, 10));\r
-    this.setLayout(borderLayout7);\r
-\r
-    //   sequenceHolderPanel.setPreferredSize(new Dimension(150, 150));\r
-    sequenceHolderPanel.setLayout(borderLayout3);\r
-    seqPanelHolder.setLayout(borderLayout1);\r
-    scalePanelHolder.setBackground(Color.white);\r
-\r
-    // scalePanelHolder.setPreferredSize(new Dimension(10, 30));\r
-    scalePanelHolder.setLayout(borderLayout6);\r
-    idPanelHolder.setLayout(borderLayout5);\r
-    idSpaceFillerPanel1.setBackground(Color.white);\r
-\r
-    //  idSpaceFillerPanel1.setPreferredSize(new Dimension(10, 30));\r
-    idSpaceFillerPanel1.setLayout(borderLayout11);\r
-    annotationSpaceFillerHolder.setBackground(Color.white);\r
-\r
-    //  annotationSpaceFillerHolder.setPreferredSize(new Dimension(10, 80));\r
-    annotationSpaceFillerHolder.setLayout(borderLayout4);\r
-    hscroll.setOrientation(Scrollbar.HORIZONTAL);\r
-    hscrollHolder.setLayout(borderLayout10);\r
-    hscrollFillerPanel.setBackground(Color.white);\r
-\r
-    //  hscrollFillerPanel.setPreferredSize(new Dimension(70, 10));\r
-    hscrollHolder.setBackground(Color.white);\r
-\r
-    //    annotationScroller.setPreferredSize(new Dimension(10, 80));\r
-    //  this.setPreferredSize(new Dimension(220, 166));\r
-    seqPanelHolder.setBackground(Color.white);\r
-    idPanelHolder.setBackground(Color.white);\r
-    sequenceHolderPanel.add(scalePanelHolder, BorderLayout.NORTH);\r
-    sequenceHolderPanel.add(seqPanelHolder, BorderLayout.CENTER);\r
-    seqPanelHolder.add(vscroll, BorderLayout.EAST);\r
-\r
-    //  Panel3.add(secondaryPanelHolder,  BorderLayout.SOUTH);\r
-    this.add(idPanelHolder, BorderLayout.WEST);\r
-    idPanelHolder.add(idSpaceFillerPanel1, BorderLayout.NORTH);\r
-    idPanelHolder.add(annotationSpaceFillerHolder, BorderLayout.SOUTH);\r
-    this.add(hscrollHolder, BorderLayout.SOUTH);\r
-    hscrollHolder.add(hscroll, BorderLayout.CENTER);\r
-    hscrollHolder.add(hscrollFillerPanel, BorderLayout.WEST);\r
-    this.add(sequenceHolderPanel, BorderLayout.CENTER);\r
-  }\r
-\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2007 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
+ */
+
+package jalview.appletgui;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import jalview.datamodel.*;
+
+public class AlignmentPanel
+    extends Panel implements AdjustmentListener
+{
+
+  public AlignViewport av;
+  OverviewPanel overviewPanel;
+  SeqPanel seqPanel;
+  IdPanel idPanel;
+  IdwidthAdjuster idwidthAdjuster;
+  public AlignFrame alignFrame;
+  ScalePanel scalePanel;
+  AnnotationPanel annotationPanel;
+  AnnotationLabels alabels;
+
+  // this value is set false when selection area being dragged
+  boolean fastPaint = true;
+
+  public AlignmentPanel(AlignFrame af, final AlignViewport av)
+  {
+    try
+    {
+      jbInit();
+    }
+    catch (Exception e)
+    {
+      e.printStackTrace();
+    }
+
+    alignFrame = af;
+    this.av = av;
+    seqPanel = new SeqPanel(av, this);
+    idPanel = new IdPanel(av, this);
+    scalePanel = new ScalePanel(av, this);
+    idwidthAdjuster = new IdwidthAdjuster(this);
+    annotationPanel = new AnnotationPanel(this);
+
+    sequenceHolderPanel.add(annotationPanel, BorderLayout.SOUTH);
+
+    alabels = new AnnotationLabels(this);
+
+    setAnnotationVisible(av.showAnnotation);
+
+    idPanelHolder.add(idPanel, BorderLayout.CENTER);
+    idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
+    annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
+    scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
+    seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
+
+    fontChanged();
+    setScrollValues(0, 0);
+
+    hscroll.addAdjustmentListener(this);
+    vscroll.addAdjustmentListener(this);
+
+    addComponentListener(new ComponentAdapter()
+    {
+      public void componentResized(ComponentEvent evt)
+      {
+        setScrollValues(av.getStartRes(), av.getStartSeq());
+        repaint();
+      }
+    });
+
+    Dimension d = calculateIdWidth();
+    idPanel.idCanvas.setSize(d);
+
+    hscrollFillerPanel.setSize(d.width, annotationPanel.getSize().height);
+
+    idPanel.idCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height);
+    annotationSpaceFillerHolder.setSize(d.width,
+                                        annotationPanel.getSize().height);
+    alabels.setSize(d.width, annotationPanel.getSize().height);
+
+    final AlignmentPanel ap = this;
+    av.addPropertyChangeListener(new java.beans.PropertyChangeListener()
+    {
+      public void propertyChange(java.beans.PropertyChangeEvent evt)
+      {
+        if (evt.getPropertyName().equals("alignment"))
+        {
+          PaintRefresher.Refresh(ap,
+                                 av.getSequenceSetId(),
+                                 true,
+                                 true);
+          alignmentChanged();
+        }
+      }
+    });
+
+  }
+
+  public SequenceRenderer getSequenceRenderer()
+  {
+    return seqPanel.seqCanvas.sr;
+  }
+
+  public FeatureRenderer getFeatureRenderer()
+  {
+    return seqPanel.seqCanvas.fr;
+  }
+
+  public void alignmentChanged()
+  {
+    av.alignmentChanged(this);
+
+    if (overviewPanel != null)
+    {
+      overviewPanel.updateOverviewImage();
+    }
+
+    alignFrame.updateEditMenuBar();
+
+    repaint();
+  }
+
+  public void fontChanged()
+  {
+    // set idCanvas bufferedImage to null
+    // to prevent drawing old image
+    idPanel.idCanvas.image = null;
+    FontMetrics fm = getFontMetrics(av.getFont());
+
+    scalePanel.setSize(new Dimension(10, av.charHeight + fm.getDescent()));
+    idwidthAdjuster.setSize(new Dimension(10, av.charHeight + fm.getDescent()));
+    av.updateSequenceIdColours();
+    annotationPanel.image = null;
+    int ap = annotationPanel.adjustPanelHeight();
+    annotationPanel.repaint();
+    Dimension d = calculateIdWidth();
+    d.setSize(d.width + 4, seqPanel.seqCanvas.getSize().height);
+    alabels.setSize(d.width + 4, ap);
+    idPanel.idCanvas.setSize(d);
+    hscrollFillerPanel.setSize(d);
+
+    validate();
+    repaint();
+
+    if (overviewPanel != null)
+    {
+      overviewPanel.updateOverviewImage();
+    }
+  }
+
+  public void setIdWidth(int w, int h)
+  {
+    idPanel.idCanvas.setSize(w, h);
+    idPanelHolder.setSize(w, idPanelHolder.getSize().height);
+    alabels.setSize(w, alabels.getSize().height);
+    validate();
+  }
+
+  Dimension calculateIdWidth()
+  {
+    if (av.nullFrame == null)
+    {
+      av.nullFrame = new Frame();
+      av.nullFrame.addNotify();
+    }
+
+    Graphics g = av.nullFrame.getGraphics();
+
+    FontMetrics fm = g.getFontMetrics(av.font);
+    AlignmentI al = av.getAlignment();
+
+    int i = 0;
+    int idWidth = 0;
+    String id;
+    while (i < al.getHeight() && al.getSequenceAt(i) != null)
+    {
+      SequenceI s = al.getSequenceAt(i);
+      id = s.getDisplayId(av.getShowJVSuffix());
+
+      if (fm.stringWidth(id) > idWidth)
+      {
+        idWidth = fm.stringWidth(id);
+      }
+      i++;
+    }
+
+    // Also check annotation label widths
+    i = 0;
+    if (al.getAlignmentAnnotation() != null)
+    {
+      fm = g.getFontMetrics(av.nullFrame.getFont());
+      while (i < al.getAlignmentAnnotation().length)
+      {
+        String label = al.getAlignmentAnnotation()[i].label;
+        if (fm.stringWidth(label) > idWidth)
+        {
+          idWidth = fm.stringWidth(label);
+        }
+        i++;
+      }
+    }
+
+    return new Dimension(idWidth, idPanel.idCanvas.getSize().height);
+  }
+
+  public void highlightSearchResults(SearchResults results)
+  {
+    seqPanel.seqCanvas.highlightSearchResults(results);
+
+    // do we need to scroll the panel?
+    if (results != null)
+    {
+      SequenceI seq = results.getResultSequence(0);
+      int seqIndex = av.alignment.findIndex(seq);
+      int start = seq.findIndex(results.getResultStart(0)) - 1;
+      int end = seq.findIndex(results.getResultEnd(0)) - 1;
+
+      if (!av.wrapAlignment)
+      {
+        if ( (av.getStartRes() > end) || (av.getEndRes() < start) ||
+            ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
+        {
+          if (start > av.alignment.getWidth() - hextent)
+          {
+            start = av.alignment.getWidth() - hextent;
+            if (start < 0)
+            {
+              start = 0;
+            }
+          }
+          if (seqIndex > av.alignment.getHeight() - vextent)
+          {
+            seqIndex = av.alignment.getHeight() - vextent;
+            if (seqIndex < 0)
+            {
+              seqIndex = 0;
+            }
+          }
+          setScrollValues(start, seqIndex);
+        }
+      }
+      else
+      {
+        scrollToWrappedVisible(start);
+      }
+    }
+
+    repaint();
+  }
+
+  void scrollToWrappedVisible(int res)
+  {
+    int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.
+        getSize().width);
+    if (res <= av.getStartRes() || res >= (av.getStartRes() + cwidth))
+    {
+      vscroll.setValue(res / cwidth);
+      av.startRes = vscroll.getValue() * cwidth;
+    }
+  }
+
+  public OverviewPanel getOverviewPanel()
+  {
+    return overviewPanel;
+  }
+
+  public void setOverviewPanel(OverviewPanel op)
+  {
+    overviewPanel = op;
+  }
+
+  public void setAnnotationVisible(boolean b)
+  {
+    if (!av.wrapAlignment)
+    {
+      annotationSpaceFillerHolder.setVisible(b);
+      annotationPanel.setVisible(b);
+    }
+    validate();
+    repaint();
+  }
+
+  public void setWrapAlignment(boolean wrap)
+  {
+    av.startSeq = 0;
+    av.startRes = 0;
+    scalePanelHolder.setVisible(!wrap);
+
+    hscroll.setVisible(!wrap);
+    idwidthAdjuster.setVisible(!wrap);
+
+    if (wrap)
+    {
+      annotationPanel.setVisible(false);
+      annotationSpaceFillerHolder.setVisible(false);
+    }
+    else if (av.showAnnotation)
+    {
+      annotationPanel.setVisible(true);
+      annotationSpaceFillerHolder.setVisible(true);
+    }
+
+    idSpaceFillerPanel1.setVisible(!wrap);
+
+    fontChanged(); //This is so that the scalePanel is resized correctly
+
+    validate();
+    repaint();
+
+  }
+
+  int hextent = 0;
+  int vextent = 0;
+
+  // return value is true if the scroll is valid
+  public boolean scrollUp(boolean up)
+  {
+    if (up)
+    {
+      if (vscroll.getValue() < 1)
+      {
+        return false;
+      }
+      setScrollValues(hscroll.getValue(), vscroll.getValue() - 1);
+    }
+    else
+    {
+      if (vextent + vscroll.getValue() >= av.getAlignment().getHeight())
+      {
+        return false;
+      }
+      setScrollValues(hscroll.getValue(), vscroll.getValue() + 1);
+    }
+
+    repaint();
+    return true;
+  }
+
+  public boolean scrollRight(boolean right)
+  {
+    if (!right)
+    {
+      if (hscroll.getValue() < 1)
+      {
+        return false;
+      }
+      setScrollValues(hscroll.getValue() - 1, vscroll.getValue());
+    }
+    else
+    {
+      if (hextent + hscroll.getValue() >= av.getAlignment().getWidth())
+      {
+        return false;
+      }
+      setScrollValues(hscroll.getValue() + 1, vscroll.getValue());
+    }
+
+    repaint();
+    return true;
+  }
+
+  public void setScrollValues(int x, int y)
+  {
+    int width = av.alignment.getWidth();
+    int height = av.alignment.getHeight();
+
+    if (av.hasHiddenColumns)
+    {
+      width = av.getColumnSelection().findColumnPosition(width);
+    }
+
+    av.setStartRes(x);
+    av.setEndRes( (x + (seqPanel.seqCanvas.getSize().width / av.charWidth)) - 1);
+
+    hextent = seqPanel.seqCanvas.getSize().width / av.charWidth;
+    vextent = seqPanel.seqCanvas.getSize().height / av.charHeight;
+
+    if (hextent > width)
+    {
+      hextent = width;
+    }
+
+    if (vextent > height)
+    {
+      vextent = height;
+    }
+
+    if ( (hextent + x) > width)
+    {
+      x = width - hextent;
+    }
+
+    if ( (vextent + y) > height)
+    {
+      y = height - vextent;
+    }
+
+    if (y < 0)
+    {
+      y = 0;
+    }
+
+    if (x < 0)
+    {
+      x = 0;
+    }
+
+    av.setStartSeq(y);
+
+    int endSeq = y + vextent;
+    if (endSeq > av.alignment.getHeight())
+    {
+      endSeq = av.alignment.getHeight();
+    }
+
+    av.setEndSeq(endSeq);
+    hscroll.setValues(x, hextent, 0, width);
+    vscroll.setValues(y, vextent, 0, height);
+
+    if (overviewPanel != null)
+    {
+      overviewPanel.setBoxPosition();
+    }
+
+  }
+
+  public void adjustmentValueChanged(AdjustmentEvent evt)
+  {
+    int oldX = av.getStartRes();
+    int oldY = av.getStartSeq();
+
+    if (evt == null || evt.getSource() == hscroll)
+    {
+      int x = hscroll.getValue();
+      av.setStartRes(x);
+      av.setEndRes(x + seqPanel.seqCanvas.getSize().width / av.getCharWidth() -
+                   1);
+    }
+
+    if (evt == null || evt.getSource() == vscroll)
+    {
+      int offy = vscroll.getValue();
+      if (av.getWrapAlignment())
+      {
+        int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.
+            seqCanvas.getSize().width);
+        av.setStartRes(vscroll.getValue() * rowSize);
+        av.setEndRes( (vscroll.getValue() + 1) * rowSize);
+      }
+      else
+      {
+        av.setStartSeq(offy);
+        av.setEndSeq(offy +
+                     seqPanel.seqCanvas.getSize().height / av.getCharHeight());
+      }
+    }
+
+    if (overviewPanel != null)
+    {
+      overviewPanel.setBoxPosition();
+    }
+
+    int scrollX = av.startRes - oldX;
+    int scrollY = av.startSeq - oldY;
+
+    if (av.getWrapAlignment() || !fastPaint || av.MAC)
+    {
+      repaint();
+    }
+    else
+    {
+      // Make sure we're not trying to draw a panel
+      // larger than the visible window
+      if (scrollX > av.endRes - av.startRes)
+      {
+        scrollX = av.endRes - av.startRes;
+      }
+      else if (scrollX < av.startRes - av.endRes)
+      {
+        scrollX = av.startRes - av.endRes;
+      }
+
+      idPanel.idCanvas.fastPaint(scrollY);
+      seqPanel.seqCanvas.fastPaint(scrollX,
+                                   scrollY);
+
+      scalePanel.repaint();
+      if (av.getShowAnnotation())
+      {
+        annotationPanel.fastPaint(av.getStartRes() - oldX);
+      }
+    }
+
+  }
+
+  public void paintAlignment(boolean updateOverview)
+  {
+    repaint();
+
+    if(updateOverview)
+    {
+      jalview.structure.StructureSelectionManager.getStructureSelectionManager()
+          .sequenceColoursChanged(this);
+
+      if (overviewPanel != null)
+      {
+        overviewPanel.updateOverviewImage();
+      }
+    }
+  }
+
+  public void update(Graphics g)
+  {
+    paint(g);
+  }
+
+  public void paint(Graphics g)
+  {
+    invalidate();
+    Dimension d = idPanel.idCanvas.getSize();
+    idPanel.idCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height);
+    annotationSpaceFillerHolder.setSize(d.width,
+                                        annotationPanel.getSize().height);
+
+    alabels.setSize(d.width, annotationPanel.getSize().height);
+
+    if (av.getWrapAlignment())
+    {
+      int maxwidth = av.alignment.getWidth();
+
+      if (av.hasHiddenColumns)
+      {
+        maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
+      }
+
+      int canvasWidth = seqPanel.seqCanvas.getWrappedCanvasWidth
+          (seqPanel.seqCanvas.getSize().width);
+
+      if (canvasWidth > 0)
+      {
+        int max = maxwidth / canvasWidth;
+        vscroll.setMaximum(max);
+        vscroll.setUnitIncrement(1);
+        vscroll.setVisibleAmount(1);
+      }
+    }
+    else
+    {
+      setScrollValues(av.getStartRes(), av.getStartSeq());
+    }
+
+    alabels.repaint();
+
+    seqPanel.seqCanvas.repaint();
+    scalePanel.repaint();
+    annotationPanel.repaint();
+    idPanel.idCanvas.repaint();
+  }
+
+  protected Panel sequenceHolderPanel = new Panel();
+  protected Scrollbar vscroll = new Scrollbar();
+  protected Scrollbar hscroll = new Scrollbar();
+  protected Panel seqPanelHolder = new Panel();
+  BorderLayout borderLayout1 = new BorderLayout();
+  BorderLayout borderLayout3 = new BorderLayout();
+  protected Panel scalePanelHolder = new Panel();
+  protected Panel idPanelHolder = new Panel();
+  BorderLayout borderLayout5 = new BorderLayout();
+  protected Panel idSpaceFillerPanel1 = new Panel();
+  public Panel annotationSpaceFillerHolder = new Panel();
+  BorderLayout borderLayout6 = new BorderLayout();
+  BorderLayout borderLayout7 = new BorderLayout();
+  Panel hscrollHolder = new Panel();
+  BorderLayout borderLayout10 = new BorderLayout();
+  protected Panel hscrollFillerPanel = new Panel();
+  BorderLayout borderLayout11 = new BorderLayout();
+  BorderLayout borderLayout4 = new BorderLayout();
+  BorderLayout borderLayout2 = new BorderLayout();
+
+  private void jbInit()
+      throws Exception
+  {
+    //  idPanelHolder.setPreferredSize(new Dimension(70, 10));
+    this.setLayout(borderLayout7);
+
+    //   sequenceHolderPanel.setPreferredSize(new Dimension(150, 150));
+    sequenceHolderPanel.setLayout(borderLayout3);
+    seqPanelHolder.setLayout(borderLayout1);
+    scalePanelHolder.setBackground(Color.white);
+
+    // scalePanelHolder.setPreferredSize(new Dimension(10, 30));
+    scalePanelHolder.setLayout(borderLayout6);
+    idPanelHolder.setLayout(borderLayout5);
+    idSpaceFillerPanel1.setBackground(Color.white);
+
+    //  idSpaceFillerPanel1.setPreferredSize(new Dimension(10, 30));
+    idSpaceFillerPanel1.setLayout(borderLayout11);
+    annotationSpaceFillerHolder.setBackground(Color.white);
+
+    //  annotationSpaceFillerHolder.setPreferredSize(new Dimension(10, 80));
+    annotationSpaceFillerHolder.setLayout(borderLayout4);
+    hscroll.setOrientation(Scrollbar.HORIZONTAL);
+    hscrollHolder.setLayout(borderLayout10);
+    hscrollFillerPanel.setBackground(Color.white);
+
+    //  hscrollFillerPanel.setPreferredSize(new Dimension(70, 10));
+    hscrollHolder.setBackground(Color.white);
+
+    //    annotationScroller.setPreferredSize(new Dimension(10, 80));
+    //  this.setPreferredSize(new Dimension(220, 166));
+    seqPanelHolder.setBackground(Color.white);
+    idPanelHolder.setBackground(Color.white);
+    sequenceHolderPanel.add(scalePanelHolder, BorderLayout.NORTH);
+    sequenceHolderPanel.add(seqPanelHolder, BorderLayout.CENTER);
+    seqPanelHolder.add(vscroll, BorderLayout.EAST);
+
+    //  Panel3.add(secondaryPanelHolder,  BorderLayout.SOUTH);
+    this.add(idPanelHolder, BorderLayout.WEST);
+    idPanelHolder.add(idSpaceFillerPanel1, BorderLayout.NORTH);
+    idPanelHolder.add(annotationSpaceFillerHolder, BorderLayout.SOUTH);
+    this.add(hscrollHolder, BorderLayout.SOUTH);
+    hscrollHolder.add(hscroll, BorderLayout.CENTER);
+    hscrollHolder.add(hscrollFillerPanel, BorderLayout.WEST);
+    this.add(sequenceHolderPanel, BorderLayout.CENTER);
+  }
+
+}
index 08a2550..425c7a9 100755 (executable)
@@ -611,7 +611,7 @@ public class TreeCanvas
                                            av.alignment.getWidth() - 1);
 
       sg.setName("JTreeGroup:" + sg.hashCode());
-
+      sg.setIdColour(col);
       if (av.getGlobalColourScheme() != null
           && av.getGlobalColourScheme().conservationApplied())
       {