1 package org.wcb.common;
2
3 import javax.swing.*;
4 import org.wcb.common.component.PrintPreviewPanel;
5 import java.awt.*;
6 import java.awt.print.PrinterJob;
7 import java.awt.print.PrinterException;
8 import java.awt.event.ActionListener;
9 import java.awt.event.ActionEvent;
10
11 /***
12 * Copyright (C) 1999 Walter Bogaardt
13 *
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2 of the License, or (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 *
28 * Project: Alice X10 Home Automation
29 * Filename: $Id: PrintPreviewDialog.java,v 1.2 2004/07/22 03:06:50 wbogaardt Exp $<BR>
30 * Abstract: Used to display Print preview panel settings.
31 *
32 * $Log: PrintPreviewDialog.java,v $
33 * Revision 1.2 2004/07/22 03:06:50 wbogaardt
34 * removed deprecated method calls.
35 *
36 * Revision 1.1 2004/02/20 23:56:20 wbogaardt
37 * added print preview dialog box
38 *
39 */
40 public class PrintPreviewDialog extends JDialog implements ActionListener{
41
42 private PrintPreviewPanel printPanel;
43
44 private JButton jbPrint = new JButton("Print");
45
46 /***
47 * This dialog takes the frame reference a calender object to to
48 * display a time dialog box. This dialog box makes it easier for the
49 * user to set the time as they can drag a slide bar across and it will
50 * change the time rather than typing in the time.
51 * @param frame main frame reference
52 * @param controller The button that will controll closing this dialog.
53 */
54 public PrintPreviewDialog(Frame frame, JButton controller){
55 super(frame,"Print Preview",true);
56 Container pane = getContentPane();
57 pane.setLayout(new BorderLayout());
58 JPanel southPanel = new JPanel();
59 southPanel.add(controller);
60 southPanel.add(jbPrint);
61 jbPrint.addActionListener(this);
62 printPanel = new PrintPreviewPanel();
63 pane.add(printPanel, BorderLayout.CENTER);
64 pane.add(southPanel, BorderLayout.SOUTH);
65 pack();
66 }
67
68 public void setPrintableText(String text){
69 printPanel.setTextArea(text);
70 }
71
72 public void actionPerformed(ActionEvent e) {
73 if (e.getSource() instanceof JButton) {
74 PrinterJob printJob = PrinterJob.getPrinterJob();
75 printJob.setPrintable(printPanel);
76 if (printJob.printDialog()) {
77 try {
78 printJob.print();
79 } catch (PrinterException ex) {
80 ex.printStackTrace();
81 }
82 }
83 }
84 }
85 }