Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / ui / cmd / CmdZoom.java @ 2312

History | View | Annotate | Download (2.6 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 java.awt.geom.Point2D;
27

    
28
import java.awt.event.MouseEvent;
29

    
30
import org.cresques.px.Extent;
31
import org.cresques.ui.CQCursor;
32
import org.cresques.ui.CQMapCanvas;
33

    
34
/**
35
 * Comando zoom.
36
 * A?ade al canvas la capacidad de aumentar y disminuir la vista.
37
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
38
 */
39
public class CmdZoom extends Cmd {
40
        public double aumenta = 2.0;
41
        public double reduce = .5;
42
        private Point2D ptIni = null;
43
        
44
        /**
45
         * Construye un nuevo CmdZoom para el Canvas
46
         * @param canvas
47
         */
48
        public CmdZoom(CQMapCanvas canvas) {
49
                super(canvas);
50
                eventsWanted = (LEFT | RIGHT | PRESS | RELEASE | DRAG);
51
                cursor = CQCursor.getCursor(CQCursor.ZOOMIN_CURSOR);
52

    
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
}