Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / ui / cmd / CmdPLine.java @ 130

History | View | Annotate | Download (1.56 KB)

1
/*
2
 * 20-sep-2004
3
 */
4
package org.cresques.ui.cmd;
5

    
6
import java.awt.event.MouseEvent;
7
import java.awt.geom.Point2D;
8
import java.util.Vector;
9

    
10
import org.cresques.px.PxLine;
11
import org.cresques.px.dxf.DxfPolyline;
12
import org.cresques.px.gml.Feature;
13
import org.cresques.px.gml.LineString;
14
import org.cresques.ui.CQCursor;
15
import org.cresques.ui.CQMapCanvas;
16

    
17
/**
18
 * Comando pline.
19
 * A?ade al canvas la capacidad de crear polilineas.
20
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
21
 */
22
public class CmdPLine extends Cmd {
23
        private Point2D ptIni = null;
24
        private Vector pts = new Vector();
25
        private Feature pLine = null;
26
        
27
        /**
28
         * Construye un nuevo CmdPan para el Canvas.
29
         * @param canvas
30
         */
31
        public CmdPLine(CQMapCanvas canvas) {
32
                super(canvas);
33
                eventsWanted = LEFT | RIGHT | PRESS | RELEASE;
34
                cursor = CQCursor.getCursor(CQCursor.SELECT_CURSOR);
35
        }
36

    
37
        /**
38
         * Recibe los eventos del rat?n.
39
         */
40
        public void cmd(Point2D pt, int bt, int mouseEvent) {
41
                if (mouseEvent == Cmd.RELEASE) 
42
                        if (bt == MouseEvent.BUTTON1) {
43
                                pts.add(pt);
44
                                pline();
45
                        } else {
46
                                pts = new Vector();
47
                        }
48
        }
49
        
50
        /**
51
         * Realiza un desplazamiento de la vista.
52
         * @param ptIni Punto inicial.
53
         * @param ptFin Punto final.
54
         */
55
        private void pline() {
56
                if (pts.size() > 2) {
57
                        pLine.getGeometry().add((Point2D) pts.lastElement());
58
                } else if (pts.size() == 2) {
59
                        pLine = new Feature();
60
                        pLine.setGeometry(new LineString());
61
                        pLine.getGeometry().add((Point2D) pts.get(0));
62
                        pLine.getGeometry().add((Point2D) pts.get(1));
63
                        canvas.getApp().getCurrentLayer().add(pLine);
64
                } 
65
                canvas.repaint();
66
        }
67
}