Changeset 7466 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2014-08-30T12:58:39+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/HelpAwareOptionPane.java
r7005 r7466 211 211 * @return the index of the selected option or {@link JOptionPane#CLOSED_OPTION} 212 212 */ 213 public static int showOptionDialog(Component parentComponent, Object msg, String title, int messageType, Icon icon, final ButtonSpec[] options, final ButtonSpec defaultOption, final String helpTopic) { 213 public static int showOptionDialog(Component parentComponent, Object msg, String title, int messageType, 214 Icon icon, final ButtonSpec[] options, final ButtonSpec defaultOption, final String helpTopic) { 214 215 final List<JButton> buttons = createOptionButtons(options, helpTopic); 215 216 if (helpTopic != null) { … … 318 319 * @see #showOptionDialog(Component, Object, String, int, Icon, ButtonSpec[], ButtonSpec, String) 319 320 */ 320 public static int showOptionDialog(Component parentComponent, Object msg, String title, int messageType, finalString helpTopic) {321 return showOptionDialog(parentComponent, msg, title, messageType, null, null,null, helpTopic);321 public static int showOptionDialog(Component parentComponent, Object msg, String title, int messageType, String helpTopic) { 322 return showOptionDialog(parentComponent, msg, title, messageType, null, null, null, helpTopic); 322 323 } 323 324 324 325 /** 325 326 * Run it in Event Dispatch Thread. 326 * This version does not return anything, so it is more like showMessageDialog.327 * This version does not return anything, so it is more like {@code showMessageDialog}. 327 328 * 328 329 * It can be used, when you need to show a message dialog from a worker thread, 329 * e.g. from PleaseWaitRunnable 330 * e.g. from {@code PleaseWaitRunnable}. 331 * 332 * @param parentComponent the parent component 333 * @param msg the message 334 * @param title the title 335 * @param messageType the message type (see {@link JOptionPane}) 336 * @param helpTopic the help topic. Can be null. 330 337 */ 331 338 public static void showMessageDialogInEDT(final Component parentComponent, final Object msg, final String title, final int messageType, final String helpTopic) { -
trunk/src/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTask.java
r7082 r7466 5 5 6 6 import java.awt.Component; 7 import java.io.BufferedReader;8 7 import java.io.IOException; 9 import java.io.InputStreamReader;10 8 import java.net.HttpURLConnection; 11 9 import java.net.MalformedURLException; 12 10 import java.net.URL; 13 import java.nio.charset.StandardCharsets;14 11 15 12 import javax.swing.JOptionPane; … … 19 16 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 20 17 import org.openstreetmap.josm.gui.help.HelpUtil; 18 import org.openstreetmap.josm.io.IllegalDataException; 19 import org.openstreetmap.josm.io.OsmChangesetParser; 21 20 import org.openstreetmap.josm.io.OsmTransferException; 22 21 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 33 32 * to "https://x.y.y/api/0/capabilities" or "https://x.y.y/a/capabilities" with valid capabilities. If we get 34 33 * valid capabilities with an URL we therefore can't be sure that the base URL is valid API URL. 35 * 34 * @since 2745 36 35 */ 37 public class ApiUrlTestTask extends PleaseWaitRunnable {38 39 private String url;36 public class ApiUrlTestTask extends PleaseWaitRunnable { 37 38 private final String url; 40 39 private boolean canceled; 41 40 private boolean success; 42 private Component parent;41 private final Component parent; 43 42 private HttpURLConnection connection; 44 43 45 44 /** 46 * C reates the task45 * Constructs a new {@code ApiUrlTestTask}. 47 46 * 48 47 * @param parent the parent component relative to which the {@link PleaseWaitRunnable}-Dialog is displayed … … 58 57 59 58 protected void alertInvalidUrl(String url) { 60 HelpAwareOptionPane.show OptionDialog(59 HelpAwareOptionPane.showMessageDialogInEDT( 61 60 parent, 62 61 tr("<html>" … … 73 72 74 73 protected void alertInvalidChangesetUrl(String url) { 75 HelpAwareOptionPane.show OptionDialog(74 HelpAwareOptionPane.showMessageDialogInEDT( 76 75 parent, 77 76 tr("<html>" … … 89 88 90 89 protected void alertConnectionFailed() { 91 HelpAwareOptionPane.show OptionDialog(90 HelpAwareOptionPane.showMessageDialogInEDT( 92 91 parent, 93 92 tr("<html>" … … 105 104 106 105 protected void alertInvalidServerResult(int retCode) { 107 HelpAwareOptionPane.show OptionDialog(106 HelpAwareOptionPane.showMessageDialogInEDT( 108 107 parent, 109 108 tr("<html>" … … 122 121 123 122 protected void alertInvalidChangesetList() { 124 HelpAwareOptionPane.show OptionDialog(123 HelpAwareOptionPane.showMessageDialogInEDT( 125 124 parent, 126 125 tr("<html>" … … 194 193 return; 195 194 } 196 StringBuilder changesets = new StringBuilder(); 197 try (BufferedReader bin = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) { 198 String line; 199 while ((line = bin.readLine()) != null) { 200 changesets.append(line).append("\n"); 195 196 try { 197 OsmChangesetParser.parse(connection.getInputStream(), progressMonitor.createSubTaskMonitor(1, true)); 198 } catch (IllegalDataException e) { 199 if (e.getCause() instanceof IOException) { 200 throw (IOException) e.getCause(); 201 } else { 202 Main.warn(e.getMessage()); 203 alertInvalidChangesetList(); 204 return; 201 205 } 202 }203 if (! (changesets.toString().contains("<osm") && changesets.toString().contains("</osm>"))) {204 // heuristic: if there isn't an opening and closing "<osm>" tag in the returned content,205 // then we didn't get a list of changesets in return. Could be replaced by explicitly parsing206 // the result but currently not worth the effort.207 alertInvalidChangesetList();208 return;209 206 } 210 207 success = true;
Note:
See TracChangeset
for help on using the changeset viewer.