Remove TODO file
[remote/remote-gui.git] / src / motecontrol / client / SimpleMoteStatus.java
blob8dc8f8e96bb88bf8119cf33009b5117cf5d07910
1 /*
2 * Created on Sep 19, 2005
4 * TODO To change the template for this generated file go to
5 * Window - Preferences - Java - Code Style - Code Templates
6 */
8 package diku.distlab.motecontrolclientlib.client;
9 import diku.distlab.motecontrolclientlib.protocols.motecontrol.*;
11 import java.util.Observable;
12 import java.util.Observer;
13 /**
14 * @author zept
16 * TODO To change the template for this generated type comment go to
17 * Window - Preferences - Java - Code Style - Code Templates
19 public class SimpleMoteStatus
21 // global constants
22 public static final short UNKNOWN = MsgStatus.UNKNOWN;
23 public static final short UNAVAILABLE = MsgStatus.UNAVAILABLE;
24 public static final short STOPPED = MsgStatus.STOPPED;
25 public static final short RUNNING = MsgStatus.RUNNING;
26 public static final short PROGRAMMING = MsgStatus.PROGRAMMING;
28 // local constants
29 public static final short INVALID = 60;
30 public static final short REQ_STATUS = 61;
31 public static final short REQ_START = 62;
32 public static final short REQ_STOP = 63;
33 public static final short REQ_RESET = 64;
34 public static final short REQ_PROGRAM = 65;
35 public static final short REQ_CANCELPROGRAMMING = 66;
37 protected SimpleMote mote;
38 protected short status = 0;
39 protected short lastCommand = -1;
40 protected short lastResult = -1;
42 protected ExposedObservable eventDispatcher = new ExposedObservable();
44 protected class ObserverWrapper implements Observer
46 protected SimpleMoteStatusListener listener;
47 protected SimpleMote mote;
49 public ObserverWrapper(SimpleMote mote, SimpleMoteStatusListener listener)
51 super();
52 this.listener = listener;
53 this.mote = mote;
56 public void update(Observable o, Object arg) {
57 this.listener.simpleMoteStatusChange(this.mote);
61 protected SimpleMoteStatus(SimpleMote mote)
63 this.mote = mote;
67 public short getStatus() {
68 return status;
71 public boolean isReady()
73 return status == RUNNING ||
74 status == PROGRAMMING ||
75 status == REQ_PROGRAM ||
76 status == STOPPED ||
77 status == UNKNOWN;
80 public void addChangeListener(SimpleMoteStatusListener listener)
82 eventDispatcher.addWrappedObserver(listener,new ObserverWrapper(this.mote,listener));
85 public void removeChangeListener(SimpleMoteStatusListener listener)
87 eventDispatcher.deleteWrappedObserver(listener);
90 protected void setStatus(short status)
92 this.status = status;
93 this.fireChangeEvent();
96 public short getLastCommand() {
97 return lastCommand;
101 public short getLastResult() {
102 return lastResult;
106 protected void update(MsgConfirm confirm)
108 this.lastResult = confirm.getResult().getValue();
109 this.lastCommand = confirm.getCommand().getValue();
110 this.status = confirm.getStatus().getValue();
111 this.fireChangeEvent();
114 protected void update(MsgRequest request)
116 switch (request.getCommand().getValue())
118 case MsgCommand.PROGRAM:
119 this.status = REQ_PROGRAM;
120 break;
121 case MsgCommand.CANCELPROGRAMMING:
122 this.status = REQ_CANCELPROGRAMMING;
123 break;
124 case MsgCommand.RESET:
125 this.status= REQ_RESET;
126 break;
127 case MsgCommand.START:
128 this.status= REQ_START;
129 break;
130 case MsgCommand.STATUS:
131 this.status= REQ_STATUS;
132 break;
133 case MsgCommand.STOP:
134 this.status= REQ_STOP;
135 break;
136 default:
137 this.status = INVALID;
139 this.fireChangeEvent();
142 protected void fireChangeEvent()
144 this.eventDispatcher.setChanged();
145 this.eventDispatcher.notifyObservers();