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