Revision 1714 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
DefaultLayoutPanel.java | ||
---|---|---|
25 | 25 |
import java.awt.Component; |
26 | 26 |
import java.awt.Graphics2D; |
27 | 27 |
import java.awt.GridBagConstraints; |
28 |
import java.awt.event.ActionEvent; |
|
29 |
import java.awt.event.ActionListener; |
|
30 | 28 |
import java.awt.geom.AffineTransform; |
31 | 29 |
import java.awt.geom.Rectangle2D; |
32 | 30 |
import java.awt.print.PageFormat; |
... | ... | |
37 | 35 |
import java.beans.PropertyChangeListener; |
38 | 36 |
import java.io.File; |
39 | 37 |
import java.util.Collections; |
40 |
|
|
41 | 38 |
import javax.print.Doc; |
42 | 39 |
import javax.print.DocFlavor; |
43 | 40 |
import javax.print.DocPrintJob; |
... | ... | |
50 | 47 |
import javax.print.event.PrintJobAdapter; |
51 | 48 |
import javax.print.event.PrintJobEvent; |
52 | 49 |
import javax.print.event.PrintJobListener; |
53 |
import javax.swing.JOptionPane; |
|
54 | 50 |
import javax.swing.JPanel; |
55 | 51 |
import javax.swing.JSplitPane; |
56 | 52 |
import javax.swing.filechooser.FileFilter; |
57 |
|
|
58 | 53 |
import org.gvsig.andami.PluginServices; |
59 | 54 |
import org.gvsig.andami.PluginsLocator; |
60 | 55 |
import org.gvsig.andami.messages.NotificationManager; |
61 |
import org.gvsig.andami.ui.mdiManager.IWindowListener; |
|
62 | 56 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
63 |
import org.gvsig.app.ApplicationLocator; |
|
64 | 57 |
import org.gvsig.app.gui.preferencespage.PreferenceKeys; |
65 | 58 |
import org.gvsig.app.project.documents.Document; |
66 | 59 |
import org.gvsig.app.project.documents.gui.WindowLayout; |
... | ... | |
72 | 65 |
import org.gvsig.app.project.documents.layout.LayoutManager; |
73 | 66 |
import org.gvsig.app.project.documents.layout.TocModelChangedNotification; |
74 | 67 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
75 |
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap; |
|
76 | 68 |
import org.gvsig.app.project.documents.layout.fframes.LayoutPanelListener; |
77 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
|
|
69 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFramePanel;
|
|
78 | 70 |
import org.gvsig.app.project.documents.layout.gui.dialogs.FConfigLayoutDialog; |
79 | 71 |
import org.gvsig.app.project.documents.layout.toc.TocModelObserver; |
80 | 72 |
import org.gvsig.app.project.documents.view.toc.gui.TOC; |
... | ... | |
143 | 135 |
/** |
144 | 136 |
* Creates a new Layout object. |
145 | 137 |
*/ |
138 |
@SuppressWarnings("LeakingThisInConstructor") |
|
146 | 139 |
public DefaultLayoutPanel() { |
147 | 140 |
DefaultLayoutControl defaultLayoutControl = new DefaultLayoutControl(); |
148 | 141 |
this.layoutControl = defaultLayoutControl; |
... | ... | |
150 | 143 |
this.initComponents(); |
151 | 144 |
} |
152 | 145 |
|
146 |
@Override |
|
153 | 147 |
public void setDocument(Document document) { |
154 | 148 |
layoutDocument = (LayoutDocument) document; |
155 | 149 |
setLayoutContext(layoutDocument.getLayoutContext()); |
156 | 150 |
this.setName(document.getName()); |
157 | 151 |
layoutDocument.addPropertyChangeListener(new PropertyChangeListener() { |
158 | 152 |
|
153 |
@Override |
|
159 | 154 |
public void propertyChange(PropertyChangeEvent evt) { |
160 | 155 |
if (evt.getPropertyName().equals("name")) { |
161 | 156 |
PluginServices |
... | ... | |
224 | 219 |
DefaultLayoutPanel.this.leftPanel.remove(toc); |
225 | 220 |
} |
226 | 221 |
|
227 |
this.getLayoutContext().addTocObserver(new TocModelObserver() { |
|
228 |
|
|
229 |
public void tocUpdated(Object observable, |
|
230 |
TocModelChangedNotification notification) { |
|
231 |
if (TocModelChangedNotification.Type.ITEM_UPDATED==notification.getType()) { |
|
232 |
if (DefaultLayoutPanel.this.toc!=null){ |
|
233 |
DefaultLayoutPanel.this.toc.repaint(); |
|
234 |
} |
|
235 |
} |
|
236 |
else if (TocModelChangedNotification.Type.MODEL_CHANGED==notification.getType()) { |
|
237 |
if (DefaultLayoutPanel.this.toc!=null){ |
|
238 |
DefaultLayoutPanel.this.toc.refresh(); |
|
239 |
} |
|
240 |
} |
|
241 |
else if (TocModelChangedNotification.Type.MODEL_SET==notification.getType()) { |
|
242 |
MapContext mapContext = notification.getModel(); |
|
243 |
if (mapContext!=null) { |
|
244 |
createToc(); |
|
245 |
} |
|
246 |
else if (DefaultLayoutPanel.this.toc!=null){ |
|
247 |
DefaultLayoutPanel.this.leftPanel.remove(DefaultLayoutPanel.this.toc); |
|
248 |
DefaultLayoutPanel.this.leftPanel.repaint(); |
|
249 |
} |
|
250 |
} |
|
251 |
} |
|
252 |
}); |
|
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 |
}); |
|
253 | 245 |
} |
254 | 246 |
} |
255 | 247 |
} |
... | ... | |
269 | 261 |
layoutControl.refresh(); |
270 | 262 |
} |
271 | 263 |
|
264 |
@Override |
|
272 | 265 |
public void obtainRect(boolean isPrint) { |
273 | 266 |
Rectangle2D r = layoutControl.getRect(); |
274 | 267 |
layoutContext.getAttributes().obtainRect(isPrint, |
... | ... | |
276 | 269 |
layoutControl.setRect(r); |
277 | 270 |
} |
278 | 271 |
|
272 |
@Override |
|
279 | 273 |
public void showFConfig() { |
280 | 274 |
FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this); |
281 | 275 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
... | ... | |
287 | 281 |
); |
288 | 282 |
} |
289 | 283 |
|
284 |
@Override |
|
290 | 285 |
public boolean showFProperties() { |
291 | 286 |
if (layoutDocument == null) { |
292 | 287 |
layoutDocument = new DefaultLayoutDocument(); |
... | ... | |
298 | 293 |
return m_propertiesLayout.isAccepted(); |
299 | 294 |
} |
300 | 295 |
|
296 |
@Override |
|
301 | 297 |
public void showPrintDialog(PrinterJob job) { |
302 | 298 |
if (job != null) { |
303 | 299 |
job.printDialog(); |
... | ... | |
357 | 353 |
if (m_cachePrintService != null) { |
358 | 354 |
DocPrintJob jobNuevo = m_cachePrintService.createPrintJob(); |
359 | 355 |
PrintJobListener pjlistener = new PrintJobAdapter() { |
360 |
|
|
356 |
@Override |
|
361 | 357 |
public void printDataTransferCompleted(PrintJobEvent e) { |
362 | 358 |
// System.out.println("Fin de impresi?n"); |
363 | 359 |
layoutControl.fullRect(); |
... | ... | |
366 | 362 |
|
367 | 363 |
jobNuevo.addPrintJobListener(pjlistener); |
368 | 364 |
|
369 |
Printable pb = null; |
|
370 |
Class repClass = null; |
|
365 |
Class repClass; |
|
371 | 366 |
try { |
372 | 367 |
repClass = Class.forName(flavor.getRepresentationClassName()); |
373 | 368 |
} catch (Throwable e) { |
... | ... | |
388 | 383 |
} |
389 | 384 |
} |
390 | 385 |
|
391 |
public IFFrameDialog createFFrameDialog(IFFrame fframe) { |
|
386 |
@Override |
|
387 |
public IFFramePanel createFFrameDialog(IFFrame fframe) { |
|
392 | 388 |
return layoutManager.createFFrameDialog(fframe, this); |
393 | 389 |
} |
394 | 390 |
|
... | ... | |
401 | 397 |
* |
402 | 398 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo() |
403 | 399 |
*/ |
400 |
@Override |
|
404 | 401 |
public WindowInfo getWindowInfo() { |
405 | 402 |
if (m_viewInfo == null) { |
406 | 403 |
m_viewInfo = |
... | ... | |
415 | 412 |
return m_viewInfo; |
416 | 413 |
} |
417 | 414 |
|
415 |
@Override |
|
418 | 416 |
public LayoutContext getLayoutContext() { |
419 | 417 |
return layoutContext; |
420 | 418 |
} |
421 | 419 |
|
420 |
@Override |
|
422 | 421 |
public LayoutControl getLayoutControl() { |
423 | 422 |
return layoutControl; |
424 | 423 |
} |
... | ... | |
426 | 425 |
/** |
427 | 426 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated() |
428 | 427 |
*/ |
428 |
@Override |
|
429 | 429 |
public void windowActivated() { |
430 | 430 |
if (layoutControl.getRect().getWidth()<=0) { |
431 | 431 |
layoutControl.fullRect(); |
... | ... | |
446 | 446 |
} |
447 | 447 |
// notify fframes |
448 | 448 |
IFFrame[] frames = layoutContext.getFFrames(); |
449 |
for (int i=0; i<frames.length; i++) {
|
|
450 |
if (frames[i] instanceof LayoutPanelListener) {
|
|
451 |
((LayoutPanelListener)frames[i]).windowActivated();
|
|
452 |
}
|
|
453 |
}
|
|
449 |
for (IFFrame frame : frames) {
|
|
450 |
if (frame instanceof LayoutPanelListener) {
|
|
451 |
((LayoutPanelListener) frame).windowActivated();
|
|
452 |
}
|
|
453 |
}
|
|
454 | 454 |
requestFocus(); |
455 | 455 |
layoutControl.getComponent().requestFocus(); |
456 | 456 |
} |
... | ... | |
458 | 458 |
/** |
459 | 459 |
* @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel() |
460 | 460 |
*/ |
461 |
@Override |
|
461 | 462 |
public Object getWindowModel() { |
462 | 463 |
return layoutDocument; |
463 | 464 |
} |
464 | 465 |
|
466 |
@Override |
|
465 | 467 |
public Document getDocument() { |
466 | 468 |
return layoutDocument; |
467 | 469 |
} |
... | ... | |
469 | 471 |
/** |
470 | 472 |
* @see org.gvsig.andami.ui.mdiManager.IWindowListener#windowClosed() |
471 | 473 |
*/ |
474 |
@Override |
|
472 | 475 |
public void windowClosed() { |
473 | 476 |
IFFrame[] frames = layoutContext.getFFrames(); |
474 |
for (int i=0; i<frames.length; i++) {
|
|
475 |
if (frames[i] instanceof LayoutPanelListener) {
|
|
476 |
((LayoutPanelListener)frames[i]).windowClosed();
|
|
477 |
}
|
|
478 |
}
|
|
477 |
for (IFFrame frame : frames) {
|
|
478 |
if (frame instanceof LayoutPanelListener) {
|
|
479 |
((LayoutPanelListener) frame).windowClosed();
|
|
480 |
}
|
|
481 |
}
|
|
479 | 482 |
} |
480 | 483 |
|
481 | 484 |
/** |
... | ... | |
485 | 488 |
// refresh(); |
486 | 489 |
} |
487 | 490 |
|
491 |
@Override |
|
488 | 492 |
public void layoutToPDF(File file) { |
489 | 493 |
layoutControl.getLayoutDraw().toPDF(file); |
490 | 494 |
} |
491 | 495 |
|
496 |
@Override |
|
492 | 497 |
public void layoutToPDF(String suggestedName) { |
493 | 498 |
FileFilter pdfFilter = |
494 | 499 |
new GenericFileFilter("pdf", PluginServices.getText(this, "pdf")); |
... | ... | |
503 | 508 |
|
504 | 509 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
505 | 510 |
File f = jfc.getSelectedFile(); |
506 |
File faux = null;
|
|
511 |
File faux; |
|
507 | 512 |
|
508 | 513 |
if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) { |
509 | 514 |
faux = f; |
... | ... | |
514 | 519 |
} |
515 | 520 |
} |
516 | 521 |
|
522 |
@Override |
|
517 | 523 |
public void layoutToPS(String suggestedName) { |
518 | 524 |
FileFilter pdfFilter = |
519 | 525 |
new GenericFileFilter("ps", PluginServices.getText(this, "ps")); |
... | ... | |
528 | 534 |
|
529 | 535 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
530 | 536 |
File f = jfc.getSelectedFile(); |
531 |
File faux = null;
|
|
537 |
File faux; |
|
532 | 538 |
|
533 | 539 |
if (f.getName().endsWith(".ps") || f.getName().endsWith(".PS")) { |
534 | 540 |
faux = f; |
... | ... | |
540 | 546 |
} |
541 | 547 |
} |
542 | 548 |
|
549 |
@Override |
|
543 | 550 |
public void layoutToPDF() { |
544 | 551 |
layoutToPDF((String)null); |
545 | 552 |
} |
546 | 553 |
|
554 |
@Override |
|
547 | 555 |
public void layoutToPS() { |
548 | 556 |
layoutToPS(null); |
549 | 557 |
} |
550 | 558 |
|
559 |
@Override |
|
551 | 560 |
public boolean isShowIconTag() { |
552 | 561 |
return bShowIconTag; |
553 | 562 |
} |
554 | 563 |
|
564 |
@Override |
|
555 | 565 |
public void setShowIconTag(boolean modeDebug) { |
556 | 566 |
bShowIconTag = modeDebug; |
557 | 567 |
} |
558 | 568 |
|
569 |
@Override |
|
559 | 570 |
public void update(Observable observable, Object notification) { |
560 | 571 |
this.layoutContext.updateFFrames(); |
561 | 572 |
this.layoutControl.refresh(); |
562 | 573 |
} |
563 | 574 |
|
575 |
@Override |
|
564 | 576 |
public Object getWindowProfile() { |
565 | 577 |
return WindowInfo.EDITOR_PROFILE; |
566 | 578 |
} |
567 | 579 |
|
580 |
@Override |
|
568 | 581 |
public void saveToState(PersistentState state) throws PersistenceException { |
569 | 582 |
state.set(LAYOUTCONTEXT_OBJECT, layoutContext); |
570 | 583 |
state.set(LAYOUTDOCUMENT_OBJECT, layoutDocument); |
571 | 584 |
} |
572 | 585 |
|
586 |
@Override |
|
573 | 587 |
public void loadFromState(PersistentState state) |
574 | 588 |
throws PersistenceException { |
575 | 589 |
this.layoutContext = (LayoutContext) state.get(LAYOUTCONTEXT_OBJECT); |
... | ... | |
591 | 605 |
} |
592 | 606 |
} |
593 | 607 |
|
608 |
@Override |
|
594 | 609 |
public WindowLayout getWindowLayout() { |
595 | 610 |
return null; |
596 | 611 |
} |
597 | 612 |
|
613 |
@Override |
|
598 | 614 |
public void setWindowLayout(WindowLayout layout) { |
599 | 615 |
|
600 | 616 |
} |
... | ... | |
618 | 634 |
* |
619 | 635 |
* @param g2 Geaphics2D |
620 | 636 |
*/ |
637 |
@Override |
|
621 | 638 |
public void drawLayoutPrint(Graphics2D g2) { |
622 | 639 |
layoutControl.setCancelDrawing(false); |
623 | 640 |
|
624 |
double scale = 0; |
|
625 |
scale = layoutControl.getRect().height / layoutContext.getAttributes().getPaperSize().getHeight() * 1; |
|
641 |
double scale = layoutControl.getRect().height / layoutContext.getAttributes().getPaperSize().getHeight() * 1; |
|
626 | 642 |
AffineTransform escalado = new AffineTransform(); |
627 | 643 |
AffineTransform translacion = new AffineTransform(); |
628 | 644 |
translacion.setToTranslation(layoutControl.getRect().getMinX(), layoutControl.getRect().getMinY()); |
... | ... | |
634 | 650 |
layoutContext.getAttributes().calculateGridGapY(layoutControl.getRect()); |
635 | 651 |
IFFrame[] fframes=layoutContext.getFFrames(); |
636 | 652 |
|
637 |
for (int i = 0; i < fframes.length; i++) { |
|
638 |
fframes[i].print( |
|
639 |
g2, |
|
640 |
layoutControl.getAT(), |
|
641 |
null, |
|
642 |
layoutContext.getAttributes().toPrintAttributes()); |
|
653 |
for (IFFrame fframe : fframes) { |
|
654 |
fframe.print(g2, layoutControl.getAT(), null, layoutContext.getAttributes().toPrintAttributes()); |
|
643 | 655 |
} |
644 | 656 |
} |
645 | 657 |
|
658 |
@Override |
|
646 | 659 |
public void hideToc() { |
647 | 660 |
if (isTocEnabled()) { |
648 | 661 |
lastPanePos = splitPane.getDividerLocation(); |
... | ... | |
650 | 663 |
} |
651 | 664 |
} |
652 | 665 |
|
666 |
@Override |
|
653 | 667 |
public void showToc() { |
654 | 668 |
if (isTocEnabled()) { |
655 | 669 |
splitPane.setDividerLocation(lastPanePos); |
Also available in: Unified diff