e7a341f05c04f961d495c6083fe8bcd6974d28da
[jalviewjs.git] / site / j2s / swingjs / plaf / JSTextUI.js
1 Clazz.declarePackage ("swingjs.plaf");\r
2 Clazz.load (["javax.swing.AbstractAction", "javax.swing.text.TextAction", "swingjs.plaf.JSComponentUI", "javax.swing.text.DefaultEditorKit"], "swingjs.plaf.JSTextUI", ["javax.swing.SwingUtilities", "$.UIManager", "javax.swing.plaf.ActionMapUIResource", "$.InputMapUIResource", "$.UIResource", "swingjs.JSToolkit", "swingjs.api.DOMNode", "swingjs.plaf.JSCaret", "$.TextListener"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.updateHandler = null;\r
5 this.editor = null;\r
6 this.editable = true;\r
7 if (!Clazz.isClassDefined ("swingjs.plaf.JSTextUI.TextActionWrapper")) {\r
8 swingjs.plaf.JSTextUI.$JSTextUI$TextActionWrapper$ ();\r
9 }\r
10 if (!Clazz.isClassDefined ("swingjs.plaf.JSTextUI.FocusAction")) {\r
11 swingjs.plaf.JSTextUI.$JSTextUI$FocusAction$ ();\r
12 }\r
13 this.bgcolor0 = null;\r
14 Clazz.instantialize (this, arguments);\r
15 }, swingjs.plaf, "JSTextUI", swingjs.plaf.JSComponentUI);\r
16 Clazz.defineMethod (c$, "setFocusable", \r
17 function () {\r
18 var node = this.$ (this.focusNode);\r
19 var me = this;\r
20 {\r
21 node.focus(function() {me.notifyFocus(true)});\r
22 node.blur(function() {me.notifyFocus(false)});\r
23 }});\r
24 Clazz.defineMethod (c$, "getComponentText", \r
25 function () {\r
26 return this.currentText = (this.c).getText ();\r
27 });\r
28 Clazz.defineMethod (c$, "bindKeys", \r
29 function (domNode) {\r
30 var f = null;\r
31 var me = this;\r
32 if (!(this.c).isEditable ()) return;\r
33 {\r
34 f = function(event) { me.handleJSEvent(me.domNode, 401, event)\r
35 }\r
36 }this.$ (domNode).bind ("keydown keypress keyup", f);\r
37 }, "swingjs.api.DOMNode");\r
38 Clazz.defineMethod (c$, "installDefaults", \r
39 function () {\r
40 });\r
41 Clazz.defineMethod (c$, "installDefaults2", \r
42  function () {\r
43 var caret = this.editor.getCaret ();\r
44 if (caret == null || Clazz.instanceOf (caret, javax.swing.plaf.UIResource)) {\r
45 this.editor.setCaret ( new swingjs.plaf.JSCaret ());\r
46 }});\r
47 Clazz.overrideMethod (c$, "handleJSEvent", \r
48 function (target, eventType, jQueryEvent) {\r
49 System.out.println ("Handling for " + this.id + " " + eventType + " " + jQueryEvent);\r
50 return this.updateHandler.handleJSEvent (this, eventType, jQueryEvent);\r
51 }, "~O,~N,~O");\r
52 Clazz.defineMethod (c$, "uninstallDefaults", \r
53 function () {\r
54 if (Clazz.instanceOf (this.editor.getCaretColor (), javax.swing.plaf.UIResource)) {\r
55 this.editor.setCaretColor (null);\r
56 }if (Clazz.instanceOf (this.editor.getSelectionColor (), javax.swing.plaf.UIResource)) {\r
57 this.editor.setSelectionColor (null);\r
58 }if (Clazz.instanceOf (this.editor.getDisabledTextColor (), javax.swing.plaf.UIResource)) {\r
59 this.editor.setDisabledTextColor (null);\r
60 }if (Clazz.instanceOf (this.editor.getSelectedTextColor (), javax.swing.plaf.UIResource)) {\r
61 this.editor.setSelectedTextColor (null);\r
62 }if (Clazz.instanceOf (this.editor.getBorder (), javax.swing.plaf.UIResource)) {\r
63 this.editor.setBorder (null);\r
64 }if (Clazz.instanceOf (this.editor.getMargin (), javax.swing.plaf.UIResource)) {\r
65 this.editor.setMargin (null);\r
66 }});\r
67 Clazz.defineMethod (c$, "installKeyboardActions", \r
68 function () {\r
69 var km = this.getInputMap ();\r
70 if (km != null) {\r
71 javax.swing.SwingUtilities.replaceUIInputMap (this.editor, 0, km);\r
72 }var map = this.getActionMap ();\r
73 if (map != null) {\r
74 javax.swing.SwingUtilities.replaceUIActionMap (this.editor, map);\r
75 }});\r
76 Clazz.defineMethod (c$, "getInputMap", \r
77 function () {\r
78 var map =  new javax.swing.plaf.InputMapUIResource ();\r
79 return map;\r
80 });\r
81 Clazz.defineMethod (c$, "getActionMap", \r
82 function () {\r
83 var mapName = this.classID + ".actionMap";\r
84 var map = javax.swing.UIManager.get (mapName);\r
85 if (map == null) {\r
86 map = this.createActionMap ();\r
87 if (map != null) {\r
88 javax.swing.UIManager.getLookAndFeelDefaults ().put (mapName, map);\r
89 }}return map;\r
90 });\r
91 Clazz.defineMethod (c$, "createActionMap", \r
92 function () {\r
93 var map =  new javax.swing.plaf.ActionMapUIResource ();\r
94 var actions = this.editor.getActions ();\r
95 var n = (actions == null ? 0 : actions.length);\r
96 for (var i = 0; i < n; i++) {\r
97 var a = actions[i];\r
98 map.put (a.getValue ("Name"), a);\r
99 }\r
100 return map;\r
101 });\r
102 Clazz.defineMethod (c$, "uninstallKeyboardActions", \r
103 function () {\r
104 this.editor.setKeymap (null);\r
105 javax.swing.SwingUtilities.replaceUIInputMap (this.editor, 2, null);\r
106 javax.swing.SwingUtilities.replaceUIActionMap (this.editor, null);\r
107 });\r
108 Clazz.defineMethod (c$, "getComponent", \r
109 function () {\r
110 return this.editor;\r
111 });\r
112 Clazz.overrideMethod (c$, "installJSUI", \r
113 function () {\r
114 this.editor = this.c;\r
115 this.updateHandler =  new swingjs.plaf.TextListener (this, this.editor);\r
116 this.installDefaults ();\r
117 this.installDefaults2 ();\r
118 this.installListeners (this.editor);\r
119 this.installKeyboardActions ();\r
120 });\r
121 Clazz.overrideMethod (c$, "uninstallJSUI", \r
122 function () {\r
123 this.uninstallDefaults ();\r
124 this.c.removeAll ();\r
125 var lm = this.c.getLayout ();\r
126 if (Clazz.instanceOf (lm, javax.swing.plaf.UIResource)) {\r
127 this.c.setLayout (null);\r
128 }this.uninstallKeyboardActions ();\r
129 this.uninstallListeners (this.editor);\r
130 this.editor = null;\r
131 this.updateHandler = null;\r
132 });\r
133 Clazz.defineMethod (c$, "installListeners", \r
134 function (b) {\r
135 var listener = this.updateHandler;\r
136 b.addMouseListener (listener);\r
137 b.addMouseMotionListener (listener);\r
138 b.addFocusListener (listener);\r
139 b.addPropertyChangeListener (listener);\r
140 }, "javax.swing.text.JTextComponent");\r
141 Clazz.defineMethod (c$, "uninstallListeners", \r
142 function (b) {\r
143 var listener = this.updateHandler;\r
144 b.removeMouseListener (listener);\r
145 b.removeMouseMotionListener (listener);\r
146 b.removeFocusListener (listener);\r
147 b.removePropertyChangeListener (listener);\r
148 b.getDocument ().removeDocumentListener (listener);\r
149 }, "javax.swing.text.JTextComponent");\r
150 Clazz.defineMethod (c$, "getMinimumSize", \r
151 function (c) {\r
152 var d = this.getPreferredSize ();\r
153 var i = c.getInsets ();\r
154 d.width += i.left + i.right;\r
155 d.height += i.top + i.bottom;\r
156 return d;\r
157 }, "javax.swing.JComponent");\r
158 Clazz.overrideMethod (c$, "getMaximumSize", \r
159 function (c) {\r
160 return this.getMinimumSize (c);\r
161 }, "javax.swing.JComponent");\r
162 Clazz.defineMethod (c$, "getEditorKit", \r
163 function (tc) {\r
164 return swingjs.plaf.JSTextUI.defaultKit;\r
165 }, "javax.swing.text.JTextComponent");\r
166 Clazz.defineMethod (c$, "handleEnter", \r
167 function (eventType) {\r
168 return false;\r
169 }, "~N");\r
170 Clazz.defineMethod (c$, "setEditable", \r
171 function (editable) {\r
172 this.editable = editable;\r
173 if (this.domNode == null) return;\r
174 if (this.c.isBackgroundSet ()) this.bgcolor0 = swingjs.JSToolkit.getCSSColor (this.c.getBackground ());\r
175 if (editable) {\r
176 this.domNode.removeAttribute ("readOnly");\r
177 if (this.bgcolor0 != null) swingjs.api.DOMNode.setStyles (this.domNode, ["background-color", this.bgcolor0]);\r
178 } else {\r
179 swingjs.api.DOMNode.setAttr (this.domNode, "readOnly", "true");\r
180 if (this.c.isBackgroundSet ()) {\r
181 this.bgcolor0 = swingjs.JSToolkit.getCSSColor (this.c.getBackground ());\r
182 } else {\r
183 if (this.bgcolor0 == null) this.bgcolor0 = this.domNode.getStyle ("background-color");\r
184 }swingjs.api.DOMNode.setStyles (this.domNode, ["background-color", "rgba(0,0,0,0)"]);\r
185 }}, "~B");\r
186 c$.$JSTextUI$TextActionWrapper$ = function () {\r
187 Clazz.pu$h(self.c$);\r
188 c$ = Clazz.decorateAsClass (function () {\r
189 Clazz.prepareCallback (this, arguments);\r
190 this.action = null;\r
191 Clazz.instantialize (this, arguments);\r
192 }, swingjs.plaf.JSTextUI, "TextActionWrapper", javax.swing.text.TextAction);\r
193 Clazz.makeConstructor (c$, \r
194 function (a) {\r
195 Clazz.superConstructor (this, swingjs.plaf.JSTextUI.TextActionWrapper, [a.getValue ("Name")]);\r
196 this.action = a;\r
197 }, "javax.swing.text.TextAction");\r
198 Clazz.defineMethod (c$, "actionPerformed", \r
199 function (a) {\r
200 this.action.actionPerformed (a);\r
201 }, "java.awt.event.ActionEvent");\r
202 Clazz.defineMethod (c$, "isEnabled", \r
203 function () {\r
204 return (this.b$["swingjs.plaf.JSTextUI"].editor == null || this.b$["swingjs.plaf.JSTextUI"].editor.isEditable ()) ? this.action.isEnabled () : false;\r
205 });\r
206 c$ = Clazz.p0p ();\r
207 };\r
208 c$.$JSTextUI$FocusAction$ = function () {\r
209 Clazz.pu$h(self.c$);\r
210 c$ = Clazz.decorateAsClass (function () {\r
211 Clazz.prepareCallback (this, arguments);\r
212 Clazz.instantialize (this, arguments);\r
213 }, swingjs.plaf.JSTextUI, "FocusAction", javax.swing.AbstractAction);\r
214 Clazz.overrideMethod (c$, "actionPerformed", \r
215 function (a) {\r
216 this.b$["swingjs.plaf.JSTextUI"].editor.requestFocus ();\r
217 }, "java.awt.event.ActionEvent");\r
218 Clazz.overrideMethod (c$, "isEnabled", \r
219 function () {\r
220 return this.b$["swingjs.plaf.JSTextUI"].editor.isEditable ();\r
221 });\r
222 c$ = Clazz.p0p ();\r
223 };\r
224 c$.defaultKit = c$.prototype.defaultKit =  new javax.swing.text.DefaultEditorKit ();\r
225 });\r