Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

GridKeyDownEvent.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright 2000-2014 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.GridKeyDownHandler;
  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 down event in Grid.
  26. *
  27. * @since 7.4
  28. * @author Vaadin Ltd
  29. */
  30. public class GridKeyDownEvent extends AbstractGridKeyEvent<GridKeyDownHandler> {
  31. public GridKeyDownEvent(Grid<?> grid, CellReference<?> targetCell) {
  32. super(grid, targetCell);
  33. }
  34. @Override
  35. protected void doDispatch(GridKeyDownHandler handler, Section section) {
  36. if ((section == Section.BODY && handler instanceof BodyKeyDownHandler)
  37. || (section == Section.HEADER && handler instanceof HeaderKeyDownHandler)
  38. || (section == Section.FOOTER && handler instanceof FooterKeyDownHandler)) {
  39. handler.onKeyDown(this);
  40. }
  41. }
  42. @Override
  43. protected String getBrowserEventType() {
  44. return BrowserEvents.KEYDOWN;
  45. }
  46. /**
  47. * Does the key code represent an arrow key?
  48. *
  49. * @param keyCode
  50. * the key code
  51. * @return if it is an arrow key code
  52. */
  53. public static boolean isArrow(int keyCode) {
  54. switch (keyCode) {
  55. case KeyCodes.KEY_DOWN:
  56. case KeyCodes.KEY_RIGHT:
  57. case KeyCodes.KEY_UP:
  58. case KeyCodes.KEY_LEFT:
  59. return true;
  60. default:
  61. return false;
  62. }
  63. }
  64. /**
  65. * Gets the native key code. These key codes are enumerated in the
  66. * {@link KeyCodes} class.
  67. *
  68. * @return the key code
  69. */
  70. public int getNativeKeyCode() {
  71. return getNativeEvent().getKeyCode();
  72. }
  73. /**
  74. * Is this a key down arrow?
  75. *
  76. * @return whether this is a down arrow key event
  77. */
  78. public boolean isDownArrow() {
  79. return getNativeKeyCode() == KeyCodes.KEY_DOWN;
  80. }
  81. /**
  82. * Is this a left arrow?
  83. *
  84. * @return whether this is a left arrow key event
  85. */
  86. public boolean isLeftArrow() {
  87. return getNativeKeyCode() == KeyCodes.KEY_LEFT;
  88. }
  89. /**
  90. * Is this a right arrow?
  91. *
  92. * @return whether this is a right arrow key event
  93. */
  94. public boolean isRightArrow() {
  95. return getNativeKeyCode() == KeyCodes.KEY_RIGHT;
  96. }
  97. /**
  98. * Is this a up arrow?
  99. *
  100. * @return whether this is a right arrow key event
  101. */
  102. public boolean isUpArrow() {
  103. return getNativeKeyCode() == KeyCodes.KEY_UP;
  104. }
  105. @Override
  106. public String toDebugString() {
  107. return super.toDebugString() + "[" + getNativeKeyCode() + "]";
  108. }
  109. }