1 56 57 package org.objectstyle.cayenne.modeler.dialog; 58 59 import java.awt.BorderLayout ; 60 import java.awt.Color ; 61 import java.awt.Dimension ; 62 import java.awt.FlowLayout ; 63 import java.awt.event.ActionEvent ; 64 import java.awt.event.ActionListener ; 65 import java.io.BufferedReader ; 66 import java.io.IOException ; 67 import java.io.InputStream ; 68 import java.io.InputStreamReader ; 69 70 import javax.swing.ImageIcon ; 71 import javax.swing.JButton ; 72 import javax.swing.JComponent ; 73 import javax.swing.JDialog ; 74 import javax.swing.JEditorPane ; 75 import javax.swing.JLabel ; 76 import javax.swing.JPanel ; 77 import javax.swing.JScrollPane ; 78 import javax.swing.JTabbedPane ; 79 import javax.swing.JTextArea ; 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 90 public class AboutDialog extends CayenneDialog { 94 95 private static String licenseString; 96 private static String infoString; 97 private static ImageIcon logoImage; 98 private static final Dimension infoAreaSize = new Dimension (450, 350); 99 100 static synchronized ImageIcon getLogoImage() { 101 if (logoImage == null) { 102 logoImage = ModelerUtil.buildIcon("logo.jpg"); 103 } 104 return logoImage; 105 } 106 107 110 static synchronized String getInfoString() { 111 if (infoString == null) { 112 StringBuffer buffer = new StringBuffer (); 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 version = UIStrings.get("cayenne.version"); 120 if (version != null) { 121 buffer.append("<br>Version: ").append(version); 122 } 123 124 String 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 139 static synchronized String getLicenseString() { 140 if (licenseString == null) { 141 BufferedReader in = null; 142 try { 143 InputStream licenseIn = 144 AboutDialog.class.getClassLoader().getResourceAsStream( 145 "META-INF/LICENSE"); 146 147 if (licenseIn != null) { 148 in = new BufferedReader (new InputStreamReader (licenseIn)); 149 String line = null; 150 StringBuffer buf = new StringBuffer (); 151 152 while ((line = in.readLine()) != null) { 153 if (line.startsWith("/*") || line.startsWith(" */")) { 155 continue; 156 } 157 158 if (line.indexOf("=================") >= 0) { 160 continue; 161 } 162 163 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 ioex) { 176 } 178 finally { 179 if (in != null) { 180 try { 181 in.close(); 182 } 183 catch (IOException ioex) { 184 } 186 } 187 } 188 189 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 213 private void init() { 214 215 JButton okButton = CayenneWidgetFactory.createButton("Close"); 217 okButton.addActionListener(new ActionListener () { 218 public void actionPerformed(ActionEvent e) { 219 AboutDialog.this.dispose(); 220 } 221 }); 222 223 JTabbedPane tabPanel = new JTabbedPane () { 225 226 public Dimension getPreferredSize() { 227 return infoAreaSize; 228 } 229 }; 230 231 tabPanel.setTabPlacement(JTabbedPane.TOP); 232 tabPanel.addTab("About CayenneModeler", new JScrollPane (initInfoPanel())); 233 tabPanel.addTab("License", new JScrollPane (initLicensePanel())); 234 235 JPanel buttonPanel = new JPanel (new FlowLayout (FlowLayout.RIGHT)); 237 buttonPanel.add(okButton); 238 239 getContentPane().setLayout(new BorderLayout ()); 241 getContentPane().add(tabPanel, BorderLayout.CENTER); 242 getContentPane().add(buttonPanel, BorderLayout.SOUTH); 243 } 244 245 private JComponent initInfoPanel() { 246 247 JLabel image = new JLabel (getLogoImage()); 248 image.setBounds(4, 4, 4, 4); 249 250 JEditorPane infoPanel = new JEditorPane ("text/html", getInfoString()); 251 infoPanel.setEditable(false); 252 infoPanel.addHyperlinkListener(this); 253 infoPanel.setBackground(getParent().getBackground()); 254 255 JPanel panel = new JPanel (); 256 panel.setLayout(new BorderLayout (10, 10)); 257 258 panel.add(image, BorderLayout.NORTH); 259 panel.add(infoPanel, BorderLayout.CENTER); 260 261 return panel; 262 } 263 264 private JComponent initLicensePanel() { 265 JTextArea licenseText = new JTextArea (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 |