From: amwaterhouse Date: Fri, 11 Nov 2005 18:17:29 +0000 (+0000) Subject: PNG and EPS in ImageMaker X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=6ba4f96a2593b209c3fde5fb65556fd368d791d4;p=jalview.git PNG and EPS in ImageMaker --- diff --git a/src/MCview/PDBViewer.java b/src/MCview/PDBViewer.java index 49c1b11..95d4b35 100755 --- a/src/MCview/PDBViewer.java +++ b/src/MCview/PDBViewer.java @@ -7,13 +7,6 @@ import jalview.gui.*; import jalview.io.EBIFetchClient; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; -import java.io.FileOutputStream; -import org.jibble.epsgraphics.EpsGraphics2D; -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.RenderingHints; public class PDBViewer extends JInternalFrame implements Runnable { @@ -41,11 +34,15 @@ public class PDBViewer extends JInternalFrame implements Runnable pdbcanvas = new PDBCanvas(seqcanvas, seq); setContentPane(pdbcanvas); - Desktop.addInternalFrame(this, - sequence.getName() + ":" + pdb.getId() - + " Method: " + pdb.getProperty().get("method") - + " Chain:" + pdb.getProperty().get("chains"), - 400, 400); + StringBuffer title = new StringBuffer(sequence.getName() + ":" + pdb.getId()); + if(pdb.getProperty()!=null) + { + title.append( " Method: " ); + title.append(pdb.getProperty().get("method")); + title.append( " Chain:" ); + title.append( pdb.getProperty().get("chains")); + } + Desktop.addInternalFrame(this,title.toString(),400, 400); Thread worker = new Thread(this); worker.start(); @@ -215,126 +212,52 @@ public class PDBViewer extends JInternalFrame implements Runnable JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem(); JCheckBoxMenuItem molecule = new JCheckBoxMenuItem(); - public void png_actionPerformed(ActionEvent e) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void eps_actionPerformed(ActionEvent e) { - int width = pdbcanvas.getWidth(); - int height = pdbcanvas.getHeight(); - - 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 PNG Image of Molecule"); - chooser.setToolTipText("Save"); - - int value = chooser.showSaveDialog(this); - - if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) - { - return; - } - - jalview.bin.Cache.setProperty("LAST_DIRECTORY", - chooser.getSelectedFile().getParent()); - - FileOutputStream out = new FileOutputStream(chooser.getSelectedFile()); - - BufferedImage bi = new BufferedImage(width, height, - BufferedImage.TYPE_INT_RGB); - Graphics png = bi.getGraphics(); - Graphics2D ig2 = (Graphics2D) png; - ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - - - pdbcanvas.drawAll(png, width, height); - - ImageIO.write(bi, "png", out); - out.close(); - } - catch (Exception ex) - { - ex.printStackTrace(); - } + makePDBImage(jalview.util.ImageMaker.EPS); } - public void eps_actionPerformed(ActionEvent e) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void png_actionPerformed(ActionEvent e) { - boolean accurateText = true; - - String renderStyle = jalview.bin.Cache.getDefault("EPS_RENDERING", - "Prompt each time"); - - // 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(); - - if (renderStyle==null || eps.cancelled) - return; - + makePDBImage(jalview.util.ImageMaker.PNG); + } - } + void makePDBImage(int type) + { + int width = pdbcanvas.getWidth(); + int height = pdbcanvas.getHeight(); - if (renderStyle.equalsIgnoreCase("text")) + jalview.util.ImageMaker im; + + if (type == jalview.util.ImageMaker.PNG) + im = new jalview.util.ImageMaker(this, + jalview.util.ImageMaker.PNG, + "Make PNG image from view", + width, height, + null, null); + else + im = new jalview.util.ImageMaker(this, + jalview.util.ImageMaker.EPS, + "Make EPS file from view", + width, height, + null, this.getTitle()); + + if (im.getGraphics() != null) { - accurateText = false; + pdbcanvas.drawAll(im.getGraphics(), width, height); + im.writeImage(); } - - int width = getWidth(); - int height = getHeight(); - - try - { - 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 tree"); - chooser.setToolTipText("Save"); - - int value = chooser.showSaveDialog(this); - - if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) - { - return; - } - - jalview.bin.Cache.setProperty("LAST_DIRECTORY", - chooser.getSelectedFile().getParent()); - - FileOutputStream out = new FileOutputStream(chooser.getSelectedFile()); - EpsGraphics2D pg = new EpsGraphics2D("Tree", out, 0, 0, width, - height); - Graphics2D ig2 = (Graphics2D) pg; - ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - - - pg.setAccurateTextMode(accurateText); - - pdbcanvas.drawAll(pg, width, height); - - pg.flush(); - pg.close(); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } - public void charge_actionPerformed(ActionEvent e) { clearButtonGroup(); diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index fc4c688..ecdf741 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -24,17 +24,12 @@ 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.*; @@ -47,1072 +42,939 @@ import javax.swing.*; 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) + 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); + + 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); + + annotationPanel.adjustPanelHeight(); + annotationSpaceFillerHolder.setPreferredSize(annotationPanel. + getPreferredSize()); + annotationScroller.setPreferredSize(annotationPanel. + getPreferredSize()); + setAnnotationVisible(av.getShowAnnotation()); + + hscroll.addAdjustmentListener(this); + vscroll.addAdjustmentListener(this); + + af.addKeyListener(new KeyAdapter() { - alignFrame = af; - this.av = av; - seqPanel = new SeqPanel(av, this); - idPanel = new IdPanel(av, this); + public void keyPressed(KeyEvent evt) + { + switch (evt.getKeyCode()) + { + case 27: // escape key + av.setSelectionGroup(null); + repaint(); - scalePanel = new ScalePanel(av, this); + break; - idPanelHolder.add(idPanel, BorderLayout.CENTER); - idwidthAdjuster = new IdwidthAdjuster(this); - idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER); + case KeyEvent.VK_DOWN: + alignFrame.moveSelectedSequences(false); - annotationPanel = new AnnotationPanel(this); - alabels = new AnnotationLabels(this); + break; - annotationSpaceFillerHolder.setPreferredSize(annotationPanel.getPreferredSize()); - annotationScroller.setPreferredSize(annotationPanel.getPreferredSize()); - annotationScroller.setViewportView(annotationPanel); - annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER); + case KeyEvent.VK_UP: + alignFrame.moveSelectedSequences(true); - fontChanged(); + break; - scalePanelHolder.add(scalePanel, BorderLayout.CENTER); - seqPanelHolder.add(seqPanel, BorderLayout.CENTER); + case KeyEvent.VK_BACK_SPACE: + case KeyEvent.VK_DELETE: + alignFrame.cut_actionPerformed(null); + break; - setScrollValues(0, 0); + case KeyEvent.VK_P: + seqPanel.seqCanvas.increaseAARatio(); + break; + case KeyEvent.VK_L: + seqPanel.seqCanvas.decreaseAARation(); + break; + } + } + }); + } + + /** + * 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 (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()); + } - annotationPanel.adjustPanelHeight(); - annotationSpaceFillerHolder.setPreferredSize(annotationPanel.getPreferredSize()); - annotationScroller.setPreferredSize(annotationPanel. - getPreferredSize()); - setAnnotationVisible(av.getShowAnnotation()); + if (overviewPanel != null) + overviewPanel.setBoxPosition(); + repaint(); + } - hscroll.addAdjustmentListener(this); - vscroll.addAdjustmentListener(this); + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Dimension calculateIdWidth() + { + Container c = new Container(); - af.addKeyListener(new KeyAdapter() - { - public void keyPressed(KeyEvent evt) - { - switch (evt.getKeyCode()) - { - case 27: // escape key - av.setSelectionGroup(null); - repaint(); - - break; - - case KeyEvent.VK_DOWN: - alignFrame.moveSelectedSequences(false); - - break; - - case KeyEvent.VK_UP: - alignFrame.moveSelectedSequences(true); - - break; - - case KeyEvent.VK_BACK_SPACE: - case KeyEvent.VK_DELETE: - alignFrame.cut_actionPerformed(null); - break; - - case KeyEvent.VK_P: - seqPanel.seqCanvas.increaseAARatio(); - break; - case KeyEvent.VK_L: - seqPanel.seqCanvas.decreaseAARation(); - break; - } - } - }); - } + FontMetrics fm = c.getFontMetrics(av.font); + AlignmentI al = av.getAlignment(); + int i = 0; + int idWidth = 0; + String id; - /** - * DOCUMENT ME! - */ - public void fontChanged() + while ( (i < al.getHeight()) && (al.getSequenceAt(i) != null)) { - // 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())); + SequenceI s = al.getSequenceAt(i); - 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 (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()); - } + id = s.getDisplayId(av.getShowDBPrefix(), av.getShowJVSuffix()); - 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); - - id = s.getDisplayId(av.getShowDBPrefix(), av.getShowJVSuffix()); - - 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()); + i++; + } + } - while (i < al.getAlignmentAnnotation().length) - { - String label = al.getAlignmentAnnotation()[i].label; + return new Dimension(idWidth, 12); + } - if (fm.stringWidth(label) > idWidth) - { - idWidth = fm.stringWidth(label); - } + /** + * DOCUMENT ME! + * + * @param results DOCUMENT ME! + */ + public void highlightSearchResults(int[] results) + { + seqPanel.seqCanvas.highlightSearchResults(results); - i++; - } - } + // do we need to scroll the panel? + if (results != null) + { + SequenceI seq = av.alignment.getSequenceAt(results[0]); + int start = seq.findIndex(results[1]) - 1; + int end = seq.findIndex(results[2]) - 1; - return new Dimension(idWidth, 12); + if ( (av.getStartRes() > start) || (av.getEndRes() < end) || + ( (av.getStartSeq() > results[0]) || + (av.getEndSeq() < results[0]))) + { + setScrollValues(start, results[0]); + } } - - /** - * DOCUMENT ME! - * - * @param results DOCUMENT ME! - */ - public void highlightSearchResults(int[] results) + } + + /** + * 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) { - seqPanel.seqCanvas.highlightSearchResults(results); - - // do we need to scroll the panel? - if (results != null) - { - 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]); - } - } + annotationSpaceFillerHolder.setVisible(b); + annotationScroller.setVisible(b); } - - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public OverviewPanel getOverviewPanel() + 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) { - return overviewPanel; + annotationScroller.setVisible(false); + annotationSpaceFillerHolder.setVisible(false); } - - /** - * DOCUMENT ME! - * - * @param op DOCUMENT ME! - */ - public void setOverviewPanel(OverviewPanel op) + else if (av.showAnnotation) { - overviewPanel = op; + annotationScroller.setVisible(true); + annotationSpaceFillerHolder.setVisible(true); } - /** - * DOCUMENT ME! - * - * @param b DOCUMENT ME! - */ - public void setAnnotationVisible(boolean b) + idSpaceFillerPanel1.setVisible(!wrap); + + repaint(); + } + + // return value is true if the scroll is valid + public boolean scrollUp(boolean up) + { + if (up) { - if (!av.wrapAlignment) + if (vscroll.getValue() < 1) { - annotationSpaceFillerHolder.setVisible(b); - annotationScroller.setVisible(b); + return false; } - 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(); + fastPaint = false; + vscroll.setValue(vscroll.getValue() - 1); } - - - // return value is true if the scroll is valid - public boolean scrollUp(boolean up) + else { - 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; + if ( (vextent + vscroll.getValue()) >= av.getAlignment().getHeight()) + { + 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) + fastPaint = true; + + return true; + } + + /** + * DOCUMENT ME! + * + * @param right DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public boolean scrollRight(boolean right) + { + if (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; + if (hscroll.getValue() < 1) + { + 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) + else { - av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - - 1); - - hextent = seqPanel.seqCanvas.getWidth() / av.charWidth; - vextent = seqPanel.seqCanvas.getHeight() / av.charHeight; - - if (hextent > av.alignment.getWidth()) - { - hextent = av.alignment.getWidth(); - } + if ( (hextent + hscroll.getValue()) >= av.getAlignment().getWidth()) + { + return false; + } - if (vextent > av.alignment.getHeight()) - { - vextent = av.alignment.getHeight(); - } + fastPaint = false; + hscroll.setValue(hscroll.getValue() + 1); + } - if ((hextent + x) > av.getAlignment().getWidth()) - { - x = av.getAlignment().getWidth() - hextent; - } + fastPaint = true; - if ((vextent + y) > av.getAlignment().getHeight()) - { - y = av.getAlignment().getHeight() - vextent; - } + return true; + } - if (y < 0) - { - y = 0; - } + /** + * 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); - if (x < 0) - { - x = 0; - } + hextent = seqPanel.seqCanvas.getWidth() / av.charWidth; + vextent = seqPanel.seqCanvas.getHeight() / av.charHeight; - hscroll.setValues(x, hextent, 0, av.getAlignment().getWidth()); - vscroll.setValues(y, vextent, 0, av.getAlignment().getHeight()); + if (hextent > av.alignment.getWidth()) + { + hextent = av.alignment.getWidth(); } - - /** - * DOCUMENT ME! - * - * @param evt DOCUMENT ME! - */ - public void adjustmentValueChanged(AdjustmentEvent evt) + if (vextent > av.alignment.getHeight()) { - - 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()) - { - 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 (overviewPanel != null) - { - overviewPanel.setBoxPosition(); - } - - int xShift = av.getStartRes() - oldX; - int yShift = av.getStartSeq() - oldY; - - 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); - - scalePanel.repaint(); - - if (av.getShowAnnotation()) - { - annotationPanel.fastPaint(xShift); - } - } + vextent = av.alignment.getHeight(); } - /** - * DOCUMENT ME! - * - * @param g DOCUMENT ME! - */ - public void paintComponent(Graphics g) + if ( (hextent + x) > av.getAlignment().getWidth()) { - invalidate(); - - Dimension d = idPanel.idCanvas.getPreferredSize(); - idPanelHolder.setPreferredSize(d); - hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12)); - validate(); - - 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()); - } + x = av.getAlignment().getWidth() - hextent; } - /** - * 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 ( (vextent + y) > av.getAlignment().getHeight()) { - 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); - } + y = av.getAlignment().getHeight() - vextent; } - /** - * 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 + if (y < 0) { - 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(); - - 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; + y = 0; + } - ///////////////////////////// - /// Only print these sequences and residues on this page - int endRes; + if (x < 0) + { + x = 0; + } - ///////////////////////////// - /// Only print these sequences and residues on this page - int startSeq; + hscroll.setValues(x, hextent, 0, av.getAlignment().getWidth()); + vscroll.setValues(y, vextent, 0, av.getAlignment().getHeight()); + } - ///////////////////////////// - /// Only print these sequences and residues on this page - int endSeq; - startRes = (pi % pagesWide) * totalRes; - endRes = (startRes + totalRes) - 1; + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void adjustmentValueChanged(AdjustmentEvent evt) + { - if (endRes > (av.getAlignment().getWidth() - 1)) - { - endRes = av.getAlignment().getWidth() - 1; - } + int oldX = av.getStartRes(); + int oldY = av.getStartSeq(); - startSeq = (pi / pagesWide) * totalSeq; - endSeq = startSeq + totalSeq; + if (evt.getSource() == hscroll) + { + int x = hscroll.getValue(); + av.setStartRes(x); + av.setEndRes( (x + + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1); + } - if (endSeq > av.getAlignment().getHeight()) - { - endSeq = av.getAlignment().getHeight(); - } + if (evt.getSource() == vscroll) + { + int offy = vscroll.getValue(); - int pagesHigh = ((av.alignment.getHeight() / totalSeq) + 1) * pheight; + 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 (av.showAnnotation) - { - pagesHigh += annotationPanel.adjustPanelHeight()+3; - } + if (overviewPanel != null) + { + overviewPanel.setBoxPosition(); + } - pagesHigh /= pheight; + int xShift = av.getStartRes() - oldX; + int yShift = av.getStartSeq() - oldY; - if (pi >= (pagesWide * pagesHigh)) - { - return Printable.NO_SUCH_PAGE; - } + 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); - //draw Scale - pg.translate(idWidth, 0); - scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight); - pg.translate(-idWidth, scaleHeight); + scalePanel.repaint(); - //////////////// - // Draw the ids - Color currentColor = null; - Color currentTextColor = null; + if (av.getShowAnnotation()) + { + annotationPanel.fastPaint(xShift); + } + } + } + + /** + * 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 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()); + } + } + + /** + * 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 = 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(); + + 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; + } - 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; - } + startSeq = (pi / pagesWide) * totalSeq; + endSeq = startSeq + totalSeq; - pg.setColor(currentColor); - pg.fillRect(0, (i-startSeq) * av.charHeight, idWidth, - av.getCharHeight()); + if (endSeq > av.getAlignment().getHeight()) + { + endSeq = av.getAlignment().getHeight(); + } - pg.setColor(currentTextColor); + int pagesHigh = ( (av.alignment.getHeight() / totalSeq) + 1) * pheight; - String string = av.getAlignment().getSequenceAt(i).getDisplayId - (av.getShowDBPrefix(), av.getShowJVSuffix()); + if (av.showAnnotation) + { + pagesHigh += annotationPanel.adjustPanelHeight() + 3; + } - pg.drawString(string, 0, - (((i-startSeq) * av.charHeight) + av.getCharHeight()) - - (av.getCharHeight() / 5)); - } + pagesHigh /= pheight; - // draw main sequence panel - pg.translate(idWidth, 0); - seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, - startRes, startSeq, 0); + if (pi >= (pagesWide * pagesHigh)) + { + return Printable.NO_SUCH_PAGE; + } - if (av.showAnnotation && (endSeq == av.alignment.getHeight())) - { - pg.translate(-idWidth, (endSeq - startSeq) * av.charHeight +3); - alabels.drawComponent((Graphics2D) pg, idWidth); - pg.translate(idWidth, 0); - annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes + - 1); - } + //draw Scale + pg.translate(idWidth, 0); + scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight); + pg.translate( -idWidth, scaleHeight); - return Printable.PAGE_EXISTS; - } + //////////////// + // Draw the ids + Color currentColor = null; + Color currentTextColor = null; - /** - * 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 + for (int i = startSeq; i < endSeq; i++) { - - int annotationHeight = 0; - AnnotationLabels labels = null; - if (av.showAnnotation) + if ( (av.getSelectionGroup() != null) && + av.getSelectionGroup().sequences.contains( + av.getAlignment().getSequenceAt(i))) { - annotationHeight = annotationPanel.adjustPanelHeight(); - labels = new AnnotationLabels(av); + currentColor = Color.gray; + currentTextColor = Color.black; + } + else + { + currentColor = av.getAlignment().getSequenceAt(i).getColor(); + currentTextColor = Color.black; } - int hgap = av.charHeight; - if (av.scaleAboveWrapped) - hgap += av.charHeight; - - int cHeight = av.getAlignment().getHeight() * av.charHeight - + hgap - + annotationHeight; - - - int idWidth = calculateIdWidth().width + 4; + pg.setColor(currentColor); + pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth, + av.getCharHeight()); - int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth - - idWidth); + pg.setColor(currentTextColor); - int totalHeight = cHeight * (av.alignment.getWidth() / resWidth +1); + String string = av.getAlignment().getSequenceAt(i).getDisplayId + (av.getShowDBPrefix(), av.getShowJVSuffix()); - pg.setColor(Color.white); - pg.fillRect(0, 0, pwidth, pheight); - pg.setFont(av.getFont()); + pg.drawString(string, 0, + ( ( (i - startSeq) * av.charHeight) + av.getCharHeight()) - + (av.getCharHeight() / 5)); + } + // draw main sequence panel + pg.translate(idWidth, 0); + seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, + startRes, startSeq, 0); - //////////////// - // Draw the ids - pg.setColor(Color.black); + if (av.showAnnotation && (endSeq == av.alignment.getHeight())) + { + pg.translate( -idWidth, (endSeq - startSeq) * av.charHeight + 3); + alabels.drawComponent( (Graphics2D) pg, idWidth); + pg.translate(idWidth, 0); + annotationPanel.drawComponent( (Graphics2D) pg, startRes, endRes + + 1); + } - pg.translate(0, -pi * pheight); + 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); + } - pg.setClip(0, pi * pheight, pwidth, pheight); + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + hgap += av.charHeight; - int ypos = hgap; - Font italic = new Font(av.getFont().getName(), Font.ITALIC, - av.getFont().getSize()); - pg.setFont(italic); + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + + annotationHeight; + int idWidth = calculateIdWidth().width + 4; - do - { - for (int i = 0; i < av.alignment.getHeight(); i++) - { - SequenceI s = av.alignment.getSequenceAt(i); - String string = s.getDisplayId(av.getShowDBPrefix(), av.getShowJVSuffix()); + int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth - + idWidth); - pg.drawString(string, 0, - ( (i * av.charHeight) + ypos + av.charHeight) - - (av.charHeight / 5)); - } - if (labels != null) - { - pg.translate(0, - ypos + - (av.getAlignment().getHeight() * av.charHeight)); - - pg.setFont(av.getFont()); - labels.drawComponent( pg, idWidth ); - pg.setFont(italic); - pg.translate(0, - -ypos - - (av.getAlignment().getHeight() * av.charHeight)); - } + int totalHeight = cHeight * (av.alignment.getWidth() / resWidth + 1); - ypos += cHeight; - } - while (ypos < totalHeight); + pg.setColor(Color.white); + pg.fillRect(0, 0, pwidth, pheight); + pg.setFont(av.getFont()); - pg.translate(idWidth, 0); + //////////////// + // Draw the ids + pg.setColor(Color.black); - seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0); + pg.translate(0, -pi * pheight); - if ((pi * pheight) < totalHeight) - { - return Printable.PAGE_EXISTS; + pg.setClip(0, pi * pheight, pwidth, pheight); - } - else - { - return Printable.NO_SUCH_PAGE; - } - } + int ypos = hgap; + Font italic = new Font(av.getFont().getName(), Font.ITALIC, + av.getFont().getSize()); + pg.setFont(italic); - /** - * DOCUMENT ME! - */ - public void makeEPS(File epsFile) + do { - boolean accurateText = true; - - String renderStyle = jalview.bin.Cache.getDefault("EPS_RENDERING", - "Prompt each time"); - - // 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"))) + for (int i = 0; i < av.alignment.getHeight(); i++) { - EPSOptions eps = new EPSOptions(); - renderStyle = eps.getValue(); + SequenceI s = av.alignment.getSequenceAt(i); + String string = s.getDisplayId(av.getShowDBPrefix(), av.getShowJVSuffix()); - if(eps.cancelled || renderStyle==null) - return; - - renderStyle = eps.getValue(); + pg.drawString(string, 0, + ( (i * av.charHeight) + ypos + av.charHeight) - + (av.charHeight / 5)); } - - if (renderStyle.equalsIgnoreCase("text")) + if (labels != null) { - accurateText = false; - } - - - 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); + pg.translate(0, + ypos + + (av.getAlignment().getHeight() * av.charHeight)); + pg.setFont(av.getFont()); + labels.drawComponent(pg, idWidth); + pg.setFont(italic); + pg.translate(0, + -ypos - + (av.getAlignment().getHeight() * av.charHeight)); + } - if (av.getWrapAlignment()) - { - height = getWrappedHeight(); - width = seqPanel.getWidth() + idPanel.getWidth(); - } - else if (av.getShowAnnotation()) - { - height += annotationPanel.adjustPanelHeight()+3; - } - + ypos += cHeight; + } + while (ypos < totalHeight); - try - { - FileOutputStream out = new FileOutputStream(epsFile); - EpsGraphics2D pg = new EpsGraphics2D("Example", out, 0, 0, width, - height); + pg.translate(idWidth, 0); - pg.setAccurateTextMode(accurateText); + 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 (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) - { - ex.printStackTrace(); - } } + else + { + return Printable.NO_SUCH_PAGE; + } + } + void makeAlignmentImage(int type, File file) + { + int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30; + int width = idPanel.getWidth() + (av.alignment.getWidth() * av.charWidth); - public void makePNGImageMap(File imgMapFile, String imageName) + if (av.getWrapAlignment()) { - ///////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 - + height = getWrappedHeight(); + width = seqPanel.getWidth() + idPanel.getWidth(); } - - int getWrappedHeight() + else if (av.getShowAnnotation()) { + height += annotationPanel.adjustPanelHeight() + 3; + } - int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth( - seqPanel.seqCanvas.getWidth()); - - int hgap = av.charHeight; - if (av.scaleAboveWrapped) - hgap += av.charHeight; - - int annotationHeight = 0; - if (av.showAnnotation) + 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() ); + + try + { + if (av.getWrapAlignment()) { - annotationHeight = annotationPanel.adjustPanelHeight(); + if(im.getGraphics()!=null) + printWrappedAlignment(im.getGraphics(), width, height, 0); + } + else + { + if(im.getGraphics()!=null) + printUnwrapped(im.getGraphics(), width, height, 0); } - int cHeight = av.getAlignment().getHeight() * av.charHeight - + hgap - + annotationHeight; - - - int height = ( (av.alignment.getWidth() / chunkWidth) + 1) * cHeight; - - return height; + 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(); - /** - * DOCUMENT ME! - */ - public void makePNG(File pngFile) + } + 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 = calculateIdWidth().width + 4; + FontMetrics fm = getFontMetrics(av.getFont()); + int scaleHeight = av.charHeight + fm.getDescent(); + + // Gen image map + ////////////////////////////////// + if (imgMapFile != null) { - if(pngFile==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) + PrintWriter out = new PrintWriter(new FileWriter(imgMapFile)); + out.println(jalview.io.HTMLOutput.getImageMapHTML()); + out.println("" + + ""); + + for (int s = 0; s < av.alignment.getHeight(); s++) { - return; + 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=\"#\">"); + } + } } - pngFile = chooser.getSelectedFile(); + out.println(""); + out.close(); - 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()) + catch (Exception ex) { - height = getWrappedHeight(); - width = seqPanel.getWidth() + idPanel.getWidth(); + ex.printStackTrace(); } - else if (av.getShowAnnotation()) - { - height += annotationPanel.adjustPanelHeight()+3; - } + } ///////////END OF IMAGE MAP - try - { + } - FileOutputStream out = new FileOutputStream(pngFile); + int getWrappedHeight() + { - BufferedImage bi = new BufferedImage(width, height, - BufferedImage.TYPE_INT_RGB); - Graphics2D png = (Graphics2D) bi.getGraphics(); + int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth( + seqPanel.seqCanvas.getWidth()); - png.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + hgap += av.charHeight; - if (av.getWrapAlignment()) - { - printWrappedAlignment(png, width, height, 0); - } - else - { - printUnwrapped(png, width, height, 0); - } + int annotationHeight = 0; + if (av.showAnnotation) + { + annotationHeight = annotationPanel.adjustPanelHeight(); + } - 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 cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + + annotationHeight; - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } -} + int height = ( (av.alignment.getWidth() / chunkWidth) + 1) * cHeight; + return height; + } -/** - * DOCUMENT ME! - * - * @author $author$ - * @version $Revision$ - */ -class Preview extends JFrame -{ + /** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ + class Preview + extends JFrame + { /** * Creates a new Preview object. * @@ -1120,25 +982,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; /** @@ -1148,7 +1010,7 @@ class PreviewPanel extends JPanel */ public PreviewPanel(Image image) { - this.image = image; + this.image = image; } /** @@ -1158,13 +1020,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"); + } } + } } diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java index 71891aa..e680dde 100755 --- a/src/jalview/gui/PCAPanel.java +++ b/src/jalview/gui/PCAPanel.java @@ -29,10 +29,6 @@ import java.awt.event.*; import java.util.*; import javax.swing.*; -import java.io.FileOutputStream; -import org.jibble.epsgraphics.EpsGraphics2D; -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; import java.awt.print.*; @@ -313,7 +309,6 @@ public class PCAPanel extends GPCAPanel implements Runnable - /** * DOCUMENT ME! * @@ -321,79 +316,7 @@ public class PCAPanel extends GPCAPanel implements Runnable */ public void eps_actionPerformed(ActionEvent e) { - boolean accurateText = true; - - String renderStyle = jalview.bin.Cache.getDefault("EPS_RENDERING", - "Prompt each time"); - - // 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(); - - if (renderStyle == null || eps.cancelled) - return; - - } - - if (renderStyle.equalsIgnoreCase("text")) - { - accurateText = false; - } - - int width = rc.getWidth(); - int height = rc.getHeight(); - - try - { - 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 PCA"); - chooser.setToolTipText("Save"); - - int value = chooser.showSaveDialog(this); - - if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) - { - return; - } - - jalview.bin.Cache.setProperty("LAST_DIRECTORY", - chooser.getSelectedFile().getParent()); - - FileOutputStream out = new FileOutputStream(chooser.getSelectedFile()); - EpsGraphics2D pg = new EpsGraphics2D("PCA", out, 0, 0, width, - height); - - pg.setAccurateTextMode(accurateText); - - rc.drawBackground(pg, rc.bgColour); - rc.drawScene(pg); - - if (rc.drawAxes == true) - { - rc.drawAxes(pg); - } - - - pg.flush(); - pg.close(); - } - catch (Exception ex) - { - ex.printStackTrace(); - } + makePCAImage(jalview.util.ImageMaker.EPS); } /** @@ -403,48 +326,38 @@ public class PCAPanel extends GPCAPanel implements Runnable */ public void png_actionPerformed(ActionEvent e) { + makePCAImage(jalview.util.ImageMaker.PNG); + } + + void makePCAImage(int type) + { int width = rc.getWidth(); int height = rc.getHeight(); - 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 PNG image from PCA"); - chooser.setToolTipText("Save"); - - int value = chooser.showSaveDialog(this); + jalview.util.ImageMaker im; - if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) - { - return; - } - - jalview.bin.Cache.setProperty("LAST_DIRECTORY", - chooser.getSelectedFile().getParent()); - - FileOutputStream out = new FileOutputStream(chooser.getSelectedFile()); - - BufferedImage bi = new BufferedImage(width, height, - BufferedImage.TYPE_INT_RGB); - Graphics big = bi.getGraphics(); - - big.drawImage(rc.img,0,0,this); - - ImageIO.write(bi, "png", out); - out.close(); - } - catch (Exception ex) - { - ex.printStackTrace(); - } + if(type == jalview.util.ImageMaker.PNG) + im = new jalview.util.ImageMaker(this, + jalview.util.ImageMaker.PNG, + "Make PNG image from PCA", + width, height, + null, null); + else + im = new jalview.util.ImageMaker(this, + jalview.util.ImageMaker.EPS, + "Make EPS file from PCA", + width, height, + null, this.getTitle()); + + if(im.getGraphics()!=null) + { + rc.drawBackground(im.getGraphics(), Color.black); + rc.drawScene(im.getGraphics()); + if (rc.drawAxes == true) + { + rc.drawAxes(im.getGraphics()); + } + im.writeImage(); + } } - } diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java index 7677cf8..1c70c24 100755 --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@ -26,18 +26,14 @@ import jalview.io.*; import jalview.jbgui.*; -import org.jibble.epsgraphics.*; import java.awt.*; import java.awt.event.*; -import java.awt.image.*; import java.io.*; import java.util.*; -import javax.imageio.*; - import java.beans.PropertyChangeEvent; @@ -391,70 +387,7 @@ public class TreePanel extends GTreePanel */ public void epsTree_actionPerformed(ActionEvent e) { - boolean accurateText = true; - - String renderStyle = jalview.bin.Cache.getDefault("EPS_RENDERING", - "Prompt each time"); - - // 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(); - - if (renderStyle==null || eps.cancelled) - return; - - - } - - if (renderStyle.equalsIgnoreCase("text")) - { - accurateText = false; - } - - int width = treeCanvas.getWidth(); - int height = treeCanvas.getHeight(); - - try - { - 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 tree"); - chooser.setToolTipText("Save"); - - int value = chooser.showSaveDialog(this); - - if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) - { - return; - } - - jalview.bin.Cache.setProperty("LAST_DIRECTORY", - chooser.getSelectedFile().getParent()); - - FileOutputStream out = new FileOutputStream(chooser.getSelectedFile()); - EpsGraphics2D pg = new EpsGraphics2D("Tree", out, 0, 0, width, - height); - - pg.setAccurateTextMode(accurateText); - - treeCanvas.draw(pg, width, height); - - pg.flush(); - pg.close(); - } - catch (Exception ex) - { - ex.printStackTrace(); - } + makeTreeImage(jalview.util.ImageMaker.EPS); } /** @@ -464,44 +397,34 @@ public class TreePanel extends GTreePanel */ public void pngTree_actionPerformed(ActionEvent e) { - int width = treeCanvas.getWidth(); - int height = treeCanvas.getHeight(); - - 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 PNG image from tree"); - chooser.setToolTipText("Save"); - - int value = chooser.showSaveDialog(this); - - if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) - { - return; - } - - jalview.bin.Cache.setProperty("LAST_DIRECTORY", - chooser.getSelectedFile().getParent()); + makeTreeImage(jalview.util.ImageMaker.PNG); + } - FileOutputStream out = new FileOutputStream(chooser.getSelectedFile()); + void makeTreeImage(int type) + { + int width = treeCanvas.getWidth(); + int height = treeCanvas.getHeight(); - BufferedImage bi = new BufferedImage(width, height, - BufferedImage.TYPE_INT_RGB); - Graphics png = bi.getGraphics(); + jalview.util.ImageMaker im; - treeCanvas.draw(png, width, height); + if(type == jalview.util.ImageMaker.PNG) + im = new jalview.util.ImageMaker(this, + jalview.util.ImageMaker.PNG, + "Make PNG image from tree", + width, height, + null, null); + else + im = new jalview.util.ImageMaker(this, + jalview.util.ImageMaker.EPS, + "Make EPS file from tree", + width, height, + null, this.getTitle()); - ImageIO.write(bi, "png", out); - out.close(); - } - catch (Exception ex) - { - ex.printStackTrace(); - } + if(im.getGraphics()!=null) + { + treeCanvas.draw(im.getGraphics(), width, height); + im.writeImage(); + } } + } diff --git a/src/jalview/util/ImageMaker.java b/src/jalview/util/ImageMaker.java new file mode 100755 index 0000000..02427f2 --- /dev/null +++ b/src/jalview/util/ImageMaker.java @@ -0,0 +1,165 @@ +package jalview.util; + +import java.awt.event.ActionEvent; +import java.awt.RenderingHints; +import javax.imageio.ImageIO; +import org.jibble.epsgraphics.EpsGraphics2D; +import jalview.gui.EPSOptions; +import java.awt.Graphics2D; +import java.io.*; +import java.awt.image.BufferedImage; +import java.awt.Graphics; +import jalview.io.*; +import java.awt.*; + + +public class ImageMaker +{ + public static final int EPS = 0; + public static final int PNG = 1; + int type = -1; + + EpsGraphics2D pg; + Graphics graphics; + FileOutputStream out; + BufferedImage bi; + + public ImageMaker(Component parent, int type, String title, + int width, int height, File file, String EPStitle) + { + this.type = type; + + if (file == null) + { + JalviewFileChooser chooser; + chooser = type == EPS ? getEPSChooser() : getPNGChooser(); + + chooser.setFileView(new jalview.io.JalviewFileView()); + chooser.setDialogTitle(title); + chooser.setToolTipText("Save"); + + int value = chooser.showSaveDialog(parent); + + if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION) + { + jalview.bin.Cache.setProperty("LAST_DIRECTORY", + chooser.getSelectedFile().getParent()); + + file = chooser.getSelectedFile(); + } + } + + try + { + out = new FileOutputStream(file); + + if (type == EPS) + setupEPS(width, height, EPStitle); + else + setupPNG(width, height); + } + catch (Exception ex) + { + System.out.println("Error creating " + (type == EPS ? "EPS" : "PNG") + + " file."); + } + } + + public Graphics getGraphics() + { + return graphics; + } + + + void setupPNG(int width, int height) + { + bi = new BufferedImage(width, height, + BufferedImage.TYPE_INT_RGB); + graphics = bi.getGraphics(); + Graphics2D ig2 = (Graphics2D) graphics; + ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + } + + public void writeImage() + { + try{ + switch(type) + { + case EPS: + pg.flush(); + pg.close(); + break; + case PNG: + ImageIO.write(bi, "png", out); + out.close(); + break; + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + void setupEPS(int width, int height, String title) + { + boolean accurateText = true; + + String renderStyle = jalview.bin.Cache.getDefault("EPS_RENDERING", + "Prompt each time"); + + // 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(); + + if (renderStyle == null || eps.cancelled) + return; + } + + if (renderStyle.equalsIgnoreCase("text")) + { + accurateText = false; + } + + try { + pg = new EpsGraphics2D(title, out, 0, 0, width, + height); + Graphics2D ig2 = (Graphics2D) pg; + ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + + pg.setAccurateTextMode(accurateText); + + graphics = pg; + } + catch (Exception ex) { } + } + + + JalviewFileChooser getPNGChooser() + { + return new jalview.io.JalviewFileChooser(jalview.bin.Cache.getProperty( + "LAST_DIRECTORY"), new String[] + {"png"}, + new String[] + {"Portable network graphics"}, + "Portable network graphics"); + } + + JalviewFileChooser getEPSChooser() + { + return new jalview.io.JalviewFileChooser(jalview.bin.Cache.getProperty( + "LAST_DIRECTORY"), new String[] + {"eps"}, + new String[] + {"Encapsulated Postscript"}, + "Encapsulated Postscript"); + } +}