/** Select or grow image when clicked. */ public void mousePressed(MouseEvent e) { Dimension size = fComponent.getSize(); if (e.getX() >= size.width - 7 && e.getY() >= size.height - 7 && getSelectionState() == 2) { // Click in selected grow-box: if (DEBUG) System.out.println("ImageView: grow!!! Size=" + fWidth + "x" + fHeight); Point loc = fComponent.getLocationOnScreen(); fGrowBase = new Point(loc.x + e.getX() - fWidth, loc.y + e.getY() - fHeight); fGrowProportionally = e.isShiftDown(); } else { // Else select image: fGrowBase = null; JTextComponent comp = (JTextComponent) fContainer; int start = fElement.getStartOffset(); int end = fElement.getEndOffset(); int mark = comp.getCaret().getMark(); int dot = comp.getCaret().getDot(); if (e.isShiftDown()) { // extend selection if shift key down: if (mark <= start) comp.moveCaretPosition(end); else comp.moveCaretPosition(start); } else { // just select image, without shift: if (mark != start) comp.setCaretPosition(start); if (dot != end) comp.moveCaretPosition(end); } } }
/** This method cannot be called directly. */ public void mousePressed(MouseEvent e) { synchronized (mouseLock) { mouseX = StdDraw.userX(e.getX()); mouseY = StdDraw.userY(e.getY()); mousePressed = true; } }
public void mouseClicked(MouseEvent e) { int x; int y; e.consume(); if (mouseEventsEnabled) { x = Math.round(e.getX() / scale); y = Math.round(e.getY() / scale); // allow for the canvas margin y -= margin; // System.out.println("Mouse Click: (" + x + ", " + y + ")"); if (e.getClickCount() < 2) { if (nativeSelectItem(x, y)) { parentFTAFrame.updateFrame(); } } else { if (nativeSelectItem(x, y)) { parentFTAFrame.updateFrame(); } editSelected(); parentFTAFrame.updateFrame(); } if (focusEventsEnabled) { // tell the main Canvas to point to this coordinate parentFTAFrame.setCanvasFocus(x, y); } } }
@Override public void mouseDragged(MouseEvent me) { // TODO Auto-generated method stub padx = me.getX(); pady = me.getY(); repaint(); }
/** This method cannot be called directly. */ public void mousePressed(MouseEvent e) { synchronized (mouseLock) { mouseX = StdDraw.userX(e.getX()); mouseY = StdDraw.userY(e.getY()); mousePressed = true; // System.out.println(mouseX+" ,"+mouseY); } }
private Location findloc(MouseEvent e) { int i, x = e.getX(), y = e.getY(); if (button.contains(x, y)) return button; for (i = 0; i < NUM_LOCATIONS; i++) { if (locs[i].contains(x, y)) return locs[i]; } return null; }
/** * The user has clicked in the applet. Figure out where and see if a legal move is possible. If it * is a legal move, respond with a legal move (if possible). */ public void mouseReleased(MouseEvent e) { int x = e.getX(); int y = e.getY(); switch (status()) { case WIN: case LOSE: case STALEMATE: play(getCodeBase(), "audio/return.au"); white = black = 0; if (first) { white |= 1 << (int) (Math.random() * 9); } first = !first; repaint(); return; } // Figure out the row/column Dimension d = getSize(); int c = (x * 3) / d.width; int r = (y * 3) / d.height; if (yourMove(c + r * 3)) { repaint(); switch (status()) { case WIN: play(getCodeBase(), "audio/yahoo1.au"); break; case LOSE: play(getCodeBase(), "audio/yahoo2.au"); break; case STALEMATE: break; default: if (myMove()) { repaint(); switch (status()) { case WIN: play(getCodeBase(), "audio/yahoo1.au"); break; case LOSE: play(getCodeBase(), "audio/yahoo2.au"); break; case STALEMATE: break; default: play(getCodeBase(), "audio/ding.au"); } } else { play(getCodeBase(), "audio/beep.au"); } } } else { play(getCodeBase(), "audio/beep.au"); } }
/** Resize image if initial click was in grow-box: */ public void mouseDragged(MouseEvent e) { if (fGrowBase != null) { Point loc = fComponent.getLocationOnScreen(); int width = Math.max(2, loc.x + e.getX() - fGrowBase.x); int height = Math.max(2, loc.y + e.getY() - fGrowBase.y); if (e.isShiftDown() && fImage != null) { // Make sure size is proportional to actual image size: float imgWidth = fImage.getWidth(this); float imgHeight = fImage.getHeight(this); if (imgWidth > 0 && imgHeight > 0) { float prop = imgHeight / imgWidth; float pwidth = height / prop; float pheight = width * prop; if (pwidth > width) width = (int) pwidth; else height = (int) pheight; } } resize(width, height); } }
public void mouseDragged(MouseEvent e) { mDrag(e.getX(), e.getY()); }
public void mouseMoved(MouseEvent e) { mouse.setLocation(e.getX(), e.getY()); changeArea(); changeDisplay(); }