您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PasswordField.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 org.jsoup.nodes.Attributes;
  18. import org.jsoup.nodes.Element;
  19. import com.vaadin.data.Property;
  20. import com.vaadin.legacy.ui.LegacyAbstractTextField;
  21. import com.vaadin.ui.declarative.DesignAttributeHandler;
  22. import com.vaadin.ui.declarative.DesignContext;
  23. /**
  24. * A field that is used to enter secret text information like passwords. The
  25. * entered text is not displayed on the screen.
  26. */
  27. public class PasswordField extends LegacyAbstractTextField {
  28. /**
  29. * Constructs an empty PasswordField.
  30. */
  31. public PasswordField() {
  32. setValue("");
  33. }
  34. /**
  35. * Constructs a PasswordField with given property data source.
  36. *
  37. * @param dataSource
  38. * the property data source for the field
  39. */
  40. public PasswordField(Property dataSource) {
  41. setPropertyDataSource(dataSource);
  42. }
  43. /**
  44. * Constructs a PasswordField with given caption and property data source.
  45. *
  46. * @param caption
  47. * the caption for the field
  48. * @param dataSource
  49. * the property data source for the field
  50. */
  51. public PasswordField(String caption, Property dataSource) {
  52. this(dataSource);
  53. setCaption(caption);
  54. }
  55. /**
  56. * Constructs a PasswordField with given value and caption.
  57. *
  58. * @param caption
  59. * the caption for the field
  60. * @param value
  61. * the value for the field
  62. */
  63. public PasswordField(String caption, String value) {
  64. setValue(value);
  65. setCaption(caption);
  66. }
  67. /**
  68. * Constructs a PasswordField with given caption.
  69. *
  70. * @param caption
  71. * the caption for the field
  72. */
  73. public PasswordField(String caption) {
  74. this();
  75. setCaption(caption);
  76. }
  77. /*
  78. * (non-Javadoc)
  79. *
  80. * @see com.vaadin.ui.AbstractField#readDesign(org.jsoup.nodes.Element ,
  81. * com.vaadin.ui.declarative.DesignContext)
  82. */
  83. @Override
  84. public void readDesign(Element design, DesignContext designContext) {
  85. super.readDesign(design, designContext);
  86. Attributes attr = design.attributes();
  87. if (attr.hasKey("value")) {
  88. setValue(DesignAttributeHandler.readAttribute("value", attr,
  89. String.class), false, true);
  90. }
  91. }
  92. /*
  93. * (non-Javadoc)
  94. *
  95. * @see com.vaadin.ui.AbstractTextField#writeDesign(org.jsoup.nodes.Element
  96. * , com.vaadin.ui.declarative.DesignContext)
  97. */
  98. @Override
  99. public void writeDesign(Element design, DesignContext designContext) {
  100. super.writeDesign(design, designContext);
  101. LegacyAbstractTextField def = (LegacyAbstractTextField) designContext
  102. .getDefaultInstance(this);
  103. Attributes attr = design.attributes();
  104. DesignAttributeHandler.writeAttribute("value", attr, getValue(),
  105. def.getValue(), String.class);
  106. }
  107. @Override
  108. public void clear() {
  109. setValue("");
  110. }
  111. }