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.

VTextArea.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.ui;
  5. import com.google.gwt.user.client.Command;
  6. import com.google.gwt.user.client.DOM;
  7. import com.google.gwt.user.client.DeferredCommand;
  8. import com.google.gwt.user.client.Element;
  9. import com.google.gwt.user.client.Event;
  10. import com.vaadin.terminal.gwt.client.ApplicationConnection;
  11. import com.vaadin.terminal.gwt.client.UIDL;
  12. /**
  13. * This class represents a multiline textfield (textarea).
  14. *
  15. * TODO consider replacing this with a RichTextArea based implementation. IE
  16. * does not support CSS height for textareas in Strict mode :-(
  17. *
  18. * @author IT Mill Ltd.
  19. *
  20. */
  21. public class VTextArea extends VTextField {
  22. public static final String CLASSNAME = "v-textarea";
  23. public VTextArea() {
  24. super(DOM.createTextArea());
  25. setStyleName(CLASSNAME);
  26. }
  27. @Override
  28. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  29. // Call parent renderer explicitly
  30. super.updateFromUIDL(uidl, client);
  31. if (uidl.hasAttribute("rows")) {
  32. setRows(new Integer(uidl.getStringAttribute("rows")).intValue());
  33. }
  34. if (getMaxLength() >= 0) {
  35. sinkEvents(Event.ONKEYPRESS);
  36. }
  37. }
  38. public void setRows(int rows) {
  39. setRows(getElement(), rows);
  40. }
  41. private native void setRows(Element e, int r)
  42. /*-{
  43. try {
  44. if(e.tagName.toLowerCase() == "textarea")
  45. e.rows = r;
  46. } catch (e) {}
  47. }-*/;
  48. @Override
  49. public void onBrowserEvent(Event event) {
  50. if (getMaxLength() >= 0 && event.getTypeInt() == Event.ONKEYPRESS) {
  51. DeferredCommand.addCommand(new Command() {
  52. public void execute() {
  53. if (getText().length() > getMaxLength()) {
  54. setText(getText().substring(0, getMaxLength()));
  55. }
  56. }
  57. });
  58. }
  59. super.onBrowserEvent(event);
  60. }
  61. }