1 Clazz.declarePackage ("javax.swing");
\r
2 Clazz.load (["javax.swing.text.JTextComponent"], "javax.swing.JTextArea", ["java.lang.IllegalArgumentException", "java.awt.Dimension", "javax.swing.JComponent", "$.LookAndFeel", "javax.swing.text.BadLocationException", "$.JSMinimalAbstractDocument", "swingjs.JSToolkit"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
6 this.columnWidth = 0;
\r
10 Clazz.instantialize (this, arguments);
\r
11 }, javax.swing, "JTextArea", javax.swing.text.JTextComponent);
\r
12 Clazz.makeConstructor (c$,
\r
14 this.construct (null, null, 0, 0);
\r
16 Clazz.makeConstructor (c$,
\r
18 this.construct (null, text, 0, 0);
\r
20 Clazz.makeConstructor (c$,
\r
21 function (rows, columns) {
\r
22 this.construct (null, null, rows, columns);
\r
24 Clazz.makeConstructor (c$,
\r
25 function (text, rows, columns) {
\r
26 this.construct (null, text, rows, columns);
\r
28 Clazz.makeConstructor (c$,
\r
30 this.construct (doc, null, 0, 0);
\r
31 }, "javax.swing.text.Document");
\r
32 Clazz.makeConstructor (c$,
\r
33 function (doc, text, rows, columns) {
\r
34 Clazz.superConstructor (this, javax.swing.JTextArea);
\r
36 this.columns = columns;
\r
38 doc = this.createDefaultModel ();
\r
39 }this.setDocument (doc);
\r
41 this.setText (text);
\r
44 throw new IllegalArgumentException ("rows: " + rows);
\r
46 throw new IllegalArgumentException ("columns: " + columns);
\r
47 }javax.swing.LookAndFeel.installProperty (this, "focusTraversalKeysForward", javax.swing.JComponent.getManagingFocusForwardTraversalKeys ());
\r
48 javax.swing.LookAndFeel.installProperty (this, "focusTraversalKeysBackward", javax.swing.JComponent.getManagingFocusBackwardTraversalKeys ());
\r
49 }, "javax.swing.text.Document,~S,~N,~N");
\r
50 Clazz.overrideMethod (c$, "getUIClassID",
\r
52 return "TextAreaUI";
\r
54 Clazz.defineMethod (c$, "createDefaultModel",
\r
56 return swingjs.JSToolkit.getPlainDocument (this);
\r
58 Clazz.defineMethod (c$, "setTabSize",
\r
60 var doc = this.getDocument ();
\r
62 var old = this.getTabSize ();
\r
63 doc.putProperty ("tabSize", new Integer (size));
\r
64 this.firePropertyChangeInt ("tabSize", old, size);
\r
66 Clazz.defineMethod (c$, "getTabSize",
\r
69 var doc = this.getDocument ();
\r
71 var i = doc.getProperty ("tabSize");
\r
73 size = i.intValue ();
\r
76 Clazz.defineMethod (c$, "setLineWrap",
\r
78 var old = this.wrap;
\r
80 this.firePropertyChangeBool ("lineWrap", old, wrap);
\r
82 Clazz.defineMethod (c$, "getLineWrap",
\r
86 Clazz.defineMethod (c$, "setWrapStyleWord",
\r
88 var old = this.word;
\r
90 this.firePropertyChangeBool ("wrapStyleWord", old, word);
\r
92 Clazz.defineMethod (c$, "getWrapStyleWord",
\r
96 Clazz.defineMethod (c$, "getLineOfOffset",
\r
98 var doc = this.getDocument ();
\r
100 throw new javax.swing.text.BadLocationException ("Can't translate offset to line", -1);
\r
101 } else if (offset > doc.getLength ()) {
\r
102 throw new javax.swing.text.BadLocationException ("Can't translate offset to line", doc.getLength () + 1);
\r
104 var map = this.getDocument ().getDefaultRootElement ();
\r
105 return map.getElementIndex (offset);
\r
107 Clazz.defineMethod (c$, "getLineCount",
\r
109 var map = this.getDocument ().getDefaultRootElement ();
\r
110 return map.getElementCount ();
\r
112 Clazz.defineMethod (c$, "getLineStartOffset",
\r
114 var lineCount = this.getLineCount ();
\r
116 throw new javax.swing.text.BadLocationException ("Negative line", -1);
\r
117 } else if (line >= lineCount) {
\r
118 throw new javax.swing.text.BadLocationException ("No such line", this.getDocument ().getLength () + 1);
\r
120 var map = this.getDocument ().getDefaultRootElement ();
\r
121 var lineElem = map.getElement (line);
\r
122 return lineElem.getStartOffset ();
\r
124 Clazz.defineMethod (c$, "getLineEndOffset",
\r
126 var lineCount = this.getLineCount ();
\r
128 throw new javax.swing.text.BadLocationException ("Negative line", -1);
\r
129 } else if (line >= lineCount) {
\r
130 throw new javax.swing.text.BadLocationException ("No such line", this.getDocument ().getLength () + 1);
\r
132 var map = this.getDocument ().getDefaultRootElement ();
\r
133 var lineElem = map.getElement (line);
\r
134 var endOffset = lineElem.getEndOffset ();
\r
135 return ((line == lineCount - 1) ? (endOffset - 1) : endOffset);
\r
137 Clazz.defineMethod (c$, "insert",
\r
138 function (str, pos) {
\r
139 var doc = this.getDocument ();
\r
142 doc.insertString (pos, str, null);
\r
144 if (Clazz.exceptionOf (e, javax.swing.text.BadLocationException)) {
\r
145 throw new IllegalArgumentException (e.getMessage ());
\r
151 Clazz.defineMethod (c$, "append",
\r
153 var doc = this.getDocument ();
\r
156 doc.insertString (doc.getLength (), str, null);
\r
158 if (Clazz.exceptionOf (e, javax.swing.text.BadLocationException)) {
\r
164 Clazz.defineMethod (c$, "replaceRange",
\r
165 function (str, start, end) {
\r
167 throw new IllegalArgumentException ("end before start");
\r
168 }var doc = this.getDocument ();
\r
171 if (Clazz.instanceOf (doc, javax.swing.text.JSMinimalAbstractDocument)) {
\r
172 (doc).replace (start, end - start, str, null);
\r
174 doc.remove (start, end - start);
\r
175 doc.insertString (start, str, null);
\r
177 if (Clazz.exceptionOf (e, javax.swing.text.BadLocationException)) {
\r
178 throw new IllegalArgumentException (e.getMessage ());
\r
184 Clazz.defineMethod (c$, "getRows",
\r
188 Clazz.defineMethod (c$, "setRows",
\r
190 var oldVal = this.rows;
\r
192 throw new IllegalArgumentException ("rows less than zero.");
\r
193 }if (rows != oldVal) {
\r
195 this.invalidate ();
\r
197 Clazz.defineMethod (c$, "getRowHeight",
\r
199 if (this.rowHeight == 0) {
\r
200 var metrics = this.getFontMetrics (this.getFont ());
\r
201 this.rowHeight = metrics.getHeight ();
\r
202 }return this.rowHeight;
\r
204 Clazz.defineMethod (c$, "getColumns",
\r
206 return this.columns;
\r
208 Clazz.defineMethod (c$, "setColumns",
\r
209 function (columns) {
\r
210 var oldVal = this.columns;
\r
212 throw new IllegalArgumentException ("columns less than zero.");
\r
213 }if (columns != oldVal) {
\r
214 this.columns = columns;
\r
215 this.invalidate ();
\r
217 Clazz.defineMethod (c$, "getColumnWidth",
\r
219 if (this.columnWidth == 0) {
\r
220 var metrics = this.getFontMetrics (this.getFont ());
\r
221 this.columnWidth = metrics.charWidth ('m');
\r
222 }return this.columnWidth;
\r
224 Clazz.overrideMethod (c$, "getPreferredSize",
\r
226 var d = this.getPrefSizeJComp ();
\r
227 d = (d == null) ? new java.awt.Dimension (400, 400) : d;
\r
228 var insets = this.getInsets ();
\r
229 if (this.columns != 0) {
\r
230 d.width = Math.max (d.width, this.columns * this.getColumnWidth () + insets.left + insets.right);
\r
231 }if (this.rows != 0) {
\r
232 d.height = Math.max (d.height, this.rows * this.getRowHeight () + insets.top + insets.bottom);
\r
235 Clazz.defineMethod (c$, "setFont",
\r
237 Clazz.superCall (this, javax.swing.JTextArea, "setFont", [f]);
\r
238 this.rowHeight = 0;
\r
239 this.columnWidth = 0;
\r
240 }, "java.awt.Font");
\r
241 Clazz.defineMethod (c$, "paramString",
\r
243 var wrapString = (this.wrap ? "true" : "false");
\r
244 var wordString = (this.word ? "true" : "false");
\r
245 return Clazz.superCall (this, javax.swing.JTextArea, "paramString", []) + ",colums=" + this.columns + ",columWidth=" + this.columnWidth + ",rows=" + this.rows + ",rowHeight=" + this.rowHeight + ",word=" + wordString + ",wrap=" + wrapString;
\r
247 Clazz.defineMethod (c$, "getScrollableTracksViewportWidth",
\r
249 return (this.wrap) ? true : Clazz.superCall (this, javax.swing.JTextArea, "getScrollableTracksViewportWidth", []);
\r
251 Clazz.defineMethod (c$, "getPreferredScrollableViewportSize",
\r
253 var size = Clazz.superCall (this, javax.swing.JTextArea, "getPreferredScrollableViewportSize", []);
\r
254 size = (size == null) ? new java.awt.Dimension (400, 400) : size;
\r
255 var insets = this.getInsets ();
\r
256 size.width = (this.columns == 0) ? size.width : this.columns * this.getColumnWidth () + insets.left + insets.right;
\r
257 size.height = (this.rows == 0) ? size.height : this.rows * this.getRowHeight () + insets.top + insets.bottom;
\r
260 Clazz.overrideMethod (c$, "getScrollableUnitIncrement",
\r
261 function (visibleRect, orientation, direction) {
\r
262 switch (orientation) {
\r
264 return this.getRowHeight ();
\r
266 return this.getColumnWidth ();
\r
268 throw new IllegalArgumentException ("Invalid orientation: " + orientation);
\r
270 }, "java.awt.Rectangle,~N,~N");
\r
271 Clazz.defineStatics (c$,
\r
272 "$uiClassID", "TextAreaUI");
\r