Changeset 32844 in osm for applications/editors/josm/plugins/pointInfo/src/org
- Timestamp:
- 2016-08-20T03:01:04+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pointInfo/src/org/openstreetmap/josm/plugins/pointinfo
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pointInfo/src/org/openstreetmap/josm/plugins/pointinfo/PointInfoAction.java
r30833 r32844 1 /** 2 * PointInfo - plugin for JOSM 3 * Marian Kyral 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.pointinfo; 20 3 21 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 22 6 import java.awt.Cursor; 23 7 import java.awt.Point; … … 27 11 import java.awt.event.MouseEvent; 28 12 import java.awt.event.MouseListener; 29 // import java.awt.event.KeyListener; 30 import java.util.ArrayList; 31 import java.util.Collection; 32 import java.util.LinkedList; 33 import javax.swing.SwingConstants; 13 14 import javax.swing.ImageIcon; 34 15 import javax.swing.JEditorPane; 35 16 import javax.swing.JOptionPane; 36 17 import javax.swing.JScrollPane; 37 import javax.swing.ImageIcon;38 18 import javax.swing.event.HyperlinkEvent; 39 19 import javax.swing.event.HyperlinkListener; … … 41 21 import org.openstreetmap.josm.Main; 42 22 import org.openstreetmap.josm.actions.mapmode.MapMode; 43 import org.openstreetmap.josm.command.AddCommand;44 import org.openstreetmap.josm.command.Command;45 import org.openstreetmap.josm.command.SequenceCommand;46 23 import org.openstreetmap.josm.data.coor.LatLon; 47 import org.openstreetmap.josm.data.osm.Node; 48 import org.openstreetmap.josm.data.osm.Way; 24 import org.openstreetmap.josm.gui.MapFrame; 49 25 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 50 26 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 51 import org.openstreetmap.josm.gui.MapFrame;52 27 import org.openstreetmap.josm.tools.ImageProvider; 28 import org.openstreetmap.josm.tools.OpenBrowser; 53 29 import org.openstreetmap.josm.tools.Shortcut; 54 import org.openstreetmap.josm.tools.OpenBrowser;55 30 import org.xml.sax.SAXException; 56 31 … … 58 33 59 34 private static final long serialVersionUID = 1L; 60 61 35 62 36 protected boolean cancel; … … 66 40 private String coordinatesText = ""; 67 41 68 public PointInfoAction(MapFrame mapFrame) { 69 super(tr("Point info"), "info-sml", tr("Point info."), Shortcut.registerShortcut("tools:pointInfo", tr("Tool: {0}", tr("Point info")), KeyEvent.VK_X, Shortcut.CTRL_SHIFT), mapFrame, getCursor()); 42 PointInfoAction(MapFrame mapFrame) { 43 super(tr("Point info"), "info-sml", tr("Point info."), 44 Shortcut.registerShortcut("tools:pointInfo", tr("Tool: {0}", tr("Point info")), KeyEvent.VK_X, Shortcut.CTRL_SHIFT), 45 mapFrame, getCursor()); 70 46 } 71 47 … … 78 54 Main.map.mapView.setCursor(getCursor()); 79 55 Main.map.mapView.addMouseListener(this); 80 81 56 } 82 57 … … 100 75 try { 101 76 PleaseWaitRunnable infoTask = new PleaseWaitRunnable(tr("Connecting server")) { 102 103 77 @Override 104 78 protected void realRun() throws SAXException { … … 108 82 @Override 109 83 protected void finish() { 110 111 84 } 112 85 113 86 @Override 114 87 protected void afterFinish() { 115 if (htmlText.length() > 0) { 116 117 // Show result 118 JEditorPane msgLabel = new JEditorPane("text/html", htmlText); 119 msgLabel.setEditable(false); 120 msgLabel.setOpaque(false); 121 msgLabel.addHyperlinkListener(new HyperlinkListener() { 122 public void hyperlinkUpdate(HyperlinkEvent hle) { 123 if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) { 124 if (hle.getURL() == null || hle.getURL().toString().isEmpty()) { 125 return; 88 if (htmlText.length() > 0) { 89 // Show result 90 JEditorPane msgLabel = new JEditorPane("text/html", htmlText); 91 msgLabel.setEditable(false); 92 msgLabel.setOpaque(false); 93 msgLabel.addHyperlinkListener(new HyperlinkListener() { 94 @Override 95 public void hyperlinkUpdate(HyperlinkEvent hle) { 96 if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) { 97 if (hle.getURL() == null || hle.getURL().toString().isEmpty()) { 98 return; 99 } 100 System.out.println("URL: "+ hle.getURL()); 101 if (!hle.getURL().toString().startsWith("http")) { 102 mRuian.performAction(hle.getURL().toString()); 103 } else { 104 String ret = OpenBrowser.displayUrl(hle.getURL().toString()); 105 if (ret != null) { 106 PointInfoUtils.showNotification(ret, "error"); 107 } 108 } 109 } 126 110 } 127 System.out.println("URL: "+ hle.getURL()); 128 if (! hle.getURL().toString().startsWith("http")) { 129 mRuian.performAction(hle.getURL().toString()); 130 } else { 131 String ret = OpenBrowser.displayUrl(hle.getURL().toString()); 132 if (ret != null) { 133 PointInfoUtils.showNotification(ret, "error"); 134 } 135 } 136 } 137 } 138 }); 139 JScrollPane scrollPane = new JScrollPane(msgLabel); 140 Object[] objects = {scrollPane}; 141 final ImageIcon icon = new ImageIcon(getClass().getResource("/images/dialogs/info-sml.png")); 142 JOptionPane.showMessageDialog( 143 null, objects, tr("PointInfo") + " " + coordinatesText, JOptionPane.PLAIN_MESSAGE,icon); 144 } 111 }); 112 JScrollPane scrollPane = new JScrollPane(msgLabel); 113 Object[] objects = {scrollPane}; 114 final ImageIcon icon = new ImageIcon(getClass().getResource("/images/dialogs/info-sml.png")); 115 JOptionPane.showMessageDialog( 116 null, objects, tr("PointInfo") + " " + coordinatesText, JOptionPane.PLAIN_MESSAGE, icon); 117 } 145 118 } 146 119 … … 150 123 } 151 124 }; 152 Thread executeInfoThread = new Thread(infoTask); 153 executeInfoThread.start(); 125 new Thread(infoTask).start(); 154 126 } catch (Exception e) { 155 127 e.printStackTrace(); … … 161 133 progressMonitor.beginTask(null, 3); 162 134 try { 163 164 165 135 mRuian.prepareData(pos); 136 htmlText = mRuian.getHtml(); 137 coordinatesText = PointInfoUtils.formatCoordinates(pos.lat(), pos.lon()); 166 138 167 139 } finally { … … 170 142 progressMonitor.invalidate(); 171 143 if (htmlText.length() == 0) { 172 PointInfoUtils.showNotification(tr("Data not available.")+ "\n(" + pos.toDisplayString() + ")", "warning");173 return;144 PointInfoUtils.showNotification(tr("Data not available.")+ "\n(" + pos.toDisplayString() + ")", "warning"); 145 return; 174 146 } 175 147 } … … 199 171 updateKeyModifiers(e); 200 172 if (e.getButton() == MouseEvent.BUTTON1) { 201 infoAsync(e.getPoint());173 infoAsync(e.getPoint()); 202 174 } 203 175 } -
applications/editors/josm/plugins/pointInfo/src/org/openstreetmap/josm/plugins/pointinfo/PointInfoPlugin.java
r30328 r32844 1 /** 2 * PointInfo - plugin for JOSM 3 * Marián Kyral 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 1 // License: GPL. For details, see LICENSE file. 20 2 package org.openstreetmap.josm.plugins.pointinfo; 21 22 import java.util.ArrayList;23 3 24 4 import org.openstreetmap.josm.Main; 25 5 import org.openstreetmap.josm.gui.MainMenu; 26 // import org.openstreetmap.josm.gui.preferences.PreferenceSetting;27 6 import org.openstreetmap.josm.plugins.Plugin; 28 7 import org.openstreetmap.josm.plugins.PluginInformation; 29 8 30 31 32 9 /** 33 10 * This is the main class for the PointInfo plugin. 34 *35 11 */ 36 public class PointInfoPlugin extends Plugin {12 public class PointInfoPlugin extends Plugin { 37 13 38 public PointInfoPlugin(PluginInformation info) { 39 super(info); 40 MainMenu.add(Main.main.menu.moreToolsMenu, new PointInfoAction(Main.map)); 41 42 // @Override 43 // public PreferenceSetting getPreferenceSetting() { 44 // return new PreferenceEditor(); 14 public PointInfoPlugin(PluginInformation info) { 15 super(info); 16 MainMenu.add(Main.main.menu.moreToolsMenu, new PointInfoAction(Main.map)); 45 17 } 46 18 } -
applications/editors/josm/plugins/pointInfo/src/org/openstreetmap/josm/plugins/pointinfo/PointInfoServer.java
r30328 r32844 1 /** 2 * PointInfo - plugin for JOSM 3 * Marian Kyral 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 1 // License: GPL. For details, see LICENSE file. 20 2 package org.openstreetmap.josm.plugins.pointinfo; 21 3 … … 23 5 import java.io.InputStreamReader; 24 6 import java.net.URL; 25 import java.util.ArrayList;26 import org.openstreetmap.josm.data.coor.LatLon;27 7 28 8 public class PointInfoServer { … … 46 26 while ((line = reader.readLine()) != null) { 47 27 if (sb.length() == 0) 48 sb.append(line);28 sb.append(line); 49 29 else 50 sb.append(" "+line);30 sb.append(" "+line); 51 31 } 52 32 return sb.toString(); -
applications/editors/josm/plugins/pointInfo/src/org/openstreetmap/josm/plugins/pointinfo/PointInfoUtils.java
r30328 r32844 1 /** 2 * PointInfo - plugin for JOSM 3 * Marian Kyral 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 1 // License: GPL. For details, see LICENSE file. 20 2 package org.openstreetmap.josm.plugins.pointinfo; 21 3 22 4 import java.text.DecimalFormat; 23 5 import java.text.DecimalFormatSymbols; 6 24 7 import javax.swing.JOptionPane; 25 8 26 9 import org.openstreetmap.josm.gui.Notification; 27 28 10 29 11 public abstract class PointInfoUtils { … … 34 16 * @param type Type if message (info, warning, error, plain). 35 17 */ 36 public static void showNotification 37 Notification note = new Notification(message);18 public static void showNotification(String message, String type) { 19 Notification note = new Notification(message); 38 20 39 if (type.equals("info"))40 note.setIcon(JOptionPane.INFORMATION_MESSAGE);41 else if (type.equals("warning"))42 note.setIcon(JOptionPane.WARNING_MESSAGE);43 else if (type.equals("error"))44 note.setIcon(JOptionPane.ERROR_MESSAGE);45 else46 note.setIcon(JOptionPane.PLAIN_MESSAGE);21 if (type.equals("info")) 22 note.setIcon(JOptionPane.INFORMATION_MESSAGE); 23 else if (type.equals("warning")) 24 note.setIcon(JOptionPane.WARNING_MESSAGE); 25 else if (type.equals("error")) 26 note.setIcon(JOptionPane.ERROR_MESSAGE); 27 else 28 note.setIcon(JOptionPane.PLAIN_MESSAGE); 47 29 48 note.setDuration(Notification.TIME_SHORT);49 note.show();30 note.setDuration(Notification.TIME_SHORT); 31 note.show(); 50 32 } 51 33 … … 56 38 * @return String coordinatesText 57 39 */ 58 public static String formatCoordinates 40 public static String formatCoordinates(double lat, double lon) { 59 41 60 String r = "";61 DecimalFormatSymbols symbols = new DecimalFormatSymbols();62 symbols.setDecimalSeparator('.');63 symbols.setGroupingSeparator(' ');64 DecimalFormat df = new DecimalFormat("#.00000", symbols);42 String r = ""; 43 DecimalFormatSymbols symbols = new DecimalFormatSymbols(); 44 symbols.setDecimalSeparator('.'); 45 symbols.setGroupingSeparator(' '); 46 DecimalFormat df = new DecimalFormat("#.00000", symbols); 65 47 66 r = "(" + df.format(lat) + ", " +48 r = "(" + df.format(lat) + ", " + 67 49 df.format(lon) + ")"; 68 return r;50 return r; 69 51 } 70 71 52 }
Note:
See TracChangeset
for help on using the changeset viewer.