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 @ 308
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.event.ActionEvent; |
28 |
import java.awt.event.ActionListener; |
29 |
import java.awt.geom.AffineTransform; |
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 |
|
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.JOptionPane; |
51 |
import javax.swing.JPanel; |
52 |
import javax.swing.JSplitPane; |
53 |
import javax.swing.filechooser.FileFilter; |
54 |
|
55 |
import org.gvsig.andami.PluginServices; |
56 |
import org.gvsig.andami.PluginsLocator; |
57 |
import org.gvsig.andami.messages.NotificationManager; |
58 |
import org.gvsig.andami.ui.mdiManager.IWindowListener; |
59 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
60 |
import org.gvsig.app.ApplicationLocator; |
61 |
import org.gvsig.app.gui.preferencespage.PreferenceKeys; |
62 |
import org.gvsig.app.project.documents.Document; |
63 |
import org.gvsig.app.project.documents.gui.WindowLayout; |
64 |
import org.gvsig.app.project.documents.layout.DefaultLayoutControl; |
65 |
import org.gvsig.app.project.documents.layout.DefaultLayoutDocument; |
66 |
import org.gvsig.app.project.documents.layout.LayoutContext; |
67 |
import org.gvsig.app.project.documents.layout.LayoutControl; |
68 |
import org.gvsig.app.project.documents.layout.LayoutDocument; |
69 |
import org.gvsig.app.project.documents.layout.LayoutManager; |
70 |
import org.gvsig.app.project.documents.layout.TocModelChangedNotification; |
71 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
72 |
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap; |
73 |
import org.gvsig.app.project.documents.layout.fframes.LayoutPanelListener; |
74 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog; |
75 |
import org.gvsig.app.project.documents.layout.gui.dialogs.FConfigLayoutDialog; |
76 |
import org.gvsig.app.project.documents.layout.toc.TocModelObserver; |
77 |
import org.gvsig.app.project.documents.view.toc.gui.TOC; |
78 |
import org.gvsig.fmap.mapcontext.MapContext; |
79 |
import org.gvsig.fmap.mapcontext.events.ColorEvent; |
80 |
import org.gvsig.gui.beans.swing.JFileChooser; |
81 |
import org.gvsig.tools.ToolsLocator; |
82 |
import org.gvsig.tools.dynobject.DynStruct; |
83 |
import org.gvsig.tools.observer.Observable; |
84 |
import org.gvsig.tools.persistence.PersistenceManager; |
85 |
import org.gvsig.tools.persistence.PersistentState; |
86 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
87 |
import org.gvsig.utils.GenericFileFilter; |
88 |
import org.gvsig.utils.XMLEntity; |
89 |
|
90 |
/**
|
91 |
* Graphic representation of the elements to print.
|
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 |
private 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 |
public DefaultLayoutPanel() {
|
139 |
DefaultLayoutControl defaultLayoutControl = new DefaultLayoutControl();
|
140 |
this.layoutControl = defaultLayoutControl;
|
141 |
defaultLayoutControl.initialize(this);
|
142 |
this.initComponents();
|
143 |
} |
144 |
|
145 |
public void setDocument(Document document) { |
146 |
layoutDocument = (LayoutDocument) document; |
147 |
setLayoutContext(layoutDocument.getLayoutContext()); |
148 |
this.setName(document.getName());
|
149 |
layoutDocument.addPropertyChangeListener(new PropertyChangeListener() { |
150 |
|
151 |
public void propertyChange(PropertyChangeEvent evt) { |
152 |
if (evt.getPropertyName().equals("name")) { |
153 |
PluginServices |
154 |
.getMDIManager() |
155 |
.getWindowInfo(DefaultLayoutPanel.this) |
156 |
.setTitle( |
157 |
PluginServices.getText(this, "Mapa") + " : " |
158 |
+ (String) evt.getNewValue());
|
159 |
} |
160 |
} |
161 |
}); |
162 |
|
163 |
setToc(); |
164 |
} |
165 |
|
166 |
/**
|
167 |
* It initializes the components.
|
168 |
*/
|
169 |
private void initComponents() { |
170 |
this.setLayout(new BorderLayout()); |
171 |
if (isTocEnabled()) {
|
172 |
leftPanel = new JPanel(new BorderLayout()); |
173 |
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, |
174 |
leftPanel, layoutControl.getComponent()); |
175 |
splitPane.setResizeWeight(0.2);
|
176 |
splitPane.setOneTouchExpandable(true);
|
177 |
splitPane.setContinuousLayout(true);
|
178 |
setToc(); |
179 |
add(splitPane, BorderLayout.CENTER);
|
180 |
} |
181 |
else {
|
182 |
add(layoutControl.getComponent(), BorderLayout.CENTER);
|
183 |
} |
184 |
layoutControl.getComponent().setDoubleBuffered(true);
|
185 |
} |
186 |
|
187 |
private boolean isTocEnabled() { |
188 |
if (b_isTocEnabled==null) { |
189 |
XMLEntity entity = PluginsLocator.getManager().getPlugin(this).getPersistentXML();
|
190 |
if (entity.contains(PreferenceKeys.DEFAULT_SHOW_LAYOUT_TOC_KEY_NAME)) {
|
191 |
b_isTocEnabled = entity.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_TOC_KEY_NAME); |
192 |
} |
193 |
else {
|
194 |
b_isTocEnabled = PreferenceKeys.FACTORY_DEFAULT_SHOW_LAYOUT_TOC; |
195 |
} |
196 |
} |
197 |
return b_isTocEnabled;
|
198 |
} |
199 |
|
200 |
protected void createToc() { |
201 |
if (toc==null) { |
202 |
toc = new TOC();
|
203 |
} |
204 |
toc.setMapContext(getLayoutContext().getTocModel()); |
205 |
leftPanel.removeAll(); |
206 |
leftPanel.add(toc); |
207 |
} |
208 |
|
209 |
protected void setToc() { |
210 |
if (isTocEnabled()) {
|
211 |
if (getLayoutContext()!=null) { |
212 |
if (getLayoutContext().getTocModel()!=null) { |
213 |
createToc(); |
214 |
} |
215 |
else if (toc!=null) { |
216 |
DefaultLayoutPanel.this.leftPanel.remove(toc); |
217 |
} |
218 |
|
219 |
this.getLayoutContext().addTocObserver(new TocModelObserver() { |
220 |
|
221 |
public void tocUpdated(Object observable, |
222 |
TocModelChangedNotification notification) { |
223 |
if (TocModelChangedNotification.Type.MODEL_CHANGED==notification.getType()) {
|
224 |
if (DefaultLayoutPanel.this.toc!=null){ |
225 |
DefaultLayoutPanel.this.toc.refresh(); |
226 |
} |
227 |
} |
228 |
else if (TocModelChangedNotification.Type.MODEL_SET==notification.getType()) { |
229 |
MapContext mapContext = notification.getModel(); |
230 |
if (mapContext!=null) { |
231 |
createToc(); |
232 |
} |
233 |
else if (DefaultLayoutPanel.this.toc!=null){ |
234 |
DefaultLayoutPanel.this.leftPanel.remove(DefaultLayoutPanel.this.toc); |
235 |
DefaultLayoutPanel.this.leftPanel.repaint(); |
236 |
} |
237 |
} |
238 |
} |
239 |
}); |
240 |
} |
241 |
} |
242 |
} |
243 |
|
244 |
/**
|
245 |
* Open the dialog of Layout properties.
|
246 |
*
|
247 |
* @param job
|
248 |
* PrinterJob
|
249 |
*/
|
250 |
public void showPagePropertiesWindow(PrinterJob job) { |
251 |
PageFormat pf1;
|
252 |
|
253 |
pf1 = layoutContext.getAttributes().getPageFormat(); |
254 |
pf1 = job.pageDialog(pf1); |
255 |
layoutContext.getAttributes().setPageFormat(pf1); |
256 |
layoutControl.refresh(); |
257 |
} |
258 |
|
259 |
public void obtainRect(boolean isPrint) { |
260 |
layoutContext.getAttributes().obtainRect(isPrint, |
261 |
layoutControl.getRect(), getWidth(), getHeight()); |
262 |
} |
263 |
|
264 |
public void showFConfig() { |
265 |
FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this); |
266 |
PluginServices.getMDIManager().addCentredWindow(m_configLayout); |
267 |
} |
268 |
|
269 |
public boolean showFProperties() { |
270 |
if (layoutDocument == null) { |
271 |
layoutDocument = new DefaultLayoutDocument();
|
272 |
layoutDocument.setName(getName()); |
273 |
} |
274 |
|
275 |
m_propertiesLayout = new MapProperties(layoutDocument);
|
276 |
PluginServices.getMDIManager().addWindow(m_propertiesLayout); |
277 |
return m_propertiesLayout.isAccepted();
|
278 |
} |
279 |
|
280 |
public void showPrintDialog(PrinterJob job) { |
281 |
if (job != null) { |
282 |
job.printDialog(); |
283 |
|
284 |
try {
|
285 |
job.setPrintable((Printable) PluginServices
|
286 |
.getExtension(org.gvsig.app.extension.Print.class)); |
287 |
job.print(); |
288 |
} catch (PrinterException e) { |
289 |
e.printStackTrace(); |
290 |
} |
291 |
} else {
|
292 |
// Actualizar attributes
|
293 |
att = layoutContext.getAttributes().toPrintRequestAttributeSet(); |
294 |
|
295 |
// ------------------ The Printing things --------------------- //
|
296 |
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; |
297 |
|
298 |
// returns the set of printers that support printing a specific
|
299 |
// document type (such as GIF)
|
300 |
// with a specific set of attributes (such as two sided).
|
301 |
// PrintRequestAttributeSet pras = new
|
302 |
// HashPrintRequestAttributeSet();
|
303 |
// interestingly, the printer dialog's default behavior has changed
|
304 |
// with the new API: by default the dialog is not shown.
|
305 |
// So we must use the ServiceUI class to create a print dialog
|
306 |
// returns the default print service.
|
307 |
if (m_cachePrintServices == null) { |
308 |
m_cachePrintServices = |
309 |
PrintServiceLookup.lookupPrintServices(flavor, null); |
310 |
} |
311 |
|
312 |
PrintService defaultService = null; |
313 |
|
314 |
if (m_cachePrintService == null) { |
315 |
defaultService = PrintServiceLookup.lookupDefaultPrintService();
|
316 |
} |
317 |
|
318 |
if ((defaultService == null) && (m_cachePrintService == null)) { |
319 |
JOptionPane.showMessageDialog((Component) PluginServices |
320 |
.getMainFrame(), PluginServices.getText(this,
|
321 |
"ninguna_impresora_configurada"));
|
322 |
|
323 |
return;
|
324 |
} |
325 |
|
326 |
if (m_cachePrintService == null) { |
327 |
m_cachePrintService = |
328 |
ServiceUI.printDialog(null, 200, 200, m_cachePrintServices, |
329 |
defaultService, flavor, att); |
330 |
} else {
|
331 |
m_cachePrintService = |
332 |
ServiceUI.printDialog(null, 200, 200, m_cachePrintServices, |
333 |
m_cachePrintService, flavor, att); |
334 |
} |
335 |
|
336 |
if (m_cachePrintService != null) { |
337 |
DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
|
338 |
PrintJobListener pjlistener = new PrintJobAdapter() { |
339 |
|
340 |
public void printDataTransferCompleted(PrintJobEvent e) { |
341 |
// System.out.println("Fin de impresi?n");
|
342 |
layoutControl.fullRect(); |
343 |
} |
344 |
}; |
345 |
|
346 |
jobNuevo.addPrintJobListener(pjlistener); |
347 |
|
348 |
Printable pb = null; |
349 |
Class repClass = null; |
350 |
try {
|
351 |
repClass = Class.forName(flavor.getRepresentationClassName());
|
352 |
} catch (Throwable e) { |
353 |
throw new IllegalArgumentException("unknown representation class"); |
354 |
} |
355 |
|
356 |
Object printData = PluginServices.getExtension(org.gvsig.app.extension.Print.class);
|
357 |
|
358 |
doc = new SimpleDoc(printData, flavor, null); |
359 |
|
360 |
try {
|
361 |
jobNuevo.print(doc, att); |
362 |
|
363 |
} catch (PrintException pe) { |
364 |
NotificationManager.addError(pe); |
365 |
} |
366 |
} |
367 |
} |
368 |
} |
369 |
|
370 |
public IFFrameDialog createFFrameDialog(IFFrame fframe) {
|
371 |
return layoutManager.createFFrameDialog(fframe, this); |
372 |
} |
373 |
|
374 |
/**
|
375 |
* This method is used to get <strong>an initial</strong> ViewInfo object
|
376 |
* for this Map. It is not intended to retrieve the ViewInfo object in a
|
377 |
* later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
|
378 |
* to retrieve the ViewInfo object at any time after the creation of the
|
379 |
* object.
|
380 |
*
|
381 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
|
382 |
*/
|
383 |
public WindowInfo getWindowInfo() {
|
384 |
if (m_viewInfo == null) { |
385 |
m_viewInfo = |
386 |
new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE
|
387 |
| WindowInfo.MAXIMIZABLE); |
388 |
m_viewInfo.setWidth(DEFAULT_WIDTH); |
389 |
m_viewInfo.setHeight(DEFAULT_HEIGHT); |
390 |
|
391 |
m_viewInfo.setTitle(PluginServices.getText(this, "Mapa") + " : " |
392 |
+ layoutDocument.getName()); |
393 |
} |
394 |
return m_viewInfo;
|
395 |
} |
396 |
|
397 |
public LayoutContext getLayoutContext() {
|
398 |
return layoutContext;
|
399 |
} |
400 |
|
401 |
public LayoutControl getLayoutControl() {
|
402 |
return layoutControl;
|
403 |
} |
404 |
|
405 |
private boolean isInitConfigDialogEnabled() { |
406 |
XMLEntity entity = PluginsLocator.getManager().getPlugin(this).getPersistentXML();
|
407 |
if (entity.contains(PreferenceKeys.DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME)) {
|
408 |
return entity.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME);
|
409 |
} |
410 |
else {
|
411 |
return PreferenceKeys.FACTORY_DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_FOR_LAYOUT;
|
412 |
} |
413 |
} |
414 |
|
415 |
|
416 |
protected void onInitialConfigCanceled() { |
417 |
if (layoutDocument!=null) { |
418 |
ApplicationLocator.getManager().getUIManager().closeWindow(this);
|
419 |
ApplicationLocator.getProjectManager().getCurrentProject().removeDocument(layoutDocument); |
420 |
} |
421 |
} |
422 |
|
423 |
/**
|
424 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
|
425 |
*/
|
426 |
public void windowActivated() { |
427 |
if (getLayoutContext()!=null && !getLayoutContext().hasDocBeenOpened()) { |
428 |
getLayoutContext().setHasDocBeenOpened(true);
|
429 |
if (isInitConfigDialogEnabled()) {
|
430 |
FConfigLayoutDialog configDialog = new FConfigLayoutDialog(this, true); |
431 |
ApplicationLocator.getManager().getUIManager().addCentredWindow(configDialog); |
432 |
configDialog.addCancelButtonActionListener(new ActionListener() { |
433 |
|
434 |
public void actionPerformed(ActionEvent e) { |
435 |
DefaultLayoutPanel.this.onInitialConfigCanceled(); |
436 |
} |
437 |
|
438 |
}); |
439 |
} |
440 |
} |
441 |
layoutControl.refresh(); |
442 |
PluginServices |
443 |
.getMainFrame() |
444 |
.getStatusBar() |
445 |
.setMessage( |
446 |
"units",
|
447 |
PluginServices.getText(this, layoutContext.getAttributes()
|
448 |
.getNameUnit())); |
449 |
// ensure requestFocus is enabled
|
450 |
if (!layoutControl.getComponent().isRequestFocusEnabled()) {
|
451 |
layoutControl.getComponent().setRequestFocusEnabled(true);
|
452 |
} |
453 |
// notify fframes
|
454 |
IFFrame[] frames = layoutContext.getFFrames();
|
455 |
for (int i=0; i<frames.length; i++) { |
456 |
if (frames[i] instanceof LayoutPanelListener) { |
457 |
((LayoutPanelListener)frames[i]).windowActivated(); |
458 |
} |
459 |
} |
460 |
requestFocus(); |
461 |
layoutControl.getComponent().requestFocus(); |
462 |
} |
463 |
|
464 |
/**
|
465 |
* @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
|
466 |
*/
|
467 |
public Object getWindowModel() { |
468 |
return layoutDocument;
|
469 |
} |
470 |
|
471 |
public Document getDocument() { |
472 |
return layoutDocument;
|
473 |
} |
474 |
|
475 |
/**
|
476 |
* @see org.gvsig.andami.ui.mdiManager.IWindowListener#windowClosed()
|
477 |
*/
|
478 |
public void windowClosed() { |
479 |
IFFrame[] frames = layoutContext.getFFrames();
|
480 |
for (int i=0; i<frames.length; i++) { |
481 |
if (frames[i] instanceof LayoutPanelListener) { |
482 |
((LayoutPanelListener)frames[i]).windowClosed(); |
483 |
} |
484 |
} |
485 |
} |
486 |
|
487 |
/**
|
488 |
* @see org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener#backColorChanged(org.gvsig.fmap.mapcontext.events.ColorEvent)
|
489 |
*/
|
490 |
public void backColorChanged(ColorEvent e) { |
491 |
// refresh();
|
492 |
} |
493 |
|
494 |
public void layoutToPDF(String suggestedName) { |
495 |
FileFilter pdfFilter =
|
496 |
new GenericFileFilter("pdf", PluginServices.getText(this, "pdf")); |
497 |
|
498 |
JFileChooser jfc =
|
499 |
new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath); |
500 |
if (suggestedName != null) { |
501 |
jfc.setSelectedFile(new File(suggestedName)); |
502 |
} |
503 |
jfc.addChoosableFileFilter(pdfFilter); |
504 |
jfc.setFileFilter(pdfFilter); |
505 |
|
506 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
507 |
File f = jfc.getSelectedFile();
|
508 |
File faux = null; |
509 |
|
510 |
if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) { |
511 |
faux = f; |
512 |
} else {
|
513 |
faux = new File(f.getPath() + ".pdf"); |
514 |
} |
515 |
|
516 |
layoutControl.getLayoutDraw().toPDF(faux); |
517 |
} |
518 |
} |
519 |
|
520 |
public void layoutToPS(String suggestedName) { |
521 |
FileFilter pdfFilter =
|
522 |
new GenericFileFilter("ps", PluginServices.getText(this, "ps")); |
523 |
|
524 |
JFileChooser jfc =
|
525 |
new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath); |
526 |
if (suggestedName != null) { |
527 |
jfc.setSelectedFile(new File(suggestedName)); |
528 |
} |
529 |
jfc.addChoosableFileFilter(pdfFilter); |
530 |
jfc.setFileFilter(pdfFilter); |
531 |
|
532 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
533 |
File f = jfc.getSelectedFile();
|
534 |
File faux = null; |
535 |
|
536 |
if (f.getName().endsWith(".ps") || f.getName().endsWith(".PS")) { |
537 |
faux = f; |
538 |
} else {
|
539 |
faux = new File(f.getPath() + ".ps"); |
540 |
} |
541 |
|
542 |
layoutControl.getLayoutDraw().toPS(faux); |
543 |
} |
544 |
} |
545 |
|
546 |
public void layoutToPDF() { |
547 |
layoutToPDF(null);
|
548 |
} |
549 |
|
550 |
public void layoutToPS() { |
551 |
layoutToPS(null);
|
552 |
} |
553 |
|
554 |
public boolean isShowIconTag() { |
555 |
return bShowIconTag;
|
556 |
} |
557 |
|
558 |
public void setShowIconTag(boolean modeDebug) { |
559 |
bShowIconTag = modeDebug; |
560 |
} |
561 |
|
562 |
public void update(Observable observable, Object notification) { |
563 |
this.layoutContext.updateFFrames();
|
564 |
this.layoutControl.refresh();
|
565 |
} |
566 |
|
567 |
public Object getWindowProfile() { |
568 |
return WindowInfo.EDITOR_PROFILE;
|
569 |
} |
570 |
|
571 |
public void saveToState(PersistentState state) throws PersistenceException { |
572 |
state.set(LAYOUTCONTEXT_OBJECT, layoutContext); |
573 |
state.set(LAYOUTDOCUMENT_OBJECT, layoutDocument); |
574 |
} |
575 |
|
576 |
public void loadFromState(PersistentState state) |
577 |
throws PersistenceException {
|
578 |
this.layoutContext = (LayoutContext) state.get(LAYOUTCONTEXT_OBJECT);
|
579 |
this.layoutDocument = (LayoutDocument) state.get(LAYOUTDOCUMENT_OBJECT);
|
580 |
this.layoutControl.setLayoutContext(layoutContext);
|
581 |
} |
582 |
|
583 |
public static void registerPersistent() { |
584 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
585 |
if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) { |
586 |
DynStruct definition = |
587 |
manager.addDefinition(DefaultLayoutPanel.class, |
588 |
PERSISTENCE_DEFINITION_NAME, |
589 |
"Layout panel persistence definition", null, null); |
590 |
|
591 |
definition.addDynFieldObject(LAYOUTCONTEXT_OBJECT) |
592 |
.setClassOfValue(LayoutContext.class).setMandatory(true);
|
593 |
definition.addDynFieldObject(LAYOUTDOCUMENT_OBJECT) |
594 |
.setClassOfValue(LayoutDocument.class).setMandatory(true);
|
595 |
} |
596 |
} |
597 |
|
598 |
public WindowLayout getWindowLayout() {
|
599 |
return null; |
600 |
} |
601 |
|
602 |
public void setWindowLayout(WindowLayout layout) { |
603 |
|
604 |
} |
605 |
|
606 |
private void setLayoutContext(LayoutContext theLayoutcontext) { |
607 |
this.layoutContext = theLayoutcontext;
|
608 |
this.layoutControl.setLayoutContext(theLayoutcontext);
|
609 |
layoutContext.getAttributes().calculateGridGapX(layoutControl.getRect()); |
610 |
layoutContext.getAttributes().calculateGridGapY(layoutControl.getRect()); |
611 |
layoutControl.setDefaultTool(); |
612 |
} |
613 |
|
614 |
@Override
|
615 |
public void setLayoutManager(LayoutManager layoutManager) { |
616 |
this.layoutManager = layoutManager;
|
617 |
} |
618 |
|
619 |
|
620 |
/**
|
621 |
* Method to print the Layout without modify the Affinetransform.
|
622 |
*
|
623 |
* @param g2 Geaphics2D
|
624 |
*/
|
625 |
public void drawLayoutPrint(Graphics2D g2) { |
626 |
layoutControl.setCancelDrawing(false);
|
627 |
|
628 |
double scale = 0; |
629 |
scale = layoutControl.getRect().height / layoutContext.getAttributes().m_sizePaper.getHeight() * 1;
|
630 |
AffineTransform escalado = new AffineTransform(); |
631 |
AffineTransform translacion = new AffineTransform(); |
632 |
translacion.setToTranslation(layoutControl.getRect().getMinX(), layoutControl.getRect().getMinY()); |
633 |
escalado.setToScale(scale, scale); |
634 |
layoutControl.getAT().setToIdentity(); |
635 |
layoutControl.getAT().concatenate(translacion); |
636 |
layoutControl.getAT().concatenate(escalado); |
637 |
layoutContext.getAttributes().calculateGridGapX(layoutControl.getRect()); |
638 |
layoutContext.getAttributes().calculateGridGapY(layoutControl.getRect()); |
639 |
IFFrame[] fframes=layoutContext.getFFrames();
|
640 |
|
641 |
for (int i = 0; i < fframes.length; i++) { |
642 |
fframes[i].print( |
643 |
g2, |
644 |
layoutControl.getAT(), |
645 |
null,
|
646 |
layoutContext.getAttributes().toPrintAttributes()); |
647 |
} |
648 |
} |
649 |
|
650 |
public void hideToc() { |
651 |
if (isTocEnabled()) {
|
652 |
lastPanePos = splitPane.getDividerLocation(); |
653 |
splitPane.setDividerLocation(0);
|
654 |
} |
655 |
} |
656 |
|
657 |
public void showToc() { |
658 |
if (isTocEnabled()) {
|
659 |
splitPane.setDividerLocation(lastPanePos); |
660 |
} |
661 |
} |
662 |
|
663 |
} |