/******************************************************************************* * Copyright (c) 2007, 2010 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.g2d.diagram.participant.pointertool; import java.awt.Shape; import java.awt.geom.AffineTransform; import java.awt.geom.Path2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import org.simantics.g2d.canvas.Hints; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.canvas.ICanvasParticipant; import org.simantics.g2d.canvas.IToolMode; import org.simantics.g2d.canvas.impl.CanvasContext; import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency; import org.simantics.g2d.canvas.impl.DependencyReflection.Reference; import org.simantics.g2d.connection.IConnectionAdvisor; import org.simantics.g2d.connection.handler.ConnectionHandler; import org.simantics.g2d.diagram.DiagramHints; import org.simantics.g2d.diagram.handler.PickContext; import org.simantics.g2d.diagram.handler.PickRequest; import org.simantics.g2d.diagram.handler.PickRequest.PickPolicy; import org.simantics.g2d.diagram.handler.PickRequest.PickSorter; import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant; import org.simantics.g2d.diagram.participant.Selection; import org.simantics.g2d.diagram.participant.TerminalPainter; import org.simantics.g2d.diagram.participant.TerminalPainter.ChainedHoverStrategy; import org.simantics.g2d.diagram.participant.TerminalPainter.TerminalHoverStrategy; import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo; import org.simantics.g2d.element.ElementClassProviders; import org.simantics.g2d.element.IElement; import org.simantics.g2d.element.IElementClassProvider; import org.simantics.g2d.elementclass.RouteGraphConnectionClass; import org.simantics.g2d.participant.KeyUtil; import org.simantics.g2d.participant.MouseUtil; import org.simantics.g2d.participant.TransformUtil; import org.simantics.g2d.scenegraph.SceneGraphConstants; import org.simantics.g2d.utils.CanvasUtils; import org.simantics.g2d.utils.GeometryUtils; import org.simantics.scenegraph.g2d.G2DSceneGraph; import org.simantics.scenegraph.g2d.events.Event; import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler; import org.simantics.scenegraph.g2d.events.KeyEvent; import org.simantics.scenegraph.g2d.events.KeyEvent.KeyPressedEvent; import org.simantics.scenegraph.g2d.events.MouseEvent; import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent; import org.simantics.scenegraph.g2d.events.MouseEvent.MouseClickEvent; import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDragBegin; import org.simantics.scenegraph.g2d.events.command.Commands; import org.simantics.scenegraph.g2d.nodes.connection.RouteGraphNode; import org.simantics.scenegraph.g2d.snap.ISnapAdvisor; import org.simantics.utils.ObjectUtils; import org.simantics.utils.datastructures.context.IContext; import org.simantics.utils.datastructures.context.IContextListener; import org.simantics.utils.datastructures.hints.HintListenerAdapter; import org.simantics.utils.datastructures.hints.IHintContext.Key; import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; import org.simantics.utils.datastructures.hints.IHintObservable; import org.simantics.utils.threads.ThreadUtils; /** * Pointer tool does the following operations with mouse: *
null
if current canvas transform is not invertible
*/
public Shape getCanvasPickShape(Point2D controlPos) {
AffineTransform inverse = util.getInverseTransform();
if (inverse == null)
return null;
double pd = getPickDistance();
Rectangle2D controlPickRect = new Rectangle2D.Double(controlPos.getX()-pd, controlPos.getY()-pd, pd*2, pd*2);
Shape canvasShape = GeometryUtils.transformShape(controlPickRect, inverse);
return canvasShape;
}
public List
* Note that this method assumes that elementsToDrag
and
* curCanvasPos
are already set by
* {@link #handleDrag(MouseDragBegin)}.
*
* @param me
* @return
*/
@EventHandler(priority = BOX_SELECT_PRIORITY)
public boolean handleBoxSelect(MouseDragBegin me) {
if (!hasBoxSelect()) return false;
if (me.button != MouseEvent.LEFT_BUTTON) return false;
if (getToolMode() != Hints.POINTERTOOL) return false;
if (hasToolMode(me.mouseId)) return false;
boolean nonSelectionModifierPressed = me.hasAnyModifier(MouseEvent.ALL_MODIFIERS_MASK
^ (MouseEvent.SHIFT_MASK /*| MouseEvent.CTRL_MASK*/));
if (nonSelectionModifierPressed)
return false;
if (!nonSelectionModifierPressed && elementsToDrag.isEmpty()) {
// Box Select
ICanvasParticipant bsm = createBoxSelectTool(me.mouseId, me.startCanvasPos, curCanvasDragPos, me.button, boxSelectMode);
if (bsm != null)
getContext().add(bsm);
}
return false;
}
private static boolean onlyConnections(Set