Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8264838: IGV: enhance graph export functionality #4394

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 0 additions & 85 deletions src/utils/IdealGraphVisualizer/BatikSVGProxy/pom.xml

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

15 changes: 10 additions & 5 deletions src/utils/IdealGraphVisualizer/View/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@
<artifactId>SelectionCoordinator</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sun.hotspot.igv</groupId>
<artifactId>BatikSVGProxy</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sun.hotspot.igv</groupId>
<artifactId>Settings</artifactId>
Expand Down Expand Up @@ -151,6 +146,16 @@
<artifactId>org-netbeans-api-visual</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-dom</artifactId>
<version>${batik.version}</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-svggen</artifactId>
<version>${batik.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
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.*;
Expand All @@ -52,6 +51,10 @@
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When trying to build IGV with this patch I get

Compilation failure
[ERROR] /home/christian/jdk/open/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/EditorTopComponent.java:[648,18] cannot find symbol
[ERROR]   symbol:   class SVGGraphics2DIOException
[ERROR]   location: class com.sun.hotspot.igv.view.EditorTopComponent

I think there is a missing import org.apache.batik.svggen.SVGGraphics2DIOException; here.

import org.w3c.dom.DOMImplementation;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.actions.RedoAction;
Expand Down Expand Up @@ -101,32 +104,22 @@ 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);
} 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);

} catch (UnsupportedEncodingException e) {
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
}
SVGGraphics2D svgGenerator = createGraphicsObject();
scene.paint(svgGenerator);
FileOutputStream os = null;
try {
os = new FileOutputStream(f);
Writer out = new OutputStreamWriter(os, "UTF-8");
printToStream(svgGenerator, out, true);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
}
}

}
Comment on lines +109 to 123
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified to

try (FileOutputStream os = new FileOutputStream(f)) {
    Writer out = new OutputStreamWriter(os, StandardCharsets.UTF_8);
    printToStream(svgGenerator, out, true);
} catch (IOException e) {
    e.printStackTrace();
}

You could also use StandardCharsets.UTF_8 instead of "UTF-8".

}
};
Expand Down Expand Up @@ -639,5 +632,19 @@ public UndoRedo getUndoRedo() {
@Override
protected Object writeReplace() throws ObjectStreamException {
throw new NotSerializableException();
}
}

private static SVGGraphics2D createGraphicsObject() {
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);
return new SVGGraphics2D(ctx, true);
}

private static void printToStream(SVGGraphics2D svgGenerator, Writer stream, boolean useCSS) {
try {
svgGenerator.stream(stream, useCSS);
} catch (SVGGraphics2DIOException e) {}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/utils/IdealGraphVisualizer/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@
<artifactId>Graal</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>BatikSVGProxy</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>View</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/IdealGraphVisualizer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
<module>ServerCompiler</module>
<module>FilterWindow</module>
<module>Graal</module>
<module>BatikSVGProxy</module>
<module>View</module>
</modules>
<properties>
Expand All @@ -96,6 +95,7 @@
<mvncompilerplugin.version>3.8.1</mvncompilerplugin.version>
<mvnjarplugin.version>3.1.2</mvnjarplugin.version>
<junit.version>4.13.2</junit.version>
<batik.version>1.14</batik.version>
<brandingToken>idealgraphvisualizer</brandingToken>
</properties>
</project>