39 |
package javax.swing.plaf.basic; |
package javax.swing.plaf.basic; |
40 |
|
|
41 |
|
|
42 |
|
import java.beans.PropertyChangeEvent; |
43 |
|
|
44 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
45 |
|
import javax.swing.JTextArea; |
46 |
import javax.swing.UIDefaults; |
import javax.swing.UIDefaults; |
47 |
import javax.swing.plaf.ComponentUI; |
import javax.swing.plaf.ComponentUI; |
48 |
import javax.swing.text.Element; |
import javax.swing.text.Element; |
49 |
import javax.swing.text.PlainView; |
import javax.swing.text.PlainView; |
50 |
import javax.swing.text.View; |
import javax.swing.text.View; |
51 |
|
import javax.swing.text.WrappedPlainView; |
52 |
|
|
53 |
public class BasicTextAreaUI extends BasicTextUI |
public class BasicTextAreaUI extends BasicTextUI |
54 |
{ |
{ |
59 |
|
|
60 |
public BasicTextAreaUI() |
public BasicTextAreaUI() |
61 |
{ |
{ |
62 |
|
// Nothing to do here. |
63 |
} |
} |
64 |
|
|
65 |
|
/** |
66 |
|
* Create the view. Returns a WrappedPlainView if the text area |
67 |
|
* has lineWrap set to true, otherwise returns a PlainView. If |
68 |
|
* lineWrap is true has to check whether the wrap style is word |
69 |
|
* or character and return an appropriate WrappedPlainView. |
70 |
|
* |
71 |
|
* @param elem the element to create a View for |
72 |
|
* @return an appropriate View for the element |
73 |
|
*/ |
74 |
public View create(Element elem) |
public View create(Element elem) |
75 |
{ |
{ |
76 |
return new PlainView(elem); |
JTextArea comp = (JTextArea)getComponent(); |
77 |
|
if (comp.getLineWrap()) |
78 |
|
{ |
79 |
|
if (comp.getWrapStyleWord()) |
80 |
|
return new WrappedPlainView(elem, true); |
81 |
|
else |
82 |
|
return new WrappedPlainView(elem, false); |
83 |
|
} |
84 |
|
else |
85 |
|
return new PlainView(elem); |
86 |
} |
} |
87 |
|
|
88 |
/** |
/** |
94 |
{ |
{ |
95 |
return "TextArea"; |
return "TextArea"; |
96 |
} |
} |
97 |
|
|
98 |
|
/** |
99 |
|
* Receives notification whenever one of the text component's bound |
100 |
|
* properties changes. This changes the view to WrappedPlainView |
101 |
|
* if setLineWrap(true) is called, and back to PlainView if |
102 |
|
* setLineWrap(false) is called. |
103 |
|
* |
104 |
|
* @param ev the property change event |
105 |
|
*/ |
106 |
|
protected void propertyChange(PropertyChangeEvent ev) |
107 |
|
{ |
108 |
|
JTextArea comp = (JTextArea)getComponent(); |
109 |
|
if (ev.getPropertyName() == "lineWrap" |
110 |
|
|| ev.getPropertyName() == "wrapStyleWord") |
111 |
|
modelChanged(); |
112 |
|
} |
113 |
} |
} |