make eps, png files, filefilter added
authoramwaterhouse <Andrew Waterhouse>
Fri, 18 Mar 2005 16:11:37 +0000 (16:11 +0000)
committeramwaterhouse <Andrew Waterhouse>
Fri, 18 Mar 2005 16:11:37 +0000 (16:11 +0000)
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignmentPanel.java

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