Revision 92 trunk/libraries/libCq CMS for java.old/src/org/cresques/ui/cmd/CmdZoom.java
CmdZoom.java | ||
---|---|---|
1 | 1 |
package org.cresques.ui.cmd; |
2 | 2 |
|
3 |
import java.awt.Component; |
|
4 | 3 |
import java.awt.geom.Point2D; |
5 | 4 |
|
6 | 5 |
import java.awt.event.MouseEvent; |
7 | 6 |
|
7 |
import org.cresques.px.Extent; |
|
8 | 8 |
import org.cresques.ui.CQMapCanvas; |
9 | 9 |
|
10 |
/** |
|
11 |
* Comando zoom. |
|
12 |
* A?ade al canvas la capacidad de aumentar y disminuir la vista. |
|
13 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es> |
|
14 |
*/ |
|
10 | 15 |
public class CmdZoom extends Cmd { |
11 |
public static final int type=Cmd.ZOOM; |
|
12 | 16 |
public double aumenta = 2.0; |
13 | 17 |
public double reduce = .5; |
14 |
public CmdZoom(Component canvas) { |
|
18 |
private Point2D ptIni = null; |
|
19 |
|
|
20 |
/** |
|
21 |
* Construye un nuevo CmdZoom para el Canvas |
|
22 |
* @param canvas |
|
23 |
*/ |
|
24 |
public CmdZoom(CQMapCanvas canvas) { |
|
15 | 25 |
super(canvas); |
16 | 26 |
eventsWanted = (LEFT | RIGHT | PRESS | RELEASE | DRAG); |
17 | 27 |
} |
28 |
|
|
29 |
/** |
|
30 |
* Recibe los eventos del rat?n. |
|
31 |
*/ |
|
18 | 32 |
public void cmd(Point2D pt, int bt, int mouseEvent) { |
19 | 33 |
//System.out.println("Zoom: Evento = "+ mouseEvent); |
20 |
if (mouseEvent == RELEASE) { |
|
21 |
if (bt == MouseEvent.BUTTON1) |
|
22 |
((CQMapCanvas) canvas).zoom(aumenta, pt); |
|
23 |
else if (bt == MouseEvent.BUTTON3) |
|
24 |
((CQMapCanvas) canvas).zoom(reduce, pt); |
|
25 |
} |
|
34 |
if (mouseEvent == PRESS) { |
|
35 |
ptIni = pt; |
|
36 |
} else if (mouseEvent == RELEASE) { |
|
37 |
if (pt.getX() != ptIni.getX()) { |
|
38 |
zoomBox(new Extent(ptIni, pt)); |
|
39 |
} else if (bt == MouseEvent.BUTTON1) { |
|
40 |
zoomMas(pt); |
|
41 |
} else if (bt == MouseEvent.BUTTON3) { |
|
42 |
zoomMenos(pt); |
|
43 |
} |
|
44 |
} |
|
26 | 45 |
} |
46 |
|
|
47 |
/** |
|
48 |
* Realiza un zoom de aumento, centrado en el Point2D; |
|
49 |
* @param pt |
|
50 |
*/ |
|
51 |
public void zoomMas(Point2D pt) { |
|
52 |
canvas.getVPData().zoom(aumenta, pt); |
|
53 |
canvas.viewPortChanged(); |
|
54 |
canvas.repaint(); |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* Realiza un zoom de disminuci?n, centrado en el Point2D; |
|
59 |
* @param pt |
|
60 |
*/ |
|
61 |
public void zoomMenos(Point2D pt) { |
|
62 |
canvas.getVPData().zoom(reduce, pt); |
|
63 |
canvas.viewPortChanged(); |
|
64 |
canvas.repaint(); |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* Realiza un zoom que abarque el Extent; |
|
69 |
* @param box |
|
70 |
*/ |
|
71 |
public void zoomBox(Extent box) { |
|
72 |
canvas.getVPData().zoom(box); |
|
73 |
canvas.viewPortChanged(); |
|
74 |
canvas.repaint(); |
|
75 |
} |
|
27 | 76 |
} |
Also available in: Unified diff