95d82358f0d12b6f81a6ee0e644b3071c6ce3013
[jalviewjs.git] / site / swingjs / j2s / javax / swing / tree / DefaultTreeCellRenderer.js
1 Clazz.declarePackage ("javax.swing.tree");
2 Clazz.load (["javax.swing.JLabel", "javax.swing.tree.TreeCellRenderer"], "javax.swing.tree.DefaultTreeCellRenderer", ["java.awt.Dimension", "javax.swing.border.EmptyBorder", "javax.swing.plaf.ColorUIResource", "$.FontUIResource", "jssun.swing.DefaultLookup"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.tree = null;
5 this.selected = false;
6 this.$hasFocus = false;
7 this.drawsFocusBorderAroundIcon = false;
8 this.drawDashedFocusIndicator = false;
9 this.treeBGColor = null;
10 this.focusBGColor = null;
11 this.closedIcon = null;
12 this.leafIcon = null;
13 this.openIcon = null;
14 this.textSelectionColor = null;
15 this.textNonSelectionColor = null;
16 this.backgroundSelectionColor = null;
17 this.backgroundNonSelectionColor = null;
18 this.borderSelectionColor = null;
19 this.isDropCell = false;
20 this.fillBackground = true;
21 Clazz.instantialize (this, arguments);
22 }, javax.swing.tree, "DefaultTreeCellRenderer", javax.swing.JLabel, javax.swing.tree.TreeCellRenderer);
23 Clazz.makeConstructor (c$, 
24 function () {
25 Clazz.superConstructor (this, javax.swing.tree.DefaultTreeCellRenderer, []);
26 this.setLeafIcon (jssun.swing.DefaultLookup.getIcon (this, this.ui, "Tree.leafIcon"));
27 this.setClosedIcon (jssun.swing.DefaultLookup.getIcon (this, this.ui, "Tree.closedIcon"));
28 this.setOpenIcon (jssun.swing.DefaultLookup.getIcon (this, this.ui, "Tree.openIcon"));
29 this.setTextSelectionColor (jssun.swing.DefaultLookup.getColor (this, this.ui, "Tree.selectionForeground"));
30 this.setTextNonSelectionColor (jssun.swing.DefaultLookup.getColor (this, this.ui, "Tree.textForeground"));
31 this.setBackgroundSelectionColor (jssun.swing.DefaultLookup.getColor (this, this.ui, "Tree.selectionBackground"));
32 this.setBackgroundNonSelectionColor (jssun.swing.DefaultLookup.getColor (this, this.ui, "Tree.textBackground"));
33 this.setBorderSelectionColor (jssun.swing.DefaultLookup.getColor (this, this.ui, "Tree.selectionBorderColor"));
34 this.drawsFocusBorderAroundIcon = jssun.swing.DefaultLookup.getBoolean (this, this.ui, "Tree.drawsFocusBorderAroundIcon", false);
35 this.drawDashedFocusIndicator = jssun.swing.DefaultLookup.getBoolean (this, this.ui, "Tree.drawDashedFocusIndicator", false);
36 this.fillBackground = jssun.swing.DefaultLookup.getBoolean (this, this.ui, "Tree.rendererFillBackground", true);
37 var margins = jssun.swing.DefaultLookup.getInsets (this, this.ui, "Tree.rendererMargins");
38 if (margins != null) {
39 this.setBorder ( new javax.swing.border.EmptyBorder (margins.top, margins.left, margins.bottom, margins.right));
40 }this.setName ("Tree.cellRenderer");
41 });
42 Clazz.defineMethod (c$, "getDefaultOpenIcon", 
43 function () {
44 return jssun.swing.DefaultLookup.getIcon (this, this.ui, "Tree.openIcon");
45 });
46 Clazz.defineMethod (c$, "getDefaultClosedIcon", 
47 function () {
48 return jssun.swing.DefaultLookup.getIcon (this, this.ui, "Tree.closedIcon");
49 });
50 Clazz.defineMethod (c$, "getDefaultLeafIcon", 
51 function () {
52 return jssun.swing.DefaultLookup.getIcon (this, this.ui, "Tree.leafIcon");
53 });
54 Clazz.defineMethod (c$, "setOpenIcon", 
55 function (newIcon) {
56 this.openIcon = newIcon;
57 }, "javax.swing.Icon");
58 Clazz.defineMethod (c$, "getOpenIcon", 
59 function () {
60 return this.openIcon;
61 });
62 Clazz.defineMethod (c$, "setClosedIcon", 
63 function (newIcon) {
64 this.closedIcon = newIcon;
65 }, "javax.swing.Icon");
66 Clazz.defineMethod (c$, "getClosedIcon", 
67 function () {
68 return this.closedIcon;
69 });
70 Clazz.defineMethod (c$, "setLeafIcon", 
71 function (newIcon) {
72 this.leafIcon = newIcon;
73 }, "javax.swing.Icon");
74 Clazz.defineMethod (c$, "getLeafIcon", 
75 function () {
76 return this.leafIcon;
77 });
78 Clazz.defineMethod (c$, "setTextSelectionColor", 
79 function (newColor) {
80 this.textSelectionColor = newColor;
81 }, "java.awt.Color");
82 Clazz.defineMethod (c$, "getTextSelectionColor", 
83 function () {
84 return this.textSelectionColor;
85 });
86 Clazz.defineMethod (c$, "setTextNonSelectionColor", 
87 function (newColor) {
88 this.textNonSelectionColor = newColor;
89 }, "java.awt.Color");
90 Clazz.defineMethod (c$, "getTextNonSelectionColor", 
91 function () {
92 return this.textNonSelectionColor;
93 });
94 Clazz.defineMethod (c$, "setBackgroundSelectionColor", 
95 function (newColor) {
96 this.backgroundSelectionColor = newColor;
97 }, "java.awt.Color");
98 Clazz.defineMethod (c$, "getBackgroundSelectionColor", 
99 function () {
100 return this.backgroundSelectionColor;
101 });
102 Clazz.defineMethod (c$, "setBackgroundNonSelectionColor", 
103 function (newColor) {
104 this.backgroundNonSelectionColor = newColor;
105 }, "java.awt.Color");
106 Clazz.defineMethod (c$, "getBackgroundNonSelectionColor", 
107 function () {
108 return this.backgroundNonSelectionColor;
109 });
110 Clazz.defineMethod (c$, "setBorderSelectionColor", 
111 function (newColor) {
112 this.borderSelectionColor = newColor;
113 }, "java.awt.Color");
114 Clazz.defineMethod (c$, "getBorderSelectionColor", 
115 function () {
116 return this.borderSelectionColor;
117 });
118 Clazz.defineMethod (c$, "setFont", 
119 function (font) {
120 if (Clazz.instanceOf (font, javax.swing.plaf.FontUIResource)) font = null;
121 Clazz.superCall (this, javax.swing.tree.DefaultTreeCellRenderer, "setFont", [font]);
122 }, "java.awt.Font");
123 Clazz.defineMethod (c$, "getFont", 
124 function () {
125 var font = Clazz.superCall (this, javax.swing.tree.DefaultTreeCellRenderer, "getFont", []);
126 if (font == null && this.tree != null) {
127 font = this.tree.getFont ();
128 }return font;
129 });
130 Clazz.defineMethod (c$, "setBackground", 
131 function (color) {
132 if (Clazz.instanceOf (color, javax.swing.plaf.ColorUIResource)) color = null;
133 Clazz.superCall (this, javax.swing.tree.DefaultTreeCellRenderer, "setBackground", [color]);
134 }, "java.awt.Color");
135 Clazz.overrideMethod (c$, "getTreeCellRendererComponent", 
136 function (tree, value, sel, expanded, leaf, row, hasFocus) {
137 var stringValue = tree.convertValueToText (value, sel, expanded, leaf, row, hasFocus);
138 this.tree = tree;
139 this.$hasFocus = hasFocus;
140 this.setText (stringValue);
141 var fg = null;
142 this.isDropCell = false;
143 if (sel) {
144 fg = this.getTextSelectionColor ();
145 } else {
146 fg = this.getTextNonSelectionColor ();
147 }this.setForeground (fg);
148 var icon = null;
149 if (leaf) {
150 icon = this.getLeafIcon ();
151 } else if (expanded) {
152 icon = this.getOpenIcon ();
153 } else {
154 icon = this.getClosedIcon ();
155 }if (!tree.isEnabled ()) {
156 this.setEnabled (false);
157 this.setDisabledIcon (icon);
158 } else {
159 this.setEnabled (true);
160 this.setIcon (icon);
161 }this.setComponentOrientation (tree.getComponentOrientation ());
162 this.selected = sel;
163 return this;
164 }, "javax.swing.JTree,~O,~B,~B,~B,~N,~B");
165 Clazz.defineMethod (c$, "paint", 
166 function (g) {
167 var bColor;
168 if (this.isDropCell) {
169 bColor = jssun.swing.DefaultLookup.getColor (this, this.ui, "Tree.dropCellBackground");
170 if (bColor == null) {
171 bColor = this.getBackgroundSelectionColor ();
172 }} else if (this.selected) {
173 bColor = this.getBackgroundSelectionColor ();
174 } else {
175 bColor = this.getBackgroundNonSelectionColor ();
176 if (bColor == null) {
177 bColor = this.getBackground ();
178 }}var imageOffset = -1;
179 if (bColor != null && this.fillBackground) {
180 imageOffset = this.getLabelStart ();
181 g.setColor (bColor);
182 if (this.getComponentOrientation ().isLeftToRight ()) {
183 g.fillRect (imageOffset, 0, this.getWidth () - imageOffset, this.getHeight ());
184 } else {
185 g.fillRect (0, 0, this.getWidth () - imageOffset, this.getHeight ());
186 }}if (this.$hasFocus) {
187 if (this.drawsFocusBorderAroundIcon) {
188 imageOffset = 0;
189 } else if (imageOffset == -1) {
190 imageOffset = this.getLabelStart ();
191 }if (this.getComponentOrientation ().isLeftToRight ()) {
192 this.paintFocus (g, imageOffset, 0, this.getWidth () - imageOffset, this.getHeight (), bColor);
193 } else {
194 this.paintFocus (g, 0, 0, this.getWidth () - imageOffset, this.getHeight (), bColor);
195 }}Clazz.superCall (this, javax.swing.tree.DefaultTreeCellRenderer, "paint", [g]);
196 }, "java.awt.Graphics");
197 Clazz.defineMethod (c$, "paintFocus", 
198  function (g, x, y, w, h, notColor) {
199 var bsColor = this.getBorderSelectionColor ();
200 if (bsColor != null && (this.selected || !this.drawDashedFocusIndicator)) {
201 g.setColor (bsColor);
202 g.drawRect (x, y, w - 1, h - 1);
203 }}, "java.awt.Graphics,~N,~N,~N,~N,java.awt.Color");
204 Clazz.defineMethod (c$, "getLabelStart", 
205  function () {
206 var currentI = this.getIcon ();
207 if (currentI != null && this.getText () != null) {
208 return currentI.getIconWidth () + Math.max (0, this.getIconTextGap () - 1);
209 }return 0;
210 });
211 Clazz.overrideMethod (c$, "getPreferredSize", 
212 function () {
213 var retDimension = this.getPrefSizeJComp ();
214 return (retDimension == null ? null :  new java.awt.Dimension (retDimension.width + 3, retDimension.height));
215 });
216 Clazz.overrideMethod (c$, "validate", 
217 function () {
218 });
219 Clazz.overrideMethod (c$, "invalidate", 
220 function () {
221 });
222 Clazz.overrideMethod (c$, "revalidate", 
223 function () {
224 });
225 Clazz.defineMethod (c$, "repaint", 
226 function (tm, x, y, width, height) {
227 }, "~N,~N,~N,~N,~N");
228 Clazz.defineMethod (c$, "repaint", 
229 function (r) {
230 }, "java.awt.Rectangle");
231 Clazz.defineMethod (c$, "repaint", 
232 function () {
233 });
234 Clazz.overrideMethod (c$, "firePropertyChangeObject", 
235 function (propertyName, oldValue, newValue) {
236 }, "~S,~O,~O");
237 Clazz.defineMethod (c$, "firePropertyChange", 
238 function (propertyName, oldValue, newValue) {
239 }, "~S,~N,~N");
240 Clazz.defineMethod (c$, "firePropertyChange", 
241 function (propertyName, oldValue, newValue) {
242 }, "~S,~S,~S");
243 Clazz.defineMethod (c$, "firePropertyChange", 
244 function (propertyName, oldValue, newValue) {
245 }, "~S,~N,~N");
246 Clazz.overrideMethod (c$, "firePropertyChangeInt", 
247 function (propertyName, oldValue, newValue) {
248 }, "~S,~N,~N");
249 Clazz.defineMethod (c$, "firePropertyChange", 
250 function (propertyName, oldValue, newValue) {
251 }, "~S,~N,~N");
252 Clazz.defineMethod (c$, "firePropertyChange", 
253 function (propertyName, oldValue, newValue) {
254 }, "~S,~N,~N");
255 Clazz.defineMethod (c$, "firePropertyChange", 
256 function (propertyName, oldValue, newValue) {
257 }, "~S,~N,~N");
258 Clazz.overrideMethod (c$, "firePropertyChangeBool", 
259 function (propertyName, oldValue, newValue) {
260 }, "~S,~B,~B");
261 });