0.0.1:
-- Base classes:
- - TCommand use getters/setters
- - TCommand.Type: switch to int so that subclasses can make more
- kinds of commands
- - TMouseEvent use getters/setters to make immutable
- Get a movable window on screen
- TWidget
- TWindow
// Peek at the mouse position
if (event instanceof TMouseEvent) {
TMouseEvent mouse = (TMouseEvent) event;
- if ((mouseX != mouse.x) || (mouseY != mouse.y)) {
- mouseX = mouse.x;
- mouseY = mouse.y;
+ if ((mouseX != mouse.getX()) || (mouseY != mouse.getY())) {
+ mouseX = mouse.getX();
+ mouseY = mouse.getY();
drawMouse();
}
}
public class TCommand {
/**
- * The following types are predefined for the entire system.
- *
- * TODO: Switch this to int so that TCommand can be subclassed so that
- * applications can add more.
- */
- public enum Type {
- /**
- * Immediately abort the application (e.g. remote side closed
- * connection).
- */
- ABORT,
-
- /**
- * File open dialog.
- */
- OPEN,
-
- /**
- * Exit application.
- */
- EXIT,
-
- /**
- * Spawn OS shell window.
- */
- SHELL,
-
- /**
- * Cut selected text and copy to the clipboard.
- */
- CUT,
-
- /**
- * Copy selected text to clipboard.
- */
- COPY,
-
- /**
- * Paste from clipboard.
- */
- PASTE,
-
- /**
- * Clear selected text without copying it to the clipboard.
- */
- CLEAR,
-
- /**
- * Tile windows.
- */
- TILE,
-
- /**
- * Cascade windows.
- */
- CASCADE,
-
- /**
- * Close all windows.
- */
- CLOSE_ALL,
-
- /**
- * Move (move/resize) window.
- */
- WINDOW_MOVE,
-
- /**
- * Zoom (maximize/restore) window.
- */
- WINDOW_ZOOM,
-
- /**
- * Next window (like Alt-TAB).
- */
- WINDOW_NEXT,
-
- /**
- * Previous window (like Shift-Alt-TAB).
- */
- WINDOW_PREVIOUS,
-
- /**
- * Close window.
- */
- WINDOW_CLOSE,
+ * Immediately abort the application (e.g. remote side closed
+ * connection).
+ */
+ public static final int ABORT = 1;
- }
+ /**
+ * File open dialog.
+ */
+ public static final int OPEN = 2;
+
+ /**
+ * Exit application.
+ */
+ public static final int EXIT = 3;
+
+ /**
+ * Spawn OS shell window.
+ */
+ public static final int SHELL = 4;
+
+ /**
+ * Cut selected text and copy to the clipboard.
+ */
+ public static final int CUT = 5;
+
+ /**
+ * Copy selected text to clipboard.
+ */
+ public static final int COPY = 6;
+
+ /**
+ * Paste from clipboard.
+ */
+ public static final int PASTE = 7;
+
+ /**
+ * Clear selected text without copying it to the clipboard.
+ */
+ public static final int CLEAR = 8;
+
+ /**
+ * Tile windows.
+ */
+ public static final int TILE = 9;
+
+ /**
+ * Cascade windows.
+ */
+ public static final int CASCADE = 10;
+
+ /**
+ * Close all windows.
+ */
+ public static final int CLOSE_ALL = 11;
+
+ /**
+ * Move (move/resize) window.
+ */
+ public static final int WINDOW_MOVE = 12;
+
+ /**
+ * Zoom (maximize/restore) window.
+ */
+ public static final int WINDOW_ZOOM = 13;
+
+ /**
+ * Next window (like Alt-TAB).
+ */
+ public static final int WINDOW_NEXT = 14;
+
+ /**
+ * Previous window (like Shift-Alt-TAB).
+ */
+ public static final int WINDOW_PREVIOUS = 15;
+
+ /**
+ * Close window.
+ */
+ public static final int WINDOW_CLOSE = 16;
/**
* Type of command, one of EXIT, CASCADE, etc.
*/
- private Type type;
+ private int type;
/**
- * Public constructor.
+ * Protected constructor. Subclasses can be used to define new commands.
*
* @param type the Type of command, one of EXIT, CASCADE, etc.
*/
- public TCommand(final Type type) {
+ protected TCommand(final int type) {
this.type = type;
}
return (type == that.type);
}
- public static final TCommand cmAbort = new TCommand(TCommand.Type.ABORT);
- public static final TCommand cmExit = new TCommand(TCommand.Type.EXIT);
- public static final TCommand cmQuit = new TCommand(TCommand.Type.EXIT);
- public static final TCommand cmOpen = new TCommand(TCommand.Type.OPEN);
- public static final TCommand cmShell = new TCommand(TCommand.Type.SHELL);
- public static final TCommand cmCut = new TCommand(TCommand.Type.CUT);
- public static final TCommand cmCopy = new TCommand(TCommand.Type.COPY);
- public static final TCommand cmPaste = new TCommand(TCommand.Type.PASTE);
- public static final TCommand cmClear = new TCommand(TCommand.Type.CLEAR);
- public static final TCommand cmTile = new TCommand(TCommand.Type.TILE);
- public static final TCommand cmCascade = new TCommand(TCommand.Type.CASCADE);
- public static final TCommand cmCloseAll = new TCommand(TCommand.Type.CLOSE_ALL);
- public static final TCommand cmWindowMove = new TCommand(TCommand.Type.WINDOW_MOVE);
- public static final TCommand cmWindowZoom = new TCommand(TCommand.Type.WINDOW_ZOOM);
- public static final TCommand cmWindowNext = new TCommand(TCommand.Type.WINDOW_NEXT);
- public static final TCommand cmWindowPrevious = new TCommand(TCommand.Type.WINDOW_PREVIOUS);
- public static final TCommand cmWindowClose = new TCommand(TCommand.Type.WINDOW_CLOSE);
+ public static final TCommand cmAbort = new TCommand(ABORT);
+ public static final TCommand cmExit = new TCommand(EXIT);
+ public static final TCommand cmQuit = new TCommand(EXIT);
+ public static final TCommand cmOpen = new TCommand(OPEN);
+ public static final TCommand cmShell = new TCommand(SHELL);
+ public static final TCommand cmCut = new TCommand(CUT);
+ public static final TCommand cmCopy = new TCommand(COPY);
+ public static final TCommand cmPaste = new TCommand(PASTE);
+ public static final TCommand cmClear = new TCommand(CLEAR);
+ public static final TCommand cmTile = new TCommand(TILE);
+ public static final TCommand cmCascade = new TCommand(CASCADE);
+ public static final TCommand cmCloseAll = new TCommand(CLOSE_ALL);
+ public static final TCommand cmWindowMove = new TCommand(WINDOW_MOVE);
+ public static final TCommand cmWindowZoom = new TCommand(WINDOW_ZOOM);
+ public static final TCommand cmWindowNext = new TCommand(WINDOW_NEXT);
+ public static final TCommand cmWindowPrevious = new TCommand(WINDOW_PREVIOUS);
+ public static final TCommand cmWindowClose = new TCommand(WINDOW_CLOSE);
}
this.cmd = cmd;
}
+ /**
+ * Comparison check. All fields must match to return true.
+ *
+ * @param rhs another TCommandEvent or TCommand instance
+ * @return true if all fields are equal
+ */
+ @Override
+ public boolean equals(final Object rhs) {
+ if (!(rhs instanceof TCommandEvent)
+ && !(rhs instanceof TCommand)
+ ) {
+ return false;
+ }
+
+ if (rhs instanceof TCommandEvent) {
+ TCommandEvent that = (TCommandEvent) rhs;
+ return (cmd.equals(that.cmd)
+ && (getTime().equals(that.getTime())));
+ }
+
+ TCommand that = (TCommand) rhs;
+ return (cmd.equals(that));
+ }
+
/**
* Make human-readable description of this TCommandEvent.
*
* TApplication.getMenuItem(id) can be used to obtain the TMenuItem itself,
* say for setting enabled/disabled/checked/etc.
*/
-public class TMenuEvent extends TInputEvent {
+public final class TMenuEvent extends TInputEvent {
/**
* MenuItem ID.
*
* @return the ID
*/
- public final short getId() {
+ public short getId() {
return id;
}
* @return displayable String
*/
@Override
- public final String toString() {
+ public String toString() {
return String.format("MenuEvent: %d", id);
}
}
/**
* This class encapsulates several kinds of mouse input events.
*/
-public class TMouseEvent extends TInputEvent {
+public final class TMouseEvent extends TInputEvent {
/**
* The type of event generated.
* Type of event, one of MOUSE_MOTION, MOUSE_UP, or MOUSE_DOWN, or
* KEYPRESS.
*/
- public Type type;
+ private Type type;
+
+ /**
+ * Get type.
+ *
+ * @return type
+ */
+ public Type getType() {
+ return type;
+ }
/**
* Mouse X - relative coordinates.
*/
- public int x;
+ private int x;
+
+ /**
+ * Get x.
+ *
+ * @return x
+ */
+ public int getX() {
+ return x;
+ }
/**
* Mouse Y - relative coordinates.
*/
- public int y;
+ private int y;
+
+ /**
+ * Get y.
+ *
+ * @return y
+ */
+ public int getY() {
+ return y;
+ }
/**
* Mouse X - absolute screen coordinates.
*/
- public int absoluteX;
+ private int absoluteX;
+
+ /**
+ * Get absoluteX.
+ *
+ * @return absoluteX
+ */
+ public int getAbsoluteX() {
+ return absoluteX;
+ }
/**
* Mouse Y - absolute screen coordinate.
*/
- public int absoluteY;
+ private int absoluteY;
+
+ /**
+ * Get absoluteY.
+ *
+ * @return absoluteY
+ */
+ public int getAbsoluteY() {
+ return absoluteY;
+ }
/**
* Mouse button 1 (left button).
*/
- public boolean mouse1;
+ private boolean mouse1;
+
+ /**
+ * Get mouse1.
+ *
+ * @return mouse1
+ */
+ public boolean getMouse1() {
+ return mouse1;
+ }
/**
* Mouse button 2 (right button).
*/
- public boolean mouse2;
+ private boolean mouse2;
+
+ /**
+ * Get mouse2.
+ *
+ * @return mouse2
+ */
+ public boolean getMouse2() {
+ return mouse2;
+ }
/**
* Mouse button 3 (middle button).
*/
- public boolean mouse3;
+ private boolean mouse3;
+
+ /**
+ * Get mouse3.
+ *
+ * @return mouse3
+ */
+ public boolean getMouse3() {
+ return mouse3;
+ }
/**
* Mouse wheel UP (button 4).
*/
- public boolean mouseWheelUp;
+ private boolean mouseWheelUp;
+
+ /**
+ * Get mouseWheelUp.
+ *
+ * @return mouseWheelUp
+ */
+ public boolean getMouseWheelUp() {
+ return mouseWheelUp;
+ }
/**
* Mouse wheel DOWN (button 5).
*/
- public boolean mouseWheelDown;
+ private boolean mouseWheelDown;
+
+ /**
+ * Get mouseWheelDown.
+ *
+ * @return mouseWheelDown
+ */
+ public boolean getMouseWheelDown() {
+ return mouseWheelDown;
+ }
/**
* Public contructor.
*
* @param type the type of event, MOUSE_MOTION, MOUSE_DOWN, or MOUSE_UP
+ * @param x relative column
+ * @param y relative row
+ * @param absoluteX absolute column
+ * @param absoluteY absolute row
+ * @param mouse1 if true, left button is down
+ * @param mouse2 if true, right button is down
+ * @param mouse3 if true, middle button is down
+ * @param mouseWheelUp if true, mouse wheel (button 4) is down
+ * @param mouseWheelDown if true, mouse wheel (button 5) is down
*/
- public TMouseEvent(final Type type) {
- this.type = type;
+ public TMouseEvent(final Type type, final int x, final int y,
+ final int absoluteX, final int absoluteY,
+ final boolean mouse1, final boolean mouse2, final boolean mouse3,
+ final boolean mouseWheelUp, final boolean mouseWheelDown) {
+
+ this.type = type;
+ this.x = x;
+ this.y = y;
+ this.absoluteX = absoluteX;
+ this.absoluteY = absoluteY;
+ this.mouse1 = mouse1;
+ this.mouse2 = mouse2;
+ this.mouse3 = mouse3;
+ this.mouseWheelUp = mouseWheelUp;
+ this.mouseWheelDown = mouseWheelDown;
}
/**
* @return displayable String
*/
@Override
- public final String toString() {
+ public String toString() {
return String.format("Mouse: %s x %d y %d absoluteX %d absoluteY %d 1 %s 2 %s 3 %s DOWN %s UP %s",
type,
x, y,
/**
* This class encapsulates a screen or window resize event.
*/
-public class TResizeEvent extends TInputEvent {
+public final class TResizeEvent extends TInputEvent {
/**
* Resize events can be generated for either a total screen resize or a
*
* @return SCREEN or WIDGET
*/
- public final Type getType() {
+ public Type getType() {
return type;
}
*
* @return width
*/
- public final int getWidth() {
+ public int getWidth() {
return width;
}
*
* @return height
*/
- public final int getHeight() {
- return width;
+ public int getHeight() {
+ return height;
}
/**
* @return displayable String
*/
@Override
- public final String toString() {
+ public String toString() {
return String.format("Resize: %s width = %d height = %d",
type, width, height);
}
// Unknown modifier, bail out
return null;
}
-
+
switch (key) {
case 1:
return new TKeypressEvent(kbHome, alt, ctrl, shift);
y = windowResize.getHeight() - 1;
}
- TMouseEvent event = new TMouseEvent(TMouseEvent.Type.MOUSE_DOWN);
- event.x = x;
- event.y = y;
- event.absoluteX = x;
- event.absoluteY = y;
+ TMouseEvent.Type eventType = TMouseEvent.Type.MOUSE_DOWN;
+ boolean eventMouse1 = false;
+ boolean eventMouse2 = false;
+ boolean eventMouse3 = false;
+ boolean eventMouseWheelUp = false;
+ boolean eventMouseWheelDown = false;
// System.err.printf("buttons: %04x\r\n", buttons);
switch (buttons) {
case 0:
- event.mouse1 = true;
+ eventMouse1 = true;
mouse1 = true;
break;
case 1:
- event.mouse2 = true;
+ eventMouse2 = true;
mouse2 = true;
break;
case 2:
- event.mouse3 = true;
+ eventMouse3 = true;
mouse3 = true;
break;
case 3:
// Release or Move
if (!mouse1 && !mouse2 && !mouse3) {
- event.type = TMouseEvent.Type.MOUSE_MOTION;
+ eventType = TMouseEvent.Type.MOUSE_MOTION;
} else {
- event.type = TMouseEvent.Type.MOUSE_UP;
+ eventType = TMouseEvent.Type.MOUSE_UP;
}
if (mouse1) {
mouse1 = false;
- event.mouse1 = true;
+ eventMouse1 = true;
}
if (mouse2) {
mouse2 = false;
- event.mouse2 = true;
+ eventMouse2 = true;
}
if (mouse3) {
mouse3 = false;
- event.mouse3 = true;
+ eventMouse3 = true;
}
break;
case 32:
// Dragging with mouse1 down
- event.mouse1 = true;
+ eventMouse1 = true;
mouse1 = true;
- event.type = TMouseEvent.Type.MOUSE_MOTION;
+ eventType = TMouseEvent.Type.MOUSE_MOTION;
break;
case 33:
// Dragging with mouse2 down
- event.mouse2 = true;
+ eventMouse2 = true;
mouse2 = true;
- event.type = TMouseEvent.Type.MOUSE_MOTION;
+ eventType = TMouseEvent.Type.MOUSE_MOTION;
break;
case 34:
// Dragging with mouse3 down
- event.mouse3 = true;
+ eventMouse3 = true;
mouse3 = true;
- event.type = TMouseEvent.Type.MOUSE_MOTION;
+ eventType = TMouseEvent.Type.MOUSE_MOTION;
break;
case 96:
// Dragging with mouse2 down after wheelUp
- event.mouse2 = true;
+ eventMouse2 = true;
mouse2 = true;
- event.type = TMouseEvent.Type.MOUSE_MOTION;
+ eventType = TMouseEvent.Type.MOUSE_MOTION;
break;
case 97:
// Dragging with mouse2 down after wheelDown
- event.mouse2 = true;
+ eventMouse2 = true;
mouse2 = true;
- event.type = TMouseEvent.Type.MOUSE_MOTION;
+ eventType = TMouseEvent.Type.MOUSE_MOTION;
break;
case 64:
- event.mouseWheelUp = true;
+ eventMouseWheelUp = true;
break;
case 65:
- event.mouseWheelDown = true;
+ eventMouseWheelDown = true;
break;
default:
// Unknown, just make it motion
- event.type = TMouseEvent.Type.MOUSE_MOTION;
+ eventType = TMouseEvent.Type.MOUSE_MOTION;
break;
}
- return event;
+ return new TMouseEvent(eventType, x, y, x, y,
+ eventMouse1, eventMouse2, eventMouse3,
+ eventMouseWheelUp, eventMouseWheelDown);
}
/**