1 19 20 25 26 package edu.umd.cs.findbugs.gui2; 27 28 import java.io.BufferedReader ; 29 import java.io.IOException ; 30 import java.io.InputStream ; 31 import java.io.InputStreamReader ; 32 import java.net.URL ; 33 import java.text.MessageFormat ; 34 import java.util.regex.Pattern ; 35 36 import javax.swing.JFrame ; 37 import javax.swing.event.HyperlinkEvent ; 38 39 import edu.umd.cs.findbugs.SystemProperties; 40 import edu.umd.cs.findbugs.Version; 41 import edu.umd.cs.findbugs.gui.ConsoleLogger; 42 import edu.umd.cs.findbugs.gui.Logger; 43 import edu.umd.cs.findbugs.util.LaunchBrowser; 44 45 50 public class AboutDialog extends javax.swing.JDialog { 51 private static final long serialVersionUID = 3546076956480385584L; 52 53 55 58 public AboutDialog(JFrame parent, Logger l, boolean modal) { 59 super(parent, modal); 60 62 initComponents(); 63 64 try { 65 aboutEditorPane.setPage(AboutDialog.class.getResource("help/About.html")); 66 licenseEditorPane.setPage(AboutDialog.class.getResource("help/License.html")); 67 acknowldgementsEditorPane.setPage(AboutDialog.class.getResource("help/Acknowledgements.html")); 68 } catch (IOException e) { 69 l.logMessage(ConsoleLogger.ERROR, e.toString()); 70 } 71 72 setTitle(MessageFormat.format(edu.umd.cs.findbugs.L10N.getLocalString("dlg.aboutfindbugs_ttl", "About FindBugs {0}"), new Object []{Version.RELEASE})); 73 } 74 75 static Pattern pattern = Pattern.compile("@VERSION@"); 76 80 @edu.umd.cs.findbugs.annotations.SuppressWarnings("OS_OPEN_STREAM") 81 private void processPage(javax.swing.JEditorPane pane, String fileName) throws IOException { 82 InputStream in = null; 83 BufferedReader reader = null; 84 try { 85 StringBuffer buf = new StringBuffer (); 86 87 in = getClass().getClassLoader().getResourceAsStream(fileName); 89 if (in == null) 90 throw new IOException (MessageFormat.format(edu.umd.cs.findbugs.L10N.getLocalString("msg.couldntload_txt", "Couldn't load {0}"), new Object []{fileName})); 91 reader = new BufferedReader (new InputStreamReader (in)); 92 93 95 String line; 96 while ((line = reader.readLine()) != null) { 97 line = pattern.matcher(line).replaceAll(Version.RELEASE); 98 buf.append(line); 99 buf.append('\n'); 100 } 101 102 String text = buf.toString(); 104 pane.setContentType("text/html"); 105 pane.setText(text); 106 } finally { 107 try { 108 if (reader != null) 109 reader.close(); 110 else if (in != null) 111 in.close(); 112 } catch (IOException e) { 113 } 114 } 115 } 116 117 123 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 125 126 aboutTabPane = new javax.swing.JTabbedPane (); 127 aboutScrollPane = new javax.swing.JScrollPane (); 128 aboutEditorPane = new javax.swing.JEditorPane (); 129 licenseScrollPane = new javax.swing.JScrollPane (); 130 licenseEditorPane = new javax.swing.JEditorPane (); 131 acknowledgmentsScrollPane = new javax.swing.JScrollPane (); 132 acknowldgementsEditorPane = new javax.swing.JEditorPane (); 133 jSeparator1 = new javax.swing.JSeparator (); 134 okButton = new javax.swing.JButton (); 135 136 getContentPane().setLayout(new java.awt.GridBagLayout ()); 137 138 addWindowListener(new java.awt.event.WindowAdapter () { 139 @Override 140 public void windowClosing(java.awt.event.WindowEvent evt) { 141 closeDialog(evt); 142 } 143 }); 144 145 aboutEditorPane.setEditable(false); 146 aboutEditorPane.addHyperlinkListener(new javax.swing.event.HyperlinkListener () { 147 public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) { 148 editorPaneHyperlinkUpdate(evt); 149 } 150 }); 151 152 aboutScrollPane.setViewportView(aboutEditorPane); 153 154 aboutTabPane.addTab("About", aboutScrollPane); 155 156 licenseEditorPane.setEditable(false); 157 licenseEditorPane.addHyperlinkListener(new javax.swing.event.HyperlinkListener () { 158 public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) { 159 editorPaneHyperlinkUpdate(evt); 160 } 161 }); 162 163 licenseScrollPane.setViewportView(licenseEditorPane); 164 165 aboutTabPane.addTab("License", licenseScrollPane); 166 167 acknowldgementsEditorPane.setEditable(false); 168 acknowldgementsEditorPane.addHyperlinkListener(new javax.swing.event.HyperlinkListener () { 169 public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) { 170 editorPaneHyperlinkUpdate(evt); 171 } 172 }); 173 174 acknowledgmentsScrollPane.setViewportView(acknowldgementsEditorPane); 175 176 aboutTabPane.addTab("Acknowledgments", acknowledgmentsScrollPane); 177 178 gridBagConstraints = new java.awt.GridBagConstraints (); 179 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 180 gridBagConstraints.weightx = 1.0; 181 gridBagConstraints.weighty = 1.0; 182 getContentPane().add(aboutTabPane, gridBagConstraints); 183 184 { 185 aboutTabPane.setTitleAt(0, edu.umd.cs.findbugs.L10N.getLocalString("dlg.about_tab", "About")); 186 aboutTabPane.setTitleAt(1, edu.umd.cs.findbugs.L10N.getLocalString("dlg.license_tab", "License")); 187 aboutTabPane.setTitleAt(2, edu.umd.cs.findbugs.L10N.getLocalString("dlg.acknowledgements_tab", "Acknowledgements")); 188 } 189 gridBagConstraints = new java.awt.GridBagConstraints (); 190 gridBagConstraints.gridx = 0; 191 gridBagConstraints.gridy = 1; 192 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 193 getContentPane().add(jSeparator1, gridBagConstraints); 194 195 okButton.setMnemonic('O'); 196 okButton.setText("OK"); 197 okButton.setText(edu.umd.cs.findbugs.L10N.getLocalString("dlg.ok_btn", "OK")); 198 okButton.addActionListener(new java.awt.event.ActionListener () { 199 public void actionPerformed(java.awt.event.ActionEvent evt) { 200 okButtonActionPerformed(evt); 201 } 202 }); 203 204 gridBagConstraints = new java.awt.GridBagConstraints (); 205 gridBagConstraints.gridx = 0; 206 gridBagConstraints.gridy = 2; 207 gridBagConstraints.insets = new java.awt.Insets (3, 0, 3, 0); 208 getContentPane().add(okButton, gridBagConstraints); 209 210 pack(); 211 } 213 static void editorPaneHyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) { try { 215 if (evt.getEventType().equals( HyperlinkEvent.EventType.ACTIVATED)) { 216 URL url = evt.getURL(); 217 LaunchBrowser.showDocument(url); 219 } 220 } 221 catch (Exception e) { 222 } 223 } 225 226 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) { closeDialog(); 228 } 230 233 private void closeDialog(java.awt.event.WindowEvent evt) { closeDialog(); 235 } 237 private void closeDialog() { 238 setVisible(false); 239 dispose(); 240 } 241 242 private javax.swing.JEditorPane aboutEditorPane; 244 private javax.swing.JScrollPane aboutScrollPane; 245 private javax.swing.JTabbedPane aboutTabPane; 246 private javax.swing.JEditorPane acknowldgementsEditorPane; 247 private javax.swing.JScrollPane acknowledgmentsScrollPane; 248 private javax.swing.JSeparator jSeparator1; 249 private javax.swing.JEditorPane licenseEditorPane; 250 private javax.swing.JScrollPane licenseScrollPane; 251 private javax.swing.JButton okButton; 252 254 } 255 256 | Popular Tags |