コード例 #1
0
 /*
  * (non-Javadoc)
  * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
  */
 public void mouseReleased(MouseEvent e) {
   if (!isActive()) {
     return;
   }
   if (getOperation() != NONE) {
     setOperation(NONE);
     if (listener != null) {
       listener.endAction(new ToolEvent(this));
     }
   }
 }
コード例 #2
0
 /**
  * Asigna la operación sobre el cursor que hay seleccionada
  *
  * @param op
  */
 private void setOperation(int op) {
   operation = op;
   if (op != NONE) {
     listener.onTool(new ToolEvent(this));
   }
 }
コード例 #3
0
  /*
   * (non-Javadoc)
   * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
   */
  public void mouseMoved(MouseEvent e) {
    if (!isActive()) {
      return;
    }
    int pxLeft = posX - (wCursor >> 1);
    int pxRight = posX + (wCursor >> 1);
    int pyUp = posY - (hCursor >> 1);
    int pyDown = posY + (hCursor >> 1);

    // Si estamos fuera del área del cuadrado + 2 píxeles ponemos el cursor por defecto y no hacemos
    // nada
    if (e.getX() < (pxLeft - 2)
        || e.getX() > (pxRight + 2)
        || e.getY() < (pyUp - 2)
        || e.getY() > (pyDown + 2)) {
      setOperation(NONE);
      if (canvas.getCursor().getType() != Cursor.DEFAULT_CURSOR) {
        canvas.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        listener.offTool(new ToolEvent(this));
      }
      return;
    }

    if (e.getX() >= (pxRight - 2) && e.getY() <= (pyUp + 2)) {
      if (iconMove != null) {
        canvas.setCursor(
            Toolkit.getDefaultToolkit().createCustomCursor(iconMove, new Point(16, 16), ""));
      }
      setOperation(MOVE_UR);
      return;
    }
    if (e.getX() <= (pxLeft + 2) && e.getY() <= (pyUp + 2)) {
      if (iconMove != null) {
        canvas.setCursor(
            Toolkit.getDefaultToolkit().createCustomCursor(iconMove, new Point(16, 16), ""));
      }
      setOperation(MOVE_UL);
      return;
    }
    if (e.getX() <= (pxLeft + 2) && e.getY() >= (pyDown - 2)) {
      if (iconMove != null) {
        canvas.setCursor(
            Toolkit.getDefaultToolkit().createCustomCursor(iconMove, new Point(16, 16), ""));
      }
      setOperation(MOVE_LL);
      return;
    }
    if (e.getX() >= (pxRight - 2) && e.getY() >= (pyDown - 2)) {
      if (iconMove != null) {
        canvas.setCursor(
            Toolkit.getDefaultToolkit().createCustomCursor(iconMove, new Point(16, 16), ""));
      }
      setOperation(MOVE_LR);
      return;
    }
    if (e.getX() <= (pxLeft + 1)) {
      if (iconHoriz != null) {
        canvas.setCursor(
            Toolkit.getDefaultToolkit().createCustomCursor(iconHoriz, new Point(16, 16), ""));
      }
      setOperation(REDIM_LEFT);
      return;
    }
    if (e.getX() >= (pxRight - 1)) {
      if (iconHoriz != null) {
        canvas.setCursor(
            Toolkit.getDefaultToolkit().createCustomCursor(iconHoriz, new Point(16, 16), ""));
      }
      setOperation(REDIM_RIGHT);
      return;
    }
    if (e.getY() <= (pyUp + 1)) {
      if (iconVert != null) {
        canvas.setCursor(
            Toolkit.getDefaultToolkit().createCustomCursor(iconVert, new Point(16, 16), ""));
      }
      setOperation(REDIM_UP);
      return;
    }
    if (e.getY() >= (pyDown - 1)) {
      if (iconVert != null) {
        canvas.setCursor(
            Toolkit.getDefaultToolkit().createCustomCursor(iconVert, new Point(16, 16), ""));
      }
      setOperation(REDIM_DOWN);
      return;
    }
    setOperation(NONE);
    if (canvas.getCursor().getType() != Cursor.DEFAULT_CURSOR) {
      canvas.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
      listener.offTool(new ToolEvent(this));
    }
  }