Changeset 8553 in josm


Ignore:
Timestamp:
2015-07-01T21:18:14+02:00 (6 years ago)
Author:
bastiK
Message:

applied #11633 - MapView: Made paint() method shorter by moving draw prearation to a new method. (patch by michael2402)

File:
1 edited

Legend:

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

    r8552 r8553  
    579579    }
    580580
     581    /**
     582     * Checks if virtual nodes should be drawn. Default is <code>false</code>
     583     * @return The virtual nodes property.
     584     * @see Rendering#render(DataSet, boolean, Bounds)
     585     */
    581586    public boolean isVirtualNodesEnabled() {
    582587        return virtualNodesEnabled;
     
    693698    @Override
    694699    public void paint(Graphics g) {
    695         if (initialViewport != null) {
    696             zoomTo(initialViewport);
    697             initialViewport = null;
    698         }
    699         if (BugReportExceptionHandler.exceptionHandlingInProgress())
     700        if (!prepareToDraw()) {
    700701            return;
    701 
    702         if (center == null)
    703             return; // no data loaded yet.
    704 
    705         // if the position was remembered, we need to adjust center once before repainting
    706         if (oldLoc != null && oldSize != null) {
    707             Point l1  = getLocationOnScreen();
    708             final EastNorth newCenter = new EastNorth(
    709                     center.getX()+ (l1.x-oldLoc.x - (oldSize.width-getWidth())/2.0)*getScale(),
    710                     center.getY()+ (oldLoc.y-l1.y + (oldSize.height-getHeight())/2.0)*getScale()
    711                     );
    712             oldLoc = null; oldSize = null;
    713             zoomTo(newCenter);
    714702        }
    715703
     
    847835        g.drawImage(offscreenBuffer, 0, 0, null);
    848836        super.paint(g);
     837    }
     838
     839    /**
     840     * Sets up the viewport to prepare for drawing the view.
     841     * @return <code>true</code> if the view can be drawn, <code>false</code> otherwise.
     842     */
     843    public boolean prepareToDraw() {
     844        if (initialViewport != null) {
     845            zoomTo(initialViewport);
     846            initialViewport = null;
     847        }
     848        if (BugReportExceptionHandler.exceptionHandlingInProgress())
     849            return false;
     850
     851        if (getCenter() == null)
     852            return false; // no data loaded yet.
     853
     854        // if the position was remembered, we need to adjust center once before repainting
     855        if (oldLoc != null && oldSize != null) {
     856            Point l1  = getLocationOnScreen();
     857            final EastNorth newCenter = new EastNorth(
     858                    getCenter().getX()+ (l1.x-oldLoc.x - (oldSize.width-getWidth())/2.0)*getScale(),
     859                    getCenter().getY()+ (oldLoc.y-l1.y + (oldSize.height-getHeight())/2.0)*getScale()
     860                    );
     861            oldLoc = null; oldSize = null;
     862            zoomTo(newCenter);
     863        }
     864
     865        return true;
    849866    }
    850867
Note: See TracChangeset for help on using the changeset viewer.