source: josm/trunk/src/org/openstreetmap/josm/gui/MapSlider.java@ 8285

Last change on this file since 8285 was 8285, checked in by Don-vip, 9 years ago

fix sonar squid:S2039 - Member variable visibility should be specified

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5
6import java.beans.PropertyChangeEvent;
7import java.beans.PropertyChangeListener;
8
9import javax.swing.JSlider;
10import javax.swing.event.ChangeEvent;
11import javax.swing.event.ChangeListener;
12
13import org.openstreetmap.josm.data.ProjectionBounds;
14import org.openstreetmap.josm.gui.help.Helpful;
15
16class MapSlider extends JSlider implements PropertyChangeListener, ChangeListener, Helpful {
17
18 private final MapView mv;
19 private boolean preventChange = false;
20
21 public MapSlider(MapView mv) {
22 super(35, 150);
23 setOpaque(false);
24 this.mv = mv;
25 mv.addPropertyChangeListener("scale", this);
26 addChangeListener(this);
27 // Call this manually once so it gets setup correctly
28 propertyChange(null);
29 }
30
31 @Override
32 public void propertyChange(PropertyChangeEvent evt) {
33 if (getModel().getValueIsAdjusting()) return;
34
35 ProjectionBounds world = this.mv.getMaxProjectionBounds();
36 ProjectionBounds current = this.mv.getProjectionBounds();
37
38 double cur_e = current.maxEast-current.minEast;
39 double cur_n = current.maxNorth-current.minNorth;
40 double e = world.maxEast-world.minEast;
41 double n = world.maxNorth-world.minNorth;
42 int zoom = 0;
43
44 while(zoom <= 150) {
45 e /= 1.1;
46 n /= 1.1;
47 if(e < cur_e && n < cur_n) {
48 break;
49 }
50 ++zoom;
51 }
52 preventChange=true;
53 setValue(zoom);
54 preventChange=false;
55 }
56
57 @Override
58 public void stateChanged(ChangeEvent e) {
59 if (preventChange) return;
60
61 ProjectionBounds world = this.mv.getMaxProjectionBounds();
62 double fact = Math.pow(1.1, getValue());
63 double es = world.maxEast-world.minEast;
64 double n = world.maxNorth-world.minNorth;
65
66 this.mv.zoomTo(new ProjectionBounds(this.mv.getCenter(), es/fact, n/fact));
67 }
68
69 @Override
70 public String helpTopic() {
71 return ht("/MapView/Slider");
72 }
73}
Note: See TracBrowser for help on using the repository browser.