From 47362b2951e24c0b6199f05d5d8334c21a4bbbc1 Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Sat, 14 Jul 2012 15:38:33 -0700 Subject: [PATCH] use Horstmann's PS save not mine; it'll handle Japanese char etc.. this way. --- .../src/org/antlr/v4/runtime/RuleContext.java | 16 +++++++++------- .../antlr/v4/runtime/misc/GraphicsSupport.java | 8 +++++++- .../antlr/v4/runtime/tree/gui/TreeViewer.java | 6 +++--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/RuleContext.java b/runtime/Java/src/org/antlr/v4/runtime/RuleContext.java index 8d87e85d3..3fed041ee 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/RuleContext.java +++ b/runtime/Java/src/org/antlr/v4/runtime/RuleContext.java @@ -268,15 +268,17 @@ public class RuleContext implements ParseTree.RuleNode { public void save(Parser parser, String fileName) throws IOException, PrintException { - Trees.writePS(this, parser, fileName); + TreeViewer viewer = new TreeViewer(parser, this); + viewer.save(fileName); +// Trees.writePS(this, parser, fileName); // parrt routine } - public void save(Parser parser, String fileName, - String fontName, int fontSize) - throws IOException - { - Trees.writePS(this, parser, fileName, fontName, fontSize); - } +// public void save(Parser parser, String fileName, +// String fontName, int fontSize) +// throws IOException +// { +// Trees.writePS(this, parser, fileName, fontName, fontSize); +// } /** Print out a whole tree, not just a node, in LISP format * (root child1 .. childN). Print just a node if this is a leaf. diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/GraphicsSupport.java b/runtime/Java/src/org/antlr/v4/runtime/misc/GraphicsSupport.java index 2caca2110..b7815629a 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/GraphicsSupport.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/GraphicsSupport.java @@ -30,7 +30,12 @@ package org.antlr.v4.runtime.misc; import javax.imageio.ImageIO; -import javax.print.*; +import javax.print.DocFlavor; +import javax.print.DocPrintJob; +import javax.print.PrintException; +import javax.print.PrintService; +import javax.print.SimpleDoc; +import javax.print.StreamPrintServiceFactory; import javax.print.attribute.HashPrintRequestAttributeSet; import javax.print.attribute.PrintRequestAttributeSet; import javax.swing.*; @@ -105,6 +110,7 @@ public class GraphicsSupport { job.print(doc, attributes); } } else { + // parrt: doesn't seem to do .pdf. 0-length file generated Rectangle rect = comp.getBounds(); BufferedImage image = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_RGB); diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/gui/TreeViewer.java b/runtime/Java/src/org/antlr/v4/runtime/tree/gui/TreeViewer.java index b4249840f..7a8adc447 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/gui/TreeViewer.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/gui/TreeViewer.java @@ -34,11 +34,13 @@ import org.abego.treelayout.TreeForTreeLayout; import org.abego.treelayout.TreeLayout; import org.abego.treelayout.util.DefaultConfiguration; import org.antlr.v4.runtime.Parser; +import org.antlr.v4.runtime.misc.GraphicsSupport; import org.antlr.v4.runtime.misc.Utils; import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.Tree; import org.antlr.v4.runtime.tree.Trees; +import javax.print.PrintException; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -47,6 +49,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.CubicCurve2D; import java.awt.geom.Rectangle2D; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -324,7 +327,6 @@ public class TreeViewer extends JComponent { }); } - /** This does not always seem to render the postscript properly public void save(String fileName) throws IOException, PrintException { JDialog dialog = new JDialog(); Container contentPane = dialog.getContentPane(); @@ -335,10 +337,8 @@ public class TreeViewer extends JComponent { dialog.pack(); dialog.setLocationRelativeTo(null); dialog.dispose(); -// dialog.setVisible(true); GraphicsSupport.saveImage(this, fileName); } - */ // ---------------------------------------------------