/* * (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)); } }
/** * Asigna el canvas * * @param canvas */ public void setCanvas(CanvasZone canvas) { this.canvas = canvas; canvas.addMouseMotionListener(this); canvas.addMouseListener(this); }