From: Charles Ofoegbu Date: Tue, 25 Nov 2014 17:37:25 +0000 (+0000) Subject: JAL-1469 Added SVGOptions.java for lineart/text rendering rendering of svg X-Git-Tag: Jalview_2_9~146^2~1 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=936d4dc095734df2b1e9f3bf9e0bd29b9c86434c;hp=f528f6681f3de9d41fbe0ec92e44c898d750a01d JAL-1469 Added SVGOptions.java for lineart/text rendering rendering of svg --- diff --git a/.externalToolBuilders/Jalview Release indices [Builder].launch b/.externalToolBuilders/Jalview Release indices [Builder].launch index 4c0c7dd..9d81cc8 100644 --- a/.externalToolBuilders/Jalview Release indices [Builder].launch +++ b/.externalToolBuilders/Jalview Release indices [Builder].launch @@ -14,6 +14,7 @@ + diff --git a/src/jalview/gui/SVGOptions.java b/src/jalview/gui/SVGOptions.java new file mode 100644 index 0000000..b5e194b --- /dev/null +++ b/src/jalview/gui/SVGOptions.java @@ -0,0 +1,163 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) + * Copyright (C) 2014 The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.gui; + +import jalview.util.MessageManager; + +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JRadioButton; + +public class SVGOptions extends JPanel +{ + JDialog dialog; + + public boolean cancelled = false; + + String value; + + public SVGOptions() + { + try + { + jbInit(); + } catch (Exception ex) + { + ex.printStackTrace(); + } + + ButtonGroup bg = new ButtonGroup(); + bg.add(lineart); + bg.add(text); + + JOptionPane pane = new JOptionPane(null, JOptionPane.DEFAULT_OPTION, + JOptionPane.DEFAULT_OPTION, null, new Object[] + { this }); + + dialog = pane.createDialog(Desktop.desktop, "SVG Rendering options"); + dialog.setVisible(true); + + } + + private void jbInit() throws Exception + { + lineart.setFont(JvSwingUtils.getLabelFont()); + lineart.setText(MessageManager.getString("label.lineart")); + text.setFont(JvSwingUtils.getLabelFont()); + text.setText(MessageManager.getString("action.text")); + text.setSelected(true); + askAgain.setFont(JvSwingUtils.getLabelFont()); + askAgain.setText(MessageManager.getString("label.dont_ask_me_again")); + ok.setText(MessageManager.getString("action.ok")); + ok.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + ok_actionPerformed(e); + } + }); + cancel.setText(MessageManager.getString("action.cancel")); + cancel.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + cancel_actionPerformed(e); + } + }); + jLabel1.setFont(JvSwingUtils.getLabelFont()); + jLabel1.setText("Select SVG character rendering style"); + this.setLayout(borderLayout1); + jPanel3.setBorder(BorderFactory.createEtchedBorder()); + jPanel2.add(text); + jPanel2.add(lineart); + jPanel2.add(askAgain); + jPanel1.add(ok); + jPanel1.add(cancel); + jPanel3.add(jLabel1); + jPanel3.add(jPanel2); + this.add(jPanel3, java.awt.BorderLayout.CENTER); + this.add(jPanel1, java.awt.BorderLayout.SOUTH); + } + + JRadioButton lineart = new JRadioButton(); + + JRadioButton text = new JRadioButton(); + + JCheckBox askAgain = new JCheckBox(); + + JButton ok = new JButton(); + + JButton cancel = new JButton(); + + JPanel jPanel1 = new JPanel(); + + JLabel jLabel1 = new JLabel(); + + JPanel jPanel2 = new JPanel(); + + JPanel jPanel3 = new JPanel(); + + BorderLayout borderLayout1 = new BorderLayout(); + + public void ok_actionPerformed(ActionEvent e) + { + if (lineart.isSelected()) + { + value = "Lineart"; + } + else + { + value = "Text"; + } + + if (!askAgain.isSelected()) + { + jalview.bin.Cache.applicationProperties.remove("SVG_RENDERING"); + } + else + { + jalview.bin.Cache.setProperty("SVG_RENDERING", value); + } + + dialog.setVisible(false); + } + + public void cancel_actionPerformed(ActionEvent e) + { + cancelled = true; + dialog.setVisible(false); + } + + public String getValue() + { + return value; + } +} diff --git a/src/jalview/util/ImageMaker.java b/src/jalview/util/ImageMaker.java index 61ef34f..b410be6 100755 --- a/src/jalview/util/ImageMaker.java +++ b/src/jalview/util/ImageMaker.java @@ -21,6 +21,7 @@ package jalview.util; import jalview.gui.EPSOptions; +import jalview.gui.SVGOptions; import jalview.io.JalviewFileChooser; import java.awt.Component; @@ -34,6 +35,7 @@ import java.io.FileOutputStream; import javax.imageio.ImageIO; import org.jfree.graphics2d.svg.SVGGraphics2D; +import org.jfree.graphics2d.svg.SVGHints; import org.jibble.epsgraphics.EpsGraphics2D; public class ImageMaker @@ -219,11 +221,39 @@ public class ImageMaker Graphics2D ig2 = (Graphics2D) graphics; ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + } void setupSVG(int width, int height, String title) { + g2 = new SVGGraphics2D(width, height); + Graphics2D ig2 = g2; + + String renderStyle = jalview.bin.Cache.getDefault("SVG_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"))) + { + SVGOptions svgOption = new SVGOptions(); + renderStyle = svgOption.getValue(); + + if (renderStyle == null || svgOption.cancelled) + { + return; + } + } + + if (renderStyle.equalsIgnoreCase("lineart")) + { + ig2.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE, + SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR); + } + graphics = g2; }