X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fg2d%2Fevents%2FMouseEvent.java;fp=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fg2d%2Fevents%2FMouseEvent.java;h=82843422a493d96d537d69e7d7c872d7c086bc9d;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/MouseEvent.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/MouseEvent.java new file mode 100644 index 000000000..82843422a --- /dev/null +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/MouseEvent.java @@ -0,0 +1,330 @@ +/******************************************************************************* + * 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 + *******************************************************************************/ +/* + * + * @author Toni Kalajainen + */ +package org.simantics.scenegraph.g2d.events; + +import java.awt.datatransfer.Transferable; +import java.awt.event.InputEvent; +import java.awt.geom.Point2D; + +/** + * TODO Remove hold time + * @see Event + * @see MouseClickEvent + * @see MouseDragBegin + * + * @author Toni Kalajainen + */ +public abstract class MouseEvent extends Event { + + private static final long serialVersionUID = -2090477028406944454L; + + public static final int LEFT_BUTTON = 1; + public static final int RIGHT_BUTTON = 2; + public static final int MIDDLE_BUTTON = 3; + + /** Time for mouse press + mouse release to be interpreted as mouse click */ + public static final long CLICK_TIME = 250; + + public static final int LEFT_MASK = 1 << (LEFT_BUTTON - 1); + public static final int RIGHT_MASK = 1 << (RIGHT_BUTTON - 1); + public static final int MIDDLE_MASK = 1 << (MIDDLE_BUTTON - 1); + public static final int ALL_BUTTONS_MASK = LEFT_MASK | RIGHT_MASK | MIDDLE_MASK; + + public static final int CTRL_MASK = InputEvent.CTRL_DOWN_MASK; + public static final int ALT_MASK = InputEvent.ALT_DOWN_MASK; + public static final int ALT_GRAPH_MASK = InputEvent.ALT_GRAPH_DOWN_MASK; + public static final int SHIFT_MASK = InputEvent.SHIFT_DOWN_MASK; + public static final int ALL_MODIFIERS_MASK = CTRL_MASK | ALT_MASK | ALT_GRAPH_MASK | SHIFT_MASK; + + /** + * The identifier of the mouse of this event. + * 0 = the main mouse. + */ + public final int mouseId; + + /** Position in the coordinate system of the UI component */ + public final Point2D controlPosition; + + /** Position in the coordinate system of the screen */ + public final Point2D screenPosition; + + /** + * The status of mouse buttons + * @see #LEFT_MASK + * @see #MIDDLE_MASK + * @see #RIGHT_MASK + */ + public final int buttons; + + /** + * The state of the keyboard modifier keys at the time the event was + * generated. + * + * @see #ALT_MASK + * @see #ALT_GRAPH_MASK + * @see #CTRL_MASK + * @see #SHIFT_MASK + */ + public int stateMask; + + private MouseEvent(Object context, long time, int mouseId, int buttons, int stateMask, + Point2D controlPosition, Point2D screenPosition) { + super(context, time); + this.mouseId = mouseId; + this.buttons = buttons; + this.controlPosition = controlPosition; + this.screenPosition = screenPosition; + this.stateMask = stateMask; + } + + public boolean hasAnyButton(int mask) { + return (buttons & mask) != 0; + } + + public boolean hasAllButtons(int mask) { + return (buttons & mask) == mask; + } + + public boolean hasAnyModifier(int mask) { + return (stateMask & mask) != 0; + } + + public boolean hasAllModifiers(int mask) { + return (stateMask & mask) == mask; + } + + /** + * Returns whether or not the Shift modifier is down on this event. + */ + public boolean isShiftDown() { + return (stateMask & MouseEvent.SHIFT_MASK) != 0; + } + + /** + * Returns whether or not the Control modifier is down on this event. + */ + public boolean isControlDown() { + return (stateMask & MouseEvent.CTRL_MASK) != 0; + } + + /** + * Returns whether or not the Alt modifier is down on this event. + */ + public boolean isAltDown() { + return (stateMask & MouseEvent.ALT_MASK) != 0; + } + + /** + * Returns whether or not the Alt Graph modifier is down on this event. + */ + public boolean isAltGraphDown() { + return (stateMask & MouseEvent.ALT_GRAPH_MASK) != 0; + } + + public abstract static class MouseButtonEvent extends MouseEvent { + + private static final long serialVersionUID = 3540032494506535841L; + + /** + * button of this event + */ + public final int button; + + public MouseButtonEvent(Object context, long time, int mouseId, int buttons, int stateMask, + int button, Point2D controlPosition, Point2D screenPosition) { + super(context, time, mouseId, buttons, stateMask, controlPosition,screenPosition); + this.button = button; + } + } + + public static class MouseWheelMovedEvent extends MouseEvent { + + private static final long serialVersionUID = -7896477913481842708L; + + /** + * Constant representing scrolling by "units" (like scrolling with the + * arrow keys) + * + * @see #getScrollType + */ + public static final int WHEEL_UNIT_SCROLL = 0; + + /** + * Constant representing scrolling by a "block" (like scrolling + * with page-up, page-down keys) + * + * @see #getScrollType + */ + public static final int WHEEL_BLOCK_SCROLL = 1; + + /** + * Indicates what sort of scrolling should take place in response to this + * event, based on platform settings. Legal values are: + *