1. /*
  2. * @(#)BasicTextAreaUI.java 1.55 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.plaf.basic;
  8. import java.beans.*;
  9. import java.awt.*;
  10. import java.awt.event.KeyEvent;
  11. import java.awt.event.InputEvent;
  12. import javax.swing.*;
  13. import javax.swing.text.*;
  14. import javax.swing.plaf.*;
  15. /**
  16. * Provides the look and feel for a plain text editor. In this
  17. * implementation the default UI is extended to act as a simple
  18. * view factory.
  19. * <p>
  20. * <strong>Warning:</strong>
  21. * Serialized objects of this class will not be compatible with
  22. * future Swing releases. The current serialization support is appropriate
  23. * for short term storage or RMI between applications running the same
  24. * version of Swing. A future release of Swing will provide support for
  25. * long term persistence.
  26. *
  27. * @author Timothy Prinzing
  28. * @version 1.55 11/29/01
  29. */
  30. public class BasicTextAreaUI extends BasicTextUI {
  31. /**
  32. * Creates a UI for a JTextArea.
  33. *
  34. * @param ta a text area
  35. * @return the UI
  36. */
  37. public static ComponentUI createUI(JComponent ta) {
  38. return new BasicTextAreaUI();
  39. }
  40. /**
  41. * Constructs a new BasicTextAreaUI object.
  42. */
  43. public BasicTextAreaUI() {
  44. super();
  45. }
  46. /**
  47. * Fetches the name used as a key to look up properties through the
  48. * UIManager. This is used as a prefix to all the standard
  49. * text properties.
  50. *
  51. * @return the name ("TextArea")
  52. */
  53. protected String getPropertyPrefix() {
  54. return "TextArea";
  55. }
  56. /**
  57. * This method gets called when a bound property is changed
  58. * on the associated JTextComponent. This is a hook
  59. * which UI implementations may change to reflect how the
  60. * UI displays bound properties of JTextComponent subclasses.
  61. * This is implemented to rebuild the View when the
  62. * <em>WrapLine</em> or the <em>WrapStyleWord</em> property changes.
  63. *
  64. * @param evt the property change event
  65. */
  66. protected void propertyChange(PropertyChangeEvent evt) {
  67. if (evt.getPropertyName().equals("lineWrap") ||
  68. evt.getPropertyName().equals("wrapStyleWord")) {
  69. // rebuild the view
  70. modelChanged();
  71. }
  72. }
  73. /**
  74. * Creates the view for an element. Returns a WrappedPlainView or
  75. * PlainView.
  76. *
  77. * @param elem the element
  78. * @return the view
  79. */
  80. public View create(Element elem) {
  81. JTextComponent c = getComponent();
  82. if (c instanceof JTextArea) {
  83. JTextArea area = (JTextArea) c;
  84. View v;
  85. if (area.getLineWrap()) {
  86. v = new WrappedPlainView(elem, area.getWrapStyleWord());
  87. } else {
  88. v = new PlainView(elem);
  89. }
  90. return v;
  91. }
  92. return null;
  93. }
  94. }