svn-gvsig-desktop / branches / gvSIG_CAD_Layout_version / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / LayoutCADToolAdapter.java @ 1763
History | View | Annotate | Download (4.65 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.layout; |
42 |
|
43 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
44 |
import com.iver.cit.gvsig.gui.cad.CADToolAdapter; |
45 |
import com.iver.cit.gvsig.gui.cad.CadTool; |
46 |
|
47 |
import java.awt.Color; |
48 |
import java.awt.Graphics; |
49 |
import java.awt.event.MouseEvent; |
50 |
import java.awt.geom.AffineTransform; |
51 |
import java.awt.geom.Point2D; |
52 |
import java.awt.geom.Rectangle2D; |
53 |
|
54 |
|
55 |
/**
|
56 |
* CADToolAdapter ajustado a las necesidades del Layout.
|
57 |
*
|
58 |
* @author Vicente Caballero Navarro
|
59 |
*/
|
60 |
public class LayoutCADToolAdapter extends CADToolAdapter { |
61 |
private Layout layout;
|
62 |
|
63 |
/**
|
64 |
*
|
65 |
*/
|
66 |
public LayoutCADToolAdapter(Layout l) {
|
67 |
layout = l; |
68 |
} |
69 |
|
70 |
/**
|
71 |
* Devuelve la matriz de transformaci?n del layout.
|
72 |
*
|
73 |
* @return Matriz de transformaci?n.
|
74 |
*/
|
75 |
public AffineTransform getAT() { |
76 |
return layout.getAT();
|
77 |
} |
78 |
|
79 |
/**
|
80 |
* Devuelve la distancia real del Layout a partir de los pixels.
|
81 |
*
|
82 |
* @param i Pixels.
|
83 |
*
|
84 |
* @return Distancia real.
|
85 |
*/
|
86 |
public double toDistance(int i) { |
87 |
return FLayoutUtilities.toSheetDistance(i, getAT());
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* Repinta el Layout.
|
92 |
*/
|
93 |
public void refresh() { |
94 |
// layout.refresh();
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* Pinta de alguna manera especial las geometrias seleccionadas para la
|
99 |
* edici?n. En caso de que el snapping est? activado, pintar? el efecto
|
100 |
* del mismo.
|
101 |
*
|
102 |
*/
|
103 |
public void paintComponent(Graphics g) { |
104 |
getCadTool().setAT(getAT()); |
105 |
|
106 |
Point2D.Double paux = new Point2D.Double(adjustedPoint.getX(), |
107 |
adjustedPoint.getY()); |
108 |
paux = FLayoutUtilities.toSheetPoint(paux, getAT()); |
109 |
getCadTool().drawOperation(g, null, null, paux.getX(), paux.getY()); |
110 |
} |
111 |
|
112 |
/**
|
113 |
* Devuelve un punto real a partir de uno en pixels.
|
114 |
*
|
115 |
* @param p Punto de pantalla.
|
116 |
*
|
117 |
* @return Punto real del Layout.
|
118 |
*/
|
119 |
public Point2D toPoint(Point2D p) { |
120 |
return FLayoutUtilities.toSheetPoint(p, getAT());
|
121 |
} |
122 |
|
123 |
/**
|
124 |
* Devuelve el extent real del Layout.
|
125 |
*
|
126 |
* @return Extent real.
|
127 |
*/
|
128 |
public Rectangle2D getExtent() { |
129 |
return FLayoutUtilities.toSheetRect(layout.getRect(), getAT());
|
130 |
} |
131 |
|
132 |
/**
|
133 |
* Devuelve la distancia en pixels a partir de una distancia real.
|
134 |
*
|
135 |
* @param d distancia real.
|
136 |
*
|
137 |
* @return Distancia en pixels.
|
138 |
*/
|
139 |
public double fromDistance(double d) { |
140 |
return FLayoutUtilities.fromSheetDistance(d, getAT());
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* Devuelve un punto en pixels a partir de un punto real.
|
145 |
*
|
146 |
* @param p Punto real.
|
147 |
*
|
148 |
* @return Punto en pixels.
|
149 |
*/
|
150 |
public Point2D fromPoint(Point2D p) { |
151 |
return FLayoutUtilities.fromSheetPoint(p, getAT());
|
152 |
} |
153 |
|
154 |
/**
|
155 |
* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
|
156 |
*/
|
157 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
158 |
calculateSnapPoint(e.getPoint()); |
159 |
} |
160 |
|
161 |
/**
|
162 |
* Dibuja el grid sobre el graphics que se pasa como par?metro.
|
163 |
*
|
164 |
* @param g Graphics sobre el que se dibuja el grid.
|
165 |
*/
|
166 |
public void drawGrid(Graphics g) { |
167 |
g.setColor(Color.blue);
|
168 |
grid.drawGrid(g); |
169 |
} |
170 |
|
171 |
/**
|
172 |
* Inserta true o false seg?n se quiera visualizar el grid.
|
173 |
*
|
174 |
* @param value True si se quiere visualizar el grid.
|
175 |
*/
|
176 |
public void setGrid(boolean value) { |
177 |
grid.setUseGrid(value); |
178 |
grid.setAT(getAT()); |
179 |
} |
180 |
/**
|
181 |
* DOCUMENT ME!
|
182 |
*/
|
183 |
public void configureMenu() { |
184 |
String[] desc = ((CadTool) cadToolStack.peek()).getAutomaton() |
185 |
.getCurrentTransitionDescriptions(); |
186 |
String[] labels = ((CadTool) cadToolStack.peek()).getAutomaton() |
187 |
.getCurrentTransitions(); |
188 |
layout.clearMenu(); |
189 |
|
190 |
for (int i = 0; i < desc.length; i++) { |
191 |
if (desc[i] != null) { |
192 |
layout.addMenuEntry(desc[i], labels[i]); |
193 |
} |
194 |
} |
195 |
} |
196 |
|
197 |
} |