Skip to content

Commit 42a8b81

Browse files
hansonrhansonr
authored andcommitted
AWT/Swing TextArea default size
1 parent 441e2d7 commit 42a8b81

File tree

6 files changed

+646
-14
lines changed

6 files changed

+646
-14
lines changed

sources/net.sf.j2s.java.core/src/javax/swing/JTextArea.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import javax.swing.text.Element;
4040
import javax.swing.text.JTextComponent;
4141
import javax.swing.text.PlainDocument;
42-
4342
import swingjs.api.JSMinimalAbstractDocument;
4443

4544
/**
@@ -240,8 +239,6 @@ public String getUIClassID() {
240239
* @return the default document model
241240
*/
242241
protected Document createDefaultModel() {
243-
// SwingJS
244-
// return JSToolkit.getPlainDocument(this);
245242
return new PlainDocument();
246243
}
247244

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextAreaUI.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
import java.beans.PropertyChangeEvent;
66

77
import javax.swing.JTextArea;
8+
import javax.swing.text.Document;
9+
import javax.swing.text.Element;
10+
import javax.swing.text.JTextComponent;
11+
import javax.swing.text.PlainView;
12+
import javax.swing.text.View;
13+
import javax.swing.text.WrappedPlainView;
814

915
import swingjs.JSToolkit;
1016
import swingjs.api.js.DOMNode;
@@ -45,12 +51,20 @@ public DOMNode updateDOMNode() {
4551
@Override
4652
public void propertyChange(PropertyChangeEvent e) {
4753
String prop = e.getPropertyName();
48-
if (prop == "ancestor") {
54+
// Object newValue = e.getNewValue();
55+
// Object oldValue = e.getOldValue();
56+
switch(prop) {
57+
case "ancestor":
4958
setJ2sMouseHandler();
50-
}
59+
break;
60+
}
5161
super.propertyChange(e);
5262
}
53-
63+
64+
protected void updateRootView() {
65+
useRootView = true;
66+
rootView.setView(create(editor.getDocument().getDefaultRootElement()));// does not take into account nested documents like HTML (I guess)
67+
}
5468
/**
5569
* Get the real height and width of the text in a JavaScript textarea
5670
* Used by JSScrollPaneUI
@@ -109,4 +123,22 @@ protected DOMNode setHTMLElement() {
109123
"position", "absolute");
110124
}
111125

126+
/**
127+
* Creates the view for an element. Returns a WrappedPlainView or PlainView.
128+
*
129+
* @param elem the element
130+
* @return the view
131+
*/
132+
@Override
133+
public View create(Element elem) {
134+
JTextArea area = (JTextArea) c;
135+
View v;
136+
if (area.getLineWrap()) {
137+
v = new WrappedPlainView(elem, area.getWrapStyleWord());
138+
} else {
139+
v = new PlainView(elem);
140+
}
141+
return v;
142+
}
143+
112144
}

0 commit comments

Comments
 (0)