Mercurial > hg > truffle
annotate src/share/tools/IdealGraphVisualizer/BatikSVGProxy/src/com/sun/hotspot/igv/svg/BatikSVG.java @ 2955:bf4f8817e3bd
IdealGraphVisualizer: eliminate compiler warnings by replacing calls to deprecated API methods, introducing generics parameters where missing, and when absolutely necessary adding @SuppressWarnings annotations
author | Peter Hofer <peter.hofer@jku.at> |
---|---|
date | Wed, 15 Jun 2011 14:30:40 +0200 |
parents | 53ddfe305645 |
children | 43baadc1913a |
rev | line source |
---|---|
222 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
222
diff
changeset
|
2 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
222 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
222
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
222
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
222
diff
changeset
|
21 * questions. |
222 | 22 * |
23 */ | |
24 package com.sun.hotspot.igv.svg; | |
25 | |
26 import java.awt.Graphics2D; | |
27 import java.io.Writer; | |
28 import java.lang.reflect.Constructor; | |
29 import java.lang.reflect.InvocationTargetException; | |
30 import java.lang.reflect.Method; | |
31 import org.w3c.dom.DOMImplementation; | |
32 | |
33 /** | |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
34 * Utility class |
222 | 35 * @author Thomas Wuerthinger |
36 */ | |
37 public class BatikSVG { | |
38 | |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
39 private BatikSVG() { |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
40 } |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
41 |
222 | 42 private static Constructor SVGGraphics2DConstructor; |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
43 private static Method streamMethod; |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
44 private static Method createDefaultMethod; |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
45 private static Method getDOMImplementationMethod; |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
46 private static Method setEmbeddedFontsOnMethod; |
2955
bf4f8817e3bd
IdealGraphVisualizer: eliminate compiler warnings by replacing calls to deprecated API methods, introducing generics parameters where missing, and when absolutely necessary adding @SuppressWarnings annotations
Peter Hofer <peter.hofer@jku.at>
parents:
2898
diff
changeset
|
47 private static Class<?> classSVGGraphics2D; |
222 | 48 |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
49 /** |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
50 * Creates a graphics object that allows to be exported to SVG data using the {@link #printToStream(Graphics2D, Writer, boolean) printToStream} method. |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
51 * @return the newly created Graphics2D object or null if the library does not exist |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
52 */ |
222 | 53 public static Graphics2D createGraphicsObject() { |
54 try { | |
55 if (SVGGraphics2DConstructor == null) { | |
56 ClassLoader cl = BatikSVG.class.getClassLoader(); | |
2955
bf4f8817e3bd
IdealGraphVisualizer: eliminate compiler warnings by replacing calls to deprecated API methods, introducing generics parameters where missing, and when absolutely necessary adding @SuppressWarnings annotations
Peter Hofer <peter.hofer@jku.at>
parents:
2898
diff
changeset
|
57 Class<?> classGenericDOMImplementation = cl.loadClass("org.apache.batik.dom.GenericDOMImplementation"); |
bf4f8817e3bd
IdealGraphVisualizer: eliminate compiler warnings by replacing calls to deprecated API methods, introducing generics parameters where missing, and when absolutely necessary adding @SuppressWarnings annotations
Peter Hofer <peter.hofer@jku.at>
parents:
2898
diff
changeset
|
58 Class<?> classSVGGeneratorContext = cl.loadClass("org.apache.batik.svggen.SVGGeneratorContext"); |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
59 classSVGGraphics2D = cl.loadClass("org.apache.batik.svggen.SVGGraphics2D"); |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
60 getDOMImplementationMethod = classGenericDOMImplementation.getDeclaredMethod("getDOMImplementation", new Class[0]); |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
61 createDefaultMethod = classSVGGeneratorContext.getDeclaredMethod("createDefault", new Class[]{org.w3c.dom.Document.class}); |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
62 setEmbeddedFontsOnMethod = classSVGGeneratorContext.getDeclaredMethod("setEmbeddedFontsOn", new Class[]{boolean.class}); |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
63 streamMethod = classSVGGraphics2D.getDeclaredMethod("stream", Writer.class, boolean.class); |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
64 SVGGraphics2DConstructor = classSVGGraphics2D.getConstructor(classSVGGeneratorContext, boolean.class); |
222 | 65 } |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
66 DOMImplementation dom = (DOMImplementation) getDOMImplementationMethod.invoke(null); |
222 | 67 org.w3c.dom.Document document = dom.createDocument("http://www.w3.org/2000/svg", "svg", null); |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
68 Object ctx = createDefaultMethod.invoke(null, document); |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
69 setEmbeddedFontsOnMethod.invoke(ctx, true); |
222 | 70 Graphics2D svgGenerator = (Graphics2D) SVGGraphics2DConstructor.newInstance(ctx, true); |
71 return svgGenerator; | |
72 } catch (ClassNotFoundException e) { | |
73 return null; | |
74 } catch (NoSuchMethodException e) { | |
75 return null; | |
76 } catch (IllegalAccessException e) { | |
77 return null; | |
78 } catch (InvocationTargetException e) { | |
79 return null; | |
80 } catch (InstantiationException e) { | |
81 return null; | |
82 } | |
83 } | |
84 | |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
85 /** |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
86 * Serializes a graphics object to a stream in SVG format. |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
87 * @param svgGenerator the graphics object. Only graphics objects created by the {@link #createGraphicsObject() createGraphicsObject} method are valid. |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
88 * @param stream the stream to which the data is written |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
89 * @param useCSS whether to use CSS styles in the SVG output |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
90 */ |
222 | 91 public static void printToStream(Graphics2D svgGenerator, Writer stream, boolean useCSS) { |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
92 assert classSVGGraphics2D != null; |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
93 assert classSVGGraphics2D.isInstance(svgGenerator); |
222 | 94 try { |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
1552
diff
changeset
|
95 streamMethod.invoke(svgGenerator, stream, useCSS); |
222 | 96 } catch (IllegalAccessException e) { |
97 assert false; | |
98 } catch (InvocationTargetException e) { | |
99 assert false; | |
100 } | |
101 } | |
102 } |