1 /*
2 Copyright (C) 2007 Dirk Huenniger
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 package org.indi.objects;
20
21 /**
22 * An object representing a single indi switch
23 *
24 * @author dirk
25 *
26 */
27 public class Switch extends Element {
28 /**
29 *
30 */
31 private static final long serialVersionUID = 1L;
32
33 /**
34 * the state of the switch
35 *
36 * @author Dirk Hünniger
37 *
38 */
39 public enum State {
40 Off, On
41 }
42
43 /**
44 * class constructor
45 *
46 * @param name
47 * the name of the Switch
48 * @param label
49 * the label of the Switch (to be used for display in the
50 * GUI)
51 * @param state
52 * the state of the Switch
53 */
54 public Switch(String name, String label, State state) {
55 super(name, label, state == State.On ? "On" : "Off");
56 }
57
58 /**
59 *
60 * @param name
61 * the name of the Switch
62 * @param value
63 * the value of the switch may be either On or Off
64 */
65 public Switch(String name, String value) {
66 super(name, null, value);
67 if (value.equals("On")) {
68 return;
69 }
70 if (value.equals("Off")) {
71 return;
72 }
73 throw new BadValueException(value);
74 }
75
76 /**
77 * set the state of the switch
78 *
79 * @param state
80 * the new state of the switch
81 */
82 public void setState(Switch.State state) {
83 this.value = state.toString();
84 };
85
86 /**
87 * class constructor
88 *
89 * @param name
90 * the name of the Switch
91 * @param label
92 * the label of the Switch (to be used for display in the
93 * GUI)
94 * @param value
95 * the value of the Switch (either On of Off)
96 */
97 public Switch(String name, String label, String value) {
98 super(name, label, value);
99 }
100
101 /**
102 *
103 * @return the state of the switch
104 */
105 public State getState() {
106 return (this.value.equals("On")) ? State.On : State.Off;
107 }
108
109 @Override
110 protected String getType() {
111 return "Switch";
112 }
113 }