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

Last change on this file since 1589 was 1415, checked in by stoecker, 15 years ago

applied patch #2185 by bruce89

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.gui;
3
4import java.beans.PropertyChangeEvent;
5import java.beans.PropertyChangeListener;
6
7import javax.swing.JSlider;
8import javax.swing.event.ChangeEvent;
9import javax.swing.event.ChangeListener;
10
11import org.openstreetmap.josm.actions.HelpAction.Helpful;
12import org.openstreetmap.josm.data.coor.EastNorth;
13
14class 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 > MapView.world.east() || sizey > MapView.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}
Note: See TracBrowser for help on using the repository browser.