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

Last change on this file since 3788 was 3754, checked in by stoecker, 13 years ago

some cleanups in help page marking

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