Statistics
| Revision:

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

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 org.cresques.px.gml.Feature;
27
import org.cresques.px.gml.LineString;
28

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

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

    
35
import java.util.Vector;
36

    
37

    
38
/**
39
 * Comando pline.
40
 * A?ade al canvas la capacidad de crear polilineas.
41
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
42
 */
43
public class CmdPLine extends Cmd {
44
    private Point2D ptIni = null;
45
    private Vector pts = new Vector();
46
    private Feature pLine = null;
47

    
48
    /**
49
     * Construye un nuevo CmdPLine para el Canvas.
50
     * @param canvas
51
     */
52
    public CmdPLine(CQMapCanvas canvas) {
53
        super(canvas);
54
        eventsWanted = LEFT | RIGHT | PRESS | RELEASE;
55
        cursor = CQCursor.getCursor(CQCursor.SELECT_CURSOR);
56
    }
57

    
58
    /**
59
     * Recibe los eventos del rat?n.
60
     */
61
    public void cmd(Point2D pt, int bt, int mouseEvent) {
62
        if (mouseEvent == Cmd.RELEASE) {
63
            if (bt == MouseEvent.BUTTON1) {
64
                pts.add(pt);
65
                pline();
66
            } else {
67
                pts = new Vector();
68
            }
69
        }
70
    }
71

    
72
    /**
73
     * A?ade el punto actual a la PLine. La crea si no existe.
74
     * @param ptIni Punto inicial.
75
     * @param ptFin Punto final.
76
     */
77
    private void pline() {
78
        if (pts.size() > 2) {
79
            pLine.getGeometry().add((Point2D) pts.lastElement());
80
        } else if (pts.size() == 2) {
81
            pLine = new Feature();
82
            pLine.setGeometry(new LineString());
83
            pLine.getGeometry().add((Point2D) pts.get(0));
84
            pLine.getGeometry().add((Point2D) pts.get(1));
85
            canvas.getApp().getCurrentLayer().add(pLine);
86
        }
87

    
88
        canvas.repaint();
89
    }
90
}