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 @ 36648
History | View | Annotate | Download (35 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.app.project.documents.layout.FLayoutUtilities; |
37 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
38 |
import org.gvsig.compat.print.PrintAttributes; |
39 |
import org.gvsig.fmap.geom.Geometry; |
40 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
41 |
import org.gvsig.fmap.geom.GeometryLocator; |
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.Envelope; |
48 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
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 |
|
70 |
public static final String PERSISTENCE_DEFINITION_NAME = "FFrameGrid"; |
71 |
|
72 |
private static final String SYMBOLLINE_FIELD = "symbolLine"; |
73 |
private static final String SYMBOLPOINT_FIELD = "symbolPoint"; |
74 |
private static final String FONT_FIELD = "font"; |
75 |
private static final String INTERVALX_FIELD = "intervalX"; |
76 |
private static final String INTERVALY_FIELD = "intervalY"; |
77 |
private static final String ISLINE_FIELD = "isLine"; |
78 |
private static final String FONTSYZE_FIELD = "fontsize"; |
79 |
private static final String TEXTCOLOR_FIELD = "textColor"; |
80 |
|
81 |
private static final ViewPort viewPortI = new ViewPort(null); |
82 |
private double intervalX = 10000; |
83 |
private double intervalY = 10000; |
84 |
|
85 |
private Color textColor = Color.black; |
86 |
private boolean isLine; |
87 |
private int sizeFont = 8; |
88 |
private LayoutPanel layout;
|
89 |
// private boolean print=false;
|
90 |
private SymbolManager symbolManager = MapContextLocator.getSymbolManager();
|
91 |
private ILineSymbol symbolLine = (ILineSymbol) symbolManager
|
92 |
.createSymbol(ILineSymbol.SYMBOL_NAME); |
93 |
private IMarkerSymbol symbolPoint = (IMarkerSymbol) symbolManager
|
94 |
.createSymbol(IMarkerSymbol.SYMBOL_NAME); |
95 |
private Font font = new Font("Arial", Font.PLAIN, sizeFont); |
96 |
|
97 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
98 |
BufferedImage imgBase) {
|
99 |
// if (print){
|
100 |
// fframeview.refresh();
|
101 |
// print=false;
|
102 |
// }
|
103 |
DrawOperationContext doc = new DrawOperationContext();
|
104 |
doc.setGraphics(g); |
105 |
doc.setViewPort(viewPortI); |
106 |
doc.setSymbol(symbolLine); |
107 |
ViewPort vp = fframeViewDependence.getMapContext().getViewPort(); |
108 |
// vp.setAffineTransform(at);
|
109 |
FontRenderContext frc = g.getFontRenderContext();
|
110 |
double myScale = at.getScaleX() * 0.0234; // FLayoutUtilities.fromSheetDistance(folio.getAncho(),at)/rv.getWidth(); |
111 |
int scaledFontSize = (int) (myScale * sizeFont); |
112 |
Font font =
|
113 |
new Font(this.font.getFamily(), this.font.getStyle(), |
114 |
scaledFontSize); |
115 |
Rectangle2D.Double r = getBoundingBox(at);
|
116 |
Rectangle2D rView = fframeViewDependence.getBoundingBox(at);
|
117 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), r.y |
118 |
+ (r.height / 2));
|
119 |
// AffineTransform atView=fframeview.getATMap();
|
120 |
|
121 |
// vp.setAffineTransform(at);
|
122 |
Envelope extent = vp.getAdjustedEnvelope(); |
123 |
double extentX = extent.getMinimum(0); |
124 |
double extentY = extent.getMinimum(1); |
125 |
|
126 |
double restX = (extentX / intervalX) % 1; |
127 |
double distX = restX * intervalX;
|
128 |
// double distPixelsX=FLayoutUtilities.fromSheetDistance(distX,atView);
|
129 |
double restY = (extentY / intervalY) % 1; |
130 |
double distY = restY * intervalY;
|
131 |
// double distPixelsY=FLayoutUtilities.fromSheetDistance(distY,atView);
|
132 |
|
133 |
double x = extentX - distX;
|
134 |
// double pixelsX = rView.getMinX()-distPixelsX;
|
135 |
double y = extentY - distY;
|
136 |
// double pixelsY = rView.getMinY()-distPixelsY;
|
137 |
|
138 |
// fframeview.getMapContext().getViewPort().fromMapPoint(extentX,extentY);
|
139 |
// double
|
140 |
// pixelsInterval=FLayoutUtilities.fromSheetDistance(interval,atView);
|
141 |
|
142 |
g.setColor(Color.black);
|
143 |
|
144 |
// Dibuja los m?rgenes
|
145 |
double valueIntervalX =
|
146 |
((extentX / intervalX) - restX) * intervalX - intervalX; |
147 |
x = x - intervalX; |
148 |
double topX = extentX;
|
149 |
// if (showCornerText){
|
150 |
// x+=intervalX;
|
151 |
// topX-=intervalX;
|
152 |
// }
|
153 |
while (x < extent.getMaximum(0)) { |
154 |
if (x > topX) {
|
155 |
Point2D p2 = vp.fromMapPoint(x, extentY);
|
156 |
Point2D p1 = vp.fromMapPoint(x, extent.getMaximum(1)); |
157 |
if (isLine()) {
|
158 |
g.setColor(symbolLine.getColor()); |
159 |
g.setStroke(new BasicStroke((int) symbolLine.getLineWidth())); |
160 |
} else {
|
161 |
g.setColor(symbolPoint.getColor()); |
162 |
g.setStroke(new BasicStroke(1)); |
163 |
} |
164 |
// g.setColor(lineColor);
|
165 |
g.drawLine((int) p1.getX(), (int) p1.getY() - 5, |
166 |
(int) p1.getX(), (int) p1.getY()); |
167 |
g.drawLine((int) p2.getX(), (int) p2.getY(), (int) p2.getX(), |
168 |
(int) p2.getY() + 5); |
169 |
TextLayout textaux =
|
170 |
new TextLayout(String.valueOf(valueIntervalX), font, frc); |
171 |
|
172 |
double w = textaux.getBounds().getWidth();
|
173 |
double h = textaux.getBounds().getHeight();
|
174 |
g.setColor(textColor); |
175 |
textaux.draw(g, (int) (p1.getX() - w / 2), |
176 |
(int) (p1.getY() - h) - 5); |
177 |
textaux.draw(g, (int) (p2.getX() - w / 2), |
178 |
(int) (p2.getY() + h * 2) + 5); |
179 |
} |
180 |
valueIntervalX = valueIntervalX + intervalX; |
181 |
x = x + intervalX; |
182 |
} |
183 |
double valueIntervalY =
|
184 |
((extentY / intervalY) - restY) * intervalY - intervalY; |
185 |
y = y - intervalY; |
186 |
double topY = extentY;
|
187 |
// if (showCornerText){
|
188 |
// y+=intervalY;
|
189 |
// topY-=intervalY;
|
190 |
// }
|
191 |
while (y < extent.getMaximum(1)) { |
192 |
if (y > topY) {
|
193 |
Point2D p1 = vp.fromMapPoint(extentX, y);
|
194 |
Point2D p2 = vp.fromMapPoint(extent.getMaximum(0), y); |
195 |
if (isLine()) {
|
196 |
g.setColor(symbolLine.getColor()); |
197 |
g.setStroke(new BasicStroke((int) symbolLine.getLineWidth())); |
198 |
} else {
|
199 |
g.setColor(symbolPoint.getColor()); |
200 |
g.setStroke(new BasicStroke(1)); |
201 |
} |
202 |
// g.setColor(lineColor);
|
203 |
g.drawLine((int) p1.getX() - 5, (int) p1.getY(), |
204 |
(int) p1.getX(), (int) p1.getY()); |
205 |
g.drawLine((int) p2.getX(), (int) p2.getY(), |
206 |
(int) p2.getX() + 5, (int) p2.getY()); |
207 |
TextLayout textaux =
|
208 |
new TextLayout(String.valueOf(valueIntervalY), font, frc); |
209 |
double w = textaux.getBounds().getWidth();
|
210 |
double h = textaux.getBounds().getHeight();
|
211 |
g.setColor(textColor); |
212 |
textaux.draw(g, (int) (p1.getX() - w - 10), |
213 |
(int) (p1.getY() + h / 2)); |
214 |
textaux |
215 |
.draw(g, (int) p2.getX() + 10, (int) (p2.getY() + h / 2)); |
216 |
} |
217 |
valueIntervalY = valueIntervalY + intervalY; |
218 |
y = y + intervalY; |
219 |
} |
220 |
if (isLine()) {
|
221 |
g.setColor(symbolLine.getColor()); |
222 |
g.setStroke(new BasicStroke((int) symbolLine.getLineWidth())); |
223 |
} else {
|
224 |
g.setColor(symbolPoint.getColor()); |
225 |
g.setStroke(new BasicStroke(1)); |
226 |
} |
227 |
// g.setColor(lineColor);
|
228 |
|
229 |
g.draw(rView); |
230 |
|
231 |
x = extentX - distX; |
232 |
y = extentY - distY; |
233 |
|
234 |
if (isLine) { // Dibuja las l?neas. |
235 |
while (x < extent.getMaximum(0)) { |
236 |
Point2D antPoint = vp.fromMapPoint(x, extentY);
|
237 |
if (x > extentX) {
|
238 |
while (y <= extent.getMaximum(1)) { |
239 |
if (y >= extentY) {
|
240 |
Point2D p = vp.fromMapPoint(x, y);
|
241 |
try {
|
242 |
Geometry geom = |
243 |
createLine((int) antPoint.getX(),
|
244 |
(int) antPoint.getY(), (int) p.getX(), |
245 |
(int) p.getY());
|
246 |
geom.invokeOperation(Draw.CODE, doc); |
247 |
} catch (GeometryOperationNotSupportedException e) {
|
248 |
e.printStackTrace(); |
249 |
} catch (GeometryOperationException e) {
|
250 |
e.printStackTrace(); |
251 |
} catch (LocatorException e) {
|
252 |
// TODO Auto-generated catch block
|
253 |
e.printStackTrace(); |
254 |
} catch (CreateGeometryException e) {
|
255 |
// TODO Auto-generated catch block
|
256 |
e.printStackTrace(); |
257 |
} |
258 |
antPoint = (Point2D) p.clone();
|
259 |
} |
260 |
|
261 |
y = y + intervalY; |
262 |
} |
263 |
Point2D p = vp.fromMapPoint(x, extent.getMaximum(1)); |
264 |
try {
|
265 |
Geometry geom = |
266 |
createLine((int) antPoint.getX(),
|
267 |
(int) antPoint.getY(), (int) p.getX(), |
268 |
(int) p.getY());
|
269 |
geom.invokeOperation(Draw.CODE, doc); |
270 |
} catch (GeometryOperationNotSupportedException e) {
|
271 |
e.printStackTrace(); |
272 |
} catch (GeometryOperationException e) {
|
273 |
e.printStackTrace(); |
274 |
} catch (LocatorException e) {
|
275 |
// TODO Auto-generated catch block
|
276 |
e.printStackTrace(); |
277 |
} catch (CreateGeometryException e) {
|
278 |
// TODO Auto-generated catch block
|
279 |
e.printStackTrace(); |
280 |
} |
281 |
// g.drawLine((int)antPoint.getX(),(int)antPoint.getY(),(int)p.getX(),(int)p.getY());
|
282 |
antPoint = (Point2D) p.clone();
|
283 |
y = extentY - distY; |
284 |
|
285 |
} |
286 |
|
287 |
x = x + intervalX; |
288 |
} |
289 |
while (y <= extent.getMaximum(1)) { |
290 |
Point2D antPoint = vp.fromMapPoint(extentX, y);
|
291 |
if (y > extentY) {
|
292 |
while (x <= extent.getMaximum(0)) { |
293 |
if (x >= extentX) {
|
294 |
Point2D p = vp.fromMapPoint(x, y);
|
295 |
try {
|
296 |
Geometry geom = |
297 |
createLine((int) antPoint.getX(),
|
298 |
(int) antPoint.getY(), (int) p.getX(), |
299 |
(int) p.getY());
|
300 |
geom.invokeOperation(Draw.CODE, doc); |
301 |
} catch (GeometryOperationNotSupportedException e) {
|
302 |
e.printStackTrace(); |
303 |
} catch (GeometryOperationException e) {
|
304 |
e.printStackTrace(); |
305 |
} catch (LocatorException e) {
|
306 |
e.printStackTrace(); |
307 |
} catch (CreateGeometryException e) {
|
308 |
e.printStackTrace(); |
309 |
} |
310 |
// g.drawLine((int)antPoint.getX(),(int)antPoint.getY(),(int)p.getX(),(int)p.getY());
|
311 |
antPoint = p; |
312 |
} |
313 |
x = x + intervalX; |
314 |
} |
315 |
Point2D p = vp.fromMapPoint(extent.getMaximum(0), y); |
316 |
g.drawLine((int) antPoint.getX(), (int) antPoint.getY(), |
317 |
(int) p.getX(), (int) p.getY()); |
318 |
antPoint = (Point2D) p.clone();
|
319 |
x = extentX - distX; |
320 |
} |
321 |
y = y + intervalY; |
322 |
} |
323 |
} else { // Dibuja los puntos |
324 |
while (x <= extent.getMaximum(0)) { |
325 |
if (x > extentX) {
|
326 |
while (y <= extent.getMaximum(1)) { |
327 |
if (y >= extentY) {
|
328 |
Point2D p = vp.fromMapPoint(x, y);
|
329 |
try {
|
330 |
Geometry geom = |
331 |
createPoint((int) p.getX(), (int) p.getY()); |
332 |
geom.invokeOperation(Draw.CODE, doc); |
333 |
} catch (GeometryOperationNotSupportedException e) {
|
334 |
e.printStackTrace(); |
335 |
} catch (GeometryOperationException e) {
|
336 |
e.printStackTrace(); |
337 |
} catch (LocatorException e) {
|
338 |
e.printStackTrace(); |
339 |
} catch (CreateGeometryException e) {
|
340 |
e.printStackTrace(); |
341 |
} |
342 |
} |
343 |
y = y + intervalY; |
344 |
} |
345 |
y = extentY - distY; |
346 |
} |
347 |
x = x + intervalX; |
348 |
} |
349 |
|
350 |
} |
351 |
|
352 |
g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), r.y |
353 |
+ (r.height / 2));
|
354 |
} |
355 |
|
356 |
private Geometry createLine(int i, int j, int k, int l) |
357 |
throws LocatorException, CreateGeometryException {
|
358 |
GeneralPathX gpx = new GeneralPathX();
|
359 |
gpx.moveTo(i, j); |
360 |
gpx.lineTo(k, l); |
361 |
return GeometryLocator.getGeometryManager().createCurve(gpx,
|
362 |
SUBTYPES.GEOM2D); |
363 |
} |
364 |
|
365 |
private Geometry createPoint(int i, int j) throws LocatorException, |
366 |
CreateGeometryException { |
367 |
return GeometryLocator.getGeometryManager().createPoint(i, j,
|
368 |
SUBTYPES.GEOM2D); |
369 |
} |
370 |
|
371 |
public String getNameFFrame() { |
372 |
return PluginServices.getText(this, "cuadricula") + num; |
373 |
} |
374 |
|
375 |
public String getName() { |
376 |
return PERSISTENCE_DEFINITION_NAME;
|
377 |
} |
378 |
|
379 |
public void setFFrameDependence(IFFrame f) { |
380 |
super.setFFrameDependence(f);
|
381 |
fframeViewDependence.refresh(); |
382 |
if (fframeViewDependence.getMapContext() != null) { |
383 |
setBoundBox(); |
384 |
} |
385 |
} |
386 |
|
387 |
public void setIntervalX(double d) { |
388 |
intervalX = d; |
389 |
} |
390 |
|
391 |
public void setIntervalY(double d) { |
392 |
intervalY = d; |
393 |
} |
394 |
|
395 |
public double getIntervalX() { |
396 |
return intervalX;
|
397 |
} |
398 |
|
399 |
public double getIntervalY() { |
400 |
return intervalY;
|
401 |
} |
402 |
|
403 |
public void setTextColor(Color textcolor) { |
404 |
textColor = textcolor; |
405 |
} |
406 |
|
407 |
public void setIsLine(boolean b) { |
408 |
isLine = b; |
409 |
} |
410 |
|
411 |
public boolean isLine() { |
412 |
return isLine;
|
413 |
} |
414 |
|
415 |
public Color getFontColor() { |
416 |
return textColor;
|
417 |
} |
418 |
|
419 |
public int getSizeFont() { |
420 |
return sizeFont;
|
421 |
} |
422 |
|
423 |
public void setSizeFont(int sizeFont) { |
424 |
this.sizeFont = sizeFont;
|
425 |
} |
426 |
|
427 |
public void setBoundBox() { |
428 |
Rectangle2D r = fframeViewDependence.getBoundBox();
|
429 |
Envelope extent = |
430 |
fframeViewDependence.getMapContext().getViewPort() |
431 |
.getAdjustedEnvelope(); |
432 |
double extentX = extent.getMaximum(0); |
433 |
double extentY = extent.getMaximum(1); |
434 |
int lengthX = String.valueOf((long) extentX).length(); |
435 |
double myScale = layout.getLayoutControl().getAT().getScaleX() * 0.0234; // FLayoutUtilities.fromSheetDistance(folio.getAncho(),at)/rv.getWidth(); |
436 |
int scaledFontSize = (int) (myScale * sizeFont); |
437 |
int pixelsX = (int) (lengthX * scaledFontSize * 0.7); |
438 |
int lengthY = String.valueOf((long) extentY).length(); |
439 |
int pixelsY = (lengthY * scaledFontSize);
|
440 |
double dX =
|
441 |
FLayoutUtilities.toSheetDistance(pixelsX, layout.getLayoutControl() |
442 |
.getAT()); |
443 |
double dY =
|
444 |
FLayoutUtilities.toSheetDistance(pixelsY, layout.getLayoutControl() |
445 |
.getAT()); |
446 |
Rectangle2D rBound =
|
447 |
new Rectangle2D.Double(r.getMinX() - dY, r.getMinY() - dX, |
448 |
r.getWidth() + dY * 2, r.getHeight() + dX * 2); |
449 |
super.setBoundBox(rBound);
|
450 |
} |
451 |
|
452 |
public Rectangle2D getMovieRect(int difx, int dify) { |
453 |
return this.getBoundingBox(null); |
454 |
} |
455 |
|
456 |
public void refreshDependence(IFFrame fant, IFFrame fnew) { |
457 |
if (fframeViewDependence.equals(fant)) {
|
458 |
fframeViewDependence = (FFrameView) fnew; |
459 |
fframeViewDependence.refresh(); |
460 |
setBoundBox(); |
461 |
} |
462 |
} |
463 |
|
464 |
public void setLayout(LayoutPanel l) { |
465 |
this.layout = l;
|
466 |
|
467 |
} |
468 |
|
469 |
public void drawHandlers(Graphics2D g) { |
470 |
g.setColor(Color.gray);
|
471 |
super.drawHandlers(g);
|
472 |
g.setColor(Color.black);
|
473 |
} |
474 |
|
475 |
public Rectangle2D getLastMoveRect() { |
476 |
return getBoundBox();
|
477 |
} |
478 |
|
479 |
public void setBoundBox(Rectangle2D r) { |
480 |
if (fframeViewDependence != null) { |
481 |
setBoundBox(); |
482 |
} else {
|
483 |
super.setBoundBox(r);
|
484 |
} |
485 |
} |
486 |
|
487 |
public ISymbol getSymbolLine() {
|
488 |
return symbolLine;
|
489 |
} |
490 |
|
491 |
public void setSymbolLine(ISymbol symbolLine) { |
492 |
this.symbolLine = (ILineSymbol) symbolLine;
|
493 |
} |
494 |
|
495 |
public ISymbol getSymbolPoint() {
|
496 |
return symbolPoint;
|
497 |
} |
498 |
|
499 |
public void setSymbolPoint(ISymbol symbolPoint) { |
500 |
this.symbolPoint = (IMarkerSymbol) symbolPoint;
|
501 |
} |
502 |
|
503 |
public Font getFont() { |
504 |
return font;
|
505 |
} |
506 |
|
507 |
public void setFont(Font m_font) { |
508 |
this.font = m_font;
|
509 |
} |
510 |
|
511 |
// public void setLineSymbol(ISymbol symbol) {
|
512 |
// this.symbolLine=symbol;
|
513 |
//
|
514 |
// }
|
515 |
//
|
516 |
// public void setPointSymbol(ISymbol symbol) {
|
517 |
// this.symbolPoint=symbol;
|
518 |
//
|
519 |
// }
|
520 |
|
521 |
public int getFontSize() { |
522 |
return sizeFont;
|
523 |
} |
524 |
|
525 |
public void print(Graphics2D g, AffineTransform at, Geometry shape, |
526 |
PrintAttributes properties) { |
527 |
fframeViewDependence.refresh(); |
528 |
DrawOperationContext doc = new DrawOperationContext();
|
529 |
doc.setGraphics(g); |
530 |
doc.setViewPort(viewPortI); |
531 |
doc.setSymbol(symbolLine); |
532 |
ViewPort vp = fframeViewDependence.getMapContext().getViewPort(); |
533 |
// vp.setAffineTransform(at);
|
534 |
FontRenderContext frc = g.getFontRenderContext();
|
535 |
int pq = properties.getPrintQuality();
|
536 |
double factor = 1; |
537 |
if (pq == PrintAttributes.PRINT_QUALITY_NORMAL) {
|
538 |
factor = (double) 300 / 72; |
539 |
} else
|
540 |
if (pq == PrintAttributes.PRINT_QUALITY_HIGH) {
|
541 |
factor = (double) 600 / 72; |
542 |
} else
|
543 |
if (pq == PrintAttributes.PRINT_QUALITY_DRAFT) {
|
544 |
// unitFactor *= 72; (which is the same than doing nothing)
|
545 |
} |
546 |
sizeFont *= factor; |
547 |
double myScale = at.getScaleX() * 0.0234; // FLayoutUtilities.fromSheetDistance(folio.getAncho(),at)/rv.getWidth(); |
548 |
int scaledFontSize = (int) (myScale * sizeFont); |
549 |
Font font =
|
550 |
new Font(this.font.getFamily(), this.font.getStyle(), |
551 |
scaledFontSize); |
552 |
Rectangle2D.Double r = getBoundingBox(at);
|
553 |
Rectangle2D rView = fframeViewDependence.getBoundingBox(at);
|
554 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), r.y |
555 |
+ (r.height / 2));
|
556 |
// AffineTransform atView=fframeview.getATMap();
|
557 |
|
558 |
// vp.setAffineTransform(at);
|
559 |
Envelope extent = vp.getAdjustedEnvelope(); |
560 |
double extentX = extent.getMinimum(0); |
561 |
double extentY = extent.getMinimum(1); |
562 |
|
563 |
double restX = (extentX / intervalX) % 1; |
564 |
double distX = restX * intervalX;
|
565 |
// double distPixelsX=FLayoutUtilities.fromSheetDistance(distX,atView);
|
566 |
double restY = (extentY / intervalY) % 1; |
567 |
double distY = restY * intervalY;
|
568 |
// double distPixelsY=FLayoutUtilities.fromSheetDistance(distY,atView);
|
569 |
|
570 |
double x = extentX - distX;
|
571 |
// double pixelsX = rView.getMinX()-distPixelsX;
|
572 |
double y = extentY - distY;
|
573 |
// double pixelsY = rView.getMinY()-distPixelsY;
|
574 |
|
575 |
// fframeview.getMapContext().getViewPort().fromMapPoint(extentX,extentY);
|
576 |
// double
|
577 |
// pixelsInterval=FLayoutUtilities.fromSheetDistance(interval,atView);
|
578 |
|
579 |
g.setColor(Color.black);
|
580 |
|
581 |
// Dibuja los m?rgenes
|
582 |
double valueIntervalX =
|
583 |
((extentX / intervalX) - restX) * intervalX - intervalX; |
584 |
x = x - intervalX; |
585 |
double topX = extentX;
|
586 |
// if (showCornerText){
|
587 |
// x+=intervalX;
|
588 |
// topX-=intervalX;
|
589 |
// }
|
590 |
while (x < extent.getMaximum(0)) { |
591 |
if (x > topX) {
|
592 |
Point2D p2 = vp.fromMapPoint(x, extentY);
|
593 |
Point2D p1 = vp.fromMapPoint(x, extent.getMaximum(1)); |
594 |
if (isLine()) {
|
595 |
g.setColor(symbolLine.getColor()); |
596 |
g.setStroke(new BasicStroke((int) (symbolLine |
597 |
.getLineWidth() * factor))); |
598 |
} else {
|
599 |
g.setColor(symbolPoint.getColor()); |
600 |
g.setStroke(new BasicStroke(1)); |
601 |
} |
602 |
// g.setColor(lineColor);
|
603 |
g.drawLine((int) p1.getX(), (int) p1.getY() - 5, |
604 |
(int) p1.getX(), (int) p1.getY()); |
605 |
g.drawLine((int) p2.getX(), (int) p2.getY(), (int) p2.getX(), |
606 |
(int) p2.getY() + 5); |
607 |
TextLayout textaux =
|
608 |
new TextLayout(String.valueOf(valueIntervalX), font, frc); |
609 |
|
610 |
double w = textaux.getBounds().getWidth();
|
611 |
double h = textaux.getBounds().getHeight();
|
612 |
g.setColor(textColor); |
613 |
textaux.draw(g, (int) (p1.getX() - w / 2), |
614 |
(int) (p1.getY() - h) - 5); |
615 |
textaux.draw(g, (int) (p2.getX() - w / 2), |
616 |
(int) (p2.getY() + h * 2) + 5); |
617 |
} |
618 |
valueIntervalX = valueIntervalX + intervalX; |
619 |
x = x + intervalX; |
620 |
} |
621 |
double valueIntervalY =
|
622 |
((extentY / intervalY) - restY) * intervalY - intervalY; |
623 |
y = y - intervalY; |
624 |
double topY = extentY;
|
625 |
// if (showCornerText){
|
626 |
// y+=intervalY;
|
627 |
// topY-=intervalY;
|
628 |
// }
|
629 |
while (y < extent.getMaximum(1)) { |
630 |
if (y > topY) {
|
631 |
Point2D p1 = vp.fromMapPoint(extentX, y);
|
632 |
Point2D p2 = vp.fromMapPoint(extent.getMaximum(0), y); |
633 |
if (isLine()) {
|
634 |
g.setColor(symbolLine.getColor()); |
635 |
g.setStroke(new BasicStroke((int) (symbolLine |
636 |
.getLineWidth() * factor))); |
637 |
} else {
|
638 |
g.setColor(symbolPoint.getColor()); |
639 |
g.setStroke(new BasicStroke(1)); |
640 |
} |
641 |
// g.setColor(lineColor);
|
642 |
g.drawLine((int) p1.getX() - 5, (int) p1.getY(), |
643 |
(int) p1.getX(), (int) p1.getY()); |
644 |
g.drawLine((int) p2.getX(), (int) p2.getY(), |
645 |
(int) p2.getX() + 5, (int) p2.getY()); |
646 |
TextLayout textaux =
|
647 |
new TextLayout(String.valueOf(valueIntervalY), font, frc); |
648 |
double w = textaux.getBounds().getWidth();
|
649 |
double h = textaux.getBounds().getHeight();
|
650 |
g.setColor(textColor); |
651 |
textaux.draw(g, (int) (p1.getX() - w - 10), |
652 |
(int) (p1.getY() + h / 2)); |
653 |
textaux |
654 |
.draw(g, (int) p2.getX() + 10, (int) (p2.getY() + h / 2)); |
655 |
} |
656 |
valueIntervalY = valueIntervalY + intervalY; |
657 |
y = y + intervalY; |
658 |
} |
659 |
if (isLine()) {
|
660 |
g.setColor(symbolLine.getColor()); |
661 |
g.setStroke(new BasicStroke( |
662 |
(int) (symbolLine.getLineWidth() * factor)));
|
663 |
} else {
|
664 |
g.setColor(symbolPoint.getColor()); |
665 |
g.setStroke(new BasicStroke(1)); |
666 |
} |
667 |
// g.setColor(lineColor);
|
668 |
|
669 |
g.draw(rView); |
670 |
|
671 |
x = extentX - distX; |
672 |
y = extentY - distY; |
673 |
|
674 |
if (isLine) { // Dibuja las l?neas. |
675 |
while (x < extent.getMaximum(0)) { |
676 |
Point2D antPoint = vp.fromMapPoint(x, extentY);
|
677 |
if (x > extentX) {
|
678 |
while (y <= extent.getMaximum(1)) { |
679 |
if (y >= extentY) {
|
680 |
Point2D p = vp.fromMapPoint(x, y);
|
681 |
try {
|
682 |
Geometry geom = |
683 |
createLine((int) antPoint.getX(),
|
684 |
(int) antPoint.getY(), (int) p.getX(), |
685 |
(int) p.getY());
|
686 |
geom.invokeOperation(Draw.CODE, doc); |
687 |
} catch (GeometryOperationNotSupportedException e) {
|
688 |
e.printStackTrace(); |
689 |
} catch (GeometryOperationException e) {
|
690 |
e.printStackTrace(); |
691 |
} catch (LocatorException e) {
|
692 |
e.printStackTrace(); |
693 |
} catch (CreateGeometryException e) {
|
694 |
e.printStackTrace(); |
695 |
} |
696 |
antPoint = (Point2D) p.clone();
|
697 |
} |
698 |
|
699 |
y = y + intervalY; |
700 |
} |
701 |
Point2D p = vp.fromMapPoint(x, extent.getMaximum(1)); |
702 |
try {
|
703 |
Geometry geom = |
704 |
createLine((int) antPoint.getX(),
|
705 |
(int) antPoint.getY(), (int) p.getX(), |
706 |
(int) p.getY());
|
707 |
geom.invokeOperation(Draw.CODE, doc); |
708 |
} catch (GeometryOperationNotSupportedException e) {
|
709 |
e.printStackTrace(); |
710 |
} catch (GeometryOperationException e) {
|
711 |
e.printStackTrace(); |
712 |
} catch (LocatorException e) {
|
713 |
e.printStackTrace(); |
714 |
} catch (CreateGeometryException e) {
|
715 |
e.printStackTrace(); |
716 |
} |
717 |
// g.drawLine((int)antPoint.getX(),(int)antPoint.getY(),(int)p.getX(),(int)p.getY());
|
718 |
antPoint = (Point2D) p.clone();
|
719 |
y = extentY - distY; |
720 |
|
721 |
} |
722 |
|
723 |
x = x + intervalX; |
724 |
} |
725 |
while (y <= extent.getMaximum(1)) { |
726 |
Point2D antPoint = vp.fromMapPoint(extentX, y);
|
727 |
if (y > extentY) {
|
728 |
while (x <= extent.getMaximum(0)) { |
729 |
if (x >= extentX) {
|
730 |
Point2D p = vp.fromMapPoint(x, y);
|
731 |
try {
|
732 |
Geometry geom = |
733 |
createLine((int) antPoint.getX(),
|
734 |
(int) antPoint.getY(), (int) p.getX(), |
735 |
(int) p.getY());
|
736 |
geom.invokeOperation(Draw.CODE, doc); |
737 |
} catch (GeometryOperationNotSupportedException e) {
|
738 |
e.printStackTrace(); |
739 |
} catch (GeometryOperationException e) {
|
740 |
e.printStackTrace(); |
741 |
} catch (LocatorException e) {
|
742 |
e.printStackTrace(); |
743 |
} catch (CreateGeometryException e) {
|
744 |
e.printStackTrace(); |
745 |
} |
746 |
// g.drawLine((int)antPoint.getX(),(int)antPoint.getY(),(int)p.getX(),(int)p.getY());
|
747 |
antPoint = p; |
748 |
} |
749 |
x = x + intervalX; |
750 |
} |
751 |
Point2D p = vp.fromMapPoint(extent.getMaximum(0), y); |
752 |
g.drawLine((int) antPoint.getX(), (int) antPoint.getY(), |
753 |
(int) p.getX(), (int) p.getY()); |
754 |
antPoint = (Point2D) p.clone();
|
755 |
x = extentX - distX; |
756 |
} |
757 |
y = y + intervalY; |
758 |
} |
759 |
} else { // Dibuja los puntos |
760 |
while (x <= extent.getMaximum(0)) { |
761 |
if (x > extentX) {
|
762 |
while (y <= extent.getMaximum(1)) { |
763 |
if (y >= extentY) {
|
764 |
Point2D p = vp.fromMapPoint(x, y);
|
765 |
try {
|
766 |
Geometry geom = |
767 |
createPoint((int) p.getX(), (int) p.getY()); |
768 |
geom.invokeOperation(Draw.CODE, doc); |
769 |
} catch (GeometryOperationNotSupportedException e) {
|
770 |
e.printStackTrace(); |
771 |
} catch (GeometryOperationException e) {
|
772 |
e.printStackTrace(); |
773 |
} catch (LocatorException e) {
|
774 |
e.printStackTrace(); |
775 |
} catch (CreateGeometryException e) {
|
776 |
e.printStackTrace(); |
777 |
} |
778 |
// g.drawLine((int)p.getX()-10,(int)p.getY(),(int)p.getX()+10,(int)p.getY());
|
779 |
// g.drawLine((int)p.getX(),(int)p.getY()-10,(int)p.getX(),(int)p.getY()+10);
|
780 |
} |
781 |
y = y + intervalY; |
782 |
} |
783 |
y = extentY - distY; |
784 |
} |
785 |
x = x + intervalX; |
786 |
} |
787 |
|
788 |
} |
789 |
|
790 |
g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), r.y |
791 |
+ (r.height / 2));
|
792 |
} |
793 |
|
794 |
public static void registerPersistent() { |
795 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
796 |
if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) { |
797 |
DynStruct definition = |
798 |
manager.addDefinition(FFrameGrid.class, |
799 |
PERSISTENCE_DEFINITION_NAME, |
800 |
"FFrameGrid persistence definition", null, null); |
801 |
|
802 |
definition |
803 |
.extend(manager |
804 |
.getDefinition(AbstractFFrameViewDependence.PERSISTENCE_DEFINITION_NAME)); |
805 |
|
806 |
definition.addDynFieldObject(SYMBOLLINE_FIELD) |
807 |
.setClassOfValue(ILineSymbol.class).setMandatory(true);
|
808 |
definition.addDynFieldObject(SYMBOLPOINT_FIELD) |
809 |
.setClassOfValue(IMarkerSymbol.class).setMandatory(true);
|
810 |
definition.addDynFieldObject(FONT_FIELD) |
811 |
.setClassOfValue(Font.class).setMandatory(true); |
812 |
definition.addDynFieldDouble(INTERVALX_FIELD).setMandatory(true);
|
813 |
definition.addDynFieldDouble(INTERVALY_FIELD).setMandatory(true);
|
814 |
definition.addDynFieldBoolean(ISLINE_FIELD).setMandatory(true);
|
815 |
definition.addDynFieldInt(FONTSYZE_FIELD).setMandatory(true);
|
816 |
definition.addDynFieldObject(INTERVALY_FIELD) |
817 |
.setClassOfValue(Color.class).setMandatory(true); |
818 |
} |
819 |
} |
820 |
|
821 |
@Override
|
822 |
public void loadFromState(PersistentState state) |
823 |
throws PersistenceException {
|
824 |
super.loadFromState(state);
|
825 |
symbolLine = (ILineSymbol) state.get(SYMBOLLINE_FIELD); |
826 |
symbolPoint = (IMarkerSymbol) state.get(SYMBOLPOINT_FIELD); |
827 |
font = (Font) state.get(FONT_FIELD);
|
828 |
intervalX = state.getDouble(INTERVALX_FIELD); |
829 |
intervalY = state.getDouble(INTERVALY_FIELD); |
830 |
isLine = state.getBoolean(ISLINE_FIELD); |
831 |
sizeFont = state.getInt(FONTSYZE_FIELD); |
832 |
textColor = (Color) state.get(TEXTCOLOR_FIELD);
|
833 |
} |
834 |
|
835 |
@Override
|
836 |
public void saveToState(PersistentState state) throws PersistenceException { |
837 |
super.saveToState(state);
|
838 |
state.set(SYMBOLLINE_FIELD, symbolLine); |
839 |
state.set(SYMBOLPOINT_FIELD, symbolPoint); |
840 |
state.set(FONT_FIELD, font); |
841 |
state.set(INTERVALY_FIELD, intervalY); |
842 |
state.set(ISLINE_FIELD, isLine); |
843 |
state.set(FONTSYZE_FIELD, sizeFont); |
844 |
state.set(TEXTCOLOR_FIELD, textColor); |
845 |
} |
846 |
} |