921224840dc2c63443b5abd414491c74594e6a0e
[jalviewjs.git] / site / j2s / javax / swing / JTextPane.js
1 Clazz.declarePackage ("javax.swing");\r
2 Clazz.load (["javax.swing.JEditorPane"], "javax.swing.JTextPane", ["java.lang.IllegalArgumentException", "javax.swing.UIManager", "javax.swing.text.JSMinimalAbstractDocument", "$.StyleConstants", "$.StyledDocument", "$.StyledEditorKit"], function () {\r
3 c$ = Clazz.declareType (javax.swing, "JTextPane", javax.swing.JEditorPane);\r
4 Clazz.makeConstructor (c$, \r
5 function () {\r
6 Clazz.superConstructor (this, javax.swing.JTextPane);\r
7 var editorKit = this.createDefaultEditorKit ();\r
8 var contentType = editorKit.getContentType ();\r
9 if (contentType != null && javax.swing.JEditorPane.getEditorKitClassNameForContentType (contentType) === javax.swing.JEditorPane.defaultEditorKitMap.get (contentType)) {\r
10 this.setEditorKitForContentType (contentType, editorKit);\r
11 }this.setEditorKit (editorKit);\r
12 });\r
13 Clazz.makeConstructor (c$, \r
14 function (doc) {\r
15 this.construct ();\r
16 this.setStyledDocument (doc);\r
17 }, "javax.swing.text.StyledDocument");\r
18 Clazz.overrideMethod (c$, "getUIClassID", \r
19 function () {\r
20 return "TextPaneUI";\r
21 });\r
22 Clazz.defineMethod (c$, "setDocument", \r
23 function (doc) {\r
24 if (Clazz.instanceOf (doc, javax.swing.text.StyledDocument)) {\r
25 Clazz.superCall (this, javax.swing.JTextPane, "setDocument", [doc]);\r
26 } else {\r
27 throw  new IllegalArgumentException ("Model must be StyledDocument");\r
28 }}, "javax.swing.text.Document");\r
29 Clazz.defineMethod (c$, "setStyledDocument", \r
30 function (doc) {\r
31 Clazz.superCall (this, javax.swing.JTextPane, "setDocument", [doc]);\r
32 }, "javax.swing.text.StyledDocument");\r
33 Clazz.defineMethod (c$, "getStyledDocument", \r
34 function () {\r
35 return this.getDocument ();\r
36 });\r
37 Clazz.defineMethod (c$, "replaceSelection", \r
38 function (content) {\r
39 this.replaceSelection (content, true);\r
40 }, "~S");\r
41 Clazz.defineMethod (c$, "replaceSelection", \r
42  function (content, checkEditable) {\r
43 if (checkEditable && !this.isEditable ()) {\r
44 javax.swing.UIManager.getLookAndFeel ().provideErrorFeedback (this);\r
45 return;\r
46 }var doc = this.getStyledDocument ();\r
47 if (doc != null) {\r
48 try {\r
49 var caret = this.getCaret ();\r
50 var p0 = Math.min (caret.getDot (), caret.getMark ());\r
51 var p1 = Math.max (caret.getDot (), caret.getMark ());\r
52 var attr = this.getInputAttributes ().copyAttributes ();\r
53 if (Clazz.instanceOf (doc, javax.swing.text.JSMinimalAbstractDocument)) {\r
54 (doc).replace (p0, p1 - p0, content, attr);\r
55 } else {\r
56 if (p0 != p1) {\r
57 doc.remove (p0, p1 - p0);\r
58 }if (content != null && content.length > 0) {\r
59 doc.insertString (p0, content, attr);\r
60 }}} catch (e) {\r
61 if (Clazz.exceptionOf (e, javax.swing.text.BadLocationException)) {\r
62 javax.swing.UIManager.getLookAndFeel ().provideErrorFeedback (this);\r
63 } else {\r
64 throw e;\r
65 }\r
66 }\r
67 }}, "~S,~B");\r
68 Clazz.defineMethod (c$, "insertComponent", \r
69 function (c) {\r
70 var inputAttributes = this.getInputAttributes ();\r
71 inputAttributes.removeAttributes (inputAttributes);\r
72 javax.swing.text.StyleConstants.setComponent (inputAttributes, c);\r
73 this.replaceSelection (" ", false);\r
74 inputAttributes.removeAttributes (inputAttributes);\r
75 }, "java.awt.Component");\r
76 Clazz.defineMethod (c$, "insertIcon", \r
77 function (g) {\r
78 var inputAttributes = this.getInputAttributes ();\r
79 inputAttributes.removeAttributes (inputAttributes);\r
80 javax.swing.text.StyleConstants.setIcon (inputAttributes, g);\r
81 this.replaceSelection (" ", false);\r
82 inputAttributes.removeAttributes (inputAttributes);\r
83 }, "javax.swing.Icon");\r
84 Clazz.defineMethod (c$, "addStyle", \r
85 function (nm, parent) {\r
86 var doc = this.getStyledDocument ();\r
87 return doc.addStyle (nm, parent);\r
88 }, "~S,javax.swing.text.Style");\r
89 Clazz.defineMethod (c$, "removeStyle", \r
90 function (nm) {\r
91 var doc = this.getStyledDocument ();\r
92 doc.removeStyle (nm);\r
93 }, "~S");\r
94 Clazz.defineMethod (c$, "getStyle", \r
95 function (nm) {\r
96 var doc = this.getStyledDocument ();\r
97 return doc.getStyle (nm);\r
98 }, "~S");\r
99 Clazz.defineMethod (c$, "setLogicalStyle", \r
100 function (s) {\r
101 var doc = this.getStyledDocument ();\r
102 doc.setLogicalStyle (this.getCaretPosition (), s);\r
103 }, "javax.swing.text.Style");\r
104 Clazz.defineMethod (c$, "getLogicalStyle", \r
105 function () {\r
106 var doc = this.getStyledDocument ();\r
107 return doc.getLogicalStyle (this.getCaretPosition ());\r
108 });\r
109 Clazz.defineMethod (c$, "getCharacterAttributes", \r
110 function () {\r
111 var doc = this.getStyledDocument ();\r
112 var run = doc.getCharacterElement (this.getCaretPosition ());\r
113 if (run != null) {\r
114 return run.getAttributes ();\r
115 }return null;\r
116 });\r
117 Clazz.defineMethod (c$, "setCharacterAttributes", \r
118 function (attr, replace) {\r
119 var p0 = this.getSelectionStart ();\r
120 var p1 = this.getSelectionEnd ();\r
121 if (p0 != p1) {\r
122 var doc = this.getStyledDocument ();\r
123 doc.setCharacterAttributes (p0, p1 - p0, attr, replace);\r
124 } else {\r
125 var inputAttributes = this.getInputAttributes ();\r
126 if (replace) {\r
127 inputAttributes.removeAttributes (inputAttributes);\r
128 }inputAttributes.addAttributes (attr);\r
129 }}, "javax.swing.text.AttributeSet,~B");\r
130 Clazz.defineMethod (c$, "getParagraphAttributes", \r
131 function () {\r
132 var doc = this.getStyledDocument ();\r
133 var paragraph = doc.getParagraphElement (this.getCaretPosition ());\r
134 if (paragraph != null) {\r
135 return paragraph.getAttributes ();\r
136 }return null;\r
137 });\r
138 Clazz.defineMethod (c$, "setParagraphAttributes", \r
139 function (attr, replace) {\r
140 var p0 = this.getSelectionStart ();\r
141 var p1 = this.getSelectionEnd ();\r
142 var doc = this.getStyledDocument ();\r
143 doc.setParagraphAttributes (p0, p1 - p0, attr, replace);\r
144 }, "javax.swing.text.AttributeSet,~B");\r
145 Clazz.defineMethod (c$, "getInputAttributes", \r
146 function () {\r
147 return this.getStyledEditorKit ().getInputAttributes ();\r
148 });\r
149 Clazz.defineMethod (c$, "getStyledEditorKit", \r
150 function () {\r
151 return this.getEditorKit ();\r
152 });\r
153 Clazz.overrideMethod (c$, "createDefaultEditorKit", \r
154 function () {\r
155 return  new javax.swing.text.StyledEditorKit ();\r
156 });\r
157 Clazz.defineMethod (c$, "setEditorKit", \r
158 function (kit) {\r
159 if (Clazz.instanceOf (kit, javax.swing.text.StyledEditorKit)) {\r
160 Clazz.superCall (this, javax.swing.JTextPane, "setEditorKit", [kit]);\r
161 } else {\r
162 throw  new IllegalArgumentException ("Must be StyledEditorKit");\r
163 }}, "javax.swing.text.EditorKit");\r
164 Clazz.defineStatics (c$,\r
165 "$$uiClassID", "TextPaneUI");\r
166 });\r