Changeset 19141 in josm
- Timestamp:
- 2024-07-15T20:55:18+02:00 (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/oauth/OAuth20Authorization.java
r18786 r19141 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Dimension; 6 7 import java.io.IOException; 7 8 import java.net.MalformedURLException; … … 17 18 import java.util.function.Consumer; 18 19 20 import javax.swing.JOptionPane; 21 import javax.swing.JScrollPane; 22 23 import org.openstreetmap.josm.gui.MainApplication; 24 import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils; 25 import org.openstreetmap.josm.gui.util.GuiHelper; 26 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 19 27 import org.openstreetmap.josm.io.remotecontrol.handler.AuthorizationHandler; 20 28 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler; … … 56 64 + "&code_challenge_method=S256&code_challenge=" + s256CodeChallenge; 57 65 AuthorizationHandler.addAuthorizationConsumer(state, new OAuth20AuthorizationHandler(state, codeVerifier, parameters, consumer)); 58 OpenBrowser.displayUrl(url); 66 GuiHelper.runInEDT(() -> showUrlOpenFailure(url, OpenBrowser.displayUrl(url))); 67 } 68 69 /** 70 * Show a message if a URL fails to open 71 * @param url The URL that failed to open 72 * @param error The message indicating why the URL failed to open; if {@code null}, no message is shown. 73 */ 74 private static void showUrlOpenFailure(String url, String error) { 75 if (error != null) { 76 final HtmlPanel textField = new HtmlPanel("<html><body>" 77 + tr("The web browser failed to open with the following error: \"{0}\".<br>\n" 78 + "Please open the following url:<br>\n" 79 + "<a href=\"{1}\">{1}</a><br>\n" 80 + "Should we copy the URL to the clipboard?", error, url) 81 + "</body></html>"); 82 textField.enableClickableHyperlinks(); 83 final JScrollPane scrollPane = new JScrollPane(textField); 84 // Ensure that the scroll pane doesn't extend too much or too little. 85 // For now, assume that the user hasn't made the main JOSM frame beyond monitors. 86 scrollPane.setPreferredSize(new Dimension(Math.min(textField.getPreferredSize().width + 32, 87 MainApplication.getMainFrame().getWidth() - 240 /* warning image + buffer */), 88 textField.getPreferredSize().height + scrollPane.getHorizontalScrollBar().getPreferredSize().height * 2)); 89 GuiHelper.prepareResizeableOptionPane(scrollPane, scrollPane.getPreferredSize()); 90 int answer = JOptionPane.showConfirmDialog(MainApplication.getMainFrame(), scrollPane, tr("Failed to open browser"), 91 JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE); 92 if (answer == JOptionPane.YES_OPTION) { 93 ClipboardUtils.copyString(url); 94 } 95 } 59 96 } 60 97
Note:
See TracChangeset
for help on using the changeset viewer.