| 1 |
/* |
| 2 |
|
| 3 |
Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 |
contributor license agreements. See the NOTICE file distributed with |
| 5 |
this work for additional information regarding copyright ownership. |
| 6 |
The ASF licenses this file to You under the Apache License, Version 2.0 |
| 7 |
(the "License"); you may not use this file except in compliance with |
| 8 |
the License. You may obtain a copy of the License at |
| 9 |
|
| 10 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
|
| 12 |
Unless required by applicable law or agreed to in writing, software |
| 13 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 14 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 |
See the License for the specific language governing permissions and |
| 16 |
limitations under the License. |
| 17 |
|
| 18 |
*/ |
| 19 |
|
| 20 |
package org.apache.batik.apps.jsvg; |
| 21 |
|
| 22 |
import javax.swing.JFrame; |
| 23 |
import java.awt.BorderLayout; |
| 24 |
import java.awt.Dimension; |
| 25 |
import java.awt.event.WindowAdapter; |
| 26 |
import java.awt.event.WindowEvent; |
| 27 |
import org.apache.batik.swing.JSVGCanvas; |
| 28 |
import org.apache.batik.swing.svg.SVGUserAgentGUIAdapter; |
| 29 |
|
| 30 |
/** |
| 31 |
* Simplest "complete" SVG Viewer using Batik. |
| 32 |
* |
| 33 |
* This is about as simple as an SVG viewer application can get. |
| 34 |
* It shuts it's self down when all windows are closed. |
| 35 |
* It reports errors interactively, and it takes a list of URI's |
| 36 |
* to open. |
| 37 |
* |
| 38 |
* @author <a href="mailto:[email protected]">deweese</a> |
| 39 |
* @version $Id$ |
| 40 |
*/ |
| 41 |
public class JSVG extends JFrame{ |
| 42 |
static int windowCount=0; |
| 43 |
public JSVG(String url) { |
| 44 |
super(url); |
| 45 |
JSVGCanvas canvas = new JSVGCanvas(new SVGUserAgentGUIAdapter(this), |
| 46 |
true, true) { |
| 47 |
/** |
| 48 |
* This method is called when the component knows the desired |
| 49 |
* size of the window (based on width/height of outermost SVG |
| 50 |
* element). We override it to immediately pack this frame. |
| 51 |
*/ |
| 52 |
public void setMySize(Dimension d) { |
| 53 |
setPreferredSize(d); |
| 54 |
invalidate(); |
| 55 |
JSVG.this.pack(); |
| 56 |
} |
| 57 |
}; |
| 58 |
|
| 59 |
getContentPane().add(canvas, BorderLayout.CENTER); |
| 60 |
canvas.setURI(url); |
| 61 |
setVisible(true); |
| 62 |
addWindowListener(new WindowAdapter() { |
| 63 |
public void windowClosing(WindowEvent e) { |
| 64 |
windowCount--; |
| 65 |
if (windowCount == 0) |
| 66 |
System.exit(0); |
| 67 |
} |
| 68 |
}); |
| 69 |
windowCount++; |
| 70 |
} |
| 71 |
|
| 72 |
public static void main(String[] args) { |
| 73 |
for (int i=0; i<args.length; i++) { |
| 74 |
new JSVG(args[i]); |
| 75 |
} |
| 76 |
} |
| 77 |
} |