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