Changeset 1337 in josm for trunk/src


Ignore:
Timestamp:
2009-01-25T14:01:09+01:00 (16 years ago)
Author:
stoecker
Message:

fix #473. Patch by xeen

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MapSlider.java

    r1169 r1337  
    22package org.openstreetmap.josm.gui;
    33
    4 import java.awt.event.MouseAdapter;
    5 import java.awt.event.MouseEvent;
    64import java.beans.PropertyChangeEvent;
    75import java.beans.PropertyChangeListener;
     
    1715
    1816    private final MapView mv;
    19     boolean clicked = false;
     17    boolean preventChange = false;
    2018
    2119    public MapSlider(MapView mv) {
    22         super(0, 20);
     20        super(35, 150);
    2321        setOpaque(false);
    2422        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         });
    3323        mv.addPropertyChangeListener("scale", this);
    3424        addChangeListener(this);
     
    3626
    3727    public void propertyChange(PropertyChangeEvent evt) {
    38         if (!getModel().getValueIsAdjusting())
    39             setValue(this.mv.zoom());
     28        if (getModel().getValueIsAdjusting()) return;
     29       
     30        double sizex = this.mv.scale * this.mv.getWidth();
     31        double sizey = this.mv.scale * this.mv.getHeight();
     32        for (int zoom = 0; zoom <= 150; zoom++, sizex *= 1.1, sizey *= 1.1) {
     33            if (sizex > this.mv.world.east() || sizey > this.mv.world.north()) {
     34                preventChange=true;
     35                setValue(zoom);
     36                preventChange=false;
     37                break;
     38            }
     39        }
    4040    }
    4141
    4242    public void stateChanged(ChangeEvent e) {
    43         if (!clicked)
    44             return;
     43        if (preventChange) return;
    4544        EastNorth pos = MapView.world;
    46         for (int zoom = 0; zoom < getValue(); ++zoom)
    47             pos = new EastNorth(pos.east()/2, pos.north()/2);
     45        for (int zoom = 0; zoom < getValue(); zoom++)
     46            pos = new EastNorth(pos.east()/1.1, pos.north()/1.1);
    4847        if (this.mv.getWidth() < this.mv.getHeight())
    49             this.mv.zoomTo(this.mv.center, pos.east()*2/(this.mv.getWidth()-20));
     48            this.mv.zoomTo(this.mv.center, pos.east()/(this.mv.getWidth()-20));
    5049        else
    51             this.mv.zoomTo(this.mv.center, pos.north()*2/(this.mv.getHeight()-20));
     50            this.mv.zoomTo(this.mv.center, pos.north()/(this.mv.getHeight()-20));
    5251    }
    5352
Note: See TracChangeset for help on using the changeset viewer.