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