1 package org.wcb.autohome.util; 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 * Filename: $Id: OpenFileDialog.java,v 1.0 1999/09/14 23:42:04 wbogaardt 21 * 22 * $Log: ModuleTablePopup.java,v $ 23 * Revision 1.13 2004/07/22 03:06:50 wbogaardt 24 * removed deprecated method calls. 25 * 26 * Revision 1.12 2004/01/16 00:53:43 wbogaardt 27 * Fixed a very obscure bug with the Macro Panel that it didn't added new 28 * x10 devices to the drop down of available x10 device for the macro. Modified Macro triggers to change the events to integer verses strings cleaner this way. 29 * 30 * Revision 1.11 2003/12/30 21:20:17 wbogaardt 31 * added new file saving dialog to actually save files in .x10 extension. 32 * 33 * Revision 1.10 2003/12/22 20:51:32 wbogaardt 34 * refactored name assignments and formatted code for readability. 35 * 36 * Revision 1.9 2003/12/13 00:29:09 wbogaardt 37 * added cm11a gateway montitor listener option. 38 * 39 * Revision 1.8 2003/12/12 23:17:36 wbogaardt 40 * javadoc comments refactored methods so they are more descriptive 41 * 42 * Revision 1.7 2003/12/12 00:37:37 wbogaardt 43 * cleaned up message printing interfaces. Also cleand up what is spoken by the speech engine 44 * 45 * Revision 1.6 2003/12/11 23:10:12 wbogaardt 46 * cleaned up exception handeling and logging of system.out messages 47 * 48 * Revision 1.5 2003/12/08 21:09:04 wbogaardt 49 * refactored old method signatures improved error handeling on windows 50 * 51 * Revision 1.4 2003/10/11 03:03:10 wbogaardt 52 * added action listener to delete menu item 53 * 54 * 55 */ 56 57 import java.awt.event.ActionListener; 58 import java.awt.event.ActionEvent; 59 import javax.swing.JPopupMenu; 60 import javax.swing.JMenuItem; 61 import javax.swing.JMenu; 62 63 import org.wcb.autohome.AutoHomeAdminSession; 64 import org.wcb.autohome.interfaces.X10DeviceConstants; 65 import org.wcb.autohome.interfaces.IX10Module; 66 import org.wcb.autohome.interfaces.I18nConstants; 67 import org.wcb.autohome.ModulePanel; 68 import org.wcb.autohome.exceptions.HomeException; 69 70 public class ModuleTablePopup extends JPopupMenu implements ActionListener,X10DeviceConstants { 71 72 private JMenuItem jmiOn, jmiOff, jmiDelete; 73 private JMenu subAllCmd; 74 private JMenuItem jmiAllLitesOn, jmiAllLitesOff, jmiAllOff; 75 private IX10Module module; 76 private ModulePanel panel_ref; 77 78 public ModuleTablePopup(ModulePanel pr){ 79 setMenus(); 80 this.panel_ref = pr; 81 } 82 83 private void setMenus() 84 { 85 jmiOn = new JMenuItem(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.ON_MENU), AutoHomeAdminSession.LIGHTICON); 86 jmiOff = new JMenuItem(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.OFF_MENU), AutoHomeAdminSession.LIGHTICON_OFF); 87 subAllCmd = new JMenu(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.HOUSE_MENU)); 88 jmiAllLitesOn = new JMenuItem(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.ALL_LIGHTS_ON_MENU), AutoHomeAdminSession.LIGHTICON); 89 jmiAllLitesOff = new JMenuItem(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.ALL_LIGHTS_OFF_MENU), AutoHomeAdminSession.LIGHTICON_OFF); 90 jmiAllOff = new JMenuItem(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.ALL_OFF_MENU), AutoHomeAdminSession.APPLIANCEICON_OFF); 91 jmiDelete = new JMenuItem(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.DELETE_MENU), AutoHomeAdminSession.DELETE_ROW_ICON); 92 add(jmiOn); 93 add(jmiOff); 94 add(jmiDelete); 95 subAllCmd.add(jmiAllLitesOn); 96 subAllCmd.add(jmiAllLitesOff); 97 subAllCmd.add(jmiAllOff); 98 add(subAllCmd); 99 100 jmiOn.addActionListener(this); 101 jmiOff.addActionListener(this); 102 jmiAllLitesOn.addActionListener(this); 103 jmiAllLitesOff.addActionListener(this); 104 jmiAllOff.addActionListener(this); 105 jmiDelete.addActionListener(this); 106 setVisible(true); 107 } 108 109 public void setModule(IX10Module x10){ 110 module = x10; 111 if (module.getType() == APPLIANCE_MODULE_ON) 112 { 113 jmiAllLitesOn.setEnabled(false); 114 jmiAllLitesOff.setEnabled(false); 115 } 116 else 117 { 118 jmiAllLitesOn.setEnabled(true); 119 jmiAllLitesOff.setEnabled(true); 120 } 121 } 122 123 public void actionPerformed(ActionEvent e){ 124 Object src = e.getSource(); 125 if (src == jmiOn) onModule(); 126 if (src == jmiOff) offModule(); 127 if (src == jmiAllLitesOff) allLightsOff(); 128 if (src == jmiAllLitesOn) allLightsOn(); 129 if (src == jmiAllOff) allDevicesOff(); 130 if (src == jmiDelete) deleteRow(); 131 } 132 133 /*** 134 * This takes the selected Module and turns that device ON 135 */ 136 private void onModule(){ 137 AutoHomeAdminSession.getInstance().printMessage("Sending on command to " + module.getDescription()); 138 try 139 { 140 AutoHomeAdminSession.getInstance().sendCommandToX10Module(module, 1); 141 } 142 catch(HomeException err) 143 { 144 AutoHomeAdminSession.getInstance().printMessage("Failed Transmission because " + err); 145 } 146 } 147 148 /*** 149 * This takes the selected Module and turns that device OFF 150 */ 151 private void offModule() { 152 AutoHomeAdminSession.getInstance().printMessage("Sending off command to " + module.getDescription()); 153 try { 154 AutoHomeAdminSession.getInstance().sendCommandToX10Module(module, 0); 155 } catch(HomeException err){ 156 AutoHomeAdminSession.getInstance().printMessage("Failed Transmission because" + err); 157 } 158 } 159 160 /*** 161 * This takes the selected Module and for all of the lights in that 162 * module's house code turns them off. This is regardless if the module device 163 * is a 1-16 values since it only looks at the associated house code. 164 */ 165 private void allLightsOff(){ 166 AutoHomeAdminSession.getInstance().printMessage("All lights off in section " + module.getHouseCode()); 167 try 168 { 169 AutoHomeAdminSession.getInstance().sendCommandToSection(module.getHouseCode(), 0); 170 } 171 catch(HomeException err) 172 { 173 AutoHomeAdminSession.getInstance().printMessage("Failed Transmission because " + err); 174 } 175 } 176 177 /*** 178 * This takes the selected Module and for all of the lights in that 179 * module's house code turns them on. This is regardless if the module device 180 * is a 1-16 values since it only looks at the associated house code. 181 */ 182 private void allLightsOn(){ 183 AutoHomeAdminSession.getInstance().printMessage("All lights on in section " + module.getHouseCode()); 184 try 185 { 186 AutoHomeAdminSession.getInstance().sendCommandToSection(module.getHouseCode(), 1); 187 } 188 catch(HomeException err) 189 { 190 AutoHomeAdminSession.getInstance().printMessage("Failed Transmission because " + err); 191 } 192 } 193 194 /*** 195 * This takes the selected Module and for all devices including lights in that 196 * module's house code turns them off. This is regardless if the module device 197 * is a 1-16 values since it only looks at the associated house code. 198 */ 199 private void allDevicesOff() 200 { 201 AutoHomeAdminSession.getInstance().printMessage("All devices off in section " + module.getHouseCode()); 202 try 203 { 204 AutoHomeAdminSession.getInstance().sendCommandToSection(module.getHouseCode(), 2); 205 } 206 catch(HomeException err) 207 { 208 AutoHomeAdminSession.getInstance().printMessage("Failed Transmission because "+err); 209 } 210 } 211 212 /*** 213 *This will delete a row from the table view using a popup 214 *menue. The selected row in the table will be the item deleted. 215 *there is no warning popup, which should possibly be there. 216 * 217 */ 218 private void deleteRow() 219 { 220 this.panel_ref.deleteRow(); 221 } 222 } 223 224 225