Ticket #2160: AddStautsReport.patch

File AddStautsReport.patch, 7.3 KB (added by xeen, 16 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\n");
     47        text.append("Java version: " + System.getProperty("java.version"));
     48        text.append("\n\n");
     49        text.append(PluginHandler.getBugReportText());
     50        text.append("\n\n");
     51        try {
     52            BufferedReader input = new BufferedReader(new FileReader(Main.pref
     53                    .getPreferencesDirFile()
     54                    + File.separator + "preferences"));
     55            try {
     56                String line = null;
     57
     58                while ((line = input.readLine()) != null) {
     59                    // Skip potential private information
     60                    if (line.trim().toLowerCase().startsWith("osm-server.username"))
     61                        continue;
     62                    if (line.trim().toLowerCase().startsWith("osm-server.password"))
     63                        continue;
     64                    if (line.trim().toLowerCase().startsWith("marker.show"))
     65                        continue;
     66                   
     67                    text.append(line);
     68                    text.append("\n");
     69                }
     70            } finally {
     71                input.close();
     72            }
     73        } catch (Exception x) {
     74            x.printStackTrace();
     75        }
     76       
     77        JTextArea ta = new JTextArea(text.toString());
     78        ta.setWrapStyleWord(true);
     79        ta.setLineWrap(true);
     80        ta.setEditable(false);
     81        JScrollPane sp = new JScrollPane(ta);
     82        sp.setPreferredSize(new Dimension(600, 500));
     83
     84        int result = new ExtendedDialog(Main.parent, tr(tr("Status Report")), sp,
     85                new String[] {tr("Copy to clipboard and close"), tr("Close") },
     86                new String[] {"copy.png", "cancel.png" }).getValue();
     87       
     88        if(result != 1) return;
     89        try {
     90            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
     91                    new StringSelection(text.toString()), new ClipboardOwner() {
     92                        public void lostOwnership(Clipboard clipboard, Transferable contents) {}
     93                    }
     94             );
     95        }
     96        catch (RuntimeException x) {}
     97    }
     98}
  • 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);