KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > test > ScrollExample


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.test;
20
21 import java.awt.Dimension JavaDoc;
22 import java.io.File JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.net.MalformedURLException JavaDoc;
25 import javax.swing.JFrame JavaDoc;
26 import javax.swing.WindowConstants JavaDoc;
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 class ScrollExample
42 {
43     
44     /** Command-line start */
45     public static void main(String JavaDoc 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 JavaDoc file = new File JavaDoc(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 JavaDoc 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 JavaDoc url)
78     {
79         JFrame JavaDoc frame = new JFrame JavaDoc("ScrollExample: "+url.getFile());
80         frame.setResizable(true);
81         frame.setSize(new Dimension JavaDoc(500,500));
82                 frame.addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
83                         public void windowClosing
84                             (java.awt.event.WindowEvent JavaDoc 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         canvas.setURI(url.toString());
94         
95         frame.getContentPane().add(scroller);
96         frame.setVisible(true);
97     }// ScrollExample()
98

99     
100     
101     
102 }// class ScrollExample
103

104
Popular Tags