Changeset 6019 in josm for trunk/src/org


Ignore:
Timestamp:
2013-06-24T16:15:44+02:00 (11 years ago)
Author:
akks
Message:

see #8652: do not shift the map on screen when toggling panels by Tab [idea by andygol]

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/DialogsToggleAction.java

    r5979 r6019  
    8282                Main.pref.put("sidetoolbar.visible", selected);
    8383            }
     84            Main.map.mapView.rememberLastPositionOnScreen();
    8485        }
    8586    }
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r6018 r6019  
    66import java.awt.AlphaComposite;
    77import java.awt.Color;
     8import java.awt.Dimension;
    89import java.awt.Graphics;
    910import java.awt.Graphics2D;
     
    4142import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
    4243import org.openstreetmap.josm.data.SelectionChangedListener;
     44import org.openstreetmap.josm.data.coor.EastNorth;
    4345import org.openstreetmap.josm.data.coor.LatLon;
    4446import org.openstreetmap.josm.data.osm.DataSet;
     
    281283    }
    282284
     285    // remebered geometry of the component
     286    private Dimension oldSize = null;
     287    private Point oldLoc = null;
     288   
     289    /*
     290     * Call this method to keep map position on screen during next repaint
     291     */
     292    public void rememberLastPositionOnScreen() {
     293        oldSize = getSize();
     294        oldLoc  = getLocationOnScreen();
     295    }
     296   
    283297    /**
    284298     * Adds a GPX layer. A GPX layer is added below the lowest data layer.
     
    526540            return; // no data loaded yet.
    527541
     542        // if the position was remembered, we need to adjust center once before repainting
     543        if (oldLoc != null && oldSize != null) {
     544            Point l1  = getLocationOnScreen();
     545            final EastNorth newCenter = new EastNorth(
     546                    center.getX()+ (l1.x-oldLoc.x - (oldSize.width-getWidth())/2.0)*getScale(),
     547                    center.getY()+ (oldLoc.y-l1.y + (oldSize.height-getHeight())/2.0)*getScale()
     548                    );
     549            oldLoc = null; oldSize = null;
     550            zoomTo(newCenter);
     551        }
     552       
    528553        List<Layer> visibleLayers = getVisibleLayersInZOrder();
    529554
Note: See TracChangeset for help on using the changeset viewer.