/** @param e */ @Override public void mouseClicked(MouseEvent e) { if (!roomEditMode) { EnvObjectLogic obj = mouseOnObject(e.getPoint()); if (obj != null) { // single click on an object if (e.getButton() == MouseEvent.BUTTON1) { if (e.getClickCount() == 1) { mouseClickObject(obj); } else { // double click on an object if (e.getClickCount() == 2) { mouseDoubleClickObject(obj); } } } else { // right click on an object if (e.getButton() == MouseEvent.BUTTON3) { if (e.getClickCount() == 1) { mouseRightClickObject(obj); } } } } else { removeIndicators(); calloutsUpdater.clearAll(); } } else { // if edit mode removeIndicators(); calloutsUpdater.clearAll(); toRealCoords(e.getPoint()); // click on an handle in edit mode Handle clickedHandle = mouseOnHandle(e.getPoint()); // single right click if (clickedHandle != null) { if ((e.getClickCount() == 1) && (e.getButton() == MouseEvent.BUTTON1)) { clickedHandle.setSelected(true); } else { // double right click if ((e.getClickCount() == 2) && (e.getButton() == MouseEvent.BUTTON1)) { clickedHandle.addAdiacent(); setSelectedZone(clickedHandle.getZone()); } else { // single left click if ((e.getClickCount() == 1) && (e.getButton() == MouseEvent.BUTTON3)) { clickedHandle.remove(); setSelectedZone(clickedHandle.getZone()); } } } } else { // click on a zone in edit mode if no handle is selected ZoneLogic zone = mouseOnZone(e.getPoint()); if (zone != null) { Callout callout = new Callout( this.getClass().getCanonicalName(), "info", I18n.msg("room_zone_selected") + " [" + zone.getPojo().getName() + "]", 50, 150, 0, -1); createCallout(callout); setSelectedZone(zone); } else { handles.clear(); // createHandles(null); } } setNeedRepaint(true); } }
/** @param e */ @Override public void mouseDragged(MouseEvent e) { inDrag = true; Point coords = toRealCoords(e.getPoint()); if ((dragDiff == null) && (getSelectedObject() != null)) { dragDiff = new Dimension( (int) Math.abs( coords.getX() - getSelectedObject() .getPojo() .getCurrentRepresentation() .getOffset() .getX()), (int) Math.abs( coords.getY() - getSelectedObject() .getPojo() .getCurrentRepresentation() .getOffset() .getY())); } int xSnapped = (int) coords.getX() - ((int) coords.getX() % SNAP_TO_GRID); int ySnapped = (int) coords.getY() - ((int) coords.getY() % SNAP_TO_GRID); // in object edit mode if (objectEditMode && (getSelectedObject() != null)) { for (Representation representation : getSelectedObject().getPojo().getRepresentations()) { // move an object representation.setOffset( xSnapped - (int) dragDiff.getWidth(), ySnapped - (int) dragDiff.getHeight()); setNeedRepaint(true); } } else { if (roomEditMode) { removeIndicators(); Callout callout = new Callout( this.getClass().getCanonicalName(), "mouse", selectedZone.getPojo().getName() + ": " + xSnapped + "cm," + ySnapped + "cm", (int) coords.getX() + 50, (int) coords.getY() + 50, 0, -1); createCallout(callout); for (Handle handle : handles) { // move the zone point if (handle.isSelected()) { if (null == originalHandleLocation) { originalHandleLocation = new FreedomPoint(handle.getPoint().getX(), handle.getPoint().getY()); } handle.move(xSnapped, ySnapped); addIndicator(TopologyUtils.convertToAWT(selectedZone.getPojo().getShape())); // add indicators for overlapping zones selectedZone = handle.getZone(); for (ZoneLogic overlapped : overlappedRooms(selectedZone)) { // mark the zone in red if it is overlapped addIndicator( TopologyUtils.convertToAWT(overlapped.getPojo().getShape()), new Color(255, 0, 0, HIGH_OPACITY)); } } } setNeedRepaint(true); } } }