public void mouseClicked(MouseEvent e) { log.info("" + hot.idx); if (e.getButton() == MouseEvent.BUTTON1) { int mask = 1 << hot.idx; if (e.isShiftDown()) { int old = panel.getSelectedMask(); if ((mask & old) == 0) mask |= old; else mask = ~mask & old; } panel.setSelectedMask(mask); } }
public void mouseMoved(MouseEvent e) { // check if the mouse is over something hot: // - a speed handle // - a rock tmp.setLocation(e.getX(), e.getY()); panel.findHotDc(tmp, hot); }
public void mouseDragged(MouseEvent e) { if (e.getModifiersEx() == MouseEvent.BUTTON1_DOWN_MASK) { if (RockEditDisplay.HotObject.ROCK.equals(hot.what)) { // move a rock final Point2D wc = getWc(e, tmp); int idx = PositionSet.findRockIndexTouchingRockAtPos(rocks, wc, hot.idx); if (idx >= 0) { log.debug("new position blocked"); } else { rocks.getRock(hot.idx).setLocation(wc); rocks.notifyChange(); log.debug("relocated"); } } if (RockEditDisplay.HotObject.SPEED.equals(hot.what)) { // change the speed of a rock final Point2D wc = getWc(e, tmp); panel.setSpeedSpot(hot.idx, wc); } } }
/** * Get the world-coordinates where the mouse event happened. * * @param e * @param dst wc container. <code>null</code> creates a <code>Point2D.Float</code> * @return the world-coordinate location */ protected Point2D getWc(final MouseEvent e, Point2D dst) { if (dst == null) dst = new Point2D.Float(e.getX(), e.getY()); else dst.setLocation(e.getX(), e.getY()); return panel.dc2wc(dst, dst); }