Changeset 7312 in josm for trunk


Ignore:
Timestamp:
2014-07-15T16:48:46+02:00 (10 years ago)
Author:
Don-vip
Message:

see #10267 - display HTML error page sent by WMS server when applicable

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMSLayerPanel.java

    r7015 r7312  
    2525import org.openstreetmap.josm.data.imagery.ImageryInfo;
    2626import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
     27import org.openstreetmap.josm.gui.util.GuiHelper;
    2728import org.openstreetmap.josm.gui.widgets.JosmTextArea;
    2829import org.openstreetmap.josm.io.imagery.WMSImagery;
     
    8687                            tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
    8788                } catch (WMSImagery.WMSGetCapabilitiesException ex) {
    88                     JOptionPane.showMessageDialog(getParent(), tr("Could not parse WMS layer list."),
    89                             tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
    90                     Main.error("Could not parse WMS layer list. Incoming data:\n"+ex.getIncomingData());
     89                    String incomingData = ex.getIncomingData().trim();
     90                    String title = tr("WMS Error");
     91                    String message = tr("Could not parse WMS layer list.");
     92                    Main.error("Could not parse WMS layer list. Incoming data:\n"+incomingData);
     93                    if (incomingData != null
     94                            && (incomingData.startsWith("<html>") || incomingData.startsWith("<HTML>"))
     95                            && (incomingData.endsWith("</html>") || incomingData.endsWith("</HTML>"))) {
     96                        GuiHelper.notifyUserHtmlError(AddWMSLayerPanel.this, title, message, incomingData);
     97                    } else {
     98                        JOptionPane.showMessageDialog(getParent(), message, title, JOptionPane.ERROR_MESSAGE);
     99                    }
    91100                }
    92101            }
  • trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java

    r7204 r7312  
    1111import java.awt.Font;
    1212import java.awt.GraphicsEnvironment;
     13import java.awt.GridBagLayout;
    1314import java.awt.Image;
    1415import java.awt.Stroke;
     
    2930import javax.swing.Icon;
    3031import javax.swing.ImageIcon;
     32import javax.swing.JLabel;
    3133import javax.swing.JOptionPane;
     34import javax.swing.JPanel;
    3235import javax.swing.JScrollPane;
    3336import javax.swing.SwingUtilities;
     
    3639import org.openstreetmap.josm.Main;
    3740import org.openstreetmap.josm.gui.ExtendedDialog;
     41import org.openstreetmap.josm.gui.widgets.HtmlPanel;
     42import org.openstreetmap.josm.tools.GBC;
    3843import org.openstreetmap.josm.tools.ImageProvider;
    3944
     
    132137
    133138    /**
     139     * Warns user about a dangerous action requiring confirmation.
     140     * @param title Title of dialog
     141     * @param content Content of dialog
     142     * @param baseActionIcon Unused? FIXME why is this parameter unused?
     143     * @param continueToolTip Tooltip to display for "continue" button
    134144     * @return true if the user wants to cancel, false if they want to continue
    135145     */
     
    150160        dlg.setCancelButton(1);
    151161        return dlg.showDialog().getValue() != 2;
     162    }
     163
     164    /**
     165     * Notifies user about an error received from an external source as an HTML page.
     166     * @param parent Parent component
     167     * @param title Title of dialog
     168     * @param message Message displayed at the top of the dialog
     169     * @param html HTML content to display (real error message)
     170     * @since 7312
     171     */
     172    public static final void notifyUserHtmlError(Component parent, String title, String message, String html) {
     173        JPanel p = new JPanel(new GridBagLayout());
     174        p.add(new JLabel(message), GBC.eol());
     175        p.add(new JLabel(tr("Received error page:")), GBC.eol());
     176        JScrollPane sp = embedInVerticalScrollPane(new HtmlPanel(html));
     177        sp.setPreferredSize(new Dimension(640, 240));
     178        p.add(sp, GBC.eol().fill(GBC.BOTH));
     179
     180        ExtendedDialog ed = new ExtendedDialog(parent, title, new String[] {tr("OK")});
     181        ed.setButtonIcons(new String[] {"ok.png"});
     182        ed.setContent(p);
     183        ed.showDialog();
    152184    }
    153185
Note: See TracChangeset for help on using the changeset viewer.