01: // $Id: DrawCommand.java,v 1.6 2006/10/09 11:35:46 belaban Exp $
02:
03: package org.jgroups.demos;
04:
05: import org.jgroups.util.Streamable;
06:
07: import java.io.DataOutputStream;
08: import java.io.IOException;
09: import java.io.DataInputStream;
10:
11: /**
12: * Encapsulates information about a draw command.
13: * Used by the {@link Draw} and other demos.
14: *
15: */
16: public class DrawCommand implements Streamable {
17: static final byte DRAW = 1;
18: static final byte CLEAR = 2;
19: byte mode;
20: int x = 0;
21: int y = 0;
22: int r = 0;
23: int g = 0;
24: int b = 0;
25:
26: public DrawCommand() { // needed for streamable
27: }
28:
29: DrawCommand(byte mode) {
30: this .mode = mode;
31: }
32:
33: DrawCommand(byte mode, int x, int y, int r, int g, int b) {
34: this .mode = mode;
35: this .x = x;
36: this .y = y;
37: this .r = r;
38: this .g = g;
39: this .b = b;
40: }
41:
42: public void writeTo(DataOutputStream out) throws IOException {
43: out.writeByte(mode);
44: out.writeInt(x);
45: out.writeInt(y);
46: out.writeInt(r);
47: out.writeInt(g);
48: out.writeInt(b);
49: }
50:
51: public void readFrom(DataInputStream in) throws IOException,
52: IllegalAccessException, InstantiationException {
53: mode = in.readByte();
54: x = in.readInt();
55: y = in.readInt();
56: r = in.readInt();
57: g = in.readInt();
58: b = in.readInt();
59: }
60:
61: public String toString() {
62: StringBuffer ret = new StringBuffer();
63: switch (mode) {
64: case DRAW:
65: ret.append("DRAW(" + x + ", " + y + ") [" + r + '|' + g
66: + '|' + b + ']');
67: break;
68: case CLEAR:
69: ret.append("CLEAR");
70: break;
71: default:
72: return "<undefined>";
73: }
74: return ret.toString();
75: }
76:
77: }
|