001: package org.acm.seguin.pmd.swingui;
002:
003: import org.acm.seguin.pmd.ProjectFile;
004:
005: import javax.swing.ImageIcon;
006: import javax.swing.JButton;
007: import javax.swing.JDialog;
008: import javax.swing.JLabel;
009: import javax.swing.JPanel;
010: import javax.swing.JScrollPane;
011: import javax.swing.JTabbedPane;
012: import javax.swing.JTextArea;
013: import javax.swing.UIManager;
014: import javax.swing.border.CompoundBorder;
015: import javax.swing.border.EmptyBorder;
016: import javax.swing.border.EtchedBorder;
017: import java.awt.BorderLayout;
018: import java.awt.Color;
019: import java.awt.Dimension;
020: import java.awt.Font;
021: import java.awt.FontMetrics;
022: import java.awt.GridBagConstraints;
023: import java.awt.GridBagLayout;
024: import java.awt.GridLayout;
025: import java.awt.Insets;
026: import java.awt.event.ActionEvent;
027: import java.awt.event.ActionListener;
028: import java.text.DecimalFormat;
029: import java.util.ArrayList;
030: import java.util.Arrays;
031: import java.util.Comparator;
032: import java.util.List;
033:
034: /**
035: *
036: * @author Donald A. Leckie
037: * @since September 6, 2002
038: * @version $Revision: 1.1 $, $Date: 2003/07/29 20:51:59 $
039: */
040: class AboutPMD extends JDialog {
041:
042: /**
043: ********************************************************************************
044: *
045: * @pmdViewer
046: */
047: protected AboutPMD(PMDViewer pmdViewer) {
048: super (pmdViewer, "About PMD", true);
049:
050: initialize();
051: }
052:
053: /**
054: ********************************************************************************
055: *
056: * @pmdViewer
057: */
058: protected AboutPMD(JDialog dialog) {
059: super (dialog, "About PMD", true);
060:
061: initialize();
062: }
063:
064: /**
065: ********************************************************************************
066: */
067: private void initialize() {
068: Dimension screenSize = getToolkit().getScreenSize();
069: int windowWidth = 750;
070: int windowHeight = 500;
071: int windowLocationX = (screenSize.width - windowWidth) / 2;
072: int windowLocationY = (screenSize.height - windowHeight) / 2;
073:
074: setLocation(windowLocationX, windowLocationY);
075: setSize(windowWidth, windowHeight);
076: setResizable(true);
077: setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
078:
079: JPanel contentPanel = new JPanel(new BorderLayout());
080: EmptyBorder emptyBorder = new EmptyBorder(10, 10, 10, 10);
081: contentPanel.setBorder(emptyBorder);
082: contentPanel.add(createTabbedPane(), BorderLayout.CENTER);
083: contentPanel.add(createButtonPanel(), BorderLayout.SOUTH);
084:
085: JScrollPane scrollPane = ComponentFactory
086: .createScrollPane(contentPanel);
087: getContentPane().add(scrollPane);
088: }
089:
090: /**
091: ********************************************************************************
092: *
093: * @return
094: */
095: private JPanel createButtonPanel() {
096: JButton closeButton = new JButton("Close");
097: closeButton.setForeground(Color.white);
098: closeButton.setBackground(UIManager.getColor("pmdBlue"));
099: closeButton.addActionListener(new CloseButtonActionListener());
100:
101: JPanel buttonPanel = ComponentFactory.createButtonPanel();
102: buttonPanel.add(closeButton);
103:
104: return buttonPanel;
105: }
106:
107: /**
108: ********************************************************************************
109: *
110: * @return
111: */
112: private JTabbedPane createTabbedPane() {
113: JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM);
114:
115: tabbedPane.addTab("About", createAboutPanel());
116: tabbedPane.addTab("Info", createInfoPanel());
117: tabbedPane.addTab("Credits", createCreditsPanel());
118: tabbedPane.setFont(UIManager.getFont("tabFont"));
119:
120: return tabbedPane;
121: }
122:
123: /**
124: ********************************************************************************
125: *
126: * @return
127: */
128: private JPanel createAboutPanel() {
129: JPanel aboutPanel = new JPanel(new BorderLayout());
130:
131: // PMD Image
132: ImageIcon imageIcon = (ImageIcon) UIManager.get("pmdLogoImage");
133: JLabel imageLabel = new JLabel(imageIcon);
134: aboutPanel.add(imageLabel, BorderLayout.CENTER);
135:
136: // Bottom Panel
137: JPanel bottomPanel = new JPanel(new GridLayout(2, 1));
138: bottomPanel.setBorder(new EmptyBorder(0, 0, 10, 0));
139: aboutPanel.add(bottomPanel, BorderLayout.SOUTH);
140:
141: // Version Label
142: String versionText = Resources.getString("RESOURCEVersion")
143: + " " + ProjectFile.getProperty("currentVersion");
144: JLabel versionLabel = new JLabel(versionText);
145: versionLabel.setFont(UIManager.getFont("labelFont"));
146: versionLabel.setHorizontalAlignment(JLabel.CENTER);
147: bottomPanel.add(versionLabel);
148:
149: // SourceForge PMD Project
150: String sourceForgeText = Resources
151: .getString("RESOURCEDevelopedBySourceForgePMDTeam");
152: JLabel sourceForgeLabel = new JLabel(sourceForgeText);
153: sourceForgeLabel.setFont(UIManager.getFont("labelFont"));
154: sourceForgeLabel.setHorizontalAlignment(JLabel.CENTER);
155: bottomPanel.add(sourceForgeLabel);
156:
157: return aboutPanel;
158: }
159:
160: /**
161: ********************************************************************************
162: *
163: * @return
164: */
165: private JPanel createInfoPanel() {
166: GridBagLayout layout = new GridBagLayout();
167: JPanel infoPanel = new JPanel(layout);
168: int row = 0;
169:
170: addName("Java Runtime Environment Version", row, infoPanel);
171: addValue(System.getProperty("java.version"), row, infoPanel);
172:
173: row++;
174: addName("Java Runtime Environment Vendor", row, infoPanel);
175: addValue(System.getProperty("java.vendor"), row, infoPanel);
176:
177: row++;
178: addName("Java Installation Directory", row, infoPanel);
179: addValue(System.getProperty("java.home"), row, infoPanel);
180:
181: row++;
182: addName("Java ClassPath", row, infoPanel);
183: addMultiLineValue(System.getProperty("java.class.path"), row,
184: 5, infoPanel);
185:
186: row += 5;
187: addName("Operating System Name", row, infoPanel);
188: addValue(System.getProperty("os.name"), row, infoPanel);
189:
190: row++;
191: addName("Operating System Architecture", row, infoPanel);
192: addValue(System.getProperty("os.arch"), row, infoPanel);
193:
194: row++;
195: addName("Operating System Version", row, infoPanel);
196: addValue(System.getProperty("os.version"), row, infoPanel);
197:
198: row++;
199: addName("User's Home Directory", row, infoPanel);
200: addValue(System.getProperty("user.home"), row, infoPanel);
201:
202: row++;
203: addName("User's Current Working Director", row, infoPanel);
204: addValue(System.getProperty("user.dir"), row, infoPanel);
205:
206: row++;
207: addName("VM Total Memory", row, infoPanel);
208: long totalMemory = Runtime.getRuntime().totalMemory() / 1024;
209: String totalMemoryText = DecimalFormat.getNumberInstance()
210: .format(totalMemory)
211: + "KB";
212: addValue(totalMemoryText, row, infoPanel);
213:
214: row++;
215: addName("VM Free Memory", row, infoPanel);
216: long freeMemory = Runtime.getRuntime().freeMemory() / 1024;
217: String freeMemoryText = DecimalFormat.getNumberInstance()
218: .format(freeMemory)
219: + "KB";
220: addValue(freeMemoryText, row, infoPanel);
221:
222: row++;
223: addName("VM Used Memory", row, infoPanel);
224: long usedMemory = totalMemory - freeMemory;
225: String usedMemoryText = DecimalFormat.getNumberInstance()
226: .format(usedMemory)
227: + "KB";
228: addValue(usedMemoryText, row, infoPanel);
229:
230: return infoPanel;
231: }
232:
233: /**
234: ********************************************************************************
235: *
236: * @param name
237: */
238: private void addName(String name, int row, JPanel infoPanel) {
239: JLabel label;
240: GridBagLayout layout;
241: GridBagConstraints constraints;
242:
243: label = new JLabel(name, JLabel.RIGHT);
244: label.setFont(UIManager.getFont("labelFont"));
245: label.setHorizontalAlignment(JLabel.RIGHT);
246: label.setForeground(UIManager.getColor("pmdBlue"));
247: layout = (GridBagLayout) infoPanel.getLayout();
248: constraints = layout.getConstraints(label);
249: constraints.gridx = 0;
250: constraints.gridy = row;
251: constraints.gridwidth = 1;
252: constraints.gridheight = 1;
253: constraints.anchor = constraints.NORTHEAST;
254: constraints.fill = constraints.NONE;
255: constraints.insets = new Insets(2, 2, 2, 2);
256:
257: infoPanel.add(label, constraints);
258: }
259:
260: /**
261: ********************************************************************************
262: *
263: * @param value
264: */
265: private void addValue(String value, int row, JPanel infoPanel) {
266: JLabel label;
267: GridBagLayout layout;
268: GridBagConstraints constraints;
269:
270: label = new JLabel(value, JLabel.LEFT);
271: label.setFont(UIManager.getFont("dataFont"));
272: layout = (GridBagLayout) infoPanel.getLayout();
273: constraints = layout.getConstraints(label);
274: constraints.gridx = 1;
275: constraints.gridy = row;
276: constraints.gridwidth = 1;
277: constraints.gridheight = 1;
278: constraints.anchor = constraints.WEST;
279: constraints.fill = constraints.NONE;
280: constraints.insets = new Insets(2, 2, 2, 2);
281:
282: infoPanel.add(label, constraints);
283: }
284:
285: /**
286: ********************************************************************************
287: *
288: * @param value
289: */
290: private void addMultiLineValue(String value, int row, int lines,
291: JPanel infoPanel) {
292: JTextArea textArea;
293: JScrollPane scrollPane;
294: GridBagLayout layout;
295: GridBagConstraints constraints;
296: Font font;
297: FontMetrics fontMetrics;
298: int height;
299: int width;
300: Dimension size;
301:
302: textArea = ComponentFactory.createTextArea(value);
303: textArea.setBackground(Color.lightGray);
304:
305: scrollPane = ComponentFactory.createScrollPane(textArea);
306: font = textArea.getFont();
307: fontMetrics = textArea.getFontMetrics(font);
308: width = 500;
309: height = (lines * fontMetrics.getHeight()) + 5;
310: size = new Dimension(width, height);
311: scrollPane.setSize(size);
312: scrollPane.setMinimumSize(size);
313: scrollPane.setPreferredSize(size);
314:
315: layout = (GridBagLayout) infoPanel.getLayout();
316: constraints = layout.getConstraints(scrollPane);
317: constraints.gridx = 1;
318: constraints.gridy = row;
319: constraints.gridwidth = 1;
320: constraints.gridheight = 1;
321: constraints.anchor = constraints.WEST;
322: constraints.fill = constraints.BOTH;
323: constraints.insets = new Insets(2, 2, 2, 2);
324:
325: infoPanel.add(scrollPane, constraints);
326: }
327:
328: /**
329: ********************************************************************************
330: *
331: * @return
332: */
333: private JPanel createCreditsPanel() {
334: JPanel parentPanel = new JPanel(new BorderLayout());
335:
336: // Panel Title
337: JLabel title;
338: EtchedBorder etchedBorder;
339: CompoundBorder compoundBorder;
340: EmptyBorder emptyBorder;
341:
342: title = new JLabel("The SourceForge PMD Project Team");
343: etchedBorder = new EtchedBorder(EtchedBorder.RAISED);
344: compoundBorder = new CompoundBorder(etchedBorder, etchedBorder);
345: emptyBorder = new EmptyBorder(10, 10, 10, 10);
346: compoundBorder = new CompoundBorder(emptyBorder, compoundBorder);
347: compoundBorder = new CompoundBorder(compoundBorder, emptyBorder);
348: title.setBorder(compoundBorder);
349: title.setFont(UIManager.getFont("label16Font"));
350: title.setHorizontalAlignment(JLabel.CENTER);
351: title.setForeground(UIManager.getColor("pmdRed"));
352: parentPanel.add(title, BorderLayout.NORTH);
353:
354: // Credits Panel
355: GridBagLayout layout = new GridBagLayout();
356: JPanel creditsPanel = new JPanel(layout);
357: parentPanel.add(creditsPanel, BorderLayout.CENTER);
358: int row = 0;
359:
360: addTitle("Project Administrators", row, creditsPanel);
361: addPerson("Tom Copeland", row, creditsPanel);
362:
363: row++;
364: addPerson("David Craine", row, creditsPanel);
365:
366: row++;
367: addPerson("David Dixon-Peugh", row, creditsPanel);
368:
369: row++;
370: addTitle(" ", row, creditsPanel);
371:
372: String developerNameKey = "developers/developer/name";
373: String developerSelectKey = "developers/developer/roles/role";
374: String selectValue = "developer";
375: String[] developers = getPeople(developerNameKey,
376: developerSelectKey, selectValue);
377:
378: row++;
379: addTitle("Developers", row, creditsPanel);
380: row--;
381:
382: for (int n = 0; n < developers.length; n++) {
383: row++;
384: addPerson(developers[n], row, creditsPanel);
385: }
386:
387: row++;
388: addTitle(" ", row, creditsPanel);
389:
390: String[] contributors = getPeople(
391: "contributors/contributor/name", null, null);
392:
393: row++;
394: addTitle("Contributors", row, creditsPanel);
395: row--;
396:
397: for (int n = 0; n < contributors.length; n++) {
398: row++;
399: addPerson(contributors[n], row, creditsPanel);
400: }
401:
402: return parentPanel;
403: }
404:
405: /**
406: ********************************************************************************
407: *
408: * @param name
409: */
410: private void addTitle(String name, int row, JPanel creditsPanel) {
411: JLabel label;
412: GridBagLayout layout;
413: GridBagConstraints constraints;
414:
415: label = new JLabel(name, JLabel.RIGHT);
416: label.setFont(UIManager.getFont("label14Font"));
417: label.setHorizontalAlignment(JLabel.RIGHT);
418: label.setForeground(UIManager.getColor("pmdBlue"));
419: layout = (GridBagLayout) creditsPanel.getLayout();
420: constraints = layout.getConstraints(label);
421: constraints.gridx = 0;
422: constraints.gridy = row;
423: constraints.gridwidth = 1;
424: constraints.gridheight = 1;
425: constraints.anchor = constraints.NORTHEAST;
426: constraints.fill = constraints.NONE;
427: constraints.insets = new Insets(0, 2, 0, 2);
428:
429: creditsPanel.add(label, constraints);
430: }
431:
432: /**
433: ********************************************************************************
434: *
435: * @param value
436: */
437: private void addPerson(String value, int row, JPanel creditsPanel) {
438: JLabel label;
439: GridBagLayout layout;
440: GridBagConstraints constraints;
441:
442: label = new JLabel(value, JLabel.LEFT);
443: label.setFont(UIManager.getFont("serif14Font"));
444: layout = (GridBagLayout) creditsPanel.getLayout();
445: constraints = layout.getConstraints(label);
446: constraints.gridx = 1;
447: constraints.gridy = row;
448: constraints.gridwidth = 1;
449: constraints.gridheight = 1;
450: constraints.anchor = constraints.WEST;
451: constraints.fill = constraints.NONE;
452: constraints.insets = new Insets(0, 2, 0, 2);
453:
454: creditsPanel.add(label, constraints);
455: }
456:
457: /**
458: ********************************************************************************
459: *
460: * @param nameKey
461: * @param selectKey
462: * @param selectValue
463: *
464: * @return
465: */
466: private String[] getPeople(String nameKey, String selectKey,
467: String selectValue) {
468: String nameList = ProjectFile.getProperty(nameKey);
469: String[] names = ProjectFile.toArray(nameList);
470:
471: if ((selectKey != null) && (selectValue != null)) {
472: String selectList = ProjectFile.getProperty(selectKey);
473: String[] selections = ProjectFile.toArray(selectList);
474: List tempNameList = new ArrayList();
475:
476: for (int n = 0; n < names.length; n++) {
477: if ((n < selections.length)
478: && selections[n].equalsIgnoreCase(selectValue)) {
479: tempNameList.add(names[n]);
480: }
481:
482: selections[n] = null;
483: names[n] = null;
484: }
485:
486: names = new String[tempNameList.size()];
487: tempNameList.toArray(names);
488: tempNameList.clear();
489: }
490:
491: Arrays.sort(names, new PeopleNameComparator());
492:
493: return names;
494: }
495:
496: /**
497: *******************************************************************************
498: *******************************************************************************
499: *******************************************************************************
500: */
501: private class PeopleNameComparator implements Comparator {
502:
503: /**
504: ********************************************************************************
505: *
506: * @param object1
507: * @param object2
508: *
509: * @return
510: */
511: public int compare(Object object1, Object object2) {
512: String name1 = (String) object1;
513: String name2 = (String) object2;
514: int index = name1.lastIndexOf(' ') + 1;
515:
516: if (index >= 0) {
517: name1 = name1.substring(index).concat(name1);
518: }
519:
520: index = name2.lastIndexOf(' ') + 1;
521:
522: if (index >= 0) {
523: name2 = name2.substring(index).concat(name2);
524: }
525:
526: return name1.compareToIgnoreCase(name2);
527: }
528:
529: /**
530: ********************************************************************************
531: *
532: * @param object
533: *
534: * @return
535: */
536: public boolean compare(Object object) {
537: return object == this ;
538: }
539: }
540:
541: /**
542: *******************************************************************************
543: *******************************************************************************
544: *******************************************************************************
545: */
546: private class CloseButtonActionListener implements ActionListener {
547:
548: /**
549: ********************************************************************
550: *
551: * @param event
552: */
553: public void actionPerformed(ActionEvent event) {
554: AboutPMD.this .setVisible(false);
555: }
556: }
557: }
|