1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.gui;
|
---|
3 |
|
---|
4 | import java.beans.PropertyChangeEvent;
|
---|
5 | import java.beans.PropertyChangeListener;
|
---|
6 |
|
---|
7 | import javax.swing.JSlider;
|
---|
8 | import javax.swing.event.ChangeEvent;
|
---|
9 | import javax.swing.event.ChangeListener;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.actions.HelpAction.Helpful;
|
---|
12 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
13 |
|
---|
14 | class MapSlider extends JSlider implements PropertyChangeListener, ChangeListener, Helpful {
|
---|
15 |
|
---|
16 | private final MapView mv;
|
---|
17 | boolean preventChange = false;
|
---|
18 |
|
---|
19 | public MapSlider(MapView mv) {
|
---|
20 | super(35, 150);
|
---|
21 | setOpaque(false);
|
---|
22 | this.mv = mv;
|
---|
23 | mv.addPropertyChangeListener("scale", this);
|
---|
24 | addChangeListener(this);
|
---|
25 | }
|
---|
26 |
|
---|
27 | public void propertyChange(PropertyChangeEvent evt) {
|
---|
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 | }
|
---|
41 |
|
---|
42 | public void stateChanged(ChangeEvent e) {
|
---|
43 | if (preventChange) return;
|
---|
44 | EastNorth pos = MapView.world;
|
---|
45 | for (int zoom = 0; zoom < getValue(); zoom++)
|
---|
46 | pos = new EastNorth(pos.east()/1.1, pos.north()/1.1);
|
---|
47 | if (this.mv.getWidth() < this.mv.getHeight())
|
---|
48 | this.mv.zoomTo(this.mv.center, pos.east()/(this.mv.getWidth()-20));
|
---|
49 | else
|
---|
50 | this.mv.zoomTo(this.mv.center, pos.north()/(this.mv.getHeight()-20));
|
---|
51 | }
|
---|
52 |
|
---|
53 | public String helpTopic() {
|
---|
54 | return "MapView/Slider";
|
---|
55 | }
|
---|
56 | }
|
---|