1 Clazz.declarePackage ("javax.swing");
2 Clazz.load (["javax.swing.JEditorPane"], "javax.swing.JTextPane", ["java.lang.IllegalArgumentException", "javax.swing.UIManager", "javax.swing.text.JSMinimalAbstractDocument", "$.StyleConstants", "$.StyledDocument", "$.StyledEditorKit"], function () {
3 c$ = Clazz.declareType (javax.swing, "JTextPane", javax.swing.JEditorPane);
4 Clazz.makeConstructor (c$,
6 Clazz.superConstructor (this, javax.swing.JTextPane);
7 var editorKit = this.createDefaultEditorKit ();
8 var contentType = editorKit.getContentType ();
9 if (contentType != null && javax.swing.JEditorPane.getEditorKitClassNameForContentType (contentType) === javax.swing.JEditorPane.defaultEditorKitMap.get (contentType)) {
10 this.setEditorKitForContentType (contentType, editorKit);
11 }this.setEditorKit (editorKit);
13 Clazz.makeConstructor (c$,
16 this.setStyledDocument (doc);
17 }, "javax.swing.text.StyledDocument");
18 Clazz.overrideMethod (c$, "getUIClassID",
22 Clazz.defineMethod (c$, "setDocument",
24 if (Clazz.instanceOf (doc, javax.swing.text.StyledDocument)) {
25 Clazz.superCall (this, javax.swing.JTextPane, "setDocument", [doc]);
27 throw new IllegalArgumentException ("Model must be StyledDocument");
28 }}, "javax.swing.text.Document");
29 Clazz.defineMethod (c$, "setStyledDocument",
31 Clazz.superCall (this, javax.swing.JTextPane, "setDocument", [doc]);
32 }, "javax.swing.text.StyledDocument");
33 Clazz.defineMethod (c$, "getStyledDocument",
35 return this.getDocument ();
37 Clazz.defineMethod (c$, "replaceSelection",
39 this.replaceSelection (content, true);
41 Clazz.defineMethod (c$, "replaceSelection",
42 function (content, checkEditable) {
43 if (checkEditable && !this.isEditable ()) {
44 javax.swing.UIManager.getLookAndFeel ().provideErrorFeedback (this);
46 }var doc = this.getStyledDocument ();
49 var caret = this.getCaret ();
50 var p0 = Math.min (caret.getDot (), caret.getMark ());
51 var p1 = Math.max (caret.getDot (), caret.getMark ());
52 var attr = this.getInputAttributes ().copyAttributes ();
53 if (Clazz.instanceOf (doc, javax.swing.text.JSMinimalAbstractDocument)) {
54 (doc).replace (p0, p1 - p0, content, attr);
57 doc.remove (p0, p1 - p0);
58 }if (content != null && content.length > 0) {
59 doc.insertString (p0, content, attr);
61 if (Clazz.exceptionOf (e, javax.swing.text.BadLocationException)) {
62 javax.swing.UIManager.getLookAndFeel ().provideErrorFeedback (this);
68 Clazz.defineMethod (c$, "insertComponent",
70 var inputAttributes = this.getInputAttributes ();
71 inputAttributes.removeAttributes (inputAttributes);
72 javax.swing.text.StyleConstants.setComponent (inputAttributes, c);
73 this.replaceSelection (" ", false);
74 inputAttributes.removeAttributes (inputAttributes);
75 }, "java.awt.Component");
76 Clazz.defineMethod (c$, "insertIcon",
78 var inputAttributes = this.getInputAttributes ();
79 inputAttributes.removeAttributes (inputAttributes);
80 javax.swing.text.StyleConstants.setIcon (inputAttributes, g);
81 this.replaceSelection (" ", false);
82 inputAttributes.removeAttributes (inputAttributes);
83 }, "javax.swing.Icon");
84 Clazz.defineMethod (c$, "addStyle",
85 function (nm, parent) {
86 var doc = this.getStyledDocument ();
87 return doc.addStyle (nm, parent);
88 }, "~S,javax.swing.text.Style");
89 Clazz.defineMethod (c$, "removeStyle",
91 var doc = this.getStyledDocument ();
94 Clazz.defineMethod (c$, "getStyle",
96 var doc = this.getStyledDocument ();
97 return doc.getStyle (nm);
99 Clazz.defineMethod (c$, "setLogicalStyle",
101 var doc = this.getStyledDocument ();
102 doc.setLogicalStyle (this.getCaretPosition (), s);
103 }, "javax.swing.text.Style");
104 Clazz.defineMethod (c$, "getLogicalStyle",
106 var doc = this.getStyledDocument ();
107 return doc.getLogicalStyle (this.getCaretPosition ());
109 Clazz.defineMethod (c$, "getCharacterAttributes",
111 var doc = this.getStyledDocument ();
112 var run = doc.getCharacterElement (this.getCaretPosition ());
114 return run.getAttributes ();
117 Clazz.defineMethod (c$, "setCharacterAttributes",
118 function (attr, replace) {
119 var p0 = this.getSelectionStart ();
120 var p1 = this.getSelectionEnd ();
122 var doc = this.getStyledDocument ();
123 doc.setCharacterAttributes (p0, p1 - p0, attr, replace);
125 var inputAttributes = this.getInputAttributes ();
127 inputAttributes.removeAttributes (inputAttributes);
128 }inputAttributes.addAttributes (attr);
129 }}, "javax.swing.text.AttributeSet,~B");
130 Clazz.defineMethod (c$, "getParagraphAttributes",
132 var doc = this.getStyledDocument ();
133 var paragraph = doc.getParagraphElement (this.getCaretPosition ());
134 if (paragraph != null) {
135 return paragraph.getAttributes ();
138 Clazz.defineMethod (c$, "setParagraphAttributes",
139 function (attr, replace) {
140 var p0 = this.getSelectionStart ();
141 var p1 = this.getSelectionEnd ();
142 var doc = this.getStyledDocument ();
143 doc.setParagraphAttributes (p0, p1 - p0, attr, replace);
144 }, "javax.swing.text.AttributeSet,~B");
145 Clazz.defineMethod (c$, "getInputAttributes",
147 return this.getStyledEditorKit ().getInputAttributes ();
149 Clazz.defineMethod (c$, "getStyledEditorKit",
151 return this.getEditorKit ();
153 Clazz.overrideMethod (c$, "createDefaultEditorKit",
155 return new javax.swing.text.StyledEditorKit ();
157 Clazz.defineMethod (c$, "setEditorKit",
159 if (Clazz.instanceOf (kit, javax.swing.text.StyledEditorKit)) {
160 Clazz.superCall (this, javax.swing.JTextPane, "setEditorKit", [kit]);
162 throw new IllegalArgumentException ("Must be StyledEditorKit");
163 }}, "javax.swing.text.EditorKit");
164 Clazz.defineStatics (c$,
165 "$$uiClassID", "TextPaneUI");