Ticket #2160: AddStatutsReport (shows mem usage, too).patch

File AddStatutsReport (shows mem usage, too).patch, 7.7 KB (added by xeen, 17 years ago)
  • src/org/openstreetmap/josm/actions/ShowStatusReportAction.java

     
     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}
  • src/org/openstreetmap/josm/gui/MainMenu.java

     
    66
    77import java.awt.event.ActionEvent;
    88import java.awt.event.ActionListener;
     9import java.awt.event.KeyEvent;
    910
    1011import javax.swing.JCheckBoxMenuItem;
    1112import javax.swing.JMenu;
    1213import javax.swing.JMenuBar;
    1314import javax.swing.JMenuItem;
    1415import javax.swing.KeyStroke;
    15 import java.awt.event.KeyEvent;
    1616
    1717import org.openstreetmap.josm.Main;
    1818import org.openstreetmap.josm.actions.AboutAction;
    1919import org.openstreetmap.josm.actions.AddNodeAction;
    2020import org.openstreetmap.josm.actions.AlignInCircleAction;
    2121import org.openstreetmap.josm.actions.AlignInLineAction;
    22 import org.openstreetmap.josm.actions.OpenLocationAction;
    23 import org.openstreetmap.josm.actions.OrthogonalizeAction;
    2422import org.openstreetmap.josm.actions.AutoScaleAction;
    2523import org.openstreetmap.josm.actions.CombineWayAction;
    2624import org.openstreetmap.josm.actions.CopyAction;
     
    3836import org.openstreetmap.josm.actions.MergeNodesAction;
    3937import org.openstreetmap.josm.actions.NewAction;
    4038import org.openstreetmap.josm.actions.OpenFileAction;
     39import org.openstreetmap.josm.actions.OpenLocationAction;
     40import org.openstreetmap.josm.actions.OrthogonalizeAction;
    4141import org.openstreetmap.josm.actions.PasteAction;
    4242import org.openstreetmap.josm.actions.PasteTagsAction;
    4343import org.openstreetmap.josm.actions.PreferencesAction;
     
    4646import org.openstreetmap.josm.actions.SaveAction;
    4747import org.openstreetmap.josm.actions.SaveAsAction;
    4848import org.openstreetmap.josm.actions.SelectAllAction;
     49import org.openstreetmap.josm.actions.ShowStatusReportAction;
    4950import org.openstreetmap.josm.actions.SplitWayAction;
     51import org.openstreetmap.josm.actions.ToggleGPXLinesAction;
    5052import org.openstreetmap.josm.actions.UnGlueAction;
    5153import org.openstreetmap.josm.actions.UndoAction;
    5254import org.openstreetmap.josm.actions.UnselectAllAction;
     
    6163import org.openstreetmap.josm.actions.audio.AudioPrevAction;
    6264import org.openstreetmap.josm.actions.audio.AudioSlowerAction;
    6365import org.openstreetmap.josm.actions.search.SearchAction;
    64 import org.openstreetmap.josm.actions.ToggleGPXLinesAction;
    65 import org.openstreetmap.josm.data.DataSetChecker;
    6666import org.openstreetmap.josm.tools.Shortcut;
    6767
    6868/**
     
    130130    /* Help menu */
    131131    public final HelpAction help = new HelpAction();
    132132    public final JosmAction about = new AboutAction();
     133    public final JosmAction statusreport = new ShowStatusReportAction();
    133134
    134135    public final JMenu fileMenu = new JMenu(tr("File"));
    135136    public final JMenu editMenu = new JMenu(tr("Edit"));
     
    267268            }
    268269        });
    269270        helpMenu.add(check);*/
    270         current = helpMenu.add(help); // why is help not a JosmAction?
     271       
     272        helpMenu.add(statusreport);
     273       
     274        current = helpMenu.add(help); // FIXME why is help not a JosmAction?
    271275        current.setAccelerator(Shortcut.registerShortcut("system:help", tr("Help"), KeyEvent.VK_F1,
    272276                Shortcut.GROUP_DIRECT).getKeyStroke());
    273277        add(helpMenu, about);