1 package org.wcb.autohome.implementations; 2 3 import org.wcb.autohome.interfaces.IRunEvent; 4 import org.wcb.autohome.interfaces.IX10Module; 5 import org.wcb.autohome.interfaces.X10DeviceConstants; 6 7 import java.io.Serializable; 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 27 * Filename: $Id: RunEvent.java,v 1.9 2004/02/28 00:21:49 wbogaardt Exp $<BR> 28 * Abstract: This is a Run event which should be executed when a monitored 29 * event detects activity. The run event can be firing off a x10 module 30 * or runing an application program. 31 * 32 * $Log: RunEvent.java,v $ 33 * Revision 1.9 2004/02/28 00:21:49 wbogaardt 34 * fixed formating to be compliant with sun coding convention 35 * 36 * Revision 1.8 2004/02/24 23:16:19 wbogaardt 37 * fixed formating to be compliant with checkstyles 38 * 39 * Revision 1.7 2004/02/06 20:06:36 wbogaardt 40 * replaced ampm drop boxes with time buttons which launch a time panel move menu items around on main panel 41 * 42 * Revision 1.6 2004/01/31 07:40:26 wbogaardt 43 * modified layout managers for the panel so that it uses the java standard layoutsrather than the FormLayout api. 44 * The purpose is to reduce dependency on non-standard layout api. 45 * 46 * Revision 1.5 2004/01/20 05:31:05 wbogaardt 47 * added speech event for runing 48 * 49 * Revision 1.4 2004/01/19 22:35:37 wbogaardt 50 * added fixes to runing events and emails so they work and added a testing of a monitored event through the table popup 51 * on a right mouse click. 52 * 53 * Revision 1.3 2004/01/18 00:48:33 wbogaardt 54 * refactored out unnecessary code and now have a functional initial design of monitoring panel 55 * 56 * Revision 1.2 2004/01/17 07:21:17 wbogaardt 57 * added serialization to run events and allow monitoring of these events to the file system to reload later 58 * 59 * Revision 1.1 2004/01/17 06:21:55 wbogaardt 60 * added new Run event interfaces 61 * 62 * 63 */ 64 public class RunEvent implements IRunEvent, Serializable { 65 66 private int iType; 67 private IX10Module iDevice; 68 private String sCommand; 69 private String[] sArguments; 70 private int iDeviceCommand; 71 private String sSpeakSentence; 72 /*** 73 * The send email constants 74 */ 75 public static final int SEND_EMAIL = 0; 76 /*** 77 * The run an application constant 78 */ 79 public static final int RUN_APPLICATION = 1; 80 /*** 81 * The speak text constant 82 */ 83 public static final int SPEAK_COMMAND = 2; 84 /*** 85 * The run an X10 event or module constant 86 */ 87 public static final int RUN_MODULE = 3; 88 89 /*** 90 * This constructor automatically runs a set of events 91 */ 92 public RunEvent() { 93 this(0, new X10Module(), X10DeviceConstants.ON_ACTION); 94 } 95 96 /*** 97 * The Constructor takes a run type see setRunType() method 98 * the X10Module interface, and the action to take place. 99 * @param iT The Run type valid valies 0-2 100 * @param mod IX10Module interface 101 * @param iAction Action type for the X10Module either ON or off 102 */ 103 public RunEvent(int iT, IX10Module mod, int iAction) { 104 this.iType = iT; 105 this.iDevice = mod; 106 this.iDeviceCommand = iAction; 107 } 108 109 /*** 110 * Sets the run type for this action. There should be only three types 111 * execute a module, execute sending email, or running 112 * an outside application. 0 send email, 1 run module, 2 run command<br> 113 * @param iT Valid values of 0-2 114 */ 115 public void setRunType(int iT) { 116 this.iType = iT; 117 } 118 119 /*** 120 * the x10 module to run only if 121 * the Run type is a value of 0. Otherwise the default is sent which is 122 * a blank X10Module Object. 123 * @param module The X10 device module to run. 124 */ 125 public void setX10Module(IX10Module module) { 126 this.iDevice = module; 127 } 128 129 /*** 130 * The module command can be one of the following from the 131 * X10DeviceConstants, which is an on event or off event; 132 * X10DeviceConstants.ON_ACTION or X10DeviceConstants.OFF_ACTION 133 * @param iCmd Either on or off command value 1 or 0 134 */ 135 public void setModuleCommand(int iCmd) { 136 this.iDeviceCommand = iCmd; 137 138 } 139 140 /*** 141 * This is the initial command to send through the command line 142 * this is usually the application name. 143 * @param sCmd The application name. 144 */ 145 public void setCommand(String sCmd) { 146 this.sCommand = sCmd; 147 } 148 149 /*** 150 * The argument parameters sent with the application name 151 * sometimes an application does not have command line parameters 152 * and that should be ok too. 153 * @param args String array of arguments for a command line execution 154 */ 155 public void setArguments(String[] args) { 156 this.sArguments = args; 157 } 158 159 /*** 160 * This saves a string of a sentence that the user 161 * wants spoken by the alice speech engine. 162 * @param sSentence Sentence to speak 163 */ 164 public void setSentence(String sSentence) { 165 this.sSpeakSentence = sSentence; 166 } 167 168 /*** 169 * Returns the run type for this action Should be only three types 170 * Either execute a module, execute sending email, or running 171 * an outside application; 172 * 0 send email, 1 run module, 2 run command 173 * @return Valid values of 0-2 174 */ 175 public int getRunType() { 176 return this.iType; 177 } 178 179 /*** 180 * Returns the x10 module to run only if 181 * the Run type is a value of 0. Otherwise the default is sent which is 182 * a blank X10Module Object. 183 * @return The X10 device module to run. 184 */ 185 public IX10Module getX10Module() { 186 if (iType == RUN_MODULE) 187 { 188 return this.iDevice; 189 } 190 return new X10Module(); 191 } 192 193 /*** 194 * Return the module command can be one of the following from the 195 * X10DeviceConstants, which is an on event or off event; 196 * X10DeviceConstants.ON_ACTION or X10DeviceConstants.OFF_ACTION 197 * @return Either on or off command value 1 or 0 198 */ 199 public int getModuleCommand() { 200 return this.iDeviceCommand; 201 } 202 203 /*** 204 * Returns the initial command to sent through the command line 205 * this is usually the application name. 206 * @return The application name. 207 */ 208 public String getCommand() { 209 return this.sCommand; 210 } 211 212 /*** 213 * Returns the argument parameters sent with the application name 214 * sometimes an application does not have command line parameters 215 * and that should be ok too. 216 * @return String array of arguments for a command line execution 217 */ 218 public String[] getArguments() { 219 return this.sArguments; 220 } 221 222 /*** 223 * Returns the sentence that the user want's the speech engine 224 * to speak. 225 * @return Sentence to speak. 226 */ 227 public String getSentence() { 228 return this.sSpeakSentence; 229 } 230 231 }