View Javadoc

1   package org.wcb.common.component;
2   
3   import javax.swing.*;
4   import java.awt.print.Printable;
5   import java.awt.print.PageFormat;
6   import java.awt.print.PrinterException;
7   import java.awt.*;
8   
9   /***
10   * Copyright (C) 1999  Walter Bogaardt
11   *
12   * This library is free software; you can redistribute it and/or
13   * modify it under the terms of the GNU Lesser General Public
14   * License as published by the Free Software Foundation; either
15   * version 2 of the License, or (at your option) any later version.
16   *
17   * This library is distributed in the hope that it will be useful,
18   * but WITHOUT ANY WARRANTY; without even the implied warranty of
19   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20   * Lesser General Public License for more details.
21   *
22   * You should have received a copy of the GNU Lesser General Public
23   * License along with this library; if not, write to the Free Software
24   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
25   *
26   * Project: Alice X10 Home Automation<BR>
27   * Filename:  $Id: PrintPreviewPanel.java,v 1.2 2004/07/22 03:06:50 wbogaardt Exp $<BR>
28   * Abstract: Used to display Print preview information before allowing list to print
29   *
30   * $Log: PrintPreviewPanel.java,v $
31   * Revision 1.2  2004/07/22 03:06:50  wbogaardt
32   * removed deprecated method calls.
33   *
34   * Revision 1.1  2004/02/20 23:57:30  wbogaardt
35   * added print preview panel
36   *
37   */
38  public class PrintPreviewPanel extends JPanel implements Printable{
39  
40      private JTextArea area = new JTextArea(10,40);
41  
42      public PrintPreviewPanel(){
43          area.setLineWrap(true);
44          area.setWrapStyleWord(true);
45          add(area);
46      }
47  
48      public void setTextArea(String text){
49          area.setText(text);
50      }
51  
52      public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
53          if (pi >= 1)
54          {
55              return Printable.NO_SUCH_PAGE;
56          }
57          Graphics2D g2 = (Graphics2D) g;
58          g2.translate(pf.getImageableX(), pf.getImageableY());
59          area.paint(g2);
60          return Printable.PAGE_EXISTS;
61      }
62  }