svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / gui / Layout.java @ 28565
History | View | Annotate | Download (26.9 KB)
1 |
/*
|
---|---|
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.JOptionPane; |
73 |
import javax.swing.JPanel; |
74 |
import javax.swing.filechooser.FileFilter; |
75 |
|
76 |
import org.apache.log4j.Logger; |
77 |
import org.gvsig.gui.beans.swing.JFileChooser; |
78 |
|
79 |
import com.iver.andami.PluginServices; |
80 |
import com.iver.andami.messages.NotificationManager; |
81 |
import com.iver.andami.ui.mdiManager.IWindowListener; |
82 |
import com.iver.andami.ui.mdiManager.SingletonWindow; |
83 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
84 |
import com.iver.cit.gvsig.fmap.ColorEvent; |
85 |
import com.iver.cit.gvsig.fmap.ExtentEvent; |
86 |
import com.iver.cit.gvsig.fmap.ProjectionEvent; |
87 |
import com.iver.cit.gvsig.fmap.ViewPortListener; |
88 |
import com.iver.cit.gvsig.fmap.edition.commands.CommandListener; |
89 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
90 |
import com.iver.cit.gvsig.project.Project; |
91 |
import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
92 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
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.FFrameGroup; |
99 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame; |
100 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameViewDependence; |
101 |
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog; |
102 |
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.FConfigLayoutDialog; |
103 |
import com.iver.utiles.GenericFileFilter; |
104 |
import com.iver.utiles.XMLEntity; |
105 |
|
106 |
/**
|
107 |
* Graphic representation of the elements to print.
|
108 |
*
|
109 |
* @author Vicente Caballero Navarro
|
110 |
*/
|
111 |
public class Layout extends JPanel implements SingletonWindow, ViewPortListener, |
112 |
IWindowListener, CommandListener { |
113 |
public static final String PDF_AND_PS_FILECHOOSER = "PDF_AND_PS_FILECHOOSER"; |
114 |
|
115 |
public static File defaultPDFFolderPath; |
116 |
|
117 |
private static Boolean defaultShowGrid = null; |
118 |
private static Boolean defaultAdjustToGrid = null; |
119 |
private static Boolean defaultShowRulers = null; |
120 |
private IFFrameDialog fframedialog = null; |
121 |
private MapProperties m_propertiesLayout = null; |
122 |
private PrintService[] m_cachePrintServices = null; |
123 |
private PrintService m_cachePrintService = null; |
124 |
private ProjectMap map = null; |
125 |
private Doc doc = null; |
126 |
private PrintRequestAttributeSet att = null; |
127 |
private WindowInfo m_viewInfo = null; |
128 |
private static boolean useDefaultJavaPrinting = true; |
129 |
|
130 |
/**
|
131 |
* We use it when we are doing a layout and assigning tags.
|
132 |
* It is put in debug when we do a VIEW_TAGS
|
133 |
*/
|
134 |
private boolean bShowIconTag = false; |
135 |
private LayoutControl layoutControl;
|
136 |
private LayoutContext layoutContext;
|
137 |
|
138 |
/**
|
139 |
* Creates a new Layout object.
|
140 |
*/
|
141 |
public Layout() {
|
142 |
layoutContext=new LayoutContext();
|
143 |
layoutControl=new LayoutControl(this); |
144 |
layoutContext.updateFFrames(); |
145 |
this.initComponents();
|
146 |
} |
147 |
|
148 |
/**
|
149 |
* Inserts the ProjectMap of this Layout.
|
150 |
*
|
151 |
* @param m ProjectMap.
|
152 |
*/
|
153 |
public void setProjectMap(ProjectMap m) { |
154 |
map = m; |
155 |
this.setName(m.getName());
|
156 |
map.addPropertyChangeListener(new PropertyChangeListener() { |
157 |
public void propertyChange(PropertyChangeEvent evt) { |
158 |
if (evt.getPropertyName().equals("name")) { |
159 |
PluginServices.getMDIManager().getWindowInfo(Layout.this) |
160 |
.setTitle( |
161 |
PluginServices.getText(this, "Mapa") |
162 |
+ " : "
|
163 |
+ (String) evt.getNewValue());
|
164 |
} |
165 |
} |
166 |
}); |
167 |
} |
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
/**
|
175 |
* Method to print the Layout without modify the Affinetransform.
|
176 |
*
|
177 |
* @param g2 Geaphics2D
|
178 |
*/
|
179 |
public void drawLayoutPrint(Graphics2D g2) { |
180 |
layoutControl.setCancelDrawing(false);
|
181 |
|
182 |
setCursor(Cursor.getDefaultCursor());
|
183 |
|
184 |
double scale = 0; |
185 |
scale = layoutControl.getRect().height / layoutContext.getAtributes().m_sizePaper.getAlto() * 1;
|
186 |
AffineTransform escalado = new AffineTransform(); |
187 |
AffineTransform translacion = new AffineTransform(); |
188 |
translacion.setToTranslation(layoutControl.getRect().getMinX(), layoutControl.getRect().getMinY()); |
189 |
escalado.setToScale(scale, scale); |
190 |
layoutControl.getAT().setToIdentity(); |
191 |
layoutControl.getAT().concatenate(translacion); |
192 |
layoutControl.getAT().concatenate(escalado); |
193 |
layoutContext.getAtributes().setDistanceUnitX(layoutControl.getRect()); |
194 |
layoutContext.getAtributes().setDistanceUnitY(layoutControl.getRect()); |
195 |
IFFrame[] fframes=layoutContext.getFFrames();
|
196 |
for (int i = 0; i < fframes.length; i++) { |
197 |
// fframes[i].setPrintingProperties(this.att);
|
198 |
fframes[i].print(g2, layoutControl.getAT(),null, layoutContext.getAtributes().getAttributes());
|
199 |
// fframes[i].setPrintingProperties(null);
|
200 |
} |
201 |
|
202 |
// TODO Esto es para ver el rect?ngulo que representa el folio en la
|
203 |
// impresi?n.
|
204 |
// g2.drawRect(0, 0, (int) rect.getWidth(), (int) rect.getHeight());
|
205 |
} |
206 |
|
207 |
|
208 |
|
209 |
/**
|
210 |
* It initializes the components.
|
211 |
*/
|
212 |
private void initComponents() { |
213 |
this.setLayout(new GridLayout(1,1)); |
214 |
add(layoutControl); |
215 |
layoutContext.getAtributes().setDistanceUnitX(layoutControl.getRect()); |
216 |
layoutContext.getAtributes().setDistanceUnitY(layoutControl.getRect()); |
217 |
setDoubleBuffered(true);
|
218 |
} |
219 |
|
220 |
/**
|
221 |
* Open the dialog of Layout properties.
|
222 |
*
|
223 |
* @param job PrinterJob
|
224 |
*/
|
225 |
public void showPagePropertiesWindow(PrinterJob job) { |
226 |
PageFormat pf1;
|
227 |
|
228 |
pf1 = layoutContext.getAtributes().getPageFormat(); |
229 |
pf1 = job.pageDialog(pf1); |
230 |
layoutContext.getAtributes().setPageFormat(pf1); |
231 |
layoutControl.refresh(); |
232 |
} |
233 |
|
234 |
/**
|
235 |
* It obtains the rect?ngulo that represents the sheet with the characteristics
|
236 |
* that contains attributes and differentiating if is to visualize in screen or
|
237 |
* for print.
|
238 |
*
|
239 |
*/
|
240 |
public void obtainRect(boolean isPrint) { |
241 |
layoutContext.getAtributes().obtainRect(isPrint,layoutControl.getRect(), getWidth(), getHeight()); |
242 |
// layoutContext.getAtributes().obtainRect(layoutControl.getRect());
|
243 |
} |
244 |
|
245 |
/**
|
246 |
* It shows the dialog of configuration of the Layout.
|
247 |
*/
|
248 |
public void showFConfig() { |
249 |
FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this); |
250 |
PluginServices.getMDIManager().addWindow(m_configLayout); |
251 |
} |
252 |
|
253 |
/**
|
254 |
* It shows the dialog of Layout?s properties.
|
255 |
*/
|
256 |
public boolean showFProperties() { |
257 |
if (map == null) { |
258 |
map = new ProjectMap();
|
259 |
map.setModel(this);
|
260 |
map.setName(getName()); |
261 |
} |
262 |
|
263 |
m_propertiesLayout = new MapProperties(map);
|
264 |
PluginServices.getMDIManager().addWindow(m_propertiesLayout); |
265 |
return m_propertiesLayout.isAccepted();
|
266 |
} |
267 |
|
268 |
/**
|
269 |
* It shows the dialog of printing of the Layout.
|
270 |
*
|
271 |
* @param job PrinterJob
|
272 |
*/
|
273 |
public void showPrintDialog(PrinterJob job) { |
274 |
if (job != null) { |
275 |
job.printDialog(); |
276 |
|
277 |
try {
|
278 |
job.setPrintable((Printable) PluginServices
|
279 |
.getExtension(com.iver.cit.gvsig.Print.class)); |
280 |
job.print(); |
281 |
} catch (PrinterException e) { |
282 |
e.printStackTrace(); |
283 |
} |
284 |
} else {
|
285 |
// Actualizar attributes
|
286 |
att = layoutContext.getAtributes().toPrintAttributes(); |
287 |
|
288 |
// ------------------ The Printing things --------------------- //
|
289 |
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; |
290 |
|
291 |
// returns the set of printers that support printing a specific
|
292 |
// document type (such as GIF)
|
293 |
// with a specific set of attributes (such as two sided).
|
294 |
// PrintRequestAttributeSet pras = new
|
295 |
// HashPrintRequestAttributeSet();
|
296 |
// interestingly, the printer dialog's default behavior has changed
|
297 |
// with the new API: by default the dialog is not shown.
|
298 |
// So we must use the ServiceUI class to create a print dialog
|
299 |
// returns the default print service.
|
300 |
if (m_cachePrintServices == null) { |
301 |
m_cachePrintServices = PrintServiceLookup.lookupPrintServices(
|
302 |
flavor, null);
|
303 |
} |
304 |
|
305 |
PrintService defaultService = null; |
306 |
|
307 |
if (m_cachePrintService == null) { |
308 |
defaultService = PrintServiceLookup.lookupDefaultPrintService();
|
309 |
} |
310 |
|
311 |
if ((defaultService == null) && (m_cachePrintService == null)) { |
312 |
JOptionPane.showMessageDialog((Component) PluginServices |
313 |
.getMainFrame(),PluginServices.getText(this,"ninguna_impresora_configurada")); |
314 |
|
315 |
return;
|
316 |
} |
317 |
|
318 |
if (useDefaultJavaPrinting) {
|
319 |
try {
|
320 |
m_cachePrintService = ServiceUI.printDialog(null, 200, 200, |
321 |
m_cachePrintServices, defaultService, flavor, att); |
322 |
} |
323 |
catch (NullPointerException ex) { |
324 |
useDefaultJavaPrinting=false;
|
325 |
Logger logger = PluginServices.getLogger();
|
326 |
logger.error("Error showing print dialog", ex);
|
327 |
|
328 |
// workaround a problem with Java 1.5 with moder CUPS versions
|
329 |
// this try-catch block may be safely removed when we move to Java 1.6
|
330 |
logger.debug("Opening gvSIG's internal Java 1.7 CUPS printing dialog");
|
331 |
m_cachePrintService = backport1_7.javax.print.ServiceUI.printDialog(null, 200, 200, |
332 |
m_cachePrintServices, defaultService, flavor, att); |
333 |
} |
334 |
} |
335 |
else {
|
336 |
PluginServices.getLogger().debug("Opening gvSIG's internal Java 1.7 CUPS printing dialog");
|
337 |
m_cachePrintService = backport1_7.javax.print.ServiceUI.printDialog(null, 200, 200, |
338 |
m_cachePrintServices, defaultService, flavor, att); |
339 |
} |
340 |
|
341 |
if (m_cachePrintService != null) { |
342 |
DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
|
343 |
PrintJobListener pjlistener = new PrintJobAdapter() { |
344 |
public void printDataTransferCompleted(PrintJobEvent e) { |
345 |
layoutControl.fullRect(); |
346 |
} |
347 |
}; |
348 |
|
349 |
jobNuevo.addPrintJobListener(pjlistener); |
350 |
|
351 |
doc = new SimpleDoc(PluginServices |
352 |
.getExtension(com.iver.cit.gvsig.Print.class), flavor, |
353 |
null);
|
354 |
|
355 |
try {
|
356 |
jobNuevo.print(doc, att); |
357 |
|
358 |
// m_attributes.
|
359 |
} catch (PrintException pe) { |
360 |
NotificationManager.addError(pe); |
361 |
} |
362 |
} |
363 |
} |
364 |
} |
365 |
|
366 |
/**
|
367 |
* The dialogs are created here each time that are needed.
|
368 |
*
|
369 |
* @param fframe
|
370 |
* Rectangle that represents the place that occupied the element added.
|
371 |
*
|
372 |
* @return IFFrame Returns the FFrame added or null if the fframe has not been added.
|
373 |
*/
|
374 |
public IFFrame openFFrameDialog(IFFrame fframe) {
|
375 |
fframedialog=fframe.getPropertyDialog(); |
376 |
if (fframedialog != null) { |
377 |
fframedialog.setRectangle(fframe.getBoundingBox(layoutControl.getAT())); |
378 |
PluginServices.getMDIManager().addWindow(fframedialog); |
379 |
} |
380 |
|
381 |
return fframedialog.getFFrame();
|
382 |
} |
383 |
|
384 |
/**
|
385 |
* This method is used to get <strong>an initial</strong> ViewInfo object
|
386 |
* for this Map. It is not intended to retrieve the ViewInfo object in a
|
387 |
* later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
|
388 |
* to retrieve the ViewInfo object at any time after the creation of the
|
389 |
* object.
|
390 |
*
|
391 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
|
392 |
*/
|
393 |
public WindowInfo getWindowInfo() {
|
394 |
if (m_viewInfo == null) { |
395 |
m_viewInfo = new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE
|
396 |
| WindowInfo.MAXIMIZABLE); |
397 |
m_viewInfo.setWidth(500);
|
398 |
m_viewInfo.setHeight(400);
|
399 |
|
400 |
m_viewInfo.setTitle(PluginServices.getText(this, "Mapa") + " : " |
401 |
+ map.getName()); |
402 |
} |
403 |
return m_viewInfo;
|
404 |
} |
405 |
|
406 |
/**
|
407 |
* It returns an Object XMLEntity with the information the necessary attributes
|
408 |
* to be able later to create again the original object.
|
409 |
*
|
410 |
* @return XMLEntity.
|
411 |
*
|
412 |
* @throws XMLException
|
413 |
*/
|
414 |
public XMLEntity getXMLEntity() {
|
415 |
XMLEntity xml = new XMLEntity();
|
416 |
xml.putProperty("className", this.getClass().getName()); |
417 |
xml.setName("layout");
|
418 |
xml.putProperty("isCuadricula", layoutContext.isAdjustingToGrid());
|
419 |
// xml.putProperty("m_name", this.getName());
|
420 |
xml.putProperty("isEditable", layoutContext.isEditable());
|
421 |
xml.putProperty("numBehind", layoutContext.numBehind);
|
422 |
xml.putProperty("numBefore", layoutContext.numBefore);
|
423 |
xml.addChild(layoutContext.getAtributes().getXMLEntity()); |
424 |
IFFrame[] fframes=layoutContext.getFFrames();
|
425 |
for (int i = 0; i < fframes.length; i++) { |
426 |
try {
|
427 |
XMLEntity xmlAux = fframes[i].getXMLEntity(); |
428 |
xml.addChild(xmlAux); |
429 |
} catch (SaveException e) {
|
430 |
e.showError(); |
431 |
} |
432 |
} |
433 |
return xml;
|
434 |
} |
435 |
/**
|
436 |
* Returns the LayoutContext.
|
437 |
* @return LayoutContext.
|
438 |
*/
|
439 |
public LayoutContext getLayoutContext() {
|
440 |
return layoutContext;
|
441 |
} |
442 |
/**
|
443 |
* Returns LayoutControl.
|
444 |
* @return LayoutControl.
|
445 |
*/
|
446 |
public LayoutControl getLayoutControl() {
|
447 |
return layoutControl;
|
448 |
} |
449 |
/**
|
450 |
* It creates an Object of this class from the information of the XMLEntity.
|
451 |
*
|
452 |
* @param xml
|
453 |
* XMLEntity
|
454 |
* @param p
|
455 |
* Project.
|
456 |
*
|
457 |
* @return Object of this class.
|
458 |
* @throws OpenException
|
459 |
*/
|
460 |
public static Layout createLayout(XMLEntity xml, Project p) |
461 |
throws OpenException {
|
462 |
Layout layout = new Layout();
|
463 |
try {
|
464 |
layout.layoutContext.setAdjustToGrid(xml.getBooleanProperty("isCuadricula"));
|
465 |
//layout.setName(xml.getStringProperty("m_name"));
|
466 |
layout.getLayoutContext().setAtributes(Attributes.createAtributes(xml.getChild(0))); |
467 |
if (xml.contains("isEditable")) { |
468 |
layout.layoutContext.setEditable(xml.getBooleanProperty("isEditable"));
|
469 |
} |
470 |
if (xml.contains("numBehind")) { |
471 |
layout.layoutContext.numBehind = xml.getIntProperty("numBehind");
|
472 |
layout.layoutContext.numBefore = xml.getIntProperty("numBefore");
|
473 |
} |
474 |
//layout.layoutContext.getEFS().startComplexCommand();
|
475 |
// for (int i = 1; i < xml.getChildrenCount(); i++) {
|
476 |
// try {
|
477 |
// layout.layoutContext.addFFrame(FFrame.createFFrame(xml.getChild(i), p,
|
478 |
// layout), true, false);
|
479 |
// } catch (OpenException e) {
|
480 |
// e.showError();
|
481 |
// }
|
482 |
// }
|
483 |
|
484 |
for (int i = 1; i < xml.getChildrenCount(); i++) { |
485 |
try {
|
486 |
IFFrame frame = FFrame.createFromXML(xml |
487 |
.getChild(i),p, layout); |
488 |
layout.layoutContext.addFFrame(frame,true,frame.getSelected()==IFFrame.RECT);
|
489 |
} catch (OpenException e) {
|
490 |
e.showError(); |
491 |
} |
492 |
} |
493 |
|
494 |
//layout.layoutContext.getEFS().endComplexCommand(PluginServices.getText(layout,"Inicializando"));
|
495 |
IFFrame[] fframes = layout.getLayoutContext().getAllFFrames();
|
496 |
for (int i = 0; i < fframes.length; i++) { |
497 |
fframes[i].setLayout(layout); |
498 |
if (fframes[i] instanceof IFFrameViewDependence) { |
499 |
try {
|
500 |
((IFFrameViewDependence) fframes[i]) |
501 |
.initDependence(fframes); |
502 |
}catch (Exception e) { |
503 |
System.out.println("Fallo FFrameGroup"); |
504 |
} |
505 |
} |
506 |
} |
507 |
IFFrame[] fs = layout.getLayoutContext().getFFrames();
|
508 |
for (int i = 0; i < fs.length; i++) { |
509 |
if (fs[i] instanceof FFrameGroup) { |
510 |
((IFFrameViewDependence) fs[i]).initDependence(fframes); |
511 |
} |
512 |
} |
513 |
} catch (Exception e) { |
514 |
throw new OpenException(e, layout.getClass().getName()); |
515 |
} |
516 |
return layout;
|
517 |
} |
518 |
|
519 |
/**
|
520 |
* It creates an Object of this class from the information of the XMLEntity.
|
521 |
*
|
522 |
* @param xml
|
523 |
* XMLEntity
|
524 |
* @param p
|
525 |
* Project.
|
526 |
*
|
527 |
* @return Object of this class.
|
528 |
* @throws OpenException
|
529 |
*/
|
530 |
public static Layout createLayout03(XMLEntity xml, Project p) { |
531 |
Layout layout = new Layout();
|
532 |
layout.layoutContext.setAdjustToGrid(xml.getBooleanProperty("isCuadricula"));
|
533 |
layout.setName(xml.getStringProperty("m_name"));
|
534 |
layout.getLayoutContext().setAtributes(Attributes.createAtributes03(xml.getChild(0))); |
535 |
|
536 |
for (int i = 1; i < xml.getChildrenCount(); i++) { |
537 |
if (xml.getChild(i).getStringProperty("className").equals( |
538 |
"com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
|
539 |
layout.layoutContext.addFFrame(FFrame.createFromXML03(xml.getChild(i),p, layout), true, false); |
540 |
} |
541 |
} |
542 |
|
543 |
for (int i = 1; i < xml.getChildrenCount(); i++) { |
544 |
if (!xml.getChild(i).getStringProperty("className").equals( |
545 |
"com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
|
546 |
layout.layoutContext.addFFrame(FFrame.createFromXML03(xml.getChild(i), p, layout), true, false); |
547 |
} |
548 |
} |
549 |
|
550 |
return layout;
|
551 |
} |
552 |
|
553 |
/**
|
554 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
|
555 |
*/
|
556 |
public void windowActivated() { |
557 |
//fullRect();
|
558 |
layoutControl.refresh(); |
559 |
PluginServices.getMainFrame().getStatusBar().setMessage("units",
|
560 |
PluginServices.getText(this, layoutContext.getAtributes().getNameUnit()));
|
561 |
// ensure requestFocus is enabled
|
562 |
if(!layoutControl.isRequestFocusEnabled()) {
|
563 |
layoutControl.setRequestFocusEnabled(true);
|
564 |
} |
565 |
requestFocus(); |
566 |
layoutControl.requestFocus(); |
567 |
} |
568 |
|
569 |
/**
|
570 |
* @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
|
571 |
*/
|
572 |
public Object getWindowModel() { |
573 |
return map;
|
574 |
} |
575 |
/**
|
576 |
* Returns ProjectMap, the model of Layout.
|
577 |
* @return ProjectMap.
|
578 |
*/
|
579 |
public ProjectMap getModel() {
|
580 |
return map;
|
581 |
} |
582 |
/**
|
583 |
* @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
|
584 |
*/
|
585 |
public void extentChanged(ExtentEvent e) { |
586 |
} |
587 |
|
588 |
/**
|
589 |
* @see com.iver.andami.ui.mdiManager.IWindowListener#windowClosed()
|
590 |
*/
|
591 |
public void windowClosed() { |
592 |
// /PluginServices.getMainFrame().getStatusBar().setMessage("1","");
|
593 |
} |
594 |
|
595 |
/**
|
596 |
* @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
|
597 |
*/
|
598 |
public void backColorChanged(ColorEvent e) { |
599 |
// refresh();
|
600 |
} |
601 |
|
602 |
/**
|
603 |
* Opens a dialog where to pick a PDF-file to save the current Layout
|
604 |
* suggesting a name for the file given by the first argument
|
605 |
*
|
606 |
* @param suggestedName
|
607 |
*/
|
608 |
public void layoutToPDF(String suggestedName) { |
609 |
FileFilter pdfFilter = new GenericFileFilter("pdf", PluginServices |
610 |
.getText(this, "pdf")); |
611 |
|
612 |
JFileChooser jfc = new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath); |
613 |
if (suggestedName != null) |
614 |
jfc.setSelectedFile(new File(suggestedName)); |
615 |
jfc.addChoosableFileFilter(pdfFilter); |
616 |
jfc.setFileFilter(pdfFilter); |
617 |
|
618 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
619 |
File f = jfc.getSelectedFile();
|
620 |
File faux = null; |
621 |
|
622 |
if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) { |
623 |
faux = f; |
624 |
} else {
|
625 |
faux = new File(f.getPath() + ".pdf"); |
626 |
} |
627 |
|
628 |
layoutControl.getLayoutDraw().toPDF(faux); |
629 |
} |
630 |
} |
631 |
/**
|
632 |
* Opens a dialog where to pick a PS-file to save the current Layout
|
633 |
* suggesting a name for the file given by the first argument
|
634 |
*
|
635 |
* @param suggestedName
|
636 |
*/
|
637 |
public void layoutToPS(String suggestedName) { |
638 |
FileFilter pdfFilter = new GenericFileFilter("ps", PluginServices |
639 |
.getText(this, "ps")); |
640 |
|
641 |
JFileChooser jfc = new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath); |
642 |
if (suggestedName != null) |
643 |
jfc.setSelectedFile(new File(suggestedName)); |
644 |
jfc.addChoosableFileFilter(pdfFilter); |
645 |
jfc.setFileFilter(pdfFilter); |
646 |
|
647 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
648 |
File f = jfc.getSelectedFile();
|
649 |
File faux = null; |
650 |
|
651 |
if (f.getName().endsWith(".ps") || f.getName().endsWith(".PS")) { |
652 |
faux = f; |
653 |
} else {
|
654 |
faux = new File(f.getPath() + ".ps"); |
655 |
} |
656 |
|
657 |
layoutControl.getLayoutDraw().toPS(faux); |
658 |
} |
659 |
} |
660 |
/**
|
661 |
* It opens a dialog to select pdf file where to save the Layout in this format.
|
662 |
*/
|
663 |
public void layoutToPDF() { |
664 |
layoutToPDF(null);
|
665 |
} |
666 |
/**
|
667 |
* It opens a dialog to select ps file where to save the Layout in this format.
|
668 |
*/
|
669 |
public void layoutToPS() { |
670 |
layoutToPS(null);
|
671 |
} |
672 |
/**
|
673 |
* @return Returns the bShowIconTag.
|
674 |
*/
|
675 |
public boolean isShowIconTag() { |
676 |
return bShowIconTag;
|
677 |
} |
678 |
|
679 |
/**
|
680 |
* @param modeDebug
|
681 |
* The bModeDebug to set.
|
682 |
*/
|
683 |
public void setShowIconTag(boolean modeDebug) { |
684 |
bShowIconTag = modeDebug; |
685 |
} |
686 |
|
687 |
/**
|
688 |
* Repaint the Layout.
|
689 |
*/
|
690 |
public void commandRepaint() { |
691 |
this.layoutContext.updateFFrames();
|
692 |
this.layoutControl.refresh();
|
693 |
} |
694 |
/**
|
695 |
* Repaint the Layout.
|
696 |
*/
|
697 |
public void commandRefresh() { |
698 |
commandRepaint(); |
699 |
|
700 |
} |
701 |
/**
|
702 |
* Event to change the projection.
|
703 |
*/
|
704 |
public void projectionChanged(ProjectionEvent e) { |
705 |
// TODO Auto-generated method stub
|
706 |
|
707 |
} |
708 |
/**
|
709 |
* Returns if the grid sould be show.
|
710 |
* @return True if the grid sould be show.
|
711 |
*/
|
712 |
public static boolean getDefaultShowGrid() { |
713 |
if (defaultShowGrid == null) { |
714 |
XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
|
715 |
if (xml.contains("DefaultShowLayoutGrid")) { |
716 |
defaultShowGrid = new Boolean(xml.getBooleanProperty("DefaultShowLayoutGrid")); |
717 |
} |
718 |
else {
|
719 |
// factory default is true
|
720 |
defaultShowGrid = new Boolean(true); |
721 |
} |
722 |
} |
723 |
return defaultShowGrid.booleanValue();
|
724 |
} |
725 |
/**
|
726 |
* Returns if the adjust to grid sould be actived.
|
727 |
* @return True if the adjust to grid sould be actived.
|
728 |
*/
|
729 |
public static boolean getDefaultAdjustToGrid() { |
730 |
if (defaultAdjustToGrid == null) { |
731 |
XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
|
732 |
if (xml.contains("DefaultEnableLayoutGrid")) { |
733 |
defaultAdjustToGrid = new Boolean(xml.getBooleanProperty("DefaultEnableLayoutGrid")); |
734 |
} |
735 |
else {
|
736 |
// factory default is false
|
737 |
defaultAdjustToGrid = new Boolean(false); |
738 |
} |
739 |
} |
740 |
return defaultAdjustToGrid.booleanValue();
|
741 |
} |
742 |
/**
|
743 |
* Returns if the ruler sould be show.
|
744 |
* @return True if the ruler sould be show.
|
745 |
*/
|
746 |
public static boolean getDefaultShowRulers() { |
747 |
if (defaultShowRulers == null){ |
748 |
XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
|
749 |
if (xml.contains("DefaultShowLayoutRules")) { |
750 |
defaultShowRulers = new Boolean(xml.getBooleanProperty("DefaultShowLayoutRules")); |
751 |
} |
752 |
else {
|
753 |
// factory default is true
|
754 |
defaultShowRulers = new Boolean(true); |
755 |
} |
756 |
} |
757 |
return defaultShowRulers.booleanValue();
|
758 |
} |
759 |
/**
|
760 |
* Inserts if the grid sould be show.
|
761 |
* @param showGrid
|
762 |
*/
|
763 |
public static void setDefaultShowGrid(boolean showGrid) { |
764 |
defaultShowGrid = new Boolean(showGrid); |
765 |
} |
766 |
/**
|
767 |
* Inserts if the adjust togrid sould be actived.
|
768 |
* @param gridEnable
|
769 |
*/
|
770 |
public static void setDefaultAdjustToGrid(boolean gridEnabled) { |
771 |
defaultAdjustToGrid = new Boolean(gridEnabled); |
772 |
} |
773 |
/**
|
774 |
* Inserts if the ruler sould be show.
|
775 |
* @param showRuler
|
776 |
*/
|
777 |
public static void setDefaultShowRulers(boolean showRules) { |
778 |
defaultShowRulers = new Boolean(showRules); |
779 |
} |
780 |
|
781 |
public Object getWindowProfile() { |
782 |
return WindowInfo.EDITOR_PROFILE;
|
783 |
} |
784 |
} |