root / branches / v2_0_0_prep / extensions / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / FFrameGrid.java @ 37196
History | View | Annotate | Download (30.8 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.app.project.documents.layout.fframes; |
23 |
|
24 |
import java.awt.BasicStroke; |
25 |
import java.awt.Color; |
26 |
import java.awt.Font; |
27 |
import java.awt.Graphics2D; |
28 |
import java.awt.font.FontRenderContext; |
29 |
import java.awt.font.TextLayout; |
30 |
import java.awt.geom.AffineTransform; |
31 |
import java.awt.geom.Point2D; |
32 |
import java.awt.geom.Rectangle2D; |
33 |
import java.awt.image.BufferedImage; |
34 |
|
35 |
import org.gvsig.andami.PluginServices; |
36 |
import org.gvsig.compat.print.PrintAttributes; |
37 |
import org.gvsig.fmap.geom.Geometry; |
38 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
39 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
40 |
import org.gvsig.fmap.geom.GeometryLocator; |
41 |
import org.gvsig.fmap.geom.GeometryManager; |
42 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
43 |
import org.gvsig.fmap.geom.operation.Draw; |
44 |
import org.gvsig.fmap.geom.operation.DrawOperationContext; |
45 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
46 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
47 |
import org.gvsig.fmap.geom.primitive.Curve; |
48 |
import org.gvsig.fmap.geom.primitive.Envelope; |
49 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
50 |
import org.gvsig.fmap.mapcontext.ViewPort; |
51 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
52 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
53 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
54 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
55 |
import org.gvsig.tools.ToolsLocator; |
56 |
import org.gvsig.tools.dynobject.DynStruct; |
57 |
import org.gvsig.tools.locator.LocatorException; |
58 |
import org.gvsig.tools.persistence.PersistenceManager; |
59 |
import org.gvsig.tools.persistence.PersistentState; |
60 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
61 |
|
62 |
/**
|
63 |
* FFrame para introducir una cuadr?cula sobre una vista en el Layout.
|
64 |
*
|
65 |
* @author Vicente Caballero Navarro
|
66 |
*/
|
67 |
public class FFrameGrid extends AbstractFFrameViewDependence implements |
68 |
IFFrameViewDependence { |
69 |
private static final GeometryManager GEOMETRY_MANAGER = GeometryLocator.getGeometryManager(); |
70 |
|
71 |
private static final int OFFSET_IN_PIXELS = 5; |
72 |
|
73 |
public static final String PERSISTENCE_DEFINITION_NAME = "FFrameGrid"; |
74 |
|
75 |
private static final String SYMBOLLINE_FIELD = "symbolLine"; |
76 |
private static final String SYMBOLPOINT_FIELD = "symbolPoint"; |
77 |
private static final String FONT_FIELD = "font"; |
78 |
private static final String INTERVALX_FIELD = "intervalX"; |
79 |
private static final String INTERVALY_FIELD = "intervalY"; |
80 |
private static final String ISLINE_FIELD = "isLine"; |
81 |
private static final String FONTSYZE_FIELD = "fontsize"; |
82 |
private static final String TEXTCOLOR_FIELD = "textColor"; |
83 |
|
84 |
private static final ViewPort viewPortI = new ViewPort(null); |
85 |
private double intervalX = 10000; |
86 |
private double intervalY = 10000; |
87 |
|
88 |
private Color textColor = Color.black; |
89 |
private boolean isLine; |
90 |
private int sizeFont = 8; |
91 |
|
92 |
// private boolean print=false;
|
93 |
private SymbolManager symbolManager = MapContextLocator.getSymbolManager();
|
94 |
private ILineSymbol symbolLine = (ILineSymbol) symbolManager
|
95 |
.createSymbol(ILineSymbol.SYMBOL_NAME); |
96 |
private IMarkerSymbol symbolPoint = (IMarkerSymbol) symbolManager
|
97 |
.createSymbol(IMarkerSymbol.SYMBOL_NAME); |
98 |
private Font font = new Font("Arial", Font.PLAIN, sizeFont); |
99 |
|
100 |
private AffineTransform emptyTransform = new AffineTransform(); |
101 |
|
102 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
103 |
BufferedImage imgBase) {
|
104 |
ViewPort vp = fframeViewDependence.getMapContext().getViewPort(); |
105 |
|
106 |
Rectangle2D.Double r = getBoundingBox(at);
|
107 |
Rectangle2D rView = fframeViewDependence.getBoundingBox(at);
|
108 |
|
109 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), r.y |
110 |
+ (r.height / 2));
|
111 |
|
112 |
Envelope envelope = vp.getAdjustedEnvelope(); |
113 |
|
114 |
double minX = envelope.getMinimum(0); |
115 |
double minY = envelope.getMinimum(1); |
116 |
double restX = (minX / intervalX) % 1; |
117 |
double distX = restX * intervalX;
|
118 |
double restY = (minY / intervalY) % 1; |
119 |
double distY = restY * intervalY;
|
120 |
|
121 |
ISymbol symbolForMargins = null;
|
122 |
if (isLine){
|
123 |
symbolForMargins = symbolLine; |
124 |
}else{
|
125 |
try {
|
126 |
symbolForMargins = (ISymbol)symbolLine.clone(); |
127 |
symbolForMargins.setColor(symbolPoint.getColor()); |
128 |
} catch (CloneNotSupportedException e) { |
129 |
LOG.error("Symbol desn't support the clone method", e);
|
130 |
} |
131 |
} |
132 |
|
133 |
//Draw the box
|
134 |
drawBox(rView, g, symbolForMargins); |
135 |
|
136 |
//Draw the margins
|
137 |
double myScale = at.getScaleX() * 0.0234; |
138 |
int scaledFontSize = (int) (myScale * sizeFont); |
139 |
Font font =
|
140 |
new Font(this.font.getFamily(), this.font.getStyle(), |
141 |
scaledFontSize); |
142 |
|
143 |
drawMargins(envelope, distX, distY, vp, g, font, symbolForMargins); |
144 |
|
145 |
//Draw the lines or the points
|
146 |
if (isLine) {
|
147 |
drawLines(envelope, distX, distY, vp, g); |
148 |
} else {
|
149 |
drawPoints(envelope, distX, distY, vp, g); |
150 |
} |
151 |
|
152 |
g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), r.y |
153 |
+ (r.height / 2));
|
154 |
} |
155 |
|
156 |
private void drawMargins(Envelope envelope, double distX, double distY, ViewPort viewPort, Graphics2D g, Font font, ISymbol symbolForMargins){ |
157 |
double minX = envelope.getMinimum(0); |
158 |
double minY = envelope.getMinimum(1); |
159 |
double x = minX - distX;
|
160 |
double y = minY - distY;
|
161 |
|
162 |
double restX = (minX / intervalX) % 1; |
163 |
double restY = (minY / intervalY) % 1; |
164 |
|
165 |
double valueIntervalX =
|
166 |
((minX / intervalX) - restX) * intervalX - intervalX; |
167 |
|
168 |
double topX = minX;
|
169 |
|
170 |
FontRenderContext frc = g.getFontRenderContext();
|
171 |
|
172 |
//Draw vertical margins
|
173 |
while (x < envelope.getMaximum(0)) { |
174 |
if (x > topX) {
|
175 |
Point2D p2 = viewPort.fromMapPoint(x, minY);
|
176 |
Point2D p1 = viewPort.fromMapPoint(x, envelope.getMaximum(1)); |
177 |
|
178 |
drawLine(p1.getX(), p1.getY() - OFFSET_IN_PIXELS, p1.getX() , p1.getY(), g, symbolForMargins); |
179 |
drawLine(p2.getX(), p2.getY(), p2.getX() , p2.getY() + OFFSET_IN_PIXELS, g, symbolForMargins); |
180 |
|
181 |
TextLayout textaux =
|
182 |
new TextLayout(String.valueOf(valueIntervalX), font, frc); |
183 |
|
184 |
double w = textaux.getBounds().getWidth();
|
185 |
double h = textaux.getBounds().getHeight();
|
186 |
g.setColor(textColor); |
187 |
textaux.draw(g, (int) (p1.getX() - w / 2), |
188 |
(int) (p1.getY() - h) - 5); |
189 |
textaux.draw(g, (int) (p2.getX() - w / 2), |
190 |
(int) (p2.getY() + h * 2) + 5); |
191 |
} |
192 |
valueIntervalX = valueIntervalX + intervalX; |
193 |
x = x + intervalX; |
194 |
} |
195 |
double valueIntervalY =
|
196 |
((minY / intervalY) - restY) * intervalY - intervalY; |
197 |
y = y - intervalY; |
198 |
|
199 |
double topY = minY;
|
200 |
|
201 |
while (y < envelope.getMaximum(1)) { |
202 |
if (y > topY) {
|
203 |
Point2D p1 = viewPort.fromMapPoint(minX, y);
|
204 |
Point2D p2 = viewPort.fromMapPoint(envelope.getMaximum(0), y); |
205 |
|
206 |
drawLine(p1.getX() - OFFSET_IN_PIXELS, p1.getY(), p1.getX() , p1.getY(), g, symbolForMargins); |
207 |
drawLine(p2.getX(), p2.getY(), p2.getX() + OFFSET_IN_PIXELS, p2.getY(), g, symbolForMargins); |
208 |
|
209 |
TextLayout textaux =
|
210 |
new TextLayout(String.valueOf(valueIntervalY), font, frc); |
211 |
double w = textaux.getBounds().getWidth();
|
212 |
double h = textaux.getBounds().getHeight();
|
213 |
g.setColor(textColor); |
214 |
textaux.draw(g, (int) (p1.getX() - w - 10), |
215 |
(int) (p1.getY() + h / 2)); |
216 |
textaux |
217 |
.draw(g, (int) p2.getX() + 10, (int) (p2.getY() + h / 2)); |
218 |
} |
219 |
valueIntervalY = valueIntervalY + intervalY; |
220 |
y = y + intervalY; |
221 |
} |
222 |
} |
223 |
|
224 |
private void drawBox(Rectangle2D mapRectangle, Graphics2D g, ISymbol symbol){ |
225 |
try {
|
226 |
Curve curve = (Curve) GEOMETRY_MANAGER.create(TYPES.CURVE, SUBTYPES.GEOM2D); |
227 |
curve.addMoveToVertex(GEOMETRY_MANAGER.createPoint(mapRectangle.getMinX(), mapRectangle.getMinY(), SUBTYPES.GEOM2D)); |
228 |
curve.addVertex(GEOMETRY_MANAGER.createPoint(mapRectangle.getMinX(), mapRectangle.getMaxY()-1, SUBTYPES.GEOM2D));
|
229 |
curve.addVertex(GEOMETRY_MANAGER.createPoint(mapRectangle.getMaxX()-1, mapRectangle.getMaxY()-1, SUBTYPES.GEOM2D)); |
230 |
curve.addVertex(GEOMETRY_MANAGER.createPoint(mapRectangle.getMaxX()-1, mapRectangle.getMinY(), SUBTYPES.GEOM2D));
|
231 |
curve.addVertex(GEOMETRY_MANAGER.createPoint(mapRectangle.getMinX(), mapRectangle.getMinY(), SUBTYPES.GEOM2D)); |
232 |
symbol.draw(g, null, curve, null, null); |
233 |
} catch (CreateGeometryException e) {
|
234 |
LOG.error("Error drawing the box", e);
|
235 |
} |
236 |
} |
237 |
|
238 |
private void drawPoints(Envelope envelope, double distX, double distY, ViewPort viewPort, Graphics2D g){ |
239 |
double minX = envelope.getMinimum(0); |
240 |
double minY = envelope.getMinimum(1); |
241 |
double x = minX - distX;
|
242 |
double y = minY - distY;
|
243 |
|
244 |
while (x <= envelope.getMaximum(0)) { |
245 |
if (x > minX) {
|
246 |
while (y <= envelope.getMaximum(1)) { |
247 |
if (y >= minY) {
|
248 |
Point2D p = viewPort.fromMapPoint(x, y);
|
249 |
drawPoint(p, g); |
250 |
} |
251 |
y = y + intervalY; |
252 |
} |
253 |
y = minY - distY; |
254 |
} |
255 |
x = x + intervalX; |
256 |
} |
257 |
} |
258 |
|
259 |
private void drawPoint(Point2D point, Graphics2D g){ |
260 |
try {
|
261 |
Geometry geom = |
262 |
createPoint((int) point.getX(), (int) point.getY()); |
263 |
symbolPoint.draw(g, emptyTransform, geom, null, null); |
264 |
} catch (LocatorException e) {
|
265 |
LOG.error("Error drawing the grid", e);
|
266 |
} catch (CreateGeometryException e) {
|
267 |
LOG.error("Error drawing the grid", e);
|
268 |
} |
269 |
} |
270 |
|
271 |
private void drawLines(Envelope envelope, double distX, double distY, ViewPort viewPort, Graphics2D g){ |
272 |
double minX = envelope.getMinimum(0); |
273 |
double minY = envelope.getMinimum(1); |
274 |
double x = minX - distX;
|
275 |
double y = minY - distY;
|
276 |
|
277 |
//Draw the vertical lines
|
278 |
while (x < envelope.getMaximum(0)) { |
279 |
Point2D antPoint = viewPort.fromMapPoint(x, minY);
|
280 |
//This if removes the first vertical line
|
281 |
if (x > minX) {
|
282 |
Point2D p = viewPort.fromMapPoint(x, envelope.getMaximum(1)); |
283 |
drawLine(antPoint, p, g, symbolLine); |
284 |
antPoint = (Point2D) p.clone();
|
285 |
} |
286 |
x = x + intervalX; |
287 |
} |
288 |
//Draw the horizontal lines
|
289 |
while (y <= envelope.getMaximum(1)) { |
290 |
Point2D antPoint = viewPort.fromMapPoint(minX, y);
|
291 |
//This if removes the first horizontal line
|
292 |
if (y > minY) {
|
293 |
Point2D p = viewPort.fromMapPoint(envelope.getMaximum(0), y); |
294 |
drawLine(antPoint, p, g, symbolLine); |
295 |
antPoint = (Point2D) p.clone();
|
296 |
} |
297 |
y = y + intervalY; |
298 |
} |
299 |
} |
300 |
|
301 |
private void drawLine(double startX, double startY, double endX, double endY, Graphics2D g, ISymbol symbolLine){ |
302 |
try {
|
303 |
Geometry geom = |
304 |
createLine((int) startX, (int)startY, (int) endX, (int) endY); |
305 |
symbolLine.draw(g, null, geom, null, null); |
306 |
} catch (LocatorException e) {
|
307 |
LOG.error("Error drawing the grid", e);
|
308 |
} catch (CreateGeometryException e) {
|
309 |
LOG.error("Error drawing the grid", e);
|
310 |
} |
311 |
} |
312 |
|
313 |
private void drawLine(Point2D startPoint, Point2D endPoint, Graphics2D g, ISymbol symbolLine){ |
314 |
drawLine(startPoint.getX(), startPoint.getY(), endPoint.getX(), endPoint.getY(), g, symbolLine); |
315 |
} |
316 |
|
317 |
private Geometry createLine(int i, int j, int k, int l) |
318 |
throws LocatorException, CreateGeometryException {
|
319 |
Curve curve = (Curve)GEOMETRY_MANAGER.create(Geometry.TYPES.CURVE, SUBTYPES.GEOM2D); |
320 |
curve.addMoveToVertex(GEOMETRY_MANAGER.createPoint(i, j, SUBTYPES.GEOM2D)); |
321 |
curve.addVertex(GEOMETRY_MANAGER.createPoint(k, l, SUBTYPES.GEOM2D)); |
322 |
return curve;
|
323 |
} |
324 |
|
325 |
private Geometry createPoint(int i, int j) throws LocatorException, |
326 |
CreateGeometryException { |
327 |
return GeometryLocator.getGeometryManager().createPoint(i, j,
|
328 |
SUBTYPES.GEOM2D); |
329 |
} |
330 |
|
331 |
public String getNameFFrame() { |
332 |
return PluginServices.getText(this, "cuadricula") + num; |
333 |
} |
334 |
|
335 |
public String getName() { |
336 |
return PERSISTENCE_DEFINITION_NAME;
|
337 |
} |
338 |
|
339 |
public void setFFrameDependence(IFFrame f) { |
340 |
super.setFFrameDependence(f);
|
341 |
fframeViewDependence.refresh(); |
342 |
} |
343 |
|
344 |
public void setIntervalX(double d) { |
345 |
intervalX = d; |
346 |
} |
347 |
|
348 |
public void setIntervalY(double d) { |
349 |
intervalY = d; |
350 |
} |
351 |
|
352 |
public double getIntervalX() { |
353 |
return intervalX;
|
354 |
} |
355 |
|
356 |
public double getIntervalY() { |
357 |
return intervalY;
|
358 |
} |
359 |
|
360 |
public void setTextColor(Color textcolor) { |
361 |
textColor = textcolor; |
362 |
} |
363 |
|
364 |
public void setIsLine(boolean b) { |
365 |
isLine = b; |
366 |
} |
367 |
|
368 |
public boolean isLine() { |
369 |
return isLine;
|
370 |
} |
371 |
|
372 |
public Color getFontColor() { |
373 |
return textColor;
|
374 |
} |
375 |
|
376 |
public int getSizeFont() { |
377 |
return sizeFont;
|
378 |
} |
379 |
|
380 |
public void setSizeFont(int sizeFont) { |
381 |
this.sizeFont = sizeFont;
|
382 |
} |
383 |
|
384 |
public Rectangle2D.Double getBoundingBox(AffineTransform at) { |
385 |
if ((fframeViewDependence == null) || (fframeViewDependence.getMapContext() == null)){ |
386 |
return super.getBoundingBox(at); |
387 |
} |
388 |
Rectangle2D.Double r = fframeViewDependence.getBoundingBox(at);
|
389 |
Envelope extent = |
390 |
fframeViewDependence.getMapContext().getViewPort() |
391 |
.getAdjustedEnvelope(); |
392 |
double extentX = extent.getMaximum(0); |
393 |
double extentY = extent.getMaximum(1); |
394 |
int lengthX = String.valueOf((long) extentX).length(); |
395 |
double myScale = at.getScaleX() * 0.0234; |
396 |
int scaledFontSize = (int) (myScale * sizeFont); |
397 |
int pixelsX = (int) (lengthX * scaledFontSize * 0.7); |
398 |
int lengthY = String.valueOf((long) extentY).length(); |
399 |
int pixelsY = (lengthY * scaledFontSize);
|
400 |
return new Rectangle2D.Double(r.getMinX() - pixelsX, r.getMinY() - pixelsY, |
401 |
r.getWidth() + pixelsX * 2, r.getHeight() + pixelsY * 2); |
402 |
} |
403 |
|
404 |
public Rectangle2D getMovieRect(int difx, int dify) { |
405 |
return this.getBoundingBox(null); |
406 |
} |
407 |
|
408 |
public void refreshDependence(IFFrame fant, IFFrame fnew) { |
409 |
if (fframeViewDependence.equals(fant)) {
|
410 |
fframeViewDependence = (FFrameView) fnew; |
411 |
fframeViewDependence.refresh(); |
412 |
} |
413 |
} |
414 |
|
415 |
public void drawHandlers(Graphics2D g) { |
416 |
g.setColor(Color.gray);
|
417 |
super.drawHandlers(g);
|
418 |
g.setColor(Color.black);
|
419 |
} |
420 |
|
421 |
public Rectangle2D getLastMoveRect() { |
422 |
return getBoundBox();
|
423 |
} |
424 |
|
425 |
public ISymbol getSymbolLine() {
|
426 |
return symbolLine;
|
427 |
} |
428 |
|
429 |
public void setSymbolLine(ISymbol symbolLine) { |
430 |
this.symbolLine = (ILineSymbol) symbolLine;
|
431 |
} |
432 |
|
433 |
public ISymbol getSymbolPoint() {
|
434 |
return symbolPoint;
|
435 |
} |
436 |
|
437 |
public void setSymbolPoint(ISymbol symbolPoint) { |
438 |
this.symbolPoint = (IMarkerSymbol) symbolPoint;
|
439 |
} |
440 |
|
441 |
public Font getFont() { |
442 |
return font;
|
443 |
} |
444 |
|
445 |
public void setFont(Font m_font) { |
446 |
this.font = m_font;
|
447 |
} |
448 |
|
449 |
public int getFontSize() { |
450 |
return sizeFont;
|
451 |
} |
452 |
|
453 |
public void print(Graphics2D g, AffineTransform at, Geometry shape, |
454 |
PrintAttributes properties) { |
455 |
fframeViewDependence.refresh(); |
456 |
DrawOperationContext doc = new DrawOperationContext();
|
457 |
doc.setGraphics(g); |
458 |
doc.setViewPort(viewPortI); |
459 |
doc.setSymbol(symbolLine); |
460 |
ViewPort vp = fframeViewDependence.getMapContext().getViewPort(); |
461 |
FontRenderContext frc = g.getFontRenderContext();
|
462 |
int pq = properties.getPrintQuality();
|
463 |
double factor = 1; |
464 |
if (pq == PrintAttributes.PRINT_QUALITY_NORMAL) {
|
465 |
factor = (double) 300 / 72; |
466 |
} else
|
467 |
if (pq == PrintAttributes.PRINT_QUALITY_HIGH) {
|
468 |
factor = (double) 600 / 72; |
469 |
} else
|
470 |
if (pq == PrintAttributes.PRINT_QUALITY_DRAFT) {
|
471 |
// unitFactor *= 72; (which is the same than doing nothing)
|
472 |
} |
473 |
sizeFont *= factor; |
474 |
double myScale = at.getScaleX() * 0.0234; // FLayoutUtilities.fromSheetDistance(folio.getAncho(),at)/rv.getWidth(); |
475 |
int scaledFontSize = (int) (myScale * sizeFont); |
476 |
Font font =
|
477 |
new Font(this.font.getFamily(), this.font.getStyle(), |
478 |
scaledFontSize); |
479 |
Rectangle2D.Double r = getBoundingBox(at);
|
480 |
Rectangle2D rView = fframeViewDependence.getBoundingBox(at);
|
481 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), r.y |
482 |
+ (r.height / 2));
|
483 |
|
484 |
Envelope extent = vp.getAdjustedEnvelope(); |
485 |
double extentX = extent.getMinimum(0); |
486 |
double extentY = extent.getMinimum(1); |
487 |
|
488 |
double restX = (extentX / intervalX) % 1; |
489 |
double distX = restX * intervalX;
|
490 |
double restY = (extentY / intervalY) % 1; |
491 |
double distY = restY * intervalY;
|
492 |
|
493 |
double x = extentX - distX;
|
494 |
double y = extentY - distY;
|
495 |
|
496 |
g.setColor(Color.black);
|
497 |
|
498 |
// Dibuja los m?rgenes
|
499 |
double valueIntervalX =
|
500 |
((extentX / intervalX) - restX) * intervalX - intervalX; |
501 |
x = x - intervalX; |
502 |
double topX = extentX;
|
503 |
while (x < extent.getMaximum(0)) { |
504 |
if (x > topX) {
|
505 |
Point2D p2 = vp.fromMapPoint(x, extentY);
|
506 |
Point2D p1 = vp.fromMapPoint(x, extent.getMaximum(1)); |
507 |
if (isLine()) {
|
508 |
g.setColor(symbolLine.getColor()); |
509 |
g.setStroke(new BasicStroke((int) (symbolLine |
510 |
.getLineWidth() * factor))); |
511 |
} else {
|
512 |
g.setColor(symbolPoint.getColor()); |
513 |
g.setStroke(new BasicStroke(1)); |
514 |
} |
515 |
// g.setColor(lineColor);
|
516 |
g.drawLine((int) p1.getX(), (int) p1.getY() - 5, |
517 |
(int) p1.getX(), (int) p1.getY()); |
518 |
g.drawLine((int) p2.getX(), (int) p2.getY(), (int) p2.getX(), |
519 |
(int) p2.getY() + 5); |
520 |
TextLayout textaux =
|
521 |
new TextLayout(String.valueOf(valueIntervalX), font, frc); |
522 |
|
523 |
double w = textaux.getBounds().getWidth();
|
524 |
double h = textaux.getBounds().getHeight();
|
525 |
g.setColor(textColor); |
526 |
textaux.draw(g, (int) (p1.getX() - w / 2), |
527 |
(int) (p1.getY() - h) - 5); |
528 |
textaux.draw(g, (int) (p2.getX() - w / 2), |
529 |
(int) (p2.getY() + h * 2) + 5); |
530 |
} |
531 |
valueIntervalX = valueIntervalX + intervalX; |
532 |
x = x + intervalX; |
533 |
} |
534 |
double valueIntervalY =
|
535 |
((extentY / intervalY) - restY) * intervalY - intervalY; |
536 |
y = y - intervalY; |
537 |
double topY = extentY;
|
538 |
|
539 |
while (y < extent.getMaximum(1)) { |
540 |
if (y > topY) {
|
541 |
Point2D p1 = vp.fromMapPoint(extentX, y);
|
542 |
Point2D p2 = vp.fromMapPoint(extent.getMaximum(0), y); |
543 |
if (isLine()) {
|
544 |
g.setColor(symbolLine.getColor()); |
545 |
g.setStroke(new BasicStroke((int) (symbolLine |
546 |
.getLineWidth() * factor))); |
547 |
} else {
|
548 |
g.setColor(symbolPoint.getColor()); |
549 |
g.setStroke(new BasicStroke(1)); |
550 |
} |
551 |
g.drawLine((int) p1.getX() - 5, (int) p1.getY(), |
552 |
(int) p1.getX(), (int) p1.getY()); |
553 |
g.drawLine((int) p2.getX(), (int) p2.getY(), |
554 |
(int) p2.getX() + 5, (int) p2.getY()); |
555 |
TextLayout textaux =
|
556 |
new TextLayout(String.valueOf(valueIntervalY), font, frc); |
557 |
double w = textaux.getBounds().getWidth();
|
558 |
double h = textaux.getBounds().getHeight();
|
559 |
g.setColor(textColor); |
560 |
textaux.draw(g, (int) (p1.getX() - w - 10), |
561 |
(int) (p1.getY() + h / 2)); |
562 |
textaux |
563 |
.draw(g, (int) p2.getX() + 10, (int) (p2.getY() + h / 2)); |
564 |
} |
565 |
valueIntervalY = valueIntervalY + intervalY; |
566 |
y = y + intervalY; |
567 |
} |
568 |
if (isLine()) {
|
569 |
g.setColor(symbolLine.getColor()); |
570 |
g.setStroke(new BasicStroke( |
571 |
(int) (symbolLine.getLineWidth() * factor)));
|
572 |
} else {
|
573 |
g.setColor(symbolPoint.getColor()); |
574 |
g.setStroke(new BasicStroke(1)); |
575 |
} |
576 |
|
577 |
g.draw(rView); |
578 |
|
579 |
x = extentX - distX; |
580 |
y = extentY - distY; |
581 |
|
582 |
if (isLine) { // Dibuja las l?neas. |
583 |
while (x < extent.getMaximum(0)) { |
584 |
Point2D antPoint = vp.fromMapPoint(x, extentY);
|
585 |
if (x > extentX) {
|
586 |
while (y <= extent.getMaximum(1)) { |
587 |
if (y >= extentY) {
|
588 |
Point2D p = vp.fromMapPoint(x, y);
|
589 |
try {
|
590 |
Geometry geom = |
591 |
createLine((int) antPoint.getX(),
|
592 |
(int) antPoint.getY(), (int) p.getX(), |
593 |
(int) p.getY());
|
594 |
geom.invokeOperation(Draw.CODE, doc); |
595 |
} catch (GeometryOperationNotSupportedException e) {
|
596 |
e.printStackTrace(); |
597 |
} catch (GeometryOperationException e) {
|
598 |
e.printStackTrace(); |
599 |
} catch (LocatorException e) {
|
600 |
e.printStackTrace(); |
601 |
} catch (CreateGeometryException e) {
|
602 |
e.printStackTrace(); |
603 |
} |
604 |
antPoint = (Point2D) p.clone();
|
605 |
} |
606 |
|
607 |
y = y + intervalY; |
608 |
} |
609 |
Point2D p = vp.fromMapPoint(x, extent.getMaximum(1)); |
610 |
try {
|
611 |
Geometry geom = |
612 |
createLine((int) antPoint.getX(),
|
613 |
(int) antPoint.getY(), (int) p.getX(), |
614 |
(int) p.getY());
|
615 |
geom.invokeOperation(Draw.CODE, doc); |
616 |
} catch (GeometryOperationNotSupportedException e) {
|
617 |
e.printStackTrace(); |
618 |
} catch (GeometryOperationException e) {
|
619 |
e.printStackTrace(); |
620 |
} catch (LocatorException e) {
|
621 |
e.printStackTrace(); |
622 |
} catch (CreateGeometryException e) {
|
623 |
e.printStackTrace(); |
624 |
} |
625 |
antPoint = (Point2D) p.clone();
|
626 |
y = extentY - distY; |
627 |
|
628 |
} |
629 |
|
630 |
x = x + intervalX; |
631 |
} |
632 |
while (y <= extent.getMaximum(1)) { |
633 |
Point2D antPoint = vp.fromMapPoint(extentX, y);
|
634 |
if (y > extentY) {
|
635 |
while (x <= extent.getMaximum(0)) { |
636 |
if (x >= extentX) {
|
637 |
Point2D p = vp.fromMapPoint(x, y);
|
638 |
try {
|
639 |
Geometry geom = |
640 |
createLine((int) antPoint.getX(),
|
641 |
(int) antPoint.getY(), (int) p.getX(), |
642 |
(int) p.getY());
|
643 |
geom.invokeOperation(Draw.CODE, doc); |
644 |
} catch (GeometryOperationNotSupportedException e) {
|
645 |
e.printStackTrace(); |
646 |
} catch (GeometryOperationException e) {
|
647 |
e.printStackTrace(); |
648 |
} catch (LocatorException e) {
|
649 |
e.printStackTrace(); |
650 |
} catch (CreateGeometryException e) {
|
651 |
e.printStackTrace(); |
652 |
} |
653 |
antPoint = p; |
654 |
} |
655 |
x = x + intervalX; |
656 |
} |
657 |
Point2D p = vp.fromMapPoint(extent.getMaximum(0), y); |
658 |
g.drawLine((int) antPoint.getX(), (int) antPoint.getY(), |
659 |
(int) p.getX(), (int) p.getY()); |
660 |
antPoint = (Point2D) p.clone();
|
661 |
x = extentX - distX; |
662 |
} |
663 |
y = y + intervalY; |
664 |
} |
665 |
} else { // Dibuja los puntos |
666 |
while (x <= extent.getMaximum(0)) { |
667 |
if (x > extentX) {
|
668 |
while (y <= extent.getMaximum(1)) { |
669 |
if (y >= extentY) {
|
670 |
Point2D p = vp.fromMapPoint(x, y);
|
671 |
try {
|
672 |
Geometry geom = |
673 |
createPoint((int) p.getX(), (int) p.getY()); |
674 |
geom.invokeOperation(Draw.CODE, doc); |
675 |
} catch (GeometryOperationNotSupportedException e) {
|
676 |
e.printStackTrace(); |
677 |
} catch (GeometryOperationException e) {
|
678 |
e.printStackTrace(); |
679 |
} catch (LocatorException e) {
|
680 |
e.printStackTrace(); |
681 |
} catch (CreateGeometryException e) {
|
682 |
e.printStackTrace(); |
683 |
} |
684 |
} |
685 |
y = y + intervalY; |
686 |
} |
687 |
y = extentY - distY; |
688 |
} |
689 |
x = x + intervalX; |
690 |
} |
691 |
|
692 |
} |
693 |
|
694 |
g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), r.y |
695 |
+ (r.height / 2));
|
696 |
} |
697 |
|
698 |
public static void registerPersistent() { |
699 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
700 |
if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) { |
701 |
DynStruct definition = |
702 |
manager.addDefinition(FFrameGrid.class, |
703 |
PERSISTENCE_DEFINITION_NAME, |
704 |
"FFrameGrid persistence definition", null, null); |
705 |
|
706 |
definition |
707 |
.extend(manager |
708 |
.getDefinition(AbstractFFrameViewDependence.PERSISTENCE_DEFINITION_NAME)); |
709 |
|
710 |
definition.addDynFieldObject(SYMBOLLINE_FIELD) |
711 |
.setClassOfValue(ILineSymbol.class).setMandatory(true);
|
712 |
definition.addDynFieldObject(SYMBOLPOINT_FIELD) |
713 |
.setClassOfValue(IMarkerSymbol.class).setMandatory(true);
|
714 |
definition.addDynFieldObject(FONT_FIELD) |
715 |
.setClassOfValue(Font.class).setMandatory(true); |
716 |
definition.addDynFieldDouble(INTERVALX_FIELD).setMandatory(true);
|
717 |
definition.addDynFieldDouble(INTERVALY_FIELD).setMandatory(true);
|
718 |
definition.addDynFieldBoolean(ISLINE_FIELD).setMandatory(true);
|
719 |
definition.addDynFieldInt(FONTSYZE_FIELD).setMandatory(true);
|
720 |
definition.addDynFieldObject(TEXTCOLOR_FIELD) |
721 |
.setClassOfValue(Color.class).setMandatory(true); |
722 |
} |
723 |
} |
724 |
|
725 |
@Override
|
726 |
public void loadFromState(PersistentState state) |
727 |
throws PersistenceException {
|
728 |
super.loadFromState(state);
|
729 |
symbolLine = (ILineSymbol) state.get(SYMBOLLINE_FIELD); |
730 |
symbolPoint = (IMarkerSymbol) state.get(SYMBOLPOINT_FIELD); |
731 |
font = (Font) state.get(FONT_FIELD);
|
732 |
intervalX = state.getDouble(INTERVALX_FIELD); |
733 |
intervalY = state.getDouble(INTERVALY_FIELD); |
734 |
isLine = state.getBoolean(ISLINE_FIELD); |
735 |
sizeFont = state.getInt(FONTSYZE_FIELD); |
736 |
textColor = (Color) state.get(TEXTCOLOR_FIELD);
|
737 |
} |
738 |
|
739 |
@Override
|
740 |
public void saveToState(PersistentState state) throws PersistenceException { |
741 |
super.saveToState(state);
|
742 |
state.set(SYMBOLLINE_FIELD, symbolLine); |
743 |
state.set(SYMBOLPOINT_FIELD, symbolPoint); |
744 |
state.set(FONT_FIELD, font); |
745 |
state.set(INTERVALX_FIELD, intervalX); |
746 |
state.set(INTERVALY_FIELD, intervalY); |
747 |
state.set(ISLINE_FIELD, isLine); |
748 |
state.set(FONTSYZE_FIELD, sizeFont); |
749 |
state.set(TEXTCOLOR_FIELD, textColor); |
750 |
} |
751 |
} |