示例#1
0
 private void onMouseUp(MouseEvent e) {
   if (hasMotionListener()) {
     changeSelectedPoint(e.getX(), e.getY());
     removeMotionListener();
   }
   updateAll();
 }
示例#2
0
 private Tile getTile(MouseEvent e) {
   return (Tile) e.getSource();
 }
示例#3
0
 private void onMouseDrag(MouseEvent e) {
   changeSelectedPoint(e.getX(), e.getY());
   updateAll();
 }
示例#4
0
  private void onMouseDown(MouseEvent e) {
    if (_tile != getTile(e)) return;

    // Remember mouse down location.
    int x = _xdown = e.getX();
    int y = _ydown = e.getY();

    // What segment and point, if any, was clicked?
    int[] i = {0, 0}, p = {0, 0};
    int icode = getSegmentAndPoint(x, y, i, p);
    int is = i[0], ip = i[1];
    int xp = p[0], yp = p[1];
    // trace("onMouseDown: is="+is+" ip="+ip);

    // If currently in the process of creating a new segment, ...
    if (_creating) {

      // If mouse is on previous (selected) point in the created segment,
      // then end segment creation.
      if (icode == 1 && isSelected(is, ip)) {
        _creating = false;
      }

      // Else append a new point to the created segment.
      else {
        is = _isSelected;
        ip = appendPoint(x, y);
        selectPoint(is, ip);
        addMotionListener();
      }
    }

    // Else if not currently in the process of creating a new segment, ...
    else {

      // If mouse on existing point, ...
      if (icode == 1) {

        // If alt key down, delete the point.
        if (e.isAltDown()) {
          selectPoint(is, ip);
          removeSelectedPoint();
        }

        // Else, select the point
        else {
          selectPoint(is, ip);
          addMotionListener();
        }
      }

      // Else if mouse on existing segment, ...
      else if (icode == 2) {

        // If shift key down, add a new point to existing segment.
        if (e.isShiftDown()) {
          insertPoint(is, ip, x, y);
          selectPoint(is, ip);
          addMotionListener();
        }
      }

      // Else if mouse down away from all segments, ...
      else {

        // If shift key down, create a new segment.
        if (e.isShiftDown()) {
          is = appendSegment(x, y);
          ip = 0;
          selectPoint(is, ip);
          addMotionListener();
          _creating = true;
        }

        // Else deselect all points.
        else {
          deselect();
        }
      }
    }
    updateAll();
  }