X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignmentPanel.java;h=b11838ce2473dbee03b7add60370998a907b96ec;hb=fb1cdebe4a9d93839c81a2d3eb39e8da9cb83d64;hp=3c80f3a38f50bd1e551d4d9594b9d631aedfd093;hpb=aa5581ff1585cfee8ccf009700f9c4dcb2e110b7;p=jalview.git diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 3c80f3a..b11838c 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * 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 @@ -18,25 +18,17 @@ */ package jalview.gui; -import jalview.datamodel.*; - -import jalview.jbgui.*; - -import jalview.schemes.*; - -import org.jibble.epsgraphics.*; +import java.beans.*; +import java.io.*; import java.awt.*; import java.awt.event.*; -import java.awt.image.*; import java.awt.print.*; - -import java.io.*; - -import javax.imageio.*; - import javax.swing.*; +import jalview.datamodel.*; +import jalview.jbgui.*; +import jalview.schemes.*; /** * DOCUMENT ME! @@ -44,980 +36,1172 @@ import javax.swing.*; * @author $author$ * @version $Revision$ */ -public class AlignmentPanel extends GAlignmentPanel - implements AdjustmentListener, Printable +public class AlignmentPanel + extends GAlignmentPanel implements AdjustmentListener, Printable { - 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); - - annotationSpaceFillerHolder.setPreferredSize(annotationPanel.getPreferredSize()); - annotationScroller.setPreferredSize(annotationPanel.getPreferredSize()); - annotationScroller.setViewportView(annotationPanel); - annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER); - - fontChanged(); - - scalePanelHolder.add(scalePanel, BorderLayout.CENTER); - seqPanelHolder.add(seqPanel, BorderLayout.CENTER); - - setScrollValues(0, 0); - - hscroll.addAdjustmentListener(this); - vscroll.addAdjustmentListener(this); - - setFocusable(true); - addKeyListener(new KeyAdapter() - { - public void keyPressed(KeyEvent evt) - { - switch (evt.getKeyCode()) - { - case 27: // escape key - av.setSelectionGroup(null); - repaint(); + 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(); + } + } + }); - break; + fontChanged(); + adjustAnnotationHeight(); - case KeyEvent.VK_DOWN: - alignFrame.moveSelectedSequences(false); + } - break; + public void alignmentChanged() + { + av.alignmentChanged(this); - case KeyEvent.VK_UP: - alignFrame.moveSelectedSequences(true); + alignFrame.updateEditMenuBar(); - break; + paintAlignment(true); - case KeyEvent.VK_BACK_SPACE: - case KeyEvent.VK_DELETE: - alignFrame.cut_actionPerformed(null); - break; - } + } - } - }); - } + /** + * DOCUMENT ME! + */ + public void fontChanged() + { + // set idCanvas bufferedImage to null + // to prevent drawing old image + FontMetrics fm = getFontMetrics(av.getFont()); - /** - * 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())); - 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(); - 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); - Dimension d = calculateIdWidth(); - d.setSize(d.width + 4, d.height); - idPanel.idCanvas.setPreferredSize(d); - hscrollFillerPanel.setPreferredSize(d); - repaint(); + if (overviewPanel != null) + { + overviewPanel.setBoxPosition(); } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public Dimension calculateIdWidth() - { - Container c = new Container(); + repaint(); + } - FontMetrics fm = c.getFontMetrics(av.font); - AlignmentI al = av.getAlignment(); + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Dimension calculateIdWidth() + { + Container c = new Container(); - int i = 0; - int idWidth = 0; - String id; + FontMetrics fm = c.getFontMetrics( + new Font(av.font.getName(), Font.ITALIC, av.font.getSize())); - while ((i < al.getHeight()) && (al.getSequenceAt(i) != null)) - { - SequenceI s = al.getSequenceAt(i); + AlignmentI al = av.getAlignment(); - if (av.getShowFullId()) - { - id = s.getDisplayId(); - } - else - { - id = s.getName(); - } + int i = 0; + int idWidth = 0; + String id; - if (fm.stringWidth(id) > idWidth) - { - idWidth = fm.stringWidth(id); - } + while ( (i < al.getHeight()) && (al.getSequenceAt(i) != null)) + { + SequenceI s = al.getSequenceAt(i); - i++; - } + id = s.getDisplayId(av.getShowJVSuffix()); - // Also check annotation label widths - i = 0; + if (fm.stringWidth(id) > idWidth) + { + idWidth = fm.stringWidth(id); + } - if (al.getAlignmentAnnotation() != null) - { - fm = c.getFontMetrics(alabels.getFont()); + i++; + } - while (i < al.getAlignmentAnnotation().length) - { - String label = al.getAlignmentAnnotation()[i].label; + // Also check annotation label widths + i = 0; - if (fm.stringWidth(label) > idWidth) - { - idWidth = fm.stringWidth(label); - } + if (al.getAlignmentAnnotation() != null) + { + fm = c.getFontMetrics(alabels.getFont()); - i++; - } + while (i < al.getAlignmentAnnotation().length) + { + String label = al.getAlignmentAnnotation()[i].label; + + if (fm.stringWidth(label) > idWidth) + { + idWidth = fm.stringWidth(label); } - return new Dimension(idWidth, 12); + i++; + } } - /** - * DOCUMENT ME! - * - * @param results DOCUMENT ME! - */ - public void highlightSearchResults(int[] results) + 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) { - seqPanel.seqCanvas.highlightSearchResults(results); + 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; - // do we need to scroll the panel? - if (results != null) + if (!av.wrapAlignment) + { + if ( (av.getStartRes() > end) || (av.getEndRes() < start) || + ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex))) { - SequenceI seq = av.alignment.getSequenceAt(results[0]); - int start = seq.findIndex(results[1]) - 1; - int end = seq.findIndex(results[2]) - 1; - - if ((av.getStartRes() > start) || (av.getEndRes() < end) || - ((av.getStartSeq() > results[0]) || - (av.getEndSeq() < results[0]))) - { - setScrollValues(start, results[0]); - } + setScrollValues(start, seqIndex); } + } + else + { + scrollToWrappedVisible(start); + } } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public OverviewPanel getOverviewPanel() + paintAlignment(true); + } + + void scrollToWrappedVisible(int res) + { + int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas. + getWidth()); + if (res <= av.getStartRes() || res >= (av.getStartRes() + cwidth)) { - return overviewPanel; + vscroll.setValue(res / cwidth); + av.startRes = vscroll.getValue() * cwidth; } - - /** - * DOCUMENT ME! - * - * @param op DOCUMENT ME! - */ - public void setOverviewPanel(OverviewPanel op) + } + + /** + * 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) { - overviewPanel = op; + annotationSpaceFillerHolder.setVisible(b); + annotationScroller.setVisible(b); } + repaint(); + } - /** - * DOCUMENT ME! - * - * @param b DOCUMENT ME! - */ - public void setAnnotationVisible(boolean b) + public void adjustAnnotationHeight() + { + if (alignFrame.getHeight() == 0) { - annotationSpaceFillerHolder.setVisible(b); - annotationScroller.setVisible(b); + System.out.println("NEEDS FIXING"); } - /** - * DOCUMENT ME! - * - * @param wrap DOCUMENT ME! - */ - public void setWrapAlignment(boolean wrap) + int height = annotationPanel.adjustPanelHeight(); + + if (hscroll.isVisible()) + { + height += hscroll.getPreferredSize().height; + } + if (height > alignFrame.getHeight() / 2) { - scalePanelHolder.setVisible(!wrap); - hscroll.setVisible(!wrap); - idwidthAdjuster.setVisible(!wrap); + height = alignFrame.getHeight() / 2; + } - av.setShowAnnotation(!wrap); - annotationScroller.setVisible(!wrap); - annotationSpaceFillerHolder.setVisible(!wrap); - idSpaceFillerPanel1.setVisible(!wrap); + hscroll.addNotify(); - repaint(); - } + annotationScroller.setPreferredSize( + new Dimension(annotationScroller.getWidth(), height)); + + + annotationSpaceFillerHolder.setPreferredSize(new Dimension( + annotationSpaceFillerHolder.getWidth(), + height)); + + repaint(); + } + /** + * DOCUMENT ME! + * + * @param wrap DOCUMENT ME! + */ + public void setWrapAlignment(boolean wrap) + { + av.startSeq = 0; + scalePanelHolder.setVisible(!wrap); + hscroll.setVisible(!wrap); + idwidthAdjuster.setVisible(!wrap); - // return value is true if the scroll is valid - public boolean scrollUp(boolean up) + if (wrap) { - if (up) - { - if (vscroll.getValue() < 1) - { - return false; - } + annotationScroller.setVisible(false); + annotationSpaceFillerHolder.setVisible(false); + } + else if (av.showAnnotation) + { + annotationScroller.setVisible(true); + annotationSpaceFillerHolder.setVisible(true); + } - fastPaint = false; - vscroll.setValue(vscroll.getValue() - 1); - } - else - { - if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight()) - { - return false; - } + idSpaceFillerPanel1.setVisible(!wrap); - fastPaint = false; - vscroll.setValue(vscroll.getValue() + 1); - } + repaint(); + } - fastPaint = true; + // return value is true if the scroll is valid + public boolean scrollUp(boolean up) + { + if (up) + { + if (vscroll.getValue() < 1) + { + return false; + } - return true; + fastPaint = false; + vscroll.setValue(vscroll.getValue() - 1); } - - /** - * DOCUMENT ME! - * - * @param right DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public boolean scrollRight(boolean right) + else { - if (right) - { - if (hscroll.getValue() < 1) - { - return false; - } + if ( (vextent + vscroll.getValue()) >= av.getAlignment().getHeight()) + { + return false; + } - fastPaint = false; - hscroll.setValue(hscroll.getValue() - 1); - } - else - { - if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth()) - { - return false; - } + fastPaint = false; + vscroll.setValue(vscroll.getValue() + 1); + } - fastPaint = false; - hscroll.setValue(hscroll.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 = true; + fastPaint = false; + hscroll.setValue(hscroll.getValue() - 1); + } + else + { + if ( (hextent + hscroll.getValue()) >= av.getAlignment().getWidth()) + { + return false; + } - return true; + fastPaint = false; + hscroll.setValue(hscroll.getValue() + 1); } - /** - * DOCUMENT ME! - * - * @param x DOCUMENT ME! - * @param y DOCUMENT ME! - */ - public void setScrollValues(int x, int y) - { - av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - - 1); + fastPaint = true; - hextent = seqPanel.seqCanvas.getWidth() / av.charWidth; - vextent = seqPanel.seqCanvas.getHeight() / av.charHeight; + return true; + } - if (hextent > av.alignment.getWidth()) - { - hextent = av.alignment.getWidth(); - } + /** + * DOCUMENT ME! + * + * @param x DOCUMENT ME! + * @param y DOCUMENT ME! + */ + public void setScrollValues(int x, int y) + { - if (vextent > av.alignment.getHeight()) - { - vextent = av.alignment.getHeight(); - } + int width = av.alignment.getWidth(); + int height = av.alignment.getHeight(); - if ((hextent + x) > av.getAlignment().getWidth()) - { - x = av.getAlignment().getWidth() - hextent; - } + if (av.hasHiddenColumns) + { + width = av.getColumnSelection().findColumnPosition(width); + } - if ((vextent + y) > av.getAlignment().getHeight()) - { - y = av.getAlignment().getHeight() - vextent; - } + av.setEndRes( (x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1); - if (y < 0) - { - y = 0; - } + hextent = seqPanel.seqCanvas.getWidth() / av.charWidth; + vextent = seqPanel.seqCanvas.getHeight() / av.charHeight; - if (x < 0) - { - x = 0; - } + if (hextent > width) + { + hextent = width; + } - hscroll.setValues(x, hextent, 0, av.getAlignment().getWidth()); - vscroll.setValues(y, vextent, 0, av.getAlignment().getHeight()); + if (vextent > height) + { + vextent = height; } + if ( (hextent + x) > width) + { + x = width - hextent; + } - /** - * DOCUMENT ME! - * - * @param evt DOCUMENT ME! - */ - public void adjustmentValueChanged(AdjustmentEvent evt) + if ( (vextent + y) > height) { - int oldX = av.getStartRes(); - int oldY = av.getStartSeq(); + y = height - vextent; + } - if (evt.getSource() == hscroll) - { - int x = hscroll.getValue(); - av.setStartRes(x); - av.setEndRes((x + - (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1); - } + if (y < 0) + { + y = 0; + } - if (evt.getSource() == vscroll) - { - int offy = vscroll.getValue(); + if (x < 0) + { + x = 0; + } - if (av.getWrapAlignment()) - { - int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); - av.setStartRes(vscroll.getValue() * rowSize); - av.setEndRes((vscroll.getValue() + 1) * rowSize); - } - else - { - av.setStartSeq(offy); - av.setEndSeq(offy + - (seqPanel.seqCanvas.getHeight() / av.getCharHeight())); - } - } + hscroll.setValues(x, hextent, 0, width); + vscroll.setValues(y, vextent, 0, height); + } - if (overviewPanel != null) - { - overviewPanel.setBoxPosition(); - } + /** + * 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() || !fastPaint) + if (av.getWrapAlignment()) + { + if (offy > -1) { - repaint(); + int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel. + seqCanvas.getWidth()); + av.setStartRes(offy * rowSize); + av.setEndRes( (offy + 1) * rowSize); } else { - idPanel.idCanvas.fastPaint(av.getStartSeq() - oldY); - seqPanel.seqCanvas.fastPaint(av.getStartRes() - oldX, - av.getStartSeq() - oldY); - - scalePanel.repaint(); - - if (av.getShowAnnotation()) + //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() { - annotationPanel.fastPaint(av.getStartRes() - oldX); + setScrollValues(av.getStartRes(), av.getStartSeq()); } + }); } + } + else + { + av.setStartSeq(offy); + av.setEndSeq(offy + + (seqPanel.seqCanvas.getHeight() / av.getCharHeight())); + } } - /** - * DOCUMENT ME! - * - * @param g DOCUMENT ME! - */ - public void paintComponent(Graphics g) + if (overviewPanel != null) { - invalidate(); + overviewPanel.setBoxPosition(); + } - Dimension d = idPanel.idCanvas.getPreferredSize(); - idPanelHolder.setPreferredSize(d); - hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12)); - validate(); + int scrollX = av.startRes - oldX; + int scrollY = av.startSeq - oldY; - if (av.getWrapAlignment()) - { - int max = av.alignment.getWidth() / seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); - vscroll.setMaximum(max); - vscroll.setUnitIncrement(1); - vscroll.setVisibleAmount(1); - } - else - { - setScrollValues(av.getStartRes(), av.getStartSeq()); - } + if (av.getWrapAlignment() || !fastPaint) + { + repaint(); } - - /** - * 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 + else { - pg.translate((int) pf.getImageableX(), (int) pf.getImageableY()); + // 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; + } - int pwidth = (int) pf.getImageableWidth(); - int pheight = (int) pf.getImageableHeight(); + if (scrollX != 0 || scrollY != 0) + { + idPanel.idCanvas.fastPaint(scrollY); + seqPanel.seqCanvas.fastPaint(scrollX, + scrollY); + scalePanel.repaint(); - if (av.getWrapAlignment()) - { - return printWrappedAlignment(pg, pwidth, pheight, pi); - } - else + if (av.getShowAnnotation()) { - return printUnwrapped(pg, pwidth, pheight, pi); + annotationPanel.fastPaint(scrollX); } + } } + } - /** - * 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 = calculateIdWidth().width + 4; - 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(); + public void paintAlignment(boolean updateOverview) + { + repaint(); - 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; + if(updateOverview) + { + jalview.structure.StructureSelectionManager.getStructureSelectionManager() + .sequenceColoursChanged(this); - ///////////////////////////// - /// Only print these sequences and residues on this page - int endRes; + 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(); - ///////////////////////////// - /// Only print these sequences and residues on this page - int startSeq; + if (av.hasHiddenColumns) + { + maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + } - ///////////////////////////// - /// Only print these sequences and residues on this page - int endSeq; - startRes = (pi % pagesWide) * totalRes; - endRes = (startRes + totalRes) - 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; + } - if (endRes > (av.getAlignment().getWidth() - 1)) - { - endRes = av.getAlignment().getWidth() - 1; - } + startSeq = (pi / pagesWide) * totalSeq; + endSeq = startSeq + totalSeq; - startSeq = (pi / pagesWide) * totalSeq; - endSeq = startSeq + totalSeq; + if (endSeq > av.getAlignment().getHeight()) + { + endSeq = av.getAlignment().getHeight(); + } - if (endSeq > av.getAlignment().getHeight()) - { - endSeq = av.getAlignment().getHeight(); - } + int pagesHigh = ( (av.alignment.getHeight() / totalSeq) + 1) * pheight; - int pagesHigh = ((av.alignment.getHeight() / totalSeq) + 1) * pheight; + if (av.showAnnotation) + { + pagesHigh += annotationPanel.adjustPanelHeight() + 3; + } - if (av.showAnnotation) - { - pagesHigh += annotationPanel.getHeight(); - } + pagesHigh /= pheight; - pagesHigh /= pheight; + if (pi >= (pagesWide * pagesHigh)) + { + return Printable.NO_SUCH_PAGE; + } - 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 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; - //////////////// - // Draw the ids - Color currentColor = null; - Color currentTextColor = null; + pg.setFont(idPanel.idCanvas.idfont); - for (int i = startSeq; i < endSeq; i++) - { - if ((av.getSelectionGroup() != null) && - av.getSelectionGroup().sequences.contains( - av.getAlignment().getSequenceAt(i))) - { - currentColor = Color.gray; - currentTextColor = Color.black; - } - else - { - currentColor = av.getAlignment().getSequenceAt(i).getColor(); - currentTextColor = Color.black; - } + 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(currentColor); + pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth, + av.getCharHeight()); - pg.setColor(currentTextColor); + pg.setColor(currentTextColor); - String string = av.getAlignment().getSequenceAt(i).getName(); + int xPos = 0; + if (av.rightAlignIds) + { + fm = pg.getFontMetrics(); + xPos = idWidth - fm.stringWidth( + seq.getDisplayId(av.getShowJVSuffix()) + ) - 4; + } - if (av.getShowFullId()) - { - string = av.getAlignment().getSequenceAt(i).getDisplayId(); - } + pg.drawString(seq.getDisplayId(av.getShowJVSuffix()), + xPos, + ( ( (i - startSeq) * av.charHeight) + av.getCharHeight()) - + (av.getCharHeight() / 5)); + } - pg.drawString(string, 0, - (((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, - startRes, startSeq, 0); + // 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, (endSeq - startSeq) * av.charHeight); - alabels.drawComponent((Graphics2D) pg); - pg.translate(idWidth, 0); - annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes + - 1); - } + 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 idWidth = calculateIdWidth().width + 4; - - int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth - - idWidth); - int totalHeight = totalHeight = (av.alignment.getHeight() + 2) * ((av.alignment.getWidth() / resWidth) + - 1) * av.charHeight; - - pg.setColor(Color.white); - pg.fillRect(0, 0, pwidth, pheight); - pg.setFont(av.getFont()); + 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); + } - //////////////// - // Draw the ids - pg.setColor(Color.black); + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + { + hgap += av.charHeight; + } - pg.translate(0, -pi * pheight); + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + + annotationHeight; - pg.setClip(0, pi * pheight, pwidth, pheight); + int idWidth = getVisibleIdWidth(); - int ypos = 2 * av.charHeight; + int maxwidth = av.alignment.getWidth(); + if (av.hasHiddenColumns) + { + maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + } - do - { - for (int i = 0; i < av.alignment.getHeight(); i++) - { - SequenceI s = av.alignment.getSequenceAt(i); - String string = s.getName(); + int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth - + idWidth); - if (av.getShowFullId()) - { - string = s.getDisplayId(); - } + int totalHeight = cHeight * (maxwidth / resWidth + 1); - pg.drawString(string, 0, - ((i * av.charHeight) + ypos + av.charHeight) - - (av.charHeight / 5)); - } + pg.setColor(Color.white); + pg.fillRect(0, 0, pwidth, pheight); + pg.setFont(av.getFont()); - ypos += ((av.alignment.getHeight() + 2) * av.charHeight); - } - while (ypos < totalHeight); + //////////////// + // Draw the ids + pg.setColor(Color.black); - pg.translate(idWidth, 0); + pg.translate(0, -pi * pheight); - seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0); + pg.setClip(0, pi * pheight, pwidth, pheight); - if ((pi * pheight) < totalHeight) - { - return Printable.PAGE_EXISTS; - } - else - { - return Printable.NO_SUCH_PAGE; - } - } + int ypos = hgap; - /** - * DOCUMENT ME! - */ - public void makeEPS(File epsFile) + do { - if(epsFile == null) + 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) { - jalview.io.JalviewFileChooser chooser = new jalview.io. - JalviewFileChooser(jalview.bin.Cache.getProperty( - "LAST_DIRECTORY"), new String[] - {"eps"}, - new String[] - {"Encapsulated Postscript"}, - "Encapsulated Postscript"); - chooser.setFileView(new jalview.io.JalviewFileView()); - chooser.setDialogTitle("Create EPS file from alignment"); - chooser.setToolTipText("Save"); - - int value = chooser.showSaveDialog(this); - - if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) - { - return; - } - - epsFile = chooser.getSelectedFile(); - - jalview.bin.Cache.setProperty("LAST_DIRECTORY", - chooser.getSelectedFile().getParent()); + 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)); - int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30; - int width = idPanel.getWidth() + (av.alignment.getWidth() * av.charWidth); - - if (av.getWrapAlignment()) - { - height = ( (av.alignment.getWidth() / av.getChunkWidth()) + 1) * - av.chunkHeight; - width = seqPanel.getWidth() + idPanel.getWidth(); - - } + pg.setFont(av.getFont()); + labels.drawComponent(pg, idWidth); + pg.translate( +3, + -ypos - + (av.getAlignment().getHeight() * av.charHeight)); + } + ypos += cHeight; + } + while (ypos < totalHeight); - if (av.getShowAnnotation()) - { - height += annotationPanel.getPreferredSize().height; - } + pg.translate(idWidth, 0); - try - { - FileOutputStream out = new FileOutputStream(epsFile); - EpsGraphics2D pg = new EpsGraphics2D("Example", out, 0, 0, width, - height); + seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0); - if (av.getWrapAlignment()) - { - printWrappedAlignment(pg, width, height, 0); - } - else - { - printUnwrapped(pg, width, height, 0); - } + if ( (pi * pheight) < totalHeight) + { + return Printable.PAGE_EXISTS; - pg.flush(); - pg.close(); - } - catch (Exception ex) - { - ex.printStackTrace(); - } + } + 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); - public void makePNGImageMap(File imgMapFile, String imageName) - { - ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS - ////////////////////////////////////////////// - int idWidth = calculateIdWidth().width + 4; - FontMetrics fm = getFontMetrics(av.getFont()); - int scaleHeight = av.charHeight + fm.getDescent(); - - // Gen image map - ////////////////////////////////// - if(imgMapFile!=null) - { - try - { - PrintWriter out = new PrintWriter(new FileWriter(imgMapFile)); - out.println(jalview.io.HTMLOutput.getImageMapHTML()); - out.println("" - +""); - - for (int s = 0; s < av.alignment.getHeight(); s++) - { - SequenceI seq = av.alignment.getSequenceAt(s); - SequenceGroup[] groups = av.alignment.findAllGroups(seq); - for (int i = 0; i < groups.length; i++) - { - int sy = s * av.charHeight + scaleHeight; - for (int res = groups[i].getStartRes(); - res < groups[i].getEndRes() + 1; res++) - { - int alIndex = seq.findPosition(res); - Object obj = ResidueProperties.aa2Triplet.get( - seq.getCharAt(res) + ""); - if (obj == null) - continue; - - String triplet = obj.toString(); - - out.println( - "" + groups[i].getName() + - "')\"; onMouseOut=\"toolTip()\"; " - + " href=\"#\">"); - } - } - } - - out.println(""); - out.close(); - - } - catch (Exception ex) - { - ex.printStackTrace(); - } - }///////////END OF IMAGE MAP - - } - - /** - * DOCUMENT ME! - */ - public void makePNG(File pngFile) - { - if(pngFile==null) + if (av.getWrapAlignment()) + { + height = getWrappedHeight(); + if (System.getProperty("java.awt.headless") != null + && System.getProperty("java.awt.headless").equals("true")) { - jalview.io.JalviewFileChooser chooser = new jalview.io. - JalviewFileChooser(jalview.bin.Cache.getProperty( - "LAST_DIRECTORY"), new String[] - {"png"}, - new String[] - {"Portable network graphics"}, - "Portable network graphics"); - chooser.setFileView(new jalview.io.JalviewFileView()); - chooser.setDialogTitle("Create EPS file from alignment"); - chooser.setToolTipText("Save"); - - int value = chooser.showSaveDialog(this); - - if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) - { - return; - } - - pngFile = chooser.getSelectedFile(); - - jalview.bin.Cache.setProperty("LAST_DIRECTORY", - chooser.getSelectedFile().getParent()); + 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 + { - int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30; - int width = idPanel.getWidth() + (av.alignment.getWidth() * av.charWidth); + 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()) { - height = ( (av.alignment.getWidth() / av.getChunkWidth()) + 1) * - av.chunkHeight; - width = seqPanel.getWidth() + idPanel.getWidth(); - + if (im.getGraphics() != null) + { + printWrappedAlignment(im.getGraphics(), width, height, 0); + im.writeImage(); + } } - - - if (av.getShowAnnotation()) + else + { + if (im.getGraphics() != null) { - height += annotationPanel.getPreferredSize().height; + 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(); - try + } + 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("" + + ""); + + for (s = 0; s < sSize; s++) { + sy = s * av.charHeight + scaleHeight; - FileOutputStream out = new FileOutputStream(pngFile); + 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) + ""); + } - BufferedImage bi = new BufferedImage(width, height, - BufferedImage.TYPE_INT_RGB); - Graphics2D png = (Graphics2D) bi.getGraphics(); + if (obj == null) + { + continue; + } - png.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + String triplet = obj.toString(); + int alIndex = seq.findPosition(res); + gSize = groups.length; + for (g = 0; g < gSize; g++) + { + if (text.length() < 1) + { + text.append(" res) + { + text.append("
" + groups[g].getName() + ""); + } + } - if (av.getWrapAlignment()) + if (features != null) { - printWrappedAlignment(png, width, height, 0); + if (text.length() < 1) + { + text.append("= 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("
disulfide bond " + features[f].getBegin() + + ":" + + features[f].getEnd()); + } + } + else + { + text.append("
"); + 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") + ")"); + } + } + } + + } } - else + if (text.length() > 1) { - printUnwrapped(png, width, height, 0); + text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">"); + out.println(text.toString()); } - - ImageIO.write(bi, "png", out); - out.close(); - } - catch(OutOfMemoryError err) - { - System.out.println("########################\n" - +"OUT OF MEMORY "+pngFile+"\n" - +"########################"); - } - catch (Exception ex) - { - ex.printStackTrace(); + } } - } -} + out.println("
"); + out.close(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } ///////////END OF IMAGE MAP -/** - * DOCUMENT ME! - * - * @author $author$ - * @version $Revision$ - */ -class Preview extends JFrame -{ - /** - * Creates a new Preview object. - * - * @param image DOCUMENT ME! - */ - public Preview(Image image) - { - setResizable(true); - setSize(image.getWidth(this), image.getHeight(this)); - setVisible(true); - getContentPane().setLayout(new BorderLayout()); - getContentPane().add(new PreviewPanel(image), BorderLayout.CENTER); - validate(); - repaint(); + } + + 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 + ); -/** - * DOCUMENT ME! - * - * @author $author$ - * @version $Revision$ - */ -class PreviewPanel extends JPanel -{ - Image image; + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + { + hgap += av.charHeight; + } - /** - * Creates a new PreviewPanel object. - * - * @param image DOCUMENT ME! - */ - public PreviewPanel(Image image) + int annotationHeight = 0; + if (av.showAnnotation) { - this.image = image; + annotationHeight = annotationPanel.adjustPanelHeight(); } - /** - * DOCUMENT ME! - * - * @param g DOCUMENT ME! - */ - public void paintComponent(Graphics g) + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + + annotationHeight; + + int maxwidth = av.alignment.getWidth(); + if (av.hasHiddenColumns) { - if (image != null) - { - g.drawImage(image, 0, 0, this); - } - else - { - System.out.println("DEBUG:image is null"); - } + maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; } + + int height = ( (maxwidth / chunkWidth) + 1) * cHeight; + + return height; + } }