460b4a270c99122be5140c2c0fc27db3c8f743b8
[jalviewjs.git] / site / swingjs / j2s / javax / swing / tree / DefaultTreeCellEditor.js
1 Clazz.declarePackage ("javax.swing.tree");
2 Clazz.load (["java.awt.Container", "java.awt.event.ActionListener", "javax.swing.JTextField", "javax.swing.event.TreeSelectionListener", "javax.swing.tree.TreeCellEditor"], "javax.swing.tree.DefaultTreeCellEditor", ["java.awt.Dimension", "java.awt.event.MouseEvent", "javax.swing.DefaultCellEditor", "$.JTree", "$.SwingUtilities", "$.UIManager", "javax.swing.plaf.FontUIResource"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.realEditor = null;
5 this.renderer = null;
6 this.editingContainer = null;
7 this.editingComponent = null;
8 this.canEdit = false;
9 this.offset = 0;
10 this.tree = null;
11 this.lastPath = null;
12 this.lastRow = 0;
13 this.borderSelectionColor = null;
14 this.editingIcon = null;
15 this.font = null;
16 if (!Clazz.isClassDefined ("javax.swing.tree.DefaultTreeCellEditor.DefaultTextField")) {
17 javax.swing.tree.DefaultTreeCellEditor.$DefaultTreeCellEditor$DefaultTextField$ ();
18 }
19 if (!Clazz.isClassDefined ("javax.swing.tree.DefaultTreeCellEditor.EditorContainer")) {
20 javax.swing.tree.DefaultTreeCellEditor.$DefaultTreeCellEditor$EditorContainer$ ();
21 }
22 Clazz.instantialize (this, arguments);
23 }, javax.swing.tree, "DefaultTreeCellEditor", null, [java.awt.event.ActionListener, javax.swing.tree.TreeCellEditor, javax.swing.event.TreeSelectionListener]);
24 Clazz.makeConstructor (c$, 
25 function (tree, renderer) {
26 this.construct (tree, renderer, null);
27 }, "javax.swing.JTree,javax.swing.tree.DefaultTreeCellRenderer");
28 Clazz.makeConstructor (c$, 
29 function (tree, renderer, editor) {
30 this.renderer = renderer;
31 this.realEditor = editor;
32 if (this.realEditor == null) this.realEditor = this.createTreeCellEditor ();
33 this.editingContainer = this.createContainer ();
34 this.setTree (tree);
35 this.setBorderSelectionColor (javax.swing.UIManager.getColor ("Tree.editorBorderSelectionColor"));
36 }, "javax.swing.JTree,javax.swing.tree.DefaultTreeCellRenderer,javax.swing.tree.TreeCellEditor");
37 Clazz.defineMethod (c$, "setBorderSelectionColor", 
38 function (newColor) {
39 this.borderSelectionColor = newColor;
40 }, "java.awt.Color");
41 Clazz.defineMethod (c$, "getBorderSelectionColor", 
42 function () {
43 return this.borderSelectionColor;
44 });
45 Clazz.defineMethod (c$, "setFont", 
46 function (font) {
47 this.font = font;
48 }, "java.awt.Font");
49 Clazz.defineMethod (c$, "getFont", 
50 function () {
51 return this.font;
52 });
53 Clazz.defineMethod (c$, "getTreeCellEditorComponent", 
54 function (tree, value, isSelected, expanded, leaf, row) {
55 this.setTree (tree);
56 this.lastRow = row;
57 this.determineOffset (tree, value, isSelected, expanded, leaf, row);
58 if (this.editingComponent != null) {
59 this.editingContainer.remove (this.editingComponent);
60 }this.editingComponent = this.realEditor.getTreeCellEditorComponent (tree, value, isSelected, expanded, leaf, row);
61 var newPath = tree.getPathForRow (row);
62 this.canEdit = (this.lastPath != null && newPath != null && this.lastPath.equals (newPath));
63 var font = this.getFont ();
64 if (font == null) {
65 if (this.renderer != null) font = this.renderer.getFont ();
66 if (font == null) font = tree.getFont ();
67 }this.editingContainer.setFont (font);
68 this.prepareForEditing ();
69 return this.editingContainer;
70 }, "javax.swing.JTree,~O,~B,~B,~B,~N");
71 Clazz.defineMethod (c$, "getCellEditorValue", 
72 function () {
73 return this.realEditor.getCellEditorValue ();
74 });
75 Clazz.defineMethod (c$, "isCellEditable", 
76 function (event) {
77 var retValue = false;
78 var editable = false;
79 if (event != null) {
80 if (Clazz.instanceOf (event.getSource (), javax.swing.JTree)) {
81 this.setTree (event.getSource ());
82 if (Clazz.instanceOf (event, java.awt.event.MouseEvent)) {
83 var path = this.tree.getPathForLocation ((event).getX (), (event).getY ());
84 editable = (this.lastPath != null && path != null && this.lastPath.equals (path));
85 if (path != null) {
86 this.lastRow = this.tree.getRowForPath (path);
87 var value = path.getLastPathComponent ();
88 var isSelected = this.tree.isRowSelected (this.lastRow);
89 var expanded = this.tree.isExpanded (path);
90 var treeModel = this.tree.getModel ();
91 var leaf = treeModel.isLeaf (value);
92 this.determineOffset (this.tree, value, isSelected, expanded, leaf, this.lastRow);
93 }}}}if (!this.realEditor.isCellEditable (event)) return false;
94 if (this.canEditImmediately (event)) retValue = true;
95  else if (editable && this.shouldStartEditingTimer (event)) {
96 this.startEditingTimer ();
97 }if (retValue) this.prepareForEditing ();
98 return retValue;
99 }, "java.util.EventObject");
100 Clazz.defineMethod (c$, "shouldSelectCell", 
101 function (event) {
102 return this.realEditor.shouldSelectCell (event);
103 }, "java.util.EventObject");
104 Clazz.defineMethod (c$, "stopCellEditing", 
105 function () {
106 if (this.realEditor.stopCellEditing ()) {
107 this.cleanupAfterEditing ();
108 return true;
109 }return false;
110 });
111 Clazz.defineMethod (c$, "cancelCellEditing", 
112 function () {
113 this.realEditor.cancelCellEditing ();
114 this.cleanupAfterEditing ();
115 });
116 Clazz.defineMethod (c$, "addCellEditorListener", 
117 function (l) {
118 this.realEditor.addCellEditorListener (l);
119 }, "javax.swing.event.CellEditorListener");
120 Clazz.defineMethod (c$, "removeCellEditorListener", 
121 function (l) {
122 this.realEditor.removeCellEditorListener (l);
123 }, "javax.swing.event.CellEditorListener");
124 Clazz.defineMethod (c$, "getCellEditorListeners", 
125 function () {
126 return (this.realEditor).getCellEditorListeners ();
127 });
128 Clazz.overrideMethod (c$, "valueChanged", 
129 function (e) {
130 if (this.tree != null) {
131 if (this.tree.getSelectionCount () == 1) this.lastPath = this.tree.getSelectionPath ();
132  else this.lastPath = null;
133 }}, "javax.swing.event.TreeSelectionEvent");
134 Clazz.overrideMethod (c$, "actionPerformed", 
135 function (e) {
136 if (this.tree != null && this.lastPath != null) {
137 this.tree.startEditingAtPath (this.lastPath);
138 }}, "java.awt.event.ActionEvent");
139 Clazz.defineMethod (c$, "setTree", 
140 function (newTree) {
141 if (this.tree !== newTree) {
142 if (this.tree != null) this.tree.removeTreeSelectionListener (this);
143 this.tree = newTree;
144 if (this.tree != null) this.tree.addTreeSelectionListener (this);
145 }}, "javax.swing.JTree");
146 Clazz.defineMethod (c$, "shouldStartEditingTimer", 
147 function (event) {
148 if ((Clazz.instanceOf (event, java.awt.event.MouseEvent)) && javax.swing.SwingUtilities.isLeftMouseButton (event)) {
149 var me = event;
150 return (me.getClickCount () == 1 && this.inHitRegion (me.getX (), me.getY ()));
151 }return false;
152 }, "java.util.EventObject");
153 Clazz.defineMethod (c$, "startEditingTimer", 
154 function () {
155 });
156 Clazz.defineMethod (c$, "canEditImmediately", 
157 function (event) {
158 if ((Clazz.instanceOf (event, java.awt.event.MouseEvent)) && javax.swing.SwingUtilities.isLeftMouseButton (event)) {
159 var me = event;
160 return ((me.getClickCount () > 2) && this.inHitRegion (me.getX (), me.getY ()));
161 }return (event == null);
162 }, "java.util.EventObject");
163 Clazz.defineMethod (c$, "inHitRegion", 
164 function (x, y) {
165 if (this.lastRow != -1 && this.tree != null) {
166 var bounds = this.tree.getRowBounds (this.lastRow);
167 var treeOrientation = this.tree.getComponentOrientation ();
168 if (treeOrientation.isLeftToRight ()) {
169 if (bounds != null && x <= (bounds.x + this.offset) && this.offset < (bounds.width - 5)) {
170 return false;
171 }} else if (bounds != null && (x >= (bounds.x + bounds.width - this.offset + 5) || x <= (bounds.x + 5)) && this.offset < (bounds.width - 5)) {
172 return false;
173 }}return true;
174 }, "~N,~N");
175 Clazz.defineMethod (c$, "determineOffset", 
176 function (tree, value, isSelected, expanded, leaf, row) {
177 if (this.renderer != null) {
178 if (leaf) this.editingIcon = this.renderer.getLeafIcon ();
179  else if (expanded) this.editingIcon = this.renderer.getOpenIcon ();
180  else this.editingIcon = this.renderer.getClosedIcon ();
181 if (this.editingIcon != null) this.offset = this.renderer.getIconTextGap () + this.editingIcon.getIconWidth ();
182  else this.offset = this.renderer.getIconTextGap ();
183 } else {
184 this.editingIcon = null;
185 this.offset = 0;
186 }}, "javax.swing.JTree,~O,~B,~B,~B,~N");
187 Clazz.defineMethod (c$, "prepareForEditing", 
188 function () {
189 if (this.editingComponent != null) {
190 this.editingContainer.add (this.editingComponent);
191 }});
192 Clazz.defineMethod (c$, "createContainer", 
193 function () {
194 return Clazz.innerTypeInstance (javax.swing.tree.DefaultTreeCellEditor.EditorContainer, this, null);
195 });
196 Clazz.defineMethod (c$, "createTreeCellEditor", 
197 function () {
198 var aBorder = javax.swing.UIManager.getBorder ("Tree.editorBorder");
199 var editor = ((Clazz.isClassDefined ("javax.swing.tree.DefaultTreeCellEditor$1") ? 0 : javax.swing.tree.DefaultTreeCellEditor.$DefaultTreeCellEditor$1$ ()), Clazz.innerTypeInstance (javax.swing.tree.DefaultTreeCellEditor$1, this, null, Clazz.innerTypeInstance (javax.swing.tree.DefaultTreeCellEditor.DefaultTextField, this, null, aBorder)));
200 editor.setClickCountToStart (1);
201 return editor;
202 });
203 Clazz.defineMethod (c$, "cleanupAfterEditing", 
204  function () {
205 if (this.editingComponent != null) {
206 this.editingContainer.remove (this.editingComponent);
207 }this.editingComponent = null;
208 });
209 c$.$DefaultTreeCellEditor$DefaultTextField$ = function () {
210 Clazz.pu$h(self.c$);
211 c$ = Clazz.decorateAsClass (function () {
212 Clazz.prepareCallback (this, arguments);
213 this.$border = null;
214 Clazz.instantialize (this, arguments);
215 }, javax.swing.tree.DefaultTreeCellEditor, "DefaultTextField", javax.swing.JTextField);
216 Clazz.makeConstructor (c$, 
217 function (a) {
218 Clazz.superConstructor (this, javax.swing.tree.DefaultTreeCellEditor.DefaultTextField, []);
219 this.setBorder (a);
220 }, "javax.swing.border.Border");
221 Clazz.defineMethod (c$, "setBorder", 
222 function (a) {
223 Clazz.superCall (this, javax.swing.tree.DefaultTreeCellEditor.DefaultTextField, "setBorder", [a]);
224 this.$border = a;
225 }, "javax.swing.border.Border");
226 Clazz.overrideMethod (c$, "getBorder", 
227 function () {
228 return this.$border;
229 });
230 Clazz.defineMethod (c$, "getFont", 
231 function () {
232 var a = Clazz.superCall (this, javax.swing.tree.DefaultTreeCellEditor.DefaultTextField, "getFont", []);
233 if (Clazz.instanceOf (a, javax.swing.plaf.FontUIResource)) {
234 var b = this.getParent ();
235 if (b != null && b.getFont () != null) a = b.getFont ();
236 }return a;
237 });
238 Clazz.overrideMethod (c$, "getPreferredSize", 
239 function () {
240 var a = this.getPrefSizeJTF ();
241 if (this.b$["javax.swing.tree.DefaultTreeCellEditor"].renderer != null && this.b$["javax.swing.tree.DefaultTreeCellEditor"].getFont () == null) {
242 var b = this.b$["javax.swing.tree.DefaultTreeCellEditor"].renderer.getPreferredSize ();
243 a.height = b.height;
244 }return a;
245 });
246 c$ = Clazz.p0p ();
247 };
248 c$.$DefaultTreeCellEditor$EditorContainer$ = function () {
249 Clazz.pu$h(self.c$);
250 c$ = Clazz.decorateAsClass (function () {
251 Clazz.prepareCallback (this, arguments);
252 Clazz.instantialize (this, arguments);
253 }, javax.swing.tree.DefaultTreeCellEditor, "EditorContainer", java.awt.Container);
254 Clazz.makeConstructor (c$, 
255 function () {
256 Clazz.superConstructor (this, javax.swing.tree.DefaultTreeCellEditor.EditorContainer, []);
257 this.setLayout (null);
258 });
259 Clazz.defineMethod (c$, "paint", 
260 function (a) {
261 var b = this.getWidth ();
262 var c = this.getHeight ();
263 if (this.b$["javax.swing.tree.DefaultTreeCellEditor"].editingIcon != null) {
264 var d = this.calculateIconY (this.b$["javax.swing.tree.DefaultTreeCellEditor"].editingIcon);
265 if (this.getComponentOrientation ().isLeftToRight ()) {
266 this.b$["javax.swing.tree.DefaultTreeCellEditor"].editingIcon.paintIcon (this, a, 0, d);
267 } else {
268 this.b$["javax.swing.tree.DefaultTreeCellEditor"].editingIcon.paintIcon (this, a, b - this.b$["javax.swing.tree.DefaultTreeCellEditor"].editingIcon.getIconWidth (), d);
269 }}var d = this.b$["javax.swing.tree.DefaultTreeCellEditor"].getBorderSelectionColor ();
270 if (d != null) {
271 a.setColor (d);
272 a.drawRect (0, 0, b - 1, c - 1);
273 }Clazz.superCall (this, javax.swing.tree.DefaultTreeCellEditor.EditorContainer, "paint", [a]);
274 }, "java.awt.Graphics");
275 Clazz.overrideMethod (c$, "doLayout", 
276 function () {
277 if (this.b$["javax.swing.tree.DefaultTreeCellEditor"].editingComponent != null) {
278 var a = this.getWidth ();
279 var b = this.getHeight ();
280 if (this.getComponentOrientation ().isLeftToRight ()) {
281 this.b$["javax.swing.tree.DefaultTreeCellEditor"].editingComponent.setBounds (this.b$["javax.swing.tree.DefaultTreeCellEditor"].offset, 0, a - this.b$["javax.swing.tree.DefaultTreeCellEditor"].offset, b);
282 } else {
283 this.b$["javax.swing.tree.DefaultTreeCellEditor"].editingComponent.setBounds (0, 0, a - this.b$["javax.swing.tree.DefaultTreeCellEditor"].offset, b);
284 }}});
285 Clazz.defineMethod (c$, "calculateIconY", 
286  function (a) {
287 var b = a.getIconHeight ();
288 var c = this.b$["javax.swing.tree.DefaultTreeCellEditor"].editingComponent.getFontMetrics (this.b$["javax.swing.tree.DefaultTreeCellEditor"].editingComponent.getFont ()).getHeight ();
289 var d = Clazz.doubleToInt (b / 2) - Clazz.doubleToInt (c / 2);
290 var e = Math.min (0, d);
291 var f = Math.max (b, d + c) - e;
292 return Clazz.doubleToInt (this.getHeight () / 2) - (e + (Clazz.doubleToInt (f / 2)));
293 }, "javax.swing.Icon");
294 Clazz.overrideMethod (c$, "getPreferredSize", 
295 function () {
296 if (this.b$["javax.swing.tree.DefaultTreeCellEditor"].editingComponent != null) {
297 var a = this.b$["javax.swing.tree.DefaultTreeCellEditor"].editingComponent.getPreferredSize ();
298 a.width += this.b$["javax.swing.tree.DefaultTreeCellEditor"].offset + 5;
299 var b = (this.b$["javax.swing.tree.DefaultTreeCellEditor"].renderer != null) ? this.b$["javax.swing.tree.DefaultTreeCellEditor"].renderer.getPreferredSize () : null;
300 if (b != null) a.height = Math.max (a.height, b.height);
301 if (this.b$["javax.swing.tree.DefaultTreeCellEditor"].editingIcon != null) a.height = Math.max (a.height, this.b$["javax.swing.tree.DefaultTreeCellEditor"].editingIcon.getIconHeight ());
302 a.width = Math.max (a.width, 100);
303 return a;
304 }return  new java.awt.Dimension (0, 0);
305 });
306 c$ = Clazz.p0p ();
307 };
308 c$.$DefaultTreeCellEditor$1$ = function () {
309 Clazz.pu$h(self.c$);
310 c$ = Clazz.declareAnonymous (javax.swing.tree, "DefaultTreeCellEditor$1", javax.swing.DefaultCellEditor);
311 Clazz.defineMethod (c$, "shouldSelectCell", 
312 function (event) {
313 var retValue = Clazz.superCall (this, javax.swing.tree.DefaultTreeCellEditor$1, "shouldSelectCell", [event]);
314 return retValue;
315 }, "java.util.EventObject");
316 c$ = Clazz.p0p ();
317 };
318 });