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.

TextArea.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright 2000-2018 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.v7.ui;
  17. import org.jsoup.nodes.Element;
  18. import com.vaadin.ui.declarative.DesignContext;
  19. import com.vaadin.ui.declarative.DesignFormatter;
  20. import com.vaadin.v7.data.Property;
  21. import com.vaadin.v7.shared.ui.textarea.TextAreaState;
  22. /**
  23. * A text field that supports multi line editing.
  24. *
  25. * @deprecated As of 8.0 replaced by {@link com.vaadin.ui.TextArea} based on the
  26. * new data binding API
  27. */
  28. @Deprecated
  29. public class TextArea extends AbstractTextField {
  30. /**
  31. * Constructs an empty TextArea.
  32. */
  33. public TextArea() {
  34. setValue("");
  35. }
  36. /**
  37. * Constructs an empty TextArea with given caption.
  38. *
  39. * @param caption
  40. * the caption for the field.
  41. */
  42. public TextArea(String caption) {
  43. this();
  44. setCaption(caption);
  45. }
  46. /**
  47. * Constructs a TextArea with given property data source.
  48. *
  49. * @param dataSource
  50. * the data source for the field
  51. */
  52. public TextArea(Property dataSource) {
  53. this();
  54. setPropertyDataSource(dataSource);
  55. }
  56. /**
  57. * Constructs a TextArea with given caption and property data source.
  58. *
  59. * @param caption
  60. * the caption for the field
  61. * @param dataSource
  62. * the data source for the field
  63. */
  64. public TextArea(String caption, Property dataSource) {
  65. this(dataSource);
  66. setCaption(caption);
  67. }
  68. /**
  69. * Constructs a TextArea with given caption and value.
  70. *
  71. * @param caption
  72. * the caption for the field
  73. * @param value
  74. * the value for the field
  75. */
  76. public TextArea(String caption, String value) {
  77. this(caption);
  78. setValue(value);
  79. }
  80. @Override
  81. protected TextAreaState getState() {
  82. return (TextAreaState) super.getState();
  83. }
  84. @Override
  85. protected TextAreaState getState(boolean markAsDirty) {
  86. return (TextAreaState) super.getState(markAsDirty);
  87. }
  88. /**
  89. * Sets the number of rows in the text area.
  90. *
  91. * @param rows
  92. * the number of rows for this text area.
  93. */
  94. public void setRows(int rows) {
  95. if (rows < 0) {
  96. rows = 0;
  97. }
  98. getState().rows = rows;
  99. }
  100. /**
  101. * Gets the number of rows in the text area.
  102. *
  103. * @return number of explicitly set rows.
  104. */
  105. public int getRows() {
  106. return getState(false).rows;
  107. }
  108. /**
  109. * Sets the text area's word-wrap mode on or off.
  110. *
  111. * @param wordwrap
  112. * the boolean value specifying if the text area should be in
  113. * word-wrap mode.
  114. */
  115. public void setWordwrap(boolean wordwrap) {
  116. getState().wordwrap = wordwrap;
  117. }
  118. /**
  119. * Tests if the text area is in word-wrap mode.
  120. *
  121. * @return <code>true</code> if the component is in word-wrap mode,
  122. * <code>false</code> if not.
  123. */
  124. public boolean isWordwrap() {
  125. return getState(false).wordwrap;
  126. }
  127. /*
  128. * (non-Javadoc)
  129. *
  130. * @see com.vaadin.ui.AbstractField#readDesign(org.jsoup.nodes.Element ,
  131. * com.vaadin.ui.declarative.DesignContext)
  132. */
  133. @Override
  134. public void readDesign(Element design, DesignContext designContext) {
  135. super.readDesign(design, designContext);
  136. setValue(DesignFormatter.decodeFromTextNode(design.html()), false,
  137. true);
  138. }
  139. /*
  140. * (non-Javadoc)
  141. *
  142. * @see com.vaadin.ui.AbstractTextField#writeDesign(org.jsoup.nodes.Element
  143. * , com.vaadin.ui.declarative.DesignContext)
  144. */
  145. @Override
  146. public void writeDesign(Element design, DesignContext designContext) {
  147. super.writeDesign(design, designContext);
  148. design.html(DesignFormatter.encodeForTextNode(getValue()));
  149. }
  150. @Override
  151. public void clear() {
  152. setValue("");
  153. }
  154. }