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.

PasswordField.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 org.jsoup.nodes.Attributes;
  18. import org.jsoup.nodes.Element;
  19. import com.vaadin.ui.declarative.DesignAttributeHandler;
  20. import com.vaadin.ui.declarative.DesignContext;
  21. /**
  22. * A field that is used to enter secret text information like passwords. The
  23. * entered text is not displayed on the screen.
  24. */
  25. public class PasswordField extends AbstractTextField {
  26. /**
  27. * Constructs an empty PasswordField.
  28. */
  29. public PasswordField() {
  30. setValue("");
  31. }
  32. /**
  33. * Constructs a PasswordField with given value and caption.
  34. *
  35. * @param caption
  36. * the caption for the field
  37. * @param value
  38. * the value for the field
  39. */
  40. public PasswordField(String caption, String value) {
  41. setValue(value);
  42. setCaption(caption);
  43. }
  44. /**
  45. * Constructs a PasswordField with given caption.
  46. *
  47. * @param caption
  48. * the caption for the field
  49. */
  50. public PasswordField(String caption) {
  51. this();
  52. setCaption(caption);
  53. }
  54. /*
  55. * (non-Javadoc)
  56. *
  57. * @see com.vaadin.ui.AbstractField#readDesign(org.jsoup.nodes.Element ,
  58. * com.vaadin.ui.declarative.DesignContext)
  59. */
  60. @Override
  61. public void readDesign(Element design, DesignContext designContext) {
  62. super.readDesign(design, designContext);
  63. Attributes attr = design.attributes();
  64. if (attr.hasKey("value")) {
  65. doSetValue(DesignAttributeHandler.readAttribute("value", attr,
  66. String.class));
  67. }
  68. }
  69. /*
  70. * (non-Javadoc)
  71. *
  72. * @see com.vaadin.ui.AbstractTextField#writeDesign(org.jsoup.nodes.Element
  73. * , com.vaadin.ui.declarative.DesignContext)
  74. */
  75. @Override
  76. public void writeDesign(Element design, DesignContext designContext) {
  77. super.writeDesign(design, designContext);
  78. AbstractTextField def = (AbstractTextField) designContext
  79. .getDefaultInstance(this);
  80. Attributes attr = design.attributes();
  81. DesignAttributeHandler.writeAttribute("value", attr, getValue(),
  82. def.getValue(), String.class);
  83. }
  84. }