Statistics
| Revision:

root / trunk / libraries / libCq_CMS_praster / src / org / cresques / ui / cmd / CmdZoom.java @ 8026

History | View | Annotate | Download (2.86 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.ui.cmd;
25

    
26
import org.cresques.px.Extent;
27

    
28
import org.cresques.ui.CQCursor;
29
import org.cresques.ui.CQMapCanvas;
30

    
31
import java.awt.event.MouseEvent;
32
import java.awt.geom.Point2D;
33

    
34

    
35
/**
36
 * Comando zoom.
37
 * A?ade al canvas la capacidad de aumentar y disminuir la vista.
38
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
39
 */
40
public class CmdZoom extends Cmd {
41
    public double aumenta = 2.0;
42
    public double reduce = .5;
43
    private Point2D ptIni = null;
44

    
45
    /**
46
     * Construye un nuevo CmdZoom para el Canvas
47
     * @param canvas
48
     */
49
    public CmdZoom(CQMapCanvas canvas) {
50
        super(canvas);
51
        eventsWanted = (LEFT | RIGHT | PRESS | RELEASE | DRAG);
52
        cursor = CQCursor.getCursor(CQCursor.ZOOMIN_CURSOR);
53
    }
54

    
55
    /**
56
     * Recibe los eventos del rat?n.
57
     */
58
    public void cmd(Point2D pt, int bt, int mouseEvent) {
59
        //System.out.println("Zoom: Evento = "+ mouseEvent);
60
        if (mouseEvent == PRESS) {
61
            ptIni = pt;
62
        } else if (mouseEvent == RELEASE) {
63
            if (pt.getX() != ptIni.getX()) {
64
                zoomBox(new Extent(ptIni, pt));
65
            } else if (bt == MouseEvent.BUTTON1) {
66
                zoomMas(pt);
67
            } else if (bt == MouseEvent.BUTTON3) {
68
                zoomMenos(pt);
69
            }
70
        }
71
    }
72

    
73
    /**
74
     * Realiza un zoom de aumento, centrado en el Point2D;
75
     * @param pt
76
     */
77
    public void zoomMas(Point2D pt) {
78
        canvas.getVPData().zoom(aumenta, pt);
79
        canvas.viewPortChanged();
80
        canvas.repaint();
81
    }
82

    
83
    /**
84
     * Realiza un zoom de disminuci?n, centrado en el Point2D;
85
     * @param pt
86
     */
87
    public void zoomMenos(Point2D pt) {
88
        canvas.getVPData().zoom(reduce, pt);
89
        canvas.viewPortChanged();
90
        canvas.repaint();
91
    }
92

    
93
    /**
94
     * Realiza un zoom que abarque el Extent;
95
     * @param box
96
     */
97
    public void zoomBox(Extent box) {
98
        canvas.getVPData().zoom(box);
99
        canvas.viewPortChanged();
100
        canvas.repaint();
101
    }
102
}