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.IMacroTrigger;
31  
32  /***
33   * Filename:    $Id: TriggerRender.java,v 1.4 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: TriggerRender.java,v $
39   *  Revision 1.4  2004/07/22 03:06:50  wbogaardt
40   *  removed deprecated method calls.
41   *
42   *  Revision 1.3  2004/02/27 01:29:53  wbogaardt
43   *  modified classes so they conform to Checkstyle format in readability
44   *
45   *  Revision 1.2  2004/01/16 00:53:43  wbogaardt
46   *  Fixed a very obscure bug with the Macro Panel that it didn't added new
47   *  x10 devices to the drop down of available x10 device for the macro. Modified Macro triggers to change
48   * the events to integer verses strings cleaner this way.
49   *
50   *  Revision 1.1  2004/01/15 21:06:57  wbogaardt
51   *  new render and directory
52   *
53   *
54   */
55  public class TriggerRender extends DefaultTableCellRenderer implements X10DeviceConstants {
56  
57      private ImageIcon onBulb = AutoHomeAdminSession.LIGHTICON;
58      private ImageIcon offBulb = AutoHomeAdminSession.LIGHTICON_OFF;
59      private ImageIcon onPlug = AutoHomeAdminSession.APPLIANCEICON;
60      private ImageIcon offPlug = AutoHomeAdminSession.APPLIANCEICON_OFF;
61      private ImageIcon timeIcon = AutoHomeAdminSession.CLOCKICON;
62      private ImageIcon eventIcon = AutoHomeAdminSession.CAUTIONICON;
63  
64  
65      /***
66       * This sets up the trigger render component.
67       */
68      public TriggerRender() {
69          setHorizontalAlignment(JLabel.CENTER);
70      }
71  
72       /***
73       * This sets up the customized cell render. Return a component that has been configured to display the specified
74       * value. That component's paint method is then called to "render" the cell. If it is necessary to compute the
75       * dimensions of a list because the list cells do not have a fixed size, this method is called to
76       * generate a component on which getPreferredSize can be invoked.
77       *
78       * @param table The JTable we're painting.
79       * @param value The value returned by list.getModel().getElementAt(index).
80       * @param isSelected True if the specified cell was selected.
81       * @param hasFocus True if the specified cell has the focus.
82       * @param row The row of the selected table
83        * @param col the column of the selected table
84       * @return A component whose paint() method will render the specified value.
85       */
86      public Component getTableCellRendererComponent(JTable table, Object value,
87                                                     boolean isSelected,
88                                                     boolean hasFocus,
89                                                     int row, int col) {
90          IMacroTrigger idevice = (IMacroTrigger) value;
91          switch(idevice.getTriggerType())
92          {
93              case LAMP_MODULE_ON:
94                  super.setIcon(onBulb);
95                  return this;
96              case APPLIANCE_MODULE_ON:
97                  super.setIcon(onPlug);
98                  return this;
99              case TIMER_EVENT:
100                 super.setText("Timer");
101                 super.setIcon(timeIcon);
102                 return this;
103             case TRIGGER_EVENT:
104                 super.setText("Trigger");
105                 super.setIcon(eventIcon);
106                 return this;
107             default:
108                  return this;
109         }
110     }
111 }