選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

FocusableFlexTable.java 3.8KB

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