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