Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

GridKeyUpEvent.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright 2000-2021 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. /** DOM event type. */
  32. public static final Type<GridKeyUpHandler> TYPE = new Type<GridKeyUpHandler>(
  33. BrowserEvents.KEYUP, new GridKeyUpEvent());
  34. /**
  35. * @since 7.7.9
  36. */
  37. public GridKeyUpEvent() {
  38. }
  39. /**
  40. * @deprecated This constructor's arguments are no longer used. Use the
  41. * no-args constructor instead.
  42. *
  43. * @param grid
  44. * the grid the event occurred in, not used
  45. * @param targetCell
  46. * the cell the event targets, not used
  47. */
  48. @Deprecated
  49. public GridKeyUpEvent(Grid<?> grid, CellReference<?> targetCell) {
  50. }
  51. @Override
  52. protected void doDispatch(GridKeyUpHandler handler, Section section) {
  53. if ((section == Section.BODY && handler instanceof BodyKeyUpHandler)
  54. || (section == Section.HEADER
  55. && handler instanceof HeaderKeyUpHandler)
  56. || (section == Section.FOOTER
  57. && handler instanceof FooterKeyUpHandler)) {
  58. handler.onKeyUp(this);
  59. }
  60. }
  61. @Override
  62. public Type<GridKeyUpHandler> getAssociatedType() {
  63. return TYPE;
  64. }
  65. @Override
  66. protected String getBrowserEventType() {
  67. return BrowserEvents.KEYUP;
  68. }
  69. /**
  70. * Does the key code represent an arrow key?
  71. *
  72. * @param keyCode
  73. * the key code
  74. * @return if it is an arrow key code
  75. */
  76. public static boolean isArrow(int keyCode) {
  77. switch (keyCode) {
  78. case KeyCodes.KEY_DOWN:
  79. case KeyCodes.KEY_RIGHT:
  80. case KeyCodes.KEY_UP:
  81. case KeyCodes.KEY_LEFT:
  82. return true;
  83. default:
  84. return false;
  85. }
  86. }
  87. /**
  88. * Gets the native key code. These key codes are enumerated in the
  89. * {@link KeyCodes} class.
  90. *
  91. * @return the key code
  92. */
  93. public int getNativeKeyCode() {
  94. return getNativeEvent().getKeyCode();
  95. }
  96. /**
  97. * Is this a key down arrow?
  98. *
  99. * @return whether this is a down arrow key event
  100. */
  101. public boolean isDownArrow() {
  102. return getNativeKeyCode() == KeyCodes.KEY_DOWN;
  103. }
  104. /**
  105. * Is this a left arrow?
  106. *
  107. * @return whether this is a left arrow key event
  108. */
  109. public boolean isLeftArrow() {
  110. return getNativeKeyCode() == KeyCodes.KEY_LEFT;
  111. }
  112. /**
  113. * Is this a right arrow?
  114. *
  115. * @return whether this is a right arrow key event
  116. */
  117. public boolean isRightArrow() {
  118. return getNativeKeyCode() == KeyCodes.KEY_RIGHT;
  119. }
  120. /**
  121. * Is this a up arrow?
  122. *
  123. * @return whether this is a right arrow key event
  124. */
  125. public boolean isUpArrow() {
  126. return getNativeKeyCode() == KeyCodes.KEY_UP;
  127. }
  128. @Override
  129. public String toDebugString() {
  130. return super.toDebugString() + "[" + getNativeKeyCode() + "]";
  131. }
  132. }