svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / gui / DefaultLayoutPanel.java @ 1714
History | View | Annotate | Download (23.1 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.app.project.documents.layout.gui; |
23 |
|
24 |
import java.awt.BorderLayout; |
25 |
import java.awt.Component; |
26 |
import java.awt.Graphics2D; |
27 |
import java.awt.GridBagConstraints; |
28 |
import java.awt.geom.AffineTransform; |
29 |
import java.awt.geom.Rectangle2D; |
30 |
import java.awt.print.PageFormat; |
31 |
import java.awt.print.Printable; |
32 |
import java.awt.print.PrinterException; |
33 |
import java.awt.print.PrinterJob; |
34 |
import java.beans.PropertyChangeEvent; |
35 |
import java.beans.PropertyChangeListener; |
36 |
import java.io.File; |
37 |
import java.util.Collections; |
38 |
import javax.print.Doc; |
39 |
import javax.print.DocFlavor; |
40 |
import javax.print.DocPrintJob; |
41 |
import javax.print.PrintException; |
42 |
import javax.print.PrintService; |
43 |
import javax.print.PrintServiceLookup; |
44 |
import javax.print.ServiceUI; |
45 |
import javax.print.SimpleDoc; |
46 |
import javax.print.attribute.PrintRequestAttributeSet; |
47 |
import javax.print.event.PrintJobAdapter; |
48 |
import javax.print.event.PrintJobEvent; |
49 |
import javax.print.event.PrintJobListener; |
50 |
import javax.swing.JPanel; |
51 |
import javax.swing.JSplitPane; |
52 |
import javax.swing.filechooser.FileFilter; |
53 |
import org.gvsig.andami.PluginServices; |
54 |
import org.gvsig.andami.PluginsLocator; |
55 |
import org.gvsig.andami.messages.NotificationManager; |
56 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
57 |
import org.gvsig.app.gui.preferencespage.PreferenceKeys; |
58 |
import org.gvsig.app.project.documents.Document; |
59 |
import org.gvsig.app.project.documents.gui.WindowLayout; |
60 |
import org.gvsig.app.project.documents.layout.DefaultLayoutControl; |
61 |
import org.gvsig.app.project.documents.layout.DefaultLayoutDocument; |
62 |
import org.gvsig.app.project.documents.layout.LayoutContext; |
63 |
import org.gvsig.app.project.documents.layout.LayoutControl; |
64 |
import org.gvsig.app.project.documents.layout.LayoutDocument; |
65 |
import org.gvsig.app.project.documents.layout.LayoutManager; |
66 |
import org.gvsig.app.project.documents.layout.TocModelChangedNotification; |
67 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
68 |
import org.gvsig.app.project.documents.layout.fframes.LayoutPanelListener; |
69 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFramePanel; |
70 |
import org.gvsig.app.project.documents.layout.gui.dialogs.FConfigLayoutDialog; |
71 |
import org.gvsig.app.project.documents.layout.toc.TocModelObserver; |
72 |
import org.gvsig.app.project.documents.view.toc.gui.TOC; |
73 |
import org.gvsig.fmap.mapcontext.MapContext; |
74 |
import org.gvsig.fmap.mapcontext.events.ColorEvent; |
75 |
import org.gvsig.gui.beans.swing.JFileChooser; |
76 |
import org.gvsig.tools.ToolsLocator; |
77 |
import org.gvsig.tools.dynobject.DynStruct; |
78 |
import org.gvsig.tools.i18n.I18nManager; |
79 |
import org.gvsig.tools.observer.Observable; |
80 |
import org.gvsig.tools.persistence.PersistenceManager; |
81 |
import org.gvsig.tools.persistence.PersistentState; |
82 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
83 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
84 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
85 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
86 |
import org.gvsig.utils.GenericFileFilter; |
87 |
import org.gvsig.utils.XMLEntity; |
88 |
|
89 |
/**
|
90 |
* Layout document window
|
91 |
*
|
92 |
*
|
93 |
* @author Vicente Caballero Navarro
|
94 |
*/
|
95 |
public class DefaultLayoutPanel extends LayoutPanel { |
96 |
|
97 |
private static final long serialVersionUID = 916830228032567624L; |
98 |
|
99 |
private static final int DEFAULT_HEIGHT = 450; |
100 |
|
101 |
private static final int DEFAULT_WIDTH = 700; |
102 |
|
103 |
public static final String PERSISTENCE_DEFINITION_NAME = "LayoutPanel"; |
104 |
private static final String LAYOUTCONTEXT_OBJECT = "LayoutContext"; |
105 |
private static final String LAYOUTDOCUMENT_OBJECT = "LayoutDocument"; |
106 |
|
107 |
public static final String PDF_AND_PS_FILECHOOSER = |
108 |
"PDF_AND_PS_FILECHOOSER";
|
109 |
|
110 |
public static File defaultPDFFolderPath; |
111 |
|
112 |
private MapProperties m_propertiesLayout = null; |
113 |
private PrintService[] m_cachePrintServices = null; |
114 |
private PrintService m_cachePrintService = null; |
115 |
protected LayoutDocument layoutDocument = null; |
116 |
private Doc doc = null; |
117 |
private PrintRequestAttributeSet att = null; |
118 |
private WindowInfo m_viewInfo = null; |
119 |
/**
|
120 |
* We use it when we are doing a layout and assigning tags.
|
121 |
* It is put in debug when we do a VIEW_TAGS
|
122 |
*/
|
123 |
private boolean bShowIconTag = false; |
124 |
private LayoutControl layoutControl = null; |
125 |
private LayoutContext layoutContext = null; |
126 |
private LayoutManager layoutManager = null; |
127 |
private JPanel leftPanel; |
128 |
private TOC toc = null; |
129 |
|
130 |
private JSplitPane splitPane; |
131 |
private int lastPanePos = 150; |
132 |
|
133 |
private Boolean b_isTocEnabled = null; |
134 |
|
135 |
/**
|
136 |
* Creates a new Layout object.
|
137 |
*/
|
138 |
@SuppressWarnings("LeakingThisInConstructor") |
139 |
public DefaultLayoutPanel() {
|
140 |
DefaultLayoutControl defaultLayoutControl = new DefaultLayoutControl();
|
141 |
this.layoutControl = defaultLayoutControl;
|
142 |
defaultLayoutControl.initialize(this);
|
143 |
this.initComponents();
|
144 |
} |
145 |
|
146 |
@Override
|
147 |
public void setDocument(Document document) { |
148 |
layoutDocument = (LayoutDocument) document; |
149 |
setLayoutContext(layoutDocument.getLayoutContext()); |
150 |
this.setName(document.getName());
|
151 |
layoutDocument.addPropertyChangeListener(new PropertyChangeListener() { |
152 |
|
153 |
@Override
|
154 |
public void propertyChange(PropertyChangeEvent evt) { |
155 |
if (evt.getPropertyName().equals("name")) { |
156 |
PluginServices |
157 |
.getMDIManager() |
158 |
.getWindowInfo(DefaultLayoutPanel.this) |
159 |
.setTitle( |
160 |
PluginServices.getText(this, "Mapa") + " : " |
161 |
+ (String) evt.getNewValue());
|
162 |
} |
163 |
} |
164 |
}); |
165 |
|
166 |
setToc(); |
167 |
} |
168 |
|
169 |
/**
|
170 |
* It initializes the components.
|
171 |
*/
|
172 |
private void initComponents() { |
173 |
this.setLayout(new BorderLayout()); |
174 |
if (isTocEnabled()) {
|
175 |
leftPanel = new JPanel(new BorderLayout()); |
176 |
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, |
177 |
leftPanel, layoutControl.getComponent()); |
178 |
splitPane.setResizeWeight(0.2);
|
179 |
splitPane.setOneTouchExpandable(true);
|
180 |
splitPane.setContinuousLayout(true);
|
181 |
setToc(); |
182 |
add(splitPane, BorderLayout.CENTER);
|
183 |
} |
184 |
else {
|
185 |
add(layoutControl.getComponent(), BorderLayout.CENTER);
|
186 |
} |
187 |
layoutControl.getComponent().setDoubleBuffered(true);
|
188 |
} |
189 |
|
190 |
private boolean isTocEnabled() { |
191 |
if (b_isTocEnabled==null) { |
192 |
XMLEntity entity = PluginsLocator.getManager().getPlugin(this).getPersistentXML();
|
193 |
if (entity.contains(PreferenceKeys.DEFAULT_SHOW_LAYOUT_TOC_KEY_NAME)) {
|
194 |
b_isTocEnabled = entity.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_TOC_KEY_NAME); |
195 |
} |
196 |
else {
|
197 |
b_isTocEnabled = PreferenceKeys.FACTORY_DEFAULT_SHOW_LAYOUT_TOC; |
198 |
} |
199 |
} |
200 |
return b_isTocEnabled;
|
201 |
} |
202 |
|
203 |
protected void createToc() { |
204 |
if (toc==null) { |
205 |
toc = new TOC();
|
206 |
} |
207 |
toc.setMapContext(getLayoutContext().getTocModel()); |
208 |
leftPanel.removeAll(); |
209 |
leftPanel.add(toc); |
210 |
} |
211 |
|
212 |
protected void setToc() { |
213 |
if (isTocEnabled()) {
|
214 |
if (getLayoutContext()!=null) { |
215 |
if (getLayoutContext().getTocModel()!=null) { |
216 |
createToc(); |
217 |
} |
218 |
else if (toc!=null) { |
219 |
DefaultLayoutPanel.this.leftPanel.remove(toc); |
220 |
} |
221 |
|
222 |
this.getLayoutContext().addTocObserver((Object observable, TocModelChangedNotification notification) -> { |
223 |
if (null!=notification.getType()) switch (notification.getType()) { |
224 |
case ITEM_UPDATED:
|
225 |
if (DefaultLayoutPanel.this.toc!=null){ |
226 |
DefaultLayoutPanel.this.toc.repaint(); |
227 |
} break;
|
228 |
case MODEL_CHANGED:
|
229 |
if (DefaultLayoutPanel.this.toc!=null){ |
230 |
DefaultLayoutPanel.this.toc.refresh(); |
231 |
} break;
|
232 |
case MODEL_SET:
|
233 |
MapContext mapContext = notification.getModel(); |
234 |
if (mapContext!=null) { |
235 |
createToc(); |
236 |
} |
237 |
else if (DefaultLayoutPanel.this.toc!=null){ |
238 |
DefaultLayoutPanel.this.leftPanel.remove(DefaultLayoutPanel.this.toc); |
239 |
DefaultLayoutPanel.this.leftPanel.repaint(); |
240 |
} break;
|
241 |
default:
|
242 |
break;
|
243 |
} |
244 |
}); |
245 |
} |
246 |
} |
247 |
} |
248 |
|
249 |
/**
|
250 |
* Open the dialog of Layout properties.
|
251 |
*
|
252 |
* @param job
|
253 |
* PrinterJob
|
254 |
*/
|
255 |
public void showPagePropertiesWindow(PrinterJob job) { |
256 |
PageFormat pf1;
|
257 |
|
258 |
pf1 = layoutContext.getAttributes().getPageFormat(); |
259 |
pf1 = job.pageDialog(pf1); |
260 |
layoutContext.getAttributes().setPageFormat(pf1); |
261 |
layoutControl.refresh(); |
262 |
} |
263 |
|
264 |
@Override
|
265 |
public void obtainRect(boolean isPrint) { |
266 |
Rectangle2D r = layoutControl.getRect();
|
267 |
layoutContext.getAttributes().obtainRect(isPrint, |
268 |
r, getWidth(), getHeight()); |
269 |
layoutControl.setRect(r); |
270 |
} |
271 |
|
272 |
@Override
|
273 |
public void showFConfig() { |
274 |
FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this); |
275 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
276 |
((WindowManager_v2)ToolsSwingLocator.getWindowManager()).showWindow( |
277 |
m_configLayout, |
278 |
i18n.getTranslation("Preparar_pagina"),
|
279 |
WindowManager.MODE.WINDOW, |
280 |
Collections.singletonMap("align", GridBagConstraints.CENTER) |
281 |
); |
282 |
} |
283 |
|
284 |
@Override
|
285 |
public boolean showFProperties() { |
286 |
if (layoutDocument == null) { |
287 |
layoutDocument = new DefaultLayoutDocument();
|
288 |
layoutDocument.setName(getName()); |
289 |
} |
290 |
|
291 |
m_propertiesLayout = new MapProperties(layoutDocument);
|
292 |
PluginServices.getMDIManager().addWindow(m_propertiesLayout); |
293 |
return m_propertiesLayout.isAccepted();
|
294 |
} |
295 |
|
296 |
@Override
|
297 |
public void showPrintDialog(PrinterJob job) { |
298 |
if (job != null) { |
299 |
job.printDialog(); |
300 |
|
301 |
try {
|
302 |
job.setPrintable((Printable) PluginServices
|
303 |
.getExtension(org.gvsig.app.extension.Print.class)); |
304 |
job.print(); |
305 |
} catch (PrinterException e) { |
306 |
e.printStackTrace(); |
307 |
} |
308 |
} else {
|
309 |
// Actualizar attributes
|
310 |
att = layoutContext.getAttributes().toPrintRequestAttributeSet(); |
311 |
|
312 |
// ------------------ The Printing things --------------------- //
|
313 |
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; |
314 |
|
315 |
// returns the set of printers that support printing a specific
|
316 |
// document type (such as GIF)
|
317 |
// with a specific set of attributes (such as two sided).
|
318 |
// PrintRequestAttributeSet pras = new
|
319 |
// HashPrintRequestAttributeSet();
|
320 |
// interestingly, the printer dialog's default behavior has changed
|
321 |
// with the new API: by default the dialog is not shown.
|
322 |
// So we must use the ServiceUI class to create a print dialog
|
323 |
// returns the default print service.
|
324 |
if (m_cachePrintServices == null) { |
325 |
m_cachePrintServices = |
326 |
PrintServiceLookup.lookupPrintServices(flavor, null); |
327 |
} |
328 |
|
329 |
PrintService defaultService = null; |
330 |
|
331 |
if (m_cachePrintService == null) { |
332 |
defaultService = PrintServiceLookup.lookupDefaultPrintService();
|
333 |
} |
334 |
|
335 |
// if ((defaultService == null) && (m_cachePrintService == null)) {
|
336 |
// JOptionPane.showMessageDialog((Component) PluginServices
|
337 |
// .getMainFrame(), PluginServices.getText(this,
|
338 |
// "ninguna_impresora_configurada"));
|
339 |
//
|
340 |
// return;
|
341 |
// }
|
342 |
|
343 |
if (m_cachePrintService == null) { |
344 |
m_cachePrintService = |
345 |
ServiceUI.printDialog(null, 200, 200, m_cachePrintServices, |
346 |
defaultService, flavor, att); |
347 |
} else {
|
348 |
m_cachePrintService = |
349 |
ServiceUI.printDialog(null, 200, 200, m_cachePrintServices, |
350 |
m_cachePrintService, flavor, att); |
351 |
} |
352 |
|
353 |
if (m_cachePrintService != null) { |
354 |
DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
|
355 |
PrintJobListener pjlistener = new PrintJobAdapter() { |
356 |
@Override
|
357 |
public void printDataTransferCompleted(PrintJobEvent e) { |
358 |
// System.out.println("Fin de impresi?n");
|
359 |
layoutControl.fullRect(); |
360 |
} |
361 |
}; |
362 |
|
363 |
jobNuevo.addPrintJobListener(pjlistener); |
364 |
|
365 |
Class repClass;
|
366 |
try {
|
367 |
repClass = Class.forName(flavor.getRepresentationClassName());
|
368 |
} catch (Throwable e) { |
369 |
throw new IllegalArgumentException("unknown representation class"); |
370 |
} |
371 |
|
372 |
Object printData = PluginServices.getExtension(org.gvsig.app.extension.Print.class);
|
373 |
|
374 |
doc = new SimpleDoc(printData, flavor, null); |
375 |
|
376 |
try {
|
377 |
jobNuevo.print(doc, att); |
378 |
|
379 |
} catch (PrintException pe) { |
380 |
NotificationManager.addError(pe); |
381 |
} |
382 |
} |
383 |
} |
384 |
} |
385 |
|
386 |
@Override
|
387 |
public IFFramePanel createFFrameDialog(IFFrame fframe) {
|
388 |
return layoutManager.createFFrameDialog(fframe, this); |
389 |
} |
390 |
|
391 |
/**
|
392 |
* This method is used to get <strong>an initial</strong> ViewInfo object
|
393 |
* for this Map. It is not intended to retrieve the ViewInfo object in a
|
394 |
* later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
|
395 |
* to retrieve the ViewInfo object at any time after the creation of the
|
396 |
* object.
|
397 |
*
|
398 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
|
399 |
*/
|
400 |
@Override
|
401 |
public WindowInfo getWindowInfo() {
|
402 |
if (m_viewInfo == null) { |
403 |
m_viewInfo = |
404 |
new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE
|
405 |
| WindowInfo.MAXIMIZABLE); |
406 |
m_viewInfo.setWidth(DEFAULT_WIDTH); |
407 |
m_viewInfo.setHeight(DEFAULT_HEIGHT); |
408 |
|
409 |
m_viewInfo.setTitle(PluginServices.getText(this, "Mapa") + " : " |
410 |
+ layoutDocument.getName()); |
411 |
} |
412 |
return m_viewInfo;
|
413 |
} |
414 |
|
415 |
@Override
|
416 |
public LayoutContext getLayoutContext() {
|
417 |
return layoutContext;
|
418 |
} |
419 |
|
420 |
@Override
|
421 |
public LayoutControl getLayoutControl() {
|
422 |
return layoutControl;
|
423 |
} |
424 |
|
425 |
/**
|
426 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
|
427 |
*/
|
428 |
@Override
|
429 |
public void windowActivated() { |
430 |
if (layoutControl.getRect().getWidth()<=0) { |
431 |
layoutControl.fullRect(); |
432 |
} |
433 |
else {
|
434 |
layoutControl.refresh(); |
435 |
} |
436 |
PluginServices |
437 |
.getMainFrame() |
438 |
.getStatusBar() |
439 |
.setMessage( |
440 |
"units",
|
441 |
PluginServices.getText(this, layoutContext.getAttributes()
|
442 |
.getNameUnit())); |
443 |
// ensure requestFocus is enabled
|
444 |
if (!layoutControl.getComponent().isRequestFocusEnabled()) {
|
445 |
layoutControl.getComponent().setRequestFocusEnabled(true);
|
446 |
} |
447 |
// notify fframes
|
448 |
IFFrame[] frames = layoutContext.getFFrames();
|
449 |
for (IFFrame frame : frames) {
|
450 |
if (frame instanceof LayoutPanelListener) { |
451 |
((LayoutPanelListener) frame).windowActivated(); |
452 |
} |
453 |
} |
454 |
requestFocus(); |
455 |
layoutControl.getComponent().requestFocus(); |
456 |
} |
457 |
|
458 |
/**
|
459 |
* @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
|
460 |
*/
|
461 |
@Override
|
462 |
public Object getWindowModel() { |
463 |
return layoutDocument;
|
464 |
} |
465 |
|
466 |
@Override
|
467 |
public Document getDocument() { |
468 |
return layoutDocument;
|
469 |
} |
470 |
|
471 |
/**
|
472 |
* @see org.gvsig.andami.ui.mdiManager.IWindowListener#windowClosed()
|
473 |
*/
|
474 |
@Override
|
475 |
public void windowClosed() { |
476 |
IFFrame[] frames = layoutContext.getFFrames();
|
477 |
for (IFFrame frame : frames) {
|
478 |
if (frame instanceof LayoutPanelListener) { |
479 |
((LayoutPanelListener) frame).windowClosed(); |
480 |
} |
481 |
} |
482 |
} |
483 |
|
484 |
/**
|
485 |
* @see org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener#backColorChanged(org.gvsig.fmap.mapcontext.events.ColorEvent)
|
486 |
*/
|
487 |
public void backColorChanged(ColorEvent e) { |
488 |
// refresh();
|
489 |
} |
490 |
|
491 |
@Override
|
492 |
public void layoutToPDF(File file) { |
493 |
layoutControl.getLayoutDraw().toPDF(file); |
494 |
} |
495 |
|
496 |
@Override
|
497 |
public void layoutToPDF(String suggestedName) { |
498 |
FileFilter pdfFilter =
|
499 |
new GenericFileFilter("pdf", PluginServices.getText(this, "pdf")); |
500 |
|
501 |
JFileChooser jfc =
|
502 |
new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath); |
503 |
if (suggestedName != null) { |
504 |
jfc.setSelectedFile(new File(suggestedName)); |
505 |
} |
506 |
jfc.addChoosableFileFilter(pdfFilter); |
507 |
jfc.setFileFilter(pdfFilter); |
508 |
|
509 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
510 |
File f = jfc.getSelectedFile();
|
511 |
File faux;
|
512 |
|
513 |
if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) { |
514 |
faux = f; |
515 |
} else {
|
516 |
faux = new File(f.getPath() + ".pdf"); |
517 |
} |
518 |
this.layoutToPDF(faux);
|
519 |
} |
520 |
} |
521 |
|
522 |
@Override
|
523 |
public void layoutToPS(String suggestedName) { |
524 |
FileFilter pdfFilter =
|
525 |
new GenericFileFilter("ps", PluginServices.getText(this, "ps")); |
526 |
|
527 |
JFileChooser jfc =
|
528 |
new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath); |
529 |
if (suggestedName != null) { |
530 |
jfc.setSelectedFile(new File(suggestedName)); |
531 |
} |
532 |
jfc.addChoosableFileFilter(pdfFilter); |
533 |
jfc.setFileFilter(pdfFilter); |
534 |
|
535 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
536 |
File f = jfc.getSelectedFile();
|
537 |
File faux;
|
538 |
|
539 |
if (f.getName().endsWith(".ps") || f.getName().endsWith(".PS")) { |
540 |
faux = f; |
541 |
} else {
|
542 |
faux = new File(f.getPath() + ".ps"); |
543 |
} |
544 |
|
545 |
layoutControl.getLayoutDraw().toPS(faux); |
546 |
} |
547 |
} |
548 |
|
549 |
@Override
|
550 |
public void layoutToPDF() { |
551 |
layoutToPDF((String)null); |
552 |
} |
553 |
|
554 |
@Override
|
555 |
public void layoutToPS() { |
556 |
layoutToPS(null);
|
557 |
} |
558 |
|
559 |
@Override
|
560 |
public boolean isShowIconTag() { |
561 |
return bShowIconTag;
|
562 |
} |
563 |
|
564 |
@Override
|
565 |
public void setShowIconTag(boolean modeDebug) { |
566 |
bShowIconTag = modeDebug; |
567 |
} |
568 |
|
569 |
@Override
|
570 |
public void update(Observable observable, Object notification) { |
571 |
this.layoutContext.updateFFrames();
|
572 |
this.layoutControl.refresh();
|
573 |
} |
574 |
|
575 |
@Override
|
576 |
public Object getWindowProfile() { |
577 |
return WindowInfo.EDITOR_PROFILE;
|
578 |
} |
579 |
|
580 |
@Override
|
581 |
public void saveToState(PersistentState state) throws PersistenceException { |
582 |
state.set(LAYOUTCONTEXT_OBJECT, layoutContext); |
583 |
state.set(LAYOUTDOCUMENT_OBJECT, layoutDocument); |
584 |
} |
585 |
|
586 |
@Override
|
587 |
public void loadFromState(PersistentState state) |
588 |
throws PersistenceException {
|
589 |
this.layoutContext = (LayoutContext) state.get(LAYOUTCONTEXT_OBJECT);
|
590 |
this.setDocument((LayoutDocument) state.get(LAYOUTDOCUMENT_OBJECT));
|
591 |
} |
592 |
|
593 |
public static void registerPersistent() { |
594 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
595 |
if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) { |
596 |
DynStruct definition = |
597 |
manager.addDefinition(DefaultLayoutPanel.class, |
598 |
PERSISTENCE_DEFINITION_NAME, |
599 |
"Layout panel persistence definition", null, null); |
600 |
|
601 |
definition.addDynFieldObject(LAYOUTCONTEXT_OBJECT) |
602 |
.setClassOfValue(LayoutContext.class).setMandatory(true);
|
603 |
definition.addDynFieldObject(LAYOUTDOCUMENT_OBJECT) |
604 |
.setClassOfValue(LayoutDocument.class).setMandatory(true);
|
605 |
} |
606 |
} |
607 |
|
608 |
@Override
|
609 |
public WindowLayout getWindowLayout() {
|
610 |
return null; |
611 |
} |
612 |
|
613 |
@Override
|
614 |
public void setWindowLayout(WindowLayout layout) { |
615 |
|
616 |
} |
617 |
|
618 |
private void setLayoutContext(LayoutContext theLayoutcontext) { |
619 |
this.layoutContext = theLayoutcontext;
|
620 |
this.layoutControl.setLayoutContext(theLayoutcontext);
|
621 |
layoutContext.getAttributes().calculateGridGapX(layoutControl.getRect()); |
622 |
layoutContext.getAttributes().calculateGridGapY(layoutControl.getRect()); |
623 |
layoutControl.setDefaultTool(); |
624 |
} |
625 |
|
626 |
@Override
|
627 |
public void setLayoutManager(LayoutManager layoutManager) { |
628 |
this.layoutManager = layoutManager;
|
629 |
} |
630 |
|
631 |
|
632 |
/**
|
633 |
* Method to print the Layout without modify the Affinetransform.
|
634 |
*
|
635 |
* @param g2 Geaphics2D
|
636 |
*/
|
637 |
@Override
|
638 |
public void drawLayoutPrint(Graphics2D g2) { |
639 |
layoutControl.setCancelDrawing(false);
|
640 |
|
641 |
double scale = layoutControl.getRect().height / layoutContext.getAttributes().getPaperSize().getHeight() * 1; |
642 |
AffineTransform escalado = new AffineTransform(); |
643 |
AffineTransform translacion = new AffineTransform(); |
644 |
translacion.setToTranslation(layoutControl.getRect().getMinX(), layoutControl.getRect().getMinY()); |
645 |
escalado.setToScale(scale, scale); |
646 |
layoutControl.getAT().setToIdentity(); |
647 |
layoutControl.getAT().concatenate(translacion); |
648 |
layoutControl.getAT().concatenate(escalado); |
649 |
layoutContext.getAttributes().calculateGridGapX(layoutControl.getRect()); |
650 |
layoutContext.getAttributes().calculateGridGapY(layoutControl.getRect()); |
651 |
IFFrame[] fframes=layoutContext.getFFrames();
|
652 |
|
653 |
for (IFFrame fframe : fframes) {
|
654 |
fframe.print(g2, layoutControl.getAT(), null, layoutContext.getAttributes().toPrintAttributes());
|
655 |
} |
656 |
} |
657 |
|
658 |
@Override
|
659 |
public void hideToc() { |
660 |
if (isTocEnabled()) {
|
661 |
lastPanePos = splitPane.getDividerLocation(); |
662 |
splitPane.setDividerLocation(0);
|
663 |
} |
664 |
} |
665 |
|
666 |
@Override
|
667 |
public void showToc() { |
668 |
if (isTocEnabled()) {
|
669 |
splitPane.setDividerLocation(lastPanePos); |
670 |
} |
671 |
} |
672 |
|
673 |
} |