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;
7 if (!Clazz.isClassDefined ("swingjs.plaf.JSTextUI.TextActionWrapper")) {
8 swingjs.plaf.JSTextUI.$JSTextUI$TextActionWrapper$ ();
10 if (!Clazz.isClassDefined ("swingjs.plaf.JSTextUI.FocusAction")) {
11 swingjs.plaf.JSTextUI.$JSTextUI$FocusAction$ ();
14 Clazz.instantialize (this, arguments);
15 }, swingjs.plaf, "JSTextUI", swingjs.plaf.JSComponentUI);
16 Clazz.defineMethod (c$, "setFocusable",
18 var node = this.$ (this.focusNode);
21 node.focus(function() {me.notifyFocus(true)});
22 node.blur(function() {me.notifyFocus(false)});
24 Clazz.defineMethod (c$, "getComponentText",
26 return this.currentText = (this.c).getText ();
28 Clazz.defineMethod (c$, "bindKeys",
32 if (!(this.c).isEditable ()) return;
34 f = function(event) { me.handleJSEvent(me.domNode, 401, event)
36 }this.$ (domNode).bind ("keydown keypress keyup", f);
37 }, "swingjs.api.DOMNode");
38 Clazz.defineMethod (c$, "installDefaults",
41 Clazz.defineMethod (c$, "installDefaults2",
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 ());
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);
52 Clazz.defineMethod (c$, "uninstallDefaults",
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);
67 Clazz.defineMethod (c$, "installKeyboardActions",
69 var km = this.getInputMap ();
71 javax.swing.SwingUtilities.replaceUIInputMap (this.editor, 0, km);
72 }var map = this.getActionMap ();
74 javax.swing.SwingUtilities.replaceUIActionMap (this.editor, map);
76 Clazz.defineMethod (c$, "getInputMap",
78 var map = new javax.swing.plaf.InputMapUIResource ();
81 Clazz.defineMethod (c$, "getActionMap",
83 var mapName = this.classID + ".actionMap";
84 var map = javax.swing.UIManager.get (mapName);
86 map = this.createActionMap ();
88 javax.swing.UIManager.getLookAndFeelDefaults ().put (mapName, map);
91 Clazz.defineMethod (c$, "createActionMap",
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++) {
98 map.put (a.getValue ("Name"), a);
102 Clazz.defineMethod (c$, "uninstallKeyboardActions",
104 this.editor.setKeymap (null);
105 javax.swing.SwingUtilities.replaceUIInputMap (this.editor, 2, null);
106 javax.swing.SwingUtilities.replaceUIActionMap (this.editor, null);
108 Clazz.defineMethod (c$, "getComponent",
112 Clazz.overrideMethod (c$, "installJSUI",
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 ();
121 Clazz.overrideMethod (c$, "uninstallJSUI",
123 this.uninstallDefaults ();
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);
131 this.updateHandler = null;
133 Clazz.defineMethod (c$, "installListeners",
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",
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",
152 var d = this.getPreferredSize ();
153 var i = c.getInsets ();
154 d.width += i.left + i.right;
155 d.height += i.top + i.bottom;
157 }, "javax.swing.JComponent");
158 Clazz.overrideMethod (c$, "getMaximumSize",
160 return this.getMinimumSize (c);
161 }, "javax.swing.JComponent");
162 Clazz.defineMethod (c$, "getEditorKit",
164 return swingjs.plaf.JSTextUI.defaultKit;
165 }, "javax.swing.text.JTextComponent");
166 Clazz.defineMethod (c$, "handleEnter",
167 function (eventType) {
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 ());
176 this.domNode.removeAttribute ("readOnly");
177 if (this.bgcolor0 != null) swingjs.api.DOMNode.setStyles (this.domNode, ["background-color", this.bgcolor0]);
179 swingjs.api.DOMNode.setAttr (this.domNode, "readOnly", "true");
180 if (this.c.isBackgroundSet ()) {
181 this.bgcolor0 = swingjs.JSToolkit.getCSSColor (this.c.getBackground ());
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)"]);
186 c$.$JSTextUI$TextActionWrapper$ = function () {
188 c$ = Clazz.decorateAsClass (function () {
189 Clazz.prepareCallback (this, arguments);
191 Clazz.instantialize (this, arguments);
192 }, swingjs.plaf.JSTextUI, "TextActionWrapper", javax.swing.text.TextAction);
193 Clazz.makeConstructor (c$,
195 Clazz.superConstructor (this, swingjs.plaf.JSTextUI.TextActionWrapper, [a.getValue ("Name")]);
197 }, "javax.swing.text.TextAction");
198 Clazz.defineMethod (c$, "actionPerformed",
200 this.action.actionPerformed (a);
201 }, "java.awt.event.ActionEvent");
202 Clazz.defineMethod (c$, "isEnabled",
204 return (this.b$["swingjs.plaf.JSTextUI"].editor == null || this.b$["swingjs.plaf.JSTextUI"].editor.isEditable ()) ? this.action.isEnabled () : false;
208 c$.$JSTextUI$FocusAction$ = function () {
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",
216 this.b$["swingjs.plaf.JSTextUI"].editor.requestFocus ();
217 }, "java.awt.event.ActionEvent");
218 Clazz.overrideMethod (c$, "isEnabled",
220 return this.b$["swingjs.plaf.JSTextUI"].editor.isEditable ();
224 c$.defaultKit = c$.prototype.defaultKit = new javax.swing.text.DefaultEditorKit ();