KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectstyle > cayenne > modeler > dialog > AboutDialog


1 /* ====================================================================
2  *
3  * The ObjectStyle Group Software License, version 1.1
4  * ObjectStyle Group - http://objectstyle.org/
5  *
6  * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
7  * of the software. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if any,
22  * must include the following acknowlegement:
23  * "This product includes software developed by independent contributors
24  * and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
25  * Alternately, this acknowlegement may appear in the software itself,
26  * if and wherever such third-party acknowlegements normally appear.
27  *
28  * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
29  * or promote products derived from this software without prior written
30  * permission. For written permission, email
31  * "andrus at objectstyle dot org".
32  *
33  * 5. Products derived from this software may not be called "ObjectStyle"
34  * or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
35  * names without prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals and hosted on ObjectStyle Group web site. For more
53  * information on the ObjectStyle Group, please see
54  * <http://objectstyle.org/>.
55  */

56
57 package org.objectstyle.cayenne.modeler.dialog;
58
59 import java.awt.BorderLayout JavaDoc;
60 import java.awt.Color JavaDoc;
61 import java.awt.Dimension JavaDoc;
62 import java.awt.FlowLayout JavaDoc;
63 import java.awt.event.ActionEvent JavaDoc;
64 import java.awt.event.ActionListener JavaDoc;
65 import java.io.BufferedReader JavaDoc;
66 import java.io.IOException JavaDoc;
67 import java.io.InputStream JavaDoc;
68 import java.io.InputStreamReader JavaDoc;
69
70 import javax.swing.ImageIcon JavaDoc;
71 import javax.swing.JButton JavaDoc;
72 import javax.swing.JComponent JavaDoc;
73 import javax.swing.JDialog JavaDoc;
74 import javax.swing.JEditorPane JavaDoc;
75 import javax.swing.JLabel JavaDoc;
76 import javax.swing.JPanel JavaDoc;
77 import javax.swing.JScrollPane JavaDoc;
78 import javax.swing.JTabbedPane JavaDoc;
79 import javax.swing.JTextArea JavaDoc;
80
81 import org.objectstyle.cayenne.modeler.CayenneModelerFrame;
82 import org.objectstyle.cayenne.modeler.util.CayenneDialog;
83 import org.objectstyle.cayenne.modeler.util.CayenneWidgetFactory;
84 import org.objectstyle.cayenne.modeler.util.ModelerUtil;
85 import org.scopemvc.util.UIStrings;
86
87 /**
88  * Displays the Cayenne license and build information.
89  */

90 // Implementation note - the data displayed here is
91
// static and very simple, so there is no need to implement complex Scope MVC
92
// triad, though it might be beneficial to use strings file
93
public class AboutDialog extends CayenneDialog {
94
95     private static String JavaDoc licenseString;
96     private static String JavaDoc infoString;
97     private static ImageIcon JavaDoc logoImage;
98     private static final Dimension JavaDoc infoAreaSize = new Dimension JavaDoc(450, 350);
99
100     static synchronized ImageIcon JavaDoc getLogoImage() {
101         if (logoImage == null) {
102             logoImage = ModelerUtil.buildIcon("logo.jpg");
103         }
104         return logoImage;
105     }
106
107     /**
108      * Builds and returns CayenneModeler info string.
109      */

110     static synchronized String JavaDoc getInfoString() {
111         if (infoString == null) {
112             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
113
114             buffer.append("<font size='-1' face='Arial,Helvetica'>");
115             buffer.append(UIStrings.get("cayenne.modeler.about.info"));
116             buffer.append("</font>");
117             buffer.append("<font size='-2' face='Arial,Helvetica'>");
118
119             String JavaDoc version = UIStrings.get("cayenne.version");
120             if (version != null) {
121                 buffer.append("<br>Version: ").append(version);
122             }
123
124             String JavaDoc buildDate = UIStrings.get("cayenne.build.date");
125             if (buildDate != null) {
126                 buffer.append(" (").append(buildDate).append(")");
127             }
128
129             buffer.append("</font>");
130             infoString = buffer.toString();
131         }
132
133         return infoString;
134     }
135
136     /**
137      * Reads Cayenne license from cayenne.jar file and returns it as a string.
138      */

139     static synchronized String JavaDoc getLicenseString() {
140         if (licenseString == null) {
141             BufferedReader JavaDoc in = null;
142             try {
143                 InputStream JavaDoc licenseIn =
144                     AboutDialog.class.getClassLoader().getResourceAsStream(
145                         "META-INF/LICENSE");
146
147                 if (licenseIn != null) {
148                     in = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(licenseIn));
149                     String JavaDoc line = null;
150                     StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
151
152                     while ((line = in.readLine()) != null) {
153                         // strip comments
154
if (line.startsWith("/*") || line.startsWith(" */")) {
155                             continue;
156                         }
157
158                         // strip separators
159
if (line.indexOf("=================") >= 0) {
160                             continue;
161                         }
162
163                         // strip beginning of the line
164
if (line.startsWith(" *")) {
165                             line = line.substring(2);
166                         }
167
168                         buf.append(line).append('\n');
169                     }
170
171                     licenseString = buf.toString();
172                 }
173
174             }
175             catch (IOException JavaDoc ioex) {
176                 // ignoring
177
}
178             finally {
179                 if (in != null) {
180                     try {
181                         in.close();
182                     }
183                     catch (IOException JavaDoc ioex) {
184                         // ignoring
185
}
186                 }
187             }
188
189             // if license is not initialized for whatever reason,
190
// send them to the website
191
if (licenseString == null) {
192                 licenseString =
193                     "Latest Cayenne license can be found at http://objectstyle.org/cayenne/";
194             }
195         }
196
197         return licenseString;
198     }
199
200     public AboutDialog(CayenneModelerFrame frame) {
201         super(frame, "About CayenneModeler", true);
202         init();
203
204         this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
205         this.pack();
206         this.centerWindow();
207         this.setVisible(true);
208     }
209
210     /**
211      * Sets up the graphical components.
212      */

