KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > apps > jsvg > JSVG


1 /*
2
3    Copyright 2001-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18
19 package org.apache.batik.apps.jsvg;
20
21 import javax.swing.JFrame JavaDoc;
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Dimension JavaDoc;
24 import java.awt.event.WindowAdapter JavaDoc;
25 import java.awt.event.WindowEvent JavaDoc;
26 import org.apache.batik.swing.JSVGCanvas;
27 import org.apache.batik.swing.svg.SVGUserAgentGUIAdapter;
28
29 /**
30  * Simplest "complete" SVG Viewer using Batik.
31  *
32  * This is about as simple as an SVG viewer application can get.
33  * It shuts it's self down when all windows are closed.
34  * It reports errors interactively, and it takes a list of URI's
35  * to open.
36  *
37  * @author <a HREF="mailto:Thomas.DeWeese@Kodak.com">deweese</a>
38  * @version $Id: JSVG.java,v 1.3 2005/03/27 08:58:29 cam Exp $
39  */

40 public class JSVG extends JFrame JavaDoc{
41     static int windowCount=0;
42     public JSVG(String JavaDoc url) {
43         super(url);
44         JSVGCanvas canvas = new JSVGCanvas(new SVGUserAgentGUIAdapter(this),
45                                            true, true) {
46                 /**
47                  * This method is called when the component knows the desired
48                  * size of the window (based on width/height of outermost SVG
49                  * element). We override it to immediately pack this frame.
50                  */

51                 public void setMySize(Dimension JavaDoc d) {
52                     setPreferredSize(d);
53                     invalidate();
54                     JSVG.this.pack();
55                 }
56             };
57
58         getContentPane().add(canvas, BorderLayout.CENTER);
59         canvas.setURI(url);
60         setVisible(true);
61         addWindowListener(new WindowAdapter JavaDoc() {
62                 public void windowClosing(WindowEvent JavaDoc e) {
63                     windowCount--;
64                     if (windowCount == 0)
65                         System.exit(0);
66                 }
67             });
68         windowCount++;
69     }
70
71     public static void main(String JavaDoc args[]) {
72         for (int i=0; i<args.length; i++) {
73             new JSVG(args[i]);
74         }
75     }
76 };
77
Popular Tags