Changeset 41 in josm for src/org/openstreetmap
- Timestamp:
- 2006-01-19T08:22:18+01:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 2 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/DownloadAction.java
r40 r41 1 1 package org.openstreetmap.josm.actions; 2 2 3 import java.awt.Dimension; 3 4 import java.awt.GridBagLayout; 4 5 import java.awt.GridLayout; … … 30 31 import org.openstreetmap.josm.gui.MapFrame; 31 32 import org.openstreetmap.josm.gui.MapView; 33 import org.openstreetmap.josm.gui.WorldChooser; 32 34 import org.openstreetmap.josm.gui.BookmarkList.Bookmark; 33 35 import org.openstreetmap.josm.gui.layer.Layer; … … 60 62 public void actionPerformed(ActionEvent e) { 61 63 JPanel dlg = new JPanel(new GridBagLayout()); 64 65 WorldChooser wc = new WorldChooser(); 66 dlg.add(wc, GBC.eop()); 67 62 68 dlg.add(new JLabel("Bounding box"), GBC.eol()); 63 64 69 dlg.add(new JLabel("min lat"), GBC.std().insets(10,0,5,0)); 65 70 dlg.add(latlon[0], GBC.std()); … … 139 144 dlg.add(buttons, GBC.eop().fill(GBC.HORIZONTAL)); 140 145 146 Dimension d = dlg.getPreferredSize(); 147 wc.setPreferredSize(new Dimension(d.width, d.width/2)); 148 141 149 int r = JOptionPane.showConfirmDialog(Main.main, dlg, "Choose an area", 142 150 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); -
src/org/openstreetmap/josm/data/GeoPoint.java
r40 r41 35 35 this.lat = lat; 36 36 this.lon = lon; 37 } 38 39 /** 40 * Construct the point with all values available. 41 */ 42 public GeoPoint(double lat, double lon, double x, double y) { 43 this.lat = lat; 44 this.lon = lon; 45 this.x = x; 46 this.y = y; 37 47 } 38 48 -
src/org/openstreetmap/josm/data/Preferences.java
r38 r41 55 55 * Base URL to the osm data server 56 56 */ 57 public String osmDataServer = "http://www.openstreetmap.org/api/0. 1";57 public String osmDataServer = "http://www.openstreetmap.org/api/0.2"; 58 58 /** 59 59 * The username to the osm server -
src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r35 r41 9 9 import org.openstreetmap.josm.data.osm.Node; 10 10 import org.openstreetmap.josm.data.osm.Track; 11 import org.openstreetmap.josm.gui. MapView;11 import org.openstreetmap.josm.gui.NavigatableComponent; 12 12 13 13 /** … … 29 29 * MapView to get screen coordinates. 30 30 */ 31 private final MapView mv;31 private final NavigatableComponent nc; 32 32 33 33 /** … … 36 36 * @param mv The view to get screen coordinates from. 37 37 */ 38 public SimplePaintVisitor(Graphics g, MapViewmv) {38 public SimplePaintVisitor(Graphics g, NavigatableComponent mv) { 39 39 this.g = g; 40 this. mv= mv;40 this.nc = mv; 41 41 } 42 42 … … 83 83 */ 84 84 private void drawNode(Node n, Color color) { 85 Point p = mv.getScreenPoint(n.coor);85 Point p = nc.getScreenPoint(n.coor); 86 86 g.setColor(color); 87 87 g.drawRect(p.x-1, p.y-1, 2, 2); … … 95 95 col = Color.WHITE; 96 96 g.setColor(col); 97 Point p1 = mv.getScreenPoint(ls.start.coor);98 Point p2 = mv.getScreenPoint(ls.end.coor);97 Point p1 = nc.getScreenPoint(ls.start.coor); 98 Point p2 = nc.getScreenPoint(ls.end.coor); 99 99 g.drawLine(p1.x, p1.y, p2.x, p2.y); 100 100 } -
src/org/openstreetmap/josm/data/projection/Projection.java
r40 r41 19 19 abstract public class Projection implements Cloneable { 20 20 21 public static double MAX_LAT = 85; // yep - JOSM cannot cartograph the poles.22 public static double MAX_LON = 1 79.99999;21 public static double MAX_LAT = 85; 22 public static double MAX_LON = 180; 23 23 24 24 /** -
src/org/openstreetmap/josm/gui/BookmarkList.java
r21 r41 44 44 setModel(new DefaultListModel()); 45 45 load(); 46 setVisibleRowCount( 10);46 setVisibleRowCount(7); 47 47 setCellRenderer(new DefaultListCellRenderer(){ 48 48 @Override -
src/org/openstreetmap/josm/gui/ImageProvider.java
r22 r41 30 30 * The icon cache 31 31 */ 32 private static Map<URL, I con> cache = new HashMap<URL,Icon>();32 private static Map<URL, ImageIcon> cache = new HashMap<URL, ImageIcon>(); 33 33 34 34 /** … … 39 39 * @return The requested ImageIcon. 40 40 */ 41 public static I con get(String subdir, String name) {41 public static ImageIcon get(String subdir, String name) { 42 42 if (subdir != "") 43 43 subdir += "/"; 44 44 URL path = Main.class.getResource("/images/"+subdir+name+".png"); 45 I con icon = cache.get(path);45 ImageIcon icon = cache.get(path); 46 46 if (icon == null) { 47 icon = new ImageIcon( Main.class.getResource("/images/"+subdir+name+".png"));47 icon = new ImageIcon(path); 48 48 cache.put(path, icon); 49 49 } … … 54 54 * Shortcut for get("", name); 55 55 */ 56 public static I con get(String name) {56 public static ImageIcon get(String name) { 57 57 return get("", name); 58 58 } -
src/org/openstreetmap/josm/gui/MapMover.java
r18 r41 26 26 * The map to move around. 27 27 */ 28 private final MapView mv;28 private final NavigatableComponent nc; 29 29 /** 30 30 * The old cursor when we changed it to movement cursor. … … 36 36 * @param mapView The map that should be moved. 37 37 */ 38 public MapMover( MapViewmapView) {39 this. mv= mapView;40 mv.addMouseListener(this);41 mv.addMouseMotionListener(this);42 mv.addMouseWheelListener(this);38 public MapMover(NavigatableComponent mapView) { 39 this.nc = mapView; 40 nc.addMouseListener(this); 41 nc.addMouseMotionListener(this); 42 nc.addMouseWheelListener(this); 43 43 } 44 44 … … 51 51 if (mousePosMove == null) 52 52 startMovement(e); 53 GeoPoint center = mv.getCenter();54 GeoPoint mouseCenter = mv.getPoint(e.getX(), e.getY(), false);53 GeoPoint center = nc.getCenter(); 54 GeoPoint mouseCenter = nc.getPoint(e.getX(), e.getY(), false); 55 55 GeoPoint p = new GeoPoint(); 56 56 p.x = mousePosMove.x + center.x - mouseCenter.x; 57 57 p.y = mousePosMove.y + center.y - mouseCenter.y; 58 mv.zoomTo(p, mv.getScale());58 nc.zoomTo(p, nc.getScale()); 59 59 } else 60 60 endMovement(); … … 86 86 */ 87 87 private void startMovement(MouseEvent e) { 88 mousePosMove = mv.getPoint(e.getX(), e.getY(), false);89 oldCursor = mv.getCursor();90 mv.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));88 mousePosMove = nc.getPoint(e.getX(), e.getY(), false); 89 oldCursor = nc.getCursor(); 90 nc.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 91 91 } 92 92 … … 96 96 private void endMovement() { 97 97 if (oldCursor != null) 98 mv.setCursor(oldCursor);98 nc.setCursor(oldCursor); 99 99 else 100 mv.setCursor(Cursor.getDefaultCursor());100 nc.setCursor(Cursor.getDefaultCursor()); 101 101 mousePosMove = null; 102 102 oldCursor = null; … … 109 109 public void mouseWheelMoved(MouseWheelEvent e) { 110 110 double zoom = Math.max(0.1, 1 + e.getWheelRotation()/5.0); 111 mv.zoomTo(mv.getCenter(), mv.getScale()*zoom);111 nc.zoomTo(nc.getCenter(), nc.getScale()*zoom); 112 112 } 113 113 -
src/org/openstreetmap/josm/gui/MapView.java
r40 r41 14 14 import java.util.LinkedList; 15 15 16 import javax.swing.JComponent;17 16 import javax.swing.event.ChangeEvent; 18 17 import javax.swing.event.ChangeListener; … … 43 42 * @author imi 44 43 */ 45 public class MapView extends JComponent implements ChangeListener, PropertyChangeListener{44 public class MapView extends NavigatableComponent implements ChangeListener, PropertyChangeListener { 46 45 47 46 /** … … 59 58 */ 60 59 boolean autoScale = true; 61 62 /**63 * The scale factor in meter per pixel.64 */65 private double scale;66 /**67 * Center n/e coordinate of the desired screen center.68 */69 private GeoPoint center;70 60 71 61 /** … … 169 159 else 170 160 layers.add(pos, layer); 171 }172 173 /**174 * Get geographic coordinates from a specific pixel coordination175 * on the screen.176 *177 * If you don't need it, provide false at third parameter to speed178 * up the calculation.179 *180 * @param x X-Pixelposition to get coordinate from181 * @param y Y-Pixelposition to get coordinate from182 * @param latlon If set, the return value will also have the183 * latitude/longitude filled.184 *185 * @return The geographic coordinate, filled with x/y (northing/easting)186 * settings and, if requested with latitude/longitude.187 */188 public GeoPoint getPoint(int x, int y, boolean latlon) {189 GeoPoint p = new GeoPoint();190 p.x = (x - getWidth()/2.0)*scale + center.x;191 p.y = (getHeight()/2.0 - y)*scale + center.y;192 if (latlon)193 Main.pref.getProjection().xy2latlon(p);194 return p;195 }196 197 /**198 * Return the point on the screen where this GeoPoint would be.199 * @param point The point, where this geopoint would be drawn.200 * @return The point on screen where "point" would be drawn, relative201 * to the own top/left.202 */203 public Point getScreenPoint(GeoPoint point) {204 GeoPoint p;205 if (!Double.isNaN(point.x) && !Double.isNaN(point.y))206 p = point;207 else {208 if (Double.isNaN(point.lat) || Double.isNaN(point.lon))209 throw new IllegalArgumentException("point: Either lat/lon or x/y must be set.");210 p = point.clone();211 Main.pref.getProjection().latlon2xy(p);212 }213 int x = ((int)Math.round((p.x-center.x) / scale + getWidth()/2));214 int y = ((int)Math.round((center.y-p.y) / scale + getHeight()/2));215 return new Point(x,y);216 161 } 217 162 … … 358 303 359 304 /** 360 * Zoom to the given coordinate.361 * @param centerX The center x-value (easting) to zoom to.362 * @param centerY The center y-value (northing) to zoom to.363 * @param scale The scale to use.364 */365 public void zoomTo(GeoPoint newCenter, double scale) {366 boolean oldAutoScale = autoScale;367 GeoPoint oldCenter = center;368 double oldScale = this.scale;369 370 autoScale = false;371 center = newCenter.clone();372 Main.pref.getProjection().xy2latlon(center);373 this.scale = scale;374 recalculateCenterScale();375 376 firePropertyChange("center", oldCenter, center);377 if (oldAutoScale != autoScale)378 firePropertyChange("autoScale", oldAutoScale, autoScale);379 if (oldScale != scale)380 firePropertyChange("scale", oldScale, scale);381 }382 383 /**384 305 * Draw the component. 385 306 */ … … 394 315 l.paint(g, this); 395 316 } 396 317 397 318 // draw world borders 398 g.setColor(Color. DARK_GRAY);319 g.setColor(Color.WHITE); 399 320 Bounds b = new Bounds(); 400 321 Point min = getScreenPoint(b.min); … … 404 325 int x2 = Math.max(min.x, max.x); 405 326 int y2 = Math.max(min.y, max.y); 406 g.drawRect(x1, y1, x2-x1+1, y2-y1+1); 407 } 408 409 /** 410 * Notify from the projection, that something has changed. 411 * @param e 412 */ 413 public void stateChanged(ChangeEvent e) { 414 // reset all datasets. 415 Projection p = Main.pref.getProjection(); 416 for (Node n : Main.main.ds.nodes) 417 p.latlon2xy(n.coor); 418 recalculateCenterScale(); 419 } 420 421 /** 422 * Return the current scale value. 423 * @return The scale value currently used in display 424 */ 425 public double getScale() { 426 return scale; 327 if (x1 > 0 || y1 > 0 || x2 < getWidth() || y2 < getHeight()) 328 g.drawRect(x1, y1, x2-x1+1, y2-y1+1); 427 329 } 428 330 … … 444 346 } 445 347 } 446 /**447 * @return Returns the center point. A copy is returned, so users cannot448 * change the center by accessing the return value. Use zoomTo instead.449 */450 public GeoPoint getCenter() {451 return center.clone();452 }453 454 455 /**456 * Change to the new projection. Recalculate the dataset and zoom, if autoZoom457 * is active.458 * @param oldProjection The old projection. Unregister from this.459 * @param newProjection The new projection. Register as state change listener.460 */461 public void propertyChange(PropertyChangeEvent evt) {462 if (!evt.getPropertyName().equals("projection"))463 return;464 if (evt.getOldValue() != null)465 ((Projection)evt.getOldValue()).removeChangeListener(this);466 if (evt.getNewValue() != null) {467 Projection p = (Projection)evt.getNewValue();468 p.addChangeListener(this);469 470 stateChanged(new ChangeEvent(this));471 }472 }473 474 348 /** 475 349 * Set the new dimension to the projection class. Also adjust the components … … 581 455 return editLayer; 582 456 } 457 458 /** 459 * In addition to the base class funcitonality, this keep trak of the autoscale 460 * feature. 461 */ 462 @Override 463 public void zoomTo(GeoPoint newCenter, double scale) { 464 boolean oldAutoScale = autoScale; 465 GeoPoint oldCenter = center; 466 double oldScale = this.scale; 467 autoScale = false; 468 469 super.zoomTo(newCenter, scale); 470 471 recalculateCenterScale(); 472 473 firePropertyChange("center", oldCenter, center); 474 if (oldAutoScale != autoScale) 475 firePropertyChange("autoScale", oldAutoScale, autoScale); 476 if (oldScale != scale) 477 firePropertyChange("scale", oldScale, scale); 478 } 479 480 /** 481 * Notify from the projection, that something has changed. 482 */ 483 public void stateChanged(ChangeEvent e) { 484 // reset all datasets. 485 Projection p = Main.pref.getProjection(); 486 for (Node n : Main.main.ds.nodes) 487 p.latlon2xy(n.coor); 488 recalculateCenterScale(); 489 } 490 491 /** 492 * Change to the new projection. Recalculate the dataset and zoom, if autoZoom 493 * is active. 494 * @param oldProjection The old projection. Unregister from this. 495 * @param newProjection The new projection. Register as state change listener. 496 */ 497 public void propertyChange(PropertyChangeEvent evt) { 498 if (!evt.getPropertyName().equals("projection")) 499 return; 500 if (evt.getOldValue() != null) 501 ((Projection)evt.getOldValue()).removeChangeListener(this); 502 if (evt.getNewValue() != null) { 503 Projection p = (Projection)evt.getNewValue(); 504 p.addChangeListener(this); 505 506 stateChanged(new ChangeEvent(this)); 507 } 508 } 583 509 } -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r40 r41 2 2 3 3 import java.awt.Graphics; 4 import java.beans.PropertyChangeEvent; 5 import java.beans.PropertyChangeListener; 4 6 import java.util.Collection; 5 7 import java.util.Iterator; … … 54 56 super(name); 55 57 this.data = data; 58 Main.pref.addPropertyChangeListener(new PropertyChangeListener() { 59 public void propertyChange(PropertyChangeEvent evt) { 60 if (evt.getPropertyName().equals("projection")) 61 for (Node n : OsmDataLayer.this.data.nodes) 62 ((Projection)evt.getNewValue()).latlon2xy(n.coor); 63 } 64 }); 56 65 } 57 66 -
src/org/openstreetmap/josm/io/OsmServerReader.java
r37 r41 78 78 */ 79 79 public DataSet parseOsm() throws JDOMException, IOException { 80 long start = System.currentTimeMillis();81 80 Reader r = getReader(Main.pref.osmDataServer+"/map?bbox="+lon1+","+lat1+","+lon2+","+lat2); 82 System.out.println(System.currentTimeMillis() - start);83 81 if (r == null) 84 82 return null; -
src/org/openstreetmap/josm/io/OsmServerWriter.java
r35 r41 123 123 Document doc = new Document(root); 124 124 xmlOut.output(doc, out); 125 xmlOut.output(doc, System.out);126 125 out.close(); 127 126 }
Note:
See TracChangeset
for help on using the changeset viewer.