Changeset 10649 in josm


Ignore:
Timestamp:
2016-07-26T21:34:35+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #13193 - Use a new bug report dialog (patch by michael2402) - gsoc-core

Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java

    r10616 r10649  
    66import java.awt.Component;
    77import java.awt.Dimension;
     8import java.awt.Frame;
    89import java.awt.GridBagConstraints;
    910import java.awt.GridBagLayout;
     
    146147
    147148    public ExtendedDialog(Component parent, String title, String[] buttonTexts, boolean modal, boolean disposeOnClose) {
    148         super(GuiHelper.getFrameForComponent(parent), title, modal ? ModalityType.DOCUMENT_MODAL : ModalityType.MODELESS);
     149        super(searchRealParent(parent), title, modal ? ModalityType.DOCUMENT_MODAL : ModalityType.MODELESS);
    149150        this.parent = parent;
    150151        this.modal = modal;
     
    154155        }
    155156        this.disposeOnClose = disposeOnClose;
     157    }
     158
     159    private static Frame searchRealParent(Component parent) {
     160        if (parent == null) {
     161            return null;
     162        } else {
     163            return GuiHelper.getFrameForComponent(parent);
     164        }
    156165    }
    157166
  • trunk/src/org/openstreetmap/josm/tools/GBC.java

    r9231 r10649  
    9797
    9898    /**
     99     * Adds insets to this GBC.
     100     * @param insets The insets in all directions.
     101     * @return This constraint for chaining.
     102     * @since 10649
     103     */
     104    public GBC insets(int insets) {
     105        insets(insets, insets, insets, insets);
     106        return this;
     107    }
     108
     109    /**
    99110     * Specifies how to distribute extra horizontal space.
    100111     * @param weightx   Weight in horizontal direction
  • trunk/src/org/openstreetmap/josm/tools/bugreport/BugReport.java

    r10598 r10649  
    33
    44import java.io.PrintWriter;
     5import java.io.Serializable;
    56import java.io.StringWriter;
    67import java.util.concurrent.CopyOnWriteArrayList;
     
    3839 * @since 10285
    3940 */
    40 public final class BugReport {
     41public final class BugReport implements Serializable {
     42    private static final long serialVersionUID = 1L;
     43
    4144    private boolean includeStatusReport = true;
    4245    private boolean includeData = true;
  • trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportExceptionHandler.java

    r10585 r10649  
    22package org.openstreetmap.josm.tools.bugreport;
    33
    4 import static org.openstreetmap.josm.tools.I18n.tr;
     4import java.awt.GraphicsEnvironment;
    55
    6 import java.awt.Component;
    7 import java.awt.GraphicsEnvironment;
    8 import java.awt.GridBagConstraints;
    9 import java.awt.GridBagLayout;
    10 import java.io.IOException;
    11 import java.io.PrintWriter;
    12 import java.io.StringWriter;
    13 
    14 import javax.swing.JButton;
    15 import javax.swing.JCheckBox;
    16 import javax.swing.JLabel;
    176import javax.swing.JOptionPane;
    18 import javax.swing.JPanel;
    197import javax.swing.SwingUtilities;
    208
    219import org.openstreetmap.josm.Main;
    22 import org.openstreetmap.josm.actions.ReportBugAction;
    23 import org.openstreetmap.josm.actions.ShowStatusReportAction;
    24 import org.openstreetmap.josm.data.Version;
    25 import org.openstreetmap.josm.gui.ExtendedDialog;
    2610import org.openstreetmap.josm.gui.preferences.plugin.PluginPreference;
    27 import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
    28 import org.openstreetmap.josm.gui.widgets.UrlLabel;
    2911import org.openstreetmap.josm.plugins.PluginDownloadTask;
    3012import org.openstreetmap.josm.plugins.PluginHandler;
    31 import org.openstreetmap.josm.tools.GBC;
    32 import org.openstreetmap.josm.tools.WikiReader;
    3313
    3414/**
     
    7959
    8060        static void askForBugReport(final Throwable e) {
    81             String[] buttonTexts = new String[] {tr("Do nothing"), tr("Report Bug")};
    82             String[] buttonIcons = new String[] {"cancel", "bug"};
    83             int defaultButtonIdx = 1;
    84             String message = tr("An unexpected exception occurred.<br>" +
    85                     "This is always a coding error. If you are running the latest<br>" +
    86                     "version of JOSM, please consider being kind and file a bug report."
    87                     );
    88             // Check user is running current tested version, the error may already be fixed
    89             int josmVersion = Version.getInstance().getVersion();
    90             if (josmVersion != Version.JOSM_UNKNOWN_VERSION) {
    91                 try {
    92                     int latestVersion = Integer.parseInt(new WikiReader().
    93                             read(Main.getJOSMWebsite()+"/wiki/TestedVersion?format=txt").trim());
    94                     if (latestVersion > josmVersion) {
    95                         buttonTexts = new String[] {tr("Do nothing"), tr("Update JOSM"), tr("Report Bug")};
    96                         buttonIcons = new String[] {"cancel", "download", "bug"};
    97                         defaultButtonIdx = 2;
    98                         message = tr("An unexpected exception occurred. This is always a coding error.<br><br>" +
    99                                 "However, you are running an old version of JOSM ({0}),<br>" +
    100                                 "instead of using the current tested version (<b>{1}</b>).<br><br>"+
    101                                 "<b>Please update JOSM</b> before considering to file a bug report.",
    102                                 String.valueOf(josmVersion), String.valueOf(latestVersion));
    103                     }
    104                 } catch (IOException | NumberFormatException ex) {
    105                     Main.warn(ex, "Unable to detect latest version of JOSM:");
    106                 }
    107             }
    108             // Build panel
    109             JPanel pnl = new JPanel(new GridBagLayout());
    110             pnl.add(new JLabel("<html>" + message + "</html>"), GBC.eol());
    111             JCheckBox cbSuppress = null;
    112             if (exceptionCounter > 1) {
    113                 cbSuppress = new JCheckBox(tr("Suppress further error dialogs for this session."));
    114                 pnl.add(cbSuppress, GBC.eol());
    115             }
    11661            if (GraphicsEnvironment.isHeadless()) {
    11762                return;
    11863            }
    119             // Show dialog
    120             ExtendedDialog ed = new ExtendedDialog(Main.parent, tr("Unexpected Exception"), buttonTexts);
    121             ed.setButtonIcons(buttonIcons);
    122             ed.setIcon(JOptionPane.ERROR_MESSAGE);
    123             ed.setCancelButton(1);
    124             ed.setDefaultButton(defaultButtonIdx);
    125             ed.setContent(pnl);
    126             ed.setFocusOnDefaultButton(true);
    127             ed.showDialog();
    128             if (cbSuppress != null && cbSuppress.isSelected()) {
    129                 suppressExceptionDialogs = true;
    130             }
    131             if (ed.getValue() <= 1) {
    132                 // "Do nothing"
    133                 return;
    134             } else if (ed.getValue() < buttonTexts.length) {
    135                 // "Update JOSM"
    136                 try {
    137                     Main.platform.openUrl(Main.getJOSMWebsite());
    138                 } catch (IOException ex) {
    139                     Main.warn(ex, "Unable to access JOSM website:");
    140                 }
    141             } else {
    142                 // "Report bug"
    143                 try {
    144                     JPanel p = buildPanel(e);
    145                     JOptionPane.showMessageDialog(Main.parent, p, tr("You have encountered a bug in JOSM"), JOptionPane.ERROR_MESSAGE);
    146                 } catch (RuntimeException ex) {
    147                     Main.error(ex);
    148                 }
    149             }
     64            BugReport report = new BugReport(BugReport.intercept(e));
     65            BugReportDialog dialog = new BugReportDialog(report);
     66            dialog.setShowSuppress(exceptionCounter > 1);
     67            dialog.setVisible(true);
     68            suppressExceptionDialogs = dialog.shouldSuppressFurtherErrors();
    15069        }
    15170
     
    196115    }
    197116
    198     static JPanel buildPanel(final Throwable e) {
    199         DebugTextDisplay textarea;
    200         if (e instanceof ReportedException) {
    201             // Temporary!
    202             textarea = new DebugTextDisplay(new BugReport((ReportedException) e));
    203         } else {
    204             StringWriter stack = new StringWriter();
    205             e.printStackTrace(new PrintWriter(stack));
    206             textarea = new DebugTextDisplay(ShowStatusReportAction.getReportHeader() + stack.getBuffer().toString());
    207         }
    208 
    209         JPanel p = new JPanel(new GridBagLayout());
    210         p.add(new JMultilineLabel(
    211                 tr("You have encountered an error in JOSM. Before you file a bug report " +
    212                         "make sure you have updated to the latest version of JOSM here:")),
    213                         GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    214         p.add(new UrlLabel(Main.getJOSMWebsite(), 2), GBC.eop().insets(8, 0, 0, 0));
    215         p.add(new JMultilineLabel(
    216                 tr("You should also update your plugins. If neither of those help please " +
    217                         "file a bug report in our bugtracker using this link:")),
    218                         GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    219         p.add(new JButton(new ReportBugAction(textarea.getCodeText())), GBC.eop().insets(8, 0, 0, 0));
    220         p.add(new JMultilineLabel(
    221                 tr("There the error information provided below should already be " +
    222                         "filled in for you. Please include information on how to reproduce " +
    223                         "the error and try to supply as much detail as possible.")),
    224                         GBC.eop().fill(GridBagConstraints.HORIZONTAL));
    225         p.add(new JMultilineLabel(
    226                 tr("Alternatively, if that does not work you can manually fill in the information " +
    227                         "below at this URL:")), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    228         p.add(new UrlLabel(Main.getJOSMWebsite()+"/newticket", 2), GBC.eop().insets(8, 0, 0, 0));
    229 
    230         if (textarea.copyToClippboard()) {
    231             p.add(new JLabel(tr("(The text has already been copied to your clipboard.)")),
    232                     GBC.eop().fill(GridBagConstraints.HORIZONTAL));
    233         }
    234 
    235         p.add(textarea, GBC.eop().fill());
    236 
    237         for (Component c: p.getComponents()) {
    238             if (c instanceof JMultilineLabel) {
    239                 ((JMultilineLabel) c).setMaxWidth(400);
    240             }
    241         }
    242         return p;
    243     }
    244 
    245117    /**
    246118     * Determines if an exception is currently being handled
  • trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportSettingsPanel.java

    r10597 r10649  
    2626        add(statusReport);
    2727
    28         JCheckBox data = new JCheckBox(tr("Include information about the data that was worked on."));
     28        JCheckBox data = new JCheckBox(tr("Include information about the data you were working on."));
    2929        data.setSelected(report.isIncludeData());
    3030        data.addChangeListener(e -> report.setIncludeData(data.isSelected()));
  • trunk/test/unit/org/openstreetmap/josm/tools/bugreport/BugReportExceptionHandlerTest.java

    r10067 r10649  
    33
    44import static org.junit.Assert.assertFalse;
    5 import static org.junit.Assert.assertNotNull;
    65
    76import org.junit.Before;
     
    2322
    2423    /**
    25      * Unit test for {@link BugReportExceptionHandler#buildPanel} method.
    26      */
    27     @Test
    28     public void testBuildPanel() {
    29         assertNotNull(BugReportExceptionHandler.buildPanel(new Exception("testBuildPanel")));
    30     }
    31 
    32     /**
    3324     * Unit test for {@link BugReportExceptionHandler.BugReporterThread#askForBugReport} method.
    3425     */
Note: See TracChangeset for help on using the changeset viewer.