+ /**
+ * Translate the mouse event to a VT100, VT220, or XTERM sequence and
+ * send to the remote side.
+ *
+ * @param mouse mouse event received from the local user
+ */
+ public void mouse(final TMouseEvent mouse) {
+ /*
+ * TODO:
+ *
+ * - Parse the mouse requests from the remote side regarding protocol
+ * + encoding
+ *
+ * - Send mouse events to the other side.
+ *
+ * - Handle the cursor (double invert).
+ */
+
+ // System.err.printf("Mouse: %s\n", mouse);
+
+ /*
+ if (mouseEncoding != MouseEncoding.UTF8) {
+ // We only support UTF8 encoding, bail out now.
+ return;
+ }
+ */
+
+ switch (mouseProtocol) {
+
+ case OFF:
+ // Do nothing
+ return;
+
+ case X10:
+ // Only report button presses
+ if (mouse.getType() != TMouseEvent.Type.MOUSE_DOWN) {
+ return;
+ }
+ break;
+
+ case NORMAL:
+ // Only report button presses and releases
+ if ((mouse.getType() != TMouseEvent.Type.MOUSE_DOWN)
+ && (mouse.getType() != TMouseEvent.Type.MOUSE_UP)
+ ) {
+ return;
+ }
+ break;
+
+ case BUTTONEVENT:
+ /*
+ * Only report button presses, button releases, and motions that
+ * have a button down (i.e. drag-and-drop).
+ */
+ if (mouse.getType() == TMouseEvent.Type.MOUSE_MOTION) {
+ if (!mouse.getMouse1()
+ && !mouse.getMouse2()
+ && !mouse.getMouse3()
+ && !mouse.getMouseWheelUp()
+ && !mouse.getMouseWheelDown()
+ ) {
+ return;
+ }
+ }
+ break;
+
+ case ANYEVENT:
+ // Report everything
+ break;
+ }
+
+ // Now encode the event
+ StringBuilder sb = new StringBuilder(6);
+ sb.append((char) 0x1B);
+ sb.append('[');
+ sb.append('M');
+ if (mouse.getMouse1()) {
+ sb.append((char) (0x00 + 32));
+ } else if (mouse.getMouse2()) {
+ sb.append((char) (0x01 + 32));
+ } else if (mouse.getMouse3()) {
+ sb.append((char) (0x02 + 32));
+ } else if (mouse.getMouseWheelUp()) {
+ sb.append((char) (0x04 + 64));
+ } else if (mouse.getMouseWheelDown()) {
+ sb.append((char) (0x05 + 64));
+ } else {
+ sb.append((char) (0x03 + 32));
+ }
+
+ sb.append((char) (mouse.getX() + 33));
+ sb.append((char) (mouse.getY() + 33));
+
+ // System.err.printf("Would write: \'%s\'\n", sb.toString());
+ writeRemote(sb.toString());
+ }
+