Statistics
| Revision:

svn-gvsig-desktop / branches / gvSIG_CAD_Layout_version / applications / appgvSIG / src / com / iver / cit / gvsig / gui / cad / ViewCADToolAdapter.java @ 1763

History | View | Annotate | Download (4.82 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.gui.cad;
42

    
43
import com.iver.cit.gvsig.fmap.layers.FBitSet;
44
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
45

    
46
import java.awt.Graphics;
47
import java.awt.event.MouseEvent;
48
import java.awt.geom.AffineTransform;
49
import java.awt.geom.Point2D;
50
import java.awt.geom.Rectangle2D;
51

    
52

    
53
/**
54
 * CADToolAdapter para gestionar la interactividad de la parte CAD con el MapControl.
55
 *
56
 * @author Vicente Caballero Navarro
57
 */
58
public class ViewCADToolAdapter extends CADToolAdapter {
59
        /**
60
         * Pinta de alguna manera especial las geometrias seleccionadas para la
61
         * edici?n. En caso de que el snapping est? activado, pintar? el efecto
62
         * del mismo.
63
         *
64
         * @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
65
         */
66
        public void paintComponent(Graphics g) {
67
                super.paintComponent(g);
68
                //grid.drawGrid(g);
69
                drawCursor(g);
70

    
71
                if (adjustedPoint != null) {
72
                        Point2D p = getMapControl().getViewPort().toMapPoint((int) adjustedPoint.getX(),
73
                                        (int) adjustedPoint.getY());
74
                        CadTool cadtool = (CadTool) cadToolStack.peek();
75
                        cadtool.setAT(getMapControl().getViewPort().getAffineTransform());
76
                        cadtool.drawOperation(g, editableFeatureSource, selection,
77
                                p.getX(), p.getY());
78
                }
79
        }
80

    
81
        /**
82
         * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
83
         */
84
        public void mouseMoved(MouseEvent e) throws BehaviorException {
85
                calculateSnapPoint(e.getPoint());
86

    
87
                getMapControl().repaint();
88
        }
89

    
90
        /**
91
         * Inserta true o false seg?n se quiera visualizar el grid.
92
         *
93
         * @param value True si se quiere visualizar el grid.
94
         */
95
        public void setGrid(boolean value) {
96
                grid.setUseGrid(value);
97
                grid.setAT(getAT());
98
                setGridSizeX(toDistance(20));
99
                setGridSizeY(toDistance(20));
100
                getMapControl().setGrid(grid);
101
        }
102

    
103
        /**
104
         * Devuelve la matriz de transformaci?n del viewport de la vista.
105
         *
106
         * @return MAtriz de transformaci?n.
107
         */
108
        public AffineTransform getAT() {
109
                return getMapControl().getViewPort().getAffineTransform();
110
        }
111

    
112
        /**
113
         * Devuelve la distancia real de la cartograf?a a partir de los pixels.
114
         *
115
         * @param i Pixels.
116
         *
117
         * @return Distancia real.
118
         */
119
        public double toDistance(int i) {
120
                return getMapControl().getViewPort().toMapDistance(i);
121
        }
122

    
123
        
124
        /**
125
         * Repinta la vista.
126
         */
127
        public void refresh() {
128
                getMapControl().drawMap(false);
129
        }
130

    
131
        /**
132
         * Devuelve un punto real a partir de uno en pixels.
133
         *
134
         * @param p Punto de pantalla.
135
         *
136
         * @return Punto real de la cartograf?a.
137
         */
138
        public Point2D toPoint(Point2D p) {
139
                return getMapControl().getViewPort().toMapPoint(p);
140
        }
141

    
142
        /**
143
         * Devuelve el extent real de la cartograf?a.
144
         *
145
         * @return Extent real.
146
         */
147
        public Rectangle2D getExtent() {
148
                return getMapControl().getViewPort().getAdjustedExtent();
149
        }
150

    
151
        /**
152
         * Devuelve la distancia en pixels a partir de una distancia real.
153
         *
154
         * @param d distancia real.
155
         *
156
         * @return Distancia en pixels.
157
         */
158
        public double fromDistance(double d) {
159
                return getMapControl().getViewPort().fromMapDistance(d);
160
        }
161

    
162
        /**
163
         * Devuelve un punto en pixels a partir de un punto real.
164
         *
165
         * @param p Punto real.
166
         *
167
         * @return Punto en pixels.
168
         */
169
        public Point2D fromPoint(Point2D p) {
170
                return getMapControl().getViewPort().fromMapPoint(p);
171
        }
172
        /**
173
         * DOCUMENT ME!
174
         */
175
        public void configureMenu() {
176
                String[] desc = ((CadTool) cadToolStack.peek()).getAutomaton()
177
                                                 .getCurrentTransitionDescriptions();
178
                String[] labels = ((CadTool) cadToolStack.peek()).getAutomaton()
179
                                                   .getCurrentTransitions();
180
                if (getCadMapControl()!=null){
181
                getCadMapControl().clearMenu();
182

    
183
                for (int i = 0; i < desc.length; i++) {
184
                        if (desc[i] != null) {
185
                                getCadMapControl().addMenuEntry(desc[i], labels[i]);
186
                        }
187
                }
188
                }
189
        }
190
}