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