X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignmentPanel.java;h=1574d0350772b2e8882ebb5f29efbbd05d8155b5;hb=237972562c84b83dbd287071cdd839d97aaf7d4b;hp=f6e6114c4a7f7762584684d49ff1621603026188;hpb=e1124a62486322d2d28482529d2d6b850ce1719b;p=jalview.git diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index f6e6114..1574d03 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) 2006 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 @@ -24,18 +24,13 @@ import jalview.jbgui.*; import jalview.schemes.*; -import org.jibble.epsgraphics.*; - 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 java.beans.*; + /** @@ -47,1013 +42,1120 @@ import javax.swing.*; 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) + 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); + + fontChanged(); + + 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() { - alignFrame = af; - this.av = av; - seqPanel = new SeqPanel(av, this); - idPanel = new IdPanel(av, this); + public void propertyChange(PropertyChangeEvent evt) + { + if (evt.getPropertyName().equals("alignment")) + { + PaintRefresher.Refresh(ap, + av.getSequenceSetId(), + true, + true); + alignmentChanged(); + } + } + }); - scalePanel = new ScalePanel(av, this); + adjustAnnotationHeight(); - idPanelHolder.add(idPanel, BorderLayout.CENTER); - idwidthAdjuster = new IdwidthAdjuster(this); - idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER); + } - annotationPanel = new AnnotationPanel(this); - alabels = new AnnotationLabels(this); + public void alignmentChanged() + { + av.alignmentChanged(this); - annotationSpaceFillerHolder.setPreferredSize(annotationPanel.getPreferredSize()); - annotationScroller.setPreferredSize(annotationPanel.getPreferredSize()); - annotationScroller.setViewportView(annotationPanel); - annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER); + if (overviewPanel != null) + overviewPanel.updateOverviewImage(); - fontChanged(); + alignFrame.updateEditMenuBar(); - scalePanelHolder.add(scalePanel, BorderLayout.CENTER); - seqPanelHolder.add(seqPanel, BorderLayout.CENTER); + repaint(); + } - 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(); + /** + * DOCUMENT ME! + */ + public void fontChanged() + { + // set idCanvas bufferedImage to null + // to prevent drawing old image + FontMetrics fm = getFontMetrics(av.getFont()); - break; + scalePanelHolder.setPreferredSize(new Dimension(10, + av.charHeight + fm.getDescent())); + idSpaceFillerPanel1.setPreferredSize(new Dimension(10, + av.charHeight + fm.getDescent())); - case KeyEvent.VK_DOWN: - alignFrame.moveSelectedSequences(false); + idPanel.idCanvas.gg = null; + seqPanel.seqCanvas.img = null; + annotationPanel.adjustPanelHeight(); - break; + Dimension d = calculateIdWidth(); + d.setSize(d.width + 4, d.height); + idPanel.idCanvas.setPreferredSize(d); + hscrollFillerPanel.setPreferredSize(d); - case KeyEvent.VK_UP: - alignFrame.moveSelectedSequences(true); + if (overviewPanel != null) + overviewPanel.setBoxPosition(); - break; + repaint(); + } - case KeyEvent.VK_BACK_SPACE: - case KeyEvent.VK_DELETE: - alignFrame.cut_actionPerformed(null); - break; - } + /** + * 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())); - /** - * DOCUMENT ME! - */ - public void fontChanged() - { - // set idCanvas bufferedImage to null - // to prevent drawing old image - FontMetrics fm = getFontMetrics(av.getFont()); + AlignmentI al = av.getAlignment(); - scalePanelHolder.setPreferredSize(new Dimension(10, - av.charHeight + fm.getDescent())); - idSpaceFillerPanel1.setPreferredSize(new Dimension(10, - av.charHeight + fm.getDescent())); + int i = 0; + int idWidth = 0; + String id; - idPanel.idCanvas.gg = null; - seqPanel.seqCanvas.img = null; - annotationPanel.adjustPanelHeight(); + while ( (i < al.getHeight()) && (al.getSequenceAt(i) != null)) + { + SequenceI s = al.getSequenceAt(i); - Dimension d = calculateIdWidth(); - d.setSize(d.width + 4, d.height); - idPanel.idCanvas.setPreferredSize(d); - hscrollFillerPanel.setPreferredSize(d); + id = s.getDisplayId(av.getShowJVSuffix()); - 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(overviewPanel!=null) - overviewPanel.setBoxPosition(); + if (fm.stringWidth(id) > idWidth) + { + idWidth = fm.stringWidth(id); + } - repaint(); + i++; } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public Dimension calculateIdWidth() - { - Container c = new Container(); + // Also check annotation label widths + i = 0; - FontMetrics fm = c.getFontMetrics(av.font); - AlignmentI al = av.getAlignment(); + if (al.getAlignmentAnnotation() != null) + { + fm = c.getFontMetrics(alabels.getFont()); - int i = 0; - int idWidth = 0; - String id; + while (i < al.getAlignmentAnnotation().length) + { + String label = al.getAlignmentAnnotation()[i].label; - while ((i < al.getHeight()) && (al.getSequenceAt(i) != null)) + if (fm.stringWidth(label) > idWidth) { - SequenceI s = al.getSequenceAt(i); - - if (av.getShowFullId()) - { - id = s.getDisplayId(); - } - else - { - id = s.getName(); - } - - if (fm.stringWidth(id) > idWidth) - { - idWidth = fm.stringWidth(id); - } - - i++; + idWidth = fm.stringWidth(label); } - // 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; + i++; + } + } - if (fm.stringWidth(label) > idWidth) - { - idWidth = fm.stringWidth(label); - } + return new Dimension(idWidth, 12); + } - i++; - } - } + /** + * DOCUMENT ME! + * + * @param results DOCUMENT ME! + */ + public void highlightSearchResults(SearchResults results) + { + seqPanel.seqCanvas.highlightSearchResults(results); - return new Dimension(idWidth, 12); - } - - /** - * DOCUMENT ME! - * - * @param results DOCUMENT ME! - */ - public void highlightSearchResults(int[] 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() + 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 (height > alignFrame.getHeight() / 2) { - 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(); + height = alignFrame.getHeight() / 2; } - - // return value is true if the scroll is valid - public boolean scrollUp(boolean up) + 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); + + 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; - } - - 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; + if ( (vextent + vscroll.getValue()) >= av.getAlignment().getHeight()) + { + return false; + } - return true; + fastPaint = false; + vscroll.setValue(vscroll.getValue() + 1); } - /** - * DOCUMENT ME! - * - * @param x DOCUMENT ME! - * @param y DOCUMENT ME! - */ - public void setScrollValues(int x, int y) + fastPaint = true; + + return true; + } + + /** + * DOCUMENT ME! + * + * @param right DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public boolean scrollRight(boolean right) + { + if (!right) { - av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - - 1); + if (hscroll.getValue() < 1) + { + return false; + } - hextent = seqPanel.seqCanvas.getWidth() / av.charWidth; - vextent = seqPanel.seqCanvas.getHeight() / av.charHeight; + fastPaint = false; + hscroll.setValue(hscroll.getValue() - 1); + } + else + { + if ( (hextent + hscroll.getValue()) >= av.getAlignment().getWidth()) + { + return false; + } - if (hextent > av.alignment.getWidth()) - { - hextent = av.alignment.getWidth(); - } + fastPaint = false; + hscroll.setValue(hscroll.getValue() + 1); + } - if (vextent > av.alignment.getHeight()) - { - vextent = av.alignment.getHeight(); - } + fastPaint = true; - if ((hextent + x) > av.getAlignment().getWidth()) - { - x = av.getAlignment().getWidth() - hextent; - } + return true; + } - if ((vextent + y) > av.getAlignment().getHeight()) - { - y = av.getAlignment().getHeight() - vextent; - } + /** + * DOCUMENT ME! + * + * @param x DOCUMENT ME! + * @param y DOCUMENT ME! + */ + public void setScrollValues(int x, int y) + { - if (y < 0) - { - y = 0; - } + int width = av.alignment.getWidth(); + int height = av.alignment.getHeight(); - if (x < 0) - { - x = 0; - } + if(av.hasHiddenColumns) + width = av.getColumnSelection().findColumnPosition(width); - hscroll.setValues(x, hextent, 0, av.getAlignment().getWidth()); - vscroll.setValues(y, vextent, 0, av.getAlignment().getHeight()); - } + av.setEndRes( (x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) -1); + hextent = seqPanel.seqCanvas.getWidth() / av.charWidth; + vextent = seqPanel.seqCanvas.getHeight() / av.charHeight; - /** - * DOCUMENT ME! - * - * @param evt DOCUMENT ME! - */ - public void adjustmentValueChanged(AdjustmentEvent evt) + if (hextent > width) { + hextent = width; + } - int oldX = av.getStartRes(); - int oldY = av.getStartSeq(); + if (vextent > height) + { + vextent = height; + } - if (evt.getSource() == hscroll) - { - int x = hscroll.getValue(); - av.setStartRes(x); - av.setEndRes((x + - (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1); - } + if ( (hextent + x) > width) + { + x = width - hextent; + } - if (evt.getSource() == vscroll) - { - int offy = vscroll.getValue(); + if ( (vextent + y) > height) + { + y = height - vextent; + } - 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())); - } - } + if (y < 0) + { + y = 0; + } - if (overviewPanel != null) - { - overviewPanel.setBoxPosition(); - } + if (x < 0) + { + x = 0; + } - int xShift = av.getStartRes() - oldX; - int yShift = av.getStartSeq() - oldY; + hscroll.setValues(x, hextent, 0, width); + vscroll.setValues(y, vextent, 0, height); + } - if ( (xShift != 0 && yShift != 0) || - (Math.abs(xShift) > av.getEndRes() - av.getStartRes() - || Math.abs(yShift) > av.getEndSeq() - av.getStartSeq()) - || av.getWrapAlignment() - || !fastPaint) - { - // Either no shift at all, or shift greater than visible amount - repaint(); - } - else - { - idPanel.idCanvas.fastPaint(yShift); - seqPanel.seqCanvas.fastPaint(xShift, yShift); + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void adjustmentValueChanged(AdjustmentEvent evt) + { - scalePanel.repaint(); + int oldX = av.getStartRes(); + int oldY = av.getStartSeq(); - if (av.getShowAnnotation()) - { - annotationPanel.fastPaint(xShift); - } - } + if (evt.getSource() == hscroll) + { + int x = hscroll.getValue(); + av.setStartRes(x); + av.setEndRes( (x + + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1); } - /** - * DOCUMENT ME! - * - * @param g DOCUMENT ME! - */ - public void paintComponent(Graphics g) + if (evt.getSource() == vscroll) { - invalidate(); + int offy = vscroll.getValue(); - Dimension d = idPanel.idCanvas.getPreferredSize(); - idPanelHolder.setPreferredSize(d); - hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12)); - validate(); - - if (av.getWrapAlignment()) + if (av.getWrapAlignment()) + { + if(offy>-1) { - int max = av.alignment.getWidth() / seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); - vscroll.setMaximum(max); - vscroll.setUnitIncrement(1); - vscroll.setVisibleAmount(1); + int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel. + seqCanvas.getWidth()); + av.setStartRes(offy * rowSize); + av.setEndRes( (offy + 1) * rowSize); } else { - setScrollValues(av.getStartRes(), av.getStartSeq()); + //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())); + } } - /** - * 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 + if (overviewPanel != null) { - pg.translate((int) pf.getImageableX(), (int) pf.getImageableY()); + overviewPanel.setBoxPosition(); + } - int pwidth = (int) pf.getImageableWidth(); - int pheight = (int) pf.getImageableHeight(); + int scrollX = av.startRes - oldX; + int scrollY = av.startSeq - oldY; - if (av.getWrapAlignment()) - { - return printWrappedAlignment(pg, pwidth, pheight, pi); - } - else + 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(scrollX0) + { + 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()); + } - 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; + if( this.getVisibleRect().getBounds() == g.getClipBounds() + && overviewPanel != null) + overviewPanel.updateOverviewImage(); + } + + /** + * 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; + } - ///////////////////////////// - /// Only print these sequences and residues on this page - int startSeq; + startSeq = (pi / pagesWide) * totalSeq; + endSeq = startSeq + totalSeq; - ///////////////////////////// - /// Only print these sequences and residues on this page - int endSeq; - startRes = (pi % pagesWide) * totalRes; - endRes = (startRes + totalRes) - 1; + if (endSeq > av.getAlignment().getHeight()) + { + endSeq = av.getAlignment().getHeight(); + } - if (endRes > (av.getAlignment().getWidth() - 1)) - { - endRes = av.getAlignment().getWidth() - 1; - } + int pagesHigh = ( (av.alignment.getHeight() / totalSeq) + 1) * pheight; - startSeq = (pi / pagesWide) * totalSeq; - endSeq = startSeq + totalSeq; + if (av.showAnnotation) + { + pagesHigh += annotationPanel.adjustPanelHeight() + 3; + } - if (endSeq > av.getAlignment().getHeight()) - { - endSeq = av.getAlignment().getHeight(); - } + pagesHigh /= pheight; - int pagesHigh = ((av.alignment.getHeight() / totalSeq) + 1) * pheight; + if (pi >= (pagesWide * pagesHigh)) + { + return Printable.NO_SUCH_PAGE; + } - if (av.showAnnotation) - { - pagesHigh += annotationPanel.getHeight(); - } + //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(new Font(av.getFont().getName(), + Font.ITALIC, + av.getFont().getSize())); + SequenceI seq; + for (int i = startSeq; i < endSeq; i++) + { + seq = av.getAlignment().getSequenceAt(i); + if ( (av.getSelectionGroup() != null) && + av.getSelectionGroup().getSequences(false).contains(seq)) + { + currentColor = Color.gray; + currentTextColor = Color.black; + } + else + { + currentColor = av.getSequenceColour(seq); + currentTextColor = Color.black; + } - pagesHigh /= pheight; + pg.setColor(currentColor); + pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth, + av.getCharHeight()); - if (pi >= (pagesWide * pagesHigh)) - { - return Printable.NO_SUCH_PAGE; - } + pg.setColor(currentTextColor); - //draw Scale - pg.translate(idWidth, 0); - scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight); - pg.translate(-idWidth, scaleHeight); + int xPos = 0; + if (av.rightAlignIds) + { + fm = pg.getFontMetrics(); + xPos = idWidth - fm.stringWidth( + seq.getDisplayId(av.getShowJVSuffix()) + ) - 4; + } - //////////////// - // Draw the ids - Color currentColor = null; - Color currentTextColor = null; + pg.drawString(seq.getDisplayId( av.getShowJVSuffix()), + xPos, + ( ( (i - startSeq) * av.charHeight) + av.getCharHeight()) - + (av.getCharHeight() / 5)); + } - 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; - } + pg.setFont(av.getFont()); - pg.setColor(currentColor); - pg.fillRect(0, (i-startSeq) * av.charHeight, idWidth, - av.getCharHeight()); + // draw main sequence panel + pg.translate(idWidth, 0); + seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0); - pg.setColor(currentTextColor); + 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); + } - String string = av.getAlignment().getSequenceAt(i).getName(); + 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); + } - if (av.getShowFullId()) - { - string = av.getAlignment().getSequenceAt(i).getDisplayId(); - } + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + hgap += av.charHeight; - pg.drawString(string, 0, - (((i-startSeq) * av.charHeight) + av.getCharHeight()) - - (av.getCharHeight() / 5)); - } + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + + annotationHeight; - // draw main sequence panel - pg.translate(idWidth, 0); - seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, - startRes, startSeq, 0); + int idWidth = getVisibleIdWidth(); - 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); - } + int maxwidth = av.alignment.getWidth(); + if (av.hasHiddenColumns) + maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 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 resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth - - idWidth); - int totalHeight = totalHeight = (av.alignment.getHeight() + 2) * ((av.alignment.getWidth() / resWidth) + - 1) * av.charHeight; + int totalHeight = cHeight * (maxwidth / resWidth + 1); - pg.setColor(Color.white); - pg.fillRect(0, 0, pwidth, pheight); - pg.setFont(av.getFont()); + pg.setColor(Color.white); + pg.fillRect(0, 0, pwidth, pheight); + pg.setFont(av.getFont()); - //////////////// - // Draw the ids - pg.setColor(Color.black); + //////////////// + // Draw the ids + pg.setColor(Color.black); - pg.translate(0, -pi * pheight); + pg.translate(0, -pi * pheight); - pg.setClip(0, pi * pheight, pwidth, pheight); + pg.setClip(0, pi * pheight, pwidth, pheight); - int ypos = 2 * av.charHeight; + int ypos = hgap; + Font italic = new Font(av.getFont().getName(), Font.ITALIC, + av.getFont().getSize()); + pg.setFont(italic); - do + do + { + for (int i = 0; i < av.alignment.getHeight(); i++) + { + SequenceI s = av.alignment.getSequenceAt(i); + String string = s.getDisplayId( av.getShowJVSuffix()); + int xPos = 0; + if (av.rightAlignIds) { - for (int i = 0; i < av.alignment.getHeight(); i++) - { - SequenceI s = av.alignment.getSequenceAt(i); - String string = s.getName(); + FontMetrics fm = getFontMetrics(italic); + 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)); - if (av.getShowFullId()) - { - string = s.getDisplayId(); - } + pg.setFont(av.getFont()); + labels.drawComponent(pg, idWidth); + pg.setFont(italic); + pg.translate(+3, + -ypos - + (av.getAlignment().getHeight() * av.charHeight)); + } - pg.drawString(string, 0, - ((i * av.charHeight) + ypos + av.charHeight) - - (av.charHeight / 5)); - } + ypos += cHeight; + } + while (ypos < totalHeight); - ypos += ((av.alignment.getHeight() + 2) * av.charHeight); - } - while (ypos < totalHeight); + pg.translate(idWidth, 0); - pg.translate(idWidth, 0); + seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0); - seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0); + if ( (pi * pheight) < totalHeight) + { + return Printable.PAGE_EXISTS; - if ((pi * pheight) < totalHeight) - { - return Printable.PAGE_EXISTS; - } - else - { - return Printable.NO_SUCH_PAGE; - } } - - /** - * DOCUMENT ME! - */ - public void makeEPS(File epsFile) + else { - boolean accurateText = true; - - String renderStyle = jalview.bin.Cache.getDefault("EPS_RENDERING", - "Prompt each time"); + return Printable.NO_SUCH_PAGE; + } + } - // If we need to prompt, and if the GUI is visible then - // Prompt for EPS rendering style - if (renderStyle.equalsIgnoreCase("Prompt each time") - && ! - (System.getProperty("java.awt.headless") != null - && System.getProperty("java.awt.headless").equals("true"))) - { - EPSOptions eps = new EPSOptions(); - renderStyle = eps.getValue(); + int getVisibleIdWidth() + { + return + idPanel.getWidth() > 0 ? idPanel.getWidth() : + calculateIdWidth().width + 4; + } - if(eps.cancelled || renderStyle==null) - return; + void makeAlignmentImage(int type, File file) + { + int maxwidth = av.alignment.getWidth(); + if (av.hasHiddenColumns) + maxwidth = av.getColumnSelection().findColumnPosition(maxwidth); - renderStyle = eps.getValue(); - } + int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30; + int width = getVisibleIdWidth() + (maxwidth * av.charWidth); - if (renderStyle.equalsIgnoreCase("text")) + if (av.getWrapAlignment()) + { + height = getWrappedHeight(); + if (System.getProperty("java.awt.headless") != null + && System.getProperty("java.awt.headless").equals("true")) { - accurateText = false; + width = alignFrame.getWidth() - 22; } + else + width = seqPanel.getWidth() + getVisibleIdWidth(); + } + else if (av.getShowAnnotation()) + { + height += annotationPanel.adjustPanelHeight() + 3; + } - if(epsFile == null) - { - 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()); - } - - 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(); - - } + 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.getShowAnnotation()) + if (av.getWrapAlignment()) + { + if(im.getGraphics()!=null) { - height += annotationPanel.getPreferredSize().height; + printWrappedAlignment(im.getGraphics(), width, height, 0); + im.writeImage(); } - - try - { - FileOutputStream out = new FileOutputStream(epsFile); - EpsGraphics2D pg = new EpsGraphics2D("Example", out, 0, 0, width, - height); - - pg.setAccurateTextMode(accurateText); - - if (av.getWrapAlignment()) - { - printWrappedAlignment(pg, width, height, 0); - } - else - { - printUnwrapped(pg, width, height, 0); - } - - pg.flush(); - pg.close(); - } - catch (OutOfMemoryError err) - { - System.out.println("########################\n" - + "OUT OF MEMORY " + epsFile + "\n" - + "########################"); - - JOptionPane.showInternalMessageDialog(Desktop.desktop, - "Out of memory creating EPS file!!" - + - "\nSee help files for increasing Java Virtual Machine memory." - , "Out of memory", - JOptionPane.WARNING_MESSAGE); - System.out.println("Create EPS: " + err); - System.gc(); - } - catch (Exception ex) + } + else + { + if(im.getGraphics()!=null) { - ex.printStackTrace(); + printUnwrapped(im.getGraphics(), width, height, 0); + im.writeImage(); } + } } - - - public void makePNGImageMap(File imgMapFile, String imageName) + catch (OutOfMemoryError err) { - ///////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 + 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(); } - - /** - * DOCUMENT ME! - */ - public void makePNG(File pngFile) + catch (Exception ex) { - if(pngFile==null) + 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 { - 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) + 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++) { - return; - } + sy = s * av.charHeight + scaleHeight; - pngFile = chooser.getSelectedFile(); + SequenceI seq = av.alignment.getSequenceAt(s); + SequenceFeature [] features = seq.getDatasetSequence().getSequenceFeatures(); + SequenceGroup[] groups = av.alignment.findAllGroups(seq); + for(res =0; resres) + text.append("
" + groups[g].getName() + ""); + } + if (features != null) + { + 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") + ")"); + } + } + } - if (av.getWrapAlignment()) - { - height = ( (av.alignment.getWidth() / av.getChunkWidth()) + 1) * - av.chunkHeight; - width = seqPanel.getWidth() + idPanel.getWidth(); + } + } + if(text.length()>1) + { + text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">"); + out.println(text.toString()); + } + } + } + out.println("
"); + out.close(); } + catch (Exception ex) + { + ex.printStackTrace(); + } + } ///////////END OF IMAGE MAP + } - if (av.getShowAnnotation()) - { - height += annotationPanel.getPreferredSize().height; - } + int getWrappedHeight() + { + int seqPanelWidth = seqPanel.seqCanvas.getWidth(); - try - { + //If headless, seqPanel will have 0 width + if (System.getProperty("java.awt.headless") != null + && System.getProperty("java.awt.headless").equals("true")) + { + seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth(); + } - FileOutputStream out = new FileOutputStream(pngFile); + int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth( + seqPanelWidth + ); - BufferedImage bi = new BufferedImage(width, height, - BufferedImage.TYPE_INT_RGB); - Graphics2D png = (Graphics2D) bi.getGraphics(); + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + hgap += av.charHeight; - png.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + int annotationHeight = 0; + if (av.showAnnotation) + { + annotationHeight = annotationPanel.adjustPanelHeight(); + } - if (av.getWrapAlignment()) - { - printWrappedAlignment(png, width, height, 0); - } - else - { - printUnwrapped(png, width, height, 0); - } + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + + annotationHeight; - ImageIO.write(bi, "png", out); - out.close(); - } - catch (OutOfMemoryError err) - { - System.out.println("########################\n" - + "OUT OF MEMORY " + pngFile + "\n" - + "########################"); - - JOptionPane.showInternalMessageDialog(Desktop.desktop, - "Out of memory creating PNG!!" - + - "\nSee help files for increasing Java Virtual Machine memory." - , "Out of memory", - JOptionPane.WARNING_MESSAGE); - System.out.println("Create PNG: " + err); - System.gc(); + int maxwidth = av.alignment.getWidth(); + if (av.hasHiddenColumns) + maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } -} + int height = ( (maxwidth / chunkWidth) + 1) * cHeight; -/** - * DOCUMENT ME! - * - * @author $author$ - * @version $Revision$ - */ -class Preview extends JFrame -{ + return height; + } + + /** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ + class Preview + extends JFrame + { /** * Creates a new Preview object. * @@ -1061,25 +1163,25 @@ class Preview extends JFrame */ 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(); + setResizable(true); + setSize(image.getWidth(this), image.getHeight(this)); + setVisible(true); + getContentPane().setLayout(new BorderLayout()); + getContentPane().add(new PreviewPanel(image), BorderLayout.CENTER); + validate(); + repaint(); } -} - - -/** - * DOCUMENT ME! - * - * @author $author$ - * @version $Revision$ - */ -class PreviewPanel extends JPanel -{ + } + + /** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ + class PreviewPanel + extends JPanel + { Image image; /** @@ -1089,7 +1191,7 @@ class PreviewPanel extends JPanel */ public PreviewPanel(Image image) { - this.image = image; + this.image = image; } /** @@ -1099,13 +1201,14 @@ class PreviewPanel extends JPanel */ public void paintComponent(Graphics g) { - if (image != null) - { - g.drawImage(image, 0, 0, this); - } - else - { - System.out.println("DEBUG:image is null"); - } + if (image != null) + { + g.drawImage(image, 0, 0, this); + } + else + { + System.out.println("DEBUG:image is null"); + } } + } }