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

Last change on this file since 2264 was 2252, checked in by Gubaer, 15 years ago

Refactored JOSM help system, slightly extended
Fixed problem with new internal representation of nodes as array (in Way)

  • Property svn:eol-style set to native
File size: 2.0 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.data.ProjectionBounds;
12import org.openstreetmap.josm.gui.help.Helpful;
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 // Call this manually once so it gets setup correctly
26 propertyChange(null);
27 }
28
29 public void propertyChange(PropertyChangeEvent evt) {
30 if (getModel().getValueIsAdjusting()) return;
31
32 ProjectionBounds world = this.mv.getMaxProjectionBounds();
33 ProjectionBounds current = this.mv.getProjectionBounds();
34
35 double cur_e = current.max.east()-current.min.east();
36 double cur_n = current.max.north()-current.min.north();
37 double e = world.max.east()-world.min.east();
38 double n = world.max.north()-world.min.north();
39 int zoom = 0;
40
41 while(zoom <= 150) {
42 e /= 1.1;
43 n /= 1.1;
44 if(e < cur_e && n < cur_n) {
45 break;
46 }
47 ++zoom;
48 }
49 preventChange=true;
50 setValue(zoom);
51 preventChange=false;
52 }
53
54 public void stateChanged(ChangeEvent e) {
55 if (preventChange) return;
56
57 ProjectionBounds world = this.mv.getMaxProjectionBounds();
58 double fact = Math.pow(1.1, getValue());
59 double es = world.max.east()-world.min.east();
60 double n = world.max.north()-world.min.north();
61
62 this.mv.zoomTo(new ProjectionBounds(this.mv.getCenter(), es/fact, n/fact));
63 }
64
65 public String helpTopic() {
66 return "MapView/Slider";
67 }
68}
Note: See TracBrowser for help on using the repository browser.