1
2
3
4
5
6
7
8 package com.extjs.gxt.ui.client.core;
9
10 import java.util.ArrayList;
11 import java.util.Arrays;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.Set;
15
16 import com.extjs.gxt.ui.client.GXT;
17 import com.extjs.gxt.ui.client.Style;
18 import com.extjs.gxt.ui.client.Style.Direction;
19 import com.extjs.gxt.ui.client.Style.ScrollDir;
20 import com.extjs.gxt.ui.client.core.impl.ComputedStyleImpl;
21 import com.extjs.gxt.ui.client.fx.BaseEffect;
22 import com.extjs.gxt.ui.client.fx.Fx;
23 import com.extjs.gxt.ui.client.fx.FxConfig;
24 import com.extjs.gxt.ui.client.fx.Move;
25 import com.extjs.gxt.ui.client.util.Format;
26 import com.extjs.gxt.ui.client.util.Margins;
27 import com.extjs.gxt.ui.client.util.Markup;
28 import com.extjs.gxt.ui.client.util.Padding;
29 import com.extjs.gxt.ui.client.util.Point;
30 import com.extjs.gxt.ui.client.util.Rectangle;
31 import com.extjs.gxt.ui.client.util.Region;
32 import com.extjs.gxt.ui.client.util.Scroll;
33 import com.extjs.gxt.ui.client.util.Size;
34 import com.extjs.gxt.ui.client.util.TextMetrics;
35 import com.extjs.gxt.ui.client.util.Util;
36 import com.google.gwt.core.client.GWT;
37 import com.google.gwt.core.client.JavaScriptObject;
38 import com.google.gwt.dom.client.Document;
39 import com.google.gwt.dom.client.NodeList;
40 import com.google.gwt.http.client.Request;
41 import com.google.gwt.http.client.RequestBuilder;
42 import com.google.gwt.http.client.RequestCallback;
43 import com.google.gwt.http.client.Response;
44 import com.google.gwt.user.client.Command;
45 import com.google.gwt.user.client.DOM;
46 import com.google.gwt.user.client.DeferredCommand;
47 import com.google.gwt.user.client.Element;
48
49
50
51
52 @SuppressWarnings("deprecation")
53 public class El {
54
55
56
57
58
59
60 public enum VisMode {
61 DISPLAY, VISIBILITY
62 }
63
64 private static Map<String, Boolean> borderBoxMap = new FastMap<Boolean>();
65
66
67
68
69 private static Map<String, El> flyweights = new FastMap<El>();
70
71 private static ComputedStyleImpl computedStyle = GWT.create(ComputedStyleImpl.class);
72 private static JavaScriptObject leftRightTest;
73 private static JavaScriptObject removeStyleNameReCache;
74
75 static {
76 GXT.init();
77 }
78
79
80
81
82
83
84
85 public native static String addUnits(String v, String defaultUnit)
86
87
88
89
90
91
92
93
94
95
96
97 ;
98
99 public static El fly(com.google.gwt.dom.client.Element element) {
100 return fly(element, "_global");
101 }
102
103
104
105
106
107
108
109
110
111 public static El fly(com.google.gwt.dom.client.Element element, String s) {
112 assert element != null : "Element my not be null";
113 El g = flyweights.get(s);
114 if (g == null) {
115 g = new El(DOM.createDiv());
116 flyweights.put(s, g);
117 }
118 g.dom = (Element) element;
119 return g;
120 }
121
122 public static El fly(Element element) {
123 return fly(element, "_global");
124 }
125
126
127
128
129
130
131
132
133
134 public static El fly(Element element, String s) {
135 assert element != null : "Element my not be null";
136 El g = flyweights.get(s);
137 if (g == null) {
138 g = new El(DOM.createDiv());
139 flyweights.put(s, g);
140 }
141 g.dom = (Element) element;
142 return g;
143 }
144
145
146
147
148
149
150
151 public static boolean isBorderBox(Element element) {
152 assert element != null : "Element may not be null";
153 String tag = element.getTagName().toLowerCase();
154 Boolean r = borderBoxMap.get(tag);
155 if (r == null) {
156 Element testElement = (Element) Document.get().createElement(tag);
157 testElement.getStyle().setPropertyPx("padding", 1);
158 testElement.getStyle().setPropertyPx("width", 100);
159 testElement.getStyle().setProperty("visibility", "hidden");
160 testElement.getStyle().setProperty("position", "absolute");
161 XDOM.getBody().appendChild(testElement);
162 r = testElement.getOffsetWidth() == 100;
163 XDOM.getBody().removeChild(testElement);
164 borderBoxMap.put(tag, r);
165 }
166 return r;
167 }
168
169 private native static void disableTextSelectInternal(Element e, boolean disable)
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205 ;
206
207
208
209
210 public Element dom;
211
212 private VisMode visiblityMode = VisMode.DISPLAY;
213
214 private String originalDisplay = "block";
215 private El _mask;
216 private El _maskMsg;
217 private boolean isClipped;
218 private String[] originalClipped;
219
220
221
222
223
224
225 public El(Element element) {
226 assert element != null : "The element may not be null";
227 this.dom = element;
228 }
229
230
231
232
233
234
235 public El(String html) {
236 this(XDOM.create(html));
237 }
238
239
240
241
242
243
244
245 public El addEventsSunk(int event) {
246 int bits = DOM.getEventsSunk(dom);
247 DOM.sinkEvents(dom, bits | event);
248 return this;
249 }
250
251
252
253
254
255
256
257
258 public El addStyleName(String... styleNames) {
259 if (styleNames != null) {
260 for (String styleName : styleNames) {
261 if (styleName != null && !hasStyleName(styleName)) {
262 styleName = styleName.trim();
263
264
265 setClassName(dom, getClassName(dom) + " " + styleName);
266
267 }
268 }
269 return this;
270 }
271
272
273
274
275
276
277
278
279 public El toggleStyleName(String styleName) {
280 if (hasStyleName(styleName)) {
281 removeStyleName(styleName);
282 } else {
283 addStyleName(styleName);
284 }
285 return this;
286 }
287
288
289
290
291
292
293
294 public Point adjustForConstraints(Point p) {
295 return getConstrainToXY(XDOM.getBody(), p);
296 }
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334 public El alignTo(Element align, String pos, int[] offsets) {
335 if (offsets == null) {
336 offsets = new int[] {0, 0};
337 }
338 Point p = getAlignToXY(align, pos, offsets);
339 setXY(p);
340 return this;
341 }
342
343
344
345
346
347
348
349 public El appendChild(Element child) {
350 dom.appendChild(child);
351 return new El(child);
352 }
353
354
355
356
357
358
359
360
361
362 public native El applyStyles(String styles)
363
364
365
366
367
368
369 ;
370
371
372
373
374
375
376
377 public El blink(FxConfig config) {
378 BaseEffect.blink(this, config, 50);
379 return this;
380 }
381
382
383
384
385
386
387 public El blur() {
388 return setFocus(false);
389 }
390
391
392
393
394
395
396
397
398 public El boxWrap(String style) {
399 String s = style != null ? style : "x-box";
400 El temp = insertHtml("beforeBegin", Format.substitute("<div class={0}>" + Markup.BBOX, s) + "</div>");
401 temp.child("." + s + "-mc").appendChild(dom);
402 return temp;
403 }
404
405
406
407
408
409
410 public El center() {
411 return center(null);
412 }
413
414
415
416
417
418
419
420
421 public El center(boolean constrainViewport) {
422 return alignTo(XDOM.getBody(), "c-c" + (constrainViewport ? "?" : ""), null);
423 }
424
425
426
427
428
429
430
431 public El center(Element container) {
432 if (container == null) {
433 container = XDOM.getBody();
434 }
435 return alignTo(container, "c-c", null);
436 }
437
438
439
440
441
442
443
444
445 public El child(String selector) {
446 Element child = childElement(selector);
447 return child == null ? null : new El(child);
448 }
449
450
451
452
453
454
455
456
457 public Element childElement(String selector) {
458 return DomQuery.selectNode(selector, dom);
459 }
460
461
462
463
464
465
466
467 public El childNode(int index) {
468 Element e = DOM.getChild(dom, index);
469 return e == null ? null : new El(e);
470 }
471
472
473
474
475
476
477 public native El clearOpacity()
478
479
480
481
482
483
484
485
486
487 ;
488
489
490
491
492
493
494 public native El click()
495
496
497
498
499
500
501
502
503
504
505 ;
506
507
508
509
510
511
512 public El clip() {
513 if (!isClipped) {
514 isClipped = true;
515 originalClipped = new String[3];
516 originalClipped[0] = getStyleAttribute("overflow");
517 originalClipped[1] = getStyleAttribute("overflowX");
518 originalClipped[2] = getStyleAttribute("overflowY");
519 setStyleAttribute("overflow", "hidden");
520 setStyleAttribute("overflowX", "hidden");
521 setStyleAttribute("overflowY", "hidden");
522 }
523 return this;
524 }
525
526
527
528
529
530
531
532 public Element cloneNode(boolean deep) {
533 return (Element) dom.cloneNode(deep);
534 }
535
536
537
538
539
540
541
542 public El createChild(String html) {
543 return appendChild(XDOM.create(html));
544 }
545
546
547
548
549
550
551
552
553 public El createChild(String html, Element insertBefore) {
554 Element element = XDOM.create(html);
555 int idx = DOM.getChildIndex(dom, insertBefore);
556 insertChild(element, idx);
557 return new El(element);
558 }
559
560
561
562
563
564
565 public El disable() {
566 dom.setPropertyBoolean("disabled", true);
567 return this;
568 }
569
570
571
572
573
574
575
576
577
578
579 public native El disableContextMenu(boolean disable)
580
581
582
583
584
585 ;
586
587
588
589
590
591
592
593
594
595
596 public El disableTextSelection(boolean disable) {
597 setStyleName("x-unselectable", disable);
598 setElementAttribute("unselectable", disable ? "on" : "");
599 disableTextSelectInternal(dom, disable);
600 return this;
601 }
602
603
604
605
606
607
608
609
610 public El down(String selector) {
611 Element elem = DomQuery.selectNode(" > " + selector, dom);
612 if (elem != null) {
613 return new El(elem);
614 }
615 return null;
616 }
617
618
619
620
621
622
623 public El enable() {
624 dom.setPropertyBoolean("disabled", false);
625 return this;
626 }
627
628
629
630
631
632
633
634 public El enableDisplayMode(String display) {
635 setVisibilityMode(VisMode.DISPLAY);
636 if (display != null) {
637 originalDisplay = display;
638 }
639 return this;
640 }
641
642 @Override
643 public boolean equals(Object obj) {
644 if (obj instanceof El) {
645 return getId().equals(((El) obj).getId());
646 }
647 return super.equals(obj);
648 }
649
650
651
652
653
654
655
656 public El fadeIn(FxConfig config) {
657 BaseEffect.fadeIn(this, config);
658 return this;
659 }
660
661
662
663
664
665
666
667 public El fadeOut(FxConfig config) {
668 BaseEffect.fadeOut(this, config);
669 return this;
670 }
671
672
673
674
675
676
677
678 public El fadeToggle(FxConfig config) {
679 if (!isVisible()) {
680 BaseEffect.fadeIn(this, config);
681 } else {
682 BaseEffect.fadeOut(this, config);
683 }
684 return this;
685 }
686
687
688
689
690
691
692
693
694 public El findParent(String selector, int maxDepth) {
695 Element elem = findParentElement(selector, maxDepth);
696 if (elem == null) {
697 return null;
698 }
699 return new El(elem);
700 }
701
702
703
704
705
706
707
708
709
710 public Element findParentElement(String selector, int maxDepth) {
711 Element p = dom;
712 Element b = XDOM.getBody();
713 int depth = 0;
714 while (p != null && p.getNodeType() == 1 && (maxDepth == -1 || depth < maxDepth) && p != b) {
715 if (DomQuery.is(p, selector)) {
716 return p;
717 }
718 depth++;
719 p = (Element) p.getParentElement();
720 }
721 return null;
722 }
723
724
725
726
727
728
729 public El firstChild() {
730 Element firstChild = DOM.getFirstChild(dom);
731 return firstChild == null ? null : new El(firstChild);
732 }
733
734
735
736
737
738
739 public El focus() {
740 return setFocus(true);
741 }
742
743 public Point getAlignToXY(Element elem, String p, int ox, int oy) {
744 El el = new El(elem);
745
746 if (p == null) {
747 p = "tl-bl";
748 } else if (p.equals("?")) {
749 p = "tl-bl?";
750 } else if (p.indexOf("-") == -1) {
751 p = "tl-" + p;
752 }
753 p = p.toLowerCase();
754 boolean c = false;
755 String p1 = p.substring(0, p.indexOf("-"));
756 String p2 = p.substring(p.indexOf("-") + 1, ((c = p.contains("?")) ? p.indexOf("?") : p.length()));
757
758
759 Point a1 = getAnchorXY(p1, true);
760 Point a2 = el.getAnchorXY(p2, false);
761
762 int x = a2.x - a1.x + ox;
763 int y = a2.y - a1.y + oy;
764
765 if (c) {
766
767 int w = getWidth();
768 int h = getHeight();
769 Region r = el.getRegion();
770
771 int dw = XDOM.getViewWidth(false) - 10;
772 int dh = XDOM.getViewHeight(false) - 10;
773
774
775
776
777
778
779 char p1y = p1.charAt(0), p1x = p1.charAt(p1.length() - 1);
780 char p2y = p2.charAt(0), p2x = p2.charAt(p2.length() - 1);
781
782 boolean swapY = ((p1y == 't' && p2y == 'b') || (p1y == 'b' && p2y == 't'));
783 boolean swapX = ((p1x == 'r' && p2x == 'l') || (p1x == 'l' && p2x == 'r'));
784
785 int scrollX = XDOM.getBodyScrollLeft() + 5;
786 int scrollY = XDOM.getBodyScrollTop() + 5;
787
788 if ((x + w) > dw + scrollX) {
789 x = swapX ? r.left - w : dw + scrollX - w;
790 }
791 if (x < scrollX) {
792 x = swapX ? r.right : scrollX;
793 }
794
795 if ((y + h) > (dh + scrollY)) {
796 y = swapY ? r.top - h : dh + scrollY - h;
797 }
798 if (y < scrollY) {
799 y = swapY ? r.bottom : scrollY;
800 }
801 }
802
803 return new Point(x, y);
804 }
805
806
807
808
809
810
811
812
813
814
815 public Point getAlignToXY(Element align, String pos, int[] offsets) {
816 if (offsets == null) {
817 offsets = new int[] {0, 0};
818 }
819 return getAlignToXY(align, pos, offsets[0], offsets[1]);
820 }
821
822
823
824
825
826
827
828
829
830
831
832 public Point getAnchorXY(String anchor, boolean local) {
833 if (anchor == null) {
834 return null;
835 }
836 boolean vp = false;
837 int w;
838 int h;
839 if (dom == XDOM.getBody() || dom == XDOM.getDocument()) {
840 vp = true;
841 w = XDOM.getViewWidth(false);
842 h = XDOM.getViewHeight(false);
843 } else {
844 w = getWidth();
845 h = getHeight();
846 }
847
848 int x = 0, y = 0;
849 if (anchor.length() == 1) {
850 if ("c".equalsIgnoreCase(anchor)) {
851 x = (int) Math.round(w * .5);
852 y = (int) Math.round(h * .5);
853 } else if ("t".equalsIgnoreCase(anchor)) {
854 x = (int) Math.round(w * .5);
855 y = 0;
856 } else if ("l".equalsIgnoreCase(anchor)) {
857 x = 0;
858 y = (int) Math.round(h * .5);
859 } else if ("r".equalsIgnoreCase(anchor)) {
860 x = w;
861 y = (int) Math.round(h * .5);
862 } else if ("b".equalsIgnoreCase(anchor)) {
863 x = (int) Math.round(w * .5);
864 y = h;
865 }
866 } else {
867 if ("tl".equalsIgnoreCase(anchor)) {
868 x = 0;
869 y = 0;
870 } else if ("bl".equalsIgnoreCase(anchor)) {
871 x = 0;
872 y = h;
873 } else if ("br".equalsIgnoreCase(anchor)) {
874 x = w;
875 y = h;
876 } else if ("tr".equalsIgnoreCase(anchor)) {
877 x = w;
878 y = 0;
879 }
880 }
881
882 if (local) {
883 return new Point(x, y);
884 }
885 if (vp) {
886 Scroll sc = getScroll();
887 return new Point(x + sc.getScrollLeft(), y + sc.getScrollTop());
888 }
889
890
891 Point o = getXY();
892 return new Point(x + o.x, y + o.y);
893 }
894
895
896
897
898
899
900
901
902
903 public int getBorderWidth(String sides) {
904 double borderWidth = 0;
905 List<String> list = new ArrayList<String>();
906 if (sides.contains("l")) {
907 list.add("borderLeftWidth");
908 }
909 if (sides.contains("r")) {
910 list.add("borderRightWidth");
911 }
912 if (sides.contains("t")) {
913 list.add("borderTopWidth");
914 }
915 if (sides.contains("b")) {
916 list.add("borderBottomWidth");
917 }
918 FastMap<String> map = getStyleAttribute(list);
919 for (String s : map.keySet()) {
920 borderWidth += Util.parseFloat(map.get(s), 0);
921 }
922 return (int) Math.round(borderWidth);
923 }
924
925
926
927
928
929
930
931
932 public int getBottom(boolean local) {
933 return getHeight() + (local ? getTop() : getY());
934 }
935
936
937
938
939
940
941 public Rectangle getBounds() {
942 return getBounds(false, false);
943 }
944
945
946
947
948
949
950
951
952
953 public Rectangle getBounds(boolean local) {
954 return getBounds(local, false);
955 }
956
957
958
959
960
961
962
963
964
965
966 public Rectangle getBounds(boolean local, boolean adjust) {
967 Size s = getSize(adjust);
968 Rectangle rect = new Rectangle();
969 rect.width = s.width;
970 rect.height = s.height;
971 if (local) {
972 rect.x = getLeft(true);
973 rect.y = getTop(true);
974 } else {
975 Point p = getXY();
976 rect.x = p.x;
977 rect.y = p.y;
978 }
979 return rect;
980 }
981
982
983
984
985
986
987
988 public El getChild(int index) {
989 Element child = getChildElement(index);
990 return child == null ? null : new El(child);
991 }
992
993
994
995
996
997
998
999 public Element getChildElement(int index) {
1000 return DOM.getChild(dom, index);
1001 }
1002
1003
1004
1005
1006
1007
1008 public int getChildIndex(Element child) {
1009 return DOM.getChildIndex(dom, child);
1010 }
1011
1012
1013
1014
1015
1016
1017 public int getClientHeight() {
1018 return DOM.getElementPropertyInt(dom, "clientHeight");
1019 }
1020
1021
1022
1023
1024
1025
1026 public int getClientWidth() {
1027 return DOM.getElementPropertyInt(dom, "clientWidth");
1028 }
1029
1030
1031
1032
1033
1034
1035
1036 public int getComputedHeight() {
1037 int h = getHeight();
1038 if (h == 0) {
1039 h = getIntStyleAttribute("height");
1040 }
1041 return h;
1042 }
1043
1044
1045
1046
1047
1048
1049
1050 public int getComputedWidth() {
1051 int w = getWidth();
1052 if (w == 0) {
1053 w = getIntStyleAttribute("width");
1054 }
1055 return w;
1056 }
1057
1058
1059
1060
1061
1062
1063
1064 public Size getFrameSize() {
1065 double width = 0;
1066 double height = 0;
1067 List<String> list = new ArrayList<String>();
1068 list.add("paddingLeft");
1069 list.add("borderLeftWidth");
1070
1071 list.add("paddingRight");
1072 list.add("borderRightWidth");
1073
1074 list.add("paddingTop");
1075 list.add("borderTopWidth");
1076
1077 list.add("paddingBottom");
1078 list.add("borderBottomWidth");
1079
1080 FastMap<String> map = getStyleAttribute(list);
1081 for (String s : map.keySet()) {
1082 if (isLeftorRight(s)) {
1083 width += Util.parseFloat(map.get(s), 0);
1084 } else {
1085 height += Util.parseFloat(map.get(s), 0);
1086 }
1087 }
1088 return new Size((int) Math.round(width), (int) Math.round(height));
1089 }
1090
1091
1092
1093
1094
1095
1096
1097
1098 public int getFrameWidth(String sides) {
1099 double frameWidth = 0;
1100 List<String> list = new ArrayList<String>();
1101 if (sides.contains("l")) {
1102 list.add("paddingLeft");
1103 list.add("borderLeftWidth");
1104 }
1105 if (sides.contains("r")) {
1106 list.add("paddingRight");
1107 list.add("borderRightWidth");
1108 }
1109 if (sides.contains("t")) {
1110 list.add("paddingTop");
1111 list.add("borderTopWidth");
1112 }
1113 if (sides.contains("b")) {
1114 list.add("paddingBottom");
1115 list.add("borderBottomWidth");
1116 }
1117 FastMap<String> map = getStyleAttribute(list);
1118 for (String s : map.keySet()) {
1119 frameWidth += Util.parseFloat(map.get(s), 0);
1120 }
1121 return (int) Math.round(frameWidth);
1122 }
1123
1124
1125
1126
1127
1128
1129 public int getHeight() {
1130 return dom.getOffsetHeight();
1131 }
1132
1133
1134
1135
1136
1137
1138
1139 public int getHeight(boolean content) {
1140 int h = getHeight();
1141 if (content) {
1142 h -= getFrameWidth("tb");
1143 }
1144 return Math.max(0, h);
1145 }
1146
1147
1148
1149
1150
1151
1152 public String getId() {
1153 String id = DOM.getElementProperty(dom, "id");
1154 if (id == null || (id != null && id.length() == 0)) {
1155 id = XDOM.getUniqueId();
1156 setId(id);
1157 }
1158 return id;
1159 }
1160
1161
1162
1163
1164
1165
1166 public String getInnerHtml() {
1167 return DOM.getInnerHTML(dom);
1168 }
1169
1170
1171
1172
1173
1174
1175
1176 public int getIntStyleAttribute(String attr) {
1177 String v = DOM.getStyleAttribute(dom, attr);
1178 if (v == null || v.equals("")) {
1179 return 0;
1180 }
1181 return Util.parseInt(v, 0);
1182 }
1183
1184
1185
1186
1187
1188
1189 public Rectangle getLayoutBounds() {
1190 Rectangle r = getBounds();
1191 r.width -= getFrameWidth("lr");
1192 r.height -= getFrameWidth("tb");
1193 return r;
1194 }
1195
1196
1197
1198
1199
1200
1201 public int getLeft() {
1202 return getLeft(true);
1203 }
1204
1205
1206
1207
1208
1209
1210
1211 public int getLeft(boolean local) {
1212 return local ? Util.parseInt(getStyleAttribute("left"), 0) : getX();
1213 }
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223 public int getMargins(String sides) {
1224 double margin = 0;
1225 List<String> list = new ArrayList<String>();
1226 if (sides.contains("l")) {
1227 list.add("marginLeft");
1228 }
1229 if (sides.contains("r")) {
1230 list.add("marginRight");
1231 }
1232 if (sides.contains("t")) {
1233 list.add("marginTop");
1234 }
1235 if (sides.contains("b")) {
1236 list.add("marginBottom");
1237 }
1238 FastMap<String> map = getStyleAttribute(list);
1239 for (String s : map.keySet()) {
1240 margin += Util.parseFloat(map.get(s), 0);
1241 }
1242 return (int) Math.round(margin);
1243 }
1244
1245
1246
1247
1248
1249
1250
1251
1252 public Point getOffsetsTo(Element to) {
1253 Point o = getXY();
1254 Point e = El.fly(to, "_internal").getXY();
1255 return new Point(o.x - e.x, o.y - e.y);
1256 }
1257
1258
1259
1260
1261
1262
1263 public String getOuterHtml() {
1264 return dom.getAttribute("outerHTML");
1265 }
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275 public int getPadding(String sides) {
1276 double padding = 0;
1277 List<String> list = new ArrayList<String>();
1278 if (sides.contains("l")) {
1279 list.add("paddingLeft");
1280 }
1281 if (sides.contains("r")) {
1282 list.add("paddingRight");
1283 }
1284 if (sides.contains("t")) {
1285 list.add("paddingTop");
1286 }
1287 if (sides.contains("b")) {
1288 list.add("paddingBottom");
1289 }
1290 FastMap<String> map = getStyleAttribute(list);
1291 for (String s : map.keySet()) {
1292 padding += Util.parseFloat(map.get(s), 0);
1293 }
1294 return (int) Math.round(padding);
1295 }
1296
1297
1298
1299
1300
1301
1302 public El getParent() {
1303 Element e = DOM.getParent(dom);
1304 return e == null ? null : new El(e);
1305 }
1306
1307
1308
1309
1310
1311
1312
1313 public Region getRegion() {
1314 Rectangle bounds = getBounds();
1315 Region r = new Region();
1316 r.left = bounds.x;
1317 r.top = bounds.y;
1318 r.right = r.left + bounds.width;
1319 r.bottom = r.top + bounds.height;
1320 return r;
1321 }
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331 public int getRight(boolean local) {
1332 return getWidth() + (local ? getLeft(true) : getX());
1333 }
1334
1335
1336
1337
1338
1339
1340 public Scroll getScroll() {
1341 if (dom == XDOM.getBody() || dom == XDOM.getDocument()) {
1342 return new Scroll(XDOM.getBodyScrollLeft(), XDOM.getBodyScrollTop());
1343 } else {
1344 return new Scroll(getScrollLeft(), getScrollTop());
1345 }
1346 }
1347
1348
1349
1350
1351
1352
1353 public int getScrollLeft() {
1354 return DOM.getElementPropertyInt(dom, "scrollLeft");
1355 }
1356
1357
1358
1359
1360
1361
1362 public int getScrollTop() {
1363 return DOM.getElementPropertyInt(dom, "scrollTop");
1364 }
1365
1366
1367
1368
1369
1370
1371 public Size getSize() {
1372 return getSize(false);
1373 }
1374
1375
1376
1377
1378
1379
1380
1381 public Size getSize(boolean content) {
1382 int w = getWidth();
1383 int h = getHeight();
1384 if (content) {
1385 Size frameWidth = getFrameSize();
1386 w -= frameWidth.width;
1387 h -= frameWidth.height;
1388 }
1389 return new Size(Math.max(0, w), Math.max(0, h));
1390 }
1391
1392 public FastMap<String> getStyleAttribute(List<String> attr) {
1393 return computedStyle.getStyleAttribute(dom, attr);
1394 }
1395
1396
1397
1398
1399
1400
1401
1402 public String getStyleAttribute(String attr) {
1403 return getStyleAttribute(Arrays.asList(attr)).get(attr);
1404 }
1405
1406
1407
1408
1409
1410
1411 public int getStyleHeight() {
1412 String h = dom.getStyle().getProperty("height");
1413 if (h == null || h.equals("")) return 0;
1414 if (h.matches("(auto|em|%|en|ex|pt|in|cm|mm|pc)")) {
1415 return 0;
1416 }
1417 return Util.parseInt(h, 0);
1418 }
1419
1420
1421
1422
1423
1424
1425 public String getStyleName() {
1426
1427
1428 return getClassName(dom);
1429
1430 }
1431
1432 public Size getStyleSize() {
1433 return getStyleSize(true);
1434 }
1435
1436
1437
1438
1439
1440
1441 public Size getStyleSize(boolean contentOnly) {
1442 int h = Util.parseInt(dom.getStyle().getProperty("height"), Style.DEFAULT);
1443 int w = Util.parseInt(dom.getStyle().getProperty("width"), Style.DEFAULT);
1444
1445 boolean isBorderBox = isBorderBox();
1446
1447 if (isBorderBox && contentOnly && w != Style.DEFAULT) {
1448 w -= getFrameWidth("lr");
1449 if (w < 0) {
1450 w = Style.DEFAULT;
1451 }
1452 } else if (!isBorderBox && !contentOnly && w != Style.DEFAULT) {
1453 w += getFrameWidth("lr");
1454 }
1455 if (isBorderBox && contentOnly && h != Style.DEFAULT) {
1456 h -= getFrameWidth("tb");
1457 if (h < 0) {
1458 h = Style.DEFAULT;
1459 }
1460 } else if (!isBorderBox && !contentOnly && h != Style.DEFAULT) {
1461 h += getFrameWidth("tb");
1462 }
1463
1464 int offsetWidth = Style.DEFAULT;
1465 int offsetHeight = Style.DEFAULT;
1466 if (w == Style.DEFAULT && h == Style.DEFAULT) {
1467 Size s = getSize(contentOnly);
1468 offsetWidth = s.width;
1469 offsetHeight = s.height;
1470 if (s.width > 0) {
1471 w = s.width;
1472 }
1473 if (s.height > 0) {
1474 h = s.height;
1475 }
1476 } else if (w == Style.DEFAULT) {
1477 offsetWidth = getWidth(contentOnly);
1478 if (offsetWidth > 0) {
1479 w = offsetWidth;
1480 }
1481 } else if (h == Style.DEFAULT) {
1482 offsetHeight = getHeight(contentOnly);
1483 if (offsetHeight > 0) {
1484 h = offsetHeight;
1485 }
1486 }
1487
1488 List<String> l = new ArrayList<String>();
1489 if (w == Style.DEFAULT) {
1490 l.add("width");
1491 }
1492 if (h == Style.DEFAULT) {
1493 l.add("height");
1494 }
1495 Map<String, String> map = getStyleAttribute(l);
1496 if (map != null) {
1497 String wid = map.get("width");
1498 if (wid != null) {
1499 w = Util.parseInt(wid, Style.DEFAULT);
1500 if (offsetWidth == 0 && isBorderBox && contentOnly && w != Style.DEFAULT && !GXT.isIE) {
1501 w -= getFrameWidth("lr");
1502 } else if (GXT.isIE && isBorderBox && w != Style.DEFAULT && contentOnly) {
1503 w -= getFrameWidth("lr");
1504 } else if (offsetWidth == 0 && !isBorderBox && !contentOnly && w != Style.DEFAULT) {
1505 w += getFrameWidth("lr");
1506 }
1507 }
1508 String hei = map.get("height");
1509 if (hei != null) {
1510 h = Util.parseInt(hei, Style.DEFAULT);
1511 if (offsetHeight == 0 && isBorderBox && contentOnly && h != Style.DEFAULT && !GXT.isIE) {
1512 h -= getFrameWidth("tb");
1513 } else if (GXT.isIE && isBorderBox && h != Style.DEFAULT && contentOnly) {
1514 h -= getFrameWidth("tb");
1515 } else if (offsetHeight == 0 && !isBorderBox && !contentOnly && h != Style.DEFAULT) {
1516 h += getFrameWidth("tb");
1517 }
1518 }
1519 }
1520 if (w == Style.DEFAULT && h == Style.DEFAULT) {
1521 return new Size(offsetWidth, offsetHeight);
1522 }
1523 return new Size(w != Style.DEFAULT ? w : offsetWidth, h != Style.DEFAULT ? h : offsetHeight);
1524 }
1525
1526
1527
1528
1529
1530
1531
1532 public int getStyleWidth() {
1533 String w = dom.getStyle().getProperty("width");
1534 if (w == null || w.equals("")) return 0;
1535 if (w.matches("(auto|em|%|en|ex|pt|in|cm|mm|pc)")) {
1536 return 0;
1537 }
1538 return Util.parseInt(w, 0);
1539 }
1540
1541
1542
1543
1544
1545
1546
1547 public Element getSubChild(int depth) {
1548 Element child = dom;
1549 while (depth-- > 0) {
1550 child = DOM.getChild(child, 0);
1551 }
1552 return child;
1553 }
1554
1555
1556
1557
1558
1559
1560 public int getTextWidth() {
1561 String html = getInnerHtml();
1562 TextMetrics metrics = TextMetrics.get();
1563 metrics.bind(dom);
1564 return metrics.getWidth(html);
1565 }
1566
1567
1568
1569
1570
1571
1572 public int getTop() {
1573 return getTop(true);
1574 }
1575
1576
1577
1578
1579
1580
1581
1582 public int getTop(boolean local) {
1583 return local ? Util.parseInt(getStyleAttribute("top"), 0) : getY();
1584 }
1585
1586
1587
1588
1589
1590
1591 public String getValue() {
1592 return DOM.getElementProperty(dom, "value");
1593 }
1594
1595
1596
1597
1598
1599
1600 public int getWidth() {
1601 return dom.getOffsetWidth();
1602 }
1603
1604
1605
1606
1607
1608
1609
1610 public int getWidth(boolean content) {
1611 int w = getWidth();
1612 if (content) {
1613 w -= getFrameWidth("lr");
1614 }
1615 return Math.max(0, w);
1616 }
1617
1618
1619
1620
1621
1622
1623
1624 public int getX() {
1625 return dom.getAbsoluteLeft();
1626 }
1627
1628
1629
1630
1631
1632
1633
1634 public Point getXY() {
1635 return new Point(getX(), getY());
1636 }
1637
1638
1639
1640
1641
1642
1643 public int getY() {
1644 return dom.getAbsoluteTop();
1645 }
1646
1647
1648
1649
1650
1651
1652 public int getZIndex() {
1653 return Util.parseInt(getStyleAttribute("zIndex"), 0);
1654 }
1655
1656
1657
1658
1659
1660
1661
1662 public boolean hasStyleName(String style) {
1663
1664
1665 String cls = getClassName(dom);
1666
1667 return (" " + cls + " ").indexOf(" " + style + " ") != -1 ? true : false;
1668 }
1669
1670
1671
1672
1673
1674
1675 public El hide() {
1676 return setVisible(false);
1677 }
1678
1679
1680
1681
1682
1683
1684
1685 public El insertBefore(Element before) {
1686 before.getParentElement().insertBefore(dom, before);
1687 return this;
1688 }
1689
1690
1691
1692
1693
1694
1695
1696
1697 public El insertBefore(Element child, Element before) {
1698 dom.insertBefore(child, before);
1699 return this;
1700 }
1701
1702
1703
1704
1705
1706
1707
1708
1709 public El insertBefore(Element[] elements, Element before) {
1710 for (int i = 0; i < elements.length; i++) {
1711 insertBefore(elements[i], before);
1712 }
1713 return this;
1714 }
1715
1716
1717
1718
1719
1720
1721
1722
1723 public El insertChild(Element child, int index) {
1724 DOM.insertChild(dom, child, index);
1725 return this;
1726 }
1727
1728
1729
1730
1731
1732
1733
1734
1735 public El insertChild(Element[] children, int index) {
1736 for (int i = children.length - 1; i >= 0; i--) {
1737 DOM.insertChild(dom, children[i], index);
1738 }
1739 return this;
1740 }
1741
1742
1743
1744
1745
1746
1747
1748 public El insertFirst(Element element) {
1749 DOM.insertChild(dom, element, 0);
1750 return this;
1751 }
1752
1753
1754
1755
1756
1757
1758
1759 public El insertFirst(Element[] elems) {
1760 for (int i = 0; i < elems.length; i++) {
1761 DOM.appendChild(dom, elems[i]);
1762 }
1763 return this;
1764 }
1765
1766
1767
1768
1769
1770
1771
1772 public El insertFirst(String html) {
1773 return new El(DomHelper.insertFirst(dom, html));
1774 }
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784 public El insertHtml(String where, String html) {
1785 return new El(DomHelper.insertHtml(where, dom, html));
1786 }
1787
1788
1789
1790
1791
1792
1793
1794 public El insertInto(Element parent) {
1795 fly(parent, "_internal").appendChild(dom);
1796 return this;
1797 }
1798
1799
1800
1801
1802
1803
1804
1805
1806 public El insertInto(Element parent, int index) {
1807 fly(parent, "_internal").insertChild(dom, index);
1808 return this;
1809 }
1810
1811
1812
1813
1814
1815
1816
1817 public El insertLast(Element child) {
1818 int idx = dom.getChildNodes().getLength();
1819 insertChild(child, idx);
1820 return this;
1821 }
1822
1823
1824
1825
1826
1827
1828
1829
1830 public Element insertSibling(Element elem, String where) {
1831 Element refNode = where.equals("before") ? dom : nextSibling();
1832 if (refNode == null) {
1833 DOM.appendChild(DOM.getParent(dom), elem);
1834 } else {
1835 DOM.insertBefore(getParent().dom, elem, refNode);
1836 }
1837 return elem;
1838 }
1839
1840
1841
1842
1843
1844
1845
1846
1847 public El insertSibling(Element[] elems, String where) {
1848 for (int i = 0; i < elems.length; i++) {
1849 insertSibling(elems[i], where);
1850 }
1851 return this;
1852 }
1853
1854
1855
1856
1857
1858
1859
1860
1861 public boolean is(String selector) {
1862 return DomQuery.is(dom, selector);
1863 }
1864
1865
1866
1867
1868
1869
1870 public boolean isBorderBox() {
1871 return isBorderBox(dom);
1872 }
1873
1874
1875
1876
1877
1878
1879 public boolean isConnected() {
1880 return Document.get().getBody().isOrHasChild(dom);
1881 }
1882
1883
1884
1885
1886
1887
1888 public boolean isMasked() {
1889 return _mask != null && _mask.isVisible();
1890 }
1891
1892
1893
1894
1895
1896
1897
1898 public boolean isOrHasChild(Element child) {
1899 return DOM.isOrHasChild(dom, child);
1900 }
1901
1902
1903
1904
1905
1906
1907 public boolean isScrollable() {
1908 return isScrollableX() || isScrollableY();
1909 }
1910
1911
1912
1913
1914
1915
1916 public boolean isScrollableX() {
1917 return dom.getScrollWidth() > dom.getClientWidth();
1918 }
1919
1920
1921
1922
1923
1924
1925 public boolean isScrollableY() {
1926 return dom.getScrollHeight() > dom.getClientHeight();
1927 }
1928
1929 public boolean isStyleAttribute(Map<String, String> map, boolean matchAll) {
1930 Set<String> collection = map.keySet();
1931 FastMap<String> a = getStyleAttribute(new ArrayList<String>(collection));
1932 for (String s : collection) {
1933 if (map.get(s).equals(a.get(s))) {
1934 if (!matchAll) {
1935 return true;
1936 }
1937 } else {
1938 if (matchAll) {
1939 return false;
1940 }
1941 }
1942 }
1943 return false;
1944 }
1945
1946 public boolean isStyleAttribute(String attr, String value) {
1947 String a = getStyleAttribute(attr);
1948 return a != null && a.equals(value);
1949 }
1950
1951
1952
1953
1954
1955
1956
1957 public boolean isVisibility() {
1958 return isStyleAttribute("visibility", "hidden");
1959 }
1960
1961
1962
1963
1964
1965
1966 public boolean isVisible() {
1967 return isVisible(false);
1968 }
1969
1970
1971
1972
1973
1974
1975
1976
1977 public boolean isVisible(boolean deep) {
1978 Map<String, String> map = new FastMap<String>();
1979 map.put("visibility", "hidden");
1980 map.put("display", "none");
1981 boolean vis = !isStyleAttribute(map, false);
1982 El parent = getParent();
1983 Element p = parent != null ? parent.dom : null;
1984 if (p == null) {
1985 return false;
1986 }
1987 if (!deep || !vis) {
1988 return vis;
1989 }
1990 while (p != null && p != XDOM.getBody()) {
1991 if (!fly(p, "_isVisible").isVisible()) {
1992 return false;
1993 }
1994 p = (Element) p.getParentElement();
1995 }
1996
1997 return true;
1998
1999 }
2000
2001
2002
2003
2004
2005
2006 public El lastChild() {
2007 Element e = DOM.getChild(dom, DOM.getChildCount(dom) - 1);
2008 return e == null ? null : new El(e);
2009 }
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019 public Request load(RequestBuilder builder) {
2020 try {
2021 builder.setCallback(new RequestCallback() {
2022
2023 public void onError(Request request, Throwable exception) {
2024 setInnerHtml(exception.getMessage());
2025 }
2026
2027 public void onResponseReceived(Request request, Response response) {
2028 setInnerHtml(response.getText());
2029 }
2030
2031 });
2032 return builder.send();
2033 } catch (Exception e) {
2034 setInnerHtml(e.getMessage());
2035 return null;
2036 }
2037 }
2038
2039
2040
2041
2042 public El makePositionable() {
2043 return makePositionable(false);
2044 }
2045
2046
2047
2048
2049
2050
2051
2052 public El makePositionable(boolean absolute) {
2053 if (absolute) {
2054 setStyleAttribute("position", "absolute");
2055 } else if ("static".equals(getStyleAttribute("position"))) {
2056 setStyleAttribute("position", "relative");
2057 }
2058 return this;
2059 }
2060
2061
2062
2063
2064
2065
2066 public El mask() {
2067 return mask(null, null);
2068 }
2069
2070
2071
2072
2073
2074
2075
2076 public El mask(String message) {
2077 return mask(message, null);
2078 }
2079
2080
2081
2082
2083
2084
2085
2086
2087 public El mask(String message, String messageStyleName) {
2088 if ("static".equals(getStyleAttribute("position"))) {
2089 addStyleName("x-masked-relative");
2090 }
2091 if (_maskMsg != null) {
2092 _maskMsg.remove();
2093 }
2094 if (_mask != null) {
2095 _mask.remove();
2096 }
2097
2098 _mask = new El("<div class='ext-el-mask'></div>");
2099
2100 addStyleName("x-masked");
2101 _mask.setDisplayed(true);
2102
2103 appendChild(_mask.dom);
2104 if (message != null) {
2105 _maskMsg = new El("<div class='ext-el-mask-msg'><div></div></div>");
2106 if (messageStyleName != null) {
2107 _maskMsg.addStyleName(messageStyleName);
2108 }
2109 _maskMsg.firstChild().setInnerHtml(message);
2110 _maskMsg.setDisplayed(true);
2111
2112 appendChild(_maskMsg.dom);
2113 _maskMsg.center(dom);
2114 }
2115 if (GXT.isIE && !(GXT.isIE7 && GXT.isStrict) && "auto".equals(getStyleAttribute("height"))) {
2116 _mask.setSize(getWidth(), getHeight());
2117 }
2118
2119 return _mask;
2120 }
2121
2122
2123
2124
2125
2126
2127 public Element nextSibling() {
2128 return DOM.getNextSibling(dom);
2129 }
2130
2131
2132
2133
2134
2135
2136 public Element previousSibling() {
2137 return dom.getPreviousSibling().cast();
2138 }
2139
2140
2141
2142
2143 public El remove() {
2144 return removeFromParent();
2145 }
2146
2147
2148
2149
2150
2151
2152
2153 public El removeChild(Element child) {
2154 dom.removeChild(child);
2155 return this;
2156 }
2157
2158
2159
2160
2161 public El removeChildren() {
2162 El child = null;
2163 while ((child = firstChild()) != null) {
2164 dom.removeChild(child.dom);
2165 }
2166 setInnerHtml("");
2167 return this;
2168 }
2169
2170
2171
2172
2173 public El removeFromParent() {
2174 com.google.gwt.dom.client.Element p = dom.getParentElement();
2175 if (p != null) {
2176 p.removeChild(dom);
2177 }
2178 return this;
2179 }
2180
2181
2182
2183
2184
2185
2186
2187 public El removeStyleName(String... styleNames) {
2188 for (String s : styleNames) {
2189 removeStyleName(s);
2190 }
2191 return this;
2192 }
2193
2194
2195
2196
2197
2198
2199
2200 public native El removeStyleName(String styleName)
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211 ;
2212
2213
2214
2215
2216
2217
2218 public El repaint() {
2219 addStyleName("x-repaint");
2220 DeferredCommand.addCommand(new Command() {
2221 public void execute() {
2222 removeStyleName("x-repaint");
2223 }
2224 });
2225 return this;
2226 }
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236 public El replaceStyleName(String oldStyle, String newStyle) {
2237 return removeStyleName(oldStyle).addStyleName(newStyle);
2238 }
2239
2240 public El scrollIntoView(Element container, boolean hscroll) {
2241 return scrollIntoView(container, hscroll, null);
2242 }
2243
2244
2245
2246
2247
2248
2249
2250 public El scrollIntoView(Element container, boolean hscroll, int[] offsets) {
2251 if (offsets == null) {
2252 offsets = new int[] {0, 0};
2253 }
2254 Element c = container != null ? container : XDOM.getBody();
2255
2256 Point o = getOffsetsTo(c);
2257 int l = o.x;
2258 int t = o.y;
2259 l = l + c.getScrollLeft();
2260 t = t + c.getScrollTop();
2261 int b = t + getHeight() + offsets[0];
2262 int r = l + getWidth() + offsets[1];
2263
2264 int ch = c.getClientHeight();
2265 int ct = c.getScrollTop();
2266 int cb = ct + ch;
2267
2268 if (getHeight() > ch || t < ct) {
2269 c.setScrollTop(t);
2270 } else if (b > cb) {
2271 c.setScrollTop(b - ch);
2272 }
2273
2274 if (hscroll) {
2275 int cl = c.getScrollLeft();
2276 int cw = c.getClientWidth();
2277 int cr = cl + cw;
2278
2279 if (getWidth() > cw || l < cl) {
2280 c.setScrollLeft(l);
2281 } else if (r > cr) {
2282 c.setScrollLeft(r - cw);
2283 }
2284 }
2285 return this;
2286 }
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296 public El scrollTo(String side, int value) {
2297 if ("left".equalsIgnoreCase(side)) {
2298 setScrollLeft(value);
2299 } else if ("top".equalsIgnoreCase(side)) {
2300 setScrollTop(value);
2301 }
2302 return this;
2303 }
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314 public El scrollTo(String side, int value, FxConfig config) {
2315 ScrollDir dir = ScrollDir.VERTICAL;
2316 if (side.equalsIgnoreCase("left")) {
2317 dir = ScrollDir.HORIZONTAL;
2318 }
2319 BaseEffect.scroll(this, config, dir, value);
2320 return this;
2321 }
2322
2323
2324
2325
2326
2327
2328
2329
2330 public NodeList<Element> select(String selector) {
2331 return DomQuery.select(selector, dom);
2332 }
2333
2334
2335
2336
2337
2338
2339
2340 public El selectNode(String selector) {
2341 Element el = DomQuery.selectNode(selector, dom);
2342 if (el != null) {
2343 return new El(el);
2344 }
2345 return null;
2346 }
2347
2348
2349
2350
2351
2352
2353
2354
2355 public El setBorders(boolean show) {
2356 if (show) {
2357 addStyleName("x-border");
2358 setStyleAttribute("borderWidth", "1px");
2359 } else {
2360 removeStyleName("x-border");
2361 setStyleAttribute("borderWidth", "0px");
2362 }
2363 return this;
2364 }
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375 public El setBounds(int x, int y, int width, int height) {
2376 return setBounds(x, y, width, height, false);
2377 }
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389 public El setBounds(int x, int y, int width, int height, boolean adjust) {
2390 setPagePosition(x, y);
2391 setSize(width, height, adjust);
2392 return this;
2393 }
2394
2395
2396
2397
2398
2399
2400
2401 public El setBounds(Rectangle bounds) {
2402 setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
2403 return this;
2404 }
2405
2406
2407
2408
2409
2410
2411
2412
2413 public El setBounds(Rectangle bounds, boolean content) {
2414 setBounds(bounds.x, bounds.y, bounds.width, bounds.height, content);
2415 return this;
2416 }
2417
2418
2419
2420
2421
2422
2423
2424 public El setDisplayed(boolean display) {
2425 String value = display ? originalDisplay : "none";
2426 setStyleAttribute("display", value);
2427 return this;
2428 }
2429
2430
2431
2432
2433
2434
2435
2436 public El setDisplayed(String display) {
2437 setStyleAttribute("display", display);
2438 return this;
2439 }
2440
2441
2442
2443
2444
2445
2446
2447
2448 public El setElementAttribute(String attr, boolean value) {
2449 DOM.setElementPropertyBoolean(dom, attr, value);
2450 return this;
2451 }
2452
2453
2454
2455
2456
2457
2458
2459
2460 public El setElementAttribute(String attr, int value) {
2461 return setElementAttribute(attr, "" + value);
2462 }
2463
2464
2465
2466
2467
2468
2469
2470
2471 public El setElementAttribute(String attr, String value) {
2472 DOM.setElementAttribute(dom, attr, value);
2473 return this;
2474 }
2475
2476
2477
2478
2479
2480
2481 public void setEnabled(boolean enabled) {
2482 if (!enabled) {
2483 disable();
2484 } else {
2485 enable();
2486 }
2487 }
2488
2489
2490
2491
2492
2493
2494 public native El setFocus(boolean focus)
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505 ;
2506
2507
2508
2509
2510
2511
2512
2513 public El setHeight(int height) {
2514 return setHeight(height, false);
2515 }
2516
2517
2518
2519
2520
2521
2522
2523
2524 public El setHeight(int height, boolean adjust) {
2525 if (adjust && !isBorderBox()) {
2526 height -= getFrameWidth("tb");
2527 }
2528 if (height >= 0) {
2529 dom.getStyle().setPropertyPx("height", height);
2530 }
2531 return this;
2532 }
2533
2534
2535
2536
2537
2538
2539
2540 public El setHeight(String height) {
2541 DOM.setStyleAttribute(dom, "height", addUnits(height, "px"));
2542 return this;
2543 }
2544
2545
2546
2547
2548
2549
2550 public El setIconStyle(String style) {
2551 if (Util.isImagePath(style)) {
2552 setStyleAttribute("backgroundImage", "url(" + style + ")");
2553 } else {
2554 dom.setClassName(style);
2555 }
2556 return this;
2557 }
2558
2559
2560
2561
2562
2563
2564
2565 public El setId(String id) {
2566 if (id == null) {
2567 id = XDOM.getUniqueId();
2568 }
2569 dom.setId(id);
2570 return this;
2571 }
2572
2573
2574
2575
2576
2577
2578
2579 public El setInnerHtml(String html) {
2580 DOM.setInnerHTML(dom, html);
2581 return this;
2582 }
2583
2584
2585
2586
2587
2588
2589
2590
2591 public El setIntElementProperty(String property, int value) {
2592 DOM.setElementPropertyInt(dom, property, value);
2593 return this;
2594 }
2595
2596
2597
2598
2599
2600
2601
2602
2603 public El setLeft(int left) {
2604 dom.getStyle().setPropertyPx("left", left);
2605 return this;
2606 }
2607
2608
2609
2610
2611
2612
2613
2614
2615 public El setLeftTop(int left, int top) {
2616 setLeft(left);
2617 setTop(top);
2618 return this;
2619 }
2620
2621
2622
2623
2624
2625
2626
2627 public El setMargins(Margins margin) {
2628 if (margin != null) {
2629 setStyleAttribute("marginLeft", margin.left + "px");
2630 setStyleAttribute("marginTop", margin.top + "px");
2631 setStyleAttribute("marginRight", margin.right + "px");
2632 setStyleAttribute("marginBottom", margin.bottom + "px");
2633 }
2634 return this;
2635 }
2636
2637
2638
2639
2640
2641
2642
2643 public El setPadding(Padding padding) {
2644 if (padding != null) {
2645 setStyleAttribute("paddingLeft", padding.left + "px");
2646 setStyleAttribute("paddingTop", padding.top + "px");
2647 setStyleAttribute("paddingRight", padding.right + "px");
2648 setStyleAttribute("paddingBottom", padding.bottom + "px");
2649 }
2650 return this;
2651 }
2652
2653
2654
2655
2656
2657
2658
2659
2660 public El setPagePosition(int x, int y) {
2661 setX(x);
2662 setY(y);
2663 return this;
2664 }
2665
2666
2667
2668
2669
2670
2671
2672 public El setScrollLeft(int left) {
2673 DOM.setElementPropertyInt(dom, "scrollLeft", left);
2674 return this;
2675 }
2676
2677
2678
2679
2680
2681
2682
2683 public El setScrollTop(int top) {
2684 DOM.setElementPropertyInt(dom, "scrollTop", top);
2685 return this;
2686 }
2687
2688
2689
2690
2691
2692
2693
2694
2695 public El setSize(int width, int height) {
2696 setSize(width, height, false);
2697 return this;
2698 }
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708 public El setSize(int width, int height, boolean adjust) {
2709 if (adjust && !isBorderBox()) {
2710 Size frameWidth = getFrameSize();
2711 width -= frameWidth.width;
2712 height -= frameWidth.height;
2713 }
2714 if (width >= 0) {
2715 dom.getStyle().setPropertyPx("width", width);
2716 }
2717 if (height >= 0) {
2718 dom.getStyle().setPropertyPx("height", height);
2719 }
2720 return this;
2721 }
2722
2723
2724
2725
2726
2727
2728
2729 public El setSize(Size size) {
2730 setSize(size.width, size.height);
2731 return this;
2732 }
2733
2734
2735
2736
2737
2738
2739
2740
2741 public El setSize(String width, String height) {
2742 setWidth(width);
2743 setHeight(height);
2744 return this;
2745 }
2746
2747
2748
2749
2750
2751
2752
2753
2754 public El setStyleAttribute(String attr, Object value) {
2755 computedStyle.setStyleAttribute(dom, attr, value);
2756 return this;
2757 }
2758
2759
2760
2761
2762
2763
2764
2765 public El setStyleName(String style) {
2766 dom.setClassName(style);
2767 return this;
2768 }
2769
2770
2771
2772
2773
2774
2775
2776
2777 public El setStyleName(String style, boolean add) {
2778 if (add) {
2779 addStyleName(style);
2780 } else {
2781 removeStyleName(style);
2782 }
2783 return this;
2784 }
2785
2786
2787
2788
2789
2790
2791
2792
2793 public El setStyleSize(int width, int height) {
2794 setStyleAttribute("width", width);
2795 setStyleAttribute("height", height);
2796 return this;
2797 }
2798
2799
2800
2801
2802
2803
2804
2805 public El setTabIndex(int index) {
2806 DOM.setElementPropertyInt(dom, "tabIndex", index);
2807 return null;
2808 }
2809
2810
2811
2812
2813
2814
2815
2816 public El setTitle(String title) {
2817 dom.setTitle(title);
2818 return this;
2819 }
2820
2821
2822
2823
2824
2825
2826
2827
2828 public El setTop(int top) {
2829 dom.getStyle().setPropertyPx("top", top);
2830 return this;
2831 }
2832
2833
2834
2835
2836
2837
2838 public El setValue(String value) {
2839 dom.setPropertyString("value", value);
2840 return this;
2841 }
2842
2843
2844
2845
2846
2847
2848
2849
2850 public El setVisibility(boolean visible) {
2851 setStyleAttribute("visibility", visible ? "visible" : "hidden");
2852 return this;
2853 }
2854
2855
2856
2857
2858
2859
2860
2861
2862 public El setVisibilityMode(VisMode visMode) {
2863 visiblityMode = visMode;
2864 return this;
2865 }
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876 public El setVisible(boolean visible) {
2877 if (visiblityMode == VisMode.DISPLAY) {
2878 return setDisplayed(visible);
2879 } else {
2880 return setVisibility(visible);
2881 }
2882 }
2883
2884
2885
2886
2887
2888
2889
2890 public El setWidth(int width) {
2891 return setWidth(width, false);
2892 }
2893
2894
2895
2896
2897
2898
2899
2900
2901 public El setWidth(int width, boolean adjust) {
2902 if (adjust && !isBorderBox()) {
2903 width -= getFrameWidth("lr");
2904 }
2905 if (width >= 0) {
2906 dom.getStyle().setPropertyPx("width", width);
2907 }
2908 return this;
2909 }
2910
2911
2912
2913
2914
2915
2916
2917 public El setWidth(String width) {
2918 DOM.setStyleAttribute(dom, "width", addUnits(width, "px"));
2919 return this;
2920 }
2921
2922
2923
2924
2925
2926
2927
2928
2929 public El setX(int x) {
2930 return setXY(x, Style.DEFAULT);
2931 }
2932
2933
2934
2935
2936
2937
2938
2939
2940 public El setXY(int x, int y) {
2941 return setXY(new Point(x, y));
2942 }
2943
2944
2945
2946
2947
2948
2949
2950
2951 public El setXY(int x, int y, FxConfig config) {
2952 if (config == null) {
2953 setXY(x, y);
2954 } else {
2955 Fx fx = new Fx(config);
2956 fx.run(new Move(this, x, y));
2957 }
2958 return this;
2959 }
2960
2961
2962
2963
2964
2965
2966
2967 public El setXY(Point p) {
2968 makePositionable();
2969 Point pts = translatePoints(p);
2970 if (p.x != Style.DEFAULT) {
2971 setLeft(pts.x);
2972 }
2973 if (p.y != Style.DEFAULT) {
2974 setTop(pts.y);
2975 }
2976 return this;
2977 }
2978
2979
2980
2981
2982
2983
2984
2985
2986 public El setY(int y) {
2987 return setXY(Style.DEFAULT, y);
2988 }
2989
2990
2991
2992
2993
2994
2995
2996 public El setZIndex(int zIndex) {
2997 DOM.setIntStyleAttribute(dom, "zIndex", Math.max(0, zIndex));
2998 return this;
2999 }
3000
3001
3002
3003
3004
3005
3006 public El show() {
3007 return setVisible(true);
3008 }
3009
3010
3011
3012
3013
3014
3015
3016
3017 public El slideIn(Direction direction, FxConfig config) {
3018 BaseEffect.slideIn(this, config, direction);
3019 return this;
3020 }
3021
3022
3023
3024
3025
3026
3027
3028
3029 public El slideOut(Direction direction, FxConfig config) {
3030 BaseEffect.slideOut(this, config, direction);
3031 return this;
3032 }
3033
3034
3035
3036
3037
3038
3039
3040 public El subChild(int depth) {
3041 Element child = dom;
3042 while (depth-- > 0) {
3043 child = DOM.getChild(child, 0);
3044 }
3045 return new El(child);
3046 }
3047
3048
3049
3050
3051
3052
3053 public El sync(boolean show) {
3054 return this;
3055 }
3056
3057 public String toString() {
3058 return getOuterHtml();
3059 }
3060
3061 public Point translatePoints(Point p) {
3062 List<String> list = new ArrayList<String>(3);
3063 list.add("position");
3064 list.add("left");
3065 list.add("top");
3066
3067 Map<String, String> map = getStyleAttribute(list);
3068 boolean relative = "relative".equals(map.get("position"));
3069 int l = Util.parseInt(map.get("left"), -11234);
3070 int t = Util.parseInt(map.get("top"), -11234);
3071
3072 l = l != -11234 ? l : (relative ? 0 : dom.getOffsetLeft());
3073 t = t != -11234 ? t : (relative ? 0 : dom.getOffsetTop());
3074
3075 Point o = getXY();
3076 return new Point(p.x - o.x + l, p.y - o.y + t);
3077 }
3078
3079
3080
3081
3082
3083
3084 public El unclip() {
3085 if (isClipped) {
3086 isClipped = false;
3087 setStyleAttribute("overflow", originalClipped[0]);
3088 setStyleAttribute("overflowX", originalClipped[1]);
3089 setStyleAttribute("overflowY", originalClipped[2]);
3090 }
3091 return this;
3092 }
3093
3094
3095
3096
3097
3098
3099 public El unmask() {
3100 if (_mask != null) {
3101 if (_maskMsg != null) {
3102 _maskMsg.remove();
3103 _maskMsg = null;
3104 }
3105 _mask.setVisible(false);
3106 _mask.remove();
3107 _mask = null;
3108 removeStyleName("x-masked", "x-masked-relative");
3109 }
3110 return this;
3111 }
3112
3113
3114
3115
3116
3117
3118 public El unwrap(Element child, Rectangle bounds) {
3119 El.fly(child, "_internal").setLeftTop(bounds.x, bounds.y);
3120 Element p = dom.getParentElement().cast();
3121 int pos = DOM.getChildIndex(p, dom);
3122 p.removeChild(dom);
3123 DOM.insertChild(p, child, pos);
3124 return this;
3125 }
3126
3127
3128
3129
3130
3131
3132
3133 public El update(String html) {
3134 DOM.setInnerHTML(dom, html);
3135 return this;
3136 }
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146 public El updateZIndex(int adj) {
3147 setZIndex(XDOM.getTopZIndex() + adj);
3148 return this;
3149 }
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159 public Rectangle wrap(Element wrapper) {
3160 El wrap = new El(wrapper);
3161 wrap.setVisible(false);
3162
3163 String pos = getStyleAttribute("position");
3164 wrap.setStyleAttribute("position", pos);
3165
3166 int l = getLeft();
3167 int t = getTop();
3168
3169 setLeft(5000);
3170 setVisible(true);
3171
3172 int h = getComputedHeight();
3173 int w = getComputedWidth();
3174
3175 setLeft(1);
3176 setStyleAttribute("overflow", "hidden");
3177 setVisible(false);
3178
3179 wrap.insertBefore(dom);
3180 wrap.appendChild(dom);
3181
3182 wrap.setStyleAttribute("overflow", "hidden");
3183
3184 wrap.setLeft(l);
3185 wrap.setTop(t);
3186
3187 setTop(0);
3188 setLeft(0);
3189
3190 return new Rectangle(l, t, w, h);
3191 }
3192
3193 protected Point getConstrainToXY(Element elem, Point proposedXY) {
3194 int vw, vh, vx = 0, vy = 0;
3195 if (elem == XDOM.getBody()) {
3196 vw = XDOM.getViewportSize().width;
3197 vh = XDOM.getViewportSize().height;
3198
3199 if (!GXT.isIE && !fly(elem.getParentElement(), "_internal").isStyleAttribute("overflowY", "hidden")
3200 && fly(elem.getParentElement(), "_internal").isScrollableY()) {
3201 vw -= (XDOM.getScrollBarWidth());
3202 }
3203 if (!GXT.isIE && !fly(elem.getParentElement(), "_internal").isStyleAttribute("overflowX", "hidden")
3204 && fly(elem.getParentElement(), "_internal").isScrollableX()) {
3205 vh -= (XDOM.getScrollBarWidth());
3206 }
3207
3208 } else {
3209 vw = fly(elem, "_internal").getWidth();
3210 vh = fly(elem, "_internal").getHeight();
3211 }
3212
3213 Point xy = proposedXY;
3214 int x = xy.x;
3215 int y = xy.y;
3216
3217 int vr = vx + vw;
3218 int vb = vy + vh;
3219
3220 int w = getWidth();
3221 int h = getHeight();
3222
3223 if ((x + w) > vr) {
3224 x = vr - w;
3225 }
3226 if ((y + h) > vb) {
3227 y = vb - h;
3228 }
3229
3230
3231 if (x < vx) {
3232 x = vx;
3233 }
3234 if (y < vy) {
3235 y = vy;
3236 }
3237
3238 return new Point(x, y);
3239 }
3240
3241 private native boolean isLeftorRight(String s)
3242
3243
3244
3245
3246
3247 ;
3248
3249 public static native String getClassName(Element dom)
3250
3251
3252
3253
3254
3255
3256 ;
3257
3258
3259 private static native void setClassName(Element dom, String value)
3260
3261
3262
3263
3264
3265
3266 ;
3267
3268
3269
3270 }