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