Beispiel #1
0
 public void mouseDragged(java.awt.event.MouseEvent e) {
   java.awt.Point p = org.nlogo.awt.Coordinates.convertPointToScreen(e.getPoint(), this);
   int x = p.x;
   int y = p.y;
   if (mouseMode() == MouseMode.DRAG) {
     if ((e.getModifiers() & java.awt.event.InputEvent.SHIFT_MASK) == 0) {
       constrainToHorizontal = false;
       constrainToVertical = false;
     } else {
       if (!constrainToHorizontal
           && !constrainToVertical
           && StrictMath.abs(x - startPressX) > StrictMath.abs(y - startPressY)) {
         constrainToHorizontal = true;
       } else {
         constrainToVertical = true;
       }
       if (constrainToHorizontal) {
         y = startPressY;
       } else if (constrainToVertical) {
         x = startPressX;
       }
     }
     interfacePanel().dragSelectedWidgets(x - startPressX, y - startPressY);
   } else if (mouseMode() == MouseMode.NE
       || mouseMode() == MouseMode.NW
       || mouseMode() == MouseMode.SE
       || mouseMode() == MouseMode.SW
       || mouseMode() == MouseMode.S
       || mouseMode() == MouseMode.W
       || mouseMode() == MouseMode.E
       || mouseMode() == MouseMode.N) {
     doResize(x - startPressX, y - startPressY);
   }
 }
Beispiel #2
0
  public void mousePressed(java.awt.event.MouseEvent e) {
    if (e.isPopupTrigger()) {
      doPopup(e);
      return;
    }
    if (!org.nlogo.awt.Mouse.hasButton1(e)) {
      return;
    }
    foreground();
    if (e.getClickCount() == 2) {
      new org.nlogo.window.Events.EditWidgetEvent(null).raise(this);
      return;
    }
    java.awt.Dimension d = getSize();
    int x = e.getX();
    int y = e.getY();
    java.awt.Point p = org.nlogo.awt.Coordinates.convertPointToScreen(e.getPoint(), this);
    startPressX = p.x;
    startPressY = p.y;

    mouseMode(MouseMode.DRAG);
    if (x < BORDER_W) {
      if (verticallyResizable && y < BORDER_N) {
        mouseMode(MouseMode.NW);
      } else if (verticallyResizable && y > d.height - BORDER_S) {
        mouseMode(MouseMode.SW);
      } else if (y <= BORDER_N + (d.height - BORDER_S - BORDER_N - HANDLE_WIDTH) / 2 + HANDLE_WIDTH
          && y >= BORDER_N + (d.height - BORDER_S - BORDER_N - HANDLE_WIDTH) / 2) {
        mouseMode(MouseMode.W);
      }
    } else if (x > d.width - BORDER_E) {
      if (verticallyResizable && y < BORDER_N) {
        mouseMode(MouseMode.NE);
      } else if (verticallyResizable && y > d.height - BORDER_S) {
        mouseMode(MouseMode.SE);
      } else if (y <= BORDER_N + (d.height - BORDER_S - BORDER_N - HANDLE_WIDTH) / 2 + HANDLE_WIDTH
          && y >= BORDER_N + (d.height - BORDER_S - BORDER_N - HANDLE_WIDTH) / 2) {
        mouseMode(MouseMode.E);
      }
    } else if (verticallyResizable && y > d.height - BORDER_S) {
      if (x <= BORDER_W + (d.width - BORDER_E - BORDER_W + HANDLE_WIDTH) / 2
          && x >= BORDER_W + (d.width - BORDER_E - BORDER_W - HANDLE_WIDTH) / 2) {
        mouseMode(MouseMode.S);
      }
    } else if (verticallyResizable
        && y < BORDER_N
        && x <= BORDER_W + (d.width - BORDER_E - BORDER_W + HANDLE_WIDTH) / 2
        && x >= BORDER_W + (d.width - BORDER_E - BORDER_W - HANDLE_WIDTH) / 2) {
      mouseMode(MouseMode.N);
    }
    if (mouseMode() == MouseMode.DRAG) {
      interfacePanel().aboutToDragSelectedWidgets(startPressX, startPressY);
    } else {
      aboutToDrag();
    }
  }