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

Last change on this file since 4380 was 4380, checked in by simon04, 13 years ago

fix #4609 - copy node coordinate to clipboard

  • Property svn:eol-style set to native
File size: 4.8 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.event.ActionEvent;
9import java.awt.event.KeyEvent;
10import java.io.BufferedReader;
11import java.io.File;
12import java.io.FileReader;
13
14import javax.swing.JScrollPane;
15import javax.swing.JTextArea;
16
17import org.openstreetmap.josm.Main;
18import org.openstreetmap.josm.data.Version;
19import org.openstreetmap.josm.data.osm.DataSet;
20import org.openstreetmap.josm.data.osm.DatasetConsistencyTest;
21import org.openstreetmap.josm.gui.ExtendedDialog;
22import org.openstreetmap.josm.plugins.PluginHandler;
23import org.openstreetmap.josm.tools.Shortcut;
24import org.openstreetmap.josm.tools.Utils;
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), false);
40
41 putValue("help", ht("/Action/ShowStatusReport"));
42 putValue("toolbar", "help/showstatusreport");
43 Main.toolbar.register(this);
44 }
45
46 public static String getReportHeader()
47 {
48 StringBuilder text = new StringBuilder();
49 text.append(Version.getInstance().getReleaseAttributes());
50 text.append("\n");
51 text.append("Identification: " + Version.getInstance().getAgentString());
52 text.append("\n");
53 text.append("Memory Usage: ");
54 text.append(Runtime.getRuntime().totalMemory()/1024/1024);
55 text.append(" MB / ");
56 text.append(Runtime.getRuntime().maxMemory()/1024/1024);
57 text.append(" MB (");
58 text.append(Runtime.getRuntime().freeMemory()/1024/1024);
59 text.append(" MB allocated, but free)");
60 text.append("\n");
61 text.append("Java version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor") + ", " + System.getProperty("java.vm.name"));
62 text.append("\n");
63 text.append("Operating system: "+ System.getProperty("os.name"));
64 text.append("\n");
65 DataSet dataset = Main.main.getCurrentDataSet();
66 if (dataset != null) {
67 String result = DatasetConsistencyTest.runTests(dataset);
68 if (result.length() == 0) {
69 text.append("Dataset consistency test: No problems found\n");
70 } else {
71 text.append("\nDataset consistency test:\n"+result+"\n");
72 }
73 }
74 text.append("\n");
75 text.append(PluginHandler.getBugReportText());
76 text.append("\n");
77
78 return text.toString();
79 }
80
81 public void actionPerformed(ActionEvent e) {
82 StringBuilder text = new StringBuilder();
83 text.append(getReportHeader());
84 try {
85 BufferedReader input = new BufferedReader(new FileReader(Main.pref
86 .getPreferencesDirFile()
87 + File.separator + "preferences"));
88 try {
89 String line = null;
90
91 while ((line = input.readLine()) != null) {
92 String toCheck = line.trim().toLowerCase();
93 if (toCheck.startsWith("osm-server.username")
94 || toCheck.startsWith("osm-server.password")
95 || toCheck.startsWith("marker.show")
96 || toCheck.startsWith("oauth.access-token.key")
97 || toCheck.startsWith("oauth.access-token.secret")) {
98 continue;
99 }
100 text.append(line);
101 text.append("\n");
102 }
103 } finally {
104 input.close();
105 }
106 } catch (Exception x) {
107 x.printStackTrace();
108 }
109
110 JTextArea ta = new JTextArea(text.toString());
111 ta.setWrapStyleWord(true);
112 ta.setLineWrap(true);
113 ta.setEditable(false);
114 JScrollPane sp = new JScrollPane(ta);
115
116 ExtendedDialog ed = new ExtendedDialog(Main.parent,
117 tr("Status Report"),
118 new String[] {tr("Copy to clipboard and close"), tr("Close") });
119 ed.setButtonIcons(new String[] {"copy.png", "cancel.png" });
120 ed.setContent(sp, false);
121 ed.setMinimumSize(new Dimension(500, 0));
122 ed.showDialog();
123
124 if(ed.getValue() != 1) return;
125 Utils.copyToClipboard(text.toString());
126 }
127}
Note: See TracBrowser for help on using the repository browser.