01: /*
02:
03: Licensed to the Apache Software Foundation (ASF) under one or more
04: contributor license agreements. See the NOTICE file distributed with
05: this work for additional information regarding copyright ownership.
06: The ASF licenses this file to You under the Apache License, Version 2.0
07: (the "License"); you may not use this file except in compliance with
08: the License. You may obtain a copy of the License at
09:
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.test;
21:
22: import java.awt.Dimension;
23: import java.io.File;
24: import java.net.URL;
25: import java.net.MalformedURLException;
26: import javax.swing.JFrame;
27: import javax.swing.WindowConstants;
28:
29: import org.apache.batik.swing.*;
30:
31: /**
32: * A very simple example class that demonstrates the
33: * XJSVGCanvas and XJSVGScroller classes.
34: * <p>
35: * Usage: ScrollExample [svg file name]
36: * <p>
37: * @author Zach DelProposto
38: *
39: *
40: *
41: */
42: public class ScrollExample {
43:
44: /** Command-line start */
45: public static void main(String args[]) {
46: if (args.length != 1) {
47: System.out
48: .println("No or multiple SVG files were specified.");
49: System.out.println("Usage: ScrollExample svgFileName");
50: System.exit(1);
51: }
52:
53: // get the file
54: File file = new File(args[0]);
55: if (!file.exists()) {
56: System.out.println("File " + file + " does not exist!");
57: System.exit(1);
58: }
59:
60: try {
61: new ScrollExample(file.toURL());
62: } catch (MalformedURLException e) {
63: System.out.println("Cannot convert file to a valid URL...");
64: System.out.println(e);
65: System.exit(1);
66: }
67:
68: }// main()
69:
70: /** Construct the Example */
71: private ScrollExample(URL url) {
72: JFrame frame = new JFrame("ScrollExample: " + url.getFile());
73: frame.setResizable(true);
74: frame.setSize(new Dimension(500, 500));
75: frame.addWindowListener(new java.awt.event.WindowAdapter() {
76: public void windowClosing(java.awt.event.WindowEvent e) {
77: System.exit(0);
78: }
79: });
80:
81: // frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
82:
83: JSVGCanvas canvas = new JSVGCanvas();
84: JSVGScrollPane scroller = new JSVGScrollPane(canvas);
85: // scroller.setScrollbarsAlwaysVisible(true);
86: canvas.setURI(url.toString());
87:
88: frame.getContentPane().add(scroller);
89: frame.setVisible(true);
90: }// ScrollExample()
91:
92: }// class ScrollExample
|