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

Last change on this file since 5132 was 4065, checked in by jttt, 13 years ago

Improved wms cache

  • files saved in original format (no need to recode to png)
  • possibility to tile with different pos/ppd that overlaps current tile
  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
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 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 public void propertyChange(PropertyChangeEvent evt) {
32 if (getModel().getValueIsAdjusting()) return;
33
34 ProjectionBounds world = this.mv.getMaxProjectionBounds();
35 ProjectionBounds current = this.mv.getProjectionBounds();
36
37 double cur_e = current.maxEast-current.minEast;
38 double cur_n = current.maxNorth-current.minNorth;
39 double e = world.maxEast-world.minEast;
40 double n = world.maxNorth-world.minNorth;
41 int zoom = 0;
42
43 while(zoom <= 150) {
44 e /= 1.1;
45 n /= 1.1;
46 if(e < cur_e && n < cur_n) {
47 break;
48 }
49 ++zoom;
50 }
51 preventChange=true;
52 setValue(zoom);
53 preventChange=false;
54 }
55
56 public void stateChanged(ChangeEvent e) {
57 if (preventChange) return;
58
59 ProjectionBounds world = this.mv.getMaxProjectionBounds();
60 double fact = Math.pow(1.1, getValue());
61 double es = world.maxEast-world.minEast;
62 double n = world.maxNorth-world.minNorth;
63
64 this.mv.zoomTo(new ProjectionBounds(this.mv.getCenter(), es/fact, n/fact));
65 }
66
67 public String helpTopic() {
68 return ht("/MapView/Slider");
69 }
70}
Note: See TracBrowser for help on using the repository browser.