Package gistoolkit.application.command

Source Code of gistoolkit.application.command.CenterOnPointCommand

/*
*    GISToolkit - Geographical Information System Toolkit
*    (C) 2002, Ithaqua Enterprises Inc.
*
*    This library is free software; you can redistribute it and/or
*    modify it under the terms of the GNU Lesser General Public
*    License as published by the Free Software Foundation;
*    version 2.1 of the License.
*
*    This library is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
*    Lesser General Public License for more details.
*
*    You should have received a copy of the GNU Lesser General Public
*    License along with this library; if not, write to the Free Software
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
*/

package gistoolkit.application.command;
import gistoolkit.application.*;
import gistoolkit.features.*;
import gistoolkit.display.GISDisplay;
import gistoolkit.display.DrawModel;
import gistoolkit.display.drawmodel.ClickPointModel;
/**
* Command to center the map where the user clicks.
*/
public class CenterOnPointCommand extends SimpleCommand{
    /** The identifying name for this command */
    public static String getName(){return "Center";}
   
    /**
     * CenterOnPointCommand constructor comment.
     */
    public CenterOnPointCommand(GISEditor inEditor) {
        super(getName(), getIcon("Center.gif"), inEditor);
        putValue(SHORT_DESCRIPTION, "Center the map.");
        putValue(LONG_DESCRIPTION, "Center the map on the click location.");
    }
   
    public void execute() {
        GISDisplay tempDisplay = getGISDisplay();
       
        if (tempDisplay != null) {
            tempDisplay.setDrawModel(new ClickPointModel(this));
        }
    }
   
    public void executeDraw(DrawModel inDrawModel) {
        if (inDrawModel instanceof ClickPointModel) {
            ClickPointModel tempClickPointModel = (ClickPointModel) inDrawModel;
            Point tempPoint = tempClickPointModel.getPoint();
            if (tempPoint != null){
                centerOnPoint(tempPoint);
            }
        }
    }
   
    private void centerOnPoint(gistoolkit.features.Point p) {
        // draw the map on the buffer
        Envelope tempMapEnvelope = getGISDisplay().getEnvelope();
        double xOffset = tempMapEnvelope.getWidth() / 2;
        double yOffset = tempMapEnvelope.getHeight() / 2;
        Envelope tempNewEnvelope = new Envelope(
            p.getX() - xOffset,
            p.getY() - yOffset,
            p.getX() + xOffset,
            p.getY() + yOffset);
       
        try {
            getGISDisplay().setEnvelope(tempNewEnvelope);
        }
        catch (Exception ex) {
        }
    }
}
TOP

Related Classes of gistoolkit.application.command.CenterOnPointCommand

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.