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

Last change on this file since 2491 was 2369, checked in by Gubaer, 14 years ago

fixed #3305: Version is UNKNOWN
see also howto create a JOSM build

File size: 4.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
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.gui.ExtendedDialog;
25import org.openstreetmap.josm.plugins.PluginHandler;
26import org.openstreetmap.josm.tools.Shortcut;
27
28/**
29 * @author xeen
30 *
31 * Opens a dialog with useful status information like version numbers for Java, JOSM and plugins
32 * Also includes preferences with stripped username and password
33 */
34public final class ShowStatusReportAction extends JosmAction {
35 public ShowStatusReportAction() {
36 super(
37 tr("Show Status Report"),
38 "clock",
39 tr("Show status report with useful information that can be attached to bugs"),
40 Shortcut.registerShortcut("help:showstatusreport", tr("Help: {0}",
41 tr("Show Status Report")), KeyEvent.VK_R, Shortcut.GROUP_NONE), true);
42
43 putValue("help", ht("/Action/ShowStatusReport"));
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("Memory Usage: ");
52 text.append(Runtime.getRuntime().totalMemory()/1024/1024);
53 text.append(" MB / ");
54 text.append(Runtime.getRuntime().maxMemory()/1024/1024);
55 text.append(" MB (");
56 text.append(Runtime.getRuntime().freeMemory()/1024/1024);
57 text.append(" MB allocated, but free)");
58 text.append("\n");
59 text.append("Java version: " + System.getProperty("java.version"));
60 text.append("\n\n");
61 text.append(PluginHandler.getBugReportText());
62 text.append("\n\n");
63 return text.toString();
64 }
65
66 public void actionPerformed(ActionEvent e) {
67 StringBuilder text = new StringBuilder();
68 text.append(getReportHeader());
69 try {
70 BufferedReader input = new BufferedReader(new FileReader(Main.pref
71 .getPreferencesDirFile()
72 + File.separator + "preferences"));
73 try {
74 String line = null;
75
76 while ((line = input.readLine()) != null) {
77 // Skip potential private information
78 if (line.trim().toLowerCase().startsWith("osm-server.username")) {
79 continue;
80 }
81 if (line.trim().toLowerCase().startsWith("osm-server.password")) {
82 continue;
83 }
84 if (line.trim().toLowerCase().startsWith("marker.show")) {
85 continue;
86 }
87
88 text.append(line);
89 text.append("\n");
90 }
91 } finally {
92 input.close();
93 }
94 } catch (Exception x) {
95 x.printStackTrace();
96 }
97
98 JTextArea ta = new JTextArea(text.toString());
99 ta.setWrapStyleWord(true);
100 ta.setLineWrap(true);
101 ta.setEditable(false);
102 JScrollPane sp = new JScrollPane(ta);
103
104 ExtendedDialog ed = new ExtendedDialog(Main.parent,
105 tr("Status Report"),
106 new String[] {tr("Copy to clipboard and close"), tr("Close") });
107 ed.setButtonIcons(new String[] {"copy.png", "cancel.png" });
108 ed.setContent(sp, false);
109 ed.setMinimumSize(new Dimension(500, 0));
110 ed.showDialog();
111
112 if(ed.getValue() != 1) return;
113 try {
114 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
115 new StringSelection(text.toString()), new ClipboardOwner() {
116 public void lostOwnership(Clipboard clipboard, Transferable contents) {}
117 }
118 );
119 }
120 catch (RuntimeException x) {}
121 }
122}
Note: See TracBrowser for help on using the repository browser.