Changeset 9713 in osm
- Timestamp:
- 2008-08-12T14:16:26+02:00 (16 years ago)
- Location:
- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/DefaultMapController.java
r9584 r9713 17 17 * 18 18 */ 19 public class DefaultMapController extends JMapController implements 20 Mouse Listener, MouseMotionListener, MouseWheelListener {19 public class DefaultMapController extends JMapController implements MouseListener, 20 MouseMotionListener, MouseWheelListener { 21 21 22 private static final int MOUSE_BUTTONS_MASK = MouseEvent.BUTTON3_DOWN_MASK 23 | MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON2_DOWN_MASK; 22 private static final int MOUSE_BUTTONS_MASK = 23 MouseEvent.BUTTON3_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK 24 | MouseEvent.BUTTON2_DOWN_MASK; 24 25 25 26 public DefaultMapController(JMapViewer map) { … … 34 35 35 36 private int movementMouseButton = MouseEvent.BUTTON3; 37 private int movementMouseButtonMask = MouseEvent.BUTTON3_DOWN_MASK; 36 38 37 39 private boolean wheelZoomEnabled = true; … … 41 43 if (!movementEnabled || !isMoving) 42 44 return; 43 // Is only right mouse button presed?44 if ((e.getModifiersEx() & MOUSE_BUTTONS_MASK) == MouseEvent.BUTTON3_DOWN_MASK) {45 45 // Is only the selected mouse button pressed? 46 if ((e.getModifiersEx() & MOUSE_BUTTONS_MASK) == movementMouseButtonMask) { 47 Point p = e.getPoint(); 46 48 if (lastDragPoint != null) { 47 Point p = e.getPoint();48 49 int diffx = lastDragPoint.x - p.x; 49 50 int diffy = lastDragPoint.y - p.y; 50 51 map.moveMap(diffx, diffy); 51 52 } 52 lastDragPoint = e.getPoint();53 lastDragPoint = p; 53 54 } 54 55 } 55 56 56 57 public void mouseClicked(MouseEvent e) { 57 if (doubleClickZoomEnabled && e.getClickCount() == 2 58 && e.getButton() == MouseEvent.BUTTON1) 58 if (doubleClickZoomEnabled && e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) 59 59 map.zoomIn(e.getPoint()); 60 60 } … … 109 109 public void setMovementMouseButton(int movementMouseButton) { 110 110 this.movementMouseButton = movementMouseButton; 111 switch (movementMouseButton) { 112 case MouseEvent.BUTTON1: 113 movementMouseButtonMask = MouseEvent.BUTTON1_DOWN_MASK; 114 break; 115 case MouseEvent.BUTTON2: 116 movementMouseButtonMask = MouseEvent.BUTTON2_DOWN_MASK; 117 break; 118 case MouseEvent.BUTTON3: 119 movementMouseButtonMask = MouseEvent.BUTTON3_DOWN_MASK; 120 break; 121 default: 122 throw new RuntimeException("Unsupported button"); 123 } 111 124 } 112 125 -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Demo.java
r9618 r9713 29 29 final JMapViewer map = new JMapViewer(); 30 30 // final JMapViewer map = new JMapViewer(new MemoryTileCache(),4); 31 // map.setTileLoader(new 32 // Osm FileCacheTileLoader(map,OsmTileLoader.MAP_MAPNIK));33 new DefaultMapController(map);31 // map.setTileLoader(new OsmFileCacheTileLoader(map, 32 // OsmTileLoader.MAP_MAPNIK)); 33 // new DefaultMapController(map); 34 34 setLayout(new BorderLayout()); 35 35 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); … … 37 37 JPanel panel = new JPanel(); 38 38 add(panel, BorderLayout.NORTH); 39 JLabel label = new JLabel( 40 "Use right mouse button to move,\n left double click or mouse wheel to zoom."); 39 JLabel label = 40 new JLabel("Use right mouse button to move,\n " 41 + "left double click or mouse wheel to zoom."); 41 42 panel.add(label); 42 43 JButton button = new JButton("setDisplayToFitMapMarkers"); -
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java
r9619 r9713 43 43 * Vectors for clock-wise tile painting 44 44 */ 45 protected static final Point[] move = { new Point(1, 0), new Point(0, 1),46 new Point(-1, 0), new Point(0, -1) };45 protected static final Point[] move = 46 { new Point(1, 0), new Point(0, 1), new Point(-1, 0), new Point(0, -1) }; 47 47 48 48 public static final int MAX_ZOOM = 18; … … 102 102 setPreferredSize(new Dimension(400, 400)); 103 103 try { 104 loadingImage = ImageIO.read(JMapViewer.class105 .getResourceAsStream("images/hourglass.png"));104 loadingImage = 105 ImageIO.read(JMapViewer.class.getResourceAsStream("images/hourglass.png")); 106 106 } catch (Exception e1) { 107 107 loadingImage = null; … … 123 123 int size = 18; 124 124 try { 125 ImageIcon icon = new ImageIcon(getClass().getResource( 126 "images/plus.png")); 125 ImageIcon icon = new ImageIcon(getClass().getResource("images/plus.png")); 127 126 zoomInButton = new JButton(icon); 128 127 } catch (Exception e) { … … 140 139 add(zoomInButton); 141 140 try { 142 ImageIcon icon = new ImageIcon(getClass().getResource( 143 "images/minus.png")); 141 ImageIcon icon = new ImageIcon(getClass().getResource("images/minus.png")); 144 142 zoomOutButton = new JButton(icon); 145 143 } catch (Exception e) { … … 170 168 */ 171 169 public void setDisplayPositionByLatLon(double lat, double lon, int zoom) { 172 setDisplayPositionByLatLon(new Point(getWidth() / 2, getHeight() / 2), 173 lat, lon, zoom); 170 setDisplayPositionByLatLon(new Point(getWidth() / 2, getHeight() / 2), lat, lon, zoom); 174 171 } 175 172 … … 189 186 * {@link #MIN_ZOOM} <= zoom level <= {@link #MAX_ZOOM} 190 187 */ 191 public void setDisplayPositionByLatLon(Point mapPoint, double lat, 192 double lon, int zoom) { 188 public void setDisplayPositionByLatLon(Point mapPoint, double lat, double lon, int zoom) { 193 189 int x = OsmMercator.LonToX(lon, zoom); 194 190 int y = OsmMercator.LatToY(lat, zoom); … … 197 193 198 194 public void setDisplayPosition(int x, int y, int zoom) { 199 setDisplayPosition(new Point(getWidth() / 2, getHeight() / 2), x, y, 200 zoom); 195 setDisplayPosition(new Point(getWidth() / 2, getHeight() / 2), x, y, zoom); 201 196 } 202 197 … … 210 205 p.y = y - mapPoint.y + getHeight() / 2; 211 206 center = p; 212 this.zoom = zoom; 213 if (zoomSlider.getValue() != zoom) 214 zoomSlider.setValue(zoom); 215 repaint(); 207 setIgnoreRepaint(true); 208 try { 209 int oldZoom = this.zoom; 210 this.zoom = zoom; 211 if (oldZoom != zoom) 212 zoomChanged(oldZoom); 213 if (zoomSlider.getValue() != zoom) 214 zoomSlider.setValue(zoom); 215 } finally { 216 setIgnoreRepaint(false); 217 repaint(); 218 } 216 219 } 217 220 … … 240 243 // System.out.println(y_min + " < y < " + y_max); 241 244 // System.out.println("tiles: " + width + " " + height); 242 int zoom = MAX_ZOOM;245 int newZoom = MAX_ZOOM; 243 246 int x = x_max - x_min; 244 247 int y = y_max - y_min; 245 248 while (x > width || y > height) { 246 249 // System.out.println("zoom: " + zoom + " -> " + x + " " + y); 247 zoom--;250 newZoom--; 248 251 x >>= 1; 249 252 y >>= 1; … … 251 254 x = x_min + (x_max - x_min) / 2; 252 255 y = y_min + (y_max - y_min) / 2; 253 int z = 1 << (MAX_ZOOM - zoom);256 int z = 1 << (MAX_ZOOM - newZoom); 254 257 x /= z; 255 258 y /= z; 256 setDisplayPosition(x, y, zoom);259 setDisplayPosition(x, y, newZoom); 257 260 } 258 261 … … 334 337 x++; 335 338 for (int z = 0; z < x; z++) { 336 if (x_min <= posx && posx <= x_max && y_min <= posy 337 && posy <= y_max) { // tile 339 if (x_min <= posx && posx <= x_max && y_min <= posy && posy <= y_max) { // tile 338 340 // is 339 341 // visible … … 419 421 return; 420 422 Point2D.Double zoomPos = getPosition(mapPoint); 421 // addMapMarker(new MapMarkerDot(Color.RED, zoomPos.x, zoomPos.y));422 423 jobDispatcher.cancelOutstandingJobs(); // Clearing outstanding load 423 424 // requests … … 450 451 } 451 452 if (!tile.isLoaded()) { 452 jobDispatcher.addJob(tileLoader.createTileLoaderJob(tilex, tiley, 453 zoom)); 453 jobDispatcher.addJob(tileLoader.createTileLoaderJob(tilex, tiley, zoom)); 454 454 } 455 455 return tile; 456 } 457 458 /** 459 * Every time the zoom level changes this method is called. Override it in 460 * derived implementations for adapting zoom dependent values. The new zoom 461 * level can be obtained via {@link #getZoom()}. 462 * 463 * @param oldZoom 464 * the previous zoom level 465 */ 466 protected void zoomChanged(int oldZoom) { 456 467 } 457 468
Note:
See TracChangeset
for help on using the changeset viewer.