org.jgroups.demos.DrawCommand Maven / Gradle / Ivy
Go to download
This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including
all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and
JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up
with different versions on classes on the class path).
The newest version!
package org.jgroups.demos;
import org.jgroups.util.Streamable;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
/**
* Encapsulates information about a draw command.
* Used by the {@link Draw} and other demos.
*
*/
public class DrawCommand implements Streamable {
static final byte DRAW=1;
static final byte CLEAR=2;
byte mode;
int x;
int y;
int rgb;
public DrawCommand() { // needed for streamable
}
DrawCommand(byte mode) {
this.mode=mode;
}
DrawCommand(byte mode, int x, int y, int rgb) {
this.mode=mode;
this.x=x;
this.y=y;
this.rgb=rgb;
}
@Override
public void writeTo(DataOutput out) throws IOException {
out.writeByte(mode);
out.writeInt(x);
out.writeInt(y);
out.writeInt(rgb);
}
@Override
public void readFrom(DataInput in) throws IOException {
mode=in.readByte();
x=in.readInt();
y=in.readInt();
rgb=in.readInt();
}
public String toString() {
StringBuilder ret=new StringBuilder();
switch(mode) {
case DRAW: ret.append("DRAW(" + x + ", " + y + ") [" + rgb + "]");
break;
case CLEAR: ret.append("CLEAR");
break;
default:
return "";
}
return ret.toString();
}
}