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 implementation of the light element as defined by the indi standard 23 * 24 * @author Dirk Hünniger 25 * 26 */ 27 public class Light extends Element { 28 /** 29 * 30 */ 31 private static final long serialVersionUID = 1L; 32 33 /** 34 * class constuctor 35 * 36 * @param name 37 * the name of the light (unique identyfier) 38 * @param label 39 * the label of the light (to be used by the GUI) 40 * @param state 41 * the state the light is initially in 42 */ 43 public Light(String name, String label, State state) { 44 super(name, label, stateToString(state)); 45 } 46 47 /** 48 * class constuctor 49 * 50 * @param name 51 * the name of the light (unique identyfier) 52 * @param label 53 * the label of the light (to be used by the GUI) 54 */ 55 public Light(String name, String value) { 56 super(name, null, value); 57 if (value.equals("Idle")) { 58 return; 59 } 60 if (value.equals("Ok")) { 61 return; 62 } 63 if (value.equals("Busy")) { 64 return; 65 } 66 if (value.equals("Alert")) { 67 return; 68 } 69 throw new BadValueException(value); 70 } 71 72 /** 73 * converts a state object to its string reprentation 74 * 75 * @param state 76 * the light to be converted 77 * @return the string representation of the light supplyed 78 */ 79 public static String stateToString(State state) { 80 return state == State.Idle ? "Idle" : state == State.Ok ? "Ok" 81 : state == State.Busy ? "Busy" : 82 /* state==Alert */"Alert"; 83 } 84 85 /** 86 * 87 * @return the state of the light 88 */ 89 public State getState() { 90 return State.valueOf(this.value); 91 } 92 93 @Override 94 protected String getType() { 95 // TODO Auto-generated method stub 96 return "Light"; 97 } 98 }