001: /*
002: * FindBugs - Find bugs in Java programs
003: * Copyright (C) 2003,2004 University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: /*
021: * AboutDialog.java
022: *
023: * Created on April 6, 2003, 7:05 PM
024: */
025:
026: package edu.umd.cs.findbugs.gui;
027:
028: import java.io.BufferedReader;
029: import java.io.IOException;
030: import java.io.InputStream;
031: import java.net.URL;
032: import java.text.MessageFormat;
033: import java.util.regex.Pattern;
034:
035: import javax.swing.JFrame;
036: import javax.swing.event.HyperlinkEvent;
037:
038: import edu.umd.cs.findbugs.L10N;
039: import edu.umd.cs.findbugs.Version;
040: import edu.umd.cs.findbugs.util.LaunchBrowser;
041: import edu.umd.cs.findbugs.util.Util;
042:
043: /**
044: * The Help:About dialog.
045: *
046: * @author David Hovemeyer
047: */
048: public class AboutDialog extends javax.swing.JDialog {
049: private static final long serialVersionUID = 3546076956480385584L;
050:
051: //private JFrame parent;
052:
053: /**
054: * Creates new form AboutDialog
055: */
056: public AboutDialog(JFrame parent, Logger l, boolean modal) {
057: super (parent, modal);
058: //this.parent = parent;
059:
060: initComponents();
061:
062: try {
063: aboutEditorPane.setPage(getClass().getClassLoader()
064: .getResource(
065: "edu/umd/cs/findbugs/gui/help/About.html"));
066: licenseEditorPane
067: .setPage(getClass()
068: .getClassLoader()
069: .getResource(
070: "edu/umd/cs/findbugs/gui/help/License.html"));
071: acknowldgementsEditorPane
072: .setPage(getClass()
073: .getClassLoader()
074: .getResource(
075: "edu/umd/cs/findbugs/gui/help/Acknowledgements.html"));
076: } catch (IOException e) {
077: l.logMessage(ConsoleLogger.ERROR, e.toString());
078: }
079:
080: setTitle(MessageFormat.format(L10N.getLocalString(
081: "dlg.aboutfindbugs_ttl", "About FindBugs {0}"),
082: new Object[] { Version.RELEASE }));
083: }
084:
085: static Pattern pattern = Pattern.compile("@VERSION@");
086:
087: /**
088: * Process an HTML page to replace certain substitution patterns.
089: * Right now, we just expand @VERSION@.
090: */
091: @edu.umd.cs.findbugs.annotations.SuppressWarnings("OS_OPEN_STREAM")
092: private void processPage(javax.swing.JEditorPane pane,
093: String fileName) throws IOException {
094: InputStream in = null;
095: BufferedReader reader = null;
096: try {
097: StringBuffer buf = new StringBuffer();
098:
099: // Open the file as a stream
100: in = getClass().getClassLoader().getResourceAsStream(
101: fileName);
102: if (in == null)
103: throw new IOException(MessageFormat.format(L10N
104: .getLocalString("msg.couldntload_txt",
105: "Couldn't load {0}"),
106: new Object[] { fileName }));
107: reader = new BufferedReader(Util.getReader(in));
108:
109: // Replace instances of @VERSION@ with actual version number
110:
111: String line;
112: while ((line = reader.readLine()) != null) {
113: line = pattern.matcher(line)
114: .replaceAll(Version.RELEASE);
115: buf.append(line);
116: buf.append('\n');
117: }
118:
119: // Load the page into the editor pane
120: String text = buf.toString();
121: pane.setContentType("text/html");
122: pane.setText(text);
123: } finally {
124: try {
125: if (reader != null)
126: reader.close();
127: else if (in != null)
128: in.close();
129: } catch (IOException e) {
130: }
131: }
132: }
133:
134: /**
135: * This method is called from within the constructor to
136: * initialize the form.
137: * WARNING: Do NOT modify this code. The content of this method is
138: * always regenerated by the Form Editor.
139: */
140: private void initComponents() {//GEN-BEGIN:initComponents
141: java.awt.GridBagConstraints gridBagConstraints;
142:
143: aboutTabPane = new javax.swing.JTabbedPane();
144: aboutScrollPane = new javax.swing.JScrollPane();
145: aboutEditorPane = new javax.swing.JEditorPane();
146: licenseScrollPane = new javax.swing.JScrollPane();
147: licenseEditorPane = new javax.swing.JEditorPane();
148: acknowledgmentsScrollPane = new javax.swing.JScrollPane();
149: acknowldgementsEditorPane = new javax.swing.JEditorPane();
150: jSeparator1 = new javax.swing.JSeparator();
151: okButton = new javax.swing.JButton();
152:
153: getContentPane().setLayout(new java.awt.GridBagLayout());
154:
155: addWindowListener(new java.awt.event.WindowAdapter() {
156: @Override
157: public void windowClosing(java.awt.event.WindowEvent evt) {
158: closeDialog(evt);
159: }
160: });
161:
162: aboutEditorPane.setEditable(false);
163: aboutEditorPane
164: .addHyperlinkListener(new javax.swing.event.HyperlinkListener() {
165: public void hyperlinkUpdate(
166: javax.swing.event.HyperlinkEvent evt) {
167: editorPaneHyperlinkUpdate(evt);
168: }
169: });
170:
171: aboutScrollPane.setViewportView(aboutEditorPane);
172:
173: aboutTabPane.addTab("About", aboutScrollPane);
174:
175: licenseEditorPane.setEditable(false);
176: licenseEditorPane
177: .addHyperlinkListener(new javax.swing.event.HyperlinkListener() {
178: public void hyperlinkUpdate(
179: javax.swing.event.HyperlinkEvent evt) {
180: editorPaneHyperlinkUpdate(evt);
181: }
182: });
183:
184: licenseScrollPane.setViewportView(licenseEditorPane);
185:
186: aboutTabPane.addTab("License", licenseScrollPane);
187:
188: acknowldgementsEditorPane.setEditable(false);
189: acknowldgementsEditorPane
190: .addHyperlinkListener(new javax.swing.event.HyperlinkListener() {
191: public void hyperlinkUpdate(
192: javax.swing.event.HyperlinkEvent evt) {
193: editorPaneHyperlinkUpdate(evt);
194: }
195: });
196:
197: acknowledgmentsScrollPane
198: .setViewportView(acknowldgementsEditorPane);
199:
200: aboutTabPane.addTab("Acknowledgments",
201: acknowledgmentsScrollPane);
202:
203: gridBagConstraints = new java.awt.GridBagConstraints();
204: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
205: gridBagConstraints.weightx = 1.0;
206: gridBagConstraints.weighty = 1.0;
207: getContentPane().add(aboutTabPane, gridBagConstraints);
208:
209: {
210: aboutTabPane.setTitleAt(0, L10N.getLocalString(
211: "dlg.about_tab", "About"));
212: aboutTabPane.setTitleAt(1, L10N.getLocalString(
213: "dlg.license_tab", "License"));
214: aboutTabPane.setTitleAt(2, L10N.getLocalString(
215: "dlg.acknowledgements_tab", "Acknowledgements"));
216: }
217: gridBagConstraints = new java.awt.GridBagConstraints();
218: gridBagConstraints.gridx = 0;
219: gridBagConstraints.gridy = 1;
220: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
221: getContentPane().add(jSeparator1, gridBagConstraints);
222:
223: okButton.setMnemonic('O');
224: okButton.setText("OK");
225: okButton.setText(L10N.getLocalString("dlg.ok_btn", "OK"));
226: okButton.addActionListener(new java.awt.event.ActionListener() {
227: public void actionPerformed(java.awt.event.ActionEvent evt) {
228: okButtonActionPerformed(evt);
229: }
230: });
231:
232: gridBagConstraints = new java.awt.GridBagConstraints();
233: gridBagConstraints.gridx = 0;
234: gridBagConstraints.gridy = 2;
235: gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 0);
236: getContentPane().add(okButton, gridBagConstraints);
237:
238: pack();
239: }//GEN-END:initComponents
240:
241: private void editorPaneHyperlinkUpdate(
242: javax.swing.event.HyperlinkEvent evt) {//GEN-FIRST:event_editorPaneHyperlinkUpdate
243: try {
244: if (evt.getEventType().equals(
245: HyperlinkEvent.EventType.ACTIVATED)) {
246: URL url = evt.getURL();
247: //showInBrowser(url.toString());
248: LaunchBrowser.showDocument(url);
249: }
250: } catch (Exception e) {
251: }
252: }//GEN-LAST:event_editorPaneHyperlinkUpdate
253:
254: private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
255: closeDialog();
256: }//GEN-LAST:event_okButtonActionPerformed
257:
258: /**
259: * Closes the dialog
260: */
261: private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
262: closeDialog();
263: }//GEN-LAST:event_closeDialog
264:
265: private void closeDialog() {
266: setVisible(false);
267: dispose();
268: }
269:
270: // Variables declaration - do not modify//GEN-BEGIN:variables
271: private javax.swing.JEditorPane aboutEditorPane;
272: private javax.swing.JScrollPane aboutScrollPane;
273: private javax.swing.JTabbedPane aboutTabPane;
274: private javax.swing.JEditorPane acknowldgementsEditorPane;
275: private javax.swing.JScrollPane acknowledgmentsScrollPane;
276: private javax.swing.JSeparator jSeparator1;
277: private javax.swing.JEditorPane licenseEditorPane;
278: private javax.swing.JScrollPane licenseScrollPane;
279: private javax.swing.JButton okButton;
280: // End of variables declaration//GEN-END:variables
281:
282: }
283:
284: // vim:ts=4
|