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