1 package org.wcb.autohome.implementations;
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: Alice X10 Home Automation
20 */
21 import java.io.Serializable;
22 import org.wcb.autohome.interfaces.IMacro;
23 import java.util.Vector;
24
25 /***
26 *Filename: $Id: Macro.java,v 1.3 2004/02/28 00:21:49 wbogaardt Exp $
27 *
28 *Abstract: This class is a serialized place holder for a Macro object
29 * it there for has elements that are needed for the IMacro interface
30 * which is handled by the GUI.
31 *
32 * $Log: Macro.java,v $
33 * Revision 1.3 2004/02/28 00:21:49 wbogaardt
34 * fixed formating to be compliant with sun coding convention
35 *
36 * Revision 1.2 2003/10/10 21:39:07 wbogaardt
37 * modified macro triggers to use calendar in stead of strings
38 *
39 *
40 *@author wbogaardt
41 *@version 1.0
42 */
43 public class Macro implements IMacro, Serializable {
44
45 private String macroName;
46 private String description;
47 private int delay;
48 private Vector events;
49
50
51 /***
52 * Full constructor to allow building of the macro
53 * @param n Name of the macro
54 * @param desc brief description of the macro
55 * @param d Delay in minutes for the macro
56 * @param evt Vector of MacroEvent objects
57 */
58 public Macro(String n, String desc, int d, Vector evt) {
59
60 macroName = n;
61 description = new String(desc);
62 delay = d;
63 events = evt;
64 }
65
66 /***
67 * Default Constructor which automatically sets the
68 * macro name to Macro1
69 */
70 public Macro() {
71 this("Macro1", new String("NO DESCRIPTION"), 1, new Vector());
72 }
73
74 /***
75 * Clone constructor using the interface
76 * @param newO The IMacro interface to clone this object.
77 */
78 public Macro(IMacro newO) {
79 this(newO.getMacroName(), newO.getDescription(), newO.getDelay(), newO.getEvents());
80 }
81
82 /***
83 * Print routine for debugging
84 */
85 public void print() {
86 System.out.println(macroName + "\t" + description + "\t" + delay);
87 }
88
89
90
91 /***
92 *The name of the macro this gets used to
93 *assign a macro to a trigger.
94 *
95 *@param name - name of the macro
96 */
97 public void setMacroName(String name) {
98 macroName = name;
99 }
100
101 /***
102 *This is a description of from a users standpoint
103 *this description can be a phase used to describe
104 *the purpose of this macro.
105 *
106 *@param desc - string description of macro
107 */
108 public void setDescription(String desc) {
109 description = new String(desc);
110 }
111
112 /***
113 *This is the delay in minutes from when the macro is executed.
114 *It is passed on to the macro events in the JessePeterson api.
115 *
116 * @param dly - delay in minutes
117 */
118 public void setDelay(int dly) {
119 delay = dly;
120 }
121
122 /***
123 * This is a vector of Modules and their actions
124 * which are wraped in a X10Events object. This object
125 * then is enumerated through so when the macro is run
126 * the modules and the associated action will run after the
127 * delay time has passed.
128 *
129 *@param ev - of objects related to X10Events
130 */
131 public void setEvents(Vector ev) {
132 events = ev;
133 }
134
135
136
137 /***
138 *Simple accessor for the name of the macro
139 *
140 *@return Macro's assigned name
141 */
142 public String getMacroName() {
143 return macroName;
144 }
145
146 /***
147 *Description of the macro for user reference only. The default
148 *value of this is NO DESCRIPTION.
149 *
150 *@return - User description of macro.
151 */
152 public String getDescription() {
153 if (description.startsWith("") && description.length() < 1)
154 {
155 return "NO DESCRIPTION";
156 }
157 return description;
158 }
159
160 /***
161 *Delay in minutes before macro starts executing.
162 *
163 *@return - minutes in int format.
164 */
165 public int getDelay() {
166 return delay;
167 }
168
169 /***
170 *The associated modules and their actions to take for
171 *the macro. These objects are in a X10Events object.
172 *
173 *@return Vector - X10Events
174 */
175 public Vector getEvents() {
176 return events;
177 }
178 }
179
180