0d9bcd64b1de838763a45d9e48c95dd422c11131
[jalviewjs.git] / site / j2s / javax / swing / text / StyledEditorKit.js
1 Clazz.declarePackage ("javax.swing.text");
2 Clazz.load (["java.beans.PropertyChangeListener", "javax.swing.event.CaretListener", "javax.swing.text.DefaultEditorKit", "$.TextAction", "$.ViewFactory"], "javax.swing.text.StyledEditorKit", ["java.lang.IllegalArgumentException", "java.awt.Color", "javax.swing.JEditorPane", "$.UIManager", "javax.swing.text.BoxView", "$.ComponentView", "$.Document", "$.IconView", "$.JTextComponent", "$.LabelView", "$.ParagraphView", "$.SimpleAttributeSet", "$.StyleConstants", "$.StyledDocument"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.currentRun = null;
5 this.currentParagraph = null;
6 this.inputAttributes = null;
7 this.inputAttributeUpdater = null;
8 if (!Clazz.isClassDefined ("javax.swing.text.StyledEditorKit.AttributeTracker")) {
9 javax.swing.text.StyledEditorKit.$StyledEditorKit$AttributeTracker$ ();
10 }
11 Clazz.instantialize (this, arguments);
12 }, javax.swing.text, "StyledEditorKit", javax.swing.text.DefaultEditorKit);
13 Clazz.makeConstructor (c$, 
14 function () {
15 Clazz.superConstructor (this, javax.swing.text.StyledEditorKit, []);
16 this.createInputAttributeUpdated ();
17 this.createInputAttributes ();
18 });
19 Clazz.overrideMethod (c$, "getInputAttributes", 
20 function () {
21 return this.inputAttributes;
22 });
23 Clazz.defineMethod (c$, "getCharacterAttributeRun", 
24 function () {
25 return this.currentRun;
26 });
27 Clazz.defineMethod (c$, "getActions", 
28 function () {
29 return javax.swing.text.TextAction.augmentList (Clazz.superCall (this, javax.swing.text.StyledEditorKit, "getActions", []), javax.swing.text.StyledEditorKit.$defaultActions);
30 });
31 Clazz.overrideMethod (c$, "createDefaultDocument", 
32 function () {
33 return null;
34 });
35 Clazz.overrideMethod (c$, "install", 
36 function (c) {
37 c.addCaretListener (this.inputAttributeUpdater);
38 c.addPropertyChangeListener (this.inputAttributeUpdater);
39 var caret = c.getCaret ();
40 if (caret != null) {
41 this.inputAttributeUpdater.updateInputAttributes (caret.getDot (), caret.getMark (), c);
42 }}, "javax.swing.JEditorPane");
43 Clazz.overrideMethod (c$, "deinstall", 
44 function (c) {
45 c.removeCaretListener (this.inputAttributeUpdater);
46 c.removePropertyChangeListener (this.inputAttributeUpdater);
47 this.currentRun = null;
48 this.currentParagraph = null;
49 }, "javax.swing.JEditorPane");
50 Clazz.overrideMethod (c$, "getViewFactory", 
51 function () {
52 return javax.swing.text.StyledEditorKit.defaultFactory;
53 });
54 Clazz.defineMethod (c$, "clone", 
55 function () {
56 var o = Clazz.superCall (this, javax.swing.text.StyledEditorKit, "clone", []);
57 o.currentRun = o.currentParagraph = null;
58 o.createInputAttributeUpdated ();
59 o.createInputAttributes ();
60 return o;
61 });
62 Clazz.defineMethod (c$, "createInputAttributes", 
63  function () {
64 this.inputAttributes = ((Clazz.isClassDefined ("javax.swing.text.StyledEditorKit$1") ? 0 : javax.swing.text.StyledEditorKit.$StyledEditorKit$1$ ()), Clazz.innerTypeInstance (javax.swing.text.StyledEditorKit$1, this, null));
65 });
66 Clazz.defineMethod (c$, "createInputAttributeUpdated", 
67  function () {
68 this.inputAttributeUpdater = Clazz.innerTypeInstance (javax.swing.text.StyledEditorKit.AttributeTracker, this, null);
69 });
70 Clazz.defineMethod (c$, "createInputAttributes", 
71 function (element, set) {
72 if (element.getAttributes ().getAttributeCount () > 0 || element.getEndOffset () - element.getStartOffset () > 1 || element.getEndOffset () < element.getDocument ().getLength ()) {
73 set.removeAttributes (set);
74 set.addAttributes (element.getAttributes ());
75 set.removeAttribute (javax.swing.text.StyleConstants.ComponentAttribute);
76 set.removeAttribute (javax.swing.text.StyleConstants.IconAttribute);
77 set.removeAttribute ("$ename");
78 set.removeAttribute (javax.swing.text.StyleConstants.ComposedTextAttribute);
79 }}, "javax.swing.text.Element,javax.swing.text.MutableAttributeSet");
80 c$.$StyledEditorKit$AttributeTracker$ = function () {
81 Clazz.pu$h(self.c$);
82 c$ = Clazz.decorateAsClass (function () {
83 Clazz.prepareCallback (this, arguments);
84 Clazz.instantialize (this, arguments);
85 }, javax.swing.text.StyledEditorKit, "AttributeTracker", null, [javax.swing.event.CaretListener, java.beans.PropertyChangeListener]);
86 Clazz.defineMethod (c$, "updateInputAttributes", 
87 function (a, b, c) {
88 var d = c.getDocument ();
89 if (!(Clazz.instanceOf (d, javax.swing.text.StyledDocument))) {
90 return;
91 }var e = Math.min (a, b);
92 var f = d;
93 var g;
94 this.b$["javax.swing.text.StyledEditorKit"].currentParagraph = f.getParagraphElement (e);
95 if (this.b$["javax.swing.text.StyledEditorKit"].currentParagraph.getStartOffset () == e || a != b) {
96 g = f.getCharacterElement (e);
97 } else {
98 g = f.getCharacterElement (Math.max (e - 1, 0));
99 }if (g !== this.b$["javax.swing.text.StyledEditorKit"].currentRun) {
100 this.b$["javax.swing.text.StyledEditorKit"].currentRun = g;
101 this.b$["javax.swing.text.StyledEditorKit"].createInputAttributes (this.b$["javax.swing.text.StyledEditorKit"].currentRun, this.b$["javax.swing.text.StyledEditorKit"].getInputAttributes ());
102 }}, "~N,~N,javax.swing.text.JTextComponent");
103 Clazz.overrideMethod (c$, "propertyChange", 
104 function (a) {
105 var b = a.getNewValue ();
106 var c = a.getSource ();
107 if ((Clazz.instanceOf (c, javax.swing.text.JTextComponent)) && (Clazz.instanceOf (b, javax.swing.text.Document))) {
108 this.updateInputAttributes (0, 0, c);
109 }}, "java.beans.PropertyChangeEvent");
110 Clazz.overrideMethod (c$, "caretUpdate", 
111 function (a) {
112 this.updateInputAttributes (a.getDot (), a.getMark (), a.getSource ());
113 }, "javax.swing.event.CaretEvent");
114 c$ = Clazz.p0p ();
115 };
116 c$.$StyledEditorKit$1$ = function () {
117 Clazz.pu$h(self.c$);
118 c$ = Clazz.declareAnonymous (javax.swing.text, "StyledEditorKit$1", javax.swing.text.SimpleAttributeSet);
119 Clazz.overrideMethod (c$, "getResolveParent", 
120 function () {
121 return (this.b$["javax.swing.text.StyledEditorKit"].currentParagraph != null) ? this.b$["javax.swing.text.StyledEditorKit"].currentParagraph.getAttributes () : null;
122 });
123 Clazz.overrideMethod (c$, "clone", 
124 function () {
125 return  new javax.swing.text.SimpleAttributeSet (this);
126 });
127 c$ = Clazz.p0p ();
128 };
129 Clazz.pu$h(self.c$);
130 c$ = Clazz.declareType (javax.swing.text.StyledEditorKit, "StyledViewFactory", null, javax.swing.text.ViewFactory);
131 Clazz.overrideMethod (c$, "create", 
132 function (a) {
133 var b = a.getName ();
134 if (b != null) {
135 if (b.equals ("content")) {
136 return  new javax.swing.text.LabelView (a);
137 } else if (b.equals ("paragraph")) {
138 return  new javax.swing.text.ParagraphView (a);
139 } else if (b.equals ("section")) {
140 return  new javax.swing.text.BoxView (a, 1);
141 } else if (b.equals ("component")) {
142 return  new javax.swing.text.ComponentView (a);
143 } else if (b.equals ("icon")) {
144 return  new javax.swing.text.IconView (a);
145 }}return  new javax.swing.text.LabelView (a);
146 }, "javax.swing.text.Element");
147 c$ = Clazz.p0p ();
148 Clazz.pu$h(self.c$);
149 c$ = Clazz.declareType (javax.swing.text.StyledEditorKit, "StyledTextAction", javax.swing.text.TextAction);
150 Clazz.defineMethod (c$, "getEditor", 
151 function (a) {
152 var b = this.getTextComponent (a);
153 if (Clazz.instanceOf (b, javax.swing.JEditorPane)) {
154 return b;
155 }return null;
156 }, "java.awt.event.ActionEvent");
157 Clazz.defineMethod (c$, "getStyledDocument", 
158 function (a) {
159 var b = a.getDocument ();
160 if (Clazz.instanceOf (b, javax.swing.text.StyledDocument)) {
161 return b;
162 }throw  new IllegalArgumentException ("document must be StyledDocument");
163 }, "javax.swing.JEditorPane");
164 Clazz.defineMethod (c$, "getStyledEditorKit", 
165 function (a) {
166 var b = a.getEditorKit ();
167 if (Clazz.instanceOf (b, javax.swing.text.StyledEditorKit)) {
168 return b;
169 }throw  new IllegalArgumentException ("EditorKit must be StyledEditorKit");
170 }, "javax.swing.JEditorPane");
171 Clazz.defineMethod (c$, "setCharacterAttributes", 
172 function (a, b, c) {
173 var d = a.getSelectionStart ();
174 var e = a.getSelectionEnd ();
175 if (d != e) {
176 var f = this.getStyledDocument (a);
177 f.setCharacterAttributes (d, e - d, b, c);
178 }var f = this.getStyledEditorKit (a);
179 var g = f.getInputAttributes ();
180 if (c) {
181 g.removeAttributes (g);
182 }g.addAttributes (b);
183 }, "javax.swing.JEditorPane,javax.swing.text.AttributeSet,~B");
184 Clazz.defineMethod (c$, "setParagraphAttributes", 
185 function (a, b, c) {
186 var d = a.getSelectionStart ();
187 var e = a.getSelectionEnd ();
188 var f = this.getStyledDocument (a);
189 f.setParagraphAttributes (d, e - d, b, c);
190 }, "javax.swing.JEditorPane,javax.swing.text.AttributeSet,~B");
191 c$ = Clazz.p0p ();
192 Clazz.pu$h(self.c$);
193 c$ = Clazz.decorateAsClass (function () {
194 this.family = null;
195 Clazz.instantialize (this, arguments);
196 }, javax.swing.text.StyledEditorKit, "FontFamilyAction", javax.swing.text.StyledEditorKit.StyledTextAction);
197 Clazz.makeConstructor (c$, 
198 function (a, b) {
199 Clazz.superConstructor (this, javax.swing.text.StyledEditorKit.FontFamilyAction, [a]);
200 this.family = b;
201 }, "~S,~S");
202 Clazz.overrideMethod (c$, "actionPerformed", 
203 function (a) {
204 var b = this.getEditor (a);
205 if (b != null) {
206 var c = this.family;
207 if ((a != null) && (a.getSource () === b)) {
208 var d = a.getActionCommand ();
209 if (d != null) {
210 c = d;
211 }}if (c != null) {
212 var d =  new javax.swing.text.SimpleAttributeSet ();
213 javax.swing.text.StyleConstants.setFontFamily (d, c);
214 this.setCharacterAttributes (b, d, false);
215 } else {
216 javax.swing.UIManager.getLookAndFeel ().provideErrorFeedback (b);
217 }}}, "java.awt.event.ActionEvent");
218 c$ = Clazz.p0p ();
219 Clazz.pu$h(self.c$);
220 c$ = Clazz.decorateAsClass (function () {
221 this.size = 0;
222 Clazz.instantialize (this, arguments);
223 }, javax.swing.text.StyledEditorKit, "FontSizeAction", javax.swing.text.StyledEditorKit.StyledTextAction);
224 Clazz.makeConstructor (c$, 
225 function (a, b) {
226 Clazz.superConstructor (this, javax.swing.text.StyledEditorKit.FontSizeAction, [a]);
227 this.size = b;
228 }, "~S,~N");
229 Clazz.overrideMethod (c$, "actionPerformed", 
230 function (a) {
231 var b = this.getEditor (a);
232 if (b != null) {
233 var c = this.size;
234 if ((a != null) && (a.getSource () === b)) {
235 var d = a.getActionCommand ();
236 try {
237 c = Integer.parseInt (d, 10);
238 } catch (nfe) {
239 if (Clazz.exceptionOf (nfe, NumberFormatException)) {
240 } else {
241 throw nfe;
242 }
243 }
244 }if (c != 0) {
245 var d =  new javax.swing.text.SimpleAttributeSet ();
246 javax.swing.text.StyleConstants.setFontSize (d, c);
247 this.setCharacterAttributes (b, d, false);
248 } else {
249 javax.swing.UIManager.getLookAndFeel ().provideErrorFeedback (b);
250 }}}, "java.awt.event.ActionEvent");
251 c$ = Clazz.p0p ();
252 Clazz.pu$h(self.c$);
253 c$ = Clazz.decorateAsClass (function () {
254 this.fg = null;
255 Clazz.instantialize (this, arguments);
256 }, javax.swing.text.StyledEditorKit, "ForegroundAction", javax.swing.text.StyledEditorKit.StyledTextAction);
257 Clazz.makeConstructor (c$, 
258 function (a, b) {
259 Clazz.superConstructor (this, javax.swing.text.StyledEditorKit.ForegroundAction, [a]);
260 this.fg = b;
261 }, "~S,java.awt.Color");
262 Clazz.overrideMethod (c$, "actionPerformed", 
263 function (a) {
264 var b = this.getEditor (a);
265 if (b != null) {
266 var c = this.fg;
267 if ((a != null) && (a.getSource () === b)) {
268 var d = a.getActionCommand ();
269 try {
270 c = java.awt.Color.decode (d);
271 } catch (nfe) {
272 if (Clazz.exceptionOf (nfe, NumberFormatException)) {
273 } else {
274 throw nfe;
275 }
276 }
277 }if (c != null) {
278 var d =  new javax.swing.text.SimpleAttributeSet ();
279 javax.swing.text.StyleConstants.setForeground (d, c);
280 this.setCharacterAttributes (b, d, false);
281 } else {
282 javax.swing.UIManager.getLookAndFeel ().provideErrorFeedback (b);
283 }}}, "java.awt.event.ActionEvent");
284 c$ = Clazz.p0p ();
285 Clazz.pu$h(self.c$);
286 c$ = Clazz.decorateAsClass (function () {
287 this.a = 0;
288 Clazz.instantialize (this, arguments);
289 }, javax.swing.text.StyledEditorKit, "AlignmentAction", javax.swing.text.StyledEditorKit.StyledTextAction);
290 Clazz.makeConstructor (c$, 
291 function (a, b) {
292 Clazz.superConstructor (this, javax.swing.text.StyledEditorKit.AlignmentAction, [a]);
293 this.a = b;
294 }, "~S,~N");
295 Clazz.overrideMethod (c$, "actionPerformed", 
296 function (a) {
297 var b = this.getEditor (a);
298 if (b != null) {
299 var c = this.a;
300 if ((a != null) && (a.getSource () === b)) {
301 var d = a.getActionCommand ();
302 try {
303 c = Integer.parseInt (d, 10);
304 } catch (nfe) {
305 if (Clazz.exceptionOf (nfe, NumberFormatException)) {
306 } else {
307 throw nfe;
308 }
309 }
310 }var d =  new javax.swing.text.SimpleAttributeSet ();
311 javax.swing.text.StyleConstants.setAlignment (d, c);
312 this.setParagraphAttributes (b, d, false);
313 }}, "java.awt.event.ActionEvent");
314 c$ = Clazz.p0p ();
315 Clazz.pu$h(self.c$);
316 c$ = Clazz.declareType (javax.swing.text.StyledEditorKit, "BoldAction", javax.swing.text.StyledEditorKit.StyledTextAction);
317 Clazz.makeConstructor (c$, 
318 function () {
319 Clazz.superConstructor (this, javax.swing.text.StyledEditorKit.BoldAction, ["font-bold"]);
320 });
321 Clazz.overrideMethod (c$, "actionPerformed", 
322 function (a) {
323 var b = this.getEditor (a);
324 if (b != null) {
325 var c = this.getStyledEditorKit (b);
326 var d = c.getInputAttributes ();
327 var e = (javax.swing.text.StyleConstants.isBold (d)) ? false : true;
328 var f =  new javax.swing.text.SimpleAttributeSet ();
329 javax.swing.text.StyleConstants.setBold (f, e);
330 this.setCharacterAttributes (b, f, false);
331 }}, "java.awt.event.ActionEvent");
332 c$ = Clazz.p0p ();
333 Clazz.pu$h(self.c$);
334 c$ = Clazz.declareType (javax.swing.text.StyledEditorKit, "ItalicAction", javax.swing.text.StyledEditorKit.StyledTextAction);
335 Clazz.makeConstructor (c$, 
336 function () {
337 Clazz.superConstructor (this, javax.swing.text.StyledEditorKit.ItalicAction, ["font-italic"]);
338 });
339 Clazz.overrideMethod (c$, "actionPerformed", 
340 function (a) {
341 var b = this.getEditor (a);
342 if (b != null) {
343 var c = this.getStyledEditorKit (b);
344 var d = c.getInputAttributes ();
345 var e = (javax.swing.text.StyleConstants.isItalic (d)) ? false : true;
346 var f =  new javax.swing.text.SimpleAttributeSet ();
347 javax.swing.text.StyleConstants.setItalic (f, e);
348 this.setCharacterAttributes (b, f, false);
349 }}, "java.awt.event.ActionEvent");
350 c$ = Clazz.p0p ();
351 Clazz.pu$h(self.c$);
352 c$ = Clazz.declareType (javax.swing.text.StyledEditorKit, "UnderlineAction", javax.swing.text.StyledEditorKit.StyledTextAction);
353 Clazz.makeConstructor (c$, 
354 function () {
355 Clazz.superConstructor (this, javax.swing.text.StyledEditorKit.UnderlineAction, ["font-underline"]);
356 });
357 Clazz.overrideMethod (c$, "actionPerformed", 
358 function (a) {
359 var b = this.getEditor (a);
360 if (b != null) {
361 var c = this.getStyledEditorKit (b);
362 var d = c.getInputAttributes ();
363 var e = (javax.swing.text.StyleConstants.isUnderline (d)) ? false : true;
364 var f =  new javax.swing.text.SimpleAttributeSet ();
365 javax.swing.text.StyleConstants.setUnderline (f, e);
366 this.setCharacterAttributes (b, f, false);
367 }}, "java.awt.event.ActionEvent");
368 c$ = Clazz.p0p ();
369 Clazz.pu$h(self.c$);
370 c$ = Clazz.decorateAsClass (function () {
371 this.tempSet = null;
372 Clazz.instantialize (this, arguments);
373 }, javax.swing.text.StyledEditorKit, "StyledInsertBreakAction", javax.swing.text.StyledEditorKit.StyledTextAction);
374 Clazz.makeConstructor (c$, 
375 function () {
376 Clazz.superConstructor (this, javax.swing.text.StyledEditorKit.StyledInsertBreakAction, ["insert-break"]);
377 });
378 Clazz.overrideMethod (c$, "actionPerformed", 
379 function (a) {
380 var b = this.getEditor (a);
381 if (b != null) {
382 if ((!b.isEditable ()) || (!b.isEnabled ())) {
383 javax.swing.UIManager.getLookAndFeel ().provideErrorFeedback (b);
384 return;
385 }var c = this.getStyledEditorKit (b);
386 if (this.tempSet != null) {
387 this.tempSet.removeAttributes (this.tempSet);
388 } else {
389 this.tempSet =  new javax.swing.text.SimpleAttributeSet ();
390 }this.tempSet.addAttributes (c.getInputAttributes ());
391 b.replaceSelection ("\n");
392 var d = c.getInputAttributes ();
393 d.removeAttributes (d);
394 d.addAttributes (this.tempSet);
395 this.tempSet.removeAttributes (this.tempSet);
396 } else {
397 var c = this.getTextComponent (a);
398 if (c != null) {
399 if ((!c.isEditable ()) || (!c.isEnabled ())) {
400 javax.swing.UIManager.getLookAndFeel ().provideErrorFeedback (b);
401 return;
402 }c.replaceSelection ("\n");
403 }}}, "java.awt.event.ActionEvent");
404 c$ = Clazz.p0p ();
405 c$.defaultFactory = c$.prototype.defaultFactory =  new javax.swing.text.StyledEditorKit.StyledViewFactory ();
406 c$.$defaultActions = c$.prototype.$defaultActions =  Clazz.newArray (-1, [ new javax.swing.text.StyledEditorKit.FontFamilyAction ("font-family-SansSerif", "SansSerif"),  new javax.swing.text.StyledEditorKit.FontFamilyAction ("font-family-Monospaced", "Monospaced"),  new javax.swing.text.StyledEditorKit.FontFamilyAction ("font-family-Serif", "Serif"),  new javax.swing.text.StyledEditorKit.FontSizeAction ("font-size-8", 8),  new javax.swing.text.StyledEditorKit.FontSizeAction ("font-size-10", 10),  new javax.swing.text.StyledEditorKit.FontSizeAction ("font-size-12", 12),  new javax.swing.text.StyledEditorKit.FontSizeAction ("font-size-14", 14),  new javax.swing.text.StyledEditorKit.FontSizeAction ("font-size-16", 16),  new javax.swing.text.StyledEditorKit.FontSizeAction ("font-size-18", 18),  new javax.swing.text.StyledEditorKit.FontSizeAction ("font-size-24", 24),  new javax.swing.text.StyledEditorKit.FontSizeAction ("font-size-36", 36),  new javax.swing.text.StyledEditorKit.FontSizeAction ("font-size-48", 48),  new javax.swing.text.StyledEditorKit.AlignmentAction ("left-justify", 0),  new javax.swing.text.StyledEditorKit.AlignmentAction ("center-justify", 1),  new javax.swing.text.StyledEditorKit.AlignmentAction ("right-justify", 2),  new javax.swing.text.StyledEditorKit.BoldAction (),  new javax.swing.text.StyledEditorKit.ItalicAction (),  new javax.swing.text.StyledEditorKit.StyledInsertBreakAction (),  new javax.swing.text.StyledEditorKit.UnderlineAction ()]);
407 });