root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / gui / Layout.java @ 9392
History | View | Annotate | Download (25 KB)
1 | 9392 | caballero | /*
|
---|---|---|---|
2 | * Created on 20-feb-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.gui; |
||
46 | |||
47 | import java.awt.Component; |
||
48 | import java.awt.Cursor; |
||
49 | import java.awt.Graphics2D; |
||
50 | import java.awt.GridLayout; |
||
51 | import java.awt.geom.AffineTransform; |
||
52 | import java.awt.print.PageFormat; |
||
53 | import java.awt.print.Printable; |
||
54 | import java.awt.print.PrinterException; |
||
55 | import java.awt.print.PrinterJob; |
||
56 | import java.beans.PropertyChangeEvent; |
||
57 | import java.beans.PropertyChangeListener; |
||
58 | import java.io.File; |
||
59 | |||
60 | import javax.print.Doc; |
||
61 | import javax.print.DocFlavor; |
||
62 | import javax.print.DocPrintJob; |
||
63 | import javax.print.PrintException; |
||
64 | import javax.print.PrintService; |
||
65 | import javax.print.PrintServiceLookup; |
||
66 | import javax.print.ServiceUI; |
||
67 | import javax.print.SimpleDoc; |
||
68 | import javax.print.attribute.PrintRequestAttributeSet; |
||
69 | import javax.print.event.PrintJobAdapter; |
||
70 | import javax.print.event.PrintJobEvent; |
||
71 | import javax.print.event.PrintJobListener; |
||
72 | import javax.swing.JFileChooser; |
||
73 | import javax.swing.JOptionPane; |
||
74 | import javax.swing.JPanel; |
||
75 | import javax.swing.filechooser.FileFilter; |
||
76 | |||
77 | import com.iver.andami.PluginServices; |
||
78 | import com.iver.andami.messages.NotificationManager; |
||
79 | import com.iver.andami.ui.mdiManager.IWindowListener; |
||
80 | import com.iver.andami.ui.mdiManager.SingletonWindow; |
||
81 | import com.iver.andami.ui.mdiManager.WindowInfo; |
||
82 | import com.iver.cit.gvsig.fmap.ColorEvent; |
||
83 | import com.iver.cit.gvsig.fmap.DriverException; |
||
84 | import com.iver.cit.gvsig.fmap.ExtentEvent; |
||
85 | import com.iver.cit.gvsig.fmap.ProjectionEvent; |
||
86 | import com.iver.cit.gvsig.fmap.ViewPortListener; |
||
87 | import com.iver.cit.gvsig.fmap.edition.commands.CommandListener; |
||
88 | import com.iver.cit.gvsig.fmap.layers.XMLException; |
||
89 | import com.iver.cit.gvsig.project.Project; |
||
90 | import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
||
91 | import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
||
92 | import com.iver.cit.gvsig.project.documents.gui.WindowData; |
||
93 | import com.iver.cit.gvsig.project.documents.layout.Attributes; |
||
94 | import com.iver.cit.gvsig.project.documents.layout.LayoutContext; |
||
95 | import com.iver.cit.gvsig.project.documents.layout.LayoutControl; |
||
96 | import com.iver.cit.gvsig.project.documents.layout.ProjectMap; |
||
97 | import com.iver.cit.gvsig.project.documents.layout.fframes.FFrame; |
||
98 | import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame; |
||
99 | import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameViewDependence; |
||
100 | import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog; |
||
101 | import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.FConfigLayoutDialog; |
||
102 | import com.iver.utiles.GenericFileFilter; |
||
103 | import com.iver.utiles.XMLEntity; |
||
104 | |||
105 | /**
|
||
106 | * Mapa.
|
||
107 | *
|
||
108 | * @author Vicente Caballero Navarro
|
||
109 | */
|
||
110 | public class Layout extends JPanel implements SingletonWindow, ViewPortListener, |
||
111 | IWindowListener, CommandListener { |
||
112 | |||
113 | |||
114 | private static Boolean defaultShowGrid = null; |
||
115 | private static Boolean defaultAdjustToGrid = null; |
||
116 | private static Boolean defaultShowRulers = null; |
||
117 | private IFFrameDialog fframedialog = null; |
||
118 | private MapProperties m_propertiesLayout = null; |
||
119 | private PrintService[] m_cachePrintServices = null; |
||
120 | private PrintService m_cachePrintService = null; |
||
121 | private ProjectMap map = null; |
||
122 | private Doc doc = null; |
||
123 | private PrintRequestAttributeSet att = null; |
||
124 | private WindowInfo m_viewInfo = null; |
||
125 | /**
|
||
126 | * Lo usamos cuando estamos haciendo una ficha y asignando tags Se pone en
|
||
127 | * modo debug cuando hacemos un VIEW_TAGS
|
||
128 | */
|
||
129 | private boolean bShowIconTag = false; |
||
130 | private LayoutControl layoutControl;
|
||
131 | private LayoutContext layoutContext;
|
||
132 | |||
133 | /**
|
||
134 | * Creates a new Layout object.
|
||
135 | */
|
||
136 | public Layout() {
|
||
137 | layoutContext=new LayoutContext();
|
||
138 | layoutControl=new LayoutControl(this); |
||
139 | layoutContext.updateFFrames(); |
||
140 | this.initComponents();
|
||
141 | } |
||
142 | |||
143 | /**
|
||
144 | * Rellena el ProjectMap del Layout.
|
||
145 | *
|
||
146 | * @param m
|
||
147 | * ProjectMap.
|
||
148 | */
|
||
149 | public void setProjectMap(ProjectMap m) { |
||
150 | map = m; |
||
151 | this.setName(m.getName());
|
||
152 | map.addPropertyChangeListener(new PropertyChangeListener() { |
||
153 | public void propertyChange(PropertyChangeEvent evt) { |
||
154 | if (evt.getPropertyName().equals("name")) { |
||
155 | PluginServices.getMDIManager().getWindowInfo(Layout.this) |
||
156 | .setTitle( |
||
157 | PluginServices.getText(this, "Mapa") |
||
158 | + " : "
|
||
159 | + (String) evt.getNewValue());
|
||
160 | } |
||
161 | } |
||
162 | }); |
||
163 | } |
||
164 | |||
165 | |||
166 | |||
167 | |||
168 | |||
169 | |||
170 | /**
|
||
171 | * M?todo para imprimir el Layout sin modificar la matriz de transformaci?n.
|
||
172 | *
|
||
173 | * @param g2
|
||
174 | */
|
||
175 | public void drawLayoutPrint(Graphics2D g2) { |
||
176 | layoutControl.setCancelDrawing(false);
|
||
177 | |||
178 | setCursor(Cursor.getDefaultCursor());
|
||
179 | |||
180 | double scale = 0; |
||
181 | scale = layoutControl.getRect().height / layoutContext.getAtributes().m_sizePaper.getAlto() * 1;
|
||
182 | AffineTransform escalado = new AffineTransform(); |
||
183 | AffineTransform translacion = new AffineTransform(); |
||
184 | translacion.setToTranslation(layoutControl.getRect().getMinX(), layoutControl.getRect().getMinY()); |
||
185 | escalado.setToScale(scale, scale); |
||
186 | layoutControl.getAT().setToIdentity(); |
||
187 | layoutControl.getAT().concatenate(translacion); |
||
188 | layoutControl.getAT().concatenate(escalado); |
||
189 | layoutContext.getAtributes().setDistanceUnitX(layoutControl.getRect()); |
||
190 | layoutContext.getAtributes().setDistanceUnitY(layoutControl.getRect()); |
||
191 | IFFrame[] fframes=layoutContext.getFFrames();
|
||
192 | for (int i = 0; i < fframes.length; i++) { |
||
193 | try {
|
||
194 | fframes[i].print(g2, layoutControl.getAT()); |
||
195 | } catch (DriverException e) {
|
||
196 | NotificationManager.addError(e.getMessage(), e); |
||
197 | } |
||
198 | } |
||
199 | |||
200 | // TODO Esto es para ver el rect?ngulo que representa el folio en la
|
||
201 | // impresi?n.
|
||
202 | // g2.drawRect(0, 0, (int) rect.getWidth(), (int) rect.getHeight());
|
||
203 | // setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||
204 | } |
||
205 | |||
206 | |||
207 | |||
208 | /**
|
||
209 | * Inicializa los componentes.
|
||
210 | */
|
||
211 | private void initComponents() { |
||
212 | this.setLayout(new GridLayout(1,1)); |
||
213 | |||
214 | add(layoutControl); |
||
215 | //m_attributes = new Attributes();
|
||
216 | layoutContext.getAtributes().setDistanceUnitX(layoutControl.getRect()); |
||
217 | layoutContext.getAtributes().setDistanceUnitY(layoutControl.getRect()); |
||
218 | //actionDelFFrame();
|
||
219 | setDoubleBuffered(true);
|
||
220 | } |
||
221 | |||
222 | /**
|
||
223 | * Abre el di?logo de propiedades del folio, pasando como par?metro el
|
||
224 | * PrinterJob.
|
||
225 | *
|
||
226 | * @param job
|
||
227 | */
|
||
228 | public void showPagePropertiesWindow(PrinterJob job) { |
||
229 | PageFormat pf1;
|
||
230 | |||
231 | pf1 = layoutContext.getAtributes().getPageFormat(); |
||
232 | pf1 = job.pageDialog(pf1); |
||
233 | layoutContext.getAtributes().setPageFormat(pf1); |
||
234 | layoutControl.refresh(); |
||
235 | } |
||
236 | |||
237 | /**
|
||
238 | * Obtiene el rect?ngulo que representa el folio con las caracter?sticas que
|
||
239 | * contiene attributes y diferenciando si es para visualizar en pantalla o
|
||
240 | * para imprimir.
|
||
241 | *
|
||
242 | * @param isPrint
|
||
243 | * si es para imprimir.
|
||
244 | */
|
||
245 | public void obtainRect(boolean isPrint) { |
||
246 | layoutContext.getAtributes().obtainRect(isPrint, layoutControl.getRect(), getWidth(), getHeight()); |
||
247 | } |
||
248 | |||
249 | /**
|
||
250 | * Muestra el di?logo de configuraci?n del Layout.
|
||
251 | */
|
||
252 | public void showFConfig() { |
||
253 | FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this); |
||
254 | PluginServices.getMDIManager().addWindow(m_configLayout); |
||
255 | } |
||
256 | |||
257 | /**
|
||
258 | * Mestra el di?logo de propiedades del Layout.
|
||
259 | */
|
||
260 | public void showFProperties() { |
||
261 | if (map == null) { |
||
262 | map = new ProjectMap();
|
||
263 | map.setModel(this);
|
||
264 | map.setName(getName()); |
||
265 | } |
||
266 | |||
267 | m_propertiesLayout = new MapProperties(map);
|
||
268 | PluginServices.getMDIManager().addWindow(m_propertiesLayout); |
||
269 | } |
||
270 | |||
271 | /**
|
||
272 | * Muestra el di?logo de imprimir pasandole el printerJob como par?metro.
|
||
273 | *
|
||
274 | * @param job
|
||
275 | */
|
||
276 | public void showPrintDialog(PrinterJob job) { |
||
277 | if (job != null) { |
||
278 | job.printDialog(); |
||
279 | |||
280 | try {
|
||
281 | job.setPrintable((Printable) PluginServices
|
||
282 | .getExtension(com.iver.cit.gvsig.Print.class)); |
||
283 | job.print(); |
||
284 | } catch (PrinterException e) { |
||
285 | e.printStackTrace(); |
||
286 | } |
||
287 | } else {
|
||
288 | // Actualizar attributes
|
||
289 | att = layoutContext.getAtributes().toPrintAttributes(); |
||
290 | |||
291 | // ------------------ The Printing things --------------------- //
|
||
292 | DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; |
||
293 | |||
294 | // returns the set of printers that support printing a specific
|
||
295 | // document type (such as GIF)
|
||
296 | // with a specific set of attributes (such as two sided).
|
||
297 | // PrintRequestAttributeSet pras = new
|
||
298 | // HashPrintRequestAttributeSet();
|
||
299 | // interestingly, the printer dialog's default behavior has changed
|
||
300 | // with the new API: by default the dialog is not shown.
|
||
301 | // So we must use the ServiceUI class to create a print dialog
|
||
302 | // returns the default print service.
|
||
303 | if (m_cachePrintServices == null) { |
||
304 | m_cachePrintServices = PrintServiceLookup.lookupPrintServices(
|
||
305 | flavor, null);
|
||
306 | } |
||
307 | |||
308 | PrintService defaultService = null; |
||
309 | |||
310 | if (m_cachePrintService == null) { |
||
311 | defaultService = PrintServiceLookup.lookupDefaultPrintService();
|
||
312 | } |
||
313 | |||
314 | if ((defaultService == null) && (m_cachePrintService == null)) { |
||
315 | JOptionPane.showMessageDialog((Component) PluginServices |
||
316 | .getMainFrame(),PluginServices.getText(this,"ninguna_impresora_configurada")); |
||
317 | |||
318 | return;
|
||
319 | } |
||
320 | |||
321 | if (m_cachePrintService == null) { |
||
322 | m_cachePrintService = ServiceUI.printDialog(null, 200, 200, |
||
323 | m_cachePrintServices, defaultService, flavor, att); |
||
324 | |||
325 | // m_cachePrintRequestAtributeSet = new
|
||
326 | // HashPrintRequestAttributeSet();
|
||
327 | // m_cachePrintRequestAtributeSet.addAll(pras);
|
||
328 | } else {
|
||
329 | m_cachePrintService = ServiceUI.printDialog(null, 200, 200, |
||
330 | m_cachePrintServices, m_cachePrintService, flavor, att); |
||
331 | } |
||
332 | |||
333 | if (m_cachePrintService != null) { |
||
334 | DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
|
||
335 | PrintJobListener pjlistener = new PrintJobAdapter() { |
||
336 | public void printDataTransferCompleted(PrintJobEvent e) { |
||
337 | System.out.println("Fin de impresi?n"); |
||
338 | layoutControl.fullRect(); |
||
339 | } |
||
340 | }; |
||
341 | |||
342 | jobNuevo.addPrintJobListener(pjlistener); |
||
343 | |||
344 | // DocAttributeSet das = new HashDocAttributeSet();
|
||
345 | doc = new SimpleDoc(PluginServices |
||
346 | .getExtension(com.iver.cit.gvsig.Print.class), flavor, |
||
347 | null);
|
||
348 | |||
349 | try {
|
||
350 | jobNuevo.print(doc, att); |
||
351 | |||
352 | // m_attributes.
|
||
353 | } catch (PrintException pe) { |
||
354 | pe.printStackTrace(); |
||
355 | } |
||
356 | } |
||
357 | } |
||
358 | |||
359 | /*
|
||
360 | * try { print = job.printDialog(att); } catch (Exception e) {
|
||
361 | * logger.error("Abriendo el Di?logo de imprimir");
|
||
362 | * //System.out.println("Excepci?n "+e); } if (print) {
|
||
363 | * job.setPrintable((Printable)
|
||
364 | * App.instance.getPc().getExtension(com.iver.cit.gvsig.Print.class));
|
||
365 | * try { job.print(att); } catch (Exception ex) { ex.printStackTrace(); } }
|
||
366 | */
|
||
367 | } |
||
368 | |||
369 | /**
|
||
370 | * Se crean aqu? los dialogos cada vez que se necesitan.
|
||
371 | *
|
||
372 | * @param fframe
|
||
373 | * Rectangle que representa el lugar que ocupara el elemento
|
||
374 | * a?adido.
|
||
375 | *
|
||
376 | * @return true si se debe de a?adir el fframe.
|
||
377 | */
|
||
378 | public IFFrame openFFrameDialog(IFFrame fframe) {
|
||
379 | fframedialog=fframe.getPropertyDialog(); |
||
380 | if (fframedialog != null) { |
||
381 | fframedialog.setRectangle(fframe.getBoundingBox(layoutControl.getAT())); |
||
382 | PluginServices.getMDIManager().addWindow(fframedialog); |
||
383 | } |
||
384 | |||
385 | return fframedialog.getFFrame();
|
||
386 | } |
||
387 | |||
388 | /**
|
||
389 | * This method is used to get <strong>an initial</strong> ViewInfo object
|
||
390 | * for this Map. It is not intended to retrieve the ViewInfo object in a
|
||
391 | * later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
|
||
392 | * to retrieve the ViewInfo object at any time after the creation of the
|
||
393 | * object.
|
||
394 | *
|
||
395 | * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
|
||
396 | */
|
||
397 | public WindowInfo getWindowInfo() {
|
||
398 | if (m_viewInfo == null) { |
||
399 | m_viewInfo = new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE
|
||
400 | | WindowInfo.MAXIMIZABLE); |
||
401 | m_viewInfo.setWidth(500);
|
||
402 | m_viewInfo.setHeight(400);
|
||
403 | |||
404 | m_viewInfo.setTitle(PluginServices.getText(this, "Mapa") + " : " |
||
405 | + map.getName()); |
||
406 | } |
||
407 | return m_viewInfo;
|
||
408 | } |
||
409 | |||
410 | /**
|
||
411 | * Devuelve un Objeto XMLEntity con la informaci?n los atributos necesarios
|
||
412 | * para poder despu?s volver a crear el objeto original.
|
||
413 | *
|
||
414 | * @return XMLEntity.
|
||
415 | *
|
||
416 | * @throws XMLException
|
||
417 | */
|
||
418 | public XMLEntity getXMLEntity() {
|
||
419 | XMLEntity xml = new XMLEntity();
|
||
420 | xml.putProperty("className", this.getClass().getName()); |
||
421 | xml.setName("layout");
|
||
422 | xml.putProperty("isCuadricula", layoutContext.isAdjustingToGrid());
|
||
423 | // xml.putProperty("m_name", this.getName());
|
||
424 | xml.putProperty("isEditable", layoutContext.isEditable());
|
||
425 | xml.putProperty("numBehind", layoutContext.numBehind);
|
||
426 | xml.putProperty("numBefore", layoutContext.numBefore);
|
||
427 | xml.addChild(layoutContext.getAtributes().getXMLEntity()); |
||
428 | IFFrame[] fframes=layoutContext.getFFrames();
|
||
429 | for (int i = 0; i < fframes.length; i++) { |
||
430 | try {
|
||
431 | XMLEntity xmlAux = fframes[i].getXMLEntity(); |
||
432 | xml.addChild(xmlAux); |
||
433 | } catch (SaveException e) {
|
||
434 | e.showError(); |
||
435 | } |
||
436 | } |
||
437 | return xml;
|
||
438 | } |
||
439 | public LayoutContext getLayoutContext() {
|
||
440 | return layoutContext;
|
||
441 | } |
||
442 | public LayoutControl getLayoutControl() {
|
||
443 | return layoutControl;
|
||
444 | } |
||
445 | /**
|
||
446 | * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
|
||
447 | *
|
||
448 | * @param xml
|
||
449 | * XMLEntity
|
||
450 | * @param p
|
||
451 | * Proyecto.
|
||
452 | *
|
||
453 | * @return Objeto de esta clase.
|
||
454 | * @throws OpenException
|
||
455 | */
|
||
456 | public static Layout createLayout(XMLEntity xml, Project p) |
||
457 | throws OpenException {
|
||
458 | Layout layout = new Layout();
|
||
459 | try {
|
||
460 | layout.layoutContext.setAdjustToGrid(xml.getBooleanProperty("isCuadricula"));
|
||
461 | //layout.setName(xml.getStringProperty("m_name"));
|
||
462 | layout.getLayoutContext().setAtributes(Attributes.createAtributes(xml.getChild(0))); |
||
463 | if (xml.contains("isEditable")) { |
||
464 | layout.layoutContext.setEditable(xml.getBooleanProperty("isEditable"));
|
||
465 | } |
||
466 | if (xml.contains("numBehind")) { |
||
467 | layout.layoutContext.numBehind = xml.getIntProperty("numBehind");
|
||
468 | layout.layoutContext.numBefore = xml.getIntProperty("numBefore");
|
||
469 | } |
||
470 | layout.layoutContext.getEFS().startComplexCommand(); |
||
471 | for (int i = 1; i < xml.getChildrenCount(); i++) { |
||
472 | try {
|
||
473 | layout.layoutContext.addFFrame(FFrame.createFFrame(xml.getChild(i), p, |
||
474 | layout), true, false); |
||
475 | } catch (OpenException e) {
|
||
476 | e.showError(); |
||
477 | } |
||
478 | } |
||
479 | layout.layoutContext.getEFS().endComplexCommand(PluginServices.getText(layout,"Inicializando"));
|
||
480 | IFFrame[] fframes = layout.getLayoutContext().getAllFFrames();
|
||
481 | for (int i = 0; i < fframes.length; i++) { |
||
482 | fframes[i].setLayout(layout); |
||
483 | if (fframes[i] instanceof IFFrameViewDependence) { |
||
484 | ((IFFrameViewDependence) fframes[i]) |
||
485 | .initDependence(fframes); |
||
486 | } |
||
487 | } |
||
488 | } catch (Exception e) { |
||
489 | throw new OpenException(e, layout.getClass().getName()); |
||
490 | } |
||
491 | return layout;
|
||
492 | } |
||
493 | |||
494 | /**
|
||
495 | * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
|
||
496 | *
|
||
497 | * @param xml
|
||
498 | * XMLEntity
|
||
499 | * @param p
|
||
500 | * Proyecto.
|
||
501 | *
|
||
502 | * @return Objeto de esta clase.
|
||
503 | */
|
||
504 | public static Layout createLayout03(XMLEntity xml, Project p) { |
||
505 | Layout layout = new Layout();
|
||
506 | layout.layoutContext.setAdjustToGrid(xml.getBooleanProperty("isCuadricula"));
|
||
507 | layout.setName(xml.getStringProperty("m_name"));
|
||
508 | layout.getLayoutContext().setAtributes(Attributes.createAtributes03(xml.getChild(0))); |
||
509 | |||
510 | for (int i = 1; i < xml.getChildrenCount(); i++) { |
||
511 | if (xml.getChild(i).getStringProperty("className").equals( |
||
512 | "com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
|
||
513 | layout.layoutContext.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout, |
||
514 | p), true, false); |
||
515 | } |
||
516 | } |
||
517 | |||
518 | for (int i = 1; i < xml.getChildrenCount(); i++) { |
||
519 | if (!xml.getChild(i).getStringProperty("className").equals( |
||
520 | "com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
|
||
521 | layout.layoutContext.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout, |
||
522 | p), true, false); |
||
523 | } |
||
524 | } |
||
525 | |||
526 | return layout;
|
||
527 | } |
||
528 | |||
529 | /**
|
||
530 | * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
|
||
531 | */
|
||
532 | public void windowActivated() { |
||
533 | //fullRect();
|
||
534 | layoutControl.refresh(); |
||
535 | PluginServices.getMainFrame().getStatusBar().setMessage("units",
|
||
536 | PluginServices.getText(this, layoutContext.getAtributes().getNameUnit()));
|
||
537 | } |
||
538 | |||
539 | /**
|
||
540 | * @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
|
||
541 | */
|
||
542 | public Object getWindowModel() { |
||
543 | return map;
|
||
544 | } |
||
545 | |||
546 | /**
|
||
547 | * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
|
||
548 | */
|
||
549 | public void extentChanged(ExtentEvent e) { |
||
550 | } |
||
551 | |||
552 | /**
|
||
553 | * @see com.iver.andami.ui.mdiManager.IWindowListener#windowClosed()
|
||
554 | */
|
||
555 | public void windowClosed() { |
||
556 | // /PluginServices.getMainFrame().getStatusBar().setMessage("1","");
|
||
557 | } |
||
558 | |||
559 | /**
|
||
560 | * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
|
||
561 | */
|
||
562 | public void backColorChanged(ColorEvent e) { |
||
563 | // refresh();
|
||
564 | } |
||
565 | |||
566 | /**
|
||
567 | * Opens a dialog where to pick a PDF-file to save the current Layout
|
||
568 | * suggesting a name for the file given by the first argument
|
||
569 | *
|
||
570 | * @param suggestedName
|
||
571 | */
|
||
572 | public void layoutToPDF(String suggestedName) { |
||
573 | FileFilter pdfFilter = new GenericFileFilter("pdf", PluginServices |
||
574 | .getText(this, "pdf")); |
||
575 | |||
576 | JFileChooser jfc = new JFileChooser(); |
||
577 | if (suggestedName != null) |
||
578 | jfc.setSelectedFile(new File(suggestedName)); |
||
579 | jfc.addChoosableFileFilter(pdfFilter); |
||
580 | jfc.setFileFilter(pdfFilter); |
||
581 | |||
582 | if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
||
583 | File f = jfc.getSelectedFile();
|
||
584 | File faux = null; |
||
585 | |||
586 | if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) { |
||
587 | faux = f; |
||
588 | } else {
|
||
589 | faux = new File(f.getPath() + ".pdf"); |
||
590 | } |
||
591 | |||
592 | layoutControl.getLayoutDraw().toPDF(faux); |
||
593 | } |
||
594 | } |
||
595 | /**
|
||
596 | * Opens a dialog where to pick a PS-file to save the current Layout
|
||
597 | * suggesting a name for the file given by the first argument
|
||
598 | *
|
||
599 | * @param suggestedName
|
||
600 | */
|
||
601 | public void layoutToPS(String suggestedName) { |
||
602 | FileFilter pdfFilter = new GenericFileFilter("ps", PluginServices |
||
603 | .getText(this, "ps")); |
||
604 | |||
605 | JFileChooser jfc = new JFileChooser(); |
||
606 | if (suggestedName != null) |
||
607 | jfc.setSelectedFile(new File(suggestedName)); |
||
608 | jfc.addChoosableFileFilter(pdfFilter); |
||
609 | jfc.setFileFilter(pdfFilter); |
||
610 | |||
611 | if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
||
612 | File f = jfc.getSelectedFile();
|
||
613 | File faux = null; |
||
614 | |||
615 | if (f.getName().endsWith(".ps") || f.getName().endsWith(".PS")) { |
||
616 | faux = f; |
||
617 | } else {
|
||
618 | faux = new File(f.getPath() + ".ps"); |
||
619 | } |
||
620 | |||
621 | layoutControl.getLayoutDraw().toPS(faux); |
||
622 | } |
||
623 | } |
||
624 | /**
|
||
625 | * Abre un di?logo para seleccionar un fichero pdf donde guardar el Layout
|
||
626 | * en este formato.
|
||
627 | */
|
||
628 | public void layoutToPDF() { |
||
629 | layoutToPDF(null);
|
||
630 | } |
||
631 | /**
|
||
632 | * Abre un di?logo para seleccionar un fichero ps donde guardar el Layout
|
||
633 | * en este formato.
|
||
634 | */
|
||
635 | public void layoutToPS() { |
||
636 | layoutToPS(null);
|
||
637 | } |
||
638 | /**
|
||
639 | * @return Returns the bModeDebug.
|
||
640 | */
|
||
641 | public boolean isShowIconTag() { |
||
642 | return bShowIconTag;
|
||
643 | } |
||
644 | |||
645 | /**
|
||
646 | * @param modeDebug
|
||
647 | * The bModeDebug to set.
|
||
648 | */
|
||
649 | public void setShowIconTag(boolean modeDebug) { |
||
650 | bShowIconTag = modeDebug; |
||
651 | } |
||
652 | |||
653 | |||
654 | public void commandRepaint() { |
||
655 | this.layoutContext.updateFFrames();
|
||
656 | this.layoutControl.refresh();
|
||
657 | } |
||
658 | |||
659 | public void commandRefresh() { |
||
660 | commandRepaint(); |
||
661 | |||
662 | } |
||
663 | |||
664 | public void projectionChanged(ProjectionEvent e) { |
||
665 | // TODO Auto-generated method stub
|
||
666 | |||
667 | } |
||
668 | public static boolean getDefaultShowGrid() { |
||
669 | if (defaultShowGrid == null) { |
||
670 | XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
|
||
671 | if (xml.contains("DefaultShowLayoutGrid")) { |
||
672 | defaultShowGrid = new Boolean(xml.getBooleanProperty("DefaultShowLayoutGrid")); |
||
673 | } |
||
674 | else {
|
||
675 | // factory default is true
|
||
676 | defaultShowGrid = new Boolean(true); |
||
677 | } |
||
678 | } |
||
679 | return defaultShowGrid.booleanValue();
|
||
680 | } |
||
681 | |||
682 | public static boolean getDefaultAdjustToGrid() { |
||
683 | if (defaultAdjustToGrid == null) { |
||
684 | XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
|
||
685 | if (xml.contains("DefaultEnableLayoutGrid")) { |
||
686 | defaultAdjustToGrid = new Boolean(xml.getBooleanProperty("DefaultEnableLayoutGrid")); |
||
687 | } |
||
688 | else {
|
||
689 | // factory default is false
|
||
690 | defaultAdjustToGrid = new Boolean(false); |
||
691 | } |
||
692 | } |
||
693 | return defaultAdjustToGrid.booleanValue();
|
||
694 | } |
||
695 | |||
696 | public static boolean getDefaultShowRulers() { |
||
697 | if (defaultShowRulers == null){ |
||
698 | XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
|
||
699 | if (xml.contains("DefaultShowLayoutRules")) { |
||
700 | defaultShowRulers = new Boolean(xml.getBooleanProperty("DefaultShowLayoutRules")); |
||
701 | } |
||
702 | else {
|
||
703 | // factory default is true
|
||
704 | defaultShowRulers = new Boolean(true); |
||
705 | } |
||
706 | } |
||
707 | return defaultShowRulers.booleanValue();
|
||
708 | } |
||
709 | |||
710 | public static void setDefaultShowGrid(boolean showGrid) { |
||
711 | defaultShowGrid = new Boolean(showGrid); |
||
712 | } |
||
713 | |||
714 | public static void setDefaultAdjustToGrid(boolean gridEnabled) { |
||
715 | defaultAdjustToGrid = new Boolean(gridEnabled); |
||
716 | } |
||
717 | |||
718 | public static void setDefaultShowRulers(boolean showRules) { |
||
719 | defaultShowRulers = new Boolean(showRules); |
||
720 | } |
||
721 | } |