01: /*
02: * PrintPreviewAction.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.actions;
13:
14: import java.awt.Window;
15: import java.awt.event.ActionEvent;
16: import javax.swing.JFrame;
17: import javax.swing.SwingUtilities;
18: import javax.swing.event.TableModelEvent;
19: import javax.swing.event.TableModelListener;
20: import workbench.gui.components.WbTable;
21: import workbench.print.PrintPreview;
22: import workbench.print.TablePrinter;
23: import workbench.resource.ResourceMgr;
24:
25: /**
26: * @author support@sql-workbench.net
27: */
28: public class PrintPreviewAction extends WbAction implements
29: TableModelListener {
30: private WbTable client;
31:
32: public PrintPreviewAction(WbTable aClient) {
33: super ();
34: this .setClient(aClient);
35: this .initMenuDefinition("MnuTxtPrintPreview");
36: this .setMenuItemName(ResourceMgr.MNU_TXT_FILE);
37: }
38:
39: public void executeAction(ActionEvent e) {
40: TablePrinter printer = new TablePrinter(this .client);
41:
42: Window w = SwingUtilities.getWindowAncestor(this .client);
43: JFrame parent = null;
44: if (w instanceof JFrame) {
45: parent = (JFrame) w;
46: }
47: PrintPreview preview = new PrintPreview(parent, printer);
48: preview.setVisible(true);
49: }
50:
51: public void tableChanged(TableModelEvent tableModelEvent) {
52: this .setEnabled(this .client.getRowCount() > 0);
53: }
54:
55: public void setClient(WbTable c) {
56: if (this.client != null) {
57: this.client.removeTableModelListener(this);
58: }
59: this.client = c;
60: if (this.client != null) {
61: this.client.addTableModelListener(this);
62: }
63: }
64: }
|