diff --git a/src/utils/IdealGraphVisualizer/.java-version b/src/utils/IdealGraphVisualizer/.java-version
new file mode 100644
index 00000000000..60d3b2f4a4c
--- /dev/null
+++ b/src/utils/IdealGraphVisualizer/.java-version
@@ -0,0 +1 @@
+15
diff --git a/src/utils/IdealGraphVisualizer/BatikSVGProxy/pom.xml b/src/utils/IdealGraphVisualizer/BatikSVGProxy/pom.xml
deleted file mode 100644
index dccb16b356b..00000000000
--- a/src/utils/IdealGraphVisualizer/BatikSVGProxy/pom.xml
+++ /dev/null
@@ -1,85 +0,0 @@
-
-
-
-
- 4.0.0
-
- IdealGraphVisualizer-parent
- com.sun.hotspot.igv
- 1.0-SNAPSHOT
-
- com.sun.hotspot.igv
- BatikSVGProxy
- 1.0-SNAPSHOT
- nbm
- BatikSVGProxy
-
- UTF-8
-
-
-
-
-
-
- org.apache.netbeans.utilities
- nbm-maven-plugin
- ${nbmmvnplugin.version}
- true
-
-
- com.sun.hotspot.igv.svg
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- ${mvncompilerplugin.version}
-
- 1.8
- 1.8
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- ${mvnjarplugin.version}
-
-
-
- ${project.build.outputDirectory}/META-INF/MANIFEST.MF
-
-
-
-
-
-
diff --git a/src/utils/IdealGraphVisualizer/BatikSVGProxy/src/main/java/com/sun/hotspot/igv/svg/BatikSVG.java b/src/utils/IdealGraphVisualizer/BatikSVGProxy/src/main/java/com/sun/hotspot/igv/svg/BatikSVG.java
deleted file mode 100644
index 8c3d92dc064..00000000000
--- a/src/utils/IdealGraphVisualizer/BatikSVGProxy/src/main/java/com/sun/hotspot/igv/svg/BatikSVG.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code 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
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-package com.sun.hotspot.igv.svg;
-
-import java.awt.Graphics2D;
-import java.io.Writer;
-import java.io.File;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import org.w3c.dom.DOMImplementation;
-
-/**
- * Utility class
- * @author Thomas Wuerthinger
- */
-public class BatikSVG {
-
- private BatikSVG() {
- }
-
- private static Constructor SVGGraphics2DConstructor;
- private static Method streamMethod;
- private static Method createDefaultMethod;
- private static Method getDOMImplementationMethod;
- private static Method setEmbeddedFontsOnMethod;
- private static Class> classSVGGraphics2D;
-
- /**
- * Creates a graphics object that allows to be exported to SVG data using the {@link #printToStream(Graphics2D, Writer, boolean) printToStream} method.
- * @return the newly created Graphics2D object or null if the library does not exist
- */
- public static Graphics2D createGraphicsObject() {
- try {
- if (SVGGraphics2DConstructor == null) {
- String batikJar = System.getenv().get("IGV_BATIK_JAR");
- if (batikJar == null) {
- return null;
- }
- // Load batik in it's own class loader since some it's support jars interfere with the JDK
- URL url = new File(batikJar).toURI().toURL();
- ClassLoader cl = new URLClassLoader(new URL[] { url });
- Class> classGenericDOMImplementation = cl.loadClass("org.apache.batik.dom.GenericDOMImplementation");
- Class> classSVGGeneratorContext = cl.loadClass("org.apache.batik.svggen.SVGGeneratorContext");
- classSVGGraphics2D = cl.loadClass("org.apache.batik.svggen.SVGGraphics2D");
- getDOMImplementationMethod = classGenericDOMImplementation.getDeclaredMethod("getDOMImplementation", new Class[0]);
- createDefaultMethod = classSVGGeneratorContext.getDeclaredMethod("createDefault", new Class[]{org.w3c.dom.Document.class});
- setEmbeddedFontsOnMethod = classSVGGeneratorContext.getDeclaredMethod("setEmbeddedFontsOn", new Class[]{boolean.class});
- streamMethod = classSVGGraphics2D.getDeclaredMethod("stream", Writer.class, boolean.class);
- SVGGraphics2DConstructor = classSVGGraphics2D.getConstructor(classSVGGeneratorContext, boolean.class);
- }
- DOMImplementation dom = (DOMImplementation) getDOMImplementationMethod.invoke(null);
- org.w3c.dom.Document document = dom.createDocument("http://www.w3.org/2000/svg", "svg", null);
- Object ctx = createDefaultMethod.invoke(null, document);
- setEmbeddedFontsOnMethod.invoke(ctx, true);
- Graphics2D svgGenerator = (Graphics2D) SVGGraphics2DConstructor.newInstance(ctx, true);
- return svgGenerator;
- } catch (ClassNotFoundException e) {
- return null;
- } catch (NoSuchMethodException e) {
- return null;
- } catch (IllegalAccessException e) {
- return null;
- } catch (InvocationTargetException e) {
- return null;
- } catch (InstantiationException e) {
- return null;
- } catch (MalformedURLException e) {
- return null;
- }
- }
-
- /**
- * Serializes a graphics object to a stream in SVG format.
- * @param svgGenerator the graphics object. Only graphics objects created by the {@link #createGraphicsObject() createGraphicsObject} method are valid.
- * @param stream the stream to which the data is written
- * @param useCSS whether to use CSS styles in the SVG output
- */
- public static void printToStream(Graphics2D svgGenerator, Writer stream, boolean useCSS) {
- assert classSVGGraphics2D != null;
- assert classSVGGraphics2D.isInstance(svgGenerator);
- try {
- streamMethod.invoke(svgGenerator, stream, useCSS);
- } catch (IllegalAccessException e) {
- assert false;
- } catch (InvocationTargetException e) {
- assert false;
- }
- }
-}
diff --git a/src/utils/IdealGraphVisualizer/BatikSVGProxy/src/main/java/com/sun/hotspot/igv/svg/package-info.java b/src/utils/IdealGraphVisualizer/BatikSVGProxy/src/main/java/com/sun/hotspot/igv/svg/package-info.java
deleted file mode 100644
index 272fc48e96f..00000000000
--- a/src/utils/IdealGraphVisualizer/BatikSVGProxy/src/main/java/com/sun/hotspot/igv/svg/package-info.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code 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
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-/**
- * This package is used to proxy the SVG export functionality of the BatikSVG library. Reflection is used such that the
- * library is optional and need not be present at build time.
- */
-package com.sun.hotspot.igv.svg;
-
diff --git a/src/utils/IdealGraphVisualizer/BatikSVGProxy/src/main/nbm/manifest.mf b/src/utils/IdealGraphVisualizer/BatikSVGProxy/src/main/nbm/manifest.mf
deleted file mode 100644
index 175014d653e..00000000000
--- a/src/utils/IdealGraphVisualizer/BatikSVGProxy/src/main/nbm/manifest.mf
+++ /dev/null
@@ -1,5 +0,0 @@
-Manifest-Version: 1.0
-OpenIDE-Module: com.sun.hotspot.igv.svg
-OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/svg/Bundle.properties
-OpenIDE-Module-Specification-Version: 1.0
-
diff --git a/src/utils/IdealGraphVisualizer/BatikSVGProxy/src/main/resources/com/sun/hotspot/igv/svg/Bundle.properties b/src/utils/IdealGraphVisualizer/BatikSVGProxy/src/main/resources/com/sun/hotspot/igv/svg/Bundle.properties
deleted file mode 100644
index e579912925b..00000000000
--- a/src/utils/IdealGraphVisualizer/BatikSVGProxy/src/main/resources/com/sun/hotspot/igv/svg/Bundle.properties
+++ /dev/null
@@ -1 +0,0 @@
-OpenIDE-Module-Name=BatikSVGProxy
diff --git a/src/utils/IdealGraphVisualizer/View/pom.xml b/src/utils/IdealGraphVisualizer/View/pom.xml
index 12b2a8678b4..0b1b0d77f31 100644
--- a/src/utils/IdealGraphVisualizer/View/pom.xml
+++ b/src/utils/IdealGraphVisualizer/View/pom.xml
@@ -81,11 +81,6 @@
SelectionCoordinator
${project.version}
-
- com.sun.hotspot.igv
- BatikSVGProxy
- ${project.version}
-
com.sun.hotspot.igv
Settings
@@ -151,6 +146,21 @@
org-netbeans-api-visual
${netbeans.version}
+
+ org.apache.xmlgraphics
+ batik-dom
+ ${batik.version}
+
+
+ org.apache.xmlgraphics
+ batik-svggen
+ ${batik.version}
+
+
+ com.github.librepdf
+ openpdf
+ ${openpdf.version}
+
diff --git a/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramViewer.java b/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramViewer.java
index 42697d025fe..2c58ac4dd26 100644
--- a/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramViewer.java
+++ b/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramViewer.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@ package com.sun.hotspot.igv.view;
import com.sun.hotspot.igv.graph.Figure;
import java.awt.Component;
import java.awt.Graphics2D;
+import java.awt.Rectangle;
import java.util.Collection;
import java.util.List;
import javax.swing.JComponent;
@@ -44,7 +45,7 @@ interface DiagramViewer {
PANNING,
}
- public void paint(Graphics2D svgGenerator);
+ public void paint(Graphics2D generator);
public Lookup getLookup();
@@ -70,4 +71,6 @@ interface DiagramViewer {
public void setInteractionMode(InteractionMode mode);
+ public Rectangle getBounds();
+
}
diff --git a/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/EditorTopComponent.java b/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/EditorTopComponent.java
index 76a73b97068..cf5e965de69 100644
--- a/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/EditorTopComponent.java
+++ b/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/EditorTopComponent.java
@@ -36,7 +36,6 @@ import com.sun.hotspot.igv.filter.FilterChainProvider;
import com.sun.hotspot.igv.graph.Diagram;
import com.sun.hotspot.igv.graph.Figure;
import com.sun.hotspot.igv.graph.services.DiagramProvider;
-import com.sun.hotspot.igv.svg.BatikSVG;
import com.sun.hotspot.igv.util.LookupHistory;
import com.sun.hotspot.igv.util.RangeSlider;
import com.sun.hotspot.igv.view.actions.*;
@@ -48,10 +47,21 @@ import java.awt.event.KeyListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.*;
+import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.*;
import javax.swing.*;
import javax.swing.border.Border;
+import org.apache.batik.dom.GenericDOMImplementation;
+import org.apache.batik.svggen.SVGGeneratorContext;
+import org.apache.batik.svggen.SVGGraphics2D;
+import com.lowagie.text.Document;
+import com.lowagie.text.Rectangle;
+import com.lowagie.text.pdf.PdfWriter;
+import com.lowagie.text.pdf.PdfContentByte;
+import com.lowagie.text.pdf.PdfTemplate;
+import com.lowagie.text.pdf.PdfGraphics2D;
+import org.w3c.dom.DOMImplementation;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.actions.RedoAction;
@@ -103,30 +113,14 @@ public final class EditorTopComponent extends TopComponent implements PropertyCh
@Override
public void export(File f) {
- Graphics2D svgGenerator = BatikSVG.createGraphicsObject();
-
- if (svgGenerator == null) {
- NotifyDescriptor message = new NotifyDescriptor.Message("For export to SVG files the Batik SVG Toolkit must be intalled.", NotifyDescriptor.ERROR_MESSAGE);
- DialogDisplayer.getDefault().notifyLater(message);
+ String lcFileName = f.getName().toLowerCase();
+ if (lcFileName.endsWith(".pdf")) {
+ exportToPDF(scene, f);
+ } else if (lcFileName.endsWith(".svg")) {
+ exportToSVG(scene, f);
} else {
- scene.paint(svgGenerator);
- FileOutputStream os = null;
- try {
- os = new FileOutputStream(f);
- Writer out = new OutputStreamWriter(os, UTF_8);
- BatikSVG.printToStream(svgGenerator, out, true);
- } catch (FileNotFoundException e) {
- NotifyDescriptor message = new NotifyDescriptor.Message("For export to SVG files the Batik SVG Toolkit must be intalled.", NotifyDescriptor.ERROR_MESSAGE);
- DialogDisplayer.getDefault().notifyLater(message);
- } finally {
- if (os != null) {
- try {
- os.close();
- } catch (IOException e) {
- }
- }
- }
-
+ NotifyDescriptor message = new NotifyDescriptor.Message("Unknown image file extension: expected either '.pdf' or '.svg'", NotifyDescriptor.ERROR_MESSAGE);
+ DialogDisplayer.getDefault().notifyLater(message);
}
}
};
@@ -639,5 +633,47 @@ public final class EditorTopComponent extends TopComponent implements PropertyCh
@Override
protected Object writeReplace() throws ObjectStreamException {
throw new NotSerializableException();
-}
+ }
+
+ private static void exportToPDF(DiagramViewer scene, File f) {
+ int width = scene.getBounds().width;
+ int height = scene.getBounds().height;
+ com.lowagie.text.Document document = new Document(new Rectangle(width, height));
+ PdfWriter writer = null;
+ try {
+ writer = PdfWriter.getInstance(document, new FileOutputStream(f));
+ writer.setCloseStream(true);
+ document.open();
+ PdfContentByte contentByte = writer.getDirectContent();
+ PdfTemplate template = contentByte.createTemplate(width, height);
+ PdfGraphics2D pdfGenerator = new PdfGraphics2D(contentByte, width, height);
+ scene.paint(pdfGenerator);
+ pdfGenerator.dispose();
+ contentByte.addTemplate(template, 0, 0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (document.isOpen()) {
+ document.close();
+ }
+ if (writer != null) {
+ writer.close();
+ }
+ }
+ }
+
+ private static void exportToSVG(DiagramViewer scene, File f) {
+ DOMImplementation dom = GenericDOMImplementation.getDOMImplementation();
+ org.w3c.dom.Document document = dom.createDocument("http://www.w3.org/2000/svg", "svg", null);
+ SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
+ ctx.setEmbeddedFontsOn(true);
+ SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, true);
+ scene.paint(svgGenerator);
+ try (FileOutputStream os = new FileOutputStream(f)) {
+ Writer out = new OutputStreamWriter(os, StandardCharsets.UTF_8);
+ svgGenerator.stream(out, true);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
diff --git a/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/actions/ExportAction.java b/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/actions/ExportAction.java
index 8583a6fbf35..e5ea4025c33 100644
--- a/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/actions/ExportAction.java
+++ b/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/actions/ExportAction.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -45,7 +45,7 @@ public final class ExportAction extends CallableSystemAction implements LookupLi
private final Lookup.Result result;
public ExportAction() {
- putValue(Action.SHORT_DESCRIPTION, "Export current graph as SVG file");
+ putValue(Action.SHORT_DESCRIPTION, "Export current graph as image file");
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK));
lookup = Utilities.actionsGlobalContext();
result = lookup.lookup(new Lookup.Template<>(ExportCookie.class));
@@ -66,12 +66,15 @@ public final class ExportAction extends CallableSystemAction implements LookupLi
@Override
public boolean accept(File f) {
- return true;
+ String lcFileName = f.getName().toLowerCase();
+ return lcFileName.endsWith(".pdf") ||
+ lcFileName.endsWith(".svg") ||
+ f.isDirectory();
}
@Override
public String getDescription() {
- return "SVG files (*.svg)";
+ return "Image files (*.pdf, *.svg)";
}
});
fc.setCurrentDirectory(new File(Settings.get().get(Settings.DIRECTORY, Settings.DIRECTORY_DEFAULT)));
@@ -80,7 +83,7 @@ public final class ExportAction extends CallableSystemAction implements LookupLi
if (fc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
if (!file.getName().contains(".")) {
- file = new File(file.getAbsolutePath() + ".svg");
+ file = new File(file.getAbsolutePath() + ".pdf");
}
File dir = file;
diff --git a/src/utils/IdealGraphVisualizer/application/pom.xml b/src/utils/IdealGraphVisualizer/application/pom.xml
index b5422fecb52..5fcb7252c5d 100644
--- a/src/utils/IdealGraphVisualizer/application/pom.xml
+++ b/src/utils/IdealGraphVisualizer/application/pom.xml
@@ -142,11 +142,6 @@
Graal
${project.version}
-
- ${project.groupId}
- BatikSVGProxy
- ${project.version}
-
${project.groupId}
View
diff --git a/src/utils/IdealGraphVisualizer/pom.xml b/src/utils/IdealGraphVisualizer/pom.xml
index c1b1896dde4..daaae24a5fd 100644
--- a/src/utils/IdealGraphVisualizer/pom.xml
+++ b/src/utils/IdealGraphVisualizer/pom.xml
@@ -86,16 +86,17 @@
ServerCompiler
FilterWindow
Graal
- BatikSVGProxy
View
RELEASE123
1.0.2
- 4.3
+ 4.6
3.8.1
- 3.1.2
+ 3.2.0
4.13.2
+ 1.14
+ 1.3.26
idealgraphvisualizer