svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / FLayoutDraw.java @ 11358
History | View | Annotate | Download (29.2 KB)
1 | 7304 | caballero | /*
|
---|---|---|---|
2 | * Created on 27-sep-2004
|
||
3 | *
|
||
4 | */
|
||
5 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
6 | *
|
||
7 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
8 | *
|
||
9 | * This program is free software; you can redistribute it and/or
|
||
10 | * modify it under the terms of the GNU General Public License
|
||
11 | * as published by the Free Software Foundation; either version 2
|
||
12 | * of the License, or (at your option) any later version.
|
||
13 | *
|
||
14 | * This program is distributed in the hope that it will be useful,
|
||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
17 | * GNU General Public License for more details.
|
||
18 | *
|
||
19 | * You should have received a copy of the GNU General Public License
|
||
20 | * along with this program; if not, write to the Free Software
|
||
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
22 | *
|
||
23 | * For more information, contact:
|
||
24 | *
|
||
25 | * Generalitat Valenciana
|
||
26 | * Conselleria d'Infraestructures i Transport
|
||
27 | * Av. Blasco Ib??ez, 50
|
||
28 | * 46010 VALENCIA
|
||
29 | * SPAIN
|
||
30 | *
|
||
31 | * +34 963862235
|
||
32 | * gvsig@gva.es
|
||
33 | * www.gvsig.gva.es
|
||
34 | *
|
||
35 | * or
|
||
36 | *
|
||
37 | * IVER T.I. S.A
|
||
38 | * Salamanca 50
|
||
39 | * 46005 Valencia
|
||
40 | * Spain
|
||
41 | *
|
||
42 | * +34 963163400
|
||
43 | * dac@iver.es
|
||
44 | */
|
||
45 | package com.iver.cit.gvsig.project.documents.layout; |
||
46 | |||
47 | import java.awt.Color; |
||
48 | import java.awt.Component; |
||
49 | import java.awt.Graphics2D; |
||
50 | import java.awt.geom.AffineTransform; |
||
51 | import java.awt.geom.Point2D; |
||
52 | import java.awt.geom.Rectangle2D; |
||
53 | import java.awt.image.BufferedImage; |
||
54 | import java.awt.print.PageFormat; |
||
55 | import java.awt.print.PrinterException; |
||
56 | import java.io.BufferedOutputStream; |
||
57 | import java.io.File; |
||
58 | import java.io.FileOutputStream; |
||
59 | import java.io.IOException; |
||
60 | import java.io.OutputStream; |
||
61 | |||
62 | import javax.print.Doc; |
||
63 | import javax.print.DocFlavor; |
||
64 | import javax.print.DocPrintJob; |
||
65 | import javax.print.PrintException; |
||
66 | import javax.print.SimpleDoc; |
||
67 | import javax.print.StreamPrintService; |
||
68 | import javax.print.StreamPrintServiceFactory; |
||
69 | import javax.print.attribute.PrintRequestAttributeSet; |
||
70 | import javax.swing.JOptionPane; |
||
71 | |||
72 | 10626 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
73 | 7304 | caballero | import com.iver.andami.PluginServices; |
74 | import com.iver.cit.gvsig.Print; |
||
75 | import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame; |
||
76 | 9392 | caballero | import com.iver.cit.gvsig.project.documents.layout.gui.Layout; |
77 | 7304 | caballero | import com.lowagie.text.Document; |
78 | import com.lowagie.text.DocumentException; |
||
79 | import com.lowagie.text.pdf.PdfContentByte; |
||
80 | import com.lowagie.text.pdf.PdfWriter; |
||
81 | |||
82 | |||
83 | /**
|
||
84 | * Clase que implementa los m?todos del Layout que dibujan sobre el Graphics.
|
||
85 | *
|
||
86 | * @author Vicente Caballero Navarro
|
||
87 | */
|
||
88 | public class FLayoutDraw { |
||
89 | private Layout layout;
|
||
90 | |||
91 | /**
|
||
92 | * Crea un nuevo FLayoutDraw.
|
||
93 | *
|
||
94 | * @param l Referencia al Layout.
|
||
95 | */
|
||
96 | public FLayoutDraw(Layout l) {
|
||
97 | layout = l; |
||
98 | } |
||
99 | |||
100 | /**
|
||
101 | * M?todo para dibujar el Layout y modificar la matriz de transformaci?n a
|
||
102 | * partir del tama?o en pixels que tenga rect y el formato de papel
|
||
103 | * seleccionado.
|
||
104 | *
|
||
105 | * @param g2
|
||
106 | * @param imgBase Si es null, est?s imprimiendo. Si no, la usas para el
|
||
107 | * c?digo de optimizaci?n.
|
||
108 | *
|
||
109 | 10661 | caballero | * @throws ReadDriverException
|
110 | 7304 | caballero | */
|
111 | public void drawLayout(Graphics2D g2, BufferedImage imgBase) |
||
112 | 10626 | caballero | throws ReadDriverException {
|
113 | 9392 | caballero | layout.getLayoutControl().setCancelDrawing(false);
|
114 | 7304 | caballero | double scale = 0; |
115 | 9392 | caballero | scale = layout.getLayoutControl().getRect().height / layout.getLayoutContext().getAtributes().m_sizePaper.getAlto() * 1;
|
116 | 7304 | caballero | AffineTransform escalado = new AffineTransform(); |
117 | AffineTransform translacion = new AffineTransform(); |
||
118 | 9392 | caballero | translacion.setToTranslation(layout.getLayoutControl().getRect().getMinX(), |
119 | layout.getLayoutControl().getRect().getMinY()); |
||
120 | 7304 | caballero | escalado.setToScale(scale, scale); |
121 | 9392 | caballero | layout.getLayoutControl().getAT().setToIdentity(); |
122 | layout.getLayoutControl().getAT().concatenate(translacion); |
||
123 | layout.getLayoutControl().getAT().concatenate(escalado); |
||
124 | layout.getLayoutContext().getAtributes().setDistanceUnitX(layout.getLayoutControl().getRect()); |
||
125 | layout.getLayoutContext().getAtributes().setDistanceUnitY(layout.getLayoutControl().getRect()); |
||
126 | IFFrame[] fframes=layout.getLayoutContext().getFFrames();
|
||
127 | 7304 | caballero | for (int i = 0; i < fframes.length; i++) { |
128 | IFFrame f = fframes[i]; |
||
129 | 9593 | caballero | //original, lento (NO MAC)
|
130 | 9392 | caballero | f.draw(g2, layout.getLayoutControl().getAT(), layout.getLayoutControl().getVisibleRect(),imgBase); |
131 | 7304 | caballero | // ESTILO MAC
|
132 | /* if (f instanceof FFrameView)
|
||
133 | {
|
||
134 | FFrameView fframe = (FFrameView) f;
|
||
135 | 9392 | caballero | BufferedImage img = new BufferedImage((int) layout.getLayoutControl().getWidth(),
|
136 | (int) layout.getLayoutControl().getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||
137 | 7304 | caballero | |
138 | |||
139 | 9392 | caballero | fframe.draw(img.createGraphics(), layout.getLayoutControl().getAT(), layout.getLayoutControl().getVisibleRect(), imgBase);
|
140 | g2.drawImage(img, 0, 0, layout.getLayoutControl());
|
||
141 | 7304 | caballero | fframe.setBufferedImage(img);
|
142 | }
|
||
143 | else
|
||
144 | {
|
||
145 | 9392 | caballero | f.draw(g2, layout.getLayoutControl().getAT(), layout.getLayoutControl().getVisibleRect(),imgBase);
|
146 | 7304 | caballero | } */
|
147 | |||
148 | // Dibuja el s?mbolo de que contiene un tag.
|
||
149 | 9303 | caballero | if ((f.getTag() != null) && (layout.isShowIconTag())) { |
150 | 7304 | caballero | f.drawSymbolTag(g2); |
151 | } |
||
152 | } |
||
153 | |||
154 | if (!(fframes.length==0)) { |
||
155 | 9392 | caballero | layout.getLayoutControl().setStatus(LayoutControl.ACTUALIZADO); |
156 | 7304 | caballero | } else {
|
157 | 9392 | caballero | layout.getLayoutControl().setStatus(LayoutControl.DESACTUALIZADO); |
158 | 7304 | caballero | } |
159 | } |
||
160 | |||
161 | /**
|
||
162 | * Dibuja sobre un Graphics2D el rect?ngulo que representa al folio.
|
||
163 | *
|
||
164 | * @param g Graphics2D
|
||
165 | */
|
||
166 | public void drawRectangle(Graphics2D g) { |
||
167 | 10007 | caballero | double unidadesX = layout.getLayoutContext().getAtributes().getNumUnitsX();
|
168 | double unidadesY = layout.getLayoutContext().getAtributes().getNumUnitsY();
|
||
169 | 7304 | caballero | |
170 | if ((unidadesX == 0) && (unidadesY == 0)) { |
||
171 | return;
|
||
172 | } |
||
173 | |||
174 | g.setColor(Color.darkGray);
|
||
175 | |||
176 | 9392 | caballero | Rectangle2D.Double rectBig = new Rectangle2D.Double(layout.getLayoutControl().getRect().x, |
177 | layout.getLayoutControl().getRect().y, layout.getLayoutControl().getRect().width, |
||
178 | layout.getLayoutControl().getRect().height); |
||
179 | 7304 | caballero | |
180 | g.fill3DRect((int) rectBig.x + 7, (int) rectBig.y + 7, |
||
181 | (int) rectBig.width, (int) rectBig.height, true); |
||
182 | |||
183 | Rectangle2D.Double r = new Rectangle2D.Double(); |
||
184 | |||
185 | 9392 | caballero | if (layout.getLayoutContext().getAtributes().isMargin()) {
|
186 | r = new Rectangle2D.Double((layout.getLayoutControl().getRect().x + |
||
187 | 7304 | caballero | FLayoutUtilities.fromSheetDistance( |
188 | 9392 | caballero | layout.getLayoutContext().getAtributes().m_area[2], layout.getLayoutControl().getAT())),
|
189 | (layout.getLayoutControl().getRect().y + |
||
190 | 7304 | caballero | FLayoutUtilities.fromSheetDistance( |
191 | 9392 | caballero | layout.getLayoutContext().getAtributes().m_area[0], layout.getLayoutControl().getAT())),
|
192 | (layout.getLayoutControl().getRect().width - |
||
193 | FLayoutUtilities.fromSheetDistance(layout.getLayoutContext().getAtributes().m_area[2] +
|
||
194 | layout.getLayoutContext().getAtributes().m_area[3], layout.getLayoutControl().getAT())),
|
||
195 | (layout.getLayoutControl().getRect().height - |
||
196 | FLayoutUtilities.fromSheetDistance(layout.getLayoutContext().getAtributes().m_area[0] +
|
||
197 | layout.getLayoutContext().getAtributes().m_area[1], layout.getLayoutControl().getAT())));
|
||
198 | 7304 | caballero | } else {
|
199 | 9392 | caballero | r.setRect(layout.getLayoutControl().getRect()); |
200 | 7304 | caballero | } |
201 | |||
202 | g.setColor(Color.white);
|
||
203 | 9392 | caballero | g.fill(layout.getLayoutControl().getRect()); |
204 | 7304 | caballero | |
205 | g.setColor(Color.darkGray);
|
||
206 | 9392 | caballero | g.drawRect((int) layout.getLayoutControl().getRect().getMinX(),
|
207 | (int) layout.getLayoutControl().getRect().getMinY(),
|
||
208 | (int) layout.getLayoutControl().getRect().getWidth(),
|
||
209 | (int) layout.getLayoutControl().getRect().getHeight());
|
||
210 | 7304 | caballero | |
211 | 9392 | caballero | if (layout.getLayoutContext().getAtributes().isMargin()) {
|
212 | 7304 | caballero | g.setColor(Color.black);
|
213 | |||
214 | g.drawRect((int) r.x, (int) r.y, (int) r.width, (int) r.height); |
||
215 | } |
||
216 | } |
||
217 | |||
218 | /**
|
||
219 | * DOCUMENT ME!
|
||
220 | *
|
||
221 | * @param g DOCUMENT ME!
|
||
222 | */
|
||
223 | public void drawGrid(Graphics2D g) { |
||
224 | int unidadesMin = 6; |
||
225 | 10851 | caballero | double unidadesX = layout.getLayoutContext().getAtributes().getUnitInPixelsX();
|
226 | double unidadesY = layout.getLayoutContext().getAtributes().getUnitInPixelsY();
|
||
227 | 7304 | caballero | |
228 | Rectangle2D.Double r = new Rectangle2D.Double(); |
||
229 | |||
230 | 9392 | caballero | if (layout.getLayoutContext().getAtributes().isMargin()) {
|
231 | r = new Rectangle2D.Double((layout.getLayoutControl().getRect().x + |
||
232 | 7304 | caballero | FLayoutUtilities.fromSheetDistance( |
233 | 9392 | caballero | layout.getLayoutContext().getAtributes().m_area[2], layout.getLayoutControl().getAT())),
|
234 | (layout.getLayoutControl().getRect().y + |
||
235 | 7304 | caballero | FLayoutUtilities.fromSheetDistance( |
236 | 9392 | caballero | layout.getLayoutContext().getAtributes().m_area[0], layout.getLayoutControl().getAT())),
|
237 | (layout.getLayoutControl().getRect().width - |
||
238 | FLayoutUtilities.fromSheetDistance(layout.getLayoutContext().getAtributes().m_area[2] +
|
||
239 | layout.getLayoutContext().getAtributes().m_area[3], layout.getLayoutControl().getAT())),
|
||
240 | (layout.getLayoutControl().getRect().height - |
||
241 | FLayoutUtilities.fromSheetDistance(layout.getLayoutContext().getAtributes().m_area[0] +
|
||
242 | layout.getLayoutContext().getAtributes().m_area[1], layout.getLayoutControl().getAT())));
|
||
243 | 7304 | caballero | } else {
|
244 | 9392 | caballero | r.setRect(layout.getLayoutControl().getRect()); |
245 | 7304 | caballero | } |
246 | 10851 | caballero | if ((unidadesX == 0) && (unidadesY == 0)) { |
247 | return;
|
||
248 | } |
||
249 | 7304 | caballero | g.setColor(Color.darkGray);
|
250 | |||
251 | if (((unidadesX > unidadesMin) || (unidadesY > unidadesMin)) &&
|
||
252 | 9392 | caballero | layout.getLayoutContext().isGridVisible()) { |
253 | 7304 | caballero | double ax = r.getMinX();
|
254 | double ay;
|
||
255 | |||
256 | while (ax < (r.getMaxX())) {
|
||
257 | ay = (r.getMinY()); |
||
258 | |||
259 | while (ay < (r.getMaxY())) {
|
||
260 | g.drawLine((int) ax, (int) ay, (int) ax, (int) ay); |
||
261 | ay = ay + unidadesY; |
||
262 | } |
||
263 | |||
264 | ax = ax + unidadesX; |
||
265 | } |
||
266 | } |
||
267 | } |
||
268 | |||
269 | /**
|
||
270 | * Dibuja sobre el graphics2d las reglas.
|
||
271 | *
|
||
272 | * @param g graphics2d sobre el que se dibuja.
|
||
273 | * @param color Color de la regla.
|
||
274 | */
|
||
275 | public void drawRuler(Graphics2D g, Color color) { |
||
276 | 9392 | caballero | if (layout.getLayoutContext().getRuler()) {
|
277 | 7304 | caballero | int ini = 10; |
278 | int w = 30; |
||
279 | int wi = 16; |
||
280 | |||
281 | g.setColor(new Color(250, 255, 250, 180)); |
||
282 | 9392 | caballero | g.fillRect(ini, w, wi, layout.getLayoutControl().getHeight() - w); |
283 | g.fillRect(w, ini, layout.getLayoutControl().getWidth() - w, wi); |
||
284 | 7304 | caballero | |
285 | g.setColor(new Color(100, 155, 150, 180)); |
||
286 | 9392 | caballero | g.fillRect(w, ini, (int) layout.getLayoutControl().getRect().x - w, wi);
|
287 | g.fillRect((int) layout.getLayoutControl().getRect().getMaxX(), ini,
|
||
288 | layout.getLayoutControl().getWidth() - (int) layout.getLayoutControl().getRect().getMaxX(), wi);
|
||
289 | 7304 | caballero | |
290 | 9392 | caballero | g.fillRect(ini, w, wi, (int) layout.getLayoutControl().getRect().y - w);
|
291 | g.fillRect(ini, (int) layout.getLayoutControl().getRect().getMaxY(), wi,
|
||
292 | layout.getLayoutControl().getHeight() - (int) layout.getLayoutControl().getRect().getMaxY());
|
||
293 | 7304 | caballero | |
294 | 9392 | caballero | if (layout.getLayoutContext().getAtributes().isMargin()) {
|
295 | 7304 | caballero | g.setColor(new Color(50, 55, 50, 180)); |
296 | 9392 | caballero | g.fillRect((int) layout.getLayoutControl().getRect().x, ini,
|
297 | 7304 | caballero | (int) FLayoutUtilities.fromSheetDistance(
|
298 | 9392 | caballero | layout.getLayoutContext().getAtributes().m_area[2], layout.getLayoutControl().getAT()), wi);
|
299 | g.fillRect((int) layout.getLayoutControl().getRect().getMaxX() -
|
||
300 | 7304 | caballero | (int) FLayoutUtilities.fromSheetDistance(
|
301 | 9392 | caballero | layout.getLayoutContext().getAtributes().m_area[3], layout.getLayoutControl().getAT()), ini,
|
302 | 7304 | caballero | (int) FLayoutUtilities.fromSheetDistance(
|
303 | 9392 | caballero | layout.getLayoutContext().getAtributes().m_area[3], layout.getLayoutControl().getAT()), wi);
|
304 | 7304 | caballero | |
305 | 9392 | caballero | g.fillRect(ini, (int) layout.getLayoutControl().getRect().y, wi,
|
306 | 7304 | caballero | (int) FLayoutUtilities.fromSheetDistance(
|
307 | 9392 | caballero | layout.getLayoutContext().getAtributes().m_area[0], layout.getLayoutControl().getAT()));
|
308 | 7304 | caballero | g.fillRect(ini, |
309 | 9392 | caballero | (int) layout.getLayoutControl().getRect().getMaxY() -
|
310 | 7304 | caballero | (int) FLayoutUtilities.fromSheetDistance(
|
311 | 9392 | caballero | layout.getLayoutContext().getAtributes().m_area[1], layout.getLayoutControl().getAT()), wi,
|
312 | 7304 | caballero | (int) FLayoutUtilities.fromSheetDistance(
|
313 | 9392 | caballero | layout.getLayoutContext().getAtributes().m_area[1], layout.getLayoutControl().getAT()));
|
314 | 7304 | caballero | } |
315 | |||
316 | g.setColor(color); |
||
317 | 9392 | caballero | g.drawLine(w, wi + ini, layout.getLayoutControl().getWidth(), wi + ini); |
318 | g.drawLine(w, ini, layout.getLayoutControl().getWidth(), ini); |
||
319 | g.drawLine(ini, w, ini, layout.getLayoutControl().getHeight()); |
||
320 | g.drawLine(wi + ini, w, wi + ini, layout.getLayoutControl().getHeight()); |
||
321 | 7304 | caballero | |
322 | 9392 | caballero | drawLineY(g, 5, 12, 22, layout.getLayoutControl().getRect().y, 0); |
323 | drawLineX(g, 5, 12, 22, layout.getLayoutControl().getRect().x, 0); |
||
324 | 7304 | caballero | |
325 | 9392 | caballero | if (FLayoutUtilities.fromSheetDistance(1, layout.getLayoutControl().getAT()) > 15) { |
326 | drawLineY(g, 1, 12, 22, layout.getLayoutControl().getRect().y, 0); |
||
327 | drawLineX(g, 1, 12, 22, layout.getLayoutControl().getRect().x, 0); |
||
328 | 7304 | caballero | |
329 | 9392 | caballero | if (FLayoutUtilities.fromSheetDistance(1, layout.getLayoutControl().getAT()) > 25) { |
330 | drawLineY(g, 1, 18, 22, layout.getLayoutControl().getRect().y, 0.5); |
||
331 | drawLineY(g, 0.1, 21, 22, layout.getLayoutControl().getRect().y, 0); |
||
332 | drawLineX(g, 1, 18, 22, layout.getLayoutControl().getRect().x, 0.5); |
||
333 | drawLineX(g, 0.1, 21, 22, layout.getLayoutControl().getRect().x, 0); |
||
334 | 7304 | caballero | } |
335 | } |
||
336 | } |
||
337 | } |
||
338 | |||
339 | /**
|
||
340 | * Dibuja sobre el graphics2d las l?neas verticales que representan a las
|
||
341 | * unidades de medida.
|
||
342 | *
|
||
343 | * @param g Graphics2d sobre el que se dibuja.
|
||
344 | * @param dist distancia en cent?metros de una l?nea a otra.
|
||
345 | * @param init inicio de la l?nea.
|
||
346 | * @param end fin de la l?nea.
|
||
347 | * @param y rect?ngulo, dentro del cual se dibujan las l?neas.
|
||
348 | * @param desp Desplazamiento.
|
||
349 | */
|
||
350 | private void drawLineY(Graphics2D g, double dist, int init, int end, |
||
351 | double y, double desp) { |
||
352 | 9392 | caballero | double distY = FLayoutUtilities.fromSheetDistance(dist, layout.getLayoutControl().getAT());
|
353 | 7304 | caballero | double rota = Math.toRadians(90); |
354 | |||
355 | if (distY > 4) { |
||
356 | double despY = FLayoutUtilities.fromSheetDistance(desp,
|
||
357 | 9392 | caballero | layout.getLayoutControl().getAT()); |
358 | 7304 | caballero | |
359 | double posUnitY = y + despY;
|
||
360 | double posUnitYNeg = posUnitY;
|
||
361 | int num = 0; |
||
362 | double iniY = 40; |
||
363 | Point2D.Double pfin = FLayoutUtilities.fromSheetPoint(new Point2D.Double( |
||
364 | 9392 | caballero | layout.getLayoutControl().getWidth(), layout.getLayoutControl().getHeight()), layout.getLayoutControl().getAT()); |
365 | 7304 | caballero | |
366 | while (posUnitY < (pfin.y - 5)) { |
||
367 | posUnitYNeg -= distY; |
||
368 | |||
369 | if (distY > 16) { |
||
370 | if (init == 12) { |
||
371 | if (posUnitY > iniY) {
|
||
372 | g.rotate(-rota, 20, posUnitY - 12); |
||
373 | g.drawString(String.valueOf(num), 10, |
||
374 | (int) posUnitY - 12); |
||
375 | g.rotate(rota, 20, posUnitY - 12); |
||
376 | } |
||
377 | |||
378 | if (dist == 5) { |
||
379 | num = num + 5;
|
||
380 | } else {
|
||
381 | num++; |
||
382 | } |
||
383 | |||
384 | if (posUnitYNeg > iniY) {
|
||
385 | g.rotate(-rota, 20, posUnitYNeg - 12); |
||
386 | g.drawString(String.valueOf(-num), 10, |
||
387 | (int) posUnitYNeg - 12); |
||
388 | g.rotate(rota, 20, posUnitYNeg - 12); |
||
389 | } |
||
390 | } |
||
391 | } |
||
392 | |||
393 | if (posUnitY > iniY) {
|
||
394 | g.drawLine( 2 + init, (int) posUnitY, 2 + end, |
||
395 | (int) posUnitY);
|
||
396 | } |
||
397 | |||
398 | if (posUnitYNeg > iniY) {
|
||
399 | g.drawLine(2 + init, (int) posUnitYNeg, |
||
400 | 2 + end, (int) posUnitYNeg); |
||
401 | } |
||
402 | |||
403 | posUnitY += distY; |
||
404 | } |
||
405 | } |
||
406 | } |
||
407 | |||
408 | /**
|
||
409 | * Dibuja sobre el graphics2d las l?neas horizontales que representan a las
|
||
410 | * unidades de medida.
|
||
411 | *
|
||
412 | * @param g Graphics2d sobre el que se dibuja.
|
||
413 | * @param dist distancia en cent?metros de una l?nea a otra.
|
||
414 | * @param init inicio de la l?nea.
|
||
415 | * @param end fin de la l?nea.
|
||
416 | * @param x rect?ngulo, dentro del cual se dibujan las l?neas.
|
||
417 | * @param desp Desplazamiento.
|
||
418 | */
|
||
419 | private void drawLineX(Graphics2D g, double dist, int init, int end, |
||
420 | double x, double desp) { |
||
421 | 9392 | caballero | double distX = FLayoutUtilities.fromSheetDistance(dist, layout.getLayoutControl().getAT());
|
422 | 7304 | caballero | |
423 | if (distX > 4) { |
||
424 | double despX = FLayoutUtilities.fromSheetDistance(desp,
|
||
425 | 9392 | caballero | layout.getLayoutControl().getAT()); |
426 | 7304 | caballero | double posUnitX = x + despX;
|
427 | double posUnitXNeg = posUnitX;
|
||
428 | int num = 0; |
||
429 | double iniX = 40; |
||
430 | Point2D.Double pfin = FLayoutUtilities.fromSheetPoint(new Point2D.Double( |
||
431 | 9392 | caballero | layout.getLayoutControl().getWidth(), layout.getLayoutControl().getHeight()), layout.getLayoutControl().getAT()); |
432 | 7304 | caballero | |
433 | while (posUnitX < (pfin.x - 5)) { |
||
434 | posUnitXNeg -= distX; |
||
435 | |||
436 | if (init == 12) { |
||
437 | if (distX > 16) { |
||
438 | if (posUnitX > iniX) {
|
||
439 | g.drawString(String.valueOf(num),
|
||
440 | (int) posUnitX + 3, 20); |
||
441 | } |
||
442 | |||
443 | if (dist == 5) { |
||
444 | num = num + 5;
|
||
445 | } else {
|
||
446 | num++; |
||
447 | } |
||
448 | |||
449 | if (posUnitXNeg > iniX) {
|
||
450 | g.drawString(String.valueOf(-num),
|
||
451 | (int) posUnitXNeg + 3, 20); |
||
452 | } |
||
453 | } |
||
454 | } |
||
455 | |||
456 | if (posUnitX > iniX) {
|
||
457 | g.drawLine((int) posUnitX, 2 + init, (int) posUnitX, |
||
458 | 2 + end);
|
||
459 | } |
||
460 | |||
461 | if (posUnitXNeg > iniX) {
|
||
462 | g.drawLine((int) posUnitXNeg, 2 + init, |
||
463 | (int) posUnitXNeg, 2 + end); |
||
464 | } |
||
465 | |||
466 | posUnitX += distX; |
||
467 | } |
||
468 | } |
||
469 | } |
||
470 | |||
471 | /**
|
||
472 | * Dibuja los handlers sobre los fframes que esten seleccionados.
|
||
473 | *
|
||
474 | * @param g Graphics sobre el que se dibuja.
|
||
475 | * @param color Color de los Handlers.
|
||
476 | */
|
||
477 | public void drawHandlers(Graphics2D g, Color color) { |
||
478 | g.setColor(color); |
||
479 | 9392 | caballero | IFFrame[] fframes=layout.getLayoutContext().getFFrames();
|
480 | 7304 | caballero | for (int i = 0; i < fframes.length; i++) { |
481 | IFFrame fframe = fframes[i]; |
||
482 | |||
483 | if (fframe.getSelected() != IFFrame.NOSELECT) {
|
||
484 | fframe.drawHandlers(g); |
||
485 | } |
||
486 | } |
||
487 | } |
||
488 | |||
489 | /**
|
||
490 | * A partir de un fichero que se pasa como par?metro se crea un pdf con el
|
||
491 | * contenido del Layout.
|
||
492 | *
|
||
493 | * @param pdf
|
||
494 | */
|
||
495 | /* public void toPS(File ps) {
|
||
496 | |||
497 | try {
|
||
498 | // Open the image file
|
||
499 | // InputStream is = new BufferedInputStream(
|
||
500 | // new FileInputStream("filename.gif"));
|
||
501 | |||
502 | // Prepare the output file to receive the postscript
|
||
503 | OutputStream fos = new BufferedOutputStream(
|
||
504 | new FileOutputStream("filename.ps"));
|
||
505 | |||
506 | // Find a factory that can do the conversion
|
||
507 | //DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
|
||
508 | DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
|
||
509 | StreamPrintServiceFactory[] factories =
|
||
510 | StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
|
||
511 | flavor,
|
||
512 | DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());
|
||
513 | |||
514 | if (factories.length > 0) {
|
||
515 | StreamPrintService service = factories[0].getPrintService(fos);
|
||
516 | |||
517 | // Create the print job
|
||
518 | DocPrintJob job = service.createPrintJob();
|
||
519 | Print print= (Print)PluginServices.getExtension(
|
||
520 | com.iver.cit.gvsig.Print.class);
|
||
521 | print.setLayout(layout);
|
||
522 | Doc doc = new SimpleDoc((Printable)print, flavor, null);
|
||
523 | //Doc doc = new SimpleDoc(is, flavor, null);
|
||
524 | // Monitor print job events; for the implementation of PrintJobWatcher,
|
||
525 | // see e702 Determining When a Print Job Has Finished
|
||
526 | //PrintJobWatcher pjDone = new PrintJobWatcher(job);
|
||
527 | // Actualizar attributes
|
||
528 | PrintRequestAttributeSet att = layout.getAtributes()
|
||
529 | .toPrintAttributes();
|
||
530 | // Print it
|
||
531 | job.print(doc, att);
|
||
532 | |||
533 | // Wait for the print job to be done
|
||
534 | //pjDone.waitForDone();
|
||
535 | // It is now safe to close the streams
|
||
536 | }
|
||
537 | |||
538 | // is.close();
|
||
539 | fos.close();
|
||
540 | } catch (PrintException e) {
|
||
541 | } catch (IOException e) {
|
||
542 | }
|
||
543 | }
|
||
544 | */
|
||
545 | |||
546 | /*
|
||
547 | public void printLayout(Layout layout) {
|
||
548 | l = layout;
|
||
549 | |||
550 | try {
|
||
551 | printerJob.setPrintable((Printable) PluginServices.getExtension(
|
||
552 | com.iver.cit.gvsig.Print.class));
|
||
553 | |||
554 | //Actualizar attributes
|
||
555 | PrintRequestAttributeSet att = layout.getAtributes()
|
||
556 | .toPrintAttributes();
|
||
557 | DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
|
||
558 | |||
559 | if (m_cachePrintServices == null) {
|
||
560 | m_cachePrintServices = PrintServiceLookup.lookupPrintServices(flavor,
|
||
561 | null);
|
||
562 | }
|
||
563 | |||
564 | PrintService defaultService = null;
|
||
565 | |||
566 | if (m_cachePrintService == null) {
|
||
567 | defaultService = PrintServiceLookup.lookupDefaultPrintService();
|
||
568 | }
|
||
569 | |||
570 | if (m_cachePrintService == null) {
|
||
571 | m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
|
||
572 | m_cachePrintServices, defaultService, flavor, att);
|
||
573 | }
|
||
574 | |||
575 | if (m_cachePrintService != null) {
|
||
576 | DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
|
||
577 | PrintJobListener pjlistener = new PrintJobAdapter() {
|
||
578 | public void printDataTransferCompleted(PrintJobEvent e) {
|
||
579 | System.out.println("Fin de impresi?n");
|
||
580 | }
|
||
581 | };
|
||
582 | |||
583 | jobNuevo.addPrintJobListener(pjlistener);
|
||
584 | |||
585 | Doc doc = new SimpleDoc((Printable) PluginServices.getExtension(
|
||
586 | com.iver.cit.gvsig.Print.class), flavor, null);
|
||
587 | jobNuevo.print(doc, att);
|
||
588 | }
|
||
589 | } catch (PrintException pe) {
|
||
590 | pe.printStackTrace();
|
||
591 | }
|
||
592 | }
|
||
593 | |||
594 | document.close();
|
||
595 | |||
596 | layout.fullRect();
|
||
597 | }
|
||
598 | */
|
||
599 | |||
600 | |||
601 | |||
602 | /**
|
||
603 | * A partir de un fichero que se pasa como par?metro se crea un ps con el
|
||
604 | * contenido del Layout.
|
||
605 | *
|
||
606 | * @param ps
|
||
607 | */
|
||
608 | public void toPS(File ps) { |
||
609 | try {
|
||
610 | // Prepare the output file to receive the postscript
|
||
611 | OutputStream fos = new BufferedOutputStream( |
||
612 | new FileOutputStream(ps)); |
||
613 | |||
614 | // Find a factory that can do the conversion
|
||
615 | //DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
|
||
616 | DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; |
||
617 | StreamPrintServiceFactory [] factories = |
||
618 | StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor,
|
||
619 | "application/postscript");
|
||
620 | |||
621 | if (factories.length > 0) { |
||
622 | StreamPrintService service = factories[0].getPrintService(fos); |
||
623 | |||
624 | // Create the print job
|
||
625 | DocPrintJob job = service.createPrintJob();
|
||
626 | Print print= (Print)PluginServices.getExtension( |
||
627 | com.iver.cit.gvsig.Print.class); |
||
628 | print.setLayout(layout); |
||
629 | Doc doc = new SimpleDoc(print, flavor, null); |
||
630 | //Doc doc = new SimpleDoc(is, flavor, null);
|
||
631 | // Monitor print job events; for the implementation of PrintJobWatcher,
|
||
632 | // see e702 Determining When a Print Job Has Finished
|
||
633 | //PrintJobWatcher pjDone = new PrintJobWatcher(job);
|
||
634 | // Actualizar attributes
|
||
635 | 9392 | caballero | PrintRequestAttributeSet att = layout.getLayoutContext().getAtributes()
|
636 | 7304 | caballero | .toPrintAttributes(); |
637 | // Print it
|
||
638 | job.print(doc, att); |
||
639 | |||
640 | // Wait for the print job to be done
|
||
641 | //pjDone.waitForDone();
|
||
642 | // It is now safe to close the streams
|
||
643 | } |
||
644 | |||
645 | // is.close();
|
||
646 | fos.close(); |
||
647 | } catch (PrintException e) { |
||
648 | } catch (IOException e) { |
||
649 | } |
||
650 | /* PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
|
||
651 | DocPrintJob printerJob = defaultPrintService.createPrintJob();
|
||
652 | |||
653 | try {
|
||
654 | DocFlavor flavor=DocFlavor.URL.POSTSCRIPT;
|
||
655 | if (!defaultPrintService.isDocFlavorSupported(flavor)) {
|
||
656 | System.err.println("The printer does not support the appropriate DocFlavor");
|
||
657 | }else {
|
||
658 | |||
659 | SimpleDoc simpleDoc;
|
||
660 | simpleDoc = new SimpleDoc(ps.toURL(),flavor, null);
|
||
661 | printerJob.print(simpleDoc, null);
|
||
662 | }
|
||
663 | } catch (MalformedURLException e) {
|
||
664 | // TODO Auto-generated catch block
|
||
665 | e.printStackTrace();
|
||
666 | } catch (PrintException e) {
|
||
667 | // TODO Auto-generated catch block
|
||
668 | e.printStackTrace();
|
||
669 | }
|
||
670 | */
|
||
671 | 9392 | caballero | layout.getLayoutControl().fullRect(); |
672 | 7304 | caballero | } |
673 | |||
674 | |||
675 | /**
|
||
676 | * A partir de un fichero que se pasa como par?metro se crea un pdf con el
|
||
677 | * contenido del Layout.
|
||
678 | *
|
||
679 | * @param pdf
|
||
680 | */
|
||
681 | public void toPDF(File pdf) { |
||
682 | double w = 0; |
||
683 | double h = 0; |
||
684 | Document document = new Document(); |
||
685 | |||
686 | 9392 | caballero | if (layout.getLayoutContext().getAtributes().isLandSpace()) {
|
687 | w = ((layout.getLayoutContext().getAtributes().m_sizePaper.getAlto() * Attributes.DPISCREEN) / Attributes.PULGADA); |
||
688 | h = ((layout.getLayoutContext().getAtributes().m_sizePaper.getAncho() * Attributes.DPISCREEN) / Attributes.PULGADA); |
||
689 | 7304 | caballero | } else {
|
690 | 9392 | caballero | w = ((layout.getLayoutContext().getAtributes().m_sizePaper.getAncho() * Attributes.DPISCREEN) / Attributes.PULGADA); |
691 | h = ((layout.getLayoutContext().getAtributes().m_sizePaper.getAlto() * Attributes.DPISCREEN) / Attributes.PULGADA); |
||
692 | 7304 | caballero | } |
693 | |||
694 | document.setPageSize(new com.lowagie.text.Rectangle((float) w, (float) h)); |
||
695 | |||
696 | try {
|
||
697 | FileOutputStream fos=new FileOutputStream(pdf); |
||
698 | PdfWriter writer = PdfWriter.getInstance(document,fos); |
||
699 | document.open(); |
||
700 | |||
701 | Print print = new Print();
|
||
702 | print.setLayout(layout); |
||
703 | |||
704 | PdfContentByte cb = writer.getDirectContent(); |
||
705 | Graphics2D g2 = cb.createGraphicsShapes((float) w, (float) h); |
||
706 | |||
707 | try {
|
||
708 | 9392 | caballero | if (layout.getLayoutContext().getAtributes().isLandSpace()) {
|
709 | 7304 | caballero | g2.rotate(Math.toRadians(-90), 0 + (w / (h / w)), |
710 | 0 + (h / 2)); |
||
711 | print.print(g2, new PageFormat(), 0); |
||
712 | g2.rotate(Math.toRadians(90), 0 + (w / (h / w)), 0 + |
||
713 | (h / 2));
|
||
714 | } else {
|
||
715 | print.print(g2, new PageFormat(), 0); |
||
716 | } |
||
717 | } catch (PrinterException e) { |
||
718 | e.printStackTrace(); |
||
719 | } |
||
720 | |||
721 | g2.dispose(); |
||
722 | |||
723 | } catch (DocumentException de) {
|
||
724 | System.err.println(de.getMessage());
|
||
725 | } catch (IOException ioe) { |
||
726 | JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), |
||
727 | ioe.getMessage()); |
||
728 | } |
||
729 | |||
730 | document.close(); |
||
731 | |||
732 | 9392 | caballero | layout.getLayoutControl().fullRect(); |
733 | 7304 | caballero | } |
734 | } |