1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.participant;
14 import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;
15 import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;
16 import org.simantics.scenegraph.g2d.events.MouseEvent;
17 import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;
18 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonEvent;
19 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;
22 * Paints a grabbed hand when canvas is grabbed.
24 * TODO: out of order for now, needs to be adapted to scene graph
26 * @author Toni Kalajainen
28 public class HandPainter extends AbstractCanvasParticipant {
30 @Dependency CanvasGrab grab;
31 @Dependency SymbolUtil symbols;
32 @Dependency TransformUtil util;
33 @Dependency MouseUtil mice;
35 // @Painter(priority=PointerPainter.CURSOR_PAINT_PRIORITY+10)
36 // public void paint(GraphicsContext gc) {
37 // assertDependencies();
38 // Map<Integer, PointerInfo> pis = grab.getGrabInfo();
39 // Collection<MouseInfo> mis = mice.getMiceInfo().values();
40 // if (mis.isEmpty()) return;
43 // Image grab = symbols.get(DefaultImages.GRAB32, gc.getGraphics2D().getDeviceConfiguration());
44 // double gcx = grab.getBounds().getCenterX();
45 // double gcy = grab.getBounds().getCenterY();
46 // Image hand = symbols.get(DefaultImages.HAND32, gc.getGraphics2D().getDeviceConfiguration());
47 // double hcx = hand.getBounds().getCenterX();
48 // double hcy = hand.getBounds().getCenterY();
50 // for (MouseInfo mi : mis) {
51 // GraphicsContext g = gc.clone();
52 // PointerInfo pi = pis.get(mi.mouseId);
54 // Point2D pos = util.canvasToControl(pi.anchorPos, null);
55 // g.getGraphics2D().translate(pos.getX(), pos.getY());
56 // g.getGraphics2D().translate(-gcx, -gcy);
59 // Point2D pos = mi.controlPosition;
60 // g.getGraphics2D().translate(pos.getX(), pos.getY());
61 // g.getGraphics2D().translate(-gcx, -gcy);
68 @EventHandler(priority = Integer.MAX_VALUE)
69 public boolean handleMouseEvent(MouseEvent e) {
70 if (e instanceof MouseMovedEvent || e instanceof MouseButtonEvent)