You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GridKeyUpEvent.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.widget.grid.events;
  17. import com.google.gwt.dom.client.BrowserEvents;
  18. import com.google.gwt.event.dom.client.KeyCodes;
  19. import com.vaadin.client.widget.grid.CellReference;
  20. import com.vaadin.client.widget.grid.events.AbstractGridKeyEventHandler.GridKeyUpHandler;
  21. import com.vaadin.client.widgets.Grid;
  22. import com.vaadin.client.widgets.Grid.AbstractGridKeyEvent;
  23. import com.vaadin.shared.ui.grid.GridConstants.Section;
  24. /**
  25. * Represents native key up event in Grid.
  26. *
  27. * @since 7.4
  28. * @author Vaadin Ltd
  29. */
  30. public class GridKeyUpEvent extends AbstractGridKeyEvent<GridKeyUpHandler> {
  31. public static final Type<GridKeyUpHandler> TYPE = new Type<GridKeyUpHandler>(
  32. BrowserEvents.KEYUP, new GridKeyUpEvent());
  33. /**
  34. * @since 7.7.9
  35. */
  36. public GridKeyUpEvent() {
  37. }
  38. /**
  39. * @deprecated This constructor's arguments are no longer used. Use the
  40. * no-args constructor instead.
  41. */
  42. @Deprecated
  43. public GridKeyUpEvent(Grid<?> grid, CellReference<?> targetCell) {
  44. }
  45. @Override
  46. protected void doDispatch(GridKeyUpHandler handler, Section section) {
  47. if ((section == Section.BODY && handler instanceof BodyKeyUpHandler)
  48. || (section == Section.HEADER
  49. && handler instanceof HeaderKeyUpHandler)
  50. || (section == Section.FOOTER
  51. && handler instanceof FooterKeyUpHandler)) {
  52. handler.onKeyUp(this);
  53. }
  54. }
  55. @Override
  56. public Type<GridKeyUpHandler> getAssociatedType() {
  57. return TYPE;
  58. }
  59. @Override
  60. protected String getBrowserEventType() {
  61. return BrowserEvents.KEYUP;
  62. }
  63. /**
  64. * Does the key code represent an arrow key?
  65. *
  66. * @param keyCode
  67. * the key code
  68. * @return if it is an arrow key code
  69. */
  70. public static boolean isArrow(int keyCode) {
  71. switch (keyCode) {
  72. case KeyCodes.KEY_DOWN:
  73. case KeyCodes.KEY_RIGHT:
  74. case KeyCodes.KEY_UP:
  75. case KeyCodes.KEY_LEFT:
  76. return true;
  77. default:
  78. return false;
  79. }
  80. }
  81. /**
  82. * Gets the native key code. These key codes are enumerated in the
  83. * {@link KeyCodes} class.
  84. *
  85. * @return the key code
  86. */
  87. public int getNativeKeyCode() {
  88. return getNativeEvent().getKeyCode();
  89. }
  90. /**
  91. * Is this a key down arrow?
  92. *
  93. * @return whether this is a down arrow key event
  94. */
  95. public boolean isDownArrow() {
  96. return getNativeKeyCode() == KeyCodes.KEY_DOWN;
  97. }
  98. /**
  99. * Is this a left arrow?
  100. *
  101. * @return whether this is a left arrow key event
  102. */
  103. public boolean isLeftArrow() {
  104. return getNativeKeyCode() == KeyCodes.KEY_LEFT;
  105. }
  106. /**
  107. * Is this a right arrow?
  108. *
  109. * @return whether this is a right arrow key event
  110. */
  111. public boolean isRightArrow() {
  112. return getNativeKeyCode() == KeyCodes.KEY_RIGHT;
  113. }
  114. /**
  115. * Is this a up arrow?
  116. *
  117. * @return whether this is a right arrow key event
  118. */
  119. public boolean isUpArrow() {
  120. return getNativeKeyCode() == KeyCodes.KEY_UP;
  121. }
  122. @Override
  123. public String toDebugString() {
  124. return super.toDebugString() + "[" + getNativeKeyCode() + "]";
  125. }
  126. }