View Javadoc

1   package org.wcb.common.event;
2   
3   import org.wcb.autohome.AutoHomeAdminSession;
4   import org.wcb.autohome.interfaces.IX10Module;
5   import org.wcb.common.PrintPreviewDialog;
6   
7   import javax.swing.*;
8   import java.awt.event.ActionListener;
9   import java.awt.event.ActionEvent;
10  import java.util.Vector;
11  import java.util.Enumeration;
12  
13  /***
14   * Created by IntelliJ IDEA.
15   * User: 00u2583
16   * Date: Feb 23, 2004
17   * Time: 11:00:27 AM
18   * To change this template use Options | File Templates.
19   */
20  public class PrintListener implements ActionListener{
21  
22      private JButton jbClose = new JButton("Close");;
23      private PrintPreviewDialog printDialog = new PrintPreviewDialog(null,jbClose);
24  
25      public void actionPerformed(ActionEvent ae){
26         Object src = ae.getSource();
27          if(src == jbClose)
28          {
29              printDialog.dispose();
30          }
31          else {
32              printContent();
33          }
34      }
35  
36       private void printContent(){
37           jbClose.addActionListener(this);
38          StringBuffer printBuffer = new StringBuffer();
39          String rtn = "\n";
40          String tab = "\t";
41          printBuffer.append("Interface type is:");
42          printBuffer.append(((AutoHomeAdminSession.getInstance().getX10GatewayType() == 1 ) ? "CM11A" : "CM17A"));
43          printBuffer.append(rtn);
44          printBuffer.append("Module ID");
45          printBuffer.append(tab);
46          printBuffer.append("Name");
47          printBuffer.append(tab);
48          printBuffer.append(tab);
49          printBuffer.append("Description");
50          printBuffer.append(rtn);
51          Vector devices = AutoHomeAdminSession.getInstance().loadAllX10Devices();
52          Enumeration enumr = devices.elements();
53          while(enumr.hasMoreElements())
54          {
55              IX10Module module =  (IX10Module)enumr.nextElement();
56              printBuffer.append(module.getFullDeviceCode());
57              printBuffer.append(tab);
58              printBuffer.append(module.getName());
59              printBuffer.append(tab);
60              printBuffer.append(tab);
61              printBuffer.append(module.getDescription());
62              printBuffer.append(rtn);
63          }
64          printDialog.setPrintableText(printBuffer.toString());
65          printDialog.setVisible(true);
66      }
67  }