Changeset 10062 in josm


Ignore:
Timestamp:
2016-03-28T00:22:42+02:00 (9 years ago)
Author:
Don-vip
Message:

see #12652 - about dialog: replace old bug report link with new bug report button, remove unused code

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AboutAction.java

    r10055 r10062  
    1818import javax.swing.ImageIcon;
    1919import javax.swing.JLabel;
    20 import javax.swing.JOptionPane;
    2120import javax.swing.JPanel;
    2221import javax.swing.JScrollPane;
     
    2625import org.openstreetmap.josm.Main;
    2726import org.openstreetmap.josm.data.Version;
     27import org.openstreetmap.josm.gui.ExtendedDialog;
    2828import org.openstreetmap.josm.gui.util.GuiHelper;
    2929import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
     
    3434import org.openstreetmap.josm.tools.ImageProvider;
    3535import org.openstreetmap.josm.tools.Shortcut;
    36 import org.openstreetmap.josm.tools.Utils;
    37 import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;
    3836
    3937/**
     
    9694        info.add(new UrlLabel(Main.getJOSMWebsite(), 2), GBC.eol().fill(GBC.HORIZONTAL));
    9795        info.add(GBC.glue(0, 5), GBC.eol());
    98         info.add(new JLabel(tr("Bug Reports")), GBC.std().insets(10, 0, 10, 0));
    99         info.add(BugReportExceptionHandler.getBugReportUrlLabel(Utils.strip(ShowStatusReportAction.getReportHeader())),
    100                 GBC.eol().fill(GBC.HORIZONTAL));
    10196
    10297        about.addTab(tr("Info"), info);
     
    109104        // Intermediate panel to allow proper optionPane resizing
    110105        JPanel panel = new JPanel(new GridBagLayout());
    111         panel.setPreferredSize(new Dimension(600, 300));
     106        panel.setPreferredSize(new Dimension(890, 300));
     107        panel.add(new JLabel("", new ImageIcon(ImageProvider.get("logo.svg").getImage().getScaledInstance(256, 258, Image.SCALE_SMOOTH)),
     108                JLabel.CENTER), GBC.std().insets(0, 5, 0, 0));
    112109        panel.add(about, GBC.std().fill());
    113110
    114111        GuiHelper.prepareResizeableOptionPane(panel, panel.getPreferredSize());
    115         JOptionPane.showMessageDialog(Main.parent, panel, tr("About JOSM..."), JOptionPane.INFORMATION_MESSAGE,
    116                 new ImageIcon(ImageProvider.get("logo.svg").getImage().getScaledInstance(256, 258, Image.SCALE_SMOOTH)));
     112        int ret = new ExtendedDialog(Main.parent, tr("About JOSM..."), new String[] {tr("OK"), tr("Report bug")})
     113            .setButtonIcons(new String[] {"ok", "bug"})
     114            .setContent(panel, false)
     115            .showDialog().getValue();
     116        if (2 == ret) {
     117            Main.main.menu.reportbug.actionPerformed(null);
     118        }
    117119    }
    118120
  • trunk/src/org/openstreetmap/josm/actions/ReportBugAction.java

    r10055 r10062  
    2222     */
    2323    public ReportBugAction() {
    24         this(ShowStatusReportAction.getReportHeader());
     24        this(null);
    2525    }
    2626
     
    3838    @Override
    3939    public void actionPerformed(ActionEvent e) {
    40         BugReportSender.reportBug(text);
     40        BugReportSender.reportBug(text == null ? ShowStatusReportAction.getReportHeader() : text);
    4141    }
    4242}
  • trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportExceptionHandler.java

    r10055 r10062  
    77import java.awt.GridBagConstraints;
    88import java.awt.GridBagLayout;
    9 import java.io.ByteArrayOutputStream;
    109import java.io.IOException;
    1110import java.io.PrintWriter;
    1211import java.io.StringWriter;
    13 import java.net.URL;
    14 import java.nio.ByteBuffer;
    15 import java.nio.charset.StandardCharsets;
    16 import java.util.zip.GZIPOutputStream;
    1712
    1813import javax.swing.JButton;
     
    3328import org.openstreetmap.josm.plugins.PluginDownloadTask;
    3429import org.openstreetmap.josm.plugins.PluginHandler;
    35 import org.openstreetmap.josm.tools.Base64;
    3630import org.openstreetmap.josm.tools.GBC;
    3731import org.openstreetmap.josm.tools.WikiReader;
     
    154148
    155149    /**
    156      * Handles the given throwable object
    157      * @param t The throwable object
    158      */
    159     public void handle(Throwable t) {
    160         handleException(t);
    161     }
    162 
    163     /**
    164150     * Handles the given exception
    165151     * @param e the exception
     
    253239        return handlingInProgress;
    254240    }
    255 
    256     /**
    257      * Replies the URL to create a JOSM bug report with the given debug text. GZip is used to reduce the length of the parameter.
    258      * @param debugText The debug text to provide us
    259      * @return The URL to create a JOSM bug report with the given debug text
    260      * @see BugReportSender#reportBug(String) if you want to send long debug texts along.
    261      * @since 5849
    262      */
    263     public static URL getBugReportUrl(String debugText) {
    264         try (
    265             ByteArrayOutputStream out = new ByteArrayOutputStream();
    266             GZIPOutputStream gzip = new GZIPOutputStream(out)
    267         ) {
    268             gzip.write(debugText.getBytes(StandardCharsets.UTF_8));
    269             gzip.finish();
    270 
    271             return new URL(Main.getJOSMWebsite()+"/josmticket?" +
    272                     "gdata="+Base64.encode(ByteBuffer.wrap(out.toByteArray()), true));
    273         } catch (IOException e) {
    274             Main.error(e);
    275             return null;
    276         }
    277     }
    278 
    279     /**
    280      * Replies the URL label to create a JOSM bug report with the given debug text
    281      * @param debugText The debug text to provide us
    282      * @return The URL label to create a JOSM bug report with the given debug text
    283      * @since 5849
    284      */
    285     public static UrlLabel getBugReportUrlLabel(String debugText) {
    286         URL url = getBugReportUrl(debugText);
    287         if (url != null) {
    288             return new UrlLabel(url.toString(), Main.getJOSMWebsite()+"/josmticket?...", 2);
    289         }
    290         return null;
    291     }
    292241}
  • trunk/test/unit/org/openstreetmap/josm/tools/bugreport/BugReportExceptionHandlerTest.java

    r10055 r10062  
    22package org.openstreetmap.josm.tools.bugreport;
    33
    4 import static org.junit.Assert.assertEquals;
    5 import static org.junit.Assert.assertTrue;
    6 
    7 import java.io.ByteArrayInputStream;
    8 import java.io.IOException;
    9 import java.nio.charset.StandardCharsets;
    10 import java.util.zip.GZIPInputStream;
    11 
    12 import javax.xml.bind.DatatypeConverter;
    13 
    144import org.junit.Before;
    15 import org.junit.Test;
    165import org.openstreetmap.josm.JOSMFixture;
    17 import org.openstreetmap.josm.Main;
    18 import org.openstreetmap.josm.actions.ShowStatusReportAction;
    196
    207/**
     
    3017        JOSMFixture.createUnitTestFixture().init();
    3118    }
    32 
    33     /**
    34      * Test method for {@link org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler#getBugReportUrl(java.lang.String)}.
    35      * @throws IOException if any I/O error occurs
    36      */
    37     @Test
    38     public void testGetBugReportUrl() throws IOException {
    39         String report = ShowStatusReportAction.getReportHeader();
    40         String url = BugReportExceptionHandler.getBugReportUrl(report).toExternalForm();
    41         String prefix = Main.getJOSMWebsite()+"/josmticket?gdata=";
    42         assertTrue(url.startsWith(prefix));
    43 
    44         String gdata = url.substring(prefix.length());
    45         // JAXB only provides support for "base64" decoding while we encode url in "base64url", so switch encoding, only for test purpose
    46         byte[] data = DatatypeConverter.parseBase64Binary(gdata.replace('-', '+').replace('_', '/'));
    47         byte[] buff = new byte[8192];
    48         try (GZIPInputStream is = new GZIPInputStream(new ByteArrayInputStream(data))) {
    49             StringBuilder sb = new StringBuilder();
    50             for (int n = is.read(buff); n > 0; n = is.read(buff)) {
    51                 sb.append(new String(buff, 0, n, StandardCharsets.UTF_8));
    52             }
    53             assertEquals(report, sb.toString());
    54         }
    55     }
    5619}
Note: See TracChangeset for help on using the changeset viewer.