From: Matti Tahvonen Date: Tue, 24 Nov 2009 07:07:25 +0000 (+0000) Subject: fixes #3683, setting height now implies textarea, but can still be reverted back... X-Git-Tag: 6.7.0.beta1~2273 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7bc4de76454a227f02268087bc2ce4e656616510;p=vaadin-framework.git fixes #3683, setting height now implies textarea, but can still be reverted back (single line textfield, but with height). svn changeset:9966/svn branch:6.2 --- diff --git a/src/com/vaadin/ui/TextField.java b/src/com/vaadin/ui/TextField.java index a773617265..45e19de367 100644 --- a/src/com/vaadin/ui/TextField.java +++ b/src/com/vaadin/ui/TextField.java @@ -169,13 +169,13 @@ public class TextField extends AbstractField { } // Adds the number of column and rows - final int c = getColumns(); - final int r = getRows(); - if (c != 0) { - target.addAttribute("cols", String.valueOf(c)); + final int columns = getColumns(); + final int rows = getRows(); + if (columns != 0) { + target.addAttribute("cols", String.valueOf(columns)); } - if (r != 0) { - target.addAttribute("rows", String.valueOf(r)); + if (rows != 0) { + target.addAttribute("rows", String.valueOf(rows)); target.addAttribute("multiline", true); if (!wordwrap) { target.addAttribute("wordwrap", false); @@ -314,9 +314,7 @@ public class TextField extends AbstractField { } /** - * Sets the number of rows in the editor. If the number of rows is set to 0, - * the actual number of displayed rows is determined implicitly by the - * adapter. + * Sets the number of rows in the editor. * * @param rows * the number of rows for this editor. @@ -325,8 +323,60 @@ public class TextField extends AbstractField { if (rows < 0) { rows = 0; } - this.rows = rows; - requestRepaint(); + if (this.rows != rows) { + this.rows = rows; + requestRepaint(); + } + } + + /** + * Sets the height of the {@link TextField} instance. + * + *

+ * Setting height for {@link TextField} also has a side-effect that puts + * {@link TextField} into multiline mode (aka "textarea"). Multiline mode + * can also be achieved by calling {@link #setRows(int)}. The height value + * overrides the number of rows set by {@link #setRows(int)}. + *

+ * If you want to set height of single line {@link TextField}, call + * {@link #setRows(int)} with value 0 after setting the height. Setting rows + * to 0 resets the side-effect. + * + * @see com.vaadin.ui.AbstractComponent#setHeight(float, int) + */ + @Override + public void setHeight(float height, int unit) { + super.setHeight(height, unit); + if (height > 1) { + /* + * In html based terminals we most commonly want to make component + * to be textarea if height is defined. Setting row field above 0 + * will render component as textarea. + */ + rows = 2; + } + } + + /** + * Sets the height of the {@link TextField} instance. + * + *

+ * Setting height for {@link TextField} also has a side-effect that puts + * {@link TextField} into multiline mode (aka "textarea"). Multiline mode + * can also be achieved by calling {@link #setRows(int)}. The height value + * overrides the number of rows set by {@link #setRows(int)}. + *

+ * If you want to set height of single line {@link TextField}, call + * {@link #setRows(int)} with value 0 after setting the height. Setting rows + * to 0 resets the side-effect. + * + * @see com.vaadin.ui.AbstractComponent#setHeight(java.lang.String) + */ + @Override + public void setHeight(String height) { + // will call setHeight(float, int) the actually does the magic. Method + // is overridden just to document side-effects. + super.setHeight(height); } /** @@ -347,7 +397,10 @@ public class TextField extends AbstractField { * word-wrap mode after the call or not. */ public void setWordwrap(boolean wordwrap) { - this.wordwrap = wordwrap; + if (this.wordwrap != wordwrap) { + this.wordwrap = wordwrap; + requestRepaint(); + } } /* Property features */ @@ -381,8 +434,10 @@ public class TextField extends AbstractField { * information. */ public void setSecret(boolean secret) { - this.secret = secret; - requestRepaint(); + if (this.secret != secret) { + this.secret = secret; + requestRepaint(); + } } /**