From 4a15b6373466156a24c74ec977c4c6ef1a74f213 Mon Sep 17 00:00:00 2001 From: kjvdheide Date: Fri, 15 Dec 2017 20:00:30 +0000 Subject: [PATCH] JAL-2852 EPS saving code ported from TreePanel to Aptx. --- src/jalview/ext/archaeopteryx/AptxFrame.java | 76 ++++++++++++++++++++- src/jalview/ext/archaeopteryx/AptxTreePanel.java | 20 ++++++ src/jalview/ext/treeviewer/ExternalTreePanel.java | 8 +++ 3 files changed, 103 insertions(+), 1 deletion(-) diff --git a/src/jalview/ext/archaeopteryx/AptxFrame.java b/src/jalview/ext/archaeopteryx/AptxFrame.java index c105c25..e7a1517 100644 --- a/src/jalview/ext/archaeopteryx/AptxFrame.java +++ b/src/jalview/ext/archaeopteryx/AptxFrame.java @@ -1,10 +1,16 @@ package jalview.ext.archaeopteryx; +import jalview.bin.Cache; import jalview.ext.treeviewer.ExternalTreeControlsI; import jalview.ext.treeviewer.ExternalTreeFrame; import jalview.ext.treeviewer.ExternalTreeI; import jalview.ext.treeviewer.ExternalTreePanel; import jalview.gui.Desktop; +import jalview.gui.EPSOptions; +import jalview.io.JalviewFileChooser; +import jalview.io.JalviewFileView; +import jalview.util.ImageMaker; +import jalview.util.MessageManager; import java.awt.Component; import java.awt.Container; @@ -15,6 +21,7 @@ import java.awt.Image; import java.awt.MenuComponent; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.FileOutputStream; import javax.accessibility.AccessibleContext; import javax.swing.JLayeredPane; @@ -26,6 +33,7 @@ import javax.swing.JSeparator; import javax.swing.event.InternalFrameListener; import org.forester.archaeopteryx.MainFrame; +import org.jibble.epsgraphics.EpsGraphics2D; public class AptxFrame implements ExternalTreeFrame { @@ -98,7 +106,7 @@ public class AptxFrame implements ExternalTreeFrame @Override public void actionPerformed(ActionEvent e) { - // TODO Auto-generated method stub + epsTree_actionPerformed(e); } @@ -146,6 +154,72 @@ public class AptxFrame implements ExternalTreeFrame aptxFrame.validate(); } + 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 = getTreePanel().getWidth(); + int height = getTreePanel().getHeight(); + + try + { + JalviewFileChooser chooser = new JalviewFileChooser( + ImageMaker.EPS_EXTENSION, ImageMaker.EPS_EXTENSION); + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle( + MessageManager.getString("label.create_eps_from_tree")); + chooser.setToolTipText(MessageManager.getString("action.save")); + + int value = chooser.showSaveDialog(aptxFrame); + + if (value != JalviewFileChooser.APPROVE_OPTION) + { + return; + } + + 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); + + getTreePanel().paintToFile(pg, width, height); + + pg.flush(); + pg.close(); + } catch (Exception ex) + { + ex.printStackTrace(); + } + } @Override public ExternalTreePanel getTreePanel() { diff --git a/src/jalview/ext/archaeopteryx/AptxTreePanel.java b/src/jalview/ext/archaeopteryx/AptxTreePanel.java index d8a57d0..620d95b 100644 --- a/src/jalview/ext/archaeopteryx/AptxTreePanel.java +++ b/src/jalview/ext/archaeopteryx/AptxTreePanel.java @@ -7,6 +7,7 @@ import jalview.gui.PaintRefresher; import java.awt.Event; import java.awt.Font; +import java.awt.Graphics2D; import java.awt.MenuComponent; import java.awt.event.MouseListener; import java.io.File; @@ -150,4 +151,23 @@ public class AptxTreePanel implements ExternalTreePanel } } + + @Override + public int getWidth() + { + return treeView.getWidth(); + } + + @Override + public int getHeight() + { + return treeView.getHeight(); + } + + @Override + public void paintToFile(Graphics2D pg, int width, int height) + { + treeView.paintFile(pg, false, width, height, 0, 0); + + } } diff --git a/src/jalview/ext/treeviewer/ExternalTreePanel.java b/src/jalview/ext/treeviewer/ExternalTreePanel.java index ceb0e10..5197b1c 100644 --- a/src/jalview/ext/treeviewer/ExternalTreePanel.java +++ b/src/jalview/ext/treeviewer/ExternalTreePanel.java @@ -1,5 +1,6 @@ package jalview.ext.treeviewer; +import java.awt.Graphics2D; import java.awt.MenuContainer; import java.awt.event.MouseListener; import java.io.File; @@ -10,6 +11,7 @@ import javax.accessibility.Accessible; public interface ExternalTreePanel extends Accessible, MenuContainer { + public abstract void setTreeFile(File file); public abstract File getTreeFile(); @@ -38,4 +40,10 @@ public interface ExternalTreePanel extends Accessible, MenuContainer public void notifyPaintRefresher(String newSeqSetIdentifier, boolean alignmentChanged, boolean validateSequences); + public int getWidth(); + + public int getHeight(); + + public abstract void paintToFile(Graphics2D pg, int width, int height); + } -- 1.7.10.2