7d2487f294bec710d0c7fd1b361df93c5081a4e0
[jalviewjs.git] / site / swingjs / j2s / javax / swing / JTextArea.js
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 () {
4 this.rows = 0;
5 this.columns = 0;
6 this.columnWidth = 0;
7 this.rowHeight = 0;
8 this.wrap = false;
9 this.word = false;
10 Clazz.instantialize (this, arguments);
11 }, javax.swing, "JTextArea", javax.swing.text.JTextComponent);
12 Clazz.makeConstructor (c$, 
13 function () {
14 this.construct (null, null, 0, 0);
15 });
16 Clazz.makeConstructor (c$, 
17 function (text) {
18 this.construct (null, text, 0, 0);
19 }, "~S");
20 Clazz.makeConstructor (c$, 
21 function (rows, columns) {
22 this.construct (null, null, rows, columns);
23 }, "~N,~N");
24 Clazz.makeConstructor (c$, 
25 function (text, rows, columns) {
26 this.construct (null, text, rows, columns);
27 }, "~S,~N,~N");
28 Clazz.makeConstructor (c$, 
29 function (doc) {
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);
35 this.rows = rows;
36 this.columns = columns;
37 if (doc == null) {
38 doc = this.createDefaultModel ();
39 }this.setDocument (doc);
40 if (text != null) {
41 this.setText (text);
42 this.select (0, 0);
43 }if (rows < 0) {
44 throw  new IllegalArgumentException ("rows: " + rows);
45 }if (columns < 0) {
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", 
51 function () {
52 return "TextAreaUI";
53 });
54 Clazz.defineMethod (c$, "createDefaultModel", 
55 function () {
56 return swingjs.JSToolkit.getPlainDocument (this);
57 });
58 Clazz.defineMethod (c$, "setTabSize", 
59 function (size) {
60 var doc = this.getDocument ();
61 if (doc != null) {
62 var old = this.getTabSize ();
63 doc.putProperty ("tabSize",  new Integer (size));
64 this.firePropertyChangeInt ("tabSize", old, size);
65 }}, "~N");
66 Clazz.defineMethod (c$, "getTabSize", 
67 function () {
68 var size = 8;
69 var doc = this.getDocument ();
70 if (doc != null) {
71 var i = doc.getProperty ("tabSize");
72 if (i != null) {
73 size = i.intValue ();
74 }}return size;
75 });
76 Clazz.defineMethod (c$, "setLineWrap", 
77 function (wrap) {
78 var old = this.wrap;
79 this.wrap = wrap;
80 this.firePropertyChangeBool ("lineWrap", old, wrap);
81 }, "~B");
82 Clazz.defineMethod (c$, "getLineWrap", 
83 function () {
84 return this.wrap;
85 });
86 Clazz.defineMethod (c$, "setWrapStyleWord", 
87 function (word) {
88 var old = this.word;
89 this.word = word;
90 this.firePropertyChangeBool ("wrapStyleWord", old, word);
91 }, "~B");
92 Clazz.defineMethod (c$, "getWrapStyleWord", 
93 function () {
94 return this.word;
95 });
96 Clazz.defineMethod (c$, "getLineOfOffset", 
97 function (offset) {
98 var doc = this.getDocument ();
99 if (offset < 0) {
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);
103 } else {
104 var map = this.getDocument ().getDefaultRootElement ();
105 return map.getElementIndex (offset);
106 }}, "~N");
107 Clazz.defineMethod (c$, "getLineCount", 
108 function () {
109 var map = this.getDocument ().getDefaultRootElement ();
110 return map.getElementCount ();
111 });
112 Clazz.defineMethod (c$, "getLineStartOffset", 
113 function (line) {
114 var lineCount = this.getLineCount ();
115 if (line < 0) {
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);
119 } else {
120 var map = this.getDocument ().getDefaultRootElement ();
121 var lineElem = map.getElement (line);
122 return lineElem.getStartOffset ();
123 }}, "~N");
124 Clazz.defineMethod (c$, "getLineEndOffset", 
125 function (line) {
126 var lineCount = this.getLineCount ();
127 if (line < 0) {
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);
131 } else {
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);
136 }}, "~N");
137 Clazz.defineMethod (c$, "insert", 
138 function (str, pos) {
139 var doc = this.getDocument ();
140 if (doc != null) {
141 try {
142 doc.insertString (pos, str, null);
143 } catch (e) {
144 if (Clazz.exceptionOf (e, javax.swing.text.BadLocationException)) {
145 throw  new IllegalArgumentException (e.getMessage ());
146 } else {
147 throw e;
148 }
149 }
150 }}, "~S,~N");
151 Clazz.defineMethod (c$, "append", 
152 function (str) {
153 var doc = this.getDocument ();
154 if (doc != null) {
155 try {
156 doc.insertString (doc.getLength (), str, null);
157 } catch (e) {
158 if (Clazz.exceptionOf (e, javax.swing.text.BadLocationException)) {
159 } else {
160 throw e;
161 }
162 }
163 }}, "~S");
164 Clazz.defineMethod (c$, "replaceRange", 
165 function (str, start, end) {
166 if (end < start) {
167 throw  new IllegalArgumentException ("end before start");
168 }var doc = this.getDocument ();
169 if (doc != null) {
170 try {
171 if (Clazz.instanceOf (doc, javax.swing.text.JSMinimalAbstractDocument)) {
172 (doc).replace (start, end - start, str, null);
173 } else {
174 doc.remove (start, end - start);
175 doc.insertString (start, str, null);
176 }} catch (e) {
177 if (Clazz.exceptionOf (e, javax.swing.text.BadLocationException)) {
178 throw  new IllegalArgumentException (e.getMessage ());
179 } else {
180 throw e;
181 }
182 }
183 }}, "~S,~N,~N");
184 Clazz.defineMethod (c$, "getRows", 
185 function () {
186 return this.rows;
187 });
188 Clazz.defineMethod (c$, "setRows", 
189 function (rows) {
190 var oldVal = this.rows;
191 if (rows < 0) {
192 throw  new IllegalArgumentException ("rows less than zero.");
193 }if (rows != oldVal) {
194 this.rows = rows;
195 this.invalidate ();
196 }}, "~N");
197 Clazz.defineMethod (c$, "getRowHeight", 
198 function () {
199 if (this.rowHeight == 0) {
200 var metrics = this.getFontMetrics (this.getFont ());
201 this.rowHeight = metrics.getHeight ();
202 }return this.rowHeight;
203 });
204 Clazz.defineMethod (c$, "getColumns", 
205 function () {
206 return this.columns;
207 });
208 Clazz.defineMethod (c$, "setColumns", 
209 function (columns) {
210 var oldVal = this.columns;
211 if (columns < 0) {
212 throw  new IllegalArgumentException ("columns less than zero.");
213 }if (columns != oldVal) {
214 this.columns = columns;
215 this.invalidate ();
216 }}, "~N");
217 Clazz.defineMethod (c$, "getColumnWidth", 
218 function () {
219 if (this.columnWidth == 0) {
220 var metrics = this.getFontMetrics (this.getFont ());
221 this.columnWidth = metrics.charWidth ('m');
222 }return this.columnWidth;
223 });
224 Clazz.overrideMethod (c$, "getPreferredSize", 
225 function () {
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);
233 }return d;
234 });
235 Clazz.defineMethod (c$, "setFont", 
236 function (f) {
237 Clazz.superCall (this, javax.swing.JTextArea, "setFont", [f]);
238 this.rowHeight = 0;
239 this.columnWidth = 0;
240 }, "java.awt.Font");
241 Clazz.defineMethod (c$, "paramString", 
242 function () {
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;
246 });
247 Clazz.defineMethod (c$, "getScrollableTracksViewportWidth", 
248 function () {
249 return (this.wrap) ? true : Clazz.superCall (this, javax.swing.JTextArea, "getScrollableTracksViewportWidth", []);
250 });
251 Clazz.defineMethod (c$, "getPreferredScrollableViewportSize", 
252 function () {
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;
258 return size;
259 });
260 Clazz.overrideMethod (c$, "getScrollableUnitIncrement", 
261 function (visibleRect, orientation, direction) {
262 switch (orientation) {
263 case 1:
264 return this.getRowHeight ();
265 case 0:
266 return this.getColumnWidth ();
267 default:
268 throw  new IllegalArgumentException ("Invalid orientation: " + orientation);
269 }
270 }, "java.awt.Rectangle,~N,~N");
271 Clazz.defineStatics (c$,
272 "$uiClassID", "TextAreaUI");
273 });