JAL-1469 Added SVGOptions.java for lineart/text rendering rendering of svg
authorCharles Ofoegbu <tcnofoegbu@dundee.ac.uk>
Tue, 25 Nov 2014 17:37:25 +0000 (17:37 +0000)
committerCharles Ofoegbu <tcnofoegbu@dundee.ac.uk>
Tue, 25 Nov 2014 17:37:25 +0000 (17:37 +0000)
.externalToolBuilders/Jalview Release indices [Builder].launch
src/jalview/gui/SVGOptions.java [new file with mode: 0644]
src/jalview/util/ImageMaker.java

index 4c0c7dd..9d81cc8 100644 (file)
@@ -14,6 +14,7 @@
 <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
 <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="jalview"/>
 <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value=""/>
 <stringAttribute key="org.eclipse.ui.externaltools.ATTR_ANT_TARGETS" value="buildindices,"/>
 <booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="true"/>
 <stringAttribute key="org.eclipse.ui.externaltools.ATTR_LAUNCH_CONFIGURATION_BUILD_SCOPE" value="${none}"/>
diff --git a/src/jalview/gui/SVGOptions.java b/src/jalview/gui/SVGOptions.java
new file mode 100644 (file)
index 0000000..b5e194b
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ * 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;
+  }
+}
index 61ef34f..b410be6 100755 (executable)
@@ -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;
   }