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