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

Last change on this file since 9450 was 8840, checked in by Don-vip, 9 years ago

sonar - squid:S3052 - Fields should not be initialized to default values

  • Property svn:eol-style set to native
File size: 2.1 KB
RevLine 
[6380]1// License: GPL. For details, see LICENSE file.
[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;
[8840]19 private boolean preventChange;
[155]20
[8836]21 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
[6084]31 @Override
[1169]32 public void propertyChange(PropertyChangeEvent evt) {
[1337]33 if (getModel().getValueIsAdjusting()) return;
[1677]34
[1823]35 ProjectionBounds world = this.mv.getMaxProjectionBounds();
[1722]36 ProjectionBounds current = this.mv.getProjectionBounds();
37
[4065]38 double cur_e = current.maxEast-current.minEast;
39 double cur_n = current.maxNorth-current.minNorth;
40 double e = world.maxEast-world.minEast;
41 double n = world.maxNorth-world.minNorth;
[1722]42 int zoom = 0;
43
[8510]44 while (zoom <= 150) {
[1722]45 e /= 1.1;
46 n /= 1.1;
[8510]47 if (e < cur_e && n < cur_n) {
[1337]48 break;
[2114]49 }
[1722]50 ++zoom;
[1337]51 }
[8510]52 preventChange = true;
[1722]53 setValue(zoom);
[8510]54 preventChange = false;
[1169]55 }
56
[6084]57 @Override
[1169]58 public void stateChanged(ChangeEvent e) {
[1337]59 if (preventChange) return;
[1722]60
[1823]61 ProjectionBounds world = this.mv.getMaxProjectionBounds();
[1722]62 double fact = Math.pow(1.1, getValue());
[4065]63 double es = world.maxEast-world.minEast;
64 double n = world.maxNorth-world.minNorth;
[1722]65
66 this.mv.zoomTo(new ProjectionBounds(this.mv.getCenter(), es/fact, n/fact));
[1169]67 }
68
[6084]69 @Override
[1169]70 public String helpTopic() {
[3754]71 return ht("/MapView/Slider");
[1169]72 }
[2512]73}
Note: See TracBrowser for help on using the repository browser.