1 21 22 package org.armedbear.j; 23 24 import java.io.BufferedReader ; 25 import java.io.IOException ; 26 import java.io.InputStreamReader ; 27 import java.text.SimpleDateFormat ; 28 import java.util.Date ; 29 import javax.swing.Box ; 30 import javax.swing.JPanel ; 31 32 public class AboutDialog extends AbstractDialog 33 { 34 private long totalMemory; 35 private long freeMemory; 36 37 public AboutDialog() 38 { 39 super(Editor.getCurrentFrame(), "About J", true); 40 Editor.getCurrentFrame().setWaitCursor(); 41 memory(); 42 JPanel panel = Utilities.createPanel("J"); 43 mainPanel.add(panel); 44 String longVersionString = Version.getLongVersionString(); 45 if (longVersionString != null) 46 addStaticText(panel, longVersionString); 47 String snapshotInformation = Version.getSnapshotInformation(); 48 if (snapshotInformation != null) 49 addStaticText(panel, snapshotInformation); 50 addStaticText(panel, 51 "Copyright (C) 1998-2004 Peter Graves (peter@armedbear.org)"); 52 addStaticText(panel, 53 "J is free software; see the source for copying conditions."); 54 addStaticText(panel, "There is ABSOLUTELY NO WARRANTY."); 55 addStaticText(panel, "The latest version of j is available from:"); 56 addStaticText(panel, " http://armedbear.org"); 57 addStaticText(panel, "Please report bugs to:"); 58 addStaticText(panel, " armedbear-j-devel@lists.sourceforge.net"); 59 addStaticText(panel, getUptimeString()); 60 panel = Utilities.createPanel("System Information"); 61 addVerticalStrut(); 62 mainPanel.add(panel); 63 FastStringBuffer sb = new FastStringBuffer("Java "); 64 sb.append(System.getProperty("java.version")); 65 sb.append(' '); 66 sb.append(System.getProperty("java.vendor")); 67 addStaticText(panel, sb.toString()); 68 String fullversion = System.getProperty("java.fullversion"); 70 if (fullversion != null) 71 addStaticText(panel, fullversion); 72 String vm = System.getProperty("java.vm.name"); 73 if (vm != null) 74 addStaticText(panel, vm); 75 Log.debug("total memory " + totalMemory); 76 Log.debug("used " + (totalMemory - freeMemory)); 77 Log.debug("free " + freeMemory); 78 sb.setLength(0); 79 sb.append(formatMemory(totalMemory)); 80 sb.append(" total Java memory ("); 81 sb.append(formatMemory(totalMemory - freeMemory)); 82 sb.append(" used, "); 83 sb.append(formatMemory(freeMemory)); 84 sb.append(" free)"); 85 addStaticText(panel, sb.toString()); 86 sb.setLength(0); 87 sb.append(System.getProperty("os.name")); 88 sb.append(' '); 89 sb.append(System.getProperty("os.version")); 90 addStaticText(panel, sb.toString()); 91 addVerticalStrut(); 92 addOK(); 93 pack(); 94 okButton.requestFocus(); 95 Editor.getCurrentFrame().setDefaultCursor(); 96 } 97 98 private static String getUptimeString() 99 { 100 final int millisecondsPerMinute = 60 * 1000; 101 final int millisecondsPerHour = 60 * millisecondsPerMinute; 102 final int millisecondsPerDay = 24 * millisecondsPerHour; 103 104 long now = System.currentTimeMillis(); 105 SimpleDateFormat dateFormatter = new SimpleDateFormat ("EEEE MMM d yyyy h:mm a"); 106 String dateString = dateFormatter.format(new Date (now)); 107 long uptime = now - Editor.getStartTimeMillis(); 108 109 if (uptime < millisecondsPerMinute) 111 return dateString; 112 113 int days = (int) (uptime / millisecondsPerDay); 114 int remainder = (int) (uptime % millisecondsPerDay); 115 int hours = remainder / millisecondsPerHour; 116 remainder = remainder % millisecondsPerHour; 117 int minutes = remainder / millisecondsPerMinute; 118 119 FastStringBuffer sb = new FastStringBuffer(dateString); 120 sb.append(" up "); 121 if (uptime < millisecondsPerHour) { 122 sb.append(minutes); 123 sb.append(" minute"); 124 if (minutes > 1) 125 sb.append('s'); 126 } else { 127 if (days > 0) { 128 sb.append(days); 129 sb.append(" day"); 130 if (days > 1) 131 sb.append('s'); 132 sb.append(", "); 133 } 134 sb.append(hours); 135 sb.append(':'); 136 if (minutes < 10) 137 sb.append('0'); 138 sb.append(minutes); 139 } 140 return sb.toString(); 141 } 142 143 private void addStaticText(JPanel panel, String s) 144 { 145 panel.add(Box.createVerticalStrut(6)); 146 panel.add(new StaticTextField(s)); 147 } 148 149 private void memory() 150 { 151 Runtime runtime = Runtime.getRuntime(); 152 try { 153 runtime.gc(); 154 Thread.currentThread().sleep(100); 155 runtime.runFinalization(); 156 Thread.currentThread().sleep(100); 157 runtime.gc(); 158 Thread.currentThread().sleep(100); 159 } 160 catch (InterruptedException e) { 161 Log.error(e); 162 } 163 totalMemory = runtime.totalMemory(); 164 freeMemory = runtime.freeMemory(); 165 } 166 167 private String formatMemory(long value) 168 { 169 if (value < 1000) { 170 return String.valueOf(value) + " bytes"; 171 } else if (value < 1000 * 1024) { 172 double k = Math.round(value * 10 / (float) 1024) / 10.0; 173 return String.valueOf(k) + "K"; 174 } else if (value < 1000 * 1024 * 1024) { 175 double m = Math.round(value * 10 / (float) (1024 * 1024)) / 10.0; 176 return String.valueOf(m) + "M"; 177 } else { 178 double g = Math.round(value * 10 / (float) (1024 * 1024 * 1024)) / 10.0; 179 return String.valueOf(g) + "G"; 180 } 181 } 182 183 private int parseInteger(String s, String caption) throws Exception 184 { 185 int index = s.indexOf(caption); 186 if (index < 0) 187 throw new Exception (); 188 index += caption.length(); 189 while (Character.isWhitespace(s.charAt(index))) 190 ++index; 191 return Utilities.parseInt(s.substring(index)); 192 } 193 194 public static void about() 195 { 196 AboutDialog d = new AboutDialog(); 197 Editor.currentEditor().centerDialog(d); 198 d.show(); 199 } 200 } 201 | Popular Tags |