213     private void init() {
214
215         // create widgets
216
JButton JavaDoc okButton = CayenneWidgetFactory.createButton("Close");
217         okButton.addActionListener(new ActionListener JavaDoc() {
218             public void actionPerformed(ActionEvent JavaDoc e) {
219                 AboutDialog.this.dispose();
220             }
221         });
222
223         // assemble info section
224
JTabbedPane JavaDoc tabPanel = new JTabbedPane JavaDoc() {
225
226             public Dimension JavaDoc getPreferredSize() {
227                 return infoAreaSize;
228             }
229         };
230
231         tabPanel.setTabPlacement(JTabbedPane.TOP);
232         tabPanel.addTab("About CayenneModeler", new JScrollPane JavaDoc(initInfoPanel()));
233         tabPanel.addTab("License", new JScrollPane JavaDoc(initLicensePanel()));
234
235         // assemble button
236
JPanel JavaDoc buttonPanel = new JPanel JavaDoc(new FlowLayout JavaDoc(FlowLayout.RIGHT));
237         buttonPanel.add(okButton);
238
239         // assemble dialog
240
getContentPane().setLayout(new BorderLayout JavaDoc());
241         getContentPane().add(tabPanel, BorderLayout.CENTER);
242         getContentPane().add(buttonPanel, BorderLayout.SOUTH);
243     }
244
245     private JComponent JavaDoc initInfoPanel() {
246
247         JLabel JavaDoc image = new JLabel JavaDoc(getLogoImage());
248         image.setBounds(4, 4, 4, 4);
249
250         JEditorPane JavaDoc infoPanel = new JEditorPane JavaDoc("text/html", getInfoString());
251         infoPanel.setEditable(false);
252         infoPanel.addHyperlinkListener(this);
253         infoPanel.setBackground(getParent().getBackground());
254
255         JPanel JavaDoc panel = new JPanel JavaDoc();
256         panel.setLayout(new BorderLayout JavaDoc(10, 10));
257
258         panel.add(image, BorderLayout.NORTH);
259         panel.add(infoPanel, BorderLayout.CENTER);
260
261         return panel;
262     }
263
264     private JComponent JavaDoc initLicensePanel() {
265         JTextArea JavaDoc licenseText = new JTextArea JavaDoc(getLicenseString());
266
267         licenseText.setBackground(Color.WHITE);
268         licenseText.setEditable(false);
269         licenseText.setLineWrap(true);
270         licenseText.setWrapStyleWord(true);
271
272         return licenseText;
273     }
274 }
Popular Tags