01: /*
02: * PrintAction.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.event.ActionEvent;
15: import javax.swing.event.TableModelEvent;
16: import javax.swing.event.TableModelListener;
17: import workbench.gui.components.WbTable;
18: import workbench.print.TablePrinter;
19: import workbench.resource.ResourceMgr;
20:
21: /**
22: * @author support@sql-workbench.net
23: */
24: public class PrintAction extends WbAction implements TableModelListener {
25: private WbTable client;
26:
27: public PrintAction(WbTable aClient) {
28: super ();
29: this .setClient(aClient);
30: this .initMenuDefinition("MnuTxtPrint");
31: this .setMenuItemName(ResourceMgr.MNU_TXT_FILE);
32: this .setIcon(ResourceMgr.getImage("Print"));
33: }
34:
35: public void executeAction(ActionEvent e) {
36: TablePrinter printer = new TablePrinter(this .client);
37: printer.startPrint();
38: }
39:
40: public void tableChanged(TableModelEvent tableModelEvent) {
41: this .setEnabled(this .client.getRowCount() > 0);
42: }
43:
44: public void setClient(WbTable c) {
45: if (this.client != null) {
46: this.client.removeTableModelListener(this);
47: }
48: this.client = c;
49: if (this.client != null) {
50: this.client.addTableModelListener(this);
51: }
52: }
53: }
|