You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractFocusable.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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.ui;
  17. import com.vaadin.event.FieldEvents.BlurEvent;
  18. import com.vaadin.event.FieldEvents.BlurListener;
  19. import com.vaadin.event.FieldEvents.BlurNotifier;
  20. import com.vaadin.event.FieldEvents.FocusAndBlurServerRpcImpl;
  21. import com.vaadin.event.FieldEvents.FocusEvent;
  22. import com.vaadin.event.FieldEvents.FocusListener;
  23. import com.vaadin.event.FieldEvents.FocusNotifier;
  24. import com.vaadin.shared.ui.TabIndexState;
  25. import com.vaadin.ui.Component.Focusable;
  26. /**
  27. * An abstract base class for focusable components. Includes API for setting the
  28. * tab index, programmatic focusing, and adding focus and blur listeners.
  29. *
  30. * @since 7.6
  31. * @author Vaadin Ltd
  32. */
  33. public abstract class AbstractFocusable extends AbstractComponent implements
  34. Focusable, FocusNotifier, BlurNotifier {
  35. protected AbstractFocusable() {
  36. registerRpc(new FocusAndBlurServerRpcImpl(this) {
  37. @Override
  38. protected void fireEvent(Event event) {
  39. AbstractFocusable.this.fireEvent(event);
  40. }
  41. });
  42. }
  43. @Override
  44. public void addBlurListener(BlurListener listener) {
  45. addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
  46. BlurListener.blurMethod);
  47. }
  48. /**
  49. * @deprecated As of 7.0, replaced by {@link #addBlurListener(BlurListener)}
  50. */
  51. @Override
  52. @Deprecated
  53. public void addListener(BlurListener listener) {
  54. addBlurListener(listener);
  55. }
  56. @Override
  57. public void removeBlurListener(BlurListener listener) {
  58. removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
  59. }
  60. /**
  61. * @deprecated As of 7.0, replaced by
  62. * {@link #removeBlurListener(BlurListener)}
  63. */
  64. @Override
  65. @Deprecated
  66. public void removeListener(BlurListener listener) {
  67. removeBlurListener(listener);
  68. }
  69. @Override
  70. public void addFocusListener(FocusListener listener) {
  71. addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
  72. FocusListener.focusMethod);
  73. }
  74. /**
  75. * @deprecated As of 7.0, replaced by
  76. * {@link #addFocusListener(FocusListener)}
  77. */
  78. @Override
  79. @Deprecated
  80. public void addListener(FocusListener listener) {
  81. addFocusListener(listener);
  82. }
  83. @Override
  84. public void removeFocusListener(FocusListener listener) {
  85. removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
  86. }
  87. /**
  88. * @deprecated As of 7.0, replaced by
  89. * {@link #removeFocusListener(FocusListener)}
  90. */
  91. @Override
  92. @Deprecated
  93. public void removeListener(FocusListener listener) {
  94. removeFocusListener(listener);
  95. }
  96. @Override
  97. public void focus() {
  98. super.focus();
  99. }
  100. @Override
  101. public int getTabIndex() {
  102. return getState(false).tabIndex;
  103. }
  104. @Override
  105. public void setTabIndex(int tabIndex) {
  106. getState().tabIndex = tabIndex;
  107. }
  108. @Override
  109. protected TabIndexState getState() {
  110. return (TabIndexState) super.getState();
  111. }
  112. @Override
  113. protected TabIndexState getState(boolean markAsDirty) {
  114. return (TabIndexState) super.getState(markAsDirty);
  115. }
  116. }