Changeset 16162 in osm for applications/editors/josm/plugins/utilsplugin/src
- Timestamp:
- 2009-06-26T22:11:40+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin/src/UtilsPlugin
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin/src/UtilsPlugin/JoinAreasAction.java
r15960 r16162 3 3 import static org.openstreetmap.josm.tools.I18n.marktr; 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.tools.I18n.trn; 6 5 6 import java.awt.GridBagLayout; 7 import java.awt.Polygon; 7 8 import java.awt.event.ActionEvent; 8 9 import java.awt.event.KeyEvent; 9 10 import java.awt.geom.Line2D; 10 import java.awt.geom.Point2D;11 import java.awt.GridBagLayout;12 import java.awt.Point;13 import java.awt.Polygon;14 15 11 import java.util.ArrayList; 16 import java.util.Arrays;17 12 import java.util.Collection; 18 13 import java.util.Collections; 19 import java.util.Comparator;20 14 import java.util.HashMap; 21 15 import java.util.LinkedList; 22 16 import java.util.List; 23 17 import java.util.Map; 24 import java.util.Map.Entry;25 18 import java.util.Set; 26 19 import java.util.TreeMap; 27 20 import java.util.TreeSet; 21 import java.util.Map.Entry; 28 22 29 23 import javax.swing.Box; … … 33 27 import javax.swing.JPanel; 34 28 29 import org.openstreetmap.josm.Main; 35 30 import org.openstreetmap.josm.actions.CombineWayAction; 36 31 import org.openstreetmap.josm.actions.JosmAction; 37 32 import org.openstreetmap.josm.actions.ReverseWayAction; 38 33 import org.openstreetmap.josm.actions.SplitWayAction; 39 40 34 import org.openstreetmap.josm.command.AddCommand; 41 35 import org.openstreetmap.josm.command.ChangeCommand; … … 43 37 import org.openstreetmap.josm.command.DeleteCommand; 44 38 import org.openstreetmap.josm.command.SequenceCommand; 45 46 39 import org.openstreetmap.josm.data.Bounds; 40 import org.openstreetmap.josm.data.UndoRedoHandler; 47 41 import org.openstreetmap.josm.data.coor.EastNorth; 48 42 import org.openstreetmap.josm.data.coor.LatLon; … … 54 48 import org.openstreetmap.josm.data.osm.RelationMember; 55 49 import org.openstreetmap.josm.data.osm.TigerUtils; 56 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;57 50 import org.openstreetmap.josm.data.osm.Way; 58 import org.openstreetmap.josm.data.osm.WaySegment;59 import org.openstreetmap.josm.data.projection.Epsg4326;60 import org.openstreetmap.josm.data.projection.Lambert;61 import org.openstreetmap.josm.data.projection.Mercator;62 import org.openstreetmap.josm.data.UndoRedoHandler;63 64 51 import org.openstreetmap.josm.gui.ExtendedDialog; 65 52 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 66 import org.openstreetmap.josm.Main;67 53 import org.openstreetmap.josm.tools.GBC; 68 import org.openstreetmap.josm.tools.Pair;69 54 import org.openstreetmap.josm.tools.Shortcut; 70 55 … … 83 68 this.pos = pos; 84 69 this.n = n; 85 this.dis = n. coor.greatCircleDistance(dis);70 this.dis = n.getCoor().greatCircleDistance(dis); 86 71 } 87 72 … … 160 145 boolean isInsideOneBoundingBox = false; 161 146 for (Bounds b : bounds) { 162 if (b.contains(node. coor)) {147 if (b.contains(node.getCoor())) { 163 148 isInsideOneBoundingBox = true; 164 149 break; … … 362 347 } 363 348 LatLon intersection = getLineLineIntersection( 364 a.nodes.get(i) . eastNorth.east(), a.nodes.get(i) .eastNorth.north(),365 a.nodes.get(i+1). eastNorth.east(), a.nodes.get(i+1).eastNorth.north(),366 b.nodes.get(j) . eastNorth.east(), b.nodes.get(j) .eastNorth.north(),367 b.nodes.get(j+1). eastNorth.east(), b.nodes.get(j+1).eastNorth.north());349 a.nodes.get(i) .getEastNorth().east(), a.nodes.get(i) .getEastNorth().north(), 350 a.nodes.get(i+1).getEastNorth().east(), a.nodes.get(i+1).getEastNorth().north(), 351 b.nodes.get(j) .getEastNorth().east(), b.nodes.get(j) .getEastNorth().north(), 352 b.nodes.get(j+1).getEastNorth().east(), b.nodes.get(j+1).getEastNorth().north()); 368 353 if(intersection == null) continue; 369 354 … … 373 358 nodes.add(n); 374 359 // The distance is needed to sort and add the nodes in direction of the way 375 nodesA.add(new NodeToSegs(i, n, a.nodes.get(i). coor));360 nodesA.add(new NodeToSegs(i, n, a.nodes.get(i).getCoor())); 376 361 if(same) 377 nodesA.add(new NodeToSegs(j, n, a.nodes.get(j). coor));362 nodesA.add(new NodeToSegs(j, n, a.nodes.get(j).getCoor())); 378 363 else 379 nodesB.add(new NodeToSegs(j, n, b.nodes.get(j). coor));364 nodesB.add(new NodeToSegs(j, n, b.nodes.get(j).getCoor())); 380 365 } 381 366 } … … 423 408 private void addNodesToWay(Way a, ArrayList<NodeToSegs> nodes) { 424 409 Way ax=new Way(a); 425 List<NodeToSegs> newnodes = new ArrayList<NodeToSegs>();426 410 Collections.sort(nodes); 427 411 … … 539 523 for(Way w: multigonWays) { 540 524 Polygon poly = new Polygon(); 541 for(Node n: ( (Way)w).nodes) poly.addPoint(latlonToXY(n.coor.lat()), latlonToXY(n.coor.lon()));525 for(Node n: (w).nodes) poly.addPoint(latlonToXY(n.getCoor().lat()), latlonToXY(n.getCoor().lon())); 542 526 543 527 for(Node n: multigonNodes) { 544 if(!( (Way)w).nodes.contains(n) && poly.contains(latlonToXY(n.coor.lat()), latlonToXY(n.coor.lon()))) {528 if(!(w).nodes.contains(n) && poly.contains(latlonToXY(n.getCoor().lat()), latlonToXY(n.getCoor().lon()))) { 545 529 getWaysByNode(innerWays, multigonWays, n); 546 530 } … … 564 548 private void getWaysByNode(Collection<Way> innerWays, Collection<Way> w, Node n) { 565 549 for(Way way : w) { 566 if(!( (Way)way).nodes.contains(n)) continue;550 if(!(way).nodes.contains(n)) continue; 567 551 if(!innerWays.contains(way)) innerWays.add(way); // Will need this later for multigons 568 552 } -
applications/editors/josm/plugins/utilsplugin/src/UtilsPlugin/JumpToAction.java
r13575 r16162 4 4 5 5 import java.awt.BorderLayout; 6 import java.awt. Component;6 import java.awt.GridBagLayout; 7 7 import java.awt.event.ActionEvent; 8 import java.awt.event.InputEvent;9 8 import java.awt.event.KeyEvent; 9 import java.awt.event.MouseEvent; 10 10 import java.awt.event.MouseListener; 11 import java.awt.event.MouseEvent;12 import java.awt.GridBagLayout;13 import java.awt.GridLayout;14 import java.awt.Toolkit;15 11 16 import javax.swing.Box;17 import javax.swing.event.DocumentListener;18 import javax.swing.event.DocumentEvent;19 import javax.swing.JComponent;20 import javax.swing.JDialog;21 12 import javax.swing.JLabel; 22 13 import javax.swing.JOptionPane; 23 14 import javax.swing.JPanel; 24 15 import javax.swing.JTextField; 25 import javax.swing.KeyStroke; 16 import javax.swing.event.DocumentEvent; 17 import javax.swing.event.DocumentListener; 26 18 27 19 import org.openstreetmap.josm.Main; 28 20 import org.openstreetmap.josm.actions.JosmAction; 29 21 import org.openstreetmap.josm.data.Bounds; 30 import org.openstreetmap.josm.data.coor.EastNorth;31 22 import org.openstreetmap.josm.data.coor.LatLon; 32 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 33 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 23 import org.openstreetmap.josm.gui.NavigatableComponent; 34 24 import org.openstreetmap.josm.tools.GBC; 35 25 import org.openstreetmap.josm.tools.OsmUrlToBounds; … … 41 31 KeyEvent.VK_G, Shortcut.GROUP_HOTKEY), true); 42 32 } 43 33 44 34 private JTextField url = new JTextField(); 45 35 private JTextField lat = new JTextField(); 46 36 private JTextField lon = new JTextField(); 47 37 private JTextField zm = new JTextField(); 48 38 49 39 private double zoomFactor = 0; 50 40 public void showJumpToDialog() { … … 52 42 lat.setText(java.lang.Double.toString(curPos.lat())); 53 43 lon.setText(java.lang.Double.toString(curPos.lon())); 54 44 55 45 LatLon ll1 = Main.map.mapView.getLatLon(0,0); 56 46 LatLon ll2 = Main.map.mapView.getLatLon(100,0); 57 47 double dist = ll1.greatCircleDistance(ll2); 58 48 zoomFactor = Main.map.mapView.getScale()/dist; 59 49 60 50 zm.setText(java.lang.Long.toString(Math.round(dist*100)/100)); 61 51 updateUrl(true); 62 52 63 53 JPanel panel = new JPanel(new BorderLayout()); 64 54 panel.add(new JLabel("<html>" … … 69 59 + "</html>"), 70 60 BorderLayout.NORTH); 71 72 class osmURLListener implements DocumentListener { 73 public void changedUpdate(DocumentEvent e) { parseURL(); } 74 public void insertUpdate(DocumentEvent e) { parseURL(); } 75 public void removeUpdate(DocumentEvent e) { parseURL(); } 61 62 class osmURLListener implements DocumentListener { 63 public void changedUpdate(DocumentEvent e) { parseURL(); } 64 public void insertUpdate(DocumentEvent e) { parseURL(); } 65 public void removeUpdate(DocumentEvent e) { parseURL(); } 76 66 } 77 78 class osmLonLatListener implements DocumentListener { 79 public void changedUpdate(DocumentEvent e) { updateUrl(false); } 80 public void insertUpdate(DocumentEvent e) { updateUrl(false); } 81 public void removeUpdate(DocumentEvent e) { updateUrl(false); } 82 } 83 67 68 class osmLonLatListener implements DocumentListener { 69 public void changedUpdate(DocumentEvent e) { updateUrl(false); } 70 public void insertUpdate(DocumentEvent e) { updateUrl(false); } 71 public void removeUpdate(DocumentEvent e) { updateUrl(false); } 72 } 73 84 74 osmLonLatListener x=new osmLonLatListener(); 85 lat.getDocument().addDocumentListener(x); 86 lon.getDocument().addDocumentListener(x); 87 zm.getDocument().addDocumentListener(x); 88 url.getDocument().addDocumentListener(new osmURLListener()); 89 75 lat.getDocument().addDocumentListener(x); 76 lon.getDocument().addDocumentListener(x); 77 zm.getDocument().addDocumentListener(x); 78 url.getDocument().addDocumentListener(new osmURLListener()); 79 90 80 JPanel p = new JPanel(new GridBagLayout()); 91 81 panel.add(p, BorderLayout.NORTH); 92 82 93 83 p.add(new JLabel(tr("Latitude")), GBC.eol()); 94 84 p.add(lat, GBC.eol().fill(GBC.HORIZONTAL)); 95 85 96 86 p.add(new JLabel(tr("Longitude")), GBC.eol()); 97 87 p.add(lon, GBC.eol().fill(GBC.HORIZONTAL)); 98 88 99 89 p.add(new JLabel(tr("Zoom (in metres)")), GBC.eol()); 100 90 p.add(zm, GBC.eol().fill(GBC.HORIZONTAL)); 101 91 102 92 p.add(new JLabel(tr("URL")), GBC.eol()); 103 93 p.add(url, GBC.eol().fill(GBC.HORIZONTAL)); 104 94 105 95 Object[] buttons = { tr("Jump there"), tr("Cancel") }; 106 96 LatLon ll = null; … … 116 106 buttons, 117 107 buttons[0]); 118 108 119 109 if (option != JOptionPane.OK_OPTION) return; 120 110 try { … … 125 115 } 126 116 } 127 117 128 118 Main.map.mapView.zoomTo(Main.proj.latlon2eastNorth(ll), zoomFactor * zoomLvl); 129 119 } 130 120 131 121 private void parseURL() { 132 122 if(!url.hasFocus()) return; … … 135 125 lat.setText(Double.toString((b.min.lat() + b.max.lat())/2)); 136 126 lon.setText(Double.toString((b.min.lon() + b.max.lon())/2)); 137 127 138 128 int zoomLvl = 16; 139 String[] args = url.getText().substring(url.getText().indexOf('?')+1).split("&"); 140 for (String arg : args) { 141 int eq = arg.indexOf('='); 142 if (eq == -1 || !arg.substring(0, eq).equalsIgnoreCase("zoom")) continue; 143 129 String[] args = url.getText().substring(url.getText().indexOf('?')+1).split("&"); 130 for (String arg : args) { 131 int eq = arg.indexOf('='); 132 if (eq == -1 || !arg.substring(0, eq).equalsIgnoreCase("zoom")) continue; 133 144 134 zoomLvl = Integer.parseInt(arg.substring(eq + 1)); 145 135 break; 146 136 } 147 137 148 138 // 10000000 = 10 000 * 1000 = World * (km -> m) 149 139 zm.setText(Double.toString(Math.round(10000000 * Math.pow(2, (-1) * zoomLvl)))); 150 140 } 151 141 } 152 142 153 143 private void updateUrl(boolean force) { 154 144 if(!lat.hasFocus() && !lon.hasFocus() && !zm.hasFocus() && !force) return; … … 170 160 showJumpToDialog(); 171 161 } 172 162 173 163 /** 174 * Converts a given scale into OSM-Style zoom factors 164 * Converts a given scale into OSM-Style zoom factors 175 165 * @param double scale 176 */ 166 */ 177 167 public int getZoom(double scale) { 178 168 double sizex = scale * Main.map.mapView.getWidth(); 179 169 double sizey = scale * Main.map.mapView.getHeight(); 180 170 for (int zoom = 0; zoom <= 32; zoom++, sizex *= 2, sizey *= 2) 181 if (sizex > Main.map.mapView.world.east() || sizey > Main.map.mapView.world.north())171 if (sizex > NavigatableComponent.world.east() || sizey > NavigatableComponent.world.north()) 182 172 return zoom; 183 173 return 32; 184 174 } 185 175 186 176 public void mousePressed(MouseEvent e) {} 187 177 -
applications/editors/josm/plugins/utilsplugin/src/UtilsPlugin/SimplifyWayAction.java
r14121 r16162 55 55 boolean isInsideOneBoundingBox = false; 56 56 for (Bounds b : bounds) { 57 if (b.contains(node. coor)) {57 if (b.contains(node.getCoor())) { 58 58 isInsideOneBoundingBox = true; 59 59 break; … … 161 161 Node n = wnew.nodes.get(i); 162 162 double xte = Math.abs(EARTH_RAD 163 * xtd(fromN. coor.lat() * Math.PI / 180, fromN.coor.lon() * Math.PI / 180, toN.coor.lat() * Math.PI164 / 180, toN. coor.lon() * Math.PI / 180, n.coor.lat() * Math.PI / 180, n.coor.lon() * Math.PI163 * xtd(fromN.getCoor().lat() * Math.PI / 180, fromN.getCoor().lon() * Math.PI / 180, toN.getCoor().lat() * Math.PI 164 / 180, toN.getCoor().lon() * Math.PI / 180, n.getCoor().lat() * Math.PI / 180, n.getCoor().lon() * Math.PI 165 165 / 180)); 166 166 if (xte > xtemax) { -
applications/editors/josm/plugins/utilsplugin/src/UtilsPlugin/UtilsPlugin.java
r14120 r16162 1 1 package UtilsPlugin; 2 2 3 import static org.openstreetmap.josm.tools.I18n.tr;4 5 6 import java.awt.event.ActionEvent;7 import javax.swing.AbstractAction;8 3 import javax.swing.JMenuItem; 9 import javax.swing.JOptionPane;10 import javax.swing.JPanel;11 import javax.swing.BoxLayout;12 4 13 5 import org.openstreetmap.josm.Main; 6 import org.openstreetmap.josm.gui.MainMenu; 7 import org.openstreetmap.josm.gui.MapFrame; 14 8 import org.openstreetmap.josm.plugins.Plugin; 15 import org.openstreetmap.josm.gui.MapFrame;16 import org.openstreetmap.josm.gui.MainMenu;17 import org.openstreetmap.josm.gui.IconToggleButton;18 import org.openstreetmap.josm.actions.JosmAction;19 9 20 10 public class UtilsPlugin extends Plugin {
Note:
See TracChangeset
for help on using the changeset viewer.