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

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

applied #3470 - patch by xeen - better scroll handling

File size: 4.2 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 static String getReportHeader()
44 {
45 StringBuilder text = new StringBuilder();
46 text.append(AboutAction.getTextBlock());
47 text.append("\n");
48 text.append("Memory Usage: ");
49 text.append(Runtime.getRuntime().totalMemory()/1024/1024);
50 text.append(" MB / ");
51 text.append(Runtime.getRuntime().maxMemory()/1024/1024);
52 text.append(" MB (");
53 text.append(Runtime.getRuntime().freeMemory()/1024/1024);
54 text.append(" MB allocated, but free)");
55 text.append("\n");
56 text.append("Java version: " + System.getProperty("java.version"));
57 text.append("\n\n");
58 text.append(PluginHandler.getBugReportText());
59 text.append("\n\n");
60 return text.toString();
61 }
62
63 public void actionPerformed(ActionEvent e) {
64 StringBuilder text = new StringBuilder();
65 text.append(getReportHeader());
66 try {
67 BufferedReader input = new BufferedReader(new FileReader(Main.pref
68 .getPreferencesDirFile()
69 + File.separator + "preferences"));
70 try {
71 String line = null;
72
73 while ((line = input.readLine()) != null) {
74 // Skip potential private information
75 if (line.trim().toLowerCase().startsWith("osm-server.username")) {
76 continue;
77 }
78 if (line.trim().toLowerCase().startsWith("osm-server.password")) {
79 continue;
80 }
81 if (line.trim().toLowerCase().startsWith("marker.show")) {
82 continue;
83 }
84
85 text.append(line);
86 text.append("\n");
87 }
88 } finally {
89 input.close();
90 }
91 } catch (Exception x) {
92 x.printStackTrace();
93 }
94
95 JTextArea ta = new JTextArea(text.toString());
96 ta.setWrapStyleWord(true);
97 ta.setLineWrap(true);
98 ta.setEditable(false);
99 JScrollPane sp = new JScrollPane(ta);
100
101 ExtendedDialog ed = new ExtendedDialog(Main.parent,
102 tr("Status Report"),
103 new String[] {tr("Copy to clipboard and close"), tr("Close") });
104 ed.setButtonIcons(new String[] {"copy.png", "cancel.png" });
105 ed.setContent(sp, false);
106 ed.setMinimumSize(new Dimension(500, 0));
107 ed.showDialog();
108
109 if(ed.getValue() != 1) return;
110 try {
111 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
112 new StringSelection(text.toString()), new ClipboardOwner() {
113 public void lostOwnership(Clipboard clipboard, Transferable contents) {}
114 }
115 );
116 }
117 catch (RuntimeException x) {}
118 }
119}
Note: See TracBrowser for help on using the repository browser.