source: josm/trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java@ 1523

Last change on this file since 1523 was 1484, checked in by stoecker, 15 years ago

fixed user agent

File size: 3.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Dimension;
7import java.awt.Toolkit;
8import java.awt.datatransfer.Clipboard;
9import java.awt.datatransfer.ClipboardOwner;
10import java.awt.datatransfer.StringSelection;
11import java.awt.datatransfer.Transferable;
12import java.awt.event.ActionEvent;
13import java.awt.event.KeyEvent;
14import java.io.BufferedReader;
15import java.io.File;
16import java.io.FileReader;
17
18import javax.swing.JScrollPane;
19import javax.swing.JTextArea;
20
21import org.openstreetmap.josm.Main;
22import org.openstreetmap.josm.gui.ExtendedDialog;
23import org.openstreetmap.josm.plugins.PluginHandler;
24import org.openstreetmap.josm.tools.Shortcut;
25
26/**
27 * @author xeen
28 *
29 * Opens a dialog with useful status information like version numbers for Java, JOSM and plugins
30 * Also includes preferences with stripped username and password
31 */
32public final class ShowStatusReportAction extends JosmAction {
33 public ShowStatusReportAction() {
34 super(
35 tr("Show Status Report"),
36 "clock",
37 tr("Show status report with useful information that can be attached to bugs"),
38 Shortcut.registerShortcut("help:showstatusreport", tr("Help: {0}",
39 tr("Show Status Report")), KeyEvent.VK_R, Shortcut.GROUP_NONE), true);
40
41 }
42
43 public void actionPerformed(ActionEvent e) {
44 StringBuilder text = new StringBuilder();
45 text.append(AboutAction.getTextBlock());
46 text.append("\n");
47 text.append("Memory Usage: ");
48 text.append(Runtime.getRuntime().totalMemory()/1024/1024);
49 text.append(" MB / ");
50 text.append(Runtime.getRuntime().maxMemory()/1024/1024);
51 text.append(" MB (");
52 text.append(Runtime.getRuntime().freeMemory()/1024/1024);
53 text.append(" MB allocated, but free)");
54 text.append("\n");
55 text.append("Java version: " + System.getProperty("java.version"));
56 text.append("\n\n");
57 text.append(PluginHandler.getBugReportText());
58 text.append("\n\n");
59 try {
60 BufferedReader input = new BufferedReader(new FileReader(Main.pref
61 .getPreferencesDirFile()
62 + File.separator + "preferences"));
63 try {
64 String line = null;
65
66 while ((line = input.readLine()) != null) {
67 // Skip potential private information
68 if (line.trim().toLowerCase().startsWith("osm-server.username"))
69 continue;
70 if (line.trim().toLowerCase().startsWith("osm-server.password"))
71 continue;
72 if (line.trim().toLowerCase().startsWith("marker.show"))
73 continue;
74
75 text.append(line);
76 text.append("\n");
77 }
78 } finally {
79 input.close();
80 }
81 } catch (Exception x) {
82 x.printStackTrace();
83 }
84
85 JTextArea ta = new JTextArea(text.toString());
86 ta.setWrapStyleWord(true);
87 ta.setLineWrap(true);
88 ta.setEditable(false);
89 JScrollPane sp = new JScrollPane(ta);
90 sp.setPreferredSize(new Dimension(600, 500));
91
92 int result = new ExtendedDialog(Main.parent, tr(tr("Status Report")), sp,
93 new String[] {tr("Copy to clipboard and close"), tr("Close") },
94 new String[] {"copy.png", "cancel.png" }).getValue();
95
96 if(result != 1) return;
97 try {
98 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
99 new StringSelection(text.toString()), new ClipboardOwner() {
100 public void lostOwnership(Clipboard clipboard, Transferable contents) {}
101 }
102 );
103 }
104 catch (RuntimeException x) {}
105 }
106}
Note: See TracBrowser for help on using the repository browser.