Statistics
| Revision:

root / trunk / extensions / extGraph_predes / src / com / iver / cit / gvsig / graph / tools / FlagListener.java @ 8123

History | View | Annotate | Download (4.39 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.graph.tools;
42

    
43
import java.awt.Color;
44
import java.awt.Cursor;
45
import java.awt.geom.Point2D;
46

    
47
import javax.swing.JOptionPane;
48

    
49
import com.iver.cit.gvsig.fmap.MapControl;
50
import com.iver.cit.gvsig.fmap.core.FShape;
51
import com.iver.cit.gvsig.fmap.core.IGeometry;
52
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
53
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
54
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
55
import com.iver.cit.gvsig.fmap.layers.FLayer;
56
import com.iver.cit.gvsig.fmap.layers.GraphicLayer;
57
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator;
58
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
59
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
60
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
61
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener;
62
import com.iver.cit.gvsig.graph.ShortestPathExtension;
63
import com.iver.cit.gvsig.graph.core.GvFlag;
64
import com.iver.cit.gvsig.graph.core.INetSolver;
65
import com.iver.cit.gvsig.graph.core.Network;
66

    
67
public class FlagListener implements PointListener {
68
        public static int pixelTolerance = 10;
69
    private MapControl mapCtrl;
70
    private int idSymbolFlag = -1;
71
    private Cursor cur = java.awt.Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
72

    
73
    
74
    public FlagListener(MapControl mc) {
75
        this.mapCtrl = mc;
76
    }
77

    
78

    
79
    /* (non-Javadoc)
80
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
81
     * The PointEvent method bring you a point in pixel coordinates. You
82
     * need to transform it to world coordinates. The class to do conversions
83
     * is ViewPort, obtained thru the MapContext of mapCtrl.
84
     */
85
    public void point(PointEvent event) throws BehaviorException {
86
        
87
        Point2D pReal = mapCtrl.getMapContext().getViewPort().toMapPoint(event.getPoint());
88
        
89
                SingleLayerIterator it = new SingleLayerIterator(mapCtrl.getMapContext().getLayers());
90
                while (it.hasNext())
91
                {
92
                        FLayer aux = it.next();
93
                        if (!aux.isActive())
94
                                continue;
95
                        Network net = (Network) aux.getProperty("network");
96
                        
97
                        if ( net != null)
98
                        {
99
                                double realTol = mapCtrl.getViewPort().toMapDistance(pixelTolerance);
100
                                GvFlag flag = net.addFlag(pReal.getX(), pReal.getY(), realTol);
101
                                if (flag == null)
102
                                {
103
                                        JOptionPane.showMessageDialog(null, "No est? sobre la red");
104
                                        return;
105
                                }
106
                                GraphicLayer graphicLayer = mapCtrl.getMapContext().getGraphicsLayer();
107
                                if (idSymbolFlag == -1)
108
                                {
109
                                        FSymbol simFlag = new FSymbol(FShape.POINT, Color.BLUE);
110
                                        simFlag.setSize(10);
111
                                        simFlag.setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
112
                                        simFlag.setFill(null);
113
                                        simFlag.setOutlined(true);
114
                                        simFlag.setOutlineColor(Color.BLUE);
115
                                        
116
                                        idSymbolFlag = graphicLayer.addSymbol(simFlag);
117
                                }
118
                                IGeometry gAux = ShapeFactory.createPoint2D(pReal.getX(), pReal.getY());
119
                                FGraphic graphic = new FGraphic(gAux, idSymbolFlag);
120
                                graphicLayer.addGraphic(graphic);
121
                                mapCtrl.drawGraphics();
122
                                
123
                        }
124
                }
125
        
126
        
127
    }
128

    
129
    public Cursor getCursor() {
130
        return cur;
131
    }
132

    
133
    public boolean cancelDrawing() {
134
        return false;
135
    }
136

    
137

    
138
        public void pointDoubleClick(PointEvent event) throws BehaviorException {
139
                
140
        }
141

    
142
}
143

    
144