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