Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

FocusableFlowPanel.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.ui;
  17. import com.google.gwt.event.dom.client.BlurEvent;
  18. import com.google.gwt.event.dom.client.BlurHandler;
  19. import com.google.gwt.event.dom.client.FocusEvent;
  20. import com.google.gwt.event.dom.client.FocusHandler;
  21. import com.google.gwt.event.dom.client.HasBlurHandlers;
  22. import com.google.gwt.event.dom.client.HasFocusHandlers;
  23. import com.google.gwt.event.dom.client.HasKeyDownHandlers;
  24. import com.google.gwt.event.dom.client.HasKeyPressHandlers;
  25. import com.google.gwt.event.dom.client.KeyDownEvent;
  26. import com.google.gwt.event.dom.client.KeyDownHandler;
  27. import com.google.gwt.event.dom.client.KeyPressEvent;
  28. import com.google.gwt.event.dom.client.KeyPressHandler;
  29. import com.google.gwt.event.shared.HandlerRegistration;
  30. import com.google.gwt.user.client.ui.FlowPanel;
  31. import com.google.gwt.user.client.ui.impl.FocusImpl;
  32. import com.vaadin.client.Focusable;
  33. public class FocusableFlowPanel extends FlowPanel implements HasFocusHandlers,
  34. HasBlurHandlers, HasKeyDownHandlers, HasKeyPressHandlers, Focusable {
  35. /**
  36. * Constructor.
  37. */
  38. public FocusableFlowPanel() {
  39. // make focusable, as we don't need access key magic we don't need to
  40. // use FocusImpl.createFocusable
  41. getElement().setTabIndex(0);
  42. }
  43. /*
  44. * (non-Javadoc)
  45. *
  46. * @see
  47. * com.google.gwt.event.dom.client.HasFocusHandlers#addFocusHandler(com.
  48. * google.gwt.event.dom.client.FocusHandler)
  49. */
  50. @Override
  51. public HandlerRegistration addFocusHandler(FocusHandler handler) {
  52. return addDomHandler(handler, FocusEvent.getType());
  53. }
  54. /*
  55. * (non-Javadoc)
  56. *
  57. * @see
  58. * com.google.gwt.event.dom.client.HasBlurHandlers#addBlurHandler(com.google
  59. * .gwt.event.dom.client.BlurHandler)
  60. */
  61. @Override
  62. public HandlerRegistration addBlurHandler(BlurHandler handler) {
  63. return addDomHandler(handler, BlurEvent.getType());
  64. }
  65. /*
  66. * (non-Javadoc)
  67. *
  68. * @see
  69. * com.google.gwt.event.dom.client.HasKeyDownHandlers#addKeyDownHandler(
  70. * com.google.gwt.event.dom.client.KeyDownHandler)
  71. */
  72. @Override
  73. public HandlerRegistration addKeyDownHandler(KeyDownHandler handler) {
  74. return addDomHandler(handler, KeyDownEvent.getType());
  75. }
  76. /*
  77. * (non-Javadoc)
  78. *
  79. * @see
  80. * com.google.gwt.event.dom.client.HasKeyPressHandlers#addKeyPressHandler
  81. * (com.google.gwt.event.dom.client.KeyPressHandler)
  82. */
  83. @Override
  84. public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
  85. return addDomHandler(handler, KeyPressEvent.getType());
  86. }
  87. /**
  88. * Sets/Removes the keyboard focus to the panel.
  89. *
  90. * @param focus
  91. * If set to true then the focus is moved to the panel, if set to
  92. * false the focus is removed
  93. */
  94. public void setFocus(boolean focus) {
  95. if (focus) {
  96. FocusImpl.getFocusImplForPanel().focus(getElement());
  97. } else {
  98. FocusImpl.getFocusImplForPanel().blur(getElement());
  99. }
  100. }
  101. /**
  102. * Focus the panel.
  103. */
  104. @Override
  105. public void focus() {
  106. setFocus(true);
  107. }
  108. }