org.elkoserver.server.context.mods
Class Cartesian

java.lang.Object
  extended by org.elkoserver.server.context.Mod
      extended by org.elkoserver.server.context.mods.Cartesian
All Implemented Interfaces:
Cloneable, DispatchTarget, Encodable, ItemMod

public class Cartesian
extends Mod
implements ItemMod

Mod to provide an item with 2D (rectangular) geometry. This mod may only be attached to an item, not to a context or a user. This mod keeps track of a position and a rectangular extent (e.g., a width and a height). Position is reckoned relative to the object's container. Dimensions are specified by integers whose unit interpretation (e.g., pixels, inches, furlongs, attoparsecs, etc.) is left to the application.


Constructor Summary
Cartesian(int width, int height, int left, int top)
          JSON-driven constructor.
 
Method Summary
 JSONLiteral encode(EncodeControl control)
          Encode this mod for transmission or persistence.
 void move(User from, OptString into, int left, int top)
          Message handler for the 'move' message.
 
Methods inherited from class org.elkoserver.server.context.Mod
attachTo, clone, context, ensureHolding, ensureInContext, ensureReachable, ensureSameContext, ensureSameUser, holder, isEphemeral, markAsChanged, markAsEphemeral, object
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cartesian

@JSONMethod(value={"width","height","left","top"})
public Cartesian(int width,
                                 int height,
                                 int left,
                                 int top)
JSON-driven constructor.

Parameters:
width - Horizontal extent of the geometry.
height - Vertical extent of the geometry.
left - X coordinate of object position relative to container.
top - Y coordinate of object position relative to container.
Method Detail

encode

public JSONLiteral encode(EncodeControl control)
Encode this mod for transmission or persistence.

Specified by:
encode in interface Encodable
Parameters:
control - Encode control determining what flavor of encoding should be done.
Returns:
a JSON literal representing this mod.

move

@JSONMethod(value={"into","left","top"})
public void move(User from,
                                 OptString into,
                                 int left,
                                 int top)
          throws MessageHandlerException
Message handler for the 'move' message.

This message is a request from a client to move this object to a different location and/or container. If the move is successful, a corresponding 'move' message is broadcast to the context.

recv: { to:REF, op:"move", into:optREF, left:INT, top:INT }
send: { to:REF, op:"move", into:optREF, left:INT, top:INT }

Parameters:
from - The user who sent the message.
into - Container into which object should be placed (optional, defaults to same container, i.e., to leaving the container unchanged).
left - X coordinate of new position relative to container.
top - Y coordinate of new position relative to container.
Throws:
MessageHandlerException - if 'from' is not in the same context as this mod or if the proposed destination container is invalid.