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.

TextField.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.ui.declarative.DesignAttributeHandler;
  21. import com.vaadin.ui.declarative.DesignContext;
  22. /**
  23. * A component for editing textual data that fits on a single line. For a
  24. * multi-line textarea, see the {@link TextArea} component.
  25. *
  26. * @author Vaadin Ltd.
  27. */
  28. @SuppressWarnings("serial")
  29. public class TextField extends AbstractTextField {
  30. /**
  31. * Constructs an empty <code>TextField</code> with no caption.
  32. */
  33. public TextField() {
  34. clear();
  35. }
  36. /**
  37. * Constructs an empty <code>TextField</code> with given caption.
  38. *
  39. * @param caption
  40. * the caption <code>String</code> for the editor.
  41. */
  42. public TextField(String caption) {
  43. this();
  44. setCaption(caption);
  45. }
  46. /**
  47. * Constructs a new <code>TextField</code> with the given caption and
  48. * initial text contents. The editor constructed this way will not be bound
  49. * to a Property unless
  50. * {@link com.vaadin.data.Property.Viewer#setPropertyDataSource(Property)}
  51. * is called to bind it.
  52. *
  53. * @param caption
  54. * the caption <code>String</code> for the editor.
  55. * @param value
  56. * the initial text content of the editor.
  57. */
  58. public TextField(String caption, String value) {
  59. setValue(value);
  60. setCaption(caption);
  61. }
  62. @Override
  63. public void readDesign(Element design, DesignContext designContext) {
  64. super.readDesign(design, designContext);
  65. Attributes attr = design.attributes();
  66. if (attr.hasKey("value")) {
  67. String text = DesignAttributeHandler.readAttribute("value", attr,
  68. String.class);
  69. doSetValue(text);
  70. }
  71. }
  72. @Override
  73. public void writeDesign(Element design, DesignContext designContext) {
  74. super.writeDesign(design, designContext);
  75. AbstractTextField def = (AbstractTextField) designContext
  76. .getDefaultInstance(this);
  77. Attributes attr = design.attributes();
  78. DesignAttributeHandler.writeAttribute("value", attr, getValue(),
  79. def.getValue(), String.class);
  80. }
  81. }