svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / FFrameGrid.java @ 28546
History | View | Annotate | Download (28.5 KB)
1 | 27972 | vcaballero | package com.iver.cit.gvsig.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 javax.print.attribute.PrintRequestAttributeSet; |
||
15 | import javax.print.attribute.standard.PrintQuality; |
||
16 | |||
17 | import org.gvsig.fmap.dal.exception.ReadException; |
||
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.ViewPort; |
||
29 | 28129 | vcaballero | import org.gvsig.fmap.mapcontext.rendering.symbols.ILineSymbol; |
30 | import org.gvsig.fmap.mapcontext.rendering.symbols.IMarkerSymbol; |
||
31 | 27972 | vcaballero | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
32 | import org.gvsig.fmap.mapcontext.rendering.symbols.SimpleLineSymbol; |
||
33 | import org.gvsig.fmap.mapcontext.rendering.symbols.SimpleMarkerSymbol; |
||
34 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory; |
||
35 | import org.gvsig.tools.locator.LocatorException; |
||
36 | |||
37 | import com.iver.andami.PluginServices; |
||
38 | import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
||
39 | import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities; |
||
40 | import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog; |
||
41 | import com.iver.cit.gvsig.project.documents.layout.gui.Layout; |
||
42 | import com.iver.utiles.StringUtilities; |
||
43 | import com.iver.utiles.XMLEntity; |
||
44 | |||
45 | |||
46 | |||
47 | /**
|
||
48 | * FFrame para introducir una cuadr?cula sobre una vista en el Layout.
|
||
49 | *
|
||
50 | * @author Vicente Caballero Navarro
|
||
51 | */
|
||
52 | public class FFrameGrid extends FFrame implements IFFrameViewDependence{ |
||
53 | private static final ViewPort viewPortI=new ViewPort(null); |
||
54 | private FFrameView fframeview;
|
||
55 | private double intervalX=10000; |
||
56 | private double intervalY=10000; |
||
57 | |||
58 | private Color textColor=Color.black; |
||
59 | private boolean isLine; |
||
60 | private int sizeFont=8; |
||
61 | private int dependenceIndex; |
||
62 | private Layout layout;
|
||
63 | // private boolean print=false;
|
||
64 | 28129 | vcaballero | private ILineSymbol symbolLine=new SimpleLineSymbol(); |
65 | private IMarkerSymbol symbolPoint=new SimpleMarkerSymbol(); |
||
66 | 27972 | vcaballero | private Font font=new Font("Arial",Font.PLAIN,sizeFont); |
67 | |||
68 | public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, BufferedImage imgBase) { |
||
69 | // if (print){
|
||
70 | // fframeview.refresh();
|
||
71 | // print=false;
|
||
72 | // }
|
||
73 | DrawOperationContext doc=new DrawOperationContext();
|
||
74 | doc.setGraphics(g); |
||
75 | doc.setViewPort(viewPortI); |
||
76 | doc.setSymbol(symbolLine); |
||
77 | ViewPort vp=fframeview.getMapContext().getViewPort(); |
||
78 | // vp.setAffineTransform(at);
|
||
79 | FontRenderContext frc = g.getFontRenderContext();
|
||
80 | double myScale = at.getScaleX() * 0.0234; //FLayoutUtilities.fromSheetDistance(folio.getAncho(),at)/rv.getWidth(); |
||
81 | int scaledFontSize = (int) (myScale * sizeFont); |
||
82 | Font font=new Font(this.font.getFamily(),this.font.getStyle(),scaledFontSize); |
||
83 | Rectangle2D.Double r = getBoundingBox(at);
|
||
84 | Rectangle2D rView=fframeview.getBoundingBox(at);
|
||
85 | g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), |
||
86 | r.y + (r.height / 2));
|
||
87 | // AffineTransform atView=fframeview.getATMap();
|
||
88 | |||
89 | // vp.setAffineTransform(at);
|
||
90 | Envelope extent=vp.getAdjustedExtent(); |
||
91 | double extentX=extent.getMinimum(0); |
||
92 | double extentY=extent.getMinimum(1); |
||
93 | |||
94 | double restX=(extentX/intervalX) % 1; |
||
95 | double distX=restX*intervalX;
|
||
96 | //double distPixelsX=FLayoutUtilities.fromSheetDistance(distX,atView);
|
||
97 | double restY=(extentY/intervalY) % 1; |
||
98 | double distY=restY*intervalY;
|
||
99 | //double distPixelsY=FLayoutUtilities.fromSheetDistance(distY,atView);
|
||
100 | |||
101 | double x=extentX-distX;
|
||
102 | //double pixelsX = rView.getMinX()-distPixelsX;
|
||
103 | double y=extentY-distY;
|
||
104 | //double pixelsY = rView.getMinY()-distPixelsY;
|
||
105 | |||
106 | //fframeview.getMapContext().getViewPort().fromMapPoint(extentX,extentY);
|
||
107 | //double pixelsInterval=FLayoutUtilities.fromSheetDistance(interval,atView);
|
||
108 | |||
109 | g.setColor(Color.black);
|
||
110 | |||
111 | |||
112 | // Dibuja los m?rgenes
|
||
113 | double valueIntervalX=((extentX/intervalX)-restX) * intervalX-intervalX;
|
||
114 | x=x-intervalX; |
||
115 | double topX=extentX;
|
||
116 | // if (showCornerText){
|
||
117 | // x+=intervalX;
|
||
118 | // topX-=intervalX;
|
||
119 | // }
|
||
120 | while(x<extent.getMaximum(0)){ |
||
121 | if (x>topX) {
|
||
122 | Point2D p2=vp.fromMapPoint(x,extentY);
|
||
123 | Point2D p1=vp.fromMapPoint(x,extent.getMaximum(1)); |
||
124 | if (isLine()){
|
||
125 | g.setColor(symbolLine.getColor()); |
||
126 | g.setStroke(new BasicStroke((int)symbolLine.getLineWidth())); |
||
127 | }else{
|
||
128 | g.setColor(symbolPoint.getColor()); |
||
129 | g.setStroke(new BasicStroke((int)1)); |
||
130 | } |
||
131 | // g.setColor(lineColor);
|
||
132 | g.drawLine((int)p1.getX(),(int)p1.getY()-5,(int)p1.getX(),(int)p1.getY()); |
||
133 | g.drawLine((int)p2.getX(),(int)p2.getY(),(int)p2.getX(),(int)p2.getY()+5); |
||
134 | TextLayout textaux = new TextLayout(String.valueOf(valueIntervalX), |
||
135 | font, frc); |
||
136 | |||
137 | double w=textaux.getBounds().getWidth();
|
||
138 | double h=textaux.getBounds().getHeight();
|
||
139 | g.setColor(textColor); |
||
140 | textaux.draw(g,(int)(p1.getX()-w/2),(int)(p1.getY()-h)-5); |
||
141 | textaux.draw(g,(int)(p2.getX()-w/2),(int)(p2.getY()+h*2)+5); |
||
142 | } |
||
143 | valueIntervalX=valueIntervalX+intervalX; |
||
144 | x=x+intervalX; |
||
145 | } |
||
146 | double valueIntervalY=((extentY/intervalY)-restY) * intervalY-intervalY;
|
||
147 | y=y-intervalY; |
||
148 | double topY=extentY;
|
||
149 | // if (showCornerText){
|
||
150 | // y+=intervalY;
|
||
151 | // topY-=intervalY;
|
||
152 | // }
|
||
153 | while(y<extent.getMaximum(1)){ |
||
154 | if (y>topY) {
|
||
155 | Point2D p1=vp.fromMapPoint(extentX,y);
|
||
156 | Point2D p2=vp.fromMapPoint(extent.getMaximum(0),y); |
||
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((int)1)); |
||
163 | } |
||
164 | // g.setColor(lineColor);
|
||
165 | g.drawLine((int)p1.getX()-5,(int)p1.getY(),(int)p1.getX(),(int)p1.getY()); |
||
166 | g.drawLine((int)p2.getX(),(int)p2.getY(),(int)p2.getX()+5,(int)p2.getY()); |
||
167 | TextLayout textaux = new TextLayout(String.valueOf(valueIntervalY), |
||
168 | font, frc); |
||
169 | double w=textaux.getBounds().getWidth();
|
||
170 | double h=textaux.getBounds().getHeight();
|
||
171 | g.setColor(textColor); |
||
172 | textaux.draw(g,(int)(p1.getX()-w-10),(int)(p1.getY()+h/2)); |
||
173 | textaux.draw(g,(int)p2.getX()+10,(int)(p2.getY()+h/2)); |
||
174 | } |
||
175 | valueIntervalY=valueIntervalY+intervalY; |
||
176 | y=y+intervalY; |
||
177 | } |
||
178 | if (isLine()){
|
||
179 | g.setColor(symbolLine.getColor()); |
||
180 | g.setStroke(new BasicStroke((int)symbolLine.getLineWidth())); |
||
181 | }else{
|
||
182 | g.setColor(symbolPoint.getColor()); |
||
183 | g.setStroke(new BasicStroke((int)1)); |
||
184 | } |
||
185 | // g.setColor(lineColor);
|
||
186 | |||
187 | g.draw(rView); |
||
188 | |||
189 | x = extentX-distX; |
||
190 | y = extentY-distY; |
||
191 | |||
192 | if (isLine) { // Dibuja las l?neas. |
||
193 | while(x<extent.getMaximum(0)){ |
||
194 | Point2D antPoint=vp.fromMapPoint(x,extentY);
|
||
195 | if (x>extentX) {
|
||
196 | while(y<=extent.getMaximum(1)){ |
||
197 | if (y>=extentY) {
|
||
198 | Point2D p=vp.fromMapPoint(x,y);
|
||
199 | try {
|
||
200 | Geometry geom=createLine((int)antPoint.getX(),(int)antPoint.getY(),(int)p.getX(),(int)p.getY()); |
||
201 | geom.invokeOperation(Draw.CODE,doc); |
||
202 | } catch (GeometryOperationNotSupportedException e) {
|
||
203 | e.printStackTrace(); |
||
204 | } catch (GeometryOperationException e) {
|
||
205 | e.printStackTrace(); |
||
206 | } catch (LocatorException e) {
|
||
207 | // TODO Auto-generated catch block
|
||
208 | e.printStackTrace(); |
||
209 | } catch (CreateGeometryException e) {
|
||
210 | // TODO Auto-generated catch block
|
||
211 | e.printStackTrace(); |
||
212 | } |
||
213 | antPoint=(Point2D)p.clone();
|
||
214 | } |
||
215 | |||
216 | y=y+intervalY; |
||
217 | } |
||
218 | Point2D p=vp.fromMapPoint(x,extent.getMaximum(1)); |
||
219 | try {
|
||
220 | Geometry geom=createLine((int)antPoint.getX(),(int)antPoint.getY(),(int)p.getX(),(int)p.getY()); |
||
221 | geom.invokeOperation(Draw.CODE,doc); |
||
222 | } catch (GeometryOperationNotSupportedException e) {
|
||
223 | e.printStackTrace(); |
||
224 | } catch (GeometryOperationException e) {
|
||
225 | e.printStackTrace(); |
||
226 | } catch (LocatorException e) {
|
||
227 | // TODO Auto-generated catch block
|
||
228 | e.printStackTrace(); |
||
229 | } catch (CreateGeometryException e) {
|
||
230 | // TODO Auto-generated catch block
|
||
231 | e.printStackTrace(); |
||
232 | } |
||
233 | // g.drawLine((int)antPoint.getX(),(int)antPoint.getY(),(int)p.getX(),(int)p.getY());
|
||
234 | antPoint=(Point2D)p.clone();
|
||
235 | y=extentY-distY; |
||
236 | |||
237 | } |
||
238 | |||
239 | |||
240 | x=x+intervalX; |
||
241 | } |
||
242 | while(y<=extent.getMaximum(1)){ |
||
243 | Point2D antPoint=vp.fromMapPoint(extentX,y);
|
||
244 | if (y>extentY) {
|
||
245 | while(x<=extent.getMaximum(0)){ |
||
246 | if (x>=extentX) {
|
||
247 | Point2D p=vp.fromMapPoint(x,y);
|
||
248 | try {
|
||
249 | Geometry geom=createLine((int)antPoint.getX(),(int)antPoint.getY(),(int)p.getX(),(int)p.getY()); |
||
250 | geom.invokeOperation(Draw.CODE,doc); |
||
251 | } catch (GeometryOperationNotSupportedException e) {
|
||
252 | e.printStackTrace(); |
||
253 | } catch (GeometryOperationException e) {
|
||
254 | e.printStackTrace(); |
||
255 | } catch (LocatorException e) {
|
||
256 | e.printStackTrace(); |
||
257 | } catch (CreateGeometryException e) {
|
||
258 | e.printStackTrace(); |
||
259 | } |
||
260 | // g.drawLine((int)antPoint.getX(),(int)antPoint.getY(),(int)p.getX(),(int)p.getY());
|
||
261 | antPoint=p; |
||
262 | } |
||
263 | x=x+intervalX; |
||
264 | } |
||
265 | Point2D p=vp.fromMapPoint(extent.getMaximum(0),y); |
||
266 | g.drawLine((int)antPoint.getX(),(int)antPoint.getY(),(int)p.getX(),(int)p.getY()); |
||
267 | antPoint=(Point2D)p.clone();
|
||
268 | x=extentX-distX; |
||
269 | } |
||
270 | y=y+intervalY; |
||
271 | } |
||
272 | } else { //Dibuja los puntos |
||
273 | while(x<=extent.getMaximum(0)){ |
||
274 | if (x>extentX) {
|
||
275 | while(y<=extent.getMaximum(1)){ |
||
276 | if (y>=extentY) {
|
||
277 | Point2D p=vp.fromMapPoint(x,y);
|
||
278 | try {
|
||
279 | Geometry geom=createPoint((int)p.getX(),(int)p.getY()); |
||
280 | geom.invokeOperation(Draw.CODE,doc); |
||
281 | } catch (GeometryOperationNotSupportedException e) {
|
||
282 | e.printStackTrace(); |
||
283 | } catch (GeometryOperationException e) {
|
||
284 | e.printStackTrace(); |
||
285 | } catch (LocatorException e) {
|
||
286 | e.printStackTrace(); |
||
287 | } catch (CreateGeometryException e) {
|
||
288 | e.printStackTrace(); |
||
289 | } |
||
290 | } |
||
291 | y=y+intervalY; |
||
292 | } |
||
293 | y=extentY-distY; |
||
294 | } |
||
295 | x=x+intervalX; |
||
296 | } |
||
297 | |||
298 | } |
||
299 | |||
300 | g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), |
||
301 | r.y + (r.height / 2));
|
||
302 | } |
||
303 | |||
304 | private Geometry createLine(int i, int j, int k, int l) throws LocatorException, CreateGeometryException { |
||
305 | GeneralPathX gpx=new GeneralPathX();
|
||
306 | gpx.moveTo(i,j); |
||
307 | gpx.lineTo(k,l); |
||
308 | return GeometryLocator.getGeometryManager().createCurve(gpx,SUBTYPES.GEOM2D);
|
||
309 | } |
||
310 | private Geometry createPoint(int i, int j) throws LocatorException, CreateGeometryException{ |
||
311 | return GeometryLocator.getGeometryManager().createPoint(i,j,SUBTYPES.GEOM2D);
|
||
312 | } |
||
313 | |||
314 | public XMLEntity getXMLEntity() throws SaveException { |
||
315 | XMLEntity xml = super.getXMLEntity();
|
||
316 | try {
|
||
317 | |||
318 | xml.putProperty("fframegrid","fframegrid"); |
||
319 | xml.addChild(this.symbolLine.getXMLEntity());
|
||
320 | xml.addChild(this.symbolPoint.getXMLEntity());
|
||
321 | // xml.putProperty("showCornerText",this.showCornerText);
|
||
322 | xml.putProperty("familyFont",this.font.getFamily()); |
||
323 | xml.putProperty("styleFont",this.font.getStyle()); |
||
324 | |||
325 | xml.putProperty("intervalX", intervalX);
|
||
326 | xml.putProperty("intervalY", intervalY);
|
||
327 | xml.putProperty("isLine", isLine);
|
||
328 | // xml.putProperty("lineColor", StringUtilities.color2String(lineColor));
|
||
329 | xml.putProperty("sizeFont", sizeFont);
|
||
330 | xml.putProperty("textColor", StringUtilities.color2String(textColor));
|
||
331 | |||
332 | if (fframeview != null) { |
||
333 | Layout layout = fframeview.getLayout(); |
||
334 | IFFrame[] fframes = layout.getLayoutContext().getAllFFrames();
|
||
335 | |||
336 | for (int i = 0; i < fframes.length; i++) { |
||
337 | if (fframeview.equals(fframes[i])) {
|
||
338 | xml.putProperty("index", i);
|
||
339 | break;
|
||
340 | } |
||
341 | } |
||
342 | } |
||
343 | } catch (Exception e) { |
||
344 | throw new SaveException(e, this.getClass().getName()); |
||
345 | } |
||
346 | return xml;
|
||
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 | 28129 | vcaballero | this.symbolLine=(ILineSymbol)SymbologyFactory.createSymbolFromXML(xml.getChild(0),"line"); |
355 | this.symbolPoint=(IMarkerSymbol)SymbologyFactory.createSymbolFromXML(xml.getChild(1),"point"); |
||
356 | 27972 | vcaballero | // 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 | 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(Layout 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 | public ISymbol getSymbolLine() {
|
||
503 | return symbolLine;
|
||
504 | } |
||
505 | |||
506 | public void setSymbolLine(ISymbol symbolLine) { |
||
507 | 28129 | vcaballero | this.symbolLine = (ILineSymbol)symbolLine;
|
508 | 27972 | vcaballero | } |
509 | |||
510 | public ISymbol getSymbolPoint() {
|
||
511 | return symbolPoint;
|
||
512 | } |
||
513 | |||
514 | public void setSymbolPoint(ISymbol symbolPoint) { |
||
515 | 28129 | vcaballero | this.symbolPoint = (IMarkerSymbol)symbolPoint;
|
516 | 27972 | vcaballero | } |
517 | |||
518 | public Font getFont() { |
||
519 | return font;
|
||
520 | } |
||
521 | |||
522 | public void setFont(Font m_font) { |
||
523 | this.font=m_font;
|
||
524 | } |
||
525 | |||
526 | // public void setLineSymbol(ISymbol symbol) {
|
||
527 | // this.symbolLine=symbol;
|
||
528 | //
|
||
529 | // }
|
||
530 | //
|
||
531 | // public void setPointSymbol(ISymbol symbol) {
|
||
532 | // this.symbolPoint=symbol;
|
||
533 | //
|
||
534 | // }
|
||
535 | |||
536 | public int getFontSize() { |
||
537 | return sizeFont;
|
||
538 | } |
||
539 | |||
540 | public IFFrameDialog getPropertyDialog() {
|
||
541 | // TODO Auto-generated method stub
|
||
542 | return null; |
||
543 | } |
||
544 | |||
545 | public void print(Graphics2D g, AffineTransform at, Geometry shape, |
||
546 | 28370 | vcaballero | PrintRequestAttributeSet properties){
|
547 | 27972 | vcaballero | fframeview.refresh(); |
548 | DrawOperationContext doc=new DrawOperationContext();
|
||
549 | doc.setGraphics(g); |
||
550 | doc.setViewPort(viewPortI); |
||
551 | doc.setSymbol(symbolLine); |
||
552 | ViewPort vp=fframeview.getMapContext().getViewPort(); |
||
553 | // vp.setAffineTransform(at);
|
||
554 | FontRenderContext frc = g.getFontRenderContext();
|
||
555 | PrintQuality pq = (PrintQuality) properties.get(PrintQuality.class); |
||
556 | double factor=1; |
||
557 | if (pq.equals(PrintQuality.NORMAL)){ |
||
558 | factor= (double) 300/72; |
||
559 | }else if (pq.equals(PrintQuality.HIGH)){ |
||
560 | factor= (double) 600/72; |
||
561 | }else if (pq.equals(PrintQuality.DRAFT)){ |
||
562 | // unitFactor *= 72; (which is the same than doing nothing)
|
||
563 | } |
||
564 | sizeFont*=factor; |
||
565 | double myScale = at.getScaleX() * 0.0234; //FLayoutUtilities.fromSheetDistance(folio.getAncho(),at)/rv.getWidth(); |
||
566 | int scaledFontSize = (int) (myScale * sizeFont); |
||
567 | Font font=new Font(this.font.getFamily(),this.font.getStyle(),scaledFontSize); |
||
568 | Rectangle2D.Double r = getBoundingBox(at);
|
||
569 | Rectangle2D rView=fframeview.getBoundingBox(at);
|
||
570 | g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), |
||
571 | r.y + (r.height / 2));
|
||
572 | // AffineTransform atView=fframeview.getATMap();
|
||
573 | |||
574 | // vp.setAffineTransform(at);
|
||
575 | Envelope extent=vp.getAdjustedExtent(); |
||
576 | double extentX=extent.getMinimum(0); |
||
577 | double extentY=extent.getMinimum(1); |
||
578 | |||
579 | double restX=(extentX/intervalX) % 1; |
||
580 | double distX=restX*intervalX;
|
||
581 | //double distPixelsX=FLayoutUtilities.fromSheetDistance(distX,atView);
|
||
582 | double restY=(extentY/intervalY) % 1; |
||
583 | double distY=restY*intervalY;
|
||
584 | //double distPixelsY=FLayoutUtilities.fromSheetDistance(distY,atView);
|
||
585 | |||
586 | double x=extentX-distX;
|
||
587 | //double pixelsX = rView.getMinX()-distPixelsX;
|
||
588 | double y=extentY-distY;
|
||
589 | //double pixelsY = rView.getMinY()-distPixelsY;
|
||
590 | |||
591 | //fframeview.getMapContext().getViewPort().fromMapPoint(extentX,extentY);
|
||
592 | //double pixelsInterval=FLayoutUtilities.fromSheetDistance(interval,atView);
|
||
593 | |||
594 | g.setColor(Color.black);
|
||
595 | |||
596 | |||
597 | // Dibuja los m?rgenes
|
||
598 | double valueIntervalX=((extentX/intervalX)-restX) * intervalX-intervalX;
|
||
599 | x=x-intervalX; |
||
600 | double topX=extentX;
|
||
601 | // if (showCornerText){
|
||
602 | // x+=intervalX;
|
||
603 | // topX-=intervalX;
|
||
604 | // }
|
||
605 | while(x<extent.getMaximum(0)){ |
||
606 | if (x>topX) {
|
||
607 | Point2D p2=vp.fromMapPoint(x,extentY);
|
||
608 | Point2D p1=vp.fromMapPoint(x,extent.getMaximum(1)); |
||
609 | if (isLine()){
|
||
610 | g.setColor(symbolLine.getColor()); |
||
611 | g.setStroke(new BasicStroke((int)(symbolLine.getLineWidth()*factor))); |
||
612 | }else{
|
||
613 | g.setColor(symbolPoint.getColor()); |
||
614 | g.setStroke(new BasicStroke((int)1)); |
||
615 | } |
||
616 | // g.setColor(lineColor);
|
||
617 | g.drawLine((int)p1.getX(),(int)p1.getY()-5,(int)p1.getX(),(int)p1.getY()); |
||
618 | g.drawLine((int)p2.getX(),(int)p2.getY(),(int)p2.getX(),(int)p2.getY()+5); |
||
619 | TextLayout textaux = new TextLayout(String.valueOf(valueIntervalX), |
||
620 | font, frc); |
||
621 | |||
622 | double w=textaux.getBounds().getWidth();
|
||
623 | double h=textaux.getBounds().getHeight();
|
||
624 | g.setColor(textColor); |
||
625 | textaux.draw(g,(int)(p1.getX()-w/2),(int)(p1.getY()-h)-5); |
||
626 | textaux.draw(g,(int)(p2.getX()-w/2),(int)(p2.getY()+h*2)+5); |
||
627 | } |
||
628 | valueIntervalX=valueIntervalX+intervalX; |
||
629 | x=x+intervalX; |
||
630 | } |
||
631 | double valueIntervalY=((extentY/intervalY)-restY) * intervalY-intervalY;
|
||
632 | y=y-intervalY; |
||
633 | double topY=extentY;
|
||
634 | // if (showCornerText){
|
||
635 | // y+=intervalY;
|
||
636 | // topY-=intervalY;
|
||
637 | // }
|
||
638 | while(y<extent.getMaximum(1)){ |
||
639 | if (y>topY) {
|
||
640 | Point2D p1=vp.fromMapPoint(extentX,y);
|
||
641 | Point2D p2=vp.fromMapPoint(extent.getMaximum(0),y); |
||
642 | if (isLine()){
|
||
643 | g.setColor(symbolLine.getColor()); |
||
644 | g.setStroke(new BasicStroke((int)(symbolLine.getLineWidth()*factor))); |
||
645 | }else{
|
||
646 | g.setColor(symbolPoint.getColor()); |
||
647 | g.setStroke(new BasicStroke((int)1)); |
||
648 | } |
||
649 | // g.setColor(lineColor);
|
||
650 | g.drawLine((int)p1.getX()-5,(int)p1.getY(),(int)p1.getX(),(int)p1.getY()); |
||
651 | g.drawLine((int)p2.getX(),(int)p2.getY(),(int)p2.getX()+5,(int)p2.getY()); |
||
652 | TextLayout textaux = new TextLayout(String.valueOf(valueIntervalY), |
||
653 | font, frc); |
||
654 | double w=textaux.getBounds().getWidth();
|
||
655 | double h=textaux.getBounds().getHeight();
|
||
656 | g.setColor(textColor); |
||
657 | textaux.draw(g,(int)(p1.getX()-w-10),(int)(p1.getY()+h/2)); |
||
658 | textaux.draw(g,(int)p2.getX()+10,(int)(p2.getY()+h/2)); |
||
659 | } |
||
660 | valueIntervalY=valueIntervalY+intervalY; |
||
661 | y=y+intervalY; |
||
662 | } |
||
663 | if (isLine()){
|
||
664 | g.setColor(symbolLine.getColor()); |
||
665 | g.setStroke(new BasicStroke((int)(symbolLine.getLineWidth()*factor))); |
||
666 | }else{
|
||
667 | g.setColor(symbolPoint.getColor()); |
||
668 | g.setStroke(new BasicStroke((int)1)); |
||
669 | } |
||
670 | // g.setColor(lineColor);
|
||
671 | |||
672 | g.draw(rView); |
||
673 | |||
674 | x = extentX-distX; |
||
675 | y = extentY-distY; |
||
676 | |||
677 | if (isLine) { // Dibuja las l?neas. |
||
678 | while(x<extent.getMaximum(0)){ |
||
679 | Point2D antPoint=vp.fromMapPoint(x,extentY);
|
||
680 | if (x>extentX) {
|
||
681 | while(y<=extent.getMaximum(1)){ |
||
682 | if (y>=extentY) {
|
||
683 | Point2D p=vp.fromMapPoint(x,y);
|
||
684 | try{
|
||
685 | Geometry geom=createLine((int)antPoint.getX(),(int)antPoint.getY(),(int)p.getX(),(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=createLine((int)antPoint.getX(),(int)antPoint.getY(),(int)p.getX(),(int)p.getY()); |
||
704 | geom.invokeOperation(Draw.CODE,doc); |
||
705 | } catch (GeometryOperationNotSupportedException e) {
|
||
706 | e.printStackTrace(); |
||
707 | } catch (GeometryOperationException e) {
|
||
708 | e.printStackTrace(); |
||
709 | } catch (LocatorException e) {
|
||
710 | e.printStackTrace(); |
||
711 | } catch (CreateGeometryException e) {
|
||
712 | e.printStackTrace(); |
||
713 | } |
||
714 | // g.drawLine((int)antPoint.getX(),(int)antPoint.getY(),(int)p.getX(),(int)p.getY());
|
||
715 | antPoint=(Point2D)p.clone();
|
||
716 | y=extentY-distY; |
||
717 | |||
718 | } |
||
719 | |||
720 | |||
721 | x=x+intervalX; |
||
722 | } |
||
723 | while(y<=extent.getMaximum(1)){ |
||
724 | Point2D antPoint=vp.fromMapPoint(extentX,y);
|
||
725 | if (y>extentY) {
|
||
726 | while(x<=extent.getMaximum(0)){ |
||
727 | if (x>=extentX) {
|
||
728 | Point2D p=vp.fromMapPoint(x,y);
|
||
729 | try{
|
||
730 | Geometry geom=createLine((int)antPoint.getX(),(int)antPoint.getY(),(int)p.getX(),(int)p.getY()); |
||
731 | geom.invokeOperation(Draw.CODE,doc); |
||
732 | } catch (GeometryOperationNotSupportedException e) {
|
||
733 | e.printStackTrace(); |
||
734 | } catch (GeometryOperationException e) {
|
||
735 | e.printStackTrace(); |
||
736 | } catch (LocatorException e) {
|
||
737 | e.printStackTrace(); |
||
738 | } catch (CreateGeometryException e) {
|
||
739 | e.printStackTrace(); |
||
740 | } |
||
741 | // g.drawLine((int)antPoint.getX(),(int)antPoint.getY(),(int)p.getX(),(int)p.getY());
|
||
742 | antPoint=p; |
||
743 | } |
||
744 | x=x+intervalX; |
||
745 | } |
||
746 | Point2D p=vp.fromMapPoint(extent.getMaximum(0),y); |
||
747 | g.drawLine((int)antPoint.getX(),(int)antPoint.getY(),(int)p.getX(),(int)p.getY()); |
||
748 | antPoint=(Point2D)p.clone();
|
||
749 | x=extentX-distX; |
||
750 | } |
||
751 | y=y+intervalY; |
||
752 | } |
||
753 | } else { //Dibuja los puntos |
||
754 | while(x<=extent.getMaximum(0)){ |
||
755 | if (x>extentX) {
|
||
756 | while(y<=extent.getMaximum(1)){ |
||
757 | if (y>=extentY) {
|
||
758 | Point2D p=vp.fromMapPoint(x,y);
|
||
759 | try{
|
||
760 | Geometry geom=createPoint((int)p.getX(),(int)p.getY()); |
||
761 | geom.invokeOperation(Draw.CODE,doc); |
||
762 | } catch (GeometryOperationNotSupportedException e) {
|
||
763 | e.printStackTrace(); |
||
764 | } catch (GeometryOperationException e) {
|
||
765 | e.printStackTrace(); |
||
766 | } catch (LocatorException e) {
|
||
767 | e.printStackTrace(); |
||
768 | } catch (CreateGeometryException e) {
|
||
769 | e.printStackTrace(); |
||
770 | } |
||
771 | // g.drawLine((int)p.getX()-10,(int)p.getY(),(int)p.getX()+10,(int)p.getY());
|
||
772 | // g.drawLine((int)p.getX(),(int)p.getY()-10,(int)p.getX(),(int)p.getY()+10);
|
||
773 | } |
||
774 | y=y+intervalY; |
||
775 | } |
||
776 | y=extentY-distY; |
||
777 | } |
||
778 | x=x+intervalX; |
||
779 | } |
||
780 | |||
781 | } |
||
782 | |||
783 | g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), |
||
784 | r.y + (r.height / 2));
|
||
785 | |||
786 | } |
||
787 | } |