View Javadoc

1   package org.wcb.autohome.util.ui;
2   /***
3    * Copyright (C) 1999  Walter Bogaardt
4    *
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10   * This library is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with this library; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18   *
19   *  Project:   Home Automation Interface
20   *
21   */
22  
23  import java.awt.Component;
24  import javax.swing.JLabel;
25  import javax.swing.ImageIcon;
26  import javax.swing.JTable;
27  import javax.swing.table.DefaultTableCellRenderer;
28  import org.wcb.autohome.AutoHomeAdminSession;
29  import org.wcb.autohome.interfaces.X10DeviceConstants;
30  import org.wcb.autohome.interfaces.IX10Module;
31  
32  /***
33   * Filename:    $Id: LightRender.java,v 1.5 2004/07/22 03:06:50 wbogaardt Exp $
34   *
35   * Abstract:  This class renders an icon on a jtable cell. It helps to have
36   *             a graphical representation of the item rather than just text.
37   *
38   *  $Log: LightRender.java,v $
39   *  Revision 1.5  2004/07/22 03:06:50  wbogaardt
40   *  removed deprecated method calls.
41   *
42   *  Revision 1.4  2004/02/27 01:29:53  wbogaardt
43   *  modified classes so they conform to Checkstyle format in readability
44   *
45   *  Revision 1.3  2004/01/21 05:29:43  wbogaardt
46   *  fixed bug saving file format and added disable monitoring
47   *
48   *  Revision 1.2  2004/01/16 00:53:43  wbogaardt
49   *  Fixed a very obscure bug with the Macro Panel that it didn't added new
50   *  x10 devices to the drop down of available x10 device for the macro. Modified Macro triggers to change the events
51   * to integer verses strings cleaner this way.
52   *
53   *  Revision 1.1  2004/01/15 21:18:25  wbogaardt
54   *  moved light render from util directory to sub ui directory package
55   *
56   *  Revision 1.4  2004/01/15 21:05:20  wbogaardt
57   *  major revamp of Modules and interfaces changes overall structure of how information is stored
58   *
59   *  Revision 1.3  2003/12/22 20:51:32  wbogaardt
60   *  refactored name assignments and formatted code for readability.
61   *
62   *  Revision 1.2  2003/12/13 05:36:52  wbogaardt
63   *  fixed javadoc comments.
64   *
65   */
66  public class LightRender extends DefaultTableCellRenderer implements X10DeviceConstants {
67  
68      private ImageIcon onBulb = AutoHomeAdminSession.LIGHTICON;
69      private ImageIcon offBulb = AutoHomeAdminSession.LIGHTICON_OFF;
70      private ImageIcon onPlug = AutoHomeAdminSession.APPLIANCEICON;
71      private ImageIcon offPlug = AutoHomeAdminSession.APPLIANCEICON_OFF;
72      private ImageIcon timeIcon = AutoHomeAdminSession.CLOCKICON;
73      private ImageIcon eventIcon = AutoHomeAdminSession.CAUTIONICON;
74  
75     /***
76      * This creates a cell render that shows different icons instead of text
77      * on a JTable.
78      */
79      public LightRender() {
80          setHorizontalAlignment(JLabel.CENTER);
81      }
82  
83      /***
84       * Returns the default table cell renderer.
85       *
86       * @param table the JTable
87       * @param value the value to assign to the cell at [row, column]
88       * @param isSelected true if cell is selected
89       * @param hasFocus true if cell has focus
90       * @param row the row of the cell to render
91       * @param col the column of the cell to render
92       * @return the customized default table cell renderer
93       */
94      public Component getTableCellRendererComponent(JTable table, Object value,
95                                                     boolean isSelected,
96                                                     boolean hasFocus,
97                                                     int row, int col) {
98          int s = 0;
99          IX10Module idevice = (IX10Module) value;
100         s = idevice.getType();
101         super.setText(idevice.getFullDeviceCode());
102         switch(s)
103         {
104             case LAMP_MODULE_ON:
105                 super.setIcon(onBulb);
106                 return this;
107             case APPLIANCE_MODULE_ON:
108                 super.setIcon(onPlug);
109                 return this;
110             case TIMER_EVENT:
111                 super.setIcon(timeIcon);
112                 return this;
113             case TRIGGER_EVENT:
114                 super.setIcon(eventIcon);
115                 return this;
116             default:
117                 return this;
118         }
119     }
120 }
121