diff -u -r -N -x .svn orig/src/org/openstreetmap/josm/gui/MapSlider.java trunk/src/org/openstreetmap/josm/gui/MapSlider.java
old
|
new
|
|
1 | 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others |
2 | 2 | package org.openstreetmap.josm.gui; |
3 | 3 | |
4 | | import java.awt.event.MouseAdapter; |
5 | | import java.awt.event.MouseEvent; |
6 | 4 | import java.beans.PropertyChangeEvent; |
7 | 5 | import java.beans.PropertyChangeListener; |
8 | 6 | |
… |
… |
|
16 | 14 | class MapSlider extends JSlider implements PropertyChangeListener, ChangeListener, Helpful { |
17 | 15 | |
18 | 16 | private final MapView mv; |
19 | | boolean clicked = false; |
| 17 | boolean preventChange = false; |
20 | 18 | |
21 | 19 | public MapSlider(MapView mv) { |
22 | | super(0, 20); |
| 20 | super(35, 150); |
23 | 21 | setOpaque(false); |
24 | 22 | this.mv = mv; |
25 | | addMouseListener(new MouseAdapter(){ |
26 | | @Override public void mousePressed(MouseEvent e) { |
27 | | clicked = true; |
28 | | } |
29 | | @Override public void mouseReleased(MouseEvent e) { |
30 | | clicked = false; |
31 | | } |
32 | | }); |
33 | 23 | mv.addPropertyChangeListener("scale", this); |
34 | 24 | addChangeListener(this); |
35 | 25 | } |
36 | 26 | |
37 | 27 | public void propertyChange(PropertyChangeEvent evt) { |
38 | | if (!getModel().getValueIsAdjusting()) |
39 | | setValue(this.mv.zoom()); |
| 28 | if (getModel().getValueIsAdjusting()) return; |
| 29 | |
| 30 | double sizex = this.mv.scale * this.mv.getWidth(); |
| 31 | double sizey = this.mv.scale * this.mv.getHeight(); |
| 32 | for (int zoom = 0; zoom <= 150; zoom++, sizex *= 1.1, sizey *= 1.1) { |
| 33 | if (sizex > this.mv.world.east() || sizey > this.mv.world.north()) { |
| 34 | preventChange=true; |
| 35 | setValue(zoom); |
| 36 | preventChange=false; |
| 37 | break; |
| 38 | } |
| 39 | } |
40 | 40 | } |
41 | 41 | |
42 | 42 | public void stateChanged(ChangeEvent e) { |
43 | | if (!clicked) |
44 | | return; |
| 43 | if (preventChange) return; |
45 | 44 | EastNorth pos = MapView.world; |
46 | | for (int zoom = 0; zoom < getValue(); ++zoom) |
47 | | pos = new EastNorth(pos.east()/2, pos.north()/2); |
| 45 | for (int zoom = 0; zoom < getValue(); zoom++) |
| 46 | pos = new EastNorth(pos.east()/1.1, pos.north()/1.1); |
48 | 47 | if (this.mv.getWidth() < this.mv.getHeight()) |
49 | | this.mv.zoomTo(this.mv.center, pos.east()*2/(this.mv.getWidth()-20)); |
| 48 | this.mv.zoomTo(this.mv.center, pos.east()/(this.mv.getWidth()-20)); |
50 | 49 | else |
51 | | this.mv.zoomTo(this.mv.center, pos.north()*2/(this.mv.getHeight()-20)); |
| 50 | this.mv.zoomTo(this.mv.center, pos.north()/(this.mv.getHeight()-20)); |
52 | 51 | } |
53 | 52 | |
54 | 53 | public String helpTopic() { |