added bugfix todo
authorjprocter <Jim Procter>
Wed, 31 Oct 2007 17:39:51 +0000 (17:39 +0000)
committerjprocter <Jim Procter>
Wed, 31 Oct 2007 17:39:51 +0000 (17:39 +0000)
src/jalview/gui/AlignmentPanel.java

index b11838c..326ac07 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
-package jalview.gui;\r
-\r
-import java.beans.*;\r
-import java.io.*;\r
-\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-import java.awt.print.*;\r
-import javax.swing.*;\r
-\r
-import jalview.datamodel.*;\r
-import jalview.jbgui.*;\r
-import jalview.schemes.*;\r
-\r
-/**\r
- * DOCUMENT ME!\r
- *\r
- * @author $author$\r
- * @version $Revision$\r
- */\r
-public class AlignmentPanel\r
-    extends GAlignmentPanel implements AdjustmentListener, Printable\r
-{\r
-  public AlignViewport av;\r
-  OverviewPanel overviewPanel;\r
-  SeqPanel seqPanel;\r
-  IdPanel idPanel;\r
-  IdwidthAdjuster idwidthAdjuster;\r
-\r
-  /** DOCUMENT ME!! */\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
-  int hextent = 0;\r
-  int vextent = 0;\r
-\r
-  /**\r
-   * Creates a new AlignmentPanel object.\r
-   *\r
-   * @param af DOCUMENT ME!\r
-   * @param av DOCUMENT ME!\r
-   */\r
-  public AlignmentPanel(AlignFrame af, final AlignViewport av)\r
-  {\r
-    alignFrame = af;\r
-    this.av = av;\r
-    seqPanel = new SeqPanel(av, this);\r
-    idPanel = new IdPanel(av, this);\r
-\r
-    scalePanel = new ScalePanel(av, this);\r
-\r
-    idPanelHolder.add(idPanel, BorderLayout.CENTER);\r
-    idwidthAdjuster = new IdwidthAdjuster(this);\r
-    idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);\r
-\r
-    annotationPanel = new AnnotationPanel(this);\r
-    alabels = new AnnotationLabels(this);\r
-\r
-    annotationScroller.setViewportView(annotationPanel);\r
-    annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);\r
-\r
-    scalePanelHolder.add(scalePanel, BorderLayout.CENTER);\r
-    seqPanelHolder.add(seqPanel, BorderLayout.CENTER);\r
-\r
-    setScrollValues(0, 0);\r
-\r
-    setAnnotationVisible(av.getShowAnnotation());\r
-\r
-    hscroll.addAdjustmentListener(this);\r
-    vscroll.addAdjustmentListener(this);\r
-\r
-    final AlignmentPanel ap = this;\r
-    av.addPropertyChangeListener(new PropertyChangeListener()\r
-    {\r
-      public void propertyChange(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
-    fontChanged();\r
-    adjustAnnotationHeight();\r
-\r
-  }\r
-\r
-  public void alignmentChanged()\r
-  {\r
-    av.alignmentChanged(this);\r
-\r
-    alignFrame.updateEditMenuBar();\r
-\r
-    paintAlignment(true);\r
-\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   */\r
-  public void fontChanged()\r
-  {\r
-    // set idCanvas bufferedImage to null\r
-    // to prevent drawing old image\r
-    FontMetrics fm = getFontMetrics(av.getFont());\r
-\r
-    scalePanelHolder.setPreferredSize(new Dimension(10,\r
-        av.charHeight + fm.getDescent()));\r
-    idSpaceFillerPanel1.setPreferredSize(new Dimension(10,\r
-        av.charHeight + fm.getDescent()));\r
-\r
-    idPanel.idCanvas.gg = null;\r
-    seqPanel.seqCanvas.img = null;\r
-    annotationPanel.adjustPanelHeight();\r
-\r
-    Dimension d = calculateIdWidth();\r
-    d.setSize(d.width + 4, d.height);\r
-    idPanel.idCanvas.setPreferredSize(d);\r
-    hscrollFillerPanel.setPreferredSize(d);\r
-\r
-    if (overviewPanel != null)\r
-    {\r
-      overviewPanel.setBoxPosition();\r
-    }\r
-\r
-    repaint();\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @return DOCUMENT ME!\r
-   */\r
-  public Dimension calculateIdWidth()\r
-  {\r
-    Container c = new Container();\r
-\r
-    FontMetrics fm = c.getFontMetrics(\r
-        new Font(av.font.getName(), Font.ITALIC, av.font.getSize()));\r
-\r
-    AlignmentI al = av.getAlignment();\r
-\r
-    int i = 0;\r
-    int idWidth = 0;\r
-    String id;\r
-\r
-    while ( (i < al.getHeight()) && (al.getSequenceAt(i) != null))\r
-    {\r
-      SequenceI s = al.getSequenceAt(i);\r
-\r
-      id = s.getDisplayId(av.getShowJVSuffix());\r
-\r
-      if (fm.stringWidth(id) > idWidth)\r
-      {\r
-        idWidth = fm.stringWidth(id);\r
-      }\r
-\r
-      i++;\r
-    }\r
-\r
-    // Also check annotation label widths\r
-    i = 0;\r
-\r
-    if (al.getAlignmentAnnotation() != null)\r
-    {\r
-      fm = c.getFontMetrics(alabels.getFont());\r
-\r
-      while (i < al.getAlignmentAnnotation().length)\r
-      {\r
-        String label = al.getAlignmentAnnotation()[i].label;\r
-\r
-        if (fm.stringWidth(label) > idWidth)\r
-        {\r
-          idWidth = fm.stringWidth(label);\r
-        }\r
-\r
-        i++;\r
-      }\r
-    }\r
-\r
-    return new Dimension(idWidth, 12);\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param results DOCUMENT ME!\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
-          setScrollValues(start, seqIndex);\r
-        }\r
-      }\r
-      else\r
-      {\r
-        scrollToWrappedVisible(start);\r
-      }\r
-    }\r
-\r
-    paintAlignment(true);\r
-  }\r
-\r
-  void scrollToWrappedVisible(int res)\r
-  {\r
-    int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.\r
-        getWidth());\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
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @return DOCUMENT ME!\r
-   */\r
-  public OverviewPanel getOverviewPanel()\r
-  {\r
-    return overviewPanel;\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param op DOCUMENT ME!\r
-   */\r
-  public void setOverviewPanel(OverviewPanel op)\r
-  {\r
-    overviewPanel = op;\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param b DOCUMENT ME!\r
-   */\r
-  public void setAnnotationVisible(boolean b)\r
-  {\r
-    if (!av.wrapAlignment)\r
-    {\r
-      annotationSpaceFillerHolder.setVisible(b);\r
-      annotationScroller.setVisible(b);\r
-    }\r
-    repaint();\r
-  }\r
-\r
-  public void adjustAnnotationHeight()\r
-  {\r
-    if (alignFrame.getHeight() == 0)\r
-    {\r
-      System.out.println("NEEDS FIXING");\r
-    }\r
-\r
-    int height = annotationPanel.adjustPanelHeight();\r
-\r
-    if (hscroll.isVisible())\r
-    {\r
-      height += hscroll.getPreferredSize().height;\r
-    }\r
-    if (height > alignFrame.getHeight() / 2)\r
-    {\r
-      height = alignFrame.getHeight() / 2;\r
-    }\r
-\r
-    hscroll.addNotify();\r
-\r
-    annotationScroller.setPreferredSize(\r
-        new Dimension(annotationScroller.getWidth(), height));\r
-\r
-\r
-    annotationSpaceFillerHolder.setPreferredSize(new Dimension(\r
-        annotationSpaceFillerHolder.getWidth(),\r
-        height));\r
-\r
-    repaint();\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param wrap DOCUMENT ME!\r
-   */\r
-  public void setWrapAlignment(boolean wrap)\r
-  {\r
-    av.startSeq = 0;\r
-    scalePanelHolder.setVisible(!wrap);\r
-    hscroll.setVisible(!wrap);\r
-    idwidthAdjuster.setVisible(!wrap);\r
-\r
-    if (wrap)\r
-    {\r
-      annotationScroller.setVisible(false);\r
-      annotationSpaceFillerHolder.setVisible(false);\r
-    }\r
-    else if (av.showAnnotation)\r
-    {\r
-      annotationScroller.setVisible(true);\r
-      annotationSpaceFillerHolder.setVisible(true);\r
-    }\r
-\r
-    idSpaceFillerPanel1.setVisible(!wrap);\r
-\r
-    repaint();\r
-  }\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
-\r
-      fastPaint = false;\r
-      vscroll.setValue(vscroll.getValue() - 1);\r
-    }\r
-    else\r
-    {\r
-      if ( (vextent + vscroll.getValue()) >= av.getAlignment().getHeight())\r
-      {\r
-        return false;\r
-      }\r
-\r
-      fastPaint = false;\r
-      vscroll.setValue(vscroll.getValue() + 1);\r
-    }\r
-\r
-    fastPaint = true;\r
-\r
-    return true;\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param right DOCUMENT ME!\r
-   *\r
-   * @return DOCUMENT ME!\r
-   */\r
-  public boolean scrollRight(boolean right)\r
-  {\r
-    if (!right)\r
-    {\r
-      if (hscroll.getValue() < 1)\r
-      {\r
-        return false;\r
-      }\r
-\r
-      fastPaint = false;\r
-      hscroll.setValue(hscroll.getValue() - 1);\r
-    }\r
-    else\r
-    {\r
-      if ( (hextent + hscroll.getValue()) >= av.getAlignment().getWidth())\r
-      {\r
-        return false;\r
-      }\r
-\r
-      fastPaint = false;\r
-      hscroll.setValue(hscroll.getValue() + 1);\r
-    }\r
-\r
-    fastPaint = true;\r
-\r
-    return true;\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param x DOCUMENT ME!\r
-   * @param y DOCUMENT ME!\r
-   */\r
-  public void setScrollValues(int x, int y)\r
-  {\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.setEndRes( (x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);\r
-\r
-    hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;\r
-    vextent = seqPanel.seqCanvas.getHeight() / 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
-    hscroll.setValues(x, hextent, 0, width);\r
-    vscroll.setValues(y, vextent, 0, height);\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param evt DOCUMENT ME!\r
-   */\r
-  public void adjustmentValueChanged(AdjustmentEvent evt)\r
-  {\r
-\r
-    int oldX = av.getStartRes();\r
-    int oldY = av.getStartSeq();\r
-\r
-    if (evt.getSource() == hscroll)\r
-    {\r
-      int x = hscroll.getValue();\r
-      av.setStartRes(x);\r
-      av.setEndRes( (x +\r
-                     (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);\r
-    }\r
-\r
-    if (evt.getSource() == vscroll)\r
-    {\r
-      int offy = vscroll.getValue();\r
-\r
-      if (av.getWrapAlignment())\r
-      {\r
-        if (offy > -1)\r
-        {\r
-          int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.\r
-              seqCanvas.getWidth());\r
-          av.setStartRes(offy * rowSize);\r
-          av.setEndRes( (offy + 1) * rowSize);\r
-        }\r
-        else\r
-        {\r
-          //This is only called if file loaded is a jar file that\r
-          //was wrapped when saved and user has wrap alignment true\r
-          //as preference setting\r
-          SwingUtilities.invokeLater(new Runnable()\r
-          {\r
-            public void run()\r
-            {\r
-              setScrollValues(av.getStartRes(), av.getStartSeq());\r
-            }\r
-          });\r
-        }\r
-      }\r
-      else\r
-      {\r
-        av.setStartSeq(offy);\r
-        av.setEndSeq(offy +\r
-                     (seqPanel.seqCanvas.getHeight() / 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)\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
-      if (scrollX != 0 || scrollY != 0)\r
-      {\r
-        idPanel.idCanvas.fastPaint(scrollY);\r
-        seqPanel.seqCanvas.fastPaint(scrollX,\r
-                                     scrollY);\r
-        scalePanel.repaint();\r
-\r
-        if (av.getShowAnnotation())\r
-        {\r
-          annotationPanel.fastPaint(scrollX);\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
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param g DOCUMENT ME!\r
-   */\r
-  public void paintComponent(Graphics g)\r
-  {\r
-    invalidate();\r
-\r
-    Dimension d = idPanel.idCanvas.getPreferredSize();\r
-    idPanelHolder.setPreferredSize(d);\r
-    hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));\r
-    validate();\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(seqPanel.\r
-          seqCanvas.getWidth());\r
-      if (canvasWidth > 0)\r
-      {\r
-        int max = maxwidth /\r
-            seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.\r
-            getWidth()) +\r
-            1;\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
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param pg DOCUMENT ME!\r
-   * @param pf DOCUMENT ME!\r
-   * @param pi DOCUMENT ME!\r
-   *\r
-   * @return DOCUMENT ME!\r
-   *\r
-   * @throws PrinterException DOCUMENT ME!\r
-   */\r
-  public int print(Graphics pg, PageFormat pf, int pi)\r
-      throws PrinterException\r
-  {\r
-    pg.translate( (int) pf.getImageableX(), (int) pf.getImageableY());\r
-\r
-    int pwidth = (int) pf.getImageableWidth();\r
-    int pheight = (int) pf.getImageableHeight();\r
-\r
-    if (av.getWrapAlignment())\r
-    {\r
-      return printWrappedAlignment(pg, pwidth, pheight, pi);\r
-    }\r
-    else\r
-    {\r
-      return printUnwrapped(pg, pwidth, pheight, pi);\r
-    }\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param pg DOCUMENT ME!\r
-   * @param pwidth DOCUMENT ME!\r
-   * @param pheight DOCUMENT ME!\r
-   * @param pi DOCUMENT ME!\r
-   *\r
-   * @return DOCUMENT ME!\r
-   *\r
-   * @throws PrinterException DOCUMENT ME!\r
-   */\r
-  public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)\r
-      throws PrinterException\r
-  {\r
-    int idWidth = getVisibleIdWidth();\r
-    FontMetrics fm = getFontMetrics(av.getFont());\r
-    int scaleHeight = av.charHeight + fm.getDescent();\r
-\r
-    pg.setColor(Color.white);\r
-    pg.fillRect(0, 0, pwidth, pheight);\r
-    pg.setFont(av.getFont());\r
-\r
-    ////////////////////////////////////\r
-    /// How many sequences and residues can we fit on a printable page?\r
-    int totalRes = (pwidth - idWidth) / av.getCharWidth();\r
-\r
-    int totalSeq = (int) ( (pheight - scaleHeight) / av.getCharHeight()) -\r
-        1;\r
-\r
-    int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;\r
-\r
-    /////////////////////////////\r
-    /// Only print these sequences and residues on this page\r
-    int startRes;\r
-\r
-    /////////////////////////////\r
-    /// Only print these sequences and residues on this page\r
-    int endRes;\r
-\r
-    /////////////////////////////\r
-    /// Only print these sequences and residues on this page\r
-    int startSeq;\r
-\r
-    /////////////////////////////\r
-    /// Only print these sequences and residues on this page\r
-    int endSeq;\r
-    startRes = (pi % pagesWide) * totalRes;\r
-    endRes = (startRes + totalRes) - 1;\r
-\r
-    if (endRes > (av.getAlignment().getWidth() - 1))\r
-    {\r
-      endRes = av.getAlignment().getWidth() - 1;\r
-    }\r
-\r
-    startSeq = (pi / pagesWide) * totalSeq;\r
-    endSeq = startSeq + totalSeq;\r
-\r
-    if (endSeq > av.getAlignment().getHeight())\r
-    {\r
-      endSeq = av.getAlignment().getHeight();\r
-    }\r
-\r
-    int pagesHigh = ( (av.alignment.getHeight() / totalSeq) + 1) * pheight;\r
-\r
-    if (av.showAnnotation)\r
-    {\r
-      pagesHigh += annotationPanel.adjustPanelHeight() + 3;\r
-    }\r
-\r
-    pagesHigh /= pheight;\r
-\r
-    if (pi >= (pagesWide * pagesHigh))\r
-    {\r
-      return Printable.NO_SUCH_PAGE;\r
-    }\r
-\r
-    //draw Scale\r
-    pg.translate(idWidth, 0);\r
-    scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight);\r
-    pg.translate( -idWidth, scaleHeight);\r
-\r
-    ////////////////\r
-    // Draw the ids\r
-    Color currentColor = null;\r
-    Color currentTextColor = null;\r
-\r
-    pg.setFont(idPanel.idCanvas.idfont);\r
-\r
-    SequenceI seq;\r
-    for (int i = startSeq; i < endSeq; i++)\r
-    {\r
-      seq = av.getAlignment().getSequenceAt(i);\r
-      if ( (av.getSelectionGroup() != null) &&\r
-          av.getSelectionGroup().getSequences(null).contains(seq))\r
-      {\r
-        currentColor = Color.gray;\r
-        currentTextColor = Color.black;\r
-      }\r
-      else\r
-      {\r
-        currentColor = av.getSequenceColour(seq);\r
-        currentTextColor = Color.black;\r
-      }\r
-\r
-      pg.setColor(currentColor);\r
-      pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,\r
-                  av.getCharHeight());\r
-\r
-      pg.setColor(currentTextColor);\r
-\r
-      int xPos = 0;\r
-      if (av.rightAlignIds)\r
-      {\r
-        fm = pg.getFontMetrics();\r
-        xPos = idWidth - fm.stringWidth(\r
-            seq.getDisplayId(av.getShowJVSuffix())\r
-            ) - 4;\r
-      }\r
-\r
-      pg.drawString(seq.getDisplayId(av.getShowJVSuffix()),\r
-                    xPos,\r
-                    ( ( (i - startSeq) * av.charHeight) + av.getCharHeight()) -\r
-                    (av.getCharHeight() / 5));\r
-    }\r
-\r
-    pg.setFont(av.getFont());\r
-\r
-    // draw main sequence panel\r
-    pg.translate(idWidth, 0);\r
-    seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);\r
-\r
-    if (av.showAnnotation && (endSeq == av.alignment.getHeight()))\r
-    {\r
-      pg.translate( -idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);\r
-      alabels.drawComponent( (Graphics2D) pg, idWidth);\r
-      pg.translate(idWidth + 3, 0);\r
-      annotationPanel.drawComponent( (Graphics2D) pg, startRes, endRes +\r
-                                    1);\r
-    }\r
-\r
-    return Printable.PAGE_EXISTS;\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param pg DOCUMENT ME!\r
-   * @param pwidth DOCUMENT ME!\r
-   * @param pheight DOCUMENT ME!\r
-   * @param pi DOCUMENT ME!\r
-   *\r
-   * @return DOCUMENT ME!\r
-   *\r
-   * @throws PrinterException DOCUMENT ME!\r
-   */\r
-  public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,\r
-                                   int pi)\r
-      throws PrinterException\r
-  {\r
-\r
-    int annotationHeight = 0;\r
-    AnnotationLabels labels = null;\r
-    if (av.showAnnotation)\r
-    {\r
-      annotationHeight = annotationPanel.adjustPanelHeight();\r
-      labels = new AnnotationLabels(av);\r
-    }\r
-\r
-    int hgap = av.charHeight;\r
-    if (av.scaleAboveWrapped)\r
-    {\r
-      hgap += av.charHeight;\r
-    }\r
-\r
-    int cHeight = av.getAlignment().getHeight() * av.charHeight\r
-        + hgap\r
-        + annotationHeight;\r
-\r
-    int idWidth = getVisibleIdWidth();\r
-\r
-    int maxwidth = av.alignment.getWidth();\r
-    if (av.hasHiddenColumns)\r
-    {\r
-      maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;\r
-    }\r
-\r
-    int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth -\r
-        idWidth);\r
-\r
-    int totalHeight = cHeight * (maxwidth / resWidth + 1);\r
-\r
-    pg.setColor(Color.white);\r
-    pg.fillRect(0, 0, pwidth, pheight);\r
-    pg.setFont(av.getFont());\r
-\r
-    ////////////////\r
-    // Draw the ids\r
-    pg.setColor(Color.black);\r
-\r
-    pg.translate(0, -pi * pheight);\r
-\r
-    pg.setClip(0, pi * pheight, pwidth, pheight);\r
-\r
-    int ypos = hgap;\r
-\r
-    do\r
-    {\r
-      for (int i = 0; i < av.alignment.getHeight(); i++)\r
-      {\r
-        pg.setFont(idPanel.idCanvas.idfont);\r
-        SequenceI s = av.alignment.getSequenceAt(i);\r
-        String string = s.getDisplayId(av.getShowJVSuffix());\r
-        int xPos = 0;\r
-        if (av.rightAlignIds)\r
-        {\r
-          FontMetrics fm = pg.getFontMetrics();\r
-          xPos = idWidth - fm.stringWidth(string) - 4;\r
-        }\r
-        pg.drawString(string, xPos,\r
-                      ( (i * av.charHeight) + ypos + av.charHeight) -\r
-                      (av.charHeight / 5));\r
-      }\r
-      if (labels != null)\r
-      {\r
-        pg.translate( -3,\r
-                     ypos +\r
-                     (av.getAlignment().getHeight() * av.charHeight));\r
-\r
-        pg.setFont(av.getFont());\r
-        labels.drawComponent(pg, idWidth);\r
-        pg.translate( +3,\r
-                     -ypos -\r
-                     (av.getAlignment().getHeight() * av.charHeight));\r
-      }\r
-\r
-      ypos += cHeight;\r
-    }\r
-    while (ypos < totalHeight);\r
-\r
-    pg.translate(idWidth, 0);\r
-\r
-    seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0);\r
-\r
-    if ( (pi * pheight) < totalHeight)\r
-    {\r
-      return Printable.PAGE_EXISTS;\r
-\r
-    }\r
-    else\r
-    {\r
-      return Printable.NO_SUCH_PAGE;\r
-    }\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
-    if (av.hasHiddenColumns)\r
-    {\r
-      maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);\r
-    }\r
-\r
-    int height = ( (av.alignment.getHeight() + 1) * av.charHeight)\r
-        + scalePanel.getHeight();\r
-    int width = getVisibleIdWidth() + (maxwidth * av.charWidth);\r
-\r
-    if (av.getWrapAlignment())\r
-    {\r
-      height = getWrappedHeight();\r
-      if (System.getProperty("java.awt.headless") != null\r
-          && System.getProperty("java.awt.headless").equals("true"))\r
-      {\r
-        width = alignFrame.getWidth()\r
-            - vscroll.getPreferredSize().width\r
-            - alignFrame.getInsets().left\r
-            - alignFrame.getInsets().right;\r
-      }\r
-      else\r
-      {\r
-        width = seqPanel.getWidth() + getVisibleIdWidth();\r
-      }\r
-\r
-    }\r
-    else if (av.getShowAnnotation())\r
-    {\r
-      height += annotationPanel.adjustPanelHeight() + 3;\r
-    }\r
-\r
-    try\r
-    {\r
-\r
-      jalview.util.ImageMaker im;\r
-      if (type == jalview.util.ImageMaker.PNG)\r
-      {\r
-        im = new jalview.util.ImageMaker(this,\r
-                                         jalview.util.ImageMaker.PNG,\r
-                                         "Create PNG image from alignment",\r
-                                         width, height, file, null);\r
-      }\r
-      else\r
-      {\r
-        im = new jalview.util.ImageMaker(this,\r
-                                         jalview.util.ImageMaker.EPS,\r
-                                         "Create EPS file from alignment",\r
-                                         width, height, file,\r
-                                         alignFrame.getTitle());\r
-      }\r
-\r
-      if (av.getWrapAlignment())\r
-      {\r
-        if (im.getGraphics() != null)\r
-        {\r
-          printWrappedAlignment(im.getGraphics(), width, height, 0);\r
-          im.writeImage();\r
-        }\r
-      }\r
-      else\r
-      {\r
-        if (im.getGraphics() != null)\r
-        {\r
-          printUnwrapped(im.getGraphics(), width, height, 0);\r
-          im.writeImage();\r
-        }\r
-      }\r
-    }\r
-    catch (OutOfMemoryError err)\r
-    {\r
-      System.out.println("########################\n"\r
-                         + "OUT OF MEMORY " + file + "\n"\r
-                         + "########################");\r
-\r
-      JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
-                                            "Out of Memory Creating Image!!"\r
-                                            +\r
-                                            "\nSee help files for increasing Java Virtual Machine memory."\r
-                                            , "Out of memory",\r
-                                            JOptionPane.WARNING_MESSAGE);\r
-      System.out.println("Create IMAGE: " + err);\r
-      System.gc();\r
-\r
-    }\r
-    catch (Exception ex)\r
-    {\r
-      ex.printStackTrace();\r
-    }\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   */\r
-  public void makeEPS(File epsFile)\r
-  {\r
-    makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   */\r
-  public void makePNG(File pngFile)\r
-  {\r
-    makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);\r
-  }\r
-\r
-  public void makePNGImageMap(File imgMapFile, String imageName)\r
-  {\r
-    ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS\r
-    //////////////////////////////////////////////\r
-    int idWidth = getVisibleIdWidth();\r
-    FontMetrics fm = getFontMetrics(av.getFont());\r
-    int scaleHeight = av.charHeight + fm.getDescent();\r
-\r
-    // Gen image map\r
-    //////////////////////////////////\r
-    if (imgMapFile != null)\r
-    {\r
-      try\r
-      {\r
-        int s, sSize = av.alignment.getHeight(),\r
-            res, alwidth = av.alignment.getWidth(), g, gSize, f, fSize, sy;\r
-        StringBuffer text = new StringBuffer();\r
-        PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));\r
-        out.println(jalview.io.HTMLOutput.getImageMapHTML());\r
-        out.println("<img src=\"" + imageName +\r
-                    "\" border=\"0\" usemap=\"#Map\" >"\r
-                    + "<map name=\"Map\">");\r
-\r
-        for (s = 0; s < sSize; s++)\r
-        {\r
-          sy = s * av.charHeight + scaleHeight;\r
-\r
-          SequenceI seq = av.alignment.getSequenceAt(s);\r
-          SequenceFeature[] features = seq.getDatasetSequence().\r
-              getSequenceFeatures();\r
-          SequenceGroup[] groups = av.alignment.findAllGroups(seq);\r
-          for (res = 0; res < alwidth; res++)\r
-          {\r
-            text = new StringBuffer();\r
-            Object obj = null;\r
-            if (av.alignment.isNucleotide())\r
-            {\r
-              obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res) +\r
-                  "");\r
-            }\r
-            else\r
-            {\r
-              obj = ResidueProperties.aa2Triplet.get(\r
-                  seq.getCharAt(res) + "");\r
-            }\r
-\r
-            if (obj == null)\r
-            {\r
-              continue;\r
-            }\r
-\r
-            String triplet = obj.toString();\r
-            int alIndex = seq.findPosition(res);\r
-            gSize = groups.length;\r
-            for (g = 0; g < gSize; g++)\r
-            {\r
-              if (text.length() < 1)\r
-              {\r
-                text.append("<area shape=\"rect\" coords=\""\r
-                            + (idWidth + res * av.charWidth) + ","\r
-                            + sy + ","\r
-                            + (idWidth + (res + 1) * av.charWidth) + ","\r
-                            + (av.charHeight + sy) + "\""\r
-                            + " onMouseOver=\"toolTip('"\r
-                            + alIndex + " " + triplet);\r
-              }\r
-\r
-              if (groups[g].getStartRes() < res && groups[g].getEndRes() > res)\r
-              {\r
-                text.append("<br><em>" + groups[g].getName() + "</em>");\r
-              }\r
-            }\r
-\r
-            if (features != null)\r
-            {\r
-              if (text.length() < 1)\r
-              {\r
-                text.append("<area shape=\"rect\" coords=\""\r
-                            + (idWidth + res * av.charWidth) + ","\r
-                            + sy + ","\r
-                            + (idWidth + (res + 1) * av.charWidth) + ","\r
-                            + (av.charHeight + sy) + "\""\r
-                            + " onMouseOver=\"toolTip('"\r
-                            + alIndex + " " + triplet);\r
-              }\r
-              fSize = features.length;\r
-              for (f = 0; f < fSize; f++)\r
-              {\r
-\r
-                if ( (features[f].getBegin() <= seq.findPosition(res)) &&\r
-                    (features[f].getEnd() >= seq.findPosition(res)))\r
-                {\r
-                  if (features[f].getType().equals("disulfide bond"))\r
-                  {\r
-                    if (features[f].getBegin() == seq.findPosition(res)\r
-                        || features[f].getEnd() == seq.findPosition(res))\r
-                    {\r
-                      text.append("<br>disulfide bond " + features[f].getBegin() +\r
-                                  ":" +\r
-                                  features[f].getEnd());\r
-                    }\r
-                  }\r
-                  else\r
-                  {\r
-                    text.append("<br>");\r
-                    text.append(features[f].getType());\r
-                    if (features[f].getDescription() != null &&\r
-                        !features[f].\r
-                        getType().equals(features[f].getDescription()))\r
-                    {\r
-                      text.append(" " + features[f].getDescription());\r
-                    }\r
-\r
-                    if (features[f].getValue("status") != null)\r
-                    {\r
-                      text.append(" (" + features[f].getValue("status") + ")");\r
-                    }\r
-                  }\r
-                }\r
-\r
-              }\r
-            }\r
-            if (text.length() > 1)\r
-            {\r
-              text.append("')\"; onMouseOut=\"toolTip()\";  href=\"#\">");\r
-              out.println(text.toString());\r
-            }\r
-          }\r
-        }\r
-        out.println("</map></body></html>");\r
-        out.close();\r
-\r
-      }\r
-      catch (Exception ex)\r
-      {\r
-        ex.printStackTrace();\r
-      }\r
-    } ///////////END OF IMAGE MAP\r
-\r
-  }\r
-\r
-  int getWrappedHeight()\r
-  {\r
-    int seqPanelWidth = seqPanel.seqCanvas.getWidth();\r
-\r
-    if (System.getProperty("java.awt.headless") != null\r
-        && System.getProperty("java.awt.headless").equals("true"))\r
-    {\r
-      seqPanelWidth = alignFrame.getWidth()\r
-          - getVisibleIdWidth()\r
-          - vscroll.getPreferredSize().width\r
-          - alignFrame.getInsets().left\r
-          - alignFrame.getInsets().right;\r
-    }\r
-\r
-    int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(\r
-        seqPanelWidth\r
-        );\r
-\r
-    int hgap = av.charHeight;\r
-    if (av.scaleAboveWrapped)\r
-    {\r
-      hgap += av.charHeight;\r
-    }\r
-\r
-    int annotationHeight = 0;\r
-    if (av.showAnnotation)\r
-    {\r
-      annotationHeight = annotationPanel.adjustPanelHeight();\r
-    }\r
-\r
-    int cHeight = av.getAlignment().getHeight() * av.charHeight\r
-        + hgap\r
-        + annotationHeight;\r
-\r
-    int maxwidth = av.alignment.getWidth();\r
-    if (av.hasHiddenColumns)\r
-    {\r
-      maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;\r
-    }\r
-\r
-    int height = ( (maxwidth / chunkWidth) + 1) * cHeight;\r
-\r
-    return height;\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.gui;
+
+import java.beans.*;
+import java.io.*;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.print.*;
+import javax.swing.*;
+
+import jalview.datamodel.*;
+import jalview.jbgui.*;
+import jalview.schemes.*;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class AlignmentPanel
+    extends GAlignmentPanel implements AdjustmentListener, Printable
+{
+  public AlignViewport av;
+  OverviewPanel overviewPanel;
+  SeqPanel seqPanel;
+  IdPanel idPanel;
+  IdwidthAdjuster idwidthAdjuster;
+
+  /** DOCUMENT ME!! */
+  public AlignFrame alignFrame;
+  ScalePanel scalePanel;
+  AnnotationPanel annotationPanel;
+  AnnotationLabels alabels;
+
+  // this value is set false when selection area being dragged
+  boolean fastPaint = true;
+  int hextent = 0;
+  int vextent = 0;
+
+  /**
+   * Creates a new AlignmentPanel object.
+   *
+   * @param af DOCUMENT ME!
+   * @param av DOCUMENT ME!
+   */
+  public AlignmentPanel(AlignFrame af, final AlignViewport av)
+  {
+    alignFrame = af;
+    this.av = av;
+    seqPanel = new SeqPanel(av, this);
+    idPanel = new IdPanel(av, this);
+
+    scalePanel = new ScalePanel(av, this);
+
+    idPanelHolder.add(idPanel, BorderLayout.CENTER);
+    idwidthAdjuster = new IdwidthAdjuster(this);
+    idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
+
+    annotationPanel = new AnnotationPanel(this);
+    alabels = new AnnotationLabels(this);
+
+    annotationScroller.setViewportView(annotationPanel);
+    annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
+
+    scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
+    seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
+
+    setScrollValues(0, 0);
+
+    setAnnotationVisible(av.getShowAnnotation());
+
+    hscroll.addAdjustmentListener(this);
+    vscroll.addAdjustmentListener(this);
+
+    final AlignmentPanel ap = this;
+    av.addPropertyChangeListener(new PropertyChangeListener()
+    {
+      public void propertyChange(PropertyChangeEvent evt)
+      {
+        if (evt.getPropertyName().equals("alignment"))
+        {
+          PaintRefresher.Refresh(ap,
+                                 av.getSequenceSetId(),
+                                 true,
+                                 true);
+          alignmentChanged();
+        }
+      }
+    });
+
+    fontChanged();
+    adjustAnnotationHeight();
+
+  }
+
+  public void alignmentChanged()
+  {
+    av.alignmentChanged(this);
+
+    alignFrame.updateEditMenuBar();
+
+    paintAlignment(true);
+
+  }
+
+  /**
+   * DOCUMENT ME!
+   */
+  public void fontChanged()
+  {
+    // set idCanvas bufferedImage to null
+    // to prevent drawing old image
+    FontMetrics fm = getFontMetrics(av.getFont());
+
+    scalePanelHolder.setPreferredSize(new Dimension(10,
+        av.charHeight + fm.getDescent()));
+    idSpaceFillerPanel1.setPreferredSize(new Dimension(10,
+        av.charHeight + fm.getDescent()));
+
+    idPanel.idCanvas.gg = null;
+    seqPanel.seqCanvas.img = null;
+    annotationPanel.adjustPanelHeight();
+
+    Dimension d = calculateIdWidth();
+    d.setSize(d.width + 4, d.height);
+    idPanel.idCanvas.setPreferredSize(d);
+    hscrollFillerPanel.setPreferredSize(d);
+
+    if (overviewPanel != null)
+    {
+      overviewPanel.setBoxPosition();
+    }
+
+    repaint();
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public Dimension calculateIdWidth()
+  {
+    Container c = new Container();
+
+    FontMetrics fm = c.getFontMetrics(
+        new Font(av.font.getName(), Font.ITALIC, av.font.getSize()));
+
+    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 = c.getFontMetrics(alabels.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, 12);
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param results DOCUMENT ME!
+   */
+  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)))
+        {
+          setScrollValues(start, seqIndex);
+        }
+      }
+      else
+      {
+        scrollToWrappedVisible(start);
+      }
+    }
+
+    paintAlignment(true);
+  }
+
+  void scrollToWrappedVisible(int res)
+  {
+    int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.
+        getWidth());
+    if (res <= av.getStartRes() || res >= (av.getStartRes() + cwidth))
+    {
+      vscroll.setValue(res / cwidth);
+      av.startRes = vscroll.getValue() * cwidth;
+    }
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public OverviewPanel getOverviewPanel()
+  {
+    return overviewPanel;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param op DOCUMENT ME!
+   */
+  public void setOverviewPanel(OverviewPanel op)
+  {
+    overviewPanel = op;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param b DOCUMENT ME!
+   */
+  public void setAnnotationVisible(boolean b)
+  {
+    if (!av.wrapAlignment)
+    {
+      annotationSpaceFillerHolder.setVisible(b);
+      annotationScroller.setVisible(b);
+    }
+    repaint();
+  }
+
+  public void adjustAnnotationHeight()
+  {
+    //TODO: display vertical annotation scrollbar if necessary 
+    // this is called after loading new annotation onto alignment
+    if (alignFrame.getHeight() == 0)
+    {
+      System.out.println("NEEDS FIXING");
+    }
+
+    int height = annotationPanel.adjustPanelHeight();
+
+    if (hscroll.isVisible())
+    {
+      height += hscroll.getPreferredSize().height;
+    }
+    if (height > alignFrame.getHeight() / 2)
+    {
+      height = alignFrame.getHeight() / 2;
+    }
+
+    hscroll.addNotify();
+
+    annotationScroller.setPreferredSize(
+        new Dimension(annotationScroller.getWidth(), height));
+
+
+    annotationSpaceFillerHolder.setPreferredSize(new Dimension(
+        annotationSpaceFillerHolder.getWidth(),
+        height));
+    annotationScroller.validate();// repaint();
+    repaint();
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param wrap DOCUMENT ME!
+   */
+  public void setWrapAlignment(boolean wrap)
+  {
+    av.startSeq = 0;
+    scalePanelHolder.setVisible(!wrap);
+    hscroll.setVisible(!wrap);
+    idwidthAdjuster.setVisible(!wrap);
+
+    if (wrap)
+    {
+      annotationScroller.setVisible(false);
+      annotationSpaceFillerHolder.setVisible(false);
+    }
+    else if (av.showAnnotation)
+    {
+      annotationScroller.setVisible(true);
+      annotationSpaceFillerHolder.setVisible(true);
+    }
+
+    idSpaceFillerPanel1.setVisible(!wrap);
+
+    repaint();
+  }
+
+  // return value is true if the scroll is valid
+  public boolean scrollUp(boolean up)
+  {
+    if (up)
+    {
+      if (vscroll.getValue() < 1)
+      {
+        return false;
+      }
+
+      fastPaint = false;
+      vscroll.setValue(vscroll.getValue() - 1);
+    }
+    else
+    {
+      if ( (vextent + vscroll.getValue()) >= av.getAlignment().getHeight())
+      {
+        return false;
+      }
+
+      fastPaint = false;
+      vscroll.setValue(vscroll.getValue() + 1);
+    }
+
+    fastPaint = true;
+
+    return true;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param right DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public boolean scrollRight(boolean right)
+  {
+    if (!right)
+    {
+      if (hscroll.getValue() < 1)
+      {
+        return false;
+      }
+
+      fastPaint = false;
+      hscroll.setValue(hscroll.getValue() - 1);
+    }
+    else
+    {
+      if ( (hextent + hscroll.getValue()) >= av.getAlignment().getWidth())
+      {
+        return false;
+      }
+
+      fastPaint = false;
+      hscroll.setValue(hscroll.getValue() + 1);
+    }
+
+    fastPaint = true;
+
+    return true;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param x DOCUMENT ME!
+   * @param y DOCUMENT ME!
+   */
+  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.setEndRes( (x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1);
+
+    hextent = seqPanel.seqCanvas.getWidth() / av.charWidth;
+    vextent = seqPanel.seqCanvas.getHeight() / 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;
+    }
+
+    hscroll.setValues(x, hextent, 0, width);
+    vscroll.setValues(y, vextent, 0, height);
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param evt DOCUMENT ME!
+   */
+  public void adjustmentValueChanged(AdjustmentEvent evt)
+  {
+
+    int oldX = av.getStartRes();
+    int oldY = av.getStartSeq();
+
+    if (evt.getSource() == hscroll)
+    {
+      int x = hscroll.getValue();
+      av.setStartRes(x);
+      av.setEndRes( (x +
+                     (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1);
+    }
+
+    if (evt.getSource() == vscroll)
+    {
+      int offy = vscroll.getValue();
+
+      if (av.getWrapAlignment())
+      {
+        if (offy > -1)
+        {
+          int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.
+              seqCanvas.getWidth());
+          av.setStartRes(offy * rowSize);
+          av.setEndRes( (offy + 1) * rowSize);
+        }
+        else
+        {
+          //This is only called if file loaded is a jar file that
+          //was wrapped when saved and user has wrap alignment true
+          //as preference setting
+          SwingUtilities.invokeLater(new Runnable()
+          {
+            public void run()
+            {
+              setScrollValues(av.getStartRes(), av.getStartSeq());
+            }
+          });
+        }
+      }
+      else
+      {
+        av.setStartSeq(offy);
+        av.setEndSeq(offy +
+                     (seqPanel.seqCanvas.getHeight() / av.getCharHeight()));
+      }
+    }
+
+    if (overviewPanel != null)
+    {
+      overviewPanel.setBoxPosition();
+    }
+
+    int scrollX = av.startRes - oldX;
+    int scrollY = av.startSeq - oldY;
+
+    if (av.getWrapAlignment() || !fastPaint)
+    {
+      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;
+      }
+
+      if (scrollX != 0 || scrollY != 0)
+      {
+        idPanel.idCanvas.fastPaint(scrollY);
+        seqPanel.seqCanvas.fastPaint(scrollX,
+                                     scrollY);
+        scalePanel.repaint();
+
+        if (av.getShowAnnotation())
+        {
+          annotationPanel.fastPaint(scrollX);
+        }
+      }
+    }
+  }
+
+  public void paintAlignment(boolean updateOverview)
+  {
+    repaint();
+
+    if(updateOverview)
+    {
+      jalview.structure.StructureSelectionManager.getStructureSelectionManager()
+          .sequenceColoursChanged(this);
+
+      if (overviewPanel != null)
+      {
+        overviewPanel.updateOverviewImage();
+      }
+    }
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param g DOCUMENT ME!
+   */
+  public void paintComponent(Graphics g)
+  {
+    invalidate();
+
+    Dimension d = idPanel.idCanvas.getPreferredSize();
+    idPanelHolder.setPreferredSize(d);
+    hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
+    validate();
+
+    if (av.getWrapAlignment())
+    {
+      int maxwidth = av.alignment.getWidth();
+
+      if (av.hasHiddenColumns)
+      {
+        maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
+      }
+
+      int canvasWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.
+          seqCanvas.getWidth());
+      if (canvasWidth > 0)
+      {
+        int max = maxwidth /
+            seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.
+            getWidth()) +
+            1;
+        vscroll.setMaximum(max);
+        vscroll.setUnitIncrement(1);
+        vscroll.setVisibleAmount(1);
+      }
+    }
+    else
+    {
+      setScrollValues(av.getStartRes(), av.getStartSeq());
+    }
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param pg DOCUMENT ME!
+   * @param pf DOCUMENT ME!
+   * @param pi DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   *
+   * @throws PrinterException DOCUMENT ME!
+   */
+  public int print(Graphics pg, PageFormat pf, int pi)
+      throws PrinterException
+  {
+    pg.translate( (int) pf.getImageableX(), (int) pf.getImageableY());
+
+    int pwidth = (int) pf.getImageableWidth();
+    int pheight = (int) pf.getImageableHeight();
+
+    if (av.getWrapAlignment())
+    {
+      return printWrappedAlignment(pg, pwidth, pheight, pi);
+    }
+    else
+    {
+      return printUnwrapped(pg, pwidth, pheight, pi);
+    }
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param pg DOCUMENT ME!
+   * @param pwidth DOCUMENT ME!
+   * @param pheight DOCUMENT ME!
+   * @param pi DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   *
+   * @throws PrinterException DOCUMENT ME!
+   */
+  public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi)
+      throws PrinterException
+  {
+    int idWidth = getVisibleIdWidth();
+    FontMetrics fm = getFontMetrics(av.getFont());
+    int scaleHeight = av.charHeight + fm.getDescent();
+
+    pg.setColor(Color.white);
+    pg.fillRect(0, 0, pwidth, pheight);
+    pg.setFont(av.getFont());
+
+    ////////////////////////////////////
+    /// How many sequences and residues can we fit on a printable page?
+    int totalRes = (pwidth - idWidth) / av.getCharWidth();
+
+    int totalSeq = (int) ( (pheight - scaleHeight) / av.getCharHeight()) -
+        1;
+
+    int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
+
+    /////////////////////////////
+    /// Only print these sequences and residues on this page
+    int startRes;
+
+    /////////////////////////////
+    /// Only print these sequences and residues on this page
+    int endRes;
+
+    /////////////////////////////
+    /// Only print these sequences and residues on this page
+    int startSeq;
+
+    /////////////////////////////
+    /// Only print these sequences and residues on this page
+    int endSeq;
+    startRes = (pi % pagesWide) * totalRes;
+    endRes = (startRes + totalRes) - 1;
+
+    if (endRes > (av.getAlignment().getWidth() - 1))
+    {
+      endRes = av.getAlignment().getWidth() - 1;
+    }
+
+    startSeq = (pi / pagesWide) * totalSeq;
+    endSeq = startSeq + totalSeq;
+
+    if (endSeq > av.getAlignment().getHeight())
+    {
+      endSeq = av.getAlignment().getHeight();
+    }
+
+    int pagesHigh = ( (av.alignment.getHeight() / totalSeq) + 1) * pheight;
+
+    if (av.showAnnotation)
+    {
+      pagesHigh += annotationPanel.adjustPanelHeight() + 3;
+    }
+
+    pagesHigh /= pheight;
+
+    if (pi >= (pagesWide * pagesHigh))
+    {
+      return Printable.NO_SUCH_PAGE;
+    }
+
+    //draw Scale
+    pg.translate(idWidth, 0);
+    scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight);
+    pg.translate( -idWidth, scaleHeight);
+
+    ////////////////
+    // Draw the ids
+    Color currentColor = null;
+    Color currentTextColor = null;
+
+    pg.setFont(idPanel.idCanvas.idfont);
+
+    SequenceI seq;
+    for (int i = startSeq; i < endSeq; i++)
+    {
+      seq = av.getAlignment().getSequenceAt(i);
+      if ( (av.getSelectionGroup() != null) &&
+          av.getSelectionGroup().getSequences(null).contains(seq))
+      {
+        currentColor = Color.gray;
+        currentTextColor = Color.black;
+      }
+      else
+      {
+        currentColor = av.getSequenceColour(seq);
+        currentTextColor = Color.black;
+      }
+
+      pg.setColor(currentColor);
+      pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth,
+                  av.getCharHeight());
+
+      pg.setColor(currentTextColor);
+
+      int xPos = 0;
+      if (av.rightAlignIds)
+      {
+        fm = pg.getFontMetrics();
+        xPos = idWidth - fm.stringWidth(
+            seq.getDisplayId(av.getShowJVSuffix())
+            ) - 4;
+      }
+
+      pg.drawString(seq.getDisplayId(av.getShowJVSuffix()),
+                    xPos,
+                    ( ( (i - startSeq) * av.charHeight) + av.getCharHeight()) -
+                    (av.getCharHeight() / 5));
+    }
+
+    pg.setFont(av.getFont());
+
+    // draw main sequence panel
+    pg.translate(idWidth, 0);
+    seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0);
+
+    if (av.showAnnotation && (endSeq == av.alignment.getHeight()))
+    {
+      pg.translate( -idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
+      alabels.drawComponent( (Graphics2D) pg, idWidth);
+      pg.translate(idWidth + 3, 0);
+      annotationPanel.drawComponent( (Graphics2D) pg, startRes, endRes +
+                                    1);
+    }
+
+    return Printable.PAGE_EXISTS;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param pg DOCUMENT ME!
+   * @param pwidth DOCUMENT ME!
+   * @param pheight DOCUMENT ME!
+   * @param pi DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   *
+   * @throws PrinterException DOCUMENT ME!
+   */
+  public int printWrappedAlignment(Graphics pg, int pwidth, int pheight,
+                                   int pi)
+      throws PrinterException
+  {
+
+    int annotationHeight = 0;
+    AnnotationLabels labels = null;
+    if (av.showAnnotation)
+    {
+      annotationHeight = annotationPanel.adjustPanelHeight();
+      labels = new AnnotationLabels(av);
+    }
+
+    int hgap = av.charHeight;
+    if (av.scaleAboveWrapped)
+    {
+      hgap += av.charHeight;
+    }
+
+    int cHeight = av.getAlignment().getHeight() * av.charHeight
+        + hgap
+        + annotationHeight;
+
+    int idWidth = getVisibleIdWidth();
+
+    int maxwidth = av.alignment.getWidth();
+    if (av.hasHiddenColumns)
+    {
+      maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
+    }
+
+    int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth -
+        idWidth);
+
+    int totalHeight = cHeight * (maxwidth / resWidth + 1);
+
+    pg.setColor(Color.white);
+    pg.fillRect(0, 0, pwidth, pheight);
+    pg.setFont(av.getFont());
+
+    ////////////////
+    // Draw the ids
+    pg.setColor(Color.black);
+
+    pg.translate(0, -pi * pheight);
+
+    pg.setClip(0, pi * pheight, pwidth, pheight);
+
+    int ypos = hgap;
+
+    do
+    {
+      for (int i = 0; i < av.alignment.getHeight(); i++)
+      {
+        pg.setFont(idPanel.idCanvas.idfont);
+        SequenceI s = av.alignment.getSequenceAt(i);
+        String string = s.getDisplayId(av.getShowJVSuffix());
+        int xPos = 0;
+        if (av.rightAlignIds)
+        {
+          FontMetrics fm = pg.getFontMetrics();
+          xPos = idWidth - fm.stringWidth(string) - 4;
+        }
+        pg.drawString(string, xPos,
+                      ( (i * av.charHeight) + ypos + av.charHeight) -
+                      (av.charHeight / 5));
+      }
+      if (labels != null)
+      {
+        pg.translate( -3,
+                     ypos +
+                     (av.getAlignment().getHeight() * av.charHeight));
+
+        pg.setFont(av.getFont());
+        labels.drawComponent(pg, idWidth);
+        pg.translate( +3,
+                     -ypos -
+                     (av.getAlignment().getHeight() * av.charHeight));
+      }
+
+      ypos += cHeight;
+    }
+    while (ypos < totalHeight);
+
+    pg.translate(idWidth, 0);
+
+    seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0);
+
+    if ( (pi * pheight) < totalHeight)
+    {
+      return Printable.PAGE_EXISTS;
+
+    }
+    else
+    {
+      return Printable.NO_SUCH_PAGE;
+    }
+  }
+
+  int getVisibleIdWidth()
+  {
+    return
+        idPanel.getWidth() > 0 ? idPanel.getWidth() :
+        calculateIdWidth().width + 4;
+  }
+
+  void makeAlignmentImage(int type, File file)
+  {
+    int maxwidth = av.alignment.getWidth();
+    if (av.hasHiddenColumns)
+    {
+      maxwidth = av.getColumnSelection().findColumnPosition(maxwidth);
+    }
+
+    int height = ( (av.alignment.getHeight() + 1) * av.charHeight)
+        + scalePanel.getHeight();
+    int width = getVisibleIdWidth() + (maxwidth * av.charWidth);
+
+    if (av.getWrapAlignment())
+    {
+      height = getWrappedHeight();
+      if (System.getProperty("java.awt.headless") != null
+          && System.getProperty("java.awt.headless").equals("true"))
+      {
+        width = alignFrame.getWidth()
+            - vscroll.getPreferredSize().width
+            - alignFrame.getInsets().left
+            - alignFrame.getInsets().right;
+      }
+      else
+      {
+        width = seqPanel.getWidth() + getVisibleIdWidth();
+      }
+
+    }
+    else if (av.getShowAnnotation())
+    {
+      height += annotationPanel.adjustPanelHeight() + 3;
+    }
+
+    try
+    {
+
+      jalview.util.ImageMaker im;
+      if (type == jalview.util.ImageMaker.PNG)
+      {
+        im = new jalview.util.ImageMaker(this,
+                                         jalview.util.ImageMaker.PNG,
+                                         "Create PNG image from alignment",
+                                         width, height, file, null);
+      }
+      else
+      {
+        im = new jalview.util.ImageMaker(this,
+                                         jalview.util.ImageMaker.EPS,
+                                         "Create EPS file from alignment",
+                                         width, height, file,
+                                         alignFrame.getTitle());
+      }
+
+      if (av.getWrapAlignment())
+      {
+        if (im.getGraphics() != null)
+        {
+          printWrappedAlignment(im.getGraphics(), width, height, 0);
+          im.writeImage();
+        }
+      }
+      else
+      {
+        if (im.getGraphics() != null)
+        {
+          printUnwrapped(im.getGraphics(), width, height, 0);
+          im.writeImage();
+        }
+      }
+    }
+    catch (OutOfMemoryError err)
+    {
+      System.out.println("########################\n"
+                         + "OUT OF MEMORY " + file + "\n"
+                         + "########################");
+
+      JOptionPane.showInternalMessageDialog(Desktop.desktop,
+                                            "Out of Memory Creating Image!!"
+                                            +
+                                            "\nSee help files for increasing Java Virtual Machine memory."
+                                            , "Out of memory",
+                                            JOptionPane.WARNING_MESSAGE);
+      System.out.println("Create IMAGE: " + err);
+      System.gc();
+
+    }
+    catch (Exception ex)
+    {
+      ex.printStackTrace();
+    }
+  }
+
+  /**
+   * DOCUMENT ME!
+   */
+  public void makeEPS(File epsFile)
+  {
+    makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
+  }
+
+  /**
+   * DOCUMENT ME!
+   */
+  public void makePNG(File pngFile)
+  {
+    makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
+  }
+
+  public void makePNGImageMap(File imgMapFile, String imageName)
+  {
+    ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
+    //////////////////////////////////////////////
+    int idWidth = getVisibleIdWidth();
+    FontMetrics fm = getFontMetrics(av.getFont());
+    int scaleHeight = av.charHeight + fm.getDescent();
+
+    // Gen image map
+    //////////////////////////////////
+    if (imgMapFile != null)
+    {
+      try
+      {
+        int s, sSize = av.alignment.getHeight(),
+            res, alwidth = av.alignment.getWidth(), g, gSize, f, fSize, sy;
+        StringBuffer text = new StringBuffer();
+        PrintWriter out = new PrintWriter(new FileWriter(imgMapFile));
+        out.println(jalview.io.HTMLOutput.getImageMapHTML());
+        out.println("<img src=\"" + imageName +
+                    "\" border=\"0\" usemap=\"#Map\" >"
+                    + "<map name=\"Map\">");
+
+        for (s = 0; s < sSize; s++)
+        {
+          sy = s * av.charHeight + scaleHeight;
+
+          SequenceI seq = av.alignment.getSequenceAt(s);
+          SequenceFeature[] features = seq.getDatasetSequence().
+              getSequenceFeatures();
+          SequenceGroup[] groups = av.alignment.findAllGroups(seq);
+          for (res = 0; res < alwidth; res++)
+          {
+            text = new StringBuffer();
+            Object obj = null;
+            if (av.alignment.isNucleotide())
+            {
+              obj = ResidueProperties.nucleotideName.get(seq.getCharAt(res) +
+                  "");
+            }
+            else
+            {
+              obj = ResidueProperties.aa2Triplet.get(
+                  seq.getCharAt(res) + "");
+            }
+
+            if (obj == null)
+            {
+              continue;
+            }
+
+            String triplet = obj.toString();
+            int alIndex = seq.findPosition(res);
+            gSize = groups.length;
+            for (g = 0; g < gSize; g++)
+            {
+              if (text.length() < 1)
+              {
+                text.append("<area shape=\"rect\" coords=\""
+                            + (idWidth + res * av.charWidth) + ","
+                            + sy + ","
+                            + (idWidth + (res + 1) * av.charWidth) + ","
+                            + (av.charHeight + sy) + "\""
+                            + " onMouseOver=\"toolTip('"
+                            + alIndex + " " + triplet);
+              }
+
+              if (groups[g].getStartRes() < res && groups[g].getEndRes() > res)
+              {
+                text.append("<br><em>" + groups[g].getName() + "</em>");
+              }
+            }
+
+            if (features != null)
+            {
+              if (text.length() < 1)
+              {
+                text.append("<area shape=\"rect\" coords=\""
+                            + (idWidth + res * av.charWidth) + ","
+                            + sy + ","
+                            + (idWidth + (res + 1) * av.charWidth) + ","
+                            + (av.charHeight + sy) + "\""
+                            + " onMouseOver=\"toolTip('"
+                            + alIndex + " " + triplet);
+              }
+              fSize = features.length;
+              for (f = 0; f < fSize; f++)
+              {
+
+                if ( (features[f].getBegin() <= seq.findPosition(res)) &&
+                    (features[f].getEnd() >= seq.findPosition(res)))
+                {
+                  if (features[f].getType().equals("disulfide bond"))
+                  {
+                    if (features[f].getBegin() == seq.findPosition(res)
+                        || features[f].getEnd() == seq.findPosition(res))
+                    {
+                      text.append("<br>disulfide bond " + features[f].getBegin() +
+                                  ":" +
+                                  features[f].getEnd());
+                    }
+                  }
+                  else
+                  {
+                    text.append("<br>");
+                    text.append(features[f].getType());
+                    if (features[f].getDescription() != null &&
+                        !features[f].
+                        getType().equals(features[f].getDescription()))
+                    {
+                      text.append(" " + features[f].getDescription());
+                    }
+
+                    if (features[f].getValue("status") != null)
+                    {
+                      text.append(" (" + features[f].getValue("status") + ")");
+                    }
+                  }
+                }
+
+              }
+            }
+            if (text.length() > 1)
+            {
+              text.append("')\"; onMouseOut=\"toolTip()\";  href=\"#\">");
+              out.println(text.toString());
+            }
+          }
+        }
+        out.println("</map></body></html>");
+        out.close();
+
+      }
+      catch (Exception ex)
+      {
+        ex.printStackTrace();
+      }
+    } ///////////END OF IMAGE MAP
+
+  }
+
+  int getWrappedHeight()
+  {
+    int seqPanelWidth = seqPanel.seqCanvas.getWidth();
+
+    if (System.getProperty("java.awt.headless") != null
+        && System.getProperty("java.awt.headless").equals("true"))
+    {
+      seqPanelWidth = alignFrame.getWidth()
+          - getVisibleIdWidth()
+          - vscroll.getPreferredSize().width
+          - alignFrame.getInsets().left
+          - alignFrame.getInsets().right;
+    }
+
+    int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(
+        seqPanelWidth
+        );
+
+    int hgap = av.charHeight;
+    if (av.scaleAboveWrapped)
+    {
+      hgap += av.charHeight;
+    }
+
+    int annotationHeight = 0;
+    if (av.showAnnotation)
+    {
+      annotationHeight = annotationPanel.adjustPanelHeight();
+    }
+
+    int cHeight = av.getAlignment().getHeight() * av.charHeight
+        + hgap
+        + annotationHeight;
+
+    int maxwidth = av.alignment.getWidth();
+    if (av.hasHiddenColumns)
+    {
+      maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
+    }
+
+    int height = ( (maxwidth / chunkWidth) + 1) * cHeight;
+
+    return height;
+  }
+}