123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- /*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
- package com.vaadin.v7.client.widget.grid.events;
-
- import com.google.gwt.dom.client.BrowserEvents;
- import com.google.gwt.event.dom.client.KeyCodes;
- import com.vaadin.v7.client.widget.grid.CellReference;
- import com.vaadin.v7.client.widget.grid.events.AbstractGridKeyEventHandler.GridKeyUpHandler;
- import com.vaadin.v7.client.widgets.Grid;
- import com.vaadin.v7.client.widgets.Grid.AbstractGridKeyEvent;
- import com.vaadin.v7.shared.ui.grid.GridConstants.Section;
-
- /**
- * Represents native key up event in Grid.
- *
- * @since 7.4
- * @author Vaadin Ltd
- */
- public class GridKeyUpEvent extends AbstractGridKeyEvent<GridKeyUpHandler> {
-
- public static final Type<GridKeyUpHandler> TYPE = new Type<GridKeyUpHandler>(
- BrowserEvents.KEYUP, new GridKeyUpEvent());
-
- /**
- * @since 7.7.9
- */
- public GridKeyUpEvent() {
- }
-
- /**
- * @deprecated This constructor's arguments are no longer used. Use the
- * no-args constructor instead.
- */
- @Deprecated
- public GridKeyUpEvent(Grid<?> grid, CellReference<?> targetCell) {
- }
-
- @Override
- protected void doDispatch(GridKeyUpHandler handler, Section section) {
- if ((section == Section.BODY && handler instanceof BodyKeyUpHandler)
- || (section == Section.HEADER
- && handler instanceof HeaderKeyUpHandler)
- || (section == Section.FOOTER
- && handler instanceof FooterKeyUpHandler)) {
- handler.onKeyUp(this);
- }
- }
-
- @Override
- public Type<GridKeyUpHandler> getAssociatedType() {
- return TYPE;
- }
-
- @Override
- protected String getBrowserEventType() {
- return BrowserEvents.KEYUP;
- }
-
- /**
- * Does the key code represent an arrow key?
- *
- * @param keyCode
- * the key code
- * @return if it is an arrow key code
- */
- public static boolean isArrow(int keyCode) {
- switch (keyCode) {
- case KeyCodes.KEY_DOWN:
- case KeyCodes.KEY_RIGHT:
- case KeyCodes.KEY_UP:
- case KeyCodes.KEY_LEFT:
- return true;
- default:
- return false;
- }
- }
-
- /**
- * Gets the native key code. These key codes are enumerated in the
- * {@link KeyCodes} class.
- *
- * @return the key code
- */
- public int getNativeKeyCode() {
- return getNativeEvent().getKeyCode();
- }
-
- /**
- * Is this a key down arrow?
- *
- * @return whether this is a down arrow key event
- */
- public boolean isDownArrow() {
- return getNativeKeyCode() == KeyCodes.KEY_DOWN;
- }
-
- /**
- * Is this a left arrow?
- *
- * @return whether this is a left arrow key event
- */
- public boolean isLeftArrow() {
- return getNativeKeyCode() == KeyCodes.KEY_LEFT;
- }
-
- /**
- * Is this a right arrow?
- *
- * @return whether this is a right arrow key event
- */
- public boolean isRightArrow() {
- return getNativeKeyCode() == KeyCodes.KEY_RIGHT;
- }
-
- /**
- * Is this a up arrow?
- *
- * @return whether this is a right arrow key event
- */
- public boolean isUpArrow() {
- return getNativeKeyCode() == KeyCodes.KEY_UP;
- }
-
- @Override
- public String toDebugString() {
- return super.toDebugString() + "[" + getNativeKeyCode() + "]";
- }
- }
|