KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > apps > svgbrowser > AboutDialog


1 /*
2
3    Copyright 2001-2004 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 package org.apache.batik.apps.svgbrowser;
19
20 import java.awt.BorderLayout JavaDoc;
21 import java.awt.Color JavaDoc;
22 import java.awt.Dimension JavaDoc;
23 import java.awt.Frame JavaDoc;
24 import java.awt.Point JavaDoc;
25 import java.awt.Rectangle JavaDoc;
26 import java.awt.event.KeyAdapter JavaDoc;
27 import java.awt.event.KeyEvent JavaDoc;
28 import java.awt.event.MouseAdapter JavaDoc;
29 import java.awt.event.MouseEvent JavaDoc;
30 import java.net.URL JavaDoc;
31
32 import javax.swing.BorderFactory JavaDoc;
33 import javax.swing.ImageIcon JavaDoc;
34 import javax.swing.JComponent JavaDoc;
35 import javax.swing.JLabel JavaDoc;
36 import javax.swing.JPanel JavaDoc;
37 import javax.swing.JTextArea JavaDoc;
38 import javax.swing.JWindow JavaDoc;
39 import javax.swing.SwingConstants JavaDoc;
40 import javax.swing.border.BevelBorder JavaDoc;
41
42 import org.apache.batik.Version;
43
44 /**
45  * A dialog showing the revision of the Batik viewer as well
46  * as the list of contributors.
47  * The dialog can be dismissed by click or by escaping.
48  *
49  * @author <a HREF="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
50  * @version $Id: AboutDialog.java,v 1.14 2004/08/18 07:12:26 vhardy Exp $
51  */

52 public class AboutDialog extends JWindow JavaDoc {
53
54     public static final String JavaDoc ICON_BATIK_SPLASH
55         = "AboutDialog.icon.batik.splash";
56
57     public static final String JavaDoc ICON_APACHE_LOGO
58         = "AboutDialog.icon.apache.logo";
59
60     public static final String JavaDoc LABEL_APACHE_BATIK_PROJECT
61         = "AboutDialog.label.apache.batik.project";
62
63     public static final String JavaDoc LABEL_CONTRIBUTORS
64         = "AboutDialog.label.contributors";
65
66     /**
67      * Default constructor
68      */

69     public AboutDialog(){
70         super();
71         buildGUI();
72     }
73
74     public AboutDialog(Frame JavaDoc owner){
75         super(owner);
76         buildGUI();
77
78         addKeyListener(new KeyAdapter JavaDoc(){
79                 public void keyPressed(KeyEvent JavaDoc e){
80                     if(e.getKeyCode() == KeyEvent.VK_ESCAPE){
81                         setVisible(false);
82                         dispose();
83                     }
84                 }
85             });
86
87         addMouseListener(new MouseAdapter JavaDoc(){
88                 public void mousePressed(MouseEvent JavaDoc e){
89                     setVisible(false);
90                     dispose();
91                 }
92             });
93     }
94
95     public void setLocationRelativeTo(Frame JavaDoc f) {
96         Dimension JavaDoc invokerSize = f.getSize();
97         Point JavaDoc loc = f.getLocation();
98         Point JavaDoc invokerScreenLocation = new Point JavaDoc(loc.x, loc.y);
99
100         Rectangle JavaDoc bounds = getBounds();
101         int dx = invokerScreenLocation.x+((invokerSize.width-bounds.width)/2);
102         int dy = invokerScreenLocation.y+((invokerSize.height - bounds.height)/2);
103         Dimension JavaDoc screenSize = getToolkit().getScreenSize();
104
105         if (dy+bounds.height>screenSize.height) {
106             dy = screenSize.height-bounds.height;
107             dx = invokerScreenLocation.x<(screenSize.width>>1) ? invokerScreenLocation.x+invokerSize.width :
108                 invokerScreenLocation.x-bounds.width;
109         }
110         if (dx+bounds.width>screenSize.width) {
111             dx = screenSize.width-bounds.width;
112         }
113
114         if (dx<0) dx = 0;
115         if (dy<0) dy = 0;
116         setLocation(dx, dy);
117     }
118
119     /**
120      * Populates this window
121      */

122     protected void buildGUI(){
123         JPanel JavaDoc panel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 5));
124         panel.setBackground(Color.white);
125
126         ClassLoader JavaDoc cl = this.getClass().getClassLoader();
127
128         //
129
// Top is made of the Apache feather, the
130
// name of the project and URL
131
//
132
URL JavaDoc url = cl.getResource(Resources.getString(ICON_APACHE_LOGO));
133         JLabel JavaDoc l = new JLabel JavaDoc(Resources.getString(LABEL_APACHE_BATIK_PROJECT),
134                               new ImageIcon JavaDoc(url),
135                               SwingConstants.LEFT);
136         panel.add(BorderLayout.NORTH, l);
137
138         //
139
// Add splash image
140
//
141
url = cl.getResource(Resources.getString(ICON_BATIK_SPLASH));
142         panel.add(BorderLayout.CENTER, new JLabel JavaDoc(new ImageIcon JavaDoc(url)));
143
144         //
145
// Add exact revision information
146
//
147
String JavaDoc tagName = Version.getVersion();
148
149         panel.add(BorderLayout.SOUTH, new JLabel JavaDoc(tagName, SwingConstants.RIGHT));
150
151         setBackground(Color.white);
152         getContentPane().setBackground(Color.white);
153
154         JPanel JavaDoc p = new JPanel JavaDoc(new BorderLayout JavaDoc());
155         p.setBackground(Color.white);
156         p.add(panel, BorderLayout.CENTER);
157
158         JTextArea JavaDoc contributors
159             = new JTextArea JavaDoc(Resources.getString(LABEL_CONTRIBUTORS)){
160                     {setLineWrap(true); setWrapStyleWord(true); setEnabled(false); setRows(11); }
161                 };
162
163         contributors.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
164
165         p.add(contributors,
166               BorderLayout.SOUTH);
167         ((JComponent JavaDoc)getContentPane()).setBorder
168             (BorderFactory.createCompoundBorder
169              (BorderFactory.createBevelBorder(BevelBorder.RAISED, Color.gray, Color.black),
170               BorderFactory.createCompoundBorder
171              (BorderFactory.createCompoundBorder
172               (BorderFactory.createEmptyBorder(3, 3, 3, 3),
173                BorderFactory.createLineBorder(Color.black)),
174               BorderFactory.createEmptyBorder(10, 10, 10, 10))));
175         
176         getContentPane().add(p);
177         pack();
178     }
179 }
180
Popular Tags