1 33 34 package edu.rice.cs.drjava.ui; 35 36 import edu.rice.cs.drjava.platform.PlatformFactory; 37 import edu.rice.cs.util.swing.*; 38 import edu.rice.cs.util.UnexpectedException; 39 import edu.rice.cs.util.StringOps; 40 import edu.rice.cs.drjava.DrJava; 41 import edu.rice.cs.drjava.Version; 42 import javax.swing.*; 43 import javax.swing.border.*; 44 import javax.swing.text.*; 45 import javax.swing.event.ChangeListener ; 46 import javax.swing.event.ChangeEvent ; 47 import java.awt.datatransfer.Clipboard ; 48 import java.awt.datatransfer.StringSelection ; 49 import java.awt.event.*; 50 import java.awt.*; 51 52 import java.io.*; 53 import java.net.URL ; 54 import java.util.Map ; 55 58 public class AboutDialog extends JDialog implements ActionListener { 59 60 private static ImageInfo CSLOGO = new ImageInfo("RiceCS.gif",new Color(0x423585)), 61 SF = new ImageInfo("SourceForge.gif",Color.black), 62 DRJAVA = new ImageInfo("DrJava.png",new Color(0xCCCCFF)); 63 64 private final JButton _okButton = new JButton("OK"); 65 66 67 private JButton _copyButton; 68 69 70 private JTable _propertiesTable; 71 72 73 private int _propertiesTabIndex; 74 75 76 private final JTabbedPane _tabs = new JTabbedPane(); 77 78 public AboutDialog(JFrame owner) { 79 super(owner, "About DrJava", true); 81 buildGUI(getContentPane()); 82 getRootPane().setDefaultButton(_okButton); 83 setSize(550, 400); 86 } 89 90 public void setVisible(boolean vis) { 91 _tabs.remove(0); 92 addTab(_tabs,"About",createCopyrightTab(), 0); 93 _tabs.setSelectedIndex(0); 94 95 if (vis) { 96 MainFrame.setPopupLoc(this, getOwner()); 100 } 101 super.setVisible(vis); 102 } 103 104 public void buildGUI(Container cp) { 105 cp.setLayout(new BorderLayout()); 106 JLabel drjava = createImageLabel(DRJAVA,JLabel.LEFT); 107 if (drjava != null) { 108 drjava.setBorder(new CompoundBorder(new EmptyBorder(5,5,5,5), drjava.getBorder())); 109 drjava.setCursor(new Cursor(Cursor.HAND_CURSOR)); 110 final String url = "http://drjava.org/"; 111 drjava.setToolTipText(url); 112 drjava.addMouseListener(new MouseListener() { 113 public void mousePressed(MouseEvent e) { } 114 public void mouseReleased(MouseEvent e) { } 115 public void mouseEntered(MouseEvent e) { } 116 public void mouseExited(MouseEvent e) { } 117 public void mouseClicked(MouseEvent e) { 118 try { 119 PlatformFactory.ONLY.openURL(new URL (url)); 120 } catch(Exception ex) { } 121 } 122 }); 123 124 JPanel djPanel = new JPanel(new GridLayout(1,1)); 125 djPanel.add(drjava); 126 djPanel.setBorder(new CompoundBorder(new EmptyBorder(5,5,5,5), new EtchedBorder())); 127 cp.add(djPanel,BorderLayout.NORTH); 128 } 129 addTab(_tabs,"About",createCopyrightTab()); 130 LICENSE = getLicense(); 131 if (LICENSE != null) addTab(_tabs,"DrJava License",createTextScroller(LICENSE)); 132 133 addTab(_tabs,"DynamicJava License",createTextScroller(DYADE_LICENSE)); 134 addTab(_tabs,"System Properties",createSysPropTab()); 135 _propertiesTabIndex = _tabs.getTabCount()-1; 136 cp.add(createBottomBar(),BorderLayout.SOUTH); 137 cp.add(_tabs,BorderLayout.CENTER); 138 } 139 140 private JComponent createSysPropTab() { 141 java.util.Properties props = System.getProperties(); 142 int size = props.size(); 143 String [][] rowData = new String [size][2]; 144 java.util.Iterator entries = props.entrySet().iterator(); 145 int rowNum = 0; 146 while (entries.hasNext()) { 147 Map.Entry entry = (Map.Entry ) entries.next(); 148 rowData[rowNum][0] = (String ) entry.getKey(); 149 rowData[rowNum][1] = (String ) entry.getValue(); 150 rowNum++; 151 } 152 java.util.Arrays.sort(rowData,new java.util.Comparator <String []>() { 153 public int compare(String [] o1, String [] o2) { 154 return o1[0].compareTo(o2[0]); 155 } 156 }); 157 String [] nvStrings = new String []{"Name","Value"}; 158 UneditableTableModel model = new UneditableTableModel(rowData, nvStrings); 159 _propertiesTable = new JTable(model); 160 JScrollPane scroller = new BorderlessScrollPane(_propertiesTable); 161 wrapBorder(scroller,new EmptyBorder(5,0,0,0)); 162 JPanel propTab = new JPanel(new BorderLayout()); 163 propTab.add(new JLabel("Current system properties:"),BorderLayout.NORTH); 164 propTab.add(scroller,BorderLayout.CENTER); 165 return propTab; 166 } 167 168 private static void addTab(JTabbedPane tabs, String title, JComponent tab) { 169 wrapBorder(tab,new EmptyBorder(5,6,6,5)); 170 tabs.addTab(title,tab); 171 } 172 173 private static void addTab(JTabbedPane tabs, String title, JComponent tab, int i) { 174 wrapBorder(tab,new EmptyBorder(5,6,6,5)); 175 tabs.insertTab(title, null, tab, "", i); 176 } 177 178 public static JComponent createCopyrightTab() { 179 final JPanel panel = new JPanel(new BorderLayout()); 180 181 final StringBuilder sb = new StringBuilder ("DrJava Version : "); 182 sb.append(Version.getBuildTimeString()); 183 sb.append("\n\nDrJava Configuration file: "); 184 sb.append(DrJava.getPropertiesFile().getAbsolutePath()); 185 sb.append("\n\nUsed memory: about "); 186 sb.append(StringOps.memSizeToString(Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())); 187 sb.append("\nFree memory: about "); 188 sb.append(StringOps.memSizeToString(Runtime.getRuntime().freeMemory())); 189 sb.append("\nTotal memory: about "); 190 sb.append(StringOps.memSizeToString(Runtime.getRuntime().totalMemory())); 191 sb.append("\nTotal memory can expand to: about "); 192 sb.append(StringOps.memSizeToString(Runtime.getRuntime().maxMemory())); 193 sb.append("\n\n"); 194 sb.append(COPYRIGHT); 195 final JComponent copy = createTextScroller(sb.toString()); 196 wrapBorder(copy,new EmptyBorder(0,0,5,0)); 197 198 final LogoList logos = new LogoList(); 200 logos.addLogo(createBorderedLabel(CSLOGO,new EmptyBorder(5,5,5,5)), "http://compsci.rice.edu/"); 201 logos.addLogo(createBorderedLabel(SF,null), "http://sourceforge.net/projects/drjava/"); 202 logos.resizeLogos(); 203 204 final JPanel logoPanel = new JPanel(); 206 logoPanel.setLayout(new BoxLayout(logoPanel,BoxLayout.X_AXIS)); 207 logoPanel.add(Box.createHorizontalGlue()); 208 java.util.Iterator it = logos.iterator(); 209 while(it.hasNext()) { 210 final JComponent l = (JComponent) it.next(); 211 logoPanel.add(l); 212 l.setCursor(new Cursor(Cursor.HAND_CURSOR)); 213 final String url = (String )l.getClientProperty("url"); 214 if (url != null) { 215 l.setToolTipText(url); 216 l.addMouseListener(new MouseListener() { 217 public void mousePressed(MouseEvent e) { } 218 public void mouseReleased(MouseEvent e) { } 219 public void mouseEntered(MouseEvent e) { } 220 public void mouseExited(MouseEvent e) { } 221 public void mouseClicked(MouseEvent e) { 222 try { PlatformFactory.ONLY.openURL(new URL (url)); } 223 catch(Exception ex) { } 224 } 225 }); 226 } 227 logoPanel.add(Box.createHorizontalGlue()); 228 } 229 panel.add(logoPanel,BorderLayout.SOUTH); 230 panel.add(copy,BorderLayout.CENTER); 231 return panel; 232 } 233 234 private static class LogoList extends java.util.LinkedList <JPanel> implements Serializable { 235 private int width = Integer.MIN_VALUE; 236 private int height = Integer.MIN_VALUE; 237 private void addLogo(JPanel logo, String url) { 238 if (logo != null) { 239 Dimension d = logo.getMinimumSize(); 240 width = Math.max(width,d.width); 241 height = Math.max(height,d.height); 242 add(logo); 243 if (url != null) logo.putClientProperty("url", url); 244 } 245 } 246 247 private void resizeLogos() { 248 java.util.Iterator it = iterator(); 249 Dimension d = new Dimension(width,height); 250 while(it.hasNext()) { 251 JComponent i = (JComponent) it.next(); 252 i.setMinimumSize(d); 253 i.setMaximumSize(d); 254 i.setPreferredSize(d); 255 } 256 } 257 } 258 259 public static JPanel createBorderedLabel(ImageInfo info, EmptyBorder pad) { 260 JLabel label = createImageLabel(info,JLabel.CENTER); 261 if (label == null) return null; 262 JPanel panel = new JPanel(new GridLayout(1,1)); 263 panel.setOpaque(true); 264 panel.setBackground(info.color); 265 panel.setBorder(pad); 266 wrapBorder(panel,new EtchedBorder()); 267 panel.add(label); 268 return panel; 269 } 270 271 public static JLabel createImageLabel(ImageInfo info, int align) { 272 ImageIcon icon = MainFrame.getIcon(info.name); 273 if (icon==null) return null; 274 JLabel label = new JLabel(icon,align); 275 label.setOpaque(true); 276 label.setBackground(info.color); 277 return label; 278 } 279 280 public static JTextArea createTextArea(String text) { 281 JTextArea textArea = new JTextArea(text); 282 textArea.setEditable(false); 283 textArea.setLineWrap(true); 284 textArea.setWrapStyleWord(true); 285 textArea.setCaretPosition(0); 286 return textArea; 287 } 288 289 public static JScrollPane createTextScroller(String text) { 290 return new BorderlessScrollPane(createTextArea(text)); 291 } 292 293 private JPanel createBottomBar() { 294 JPanel panel = new JPanel(new BorderLayout()); 295 JPanel buttonPanel = new JPanel(); 296 _copyButton = new JButton(new AbstractAction("Copy System Properties") { 297 public void actionPerformed(ActionEvent e) { 298 Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); 299 StringSelection contents = new StringSelection (DrJavaErrorWindow.getSystemAndDrJavaInfo()); 300 cb.setContents(contents, null); 301 } 302 }); 303 _tabs.addChangeListener(new ChangeListener () { 304 public void stateChanged(ChangeEvent evt) { 306 _copyButton.setVisible(_tabs.getSelectedIndex()==_propertiesTabIndex); 307 } 308 }); 309 _copyButton.setVisible(_tabs.getSelectedIndex()==_propertiesTabIndex); 310 _okButton.addActionListener(this); 311 buttonPanel.add(_copyButton); 312 buttonPanel.add(_okButton); 313 panel.add(buttonPanel,BorderLayout.EAST); 314 wrapBorder(panel,new EmptyBorder(5,5,5,5)); 315 return panel; 316 } 317 318 public void actionPerformed(ActionEvent e) { 319 setVisible(false); 320 } 321 322 public static final String COPYRIGHT = 323 "Copyright \u00a9 2001-2006 JavaPLT group at Rice University\n"+ 324 "(javaplt@rice.edu)\n\n"+ 325 "See http://www.drjava.org for more information on DrJava or to\n"+ 326 "obtain the latest version of the program or its source code.\n\n"+ 327 "DrJava is free software; you can redistribute it and/or modify\n"+ 328 "it under the terms of the DrJava Open Source License. A copy\n"+ 329 "of the license should have been included in the documentation\n"+ 330 "for this software."; 331 private static String LICENSE; 332 private static boolean initLicense = false; 333 public static final String DYADE_LICENSE = 334 "DynamicJava - Copyright \u00a9 1999 Dyade\n\nPermission is hereby granted,"+ 335 " free of charge, to any person obtaining a copy of this software and associated"+ 336 " documentation files (the \"Software\"), to deal in the Software without restriction,"+ 337 " including without limitation the rights to use, copy, modify, merge, publish, distribute,"+ 338 " sublicense, and/or sell copies of the Software, and to permit persons to whom the Software"+ 339 " is furnished to do so, subject to the following conditions:\n\n"+ 340 "The above copyright notice and this permission notice shall be included in all copies or"+ 341 " substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY"+ 342 " OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,"+ 343 " FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL DYADE BE LIABLE FOR ANY CLAIM,"+ 344 " DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT"+ 345 " OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n"+ 346 "Except as contained in this notice, the name of Dyade shall not be used in advertising or otherwise"+ 347 " to promote the sale, use or other dealings in this Software without prior written authorization from Dyade."; 348 public static final String INTRODUCTION = 349 "DrJava is a pedagogic programming environment for Java, intended to help students focus more on program"+ 350 " design than on the features of a complicated development environment. It provides an Interactions"+ 351 " window based on a \"read-eval-print loop\", which allows programmers to develop, test, and debug"+ 352 " Java programs in an interactive, incremental fashion.\n\n"+ 353 "Home Page: http://www.drjava.org\nPaper: http://drjava.sf.net/papers/drjava-paper.shtml"; 354 355 public static class ImageInfo { 356 private final String name; 357 private final Color color; 358 public ImageInfo(String name, Color color) { 359 this.name = name; 360 this.color = color; 361 } 362 } 363 364 public static String getLicense() { 365 if (initLicense) return LICENSE; 366 367 try { 368 InputStream is = AboutDialog.class.getResourceAsStream("/edu/rice/cs/LICENSE"); 369 if (is != null) { 370 BufferedReader r = new BufferedReader(new InputStreamReader(is)); 371 try { 372 373 final StringBuilder sb = new StringBuilder (); 374 for (String s = r.readLine(); s != null; s = r.readLine()) { 375 int lastSig = s.length()-1; 377 while (lastSig >= 0 && Character.isWhitespace(s.charAt(lastSig))) lastSig--; 378 if (lastSig < 0) sb.append("\n"); else { 380 sb.append(s.substring(0,lastSig+1)); 381 sb.append('\n'); 382 } 383 } 384 LICENSE = sb.toString(); 385 LICENSE = LICENSE.trim(); 386 if (LICENSE.length() == 0) LICENSE = null; 387 } 388 finally { 389 is.close(); 390 r.close(); 391 } 392 } 393 } 394 catch(Exception e) { throw new UnexpectedException(e, StringOps.getStackTrace(e)); } 395 396 initLicense = true; 397 return LICENSE; 398 } 399 400 private static void wrapBorder(JComponent c, Border b) { 401 c.setBorder(new CompoundBorder(b,c.getBorder())); 402 } 403 } 404 | Popular Tags |