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

Last change on this file since 4203 was 4146, checked in by stoecker, 13 years ago

fix #6480 - toolbar cleanups

  • Property svn:eol-style set to native
File size: 5.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.Dimension;
8import java.awt.Toolkit;
9import java.awt.datatransfer.Clipboard;
10import java.awt.datatransfer.ClipboardOwner;
11import java.awt.datatransfer.StringSelection;
12import java.awt.datatransfer.Transferable;
13import java.awt.event.ActionEvent;
14import java.awt.event.KeyEvent;
15import java.io.BufferedReader;
16import java.io.File;
17import java.io.FileReader;
18
19import javax.swing.JScrollPane;
20import javax.swing.JTextArea;
21
22import org.openstreetmap.josm.Main;
23import org.openstreetmap.josm.data.Version;
24import org.openstreetmap.josm.data.osm.DataSet;
25import org.openstreetmap.josm.data.osm.DatasetConsistencyTest;
26import org.openstreetmap.josm.gui.ExtendedDialog;
27import org.openstreetmap.josm.plugins.PluginHandler;
28import org.openstreetmap.josm.tools.Shortcut;
29
30/**
31 * @author xeen
32 *
33 * Opens a dialog with useful status information like version numbers for Java, JOSM and plugins
34 * Also includes preferences with stripped username and password
35 */
36public final class ShowStatusReportAction extends JosmAction {
37 public ShowStatusReportAction() {
38 super(
39 tr("Show Status Report"),
40 "clock",
41 tr("Show status report with useful information that can be attached to bugs"),
42 Shortcut.registerShortcut("help:showstatusreport", tr("Help: {0}",
43 tr("Show Status Report")), KeyEvent.VK_R, Shortcut.GROUP_NONE), false);
44
45 putValue("help", ht("/Action/ShowStatusReport"));
46 putValue("toolbar", "help/showstatusreport");
47 Main.toolbar.register(this);
48 }
49
50 public static String getReportHeader()
51 {
52 StringBuilder text = new StringBuilder();
53 text.append(Version.getInstance().getReleaseAttributes());
54 text.append("\n");
55 text.append("Identification: " + Version.getInstance().getAgentString());
56 text.append("\n");
57 text.append("Memory Usage: ");
58 text.append(Runtime.getRuntime().totalMemory()/1024/1024);
59 text.append(" MB / ");
60 text.append(Runtime.getRuntime().maxMemory()/1024/1024);
61 text.append(" MB (");
62 text.append(Runtime.getRuntime().freeMemory()/1024/1024);
63 text.append(" MB allocated, but free)");
64 text.append("\n");
65 text.append("Java version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor") + ", " + System.getProperty("java.vm.name"));
66 text.append("\n");
67 text.append("Operating system: "+ System.getProperty("os.name"));
68 text.append("\n");
69 DataSet dataset = Main.main.getCurrentDataSet();
70 if (dataset != null) {
71 String result = DatasetConsistencyTest.runTests(dataset);
72 if (result.length() == 0) {
73 text.append("Dataset consistency test: No problems found\n");
74 } else {
75 text.append("\nDataset consistency test:\n"+result+"\n");
76 }
77 }
78 text.append("\n");
79 text.append(PluginHandler.getBugReportText());
80 text.append("\n");
81
82 return text.toString();
83 }
84
85 public void actionPerformed(ActionEvent e) {
86 StringBuilder text = new StringBuilder();
87 text.append(getReportHeader());
88 try {
89 BufferedReader input = new BufferedReader(new FileReader(Main.pref
90 .getPreferencesDirFile()
91 + File.separator + "preferences"));
92 try {
93 String line = null;
94
95 while ((line = input.readLine()) != null) {
96 String toCheck = line.trim().toLowerCase();
97 if (toCheck.startsWith("osm-server.username")
98 || toCheck.startsWith("osm-server.password")
99 || toCheck.startsWith("marker.show")
100 || toCheck.startsWith("oauth.access-token.key")
101 || toCheck.startsWith("oauth.access-token.secret")) {
102 continue;
103 }
104 text.append(line);
105 text.append("\n");
106 }
107 } finally {
108 input.close();
109 }
110 } catch (Exception x) {
111 x.printStackTrace();
112 }
113
114 JTextArea ta = new JTextArea(text.toString());
115 ta.setWrapStyleWord(true);
116 ta.setLineWrap(true);
117 ta.setEditable(false);
118 JScrollPane sp = new JScrollPane(ta);
119
120 ExtendedDialog ed = new ExtendedDialog(Main.parent,
121 tr("Status Report"),
122 new String[] {tr("Copy to clipboard and close"), tr("Close") });
123 ed.setButtonIcons(new String[] {"copy.png", "cancel.png" });
124 ed.setContent(sp, false);
125 ed.setMinimumSize(new Dimension(500, 0));
126 ed.showDialog();
127
128 if(ed.getValue() != 1) return;
129 try {
130 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
131 new StringSelection(text.toString()), new ClipboardOwner() {
132 public void lostOwnership(Clipboard clipboard, Transferable contents) {}
133 }
134 );
135 }
136 catch (RuntimeException x) {}
137 }
138}
Note: See TracBrowser for help on using the repository browser.