07c921b78053b8ba7ca3fdf34b85c9511943b507
[jalviewjs.git] / site / swingjs / j2s / javax / swing / JLabel.js
1 Clazz.declarePackage ("javax.swing");
2 Clazz.load (["javax.swing.JComponent", "$.SwingConstants"], "javax.swing.JLabel", ["java.lang.IllegalArgumentException", "javax.swing.SwingUtilities", "$.UIManager"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.mnemonic = '\0';
5 this.mnemonicIndex = -1;
6 this.text = "";
7 this.defaultIcon = null;
8 this.disabledIcon = null;
9 this.disabledIconSet = false;
10 this.verticalAlignment = 0;
11 this.horizontalAlignment = 10;
12 this.verticalTextPosition = 0;
13 this.horizontalTextPosition = 11;
14 this.iconTextGap = 4;
15 this.labelFor = null;
16 Clazz.instantialize (this, arguments);
17 }, javax.swing, "JLabel", javax.swing.JComponent, javax.swing.SwingConstants);
18 Clazz.makeConstructor (c$, 
19 function (text, icon, horizontalAlignment) {
20 Clazz.superConstructor (this, javax.swing.JLabel, []);
21 this.setText (text);
22 this.setIcon (icon);
23 this.setHorizontalAlignment (horizontalAlignment);
24 this.updateUI ();
25 this.setAlignmentX (0.0);
26 }, "~S,javax.swing.Icon,~N");
27 Clazz.makeConstructor (c$, 
28 function (text, horizontalAlignment) {
29 this.construct (text, null, horizontalAlignment);
30 }, "~S,~N");
31 Clazz.makeConstructor (c$, 
32 function (text) {
33 this.construct (text, null, 10);
34 }, "~S");
35 Clazz.makeConstructor (c$, 
36 function (image, horizontalAlignment) {
37 this.construct (null, image, horizontalAlignment);
38 }, "javax.swing.Icon,~N");
39 Clazz.makeConstructor (c$, 
40 function (image) {
41 this.construct (null, image, 0);
42 }, "javax.swing.Icon");
43 Clazz.makeConstructor (c$, 
44 function () {
45 this.construct ("", null, 10);
46 });
47 Clazz.overrideMethod (c$, "getUI", 
48 function () {
49 return this.ui;
50 });
51 Clazz.defineMethod (c$, "setUI", 
52 function (ui) {
53 Clazz.superCall (this, javax.swing.JLabel, "setUI", [ui]);
54 if (!this.disabledIconSet && this.disabledIcon != null) {
55 this.setDisabledIcon (null);
56 }}, "javax.swing.plaf.LabelUI");
57 Clazz.overrideMethod (c$, "updateUI", 
58 function () {
59 this.setUI (javax.swing.UIManager.getUI (this));
60 });
61 Clazz.overrideMethod (c$, "getUIClassID", 
62 function () {
63 return "LabelUI";
64 });
65 Clazz.defineMethod (c$, "getText", 
66 function () {
67 return this.text;
68 });
69 Clazz.defineMethod (c$, "setText", 
70 function (text) {
71 var oldValue = this.text;
72 this.text = text;
73 this.firePropertyChangeObject ("text", oldValue, text);
74 this.setDisplayedMnemonicIndex (javax.swing.SwingUtilities.findDisplayedMnemonicIndex (text, this.getDisplayedMnemonic ()));
75 if (text == null || oldValue == null || !text.equals (oldValue)) {
76 this.revalidate ();
77 this.repaint ();
78 }}, "~S");
79 Clazz.defineMethod (c$, "getIcon", 
80 function () {
81 return this.defaultIcon;
82 });
83 Clazz.defineMethod (c$, "setIcon", 
84 function (icon) {
85 var oldValue = this.defaultIcon;
86 this.defaultIcon = icon;
87 if ((this.defaultIcon !== oldValue) && !this.disabledIconSet) {
88 this.disabledIcon = null;
89 }this.firePropertyChangeObject ("icon", oldValue, this.defaultIcon);
90 if (this.defaultIcon !== oldValue) {
91 if ((this.defaultIcon == null) || (oldValue == null) || (this.defaultIcon.getIconWidth () != oldValue.getIconWidth ()) || (this.defaultIcon.getIconHeight () != oldValue.getIconHeight ())) {
92 this.revalidate ();
93 }this.repaint ();
94 }}, "javax.swing.Icon");
95 Clazz.defineMethod (c$, "getDisabledIcon", 
96 function () {
97 if (!this.disabledIconSet && this.disabledIcon == null && this.defaultIcon != null) {
98 this.disabledIcon = javax.swing.UIManager.getLookAndFeel ().getDisabledIcon (this, this.defaultIcon);
99 if (this.disabledIcon != null) {
100 this.firePropertyChangeObject ("disabledIcon", null, this.disabledIcon);
101 }}return this.disabledIcon;
102 });
103 Clazz.defineMethod (c$, "setDisabledIcon", 
104 function (disabledIcon) {
105 var oldValue = this.disabledIcon;
106 this.disabledIcon = disabledIcon;
107 this.disabledIconSet = (disabledIcon != null);
108 this.firePropertyChangeObject ("disabledIcon", oldValue, disabledIcon);
109 if (disabledIcon !== oldValue) {
110 if (disabledIcon == null || oldValue == null || disabledIcon.getIconWidth () != oldValue.getIconWidth () || disabledIcon.getIconHeight () != oldValue.getIconHeight ()) {
111 this.revalidate ();
112 }if (!this.isEnabled ()) {
113 this.repaint ();
114 }}}, "javax.swing.Icon");
115 Clazz.defineMethod (c$, "setDisplayedMnemonic", 
116 function (key) {
117 var oldKey = this.mnemonic;
118 this.mnemonic = key;
119 this.firePropertyChangeInt ("displayedMnemonic", oldKey, this.mnemonic);
120 this.setDisplayedMnemonicIndex (javax.swing.SwingUtilities.findDisplayedMnemonicIndex (this.getText (), this.mnemonic));
121 if (key != oldKey) {
122 this.revalidate ();
123 this.repaint ();
124 }}, "~N");
125 Clazz.defineMethod (c$, "setDisplayedMnemonic", 
126 function (aChar) {
127 var vk = (aChar).charCodeAt (0);
128 if (vk >= 97 && vk <= 122) vk -= (32);
129 this.setDisplayedMnemonic (vk);
130 }, "~S");
131 Clazz.defineMethod (c$, "getDisplayedMnemonic", 
132 function () {
133 return this.mnemonic;
134 });
135 Clazz.defineMethod (c$, "setDisplayedMnemonicIndex", 
136 function (index) {
137 var oldValue = this.mnemonicIndex;
138 if (index == -1) {
139 this.mnemonicIndex = -1;
140 } else {
141 var text = this.getText ();
142 var textLength = (text == null) ? 0 : text.length;
143 if (index < -1 || index >= textLength) {
144 throw  new IllegalArgumentException ("index == " + index);
145 }}this.mnemonicIndex = index;
146 this.firePropertyChangeInt ("displayedMnemonicIndex", oldValue, index);
147 if (index != oldValue) {
148 this.revalidate ();
149 this.repaint ();
150 }}, "~N");
151 Clazz.defineMethod (c$, "getDisplayedMnemonicIndex", 
152 function () {
153 return this.mnemonicIndex;
154 });
155 Clazz.defineMethod (c$, "checkHorizontalKey", 
156 function (key, message) {
157 if ((key == 2) || (key == 0) || (key == 4) || (key == 10) || (key == 11)) {
158 return key;
159 } else {
160 throw  new IllegalArgumentException (message);
161 }}, "~N,~S");
162 Clazz.defineMethod (c$, "checkVerticalKey", 
163 function (key, message) {
164 if ((key == 1) || (key == 0) || (key == 3)) {
165 return key;
166 } else {
167 throw  new IllegalArgumentException (message);
168 }}, "~N,~S");
169 Clazz.defineMethod (c$, "getIconTextGap", 
170 function () {
171 return this.iconTextGap;
172 });
173 Clazz.defineMethod (c$, "setIconTextGap", 
174 function (iconTextGap) {
175 var oldValue = this.iconTextGap;
176 this.iconTextGap = iconTextGap;
177 this.firePropertyChangeInt ("iconTextGap", oldValue, iconTextGap);
178 if (iconTextGap != oldValue) {
179 this.revalidate ();
180 this.repaint ();
181 }}, "~N");
182 Clazz.defineMethod (c$, "getVerticalAlignment", 
183 function () {
184 return this.verticalAlignment;
185 });
186 Clazz.defineMethod (c$, "setVerticalAlignment", 
187 function (alignment) {
188 if (alignment == this.verticalAlignment) return;
189 var oldValue = this.verticalAlignment;
190 this.verticalAlignment = this.checkVerticalKey (alignment, "verticalAlignment");
191 this.firePropertyChangeInt ("verticalAlignment", oldValue, this.verticalAlignment);
192 this.repaint ();
193 }, "~N");
194 Clazz.defineMethod (c$, "getHorizontalAlignment", 
195 function () {
196 return this.horizontalAlignment;
197 });
198 Clazz.defineMethod (c$, "setHorizontalAlignment", 
199 function (alignment) {
200 if (alignment == this.horizontalAlignment) return;
201 var oldValue = this.horizontalAlignment;
202 this.horizontalAlignment = this.checkHorizontalKey (alignment, "horizontalAlignment");
203 this.firePropertyChangeInt ("horizontalAlignment", oldValue, this.horizontalAlignment);
204 this.repaint ();
205 }, "~N");
206 Clazz.defineMethod (c$, "getVerticalTextPosition", 
207 function () {
208 return this.verticalTextPosition;
209 });
210 Clazz.defineMethod (c$, "setVerticalTextPosition", 
211 function (textPosition) {
212 if (textPosition == this.verticalTextPosition) return;
213 var old = this.verticalTextPosition;
214 this.verticalTextPosition = this.checkVerticalKey (textPosition, "verticalTextPosition");
215 this.firePropertyChangeInt ("verticalTextPosition", old, this.verticalTextPosition);
216 this.revalidate ();
217 this.repaint ();
218 }, "~N");
219 Clazz.defineMethod (c$, "getHorizontalTextPosition", 
220 function () {
221 return this.horizontalTextPosition;
222 });
223 Clazz.defineMethod (c$, "setHorizontalTextPosition", 
224 function (textPosition) {
225 var old = this.horizontalTextPosition;
226 this.horizontalTextPosition = this.checkHorizontalKey (textPosition, "horizontalTextPosition");
227 this.firePropertyChangeInt ("horizontalTextPosition", old, this.horizontalTextPosition);
228 this.revalidate ();
229 this.repaint ();
230 }, "~N");
231 Clazz.defineMethod (c$, "imageUpdate", 
232 function (img, infoflags, x, y, w, h) {
233 if (!this.isShowing () || !javax.swing.SwingUtilities.doesIconReferenceImage (this.getIcon (), img) && !javax.swing.SwingUtilities.doesIconReferenceImage (this.disabledIcon, img)) {
234 return false;
235 }return Clazz.superCall (this, javax.swing.JLabel, "imageUpdate", [img, infoflags, x, y, w, h]);
236 }, "java.awt.Image,~N,~N,~N,~N,~N");
237 Clazz.defineMethod (c$, "paramString", 
238 function () {
239 var textString = (this.text != null ? this.text : "");
240 var defaultIconString = ((this.defaultIcon != null) && (this.defaultIcon !== this) ? this.defaultIcon.toString () : "");
241 var disabledIconString = ((this.disabledIcon != null) && (this.disabledIcon !== this) ? this.disabledIcon.toString () : "");
242 var labelForString = (this.labelFor != null ? this.labelFor.toString () : "");
243 var verticalAlignmentString;
244 if (this.verticalAlignment == 1) {
245 verticalAlignmentString = "TOP";
246 } else if (this.verticalAlignment == 0) {
247 verticalAlignmentString = "CENTER";
248 } else if (this.verticalAlignment == 3) {
249 verticalAlignmentString = "BOTTOM";
250 } else verticalAlignmentString = "";
251 var horizontalAlignmentString;
252 if (this.horizontalAlignment == 2) {
253 horizontalAlignmentString = "LEFT";
254 } else if (this.horizontalAlignment == 0) {
255 horizontalAlignmentString = "CENTER";
256 } else if (this.horizontalAlignment == 4) {
257 horizontalAlignmentString = "RIGHT";
258 } else if (this.horizontalAlignment == 10) {
259 horizontalAlignmentString = "LEADING";
260 } else if (this.horizontalAlignment == 11) {
261 horizontalAlignmentString = "TRAILING";
262 } else horizontalAlignmentString = "";
263 var verticalTextPositionString;
264 if (this.verticalTextPosition == 1) {
265 verticalTextPositionString = "TOP";
266 } else if (this.verticalTextPosition == 0) {
267 verticalTextPositionString = "CENTER";
268 } else if (this.verticalTextPosition == 3) {
269 verticalTextPositionString = "BOTTOM";
270 } else verticalTextPositionString = "";
271 var horizontalTextPositionString;
272 if (this.horizontalTextPosition == 2) {
273 horizontalTextPositionString = "LEFT";
274 } else if (this.horizontalTextPosition == 0) {
275 horizontalTextPositionString = "CENTER";
276 } else if (this.horizontalTextPosition == 4) {
277 horizontalTextPositionString = "RIGHT";
278 } else if (this.horizontalTextPosition == 10) {
279 horizontalTextPositionString = "LEADING";
280 } else if (this.horizontalTextPosition == 11) {
281 horizontalTextPositionString = "TRAILING";
282 } else horizontalTextPositionString = "";
283 return Clazz.superCall (this, javax.swing.JLabel, "paramString", []) + ",defaultIcon=" + defaultIconString + ",disabledIcon=" + disabledIconString + ",horizontalAlignment=" + horizontalAlignmentString + ",horizontalTextPosition=" + horizontalTextPositionString + ",iconTextGap=" + this.iconTextGap + ",labelFor=" + labelForString + ",text=" + textString + ",verticalAlignment=" + verticalAlignmentString + ",verticalTextPosition=" + verticalTextPositionString;
284 });
285 Clazz.defineMethod (c$, "getLabelFor", 
286 function () {
287 return this.labelFor;
288 });
289 Clazz.defineMethod (c$, "setLabelFor", 
290 function (c) {
291 var oldC = this.labelFor;
292 this.labelFor = c;
293 this.firePropertyChangeObject ("labelFor", oldC, c);
294 if (Clazz.instanceOf (oldC, javax.swing.JComponent)) {
295 (oldC).putClientProperty ("labeledBy", null);
296 }if (Clazz.instanceOf (c, javax.swing.JComponent)) {
297 (c).putClientProperty ("labeledBy", this);
298 }}, "java.awt.Component");
299 Clazz.defineStatics (c$,
300 "$uiClassID", "LabelUI",
301 "LABELED_BY_PROPERTY", "labeledBy");
302 });