Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

DateField.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.ui;
  17. import java.time.LocalDate;
  18. import com.vaadin.shared.ui.datefield.LocalDateFieldState;
  19. /**
  20. * A date entry component, which displays the actual date selector as a popup.
  21. *
  22. * @see AbstractLocalDateField
  23. * @see InlineDateField
  24. * @author Vaadin Ltd.
  25. * @since 8.0
  26. */
  27. public class DateField extends AbstractLocalDateField {
  28. /**
  29. * Constructs an empty <code>DateField</code> with no caption.
  30. */
  31. public DateField() {
  32. super();
  33. }
  34. /**
  35. * Constructs a new <code>DateField</code> with the given caption and
  36. * initial text contents.
  37. *
  38. * @param caption
  39. * the caption <code>String</code> for the editor.
  40. * @param value
  41. * the LocalDate value.
  42. */
  43. public DateField(String caption, LocalDate value) {
  44. super(caption, value);
  45. }
  46. /**
  47. * Constructs an empty <code>DateField</code> with caption.
  48. *
  49. * @param caption
  50. * the caption of the datefield.
  51. */
  52. public DateField(String caption) {
  53. super(caption);
  54. }
  55. /**
  56. * Returns the current placeholder text.
  57. *
  58. * @see #setPlaceholder(String)
  59. * @return the placeholder text
  60. */
  61. public String getPlaceholder() {
  62. return getState(false).placeholder;
  63. }
  64. /**
  65. * Sets the placeholder text. The placeholder is text that is displayed when
  66. * the field would otherwise be empty, to prompt the user for input.
  67. *
  68. * @param placeholder
  69. * the placeholder text to set
  70. */
  71. public void setPlaceholder(String placeholder) {
  72. getState().placeholder = placeholder;
  73. }
  74. @Override
  75. protected LocalDateFieldState getState() {
  76. return (LocalDateFieldState) super.getState();
  77. }
  78. @Override
  79. protected LocalDateFieldState getState(boolean markAsDirty) {
  80. return (LocalDateFieldState) super.getState(markAsDirty);
  81. }
  82. /**
  83. * Checks whether the text field is enabled (default) or not.
  84. *
  85. * @see #setTextFieldEnabled(boolean)
  86. *
  87. * @return <b>true</b> if the text field is enabled, <b>false</b> otherwise.
  88. */
  89. public boolean isTextFieldEnabled() {
  90. return getState(false).textFieldEnabled;
  91. }
  92. /**
  93. * Enables or disables the text field. By default the text field is enabled.
  94. * Disabling it causes only the button for date selection to be active, thus
  95. * preventing the user from entering invalid dates.
  96. *
  97. * See {@link http://dev.vaadin.com/ticket/6790}.
  98. *
  99. * @param state
  100. * <b>true</b> to enable text field, <b>false</b> to disable it.
  101. */
  102. public void setTextFieldEnabled(boolean state) {
  103. getState().textFieldEnabled = state;
  104. }
  105. /**
  106. * Set a description that explains the usage of the Widget for users of
  107. * assistive devices.
  108. *
  109. * @param description
  110. * String with the description
  111. */
  112. public void setAssistiveText(String description) {
  113. getState().descriptionForAssistiveDevices = description;
  114. }
  115. /**
  116. * Get the description that explains the usage of the Widget for users of
  117. * assistive devices.
  118. *
  119. * @return String with the description
  120. */
  121. public String getAssistiveText() {
  122. return getState(false).descriptionForAssistiveDevices;
  123. }
  124. }