コード例 #1
0
    public void run() {
      try {
        Event tEvent = new Event("PointRightEvent");
        tEvent.addField("Screen", mMachineName);
        // This target
        tEvent.addField("PointRightEventType", "MouseEvent");
        // SrcMachine
        tEvent.addField("srcMachineName", String.class);
        // To distinguish unmarked
        tEvent.addField("level", Integer.class);
        // This type of event use Screen to determine target
        // tEvent.addField("Target", String.class);
        while (isRunning) {
          try {
            Event iEvent = mEventHeap.waitForEvent(tEvent);

            Integer level = (Integer) iEvent.getPostValue("level");
            if (level.intValue() < 1) continue;

            String Target = (String) iEvent.getPostValueString("Screen");
            if (!Target.equals(mMachineName)) continue;

            // Check if source is in list exists
            String srcMachineName = iEvent.getPostValueString("srcMachineName");
            // System.pi
            // If yes updatet the point that is associated by
            // else create a new name->point mapping
            boolean leftButtonPressed =
                ((Integer) iEvent.getPostValue("LeftButton")).equals(new Integer(1));
            boolean middeButtonPressed =
                ((Integer) iEvent.getPostValue("MiddleButton")).equals(new Integer(1));
            boolean rightButtonPressed =
                ((Integer) iEvent.getPostValue("RightButton")).equals(new Integer(1));

            // process postion events
            Point newPoint = updatePoint(iEvent);
            if (newPoint != null) nameToPointTable.put(srcMachineName, newPoint);
            else nameToPointTable.remove(srcMachineName);

            // process click events
            if (leftButtonPressed || middeButtonPressed || rightButtonPressed) {
              srcThatIsDragging = srcMachineName;
              handleButtonClickDown(leftButtonPressed, leftIsDown, InputEvent.BUTTON1_MASK);
              handleButtonClickDown(middeButtonPressed, middleIsDown, InputEvent.BUTTON2_MASK);
              handleButtonClickDown(rightButtonPressed, rightIsDown, InputEvent.BUTTON3_MASK);
            } else {
              if (srcThatIsDragging.equals(srcMachineName)) {
                handleButtonClickUp(leftIsDown, InputEvent.BUTTON1_MASK);
                handleButtonClickUp(middleIsDown, InputEvent.BUTTON2_MASK);
                handleButtonClickUp(rightIsDown, InputEvent.BUTTON3_MASK);
              } // end-if
            }
          } catch (EventHeapException eexpWait) {
          }
        } // end-while
      } catch (EventHeapException eexp) {
      }
    }
コード例 #2
0
  // Deal with absolute or relative cursor update
  public Point updatePoint(Event iEvent) throws EventHeapException {
    String srcMachineName = iEvent.getPostValueString("srcMachineName");
    Point res = new Point(0, 0);
    if (nameToPointTable.containsKey(srcMachineName)) {
      res = (Point) nameToPointTable.get(srcMachineName);
    }

    // Later distinguish between relative and aboslute creation
    Integer pos_x = (Integer) iEvent.getPostValue("X");
    Integer pos_y = (Integer) iEvent.getPostValue("Y");
    if (pos_x.intValue() <= LEAVE_MIN_X
        || pos_x.intValue() >= LEAVE_MAX_X
        || pos_y.intValue() <= LEAVE_MIN_Y
        || pos_y.intValue() >= LEAVE_MAX_Y) {
      res = null;
    } else {
      res = new Point(pos_x.intValue(), pos_y.intValue());
    }

    return res;
  }