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

SimpleFocusablePanel.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright 2000-2018 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.dom.client.KeyUpEvent;
  30. import com.google.gwt.event.dom.client.KeyUpHandler;
  31. import com.google.gwt.event.shared.HandlerRegistration;
  32. import com.google.gwt.user.client.ui.Focusable;
  33. import com.google.gwt.user.client.ui.SimplePanel;
  34. import com.google.gwt.user.client.ui.impl.FocusImpl;
  35. /**
  36. * Compared to FocusPanel in GWT this panel does not support e.g. accesskeys,
  37. * but is simpler by its dom hierarchy nor supports focusing via java api.
  38. */
  39. public class SimpleFocusablePanel extends SimplePanel
  40. implements HasFocusHandlers, HasBlurHandlers, HasKeyDownHandlers,
  41. HasKeyPressHandlers, Focusable, com.vaadin.client.Focusable {
  42. public SimpleFocusablePanel() {
  43. // make focusable, as we don't need access key magic we don't need to
  44. // use FocusImpl.createFocusable
  45. setTabIndex(0);
  46. }
  47. @Override
  48. public HandlerRegistration addFocusHandler(FocusHandler handler) {
  49. return addDomHandler(handler, FocusEvent.getType());
  50. }
  51. @Override
  52. public HandlerRegistration addBlurHandler(BlurHandler handler) {
  53. return addDomHandler(handler, BlurEvent.getType());
  54. }
  55. @Override
  56. public HandlerRegistration addKeyDownHandler(KeyDownHandler handler) {
  57. return addDomHandler(handler, KeyDownEvent.getType());
  58. }
  59. @Override
  60. public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
  61. return addDomHandler(handler, KeyPressEvent.getType());
  62. }
  63. public HandlerRegistration addKeyUpHandler(KeyUpHandler handler) {
  64. return addDomHandler(handler, KeyUpEvent.getType());
  65. }
  66. @Override
  67. public void setFocus(boolean focus) {
  68. if (focus) {
  69. FocusImpl.getFocusImplForPanel().focus(getElement());
  70. } else {
  71. FocusImpl.getFocusImplForPanel().blur(getElement());
  72. }
  73. }
  74. @Override
  75. public void focus() {
  76. setFocus(true);
  77. }
  78. @Override
  79. public void setTabIndex(int tabIndex) {
  80. getElement().setTabIndex(tabIndex);
  81. }
  82. @Override
  83. public int getTabIndex() {
  84. return getElement().getTabIndex();
  85. }
  86. @Override
  87. public void setAccessKey(char key) {
  88. FocusUtil.setAccessKey(this, key);
  89. }
  90. }