View Javadoc
1 package net.sourceforge.pmd.swingui; 2 3 import net.sourceforge.pmd.ProjectFile; 4 5 import javax.swing.ImageIcon; 6 import javax.swing.JButton; 7 import javax.swing.JDialog; 8 import javax.swing.JLabel; 9 import javax.swing.JPanel; 10 import javax.swing.JScrollPane; 11 import javax.swing.JTabbedPane; 12 import javax.swing.JTextArea; 13 import javax.swing.UIManager; 14 import javax.swing.border.CompoundBorder; 15 import javax.swing.border.EmptyBorder; 16 import javax.swing.border.EtchedBorder; 17 import java.awt.BorderLayout; 18 import java.awt.Color; 19 import java.awt.Dimension; 20 import java.awt.Font; 21 import java.awt.FontMetrics; 22 import java.awt.GridBagConstraints; 23 import java.awt.GridBagLayout; 24 import java.awt.GridLayout; 25 import java.awt.Insets; 26 import java.awt.event.ActionEvent; 27 import java.awt.event.ActionListener; 28 import java.text.DecimalFormat; 29 import java.util.ArrayList; 30 import java.util.Arrays; 31 import java.util.Comparator; 32 import java.util.List; 33 34 /*** 35 * 36 * @author Donald A. Leckie 37 * @since September 6, 2002 38 * @version $Revision: 1.16 $, $Date: 2003/05/28 18:08:31 $ 39 */ 40 class AboutPMD extends JDialog { 41 42 /*** 43 ******************************************************************************** 44 * 45 * @pmdViewer 46 */ 47 protected AboutPMD(PMDViewer pmdViewer) { 48 super(pmdViewer, "About PMD", true); 49 50 initialize(); 51 } 52 53 /*** 54 ******************************************************************************** 55 * 56 * @pmdViewer 57 */ 58 protected AboutPMD(JDialog dialog) { 59 super(dialog, "About PMD", true); 60 61 initialize(); 62 } 63 64 /*** 65 ******************************************************************************** 66 */ 67 private void initialize() { 68 Dimension screenSize = getToolkit().getScreenSize(); 69 int windowWidth = 750; 70 int windowHeight = 500; 71 int windowLocationX = (screenSize.width - windowWidth) / 2; 72 int windowLocationY = (screenSize.height - windowHeight) / 2; 73 74 setLocation(windowLocationX, windowLocationY); 75 setSize(windowWidth, windowHeight); 76 setResizable(true); 77 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 78 79 JPanel contentPanel = new JPanel(new BorderLayout()); 80 EmptyBorder emptyBorder = new EmptyBorder(10, 10, 10, 10); 81 contentPanel.setBorder(emptyBorder); 82 contentPanel.add(createTabbedPane(), BorderLayout.CENTER); 83 contentPanel.add(createButtonPanel(), BorderLayout.SOUTH); 84 85 JScrollPane scrollPane = ComponentFactory.createScrollPane(contentPanel); 86 getContentPane().add(scrollPane); 87 } 88 89 /*** 90 ******************************************************************************** 91 * 92 * @return 93 */ 94 private JPanel createButtonPanel() { 95 JButton closeButton = new JButton("Close"); 96 closeButton.setForeground(Color.white); 97 closeButton.setBackground(UIManager.getColor("pmdBlue")); 98 closeButton.addActionListener(new CloseButtonActionListener()); 99 100 JPanel buttonPanel = ComponentFactory.createButtonPanel(); 101 buttonPanel.add(closeButton); 102 103 return buttonPanel; 104 } 105 106 /*** 107 ******************************************************************************** 108 * 109 * @return 110 */ 111 private JTabbedPane createTabbedPane() { 112 JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM); 113 114 tabbedPane.addTab("About", createAboutPanel()); 115 tabbedPane.addTab("Info", createInfoPanel()); 116 tabbedPane.addTab("Credits", createCreditsPanel()); 117 tabbedPane.setFont(UIManager.getFont("tabFont")); 118 119 return tabbedPane; 120 } 121 122 /*** 123 ******************************************************************************** 124 * 125 * @return 126 */ 127 private JPanel createAboutPanel() { 128 JPanel aboutPanel = new JPanel(new BorderLayout()); 129 130 // PMD Image 131 ImageIcon imageIcon = (ImageIcon) UIManager.get("pmdLogoImage"); 132 JLabel imageLabel = new JLabel(imageIcon); 133 aboutPanel.add(imageLabel, BorderLayout.CENTER); 134 135 // Bottom Panel 136 JPanel bottomPanel = new JPanel(new GridLayout(2, 1)); 137 bottomPanel.setBorder(new EmptyBorder(0, 0, 10, 0)); 138 aboutPanel.add(bottomPanel, BorderLayout.SOUTH); 139 140 // Version Label 141 String versionText = Resources.getString("RESOURCEVersion") + " " + ProjectFile.getProperty("currentVersion"); 142 JLabel versionLabel = new JLabel(versionText); 143 versionLabel.setFont(UIManager.getFont("labelFont")); 144 versionLabel.setHorizontalAlignment(JLabel.CENTER); 145 bottomPanel.add(versionLabel); 146 147 // SourceForge PMD Project 148 String sourceForgeText = Resources.getString("RESOURCEDevelopedBySourceForgePMDTeam"); 149 JLabel sourceForgeLabel = new JLabel(sourceForgeText); 150 sourceForgeLabel.setFont(UIManager.getFont("labelFont")); 151 sourceForgeLabel.setHorizontalAlignment(JLabel.CENTER); 152 bottomPanel.add(sourceForgeLabel); 153 154 return aboutPanel; 155 } 156 157 /*** 158 ******************************************************************************** 159 * 160 * @return 161 */ 162 private JPanel createInfoPanel() { 163 GridBagLayout layout = new GridBagLayout(); 164 JPanel infoPanel = new JPanel(layout); 165 int row = 0; 166 167 addName("Java Runtime Environment Version", row, infoPanel); 168 addValue(System.getProperty("java.version"), row, infoPanel); 169 170 row++; 171 addName("Java Runtime Environment Vendor", row, infoPanel); 172 addValue(System.getProperty("java.vendor"), row, infoPanel); 173 174 row++; 175 addName("Java Installation Directory", row, infoPanel); 176 addValue(System.getProperty("java.home"), row, infoPanel); 177 178 row++; 179 addName("Java ClassPath", row, infoPanel); 180 addMultiLineValue(System.getProperty("java.class.path"), row, 5, infoPanel); 181 182 row += 5; 183 addName("Operating System Name", row, infoPanel); 184 addValue(System.getProperty("os.name"), row, infoPanel); 185 186 row++; 187 addName("Operating System Architecture", row, infoPanel); 188 addValue(System.getProperty("os.arch"), row, infoPanel); 189 190 row++; 191 addName("Operating System Version", row, infoPanel); 192 addValue(System.getProperty("os.version"), row, infoPanel); 193 194 row++; 195 addName("User's Home Directory", row, infoPanel); 196 addValue(System.getProperty("user.home"), row, infoPanel); 197 198 row++; 199 addName("User's Current Working Director", row, infoPanel); 200 addValue(System.getProperty("user.dir"), row, infoPanel); 201 202 row++; 203 addName("VM Total Memory", row, infoPanel); 204 long totalMemory = Runtime.getRuntime().totalMemory() / 1024; 205 String totalMemoryText = DecimalFormat.getNumberInstance().format(totalMemory) + "KB"; 206 addValue(totalMemoryText, row, infoPanel); 207 208 row++; 209 addName("VM Free Memory", row, infoPanel); 210 long freeMemory = Runtime.getRuntime().freeMemory() / 1024; 211 String freeMemoryText = DecimalFormat.getNumberInstance().format(freeMemory) + "KB"; 212 addValue(freeMemoryText, row, infoPanel); 213 214 row++; 215 addName("VM Used Memory", row, infoPanel); 216 long usedMemory = totalMemory - freeMemory; 217 String usedMemoryText = DecimalFormat.getNumberInstance().format(usedMemory) + "KB"; 218 addValue(usedMemoryText, row, infoPanel); 219 220 return infoPanel; 221 } 222 223 /*** 224 ******************************************************************************** 225 * 226 * @param name 227 */ 228 private void addName(String name, int row, JPanel infoPanel) { 229 JLabel label; 230 GridBagLayout layout; 231 GridBagConstraints constraints; 232 233 label = new JLabel(name, JLabel.RIGHT); 234 label.setFont(UIManager.getFont("labelFont")); 235 label.setHorizontalAlignment(JLabel.RIGHT); 236 label.setForeground(UIManager.getColor("pmdBlue")); 237 layout = (GridBagLayout) infoPanel.getLayout(); 238 constraints = layout.getConstraints(label); 239 constraints.gridx = 0; 240 constraints.gridy = row; 241 constraints.gridwidth = 1; 242 constraints.gridheight = 1; 243 constraints.anchor = constraints.NORTHEAST; 244 constraints.fill = constraints.NONE; 245 constraints.insets = new Insets(2, 2, 2, 2); 246 247 infoPanel.add(label, constraints); 248 } 249 250 /*** 251 ******************************************************************************** 252 * 253 * @param value 254 */ 255 private void addValue(String value, int row, JPanel infoPanel) { 256 JLabel label; 257 GridBagLayout layout; 258 GridBagConstraints constraints; 259 260 label = new JLabel(value, JLabel.LEFT); 261 label.setFont(UIManager.getFont("dataFont")); 262 layout = (GridBagLayout) infoPanel.getLayout(); 263 constraints = layout.getConstraints(label); 264 constraints.gridx = 1; 265 constraints.gridy = row; 266 constraints.gridwidth = 1; 267 constraints.gridheight = 1; 268 constraints.anchor = constraints.WEST; 269 constraints.fill = constraints.NONE; 270 constraints.insets = new Insets(2, 2, 2, 2); 271 272 infoPanel.add(label, constraints); 273 } 274 275 /*** 276 ******************************************************************************** 277 * 278 * @param value 279 */ 280 private void addMultiLineValue(String value, int row, int lines, JPanel infoPanel) { 281 JTextArea textArea; 282 JScrollPane scrollPane; 283 GridBagLayout layout; 284 GridBagConstraints constraints; 285 Font font; 286 FontMetrics fontMetrics; 287 int height; 288 int width; 289 Dimension size; 290 291 textArea = ComponentFactory.createTextArea(value); 292 textArea.setBackground(Color.lightGray); 293 294 scrollPane = ComponentFactory.createScrollPane(textArea); 295 font = textArea.getFont(); 296 fontMetrics = textArea.getFontMetrics(font); 297 width = 500; 298 height = (lines * fontMetrics.getHeight()) + 5; 299 size = new Dimension(width, height); 300 scrollPane.setSize(size); 301 scrollPane.setMinimumSize(size); 302 scrollPane.setPreferredSize(size); 303 304 layout = (GridBagLayout) infoPanel.getLayout(); 305 constraints = layout.getConstraints(scrollPane); 306 constraints.gridx = 1; 307 constraints.gridy = row; 308 constraints.gridwidth = 1; 309 constraints.gridheight = 1; 310 constraints.anchor = constraints.WEST; 311 constraints.fill = constraints.BOTH; 312 constraints.insets = new Insets(2, 2, 2, 2); 313 314 infoPanel.add(scrollPane, constraints); 315 } 316 317 /*** 318 ******************************************************************************** 319 * 320 * @return 321 */ 322 private JPanel createCreditsPanel() { 323 JPanel parentPanel = new JPanel(new BorderLayout()); 324 325 // Panel Title 326 JLabel title; 327 EtchedBorder etchedBorder; 328 CompoundBorder compoundBorder; 329 EmptyBorder emptyBorder; 330 331 title = new JLabel("The SourceForge PMD Project Team"); 332 etchedBorder = new EtchedBorder(EtchedBorder.RAISED); 333 compoundBorder = new CompoundBorder(etchedBorder, etchedBorder); 334 emptyBorder = new EmptyBorder(10, 10, 10, 10); 335 compoundBorder = new CompoundBorder(emptyBorder, compoundBorder); 336 compoundBorder = new CompoundBorder(compoundBorder, emptyBorder); 337 title.setBorder(compoundBorder); 338 title.setFont(UIManager.getFont("label16Font")); 339 title.setHorizontalAlignment(JLabel.CENTER); 340 title.setForeground(UIManager.getColor("pmdRed")); 341 parentPanel.add(title, BorderLayout.NORTH); 342 343 // Credits Panel 344 GridBagLayout layout = new GridBagLayout(); 345 JPanel creditsPanel = new JPanel(layout); 346 parentPanel.add(creditsPanel, BorderLayout.CENTER); 347 int row = 0; 348 349 addTitle("Project Administrators", row, creditsPanel); 350 addPerson("Tom Copeland", row, creditsPanel); 351 352 row++; 353 addPerson("David Craine", row, creditsPanel); 354 355 row++; 356 addPerson("David Dixon-Peugh", row, creditsPanel); 357 358 row++; 359 addTitle(" ", row, creditsPanel); 360 361 String developerNameKey = "developers/developer/name"; 362 String developerSelectKey = "developers/developer/roles/role"; 363 String selectValue = "developer"; 364 String[] developers = getPeople(developerNameKey, developerSelectKey, selectValue); 365 366 row++; 367 addTitle("Developers", row, creditsPanel); 368 row--; 369 370 for (int n = 0; n < developers.length; n++) { 371 row++; 372 addPerson(developers[n], row, creditsPanel); 373 } 374 375 row++; 376 addTitle(" ", row, creditsPanel); 377 378 String[] contributors = getPeople("contributors/contributor/name", null, null); 379 380 row++; 381 addTitle("Contributors", row, creditsPanel); 382 row--; 383 384 for (int n = 0; n < contributors.length; n++) { 385 row++; 386 addPerson(contributors[n], row, creditsPanel); 387 } 388 389 return parentPanel; 390 } 391 392 /*** 393 ******************************************************************************** 394 * 395 * @param name 396 */ 397 private void addTitle(String name, int row, JPanel creditsPanel) { 398 JLabel label; 399 GridBagLayout layout; 400 GridBagConstraints constraints; 401 402 label = new JLabel(name, JLabel.RIGHT); 403 label.setFont(UIManager.getFont("label14Font")); 404 label.setHorizontalAlignment(JLabel.RIGHT); 405 label.setForeground(UIManager.getColor("pmdBlue")); 406 layout = (GridBagLayout) creditsPanel.getLayout(); 407 constraints = layout.getConstraints(label); 408 constraints.gridx = 0; 409 constraints.gridy = row; 410 constraints.gridwidth = 1; 411 constraints.gridheight = 1; 412 constraints.anchor = constraints.NORTHEAST; 413 constraints.fill = constraints.NONE; 414 constraints.insets = new Insets(0, 2, 0, 2); 415 416 creditsPanel.add(label, constraints); 417 } 418 419 /*** 420 ******************************************************************************** 421 * 422 * @param value 423 */ 424 private void addPerson(String value, int row, JPanel creditsPanel) { 425 JLabel label; 426 GridBagLayout layout; 427 GridBagConstraints constraints; 428 429 label = new JLabel(value, JLabel.LEFT); 430 label.setFont(UIManager.getFont("serif14Font")); 431 layout = (GridBagLayout) creditsPanel.getLayout(); 432 constraints = layout.getConstraints(label); 433 constraints.gridx = 1; 434 constraints.gridy = row; 435 constraints.gridwidth = 1; 436 constraints.gridheight = 1; 437 constraints.anchor = constraints.WEST; 438 constraints.fill = constraints.NONE; 439 constraints.insets = new Insets(0, 2, 0, 2); 440 441 creditsPanel.add(label, constraints); 442 } 443 444 /*** 445 ******************************************************************************** 446 * 447 * @param nameKey 448 * @param selectKey 449 * @param selectValue 450 * 451 * @return 452 */ 453 private String[] getPeople(String nameKey, String selectKey, String selectValue) { 454 String nameList = ProjectFile.getProperty(nameKey); 455 String[] names = ProjectFile.toArray(nameList); 456 457 if ((selectKey != null) && (selectValue != null)) { 458 String selectList = ProjectFile.getProperty(selectKey); 459 String[] selections = ProjectFile.toArray(selectList); 460 List tempNameList = new ArrayList(); 461 462 for (int n = 0; n < names.length; n++) { 463 if ((n < selections.length) && selections[n].equalsIgnoreCase(selectValue)) { 464 tempNameList.add(names[n]); 465 } 466 467 selections[n] = null; 468 names[n] = null; 469 } 470 471 names = new String[tempNameList.size()]; 472 tempNameList.toArray(names); 473 tempNameList.clear(); 474 } 475 476 Arrays.sort(names, new PeopleNameComparator()); 477 478 return names; 479 } 480 481 /*** 482 ******************************************************************************* 483 ******************************************************************************* 484 ******************************************************************************* 485 */ 486 private class PeopleNameComparator implements Comparator { 487 488 /*** 489 ******************************************************************************** 490 * 491 * @param object1 492 * @param object2 493 * 494 * @return 495 */ 496 public int compare(Object object1, Object object2) { 497 String name1 = (String) object1; 498 String name2 = (String) object2; 499 int index = name1.lastIndexOf(' ') + 1; 500 501 if (index >= 0) { 502 name1 = name1.substring(index).concat(name1); 503 } 504 505 index = name2.lastIndexOf(' ') + 1; 506 507 if (index >= 0) { 508 name2 = name2.substring(index).concat(name2); 509 } 510 511 return name1.compareToIgnoreCase(name2); 512 } 513 514 /*** 515 ******************************************************************************** 516 * 517 * @param object 518 * 519 * @return 520 */ 521 public boolean compare(Object object) { 522 return object == this; 523 } 524 } 525 526 /*** 527 ******************************************************************************* 528 ******************************************************************************* 529 ******************************************************************************* 530 */ 531 private class CloseButtonActionListener implements ActionListener { 532 533 /*** 534 ******************************************************************** 535 * 536 * @param event 537 */ 538 public void actionPerformed(ActionEvent event) { 539 AboutPMD.this.setVisible(false); 540 } 541 } 542 }

This page was automatically generated by Maven