Changeset 31390 in osm for applications/editors/josm/plugins/mapillary/src/org/openstreetmap
- Timestamp:
- 2015-07-16T13:56:24+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
- Files:
-
- 2 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryAbstractImage.java
r31386 r31390 13 13 /** 14 14 * Abstract superclass for all image objects. At the moment there is just 2, 15 * {@ codeMapillaryImportedImage} and {@codeMapillaryImage}.15 * {@link MapillaryImportedImage} and {@link MapillaryImage}. 16 16 * 17 17 * @author nokutu -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImportedImage.java
r31386 r31390 95 95 private static String currentDate() { 96 96 Calendar cal = Calendar.getInstance(); 97 98 97 SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd hh:mm:ss"); 99 98 return formatter.format(cal.getTime()); 100 101 99 } 102 100 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/HyperlinkLabel.java
r31387 r31390 109 109 /** 110 110 * Fires an ActionEvent to all interested listeners. 111 * @param evt 111 112 */ 112 113 protected void fireActionPerformed(ActionEvent evt) { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java
r31389 r31390 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.Desktop; 5 6 import java.awt.FlowLayout; 6 7 import java.awt.event.ActionEvent; 8 import java.io.IOException; 9 import java.net.URI; 10 import java.net.URISyntaxException; 7 11 8 12 import javax.swing.AbstractAction; 9 13 import javax.swing.JButton; 10 14 import javax.swing.JCheckBox; 11 import javax.swing.JDialog;12 import javax.swing.JOptionPane;13 15 import javax.swing.JPanel; 14 16 … … 18 20 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 19 21 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin; 22 import org.openstreetmap.josm.plugins.mapillary.oauth.PortListener; 20 23 21 24 /** … … 97 100 @Override 98 101 public void actionPerformed(ActionEvent arg0) { 99 JButton login = new JButton(); 100 JButton cancel = new JButton(); 101 JOptionPane pane = new JOptionPane(new MapillaryOAuthUI(), 102 JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, 103 new JButton[] { login, cancel }); 104 login.setAction(new LoginAction(pane)); 105 cancel.setAction(new CancelAction(pane)); 106 JDialog dlg = pane.createDialog(Main.parent, tr("Login")); 107 dlg.setVisible(true); 108 dlg.dispose(); 109 } 110 } 102 PortListener portListener = new PortListener(); 103 portListener.start(); 111 104 112 private class LoginAction extends AbstractAction { 113 114 private static final long serialVersionUID = -7157028112711343289L; 115 116 private JOptionPane pane; 117 118 public LoginAction(JOptionPane pane) { 119 putValue(NAME, tr("Login")); 120 this.pane = pane; 121 } 122 123 @Override 124 public void actionPerformed(ActionEvent e) { 125 pane.setValue(JOptionPane.OK_OPTION); 126 } 127 } 128 129 private class CancelAction extends AbstractAction { 130 131 private static final long serialVersionUID = 2329066472975953270L; 132 133 private JOptionPane pane; 134 135 public CancelAction(JOptionPane pane) { 136 putValue(NAME, tr("Cancel")); 137 this.pane = pane; 138 } 139 140 @Override 141 public void actionPerformed(ActionEvent e) { 142 pane.setValue(JOptionPane.CANCEL_OPTION); 105 String url = "http://www.mapillary.io/connect?redirect_uri=http:%2F%2Flocalhost:8763%2F&client_id=MkJKbDA0bnZuZlcxeTJHTmFqN3g1dzplZTlkZjQyYjYyZTczOTdi&response_type=token&scope=user:email"; 106 Desktop desktop = Desktop.getDesktop(); 107 try { 108 desktop.browse(new URI(url)); 109 } catch (IOException | URISyntaxException ex) { 110 ex.printStackTrace(); 111 } catch (UnsupportedOperationException ex) { 112 Runtime runtime = Runtime.getRuntime(); 113 try { 114 runtime.exec("xdg-open " + url); 115 } catch (IOException exc) { 116 exc.printStackTrace(); 117 } 118 } 143 119 } 144 120 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/PortListener.java
r31388 r31390 8 8 import java.util.Scanner; 9 9 10 import javax.swing.JLabel;11 import javax.swing.SwingUtilities;12 13 10 import org.openstreetmap.josm.Main; 14 11 … … 18 15 */ 19 16 public class PortListener extends Thread { 20 21 JLabel text;22 23 /**24 * Main constructor.25 *26 * @param text27 */28 public PortListener(JLabel text) {29 this.text = text;30 }31 17 32 18 @Override … … 38 24 Scanner in = new Scanner(new InputStreamReader(clientSocket.getInputStream())); 39 25 String s; 40 String code= null;26 String accessToken = null; 41 27 while (in.hasNextLine()) { 42 28 s = in.nextLine(); 43 if (s.contains("?code=")) { 44 code = s.substring(s.indexOf("=") + 1, s.indexOf("HTTP") - 1); 29 if (s.contains("access_token=")) { 30 String[] ss = s.split("&"); 31 for (int i = 0; i < ss.length; i++) { 32 if (ss[i].contains("access_token=")) { 33 accessToken = ss[i].substring(ss[i].indexOf("access_token=") + 13, ss[i].length()); 34 break; 35 } 36 } 45 37 break; 46 38 } … … 49 41 writeContent(out); 50 42 51 System.out.println("The code is: " + code); 43 Main.info("Successful login with Mapillary, the access token is: " + accessToken); 44 Main.pref.put("mapillary.access-token", accessToken); 52 45 53 46 out.close(); … … 57 50 Main.error(e); 58 51 } 59 if (!SwingUtilities.isEventDispatchThread()) {60 SwingUtilities.invokeLater(new Runnable() {61 @Override62 public void run() {63 text.setText("Authorization successful");64 }65 });66 } else67 text.setText("Authorization successful");68 52 } 69 53 70 54 private void writeContent(PrintWriter out) { 71 String response = ""; 72 response += "<html><body>Authorization successful</body></html>"; 55 String response = "<html><head><title>Mapillary login</title></head><body>Login successful, return to JOSM.</body></html>"; 73 56 out.println("HTTP/1.1 200 OK"); 74 57 out.println("Content-Length: " + response.length());
Note:
See TracChangeset
for help on using the changeset viewer.