From: amwaterhouse Date: Fri, 18 Mar 2005 16:11:37 +0000 (+0000) Subject: make eps, png files, filefilter added X-Git-Tag: Release_2_0~563 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c4e30ea2141be5b0622cf9cd59eac0366fa47d32;p=jalview.git make eps, png files, filefilter added --- diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index f4139c6..079f315 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -63,7 +63,22 @@ public class AlignFrame extends GAlignFrame protected void saveAs_actionPerformed(ActionEvent e) { - JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY")); + String suffix = ""; + if(e.getActionCommand().equals("FASTA")) + suffix = "fa"; + else if(e.getActionCommand().equals("MSF")) + suffix = "msf"; + else if(e.getActionCommand().equals("CLUSTAL")) + suffix = "aln"; + else if(e.getActionCommand().equals("BLC")) + suffix = "blc"; + else if(e.getActionCommand().equals("PIR")) + suffix = "pir"; + else if(e.getActionCommand().equals("PFAM")) + suffix = "pfam"; + + JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY") + , new String[]{suffix}, e.getActionCommand()+" file"); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Save Alignment to file - "+e.getActionCommand() +" format."); chooser.setToolTipText("Save"); @@ -99,12 +114,24 @@ public class AlignFrame extends GAlignFrame htmlOutput = null; } - protected void createJPG_actionPerformed(ActionEvent e) + protected void createPNG_actionPerformed(ActionEvent e) { - int height = (viewport.alignment.getWidth() / viewport.getChunkWidth() +1) * viewport.chunkHeight; int width = alignPanel.seqPanel.getWidth() + alignPanel.idPanel.getWidth(); + if(!viewport.getWrapAlignment()) + { + height = viewport.alignment.getHeight() * viewport.charHeight; + width = alignPanel.idPanel.getWidth() + viewport.alignment.getWidth() * viewport.charWidth; + } + + alignPanel.makePNG( width, height); + } + + protected void epsFile_actionPerformed(ActionEvent e) + { + int height = (viewport.alignment.getWidth() / viewport.getChunkWidth() +1) * viewport.chunkHeight; + int width = alignPanel.seqPanel.getWidth() + alignPanel.idPanel.getWidth(); if(!viewport.getWrapAlignment()) { @@ -112,7 +139,8 @@ public class AlignFrame extends GAlignFrame width = alignPanel.idPanel.getWidth() + viewport.alignment.getWidth() * viewport.charWidth; } - alignPanel.makeJPG( width, height); + alignPanel.makeEPS( width, height); + } diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index ca17c20..997966f 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -12,7 +12,8 @@ import com.sun.image.codec.jpeg.*; import java.io.*; import java.awt.image.*; -import gnu.jpdf.*; +import org.jibble.epsgraphics.*; +import javax.imageio.*; public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListener, Printable @@ -44,8 +45,10 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene IdwidthAdjuster iap = new IdwidthAdjuster(this); idSpaceFillerPanel1.add(iap, BorderLayout.CENTER); - idPanel.idCanvas.setPreferredSize(calculateIdWidth()); - hscrollFillerPanel.setPreferredSize(calculateIdWidth()); + Dimension d = calculateIdWidth(); + d.setSize( d.width+4, d.height); + idPanel.idCanvas.setPreferredSize( d ); + hscrollFillerPanel.setPreferredSize( d ); scalePanelHolder.add(scalePanel, BorderLayout.CENTER); scorePanelHolder.add(scorePanel, BorderLayout.CENTER); @@ -187,8 +190,8 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene hscroll.setVisible(!wrap); - // idSpaceFillerPanel.setVisible(!wrap); - // idWidthAdjusterPanel.setVisible(!wrap); + idSpaceFillerPanel.setVisible(!wrap); + idSpaceFillerPanel1.setVisible(!wrap); RefreshPanels(); @@ -396,10 +399,10 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene //////////////// //draw Scale - pg.translate(idWidth,0); + pg.translate(30,0); scalePanel.drawScale(pg, startRes, endRes, pwidth-idWidth); - pg.translate(-idWidth, 30); + pg.translate(-30, 30); //////////////// // Draw the ids Color currentColor=null; @@ -424,7 +427,10 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene pg.setColor(currentTextColor); - String string = av.getAlignment().getSequenceAt(i).getDisplayId(); + String string = av.getAlignment().getSequenceAt(i).getName(); + if(av.getShowFullId()) + string = av.getAlignment().getSequenceAt(i).getDisplayId(); + pg.drawString(string, 0, jalview.analysis.AlignmentUtil.getPixelHeight (startSeq, i, av.getCharHeight()) + av.getCharHeight() - (av.getCharHeight() / 5)); } @@ -477,7 +483,11 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene for (int i = 0; i < endy; i++) { SequenceI s = da.getSequenceAt(i); - pg.drawString(s.getDisplayId(), 0, + String string = s.getName(); + if (av.getShowFullId()) + string = s.getDisplayId(); + + pg.drawString(string, 0, AlignmentUtil.getPixelHeight(0, i, av.charHeight) + ypos + av.charHeight - (av.charHeight / 5)); } @@ -492,48 +502,72 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene } - public void makeJPG(int width, int height) + + public void makeEPS(int width, int height) { try { + jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(jalview.bin.Cache.getProperty( + "LAST_DIRECTORY"), new String[]{"eps"}, "Encapsulated Postscript"); + chooser.setFileView(new jalview.io.JalviewFileView()); + chooser.setDialogTitle("Create EPS file from alignment"); + chooser.setToolTipText("Save"); - BufferedImage bi = new BufferedImage(width, height, - BufferedImage.TYPE_INT_RGB); - Graphics pg = bi.getGraphics(); + int value = chooser.showSaveDialog(this); + if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) + return; + + jalview.bin.Cache.setProperty("LAST_DIRECTORY",chooser.getSelectedFile().getPath()); + FileOutputStream out = new FileOutputStream(chooser.getSelectedFile()); + EpsGraphics2D pg = new EpsGraphics2D("Example", out, 0, 0, width, height); - try - { if (av.getWrapAlignment()) printWrappedAlignment(pg, width, height, 0); else printUnwrapped(pg, width, height, 0); - } - catch (Exception ex) - {} + + pg.flush(); + pg.close(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + public void makePNG(int width, int height) + { + try + { jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(jalview.bin.Cache.getProperty( - "LAST_DIRECTORY")); + "LAST_DIRECTORY"), new String[]{"png"}, "Portable network graphics"); chooser.setFileView(new jalview.io.JalviewFileView()); - chooser.setDialogTitle("Create JPG image from alignment"); + chooser.setDialogTitle("Create EPS file from alignment"); chooser.setToolTipText("Save"); int value = chooser.showSaveDialog(this); - if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION) - { + if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) + return; - FileOutputStream out = new FileOutputStream(chooser.getSelectedFile()); - JPEGImageEncoder jie = JPEGCodec.createJPEGEncoder(out); - JPEGEncodeParam param = JPEGCodec.getDefaultJPEGEncodeParam(bi); - param.setQuality(1.0f, true); + jalview.bin.Cache.setProperty("LAST_DIRECTORY",chooser.getSelectedFile().getPath()); + FileOutputStream out = new FileOutputStream(chooser.getSelectedFile()); - jie.encode(bi, param); - out.close(); - } + BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + Graphics png = bi.getGraphics(); + + if (av.getWrapAlignment()) + printWrappedAlignment(png, width, height, 0); + else + printUnwrapped(png, width, height, 0); + + ImageIO.write(bi, "png", out); + out.close(); } - catch (IOException ex) + catch (Exception ex) { - System.out.println("ex Writing image "); + ex.printStackTrace(); } }