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 *******************************************************************************/
14 * @author Toni Kalajainen
16 package org.simantics.g2d.participant;
18 import java.util.HashSet;
21 import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;
22 import org.simantics.scenegraph.g2d.events.KeyEvent;
23 import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;
24 import org.simantics.scenegraph.g2d.events.KeyEvent.KeyPressedEvent;
25 import org.simantics.scenegraph.g2d.events.KeyEvent.KeyReleasedEvent;
29 * KeyStatus monitors statuses of keys.
30 * @see java.awt.event.KeyEvent
32 public class KeyUtil extends AbstractCanvasParticipant {
35 private Set<Integer> pressedByKeyCode = new HashSet<Integer>();
36 private Set<Character> pressedByChar = new HashSet<Character>();
38 @EventHandler(priority = Integer.MAX_VALUE)
39 public boolean handleClick(KeyEvent e) {
40 if (e instanceof KeyPressedEvent) {
41 pressedByKeyCode.add(e.keyCode);
42 pressedByChar.add(e.character);
44 if (e instanceof KeyReleasedEvent) {
45 pressedByKeyCode.remove(e.keyCode);
46 pressedByChar.remove(e.character);
51 public boolean isCharPressed(char c)
53 return pressedByChar.contains(c);
58 * @see java.awt.event.KeyEvent
62 public boolean isKeyPressed(int keyCode)
64 return pressedByKeyCode.contains(keyCode);