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