9770403d8027ce01d89f5eb3a96e087fbe524b69
[jalviewjs.git] / site / j2s / javax / swing / JTextPane.js
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$, 
5 function () {
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);
12 });
13 Clazz.makeConstructor (c$, 
14 function (doc) {
15 this.construct ();
16 this.setStyledDocument (doc);
17 }, "javax.swing.text.StyledDocument");
18 Clazz.overrideMethod (c$, "getUIClassID", 
19 function () {
20 return "TextPaneUI";
21 });
22 Clazz.defineMethod (c$, "setDocument", 
23 function (doc) {
24 if (Clazz.instanceOf (doc, javax.swing.text.StyledDocument)) {
25 Clazz.superCall (this, javax.swing.JTextPane, "setDocument", [doc]);
26 } else {
27 throw  new IllegalArgumentException ("Model must be StyledDocument");
28 }}, "javax.swing.text.Document");
29 Clazz.defineMethod (c$, "setStyledDocument", 
30 function (doc) {
31 Clazz.superCall (this, javax.swing.JTextPane, "setDocument", [doc]);
32 }, "javax.swing.text.StyledDocument");
33 Clazz.defineMethod (c$, "getStyledDocument", 
34 function () {
35 return this.getDocument ();
36 });
37 Clazz.defineMethod (c$, "replaceSelection", 
38 function (content) {
39 this.replaceSelection (content, true);
40 }, "~S");
41 Clazz.defineMethod (c$, "replaceSelection", 
42  function (content, checkEditable) {
43 if (checkEditable && !this.isEditable ()) {
44 javax.swing.UIManager.getLookAndFeel ().provideErrorFeedback (this);
45 return;
46 }var doc = this.getStyledDocument ();
47 if (doc != null) {
48 try {
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);
55 } else {
56 if (p0 != p1) {
57 doc.remove (p0, p1 - p0);
58 }if (content != null && content.length > 0) {
59 doc.insertString (p0, content, attr);
60 }}} catch (e) {
61 if (Clazz.exceptionOf (e, javax.swing.text.BadLocationException)) {
62 javax.swing.UIManager.getLookAndFeel ().provideErrorFeedback (this);
63 } else {
64 throw e;
65 }
66 }
67 }}, "~S,~B");
68 Clazz.defineMethod (c$, "insertComponent", 
69 function (c) {
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", 
77 function (g) {
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", 
90 function (nm) {
91 var doc = this.getStyledDocument ();
92 doc.removeStyle (nm);
93 }, "~S");
94 Clazz.defineMethod (c$, "getStyle", 
95 function (nm) {
96 var doc = this.getStyledDocument ();
97 return doc.getStyle (nm);
98 }, "~S");
99 Clazz.defineMethod (c$, "setLogicalStyle", 
100 function (s) {
101 var doc = this.getStyledDocument ();
102 doc.setLogicalStyle (this.getCaretPosition (), s);
103 }, "javax.swing.text.Style");
104 Clazz.defineMethod (c$, "getLogicalStyle", 
105 function () {
106 var doc = this.getStyledDocument ();
107 return doc.getLogicalStyle (this.getCaretPosition ());
108 });
109 Clazz.defineMethod (c$, "getCharacterAttributes", 
110 function () {
111 var doc = this.getStyledDocument ();
112 var run = doc.getCharacterElement (this.getCaretPosition ());
113 if (run != null) {
114 return run.getAttributes ();
115 }return null;
116 });
117 Clazz.defineMethod (c$, "setCharacterAttributes", 
118 function (attr, replace) {
119 var p0 = this.getSelectionStart ();
120 var p1 = this.getSelectionEnd ();
121 if (p0 != p1) {
122 var doc = this.getStyledDocument ();
123 doc.setCharacterAttributes (p0, p1 - p0, attr, replace);
124 } else {
125 var inputAttributes = this.getInputAttributes ();
126 if (replace) {
127 inputAttributes.removeAttributes (inputAttributes);
128 }inputAttributes.addAttributes (attr);
129 }}, "javax.swing.text.AttributeSet,~B");
130 Clazz.defineMethod (c$, "getParagraphAttributes", 
131 function () {
132 var doc = this.getStyledDocument ();
133 var paragraph = doc.getParagraphElement (this.getCaretPosition ());
134 if (paragraph != null) {
135 return paragraph.getAttributes ();
136 }return null;
137 });
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", 
146 function () {
147 return this.getStyledEditorKit ().getInputAttributes ();
148 });
149 Clazz.defineMethod (c$, "getStyledEditorKit", 
150 function () {
151 return this.getEditorKit ();
152 });
153 Clazz.overrideMethod (c$, "createDefaultEditorKit", 
154 function () {
155 return  new javax.swing.text.StyledEditorKit ();
156 });
157 Clazz.defineMethod (c$, "setEditorKit", 
158 function (kit) {
159 if (Clazz.instanceOf (kit, javax.swing.text.StyledEditorKit)) {
160 Clazz.superCall (this, javax.swing.JTextPane, "setEditorKit", [kit]);
161 } else {
162 throw  new IllegalArgumentException ("Must be StyledEditorKit");
163 }}, "javax.swing.text.EditorKit");
164 Clazz.defineStatics (c$,
165 "$$uiClassID", "TextPaneUI");
166 });