Debian Codegraph @

contrib/scroll/ScrollExample.java

raw
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.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
28 import org.apache.batik.swing.*;
29
30 /**
31 * A very simple example class that demonstrates the
32 * XJSVGCanvas and XJSVGScroller classes.
33 * <p>
34 * Usage: ScrollExample [svg file name]
35 * <p>
36 * @author Zach DelProposto
37 *
38 *
39 *
40 */
41 public final class ScrollExample
42 {
43
44 /** Command-line start */
45 public static void main(String[] args)
46 {
47 if(args.length != 1)
48 {
49 System.out.println("No or multiple SVG files were specified.");
50 System.out.println("Usage: ScrollExample svgFileName");
51 System.exit(1);
52 }
53
54 // get the file
55 File file = new File(args[0]);
56 if(!file.exists())
57 {
58 System.out.println("File "+file+" does not exist!");
59 System.exit(1);
60 }
61
62 try
63 {
64 new ScrollExample(file.toURL());
65 }
66 catch(MalformedURLException e)
67 {
68 System.out.println("Cannot convert file to a valid URL...");
69 System.out.println(e);
70 System.exit(1);
71 }
72
73 }// main()
74
75
76 /** Construct the Example */
77 private ScrollExample(URL url)
78 {
79 JFrame frame = new JFrame("ScrollExample: "+url.getFile());
80 frame.setResizable(true);
81 frame.setSize(new Dimension(500,500));
82 frame.addWindowListener(new java.awt.event.WindowAdapter() {
83 public void windowClosing
84 (java.awt.event.WindowEvent e) {
85 System.exit(0);
86 }
87 });
88
89 // frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
90
91 JSVGCanvas canvas = new JSVGCanvas();
92 JSVGScrollPane scroller = new JSVGScrollPane(canvas);
93 // scroller.setScrollbarsAlwaysVisible(true);
94 canvas.setURI(url.toString());
95
96 frame.getContentPane().add(scroller);
97 frame.setVisible(true);
98 }// ScrollExample()
99
100
101
102
103 }// class ScrollExample
104