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

Last change on this file since 627 was 627, checked in by framm, 16 years ago
  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.gui;
3
4import java.awt.event.MouseAdapter;
5import java.awt.event.MouseEvent;
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.actions.HelpAction.Helpful;
14import org.openstreetmap.josm.data.coor.EastNorth;
15
16class MapSlider extends JSlider implements PropertyChangeListener, ChangeListener, Helpful {
17
18 private final MapView mv;
19 boolean clicked = false;
20
21 public MapSlider(MapView mv) {
22 super(0, 20);
23 setOpaque(false);
24 this.mv = mv;
25 addMouseListener(new MouseAdapter(){
26 @Override public void mousePressed(MouseEvent e) {
27 clicked = true;
28 }
29 @Override public void mouseReleased(MouseEvent e) {
30 clicked = false;
31 }
32 });
33 mv.addPropertyChangeListener("scale", this);
34 addChangeListener(this);
35 }
36
37 public void propertyChange(PropertyChangeEvent evt) {
38 if (!getModel().getValueIsAdjusting())
39 setValue(this.mv.zoom());
40 }
41
42 public void stateChanged(ChangeEvent e) {
43 if (!clicked)
44 return;
45 EastNorth pos = MapView.world;
46 for (int zoom = 0; zoom < getValue(); ++zoom)
47 pos = new EastNorth(pos.east()/2, pos.north()/2);
48 if (this.mv.getWidth() < this.mv.getHeight())
49 this.mv.zoomTo(this.mv.center, pos.east()*2/(this.mv.getWidth()-20));
50 else
51 this.mv.zoomTo(this.mv.center, pos.north()*2/(this.mv.getHeight()-20));
52 }
53
54 public String helpTopic() {
55 return "MapView/Slider";
56 }
57}
Note: See TracBrowser for help on using the repository browser.