|
Java example source code file (InputEvent.java)
The InputEvent.java Java example source code/* * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package java.awt.event; import java.awt.Event; import java.awt.Component; import java.awt.GraphicsEnvironment; import java.awt.Toolkit; import java.util.Arrays; import sun.awt.AWTAccessor; import sun.util.logging.PlatformLogger; import sun.security.util.SecurityConstants; /** * The root event class for all component-level input events. * * Input events are delivered to listeners before they are * processed normally by the source where they originated. * This allows listeners and component subclasses to "consume" * the event so that the source will not process them in their * default manner. For example, consuming mousePressed events * on a Button component will prevent the Button from being * activated. * * @author Carl Quinn * * @see KeyEvent * @see KeyAdapter * @see MouseEvent * @see MouseAdapter * @see MouseMotionAdapter * * @since 1.1 */ public abstract class InputEvent extends ComponentEvent { private static final PlatformLogger logger = PlatformLogger.getLogger("java.awt.event.InputEvent"); /** * The Shift key modifier constant. * It is recommended that SHIFT_DOWN_MASK be used instead. */ public static final int SHIFT_MASK = Event.SHIFT_MASK; /** * The Control key modifier constant. * It is recommended that CTRL_DOWN_MASK be used instead. */ public static final int CTRL_MASK = Event.CTRL_MASK; /** * The Meta key modifier constant. * It is recommended that META_DOWN_MASK be used instead. */ public static final int META_MASK = Event.META_MASK; /** * The Alt key modifier constant. * It is recommended that ALT_DOWN_MASK be used instead. */ public static final int ALT_MASK = Event.ALT_MASK; /** * The AltGraph key modifier constant. */ public static final int ALT_GRAPH_MASK = 1 << 5; /** * The Mouse Button1 modifier constant. * It is recommended that BUTTON1_DOWN_MASK be used instead. */ public static final int BUTTON1_MASK = 1 << 4; /** * The Mouse Button2 modifier constant. * It is recommended that BUTTON2_DOWN_MASK be used instead. * Note that BUTTON2_MASK has the same value as ALT_MASK. */ public static final int BUTTON2_MASK = Event.ALT_MASK; /** * The Mouse Button3 modifier constant. * It is recommended that BUTTON3_DOWN_MASK be used instead. * Note that BUTTON3_MASK has the same value as META_MASK. */ public static final int BUTTON3_MASK = Event.META_MASK; /** * The Shift key extended modifier constant. * @since 1.4 */ public static final int SHIFT_DOWN_MASK = 1 << 6; /** * The Control key extended modifier constant. * @since 1.4 */ public static final int CTRL_DOWN_MASK = 1 << 7; /** * The Meta key extended modifier constant. * @since 1.4 */ public static final int META_DOWN_MASK = 1 << 8; /** * The Alt key extended modifier constant. * @since 1.4 */ public static final int ALT_DOWN_MASK = 1 << 9; /** * The Mouse Button1 extended modifier constant. * @since 1.4 */ public static final int BUTTON1_DOWN_MASK = 1 << 10; /** * The Mouse Button2 extended modifier constant. * @since 1.4 */ public static final int BUTTON2_DOWN_MASK = 1 << 11; /** * The Mouse Button3 extended modifier constant. * @since 1.4 */ public static final int BUTTON3_DOWN_MASK = 1 << 12; /** * The AltGraph key extended modifier constant. * @since 1.4 */ public static final int ALT_GRAPH_DOWN_MASK = 1 << 13; /** * An array of extended modifiers for additional buttons. * @see getButtonDownMasks * There are twenty buttons fit into 4byte space. * one more bit is reserved for FIRST_HIGH_BIT. * @since 7.0 */ private static final int [] BUTTON_DOWN_MASK = new int [] { BUTTON1_DOWN_MASK, BUTTON2_DOWN_MASK, BUTTON3_DOWN_MASK, 1<<14, //4th phisical button (this is not a wheel!) 1<<15, //(this is not a wheel!) 1<<16, 1<<17, 1<<18, 1<<19, 1<<20, 1<<21, 1<<22, 1<<23, 1<<24, 1<<25, 1<<26, 1<<27, 1<<28, 1<<29, 1<<30}; /** * A method to access an array of extended modifiers for additional buttons. * @since 7.0 */ private static int [] getButtonDownMasks(){ return Arrays.copyOf(BUTTON_DOWN_MASK, BUTTON_DOWN_MASK.length); } /** * A method to obtain a mask for any existing mouse button. * The returned mask may be used for different purposes. Following are some of them: * <ul> * <li> {@link java.awt.Robot#mousePress(int) mousePress(buttons)} and * {@link java.awt.Robot#mouseRelease(int) mouseRelease(buttons)} * <li> as a {@code modifiers} parameter when creating a new {@link MouseEvent} instance * <li> to check {@link MouseEvent#getModifiersEx() modifiersEx} of existing {@code MouseEvent} * </ul> * @param button is a number to represent a button starting from 1. * For example, * <pre> * int button = InputEvent.getMaskForButton(1); * </pre> * will have the same meaning as * <pre> * int button = InputEvent.getMaskForButton(MouseEvent.BUTTON1); * </pre> * because {@link MouseEvent#BUTTON1 MouseEvent.BUTTON1} equals to 1. * If a mouse has three enabled buttons(see {@link java.awt.MouseInfo#getNumberOfButtons() MouseInfo.getNumberOfButtons()}) * then the values from the left column passed into the method will return * corresponding values from the right column: * <PRE> * <b>button returned mask * {@link MouseEvent#BUTTON1 BUTTON1} {@link MouseEvent#BUTTON1_DOWN_MASK BUTTON1_DOWN_MASK} * {@link MouseEvent#BUTTON2 BUTTON2} {@link MouseEvent#BUTTON2_DOWN_MASK BUTTON2_DOWN_MASK} * {@link MouseEvent#BUTTON3 BUTTON3} {@link MouseEvent#BUTTON3_DOWN_MASK BUTTON3_DOWN_MASK} * </PRE> * If a mouse has more than three enabled buttons then more values * are admissible (4, 5, etc.). There is no assigned constants for these extended buttons. * The button masks for the extra buttons returned by this method have no assigned names like the * first three button masks. * <p> * This method has the following implementation restriction. * It returns masks for a limited number of buttons only. The maximum number is * implementation dependent and may vary. * This limit is defined by the relevant number * of buttons that may hypothetically exist on the mouse but it is greater than the * {@link java.awt.MouseInfo#getNumberOfButtons() MouseInfo.getNumberOfButtons()}. * <p> * @throws IllegalArgumentException if {@code button} is less than zero or greater than the number * of button masks reserved for buttons * @since 7.0 * @see java.awt.MouseInfo#getNumberOfButtons() * @see Toolkit#areExtraMouseButtonsEnabled() * @see MouseEvent#getModifiers() * @see MouseEvent#getModifiersEx() */ public static int getMaskForButton(int button) { if (button <= 0 || button > BUTTON_DOWN_MASK.length) { throw new IllegalArgumentException("button doesn\'t exist " + button); } return BUTTON_DOWN_MASK[button - 1]; } // the constant below MUST be updated if any extra modifier // bits are to be added! // in fact, it is undesirable to add modifier bits // to the same field as this may break applications // see bug# 5066958 static final int FIRST_HIGH_BIT = 1 << 31; static final int JDK_1_3_MODIFIERS = SHIFT_DOWN_MASK - 1; static final int HIGH_MODIFIERS = ~( FIRST_HIGH_BIT - 1 ); /** * The input event's Time stamp in UTC format. The time stamp * indicates when the input event was created. * * @serial * @see #getWhen() */ long when; /** * The state of the modifier mask at the time the input * event was fired. * * @serial * @see #getModifiers() * @see #getModifiersEx() * @see java.awt.event.KeyEvent * @see java.awt.event.MouseEvent */ int modifiers; /* * A flag that indicates that this instance can be used to access * the system clipboard. */ private transient boolean canAccessSystemClipboard; static { /* ensure that the necessary native libraries are loaded */ NativeLibLoader.loadLibraries(); if (!GraphicsEnvironment.isHeadless()) { initIDs(); } AWTAccessor.setInputEventAccessor( new AWTAccessor.InputEventAccessor() { public int[] getButtonDownMasks() { return InputEvent.getButtonDownMasks(); } }); } /** * Initialize JNI field and method IDs for fields that may be accessed from C. */ private static native void initIDs(); /** * Constructs an InputEvent object with the specified source component, * modifiers, and type. * <p> This method throws an * <code>IllegalArgumentException if Other Java examples (source code examples)Here is a short list of links related to this Java InputEvent.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.