Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/batik/apps/svgbrowser/AboutDialog.java


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;
21  import java.awt.Color;
22  import java.awt.Dimension;
23  import java.awt.Frame;
24  import java.awt.Point;
25  import java.awt.Rectangle;
26  import java.awt.event.KeyAdapter;
27  import java.awt.event.KeyEvent;
28  import java.awt.event.MouseAdapter;
29  import java.awt.event.MouseEvent;
30  import java.net.URL;
31  
32  import javax.swing.BorderFactory;
33  import javax.swing.ImageIcon;
34  import javax.swing.JComponent;
35  import javax.swing.JLabel;
36  import javax.swing.JPanel;
37  import javax.swing.JTextArea;
38  import javax.swing.JWindow;
39  import javax.swing.SwingConstants;
40  import javax.swing.border.BevelBorder;
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 {
53  
54      public static final String ICON_BATIK_SPLASH 
55          = "AboutDialog.icon.batik.splash";
56  
57      public static final String ICON_APACHE_LOGO
58          = "AboutDialog.icon.apache.logo";
59  
60      public static final String LABEL_APACHE_BATIK_PROJECT
61          = "AboutDialog.label.apache.batik.project";
62  
63      public static final String 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 owner){
75          super(owner);
76          buildGUI();
77  
78          addKeyListener(new KeyAdapter(){
79                  public void keyPressed(KeyEvent e){
80                      if(e.getKeyCode() == KeyEvent.VK_ESCAPE){
81                          setVisible(false);
82                          dispose();
83                      }
84                  }
85              });
86  
87          addMouseListener(new MouseAdapter(){
88                  public void mousePressed(MouseEvent e){
89                      setVisible(false);
90                      dispose();
91                  }
92              });
93      }
94  
95      public void setLocationRelativeTo(Frame f) {
96          Dimension invokerSize = f.getSize();
97          Point loc = f.getLocation();
98          Point invokerScreenLocation = new Point(loc.x, loc.y);
99  
100         Rectangle bounds = getBounds();
101         int  dx = invokerScreenLocation.x+((invokerSize.width-bounds.width)/2);
102         int  dy = invokerScreenLocation.y+((invokerSize.height - bounds.height)/2);
103         Dimension 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 panel = new JPanel(new BorderLayout(5, 5));
124         panel.setBackground(Color.white);
125 
126         ClassLoader 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 url = cl.getResource(Resources.getString(ICON_APACHE_LOGO));
133         JLabel l = new JLabel(Resources.getString(LABEL_APACHE_BATIK_PROJECT),
134                               new ImageIcon(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(new ImageIcon(url)));
143 
144         //
145         // Add exact revision information
146         //
147         String tagName = Version.getVersion();
148 
149         panel.add(BorderLayout.SOUTH, new JLabel(tagName, SwingConstants.RIGHT));
150 
151         setBackground(Color.white);
152         getContentPane().setBackground(Color.white);
153 
154         JPanel p = new JPanel(new BorderLayout());
155         p.setBackground(Color.white);
156         p.add(panel, BorderLayout.CENTER);
157 
158         JTextArea contributors 
159             = new JTextArea(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)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 }