1 45 46 package org.jfree.ui.about; 47 48 import java.util.Collections ; 49 import java.util.Comparator ; 50 import java.util.Iterator ; 51 import java.util.List ; 52 import java.util.Properties ; 53 import java.util.ResourceBundle ; 54 55 import org.jfree.ui.SortableTableModel; 56 57 62 public class SystemPropertiesTableModel extends SortableTableModel { 63 64 68 protected static class SystemProperty { 69 70 71 private String name; 72 73 74 private String value; 75 76 82 public SystemProperty(final String name, final String value) { 83 this.name = name; 84 this.value = value; 85 } 86 87 92 public String getName() { 93 return this.name; 94 } 95 96 101 public String getValue() { 102 return this.value; 103 } 104 105 } 106 107 111 protected static class SystemPropertyComparator implements Comparator { 112 113 114 private boolean ascending; 115 116 121 public SystemPropertyComparator(final boolean ascending) { 122 this.ascending = ascending; 123 } 124 125 133 public int compare(final Object o1, final Object o2) { 134 135 if ((o1 instanceof SystemProperty) && (o2 instanceof SystemProperty)) { 136 final SystemProperty sp1 = (SystemProperty) o1; 137 final SystemProperty sp2 = (SystemProperty) o2; 138 if (this.ascending) { 139 return sp1.getName().compareTo(sp2.getName()); 140 } 141 else { 142 return sp2.getName().compareTo(sp1.getName()); 143 } 144 } 145 else { 146 return 0; 147 } 148 149 } 150 151 159 public boolean equals(final Object o) { 160 if (this == o) { 161 return true; 162 } 163 if (!(o instanceof SystemPropertyComparator)) { 164 return false; 165 } 166 167 final SystemPropertyComparator systemPropertyComparator = (SystemPropertyComparator) o; 168 169 if (this.ascending != systemPropertyComparator.ascending) { 170 return false; 171 } 172 173 return true; 174 } 175 176 181 public int hashCode() { 182 return (this.ascending ? 1 : 0); 183 } 184 } 185 186 187 private List properties; 188 189 190 private String nameColumnLabel; 191 192 193 private String valueColumnLabel; 194 195 198 public SystemPropertiesTableModel() { 199 200 this.properties = new java.util.ArrayList (); 201 try { 202 final Properties p = System.getProperties(); 203 final Iterator iterator = p.keySet().iterator(); 204 while (iterator.hasNext()) { 205 final String name = (String ) iterator.next(); 206 final String value = System.getProperty(name); 207 final SystemProperty sp = new SystemProperty(name, value); 208 this.properties.add(sp); 209 } 210 } 211 catch (SecurityException se) { 212 } 214 215 Collections.sort(this.properties, new SystemPropertyComparator(true)); 216 217 final String baseName = "org.jfree.ui.about.resources.AboutResources"; 218 final ResourceBundle resources = ResourceBundle.getBundle(baseName); 219 220 this.nameColumnLabel = resources.getString("system-properties-table.column.name"); 221 this.valueColumnLabel = resources.getString("system-properties-table.column.value"); 222 223 } 224 225 233 public boolean isSortable(final int column) { 234 235 if (column == 0) { 236 return true; 237 } 238 else { 239 return false; 240 } 241 242 } 243 244 249 public int getRowCount() { 250 return this.properties.size(); 251 } 252 253 259 public int getColumnCount() { 260 return 2; 261 } 262 263 270 public String getColumnName(final int column) { 271 272 if (column == 0) { 273 return this.nameColumnLabel; 274 } 275 else { 276 return this.valueColumnLabel; 277 } 278 279 } 280 281 290 public Object getValueAt(final int row, final int column) { 291 292 final SystemProperty sp = (SystemProperty) this.properties.get(row); 293 if (column == 0) { 294 return sp.getName(); 295 } 296 else { 297 if (column == 1) { 298 return sp.getValue(); 299 } 300 else { 301 return null; 302 } 303 } 304 305 } 306 307 314 public void sortByColumn(final int column, final boolean ascending) { 315 316 if (isSortable(column)) { 317 super.sortByColumn(column, ascending); 318 Collections.sort(this.properties, new SystemPropertyComparator(ascending)); 319 } 320 321 } 322 323 324 } 325 | Popular Tags |