1 |
/******************************************************************************* |
= |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
|
2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
|
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
|
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
|
7 |
* |
8 |
* Contributors: |
|
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
|
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
|
10 |
*******************************************************************************/ |
|
|
<> |
11 |
|
|
|
|
12 |
/******************************************************************************* |
|
|
|
13 |
* Additions/modifications to this source file by Oracle America, Inc. 2011 |
|
|
|
14 |
*******************************************************************************/ |
|
|
|
15 |
|
11 |
package org.eclipse.swt.widgets; |
= |
16 |
package org.eclipse.swt.widgets; |
12 |
|
|
17 |
|
13 |
|
<> |
18 |
|
|
|
|
19 |
import com.ibm.ugl.eswt.OS; |
|
|
|
20 |
|
14 |
import org.eclipse.swt.SWT; |
= |
21 |
import org.eclipse.swt.SWT; |
15 |
import org.eclipse.swt.graphics.Image; |
|
22 |
import org.eclipse.swt.graphics.Image; |
16 |
import org.eclipse.swt.graphics.Point; |
|
23 |
import org.eclipse.swt.graphics.Point; |
17 |
|
|
24 |
|
18 |
import com.ibm.ugl.eswt.OS; |
+- |
|
|
19 |
|
= |
25 |
|
20 |
/** |
|
26 |
/** |
21 |
* Instances of this class represent a non-selectable |
|
27 |
* Instances of this class represent a non-selectable |
22 |
* user interface object that displays a string or image. |
|
28 |
* user interface object that displays a string or image. |
23 |
* When SEPARATOR is specified, displays a single |
|
29 |
* When SEPARATOR is specified, displays a single |
24 |
* vertical or horizontal line. |
|
30 |
* vertical or horizontal line. |
25 |
* <dl> |
|
31 |
* <dl> |
26 |
* <dt><b>Styles:</b></dt> |
|
32 |
* <dt><b>Styles:</b></dt> |
27 |
* <dd>SEPARATOR, HORIZONTAL, VERTICAL</dd> |
|
33 |
* <dd>SEPARATOR, HORIZONTAL, VERTICAL</dd> |
28 |
* <dd>SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd> |
|
34 |
* <dd>SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd> |
29 |
* <dd>CENTER, LEFT, RIGHT, WRAP</dd> |
|
35 |
* <dd>CENTER, LEFT, RIGHT, WRAP</dd> |
30 |
* <dt><b>Events:</b></dt> |
|
36 |
* <dt><b>Events:</b></dt> |
31 |
* <dd>(none)</dd> |
|
37 |
* <dd>(none)</dd> |
32 |
* </dl> |
|
38 |
* </dl> |
33 |
* <p> |
|
39 |
* <p> |
34 |
* Note: Only one of SHADOW_IN, SHADOW_OUT and SHADOW_NONE may be specified. |
|
40 |
* Note: Only one of SHADOW_IN, SHADOW_OUT and SHADOW_NONE may be specified. |
35 |
* SHADOW_NONE is a HINT. Only one of HORIZONTAL and VERTICAL may be specified. |
|
41 |
* SHADOW_NONE is a HINT. Only one of HORIZONTAL and VERTICAL may be specified. |
36 |
* Only one of CENTER, LEFT and RIGHT may be specified. |
|
42 |
* Only one of CENTER, LEFT and RIGHT may be specified. |
37 |
* </p><p> |
|
43 |
* </p><p> |
38 |
* IMPORTANT: This class is intended to be subclassed <em>only</em> |
|
44 |
* IMPORTANT: This class is intended to be subclassed <em>only</em> |
39 |
* within the SWT implementation. |
|
45 |
* within the SWT implementation. |
40 |
* </p> |
|
46 |
* </p> |
41 |
*/ |
|
47 |
*/ |
42 |
|
|
48 |
|
43 |
public class Label extends Control { |
|
49 |
public class Label extends Control { |
44 |
|
|
50 |
|
45 |
private Image image; |
|
51 |
private Image image; |
46 |
private String text; |
|
52 |
private String text; |
47 |
|
|
53 |
|
48 |
/** |
|
54 |
/** |
49 |
* Constructs a new instance of this class given its parent |
|
55 |
* Constructs a new instance of this class given its parent |
50 |
* and a style value describing its behavior and appearance. |
|
56 |
* and a style value describing its behavior and appearance. |
51 |
* <p> |
|
57 |
* <p> |
52 |
* The style value is either one of the style constants defined in |
|
58 |
* The style value is either one of the style constants defined in |
53 |
* class <code>SWT</code> which is applicable to instances of this |
|
59 |
* class <code>SWT</code> which is applicable to instances of this |
54 |
* class, or must be built by <em>bitwise OR</em>'ing together |
|
60 |
* class, or must be built by <em>bitwise OR</em>'ing together |
55 |
* (that is, using the <code>int</code> "|" operator) two or more |
|
61 |
* (that is, using the <code>int</code> "|" operator) two or more |
56 |
* of those <code>SWT</code> style constants. The class description |
|
62 |
* of those <code>SWT</code> style constants. The class description |
57 |
* lists the style constants that are applicable to the class. |
|
63 |
* lists the style constants that are applicable to the class. |
58 |
* Style bits are also inherited from superclasses. |
|
64 |
* Style bits are also inherited from superclasses. |
59 |
* </p> |
|
65 |
* </p> |
60 |
* |
|
66 |
* |
61 |
* @param parent a composite control which will be the parent of the new instance (cannot be null) |
|
67 |
* @param parent a composite control which will be the parent of the new instance (cannot be null) |
62 |
* @param style the style of control to construct |
|
68 |
* @param style the style of control to construct |
63 |
* |
|
69 |
* |
64 |
* @exception IllegalArgumentException <ul> |
|
70 |
* @exception IllegalArgumentException <ul> |
65 |
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li> |
|
71 |
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li> |
66 |
* </ul> |
|
72 |
* </ul> |
67 |
* @exception SWTException <ul> |
|
73 |
* @exception SWTException <ul> |
68 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
|
74 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
69 |
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> |
|
75 |
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> |
70 |
* </ul> |
|
76 |
* </ul> |
71 |
* |
|
77 |
* |
72 |
* @see SWT#SEPARATOR |
|
78 |
* @see SWT#SEPARATOR |
73 |
* @see SWT#HORIZONTAL |
|
79 |
* @see SWT#HORIZONTAL |
74 |
* @see SWT#VERTICAL |
|
80 |
* @see SWT#VERTICAL |
75 |
* @see SWT#SHADOW_IN |
|
81 |
* @see SWT#SHADOW_IN |
76 |
* @see SWT#SHADOW_OUT |
|
82 |
* @see SWT#SHADOW_OUT |
77 |
* @see SWT#SHADOW_NONE |
|
83 |
* @see SWT#SHADOW_NONE |
78 |
* @see SWT#CENTER |
|
84 |
* @see SWT#CENTER |
79 |
* @see SWT#LEFT |
|
85 |
* @see SWT#LEFT |
80 |
* @see SWT#RIGHT |
|
86 |
* @see SWT#RIGHT |
81 |
* @see SWT#WRAP |
|
87 |
* @see SWT#WRAP |
82 |
* @see Widget#checkSubclass |
|
88 |
* @see Widget#checkSubclass |
83 |
* @see Widget#getStyle |
|
89 |
* @see Widget#getStyle |
84 |
*/ |
|
90 |
*/ |
85 |
public Label(Composite parent, int style) { |
|
91 |
public Label(Composite parent, int style) { |
86 |
super(parent, checkStyle(style)); |
|
92 |
super(parent, checkStyle(style)); |
87 |
text = ""; |
|
93 |
text = ""; |
88 |
} |
|
94 |
} |
89 |
|
|
95 |
|
90 |
static int checkStyle(int style) { |
|
96 |
static int checkStyle(int style) { |
91 |
if ((style & SWT.SEPARATOR) != 0) { |
|
97 |
if ((style & SWT.SEPARATOR) != 0) { |
92 |
style = checkBits (style, SWT.VERTICAL, SWT.HORIZONTAL, 0, 0, 0, 0); |
|
98 |
style = checkBits (style, SWT.VERTICAL, SWT.HORIZONTAL, 0, 0, 0, 0); |
93 |
return checkBits (style, SWT.SHADOW_OUT, SWT.SHADOW_IN, SWT.SHADOW_NONE, 0, 0, 0); |
|
99 |
return checkBits (style, SWT.SHADOW_OUT, SWT.SHADOW_IN, SWT.SHADOW_NONE, 0, 0, 0); |
94 |
} |
|
100 |
} |
95 |
return checkBits(style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0); |
|
101 |
return checkBits(style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0); |
96 |
} |
|
102 |
} |
97 |
|
|
103 |
|
98 |
protected int internal_getNativeStyle(){ |
|
104 |
protected int internal_getNativeStyle(){ |
99 |
|
|
105 |
|
100 |
int nativeStyle = super.internal_getNativeStyle(); |
|
106 |
int nativeStyle = super.internal_getNativeStyle(); |
101 |
|
|
107 |
|
102 |
if ((internal_style & SWT.SEPARATOR) != 0) { |
|
108 |
if ((internal_style & SWT.SEPARATOR) != 0) { |
103 |
|
|
109 |
|
104 |
// SWT.VERTICAL, SWT.HORIZONTAL |
|
110 |
// SWT.VERTICAL, SWT.HORIZONTAL |
105 |
if ((internal_style & SWT.VERTICAL) != 0) { |
|
111 |
if ((internal_style & SWT.VERTICAL) != 0) { |
106 |
nativeStyle |= OS.STYLE_VERTICAL; |
|
112 |
nativeStyle |= OS.STYLE_VERTICAL; |
107 |
} |
|
113 |
} |
108 |
else if ((internal_style & SWT.HORIZONTAL) != 0) { |
|
114 |
else if ((internal_style & SWT.HORIZONTAL) != 0) { |
109 |
nativeStyle |= OS.STYLE_HORIZONTAL; |
|
115 |
nativeStyle |= OS.STYLE_HORIZONTAL; |
110 |
} |
|
116 |
} |
111 |
|
|
117 |
|
112 |
// SWT.SHADOW_OUT, SWT.SHADOW_IN, SWT.SHADOW_NONE |
|
118 |
// SWT.SHADOW_OUT, SWT.SHADOW_IN, SWT.SHADOW_NONE |
113 |
if ((internal_style & SWT.SHADOW_IN) != 0) { |
|
119 |
if ((internal_style & SWT.SHADOW_IN) != 0) { |
114 |
nativeStyle |= OS.STYLE_SHADOW_IN; |
|
120 |
nativeStyle |= OS.STYLE_SHADOW_IN; |
115 |
} |
|
121 |
} |
116 |
else if ((internal_style & SWT.SHADOW_OUT) != 0) { |
|
122 |
else if ((internal_style & SWT.SHADOW_OUT) != 0) { |
117 |
nativeStyle |= OS.STYLE_SHADOW_OUT; |
|
123 |
nativeStyle |= OS.STYLE_SHADOW_OUT; |
118 |
} |
|
124 |
} |
119 |
else if ((internal_style & SWT.SHADOW_NONE) != 0) { |
|
125 |
else if ((internal_style & SWT.SHADOW_NONE) != 0) { |
120 |
nativeStyle |= OS.STYLE_SHADOW_NONE; |
|
126 |
nativeStyle |= OS.STYLE_SHADOW_NONE; |
121 |
} |
|
127 |
} |
122 |
|
|
128 |
|
123 |
} |
|
129 |
} |
124 |
else { |
|
130 |
else { |
125 |
|
|
131 |
|
126 |
// Always top-align label text. |
|
132 |
// Always top-align label text. |
127 |
nativeStyle |= OS.STYLE_TOP; |
|
133 |
nativeStyle |= OS.STYLE_TOP; |
128 |
|
|
134 |
|
129 |
// SWT.WRAP |
|
135 |
// SWT.WRAP |
130 |
if ((internal_style & SWT.WRAP) != 0) { |
|
136 |
if ((internal_style & SWT.WRAP) != 0) { |
131 |
nativeStyle |= OS.STYLE_WRAP; |
|
137 |
nativeStyle |= OS.STYLE_WRAP; |
132 |
} |
|
138 |
} |
133 |
|
|
139 |
|
134 |
} |
|
140 |
} |
135 |
return nativeStyle; |
|
141 |
return nativeStyle; |
136 |
|
|
142 |
|
137 |
} |
|
143 |
} |
138 |
|
|
144 |
|
139 |
protected void internal_createHandle(int index) { |
|
145 |
protected void internal_createHandle(int index) { |
140 |
|
|
146 |
|
141 |
int nativeStyle = internal_getNativeStyle(); |
|
147 |
int nativeStyle = internal_getNativeStyle(); |
142 |
|
|
148 |
|
143 |
if ((internal_style & SWT.SEPARATOR) != 0) { |
|
149 |
if ((internal_style & SWT.SEPARATOR) != 0) { |
144 |
|
|
150 |
|
145 |
internal_handle = OS.Separator_New(internal_parent.internal_handle,nativeStyle); |
|
151 |
internal_handle = OS.Separator_New(internal_parent.internal_handle,nativeStyle); |
146 |
} |
|
152 |
} |
147 |
else { |
|
153 |
else { |
148 |
|
|
154 |
|
149 |
internal_handle = OS.Label_New(internal_parent.internal_handle,nativeStyle); |
|
155 |
internal_handle = OS.Label_New(internal_parent.internal_handle,nativeStyle); |
150 |
|
|
156 |
|
151 |
// SWT.LEFT, SWT.CENTER, SWT.RIGHT |
|
157 |
// SWT.LEFT, SWT.CENTER, SWT.RIGHT |
152 |
setNativeAlignment(); |
|
158 |
setNativeAlignment(); |
153 |
} |
|
159 |
} |
154 |
} |
|
160 |
} |
155 |
|
|
161 |
|
156 |
/* (non-Javadoc) |
|
162 |
/* (non-Javadoc) |
157 |
* @see org.eclipse.swt.widgets.Control#computeSize(int, int, boolean) |
|
163 |
* @see org.eclipse.swt.widgets.Control#computeSize(int, int, boolean) |
158 |
*/ |
|
164 |
*/ |
159 |
public Point computeSize(int wHint, int hHint, boolean changed) { |
|
165 |
public Point computeSize(int wHint, int hHint, boolean changed) { |
160 |
if ((wHint != SWT.DEFAULT) && ((internal_style & SWT.WRAP) == SWT.WRAP)) { |
|
166 |
if ((wHint != SWT.DEFAULT) && ((internal_style & SWT.WRAP) == SWT.WRAP)) { |
161 |
checkWidget(); |
|
167 |
checkWidget(); |
|
|
-+ |
168 |
if (getDisplay().getDPI().x > 96) |
|
|
|
169 |
wHint -= 2; |
162 |
int[] pointArray = OS.Label_GetMinimumSize(internal_handle, wHint); |
= |
170 |
int[] pointArray = OS.Label_GetMinimumSize(internal_handle, wHint); |
|
|
-+ |
171 |
if (pointArray[OS.INDEX_X] > 0 && getDisplay().getDPI().x > 96) |
|
|
|
172 |
pointArray[OS.INDEX_X] += 2; |
163 |
return new Point(pointArray[OS.INDEX_X],pointArray[OS.INDEX_Y]); |
= |
173 |
return new Point(pointArray[OS.INDEX_X],pointArray[OS.INDEX_Y]); |
164 |
} else { |
|
174 |
} else { |
165 |
return super.computeSize(wHint, hHint, changed); |
<> |
175 |
Point size = super.computeSize(wHint, hHint, changed); |
|
|
|
176 |
if (size.x > 0) |
|
|
|
177 |
size.x += 2; |
|
|
|
178 |
return size; |
166 |
} |
= |
179 |
} |
167 |
} |
|
180 |
} |
168 |
|
|
181 |
|
169 |
/** |
|
182 |
/** |
170 |
* Returns a value which describes the position of the |
|
183 |
* Returns a value which describes the position of the |
171 |
* text or image in the receiver. The value will be one of |
|
184 |
* text or image in the receiver. The value will be one of |
172 |
* <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code> |
|
185 |
* <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code> |
173 |
* unless the receiver is a <code>SEPARATOR</code> label, in |
|
186 |
* unless the receiver is a <code>SEPARATOR</code> label, in |
174 |
* which case, <code>NONE</code> is returned. |
|
187 |
* which case, <code>NONE</code> is returned. |
175 |
* |
|
188 |
* |
176 |
* @return the alignment |
|
189 |
* @return the alignment |
177 |
* |
|
190 |
* |
178 |
* @exception SWTException <ul> |
|
191 |
* @exception SWTException <ul> |
179 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|
192 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
180 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|
193 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
181 |
* </ul> |
|
194 |
* </ul> |
182 |
*/ |
|
195 |
*/ |
183 |
public int getAlignment() { |
|
196 |
public int getAlignment() { |
184 |
checkWidget(); |
|
197 |
checkWidget(); |
185 |
if ((internal_style & SWT.SEPARATOR) != 0) return SWT.NONE; |
|
198 |
if ((internal_style & SWT.SEPARATOR) != 0) return SWT.NONE; |
186 |
return (internal_style & (SWT.LEFT | SWT.CENTER | SWT.RIGHT)); |
|
199 |
return (internal_style & (SWT.LEFT | SWT.CENTER | SWT.RIGHT)); |
187 |
} |
|
200 |
} |
188 |
|
|
201 |
|
189 |
/** |
|
202 |
/** |
190 |
* Returns the receiver's image if it has one, or null |
|
203 |
* Returns the receiver's image if it has one, or null |
191 |
* if it does not. |
|
204 |
* if it does not. |
192 |
* |
|
205 |
* |
193 |
* @return the receiver's image |
|
206 |
* @return the receiver's image |
194 |
* |
|
207 |
* |
195 |
* @exception SWTException <ul> |
|
208 |
* @exception SWTException <ul> |
196 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|
209 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
197 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|
210 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
198 |
* </ul> |
|
211 |
* </ul> |
199 |
*/ |
|
212 |
*/ |
200 |
public Image getImage() { |
|
213 |
public Image getImage() { |
201 |
checkWidget(); |
|
214 |
checkWidget(); |
202 |
return image; |
|
215 |
return image; |
203 |
} |
|
216 |
} |
204 |
|
|
217 |
|
205 |
/** |
|
218 |
/** |
206 |
* Returns the receiver's text, which will be an empty |
|
219 |
* Returns the receiver's text, which will be an empty |
207 |
* string if it has never been set or if the receiver is |
|
220 |
* string if it has never been set or if the receiver is |
208 |
* a <code>SEPARATOR</code> label. |
|
221 |
* a <code>SEPARATOR</code> label. |
209 |
* |
|
222 |
* |
210 |
* @return the receiver's text |
|
223 |
* @return the receiver's text |
211 |
* |
|
224 |
* |
212 |
* @exception SWTException <ul> |
|
225 |
* @exception SWTException <ul> |
213 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|
226 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
214 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|
227 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
215 |
* </ul> |
|
228 |
* </ul> |
216 |
*/ |
|
229 |
*/ |
217 |
public String getText() { |
|
230 |
public String getText() { |
218 |
checkWidget(); |
|
231 |
checkWidget(); |
219 |
if ((internal_style & SWT.SEPARATOR) != 0) return ""; |
|
232 |
if ((internal_style & SWT.SEPARATOR) != 0) return ""; |
220 |
return text; |
|
233 |
return text; |
221 |
} |
|
234 |
} |
222 |
|
|
235 |
|
223 |
void releaseWidget() { |
|
236 |
void releaseWidget() { |
224 |
super.releaseWidget(); |
|
237 |
super.releaseWidget(); |
225 |
image = null; |
|
238 |
image = null; |
226 |
} |
|
239 |
} |
227 |
|
|
240 |
|
228 |
/** |
|
241 |
/** |
229 |
* Controls how text and images will be displayed in the receiver. |
|
242 |
* Controls how text and images will be displayed in the receiver. |
230 |
* The argument should be one of <code>LEFT</code>, <code>RIGHT</code> |
|
243 |
* The argument should be one of <code>LEFT</code>, <code>RIGHT</code> |
231 |
* or <code>CENTER</code>. If the receiver is a <code>SEPARATOR</code> |
|
244 |
* or <code>CENTER</code>. If the receiver is a <code>SEPARATOR</code> |
232 |
* label, the argument is ignored and the alignment is not changed. |
|
245 |
* label, the argument is ignored and the alignment is not changed. |
233 |
* |
|
246 |
* |
234 |
* @param alignment the new alignment |
|
247 |
* @param alignment the new alignment |
235 |
* |
|
248 |
* |
236 |
* @exception SWTException <ul> |
|
249 |
* @exception SWTException <ul> |
237 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|
250 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
238 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|
251 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
239 |
* </ul> |
|
252 |
* </ul> |
240 |
*/ |
|
253 |
*/ |
241 |
public void setAlignment(int alignment) { |
|
254 |
public void setAlignment(int alignment) { |
242 |
checkWidget(); |
|
255 |
checkWidget(); |
243 |
if ((internal_style & SWT.SEPARATOR) != 0) return; |
|
256 |
if ((internal_style & SWT.SEPARATOR) != 0) return; |
244 |
if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return; |
|
257 |
if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return; |
245 |
internal_style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER); |
|
258 |
internal_style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER); |
246 |
internal_style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER); |
|
259 |
internal_style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER); |
247 |
setNativeAlignment(); |
|
260 |
setNativeAlignment(); |
248 |
} |
|
261 |
} |
249 |
|
|
262 |
|
250 |
private void setNativeAlignment() { |
|
263 |
private void setNativeAlignment() { |
251 |
int alignment = OS.STYLE_LEAD; |
|
264 |
int alignment = OS.STYLE_LEAD; |
252 |
if ((internal_style & SWT.RIGHT) == SWT.RIGHT) alignment = OS.STYLE_TRAIL; |
|
265 |
if ((internal_style & SWT.RIGHT) == SWT.RIGHT) alignment = OS.STYLE_TRAIL; |
253 |
if ((internal_style & SWT.CENTER) == SWT.CENTER) alignment = OS.STYLE_CENTER; |
|
266 |
if ((internal_style & SWT.CENTER) == SWT.CENTER) alignment = OS.STYLE_CENTER; |
254 |
OS.Label_SetAlignment(internal_handle,alignment); |
|
267 |
OS.Label_SetAlignment(internal_handle,alignment); |
255 |
} |
|
268 |
} |
256 |
|
|
269 |
|
257 |
public boolean setFocus() { |
|
270 |
public boolean setFocus() { |
258 |
checkWidget(); |
|
271 |
checkWidget(); |
259 |
return false; |
|
272 |
return false; |
260 |
} |
|
273 |
} |
261 |
|
|
274 |
|
262 |
/** |
|
275 |
/** |
263 |
* Sets the receiver's image to the argument, which may be |
|
276 |
* Sets the receiver's image to the argument, which may be |
264 |
* null indicating that no image should be displayed. |
|
277 |
* null indicating that no image should be displayed. |
265 |
* |
|
278 |
* |
266 |
* @param image the image to display on the receiver (may be null) |
|
279 |
* @param image the image to display on the receiver (may be null) |
267 |
* |
|
280 |
* |
268 |
* @exception IllegalArgumentException <ul> |
|
281 |
* @exception IllegalArgumentException <ul> |
269 |
* <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> |
|
282 |
* <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> |
270 |
* </ul> |
|
283 |
* </ul> |
271 |
* @exception SWTException <ul> |
|
284 |
* @exception SWTException <ul> |
272 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|
285 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
273 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|
286 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
274 |
* </ul> |
|
287 |
* </ul> |
275 |
*/ |
|
288 |
*/ |
276 |
public void setImage(Image image) { |
|
289 |
public void setImage(Image image) { |
277 |
checkWidget(); |
|
290 |
checkWidget(); |
278 |
this.image = image; |
|
291 |
this.image = image; |
279 |
int imageHandle = (image == null) ? 0 : image.internal_handle; |
|
292 |
int imageHandle = (image == null) ? 0 : image.internal_handle; |
280 |
// Passing 0 tells the native widget to stop displaying the image, |
|
293 |
// Passing 0 tells the native widget to stop displaying the image, |
281 |
// which is appropriate when the new image is null. |
|
294 |
// which is appropriate when the new image is null. |
282 |
OS.Label_SetImage(internal_handle,imageHandle); |
|
295 |
OS.Label_SetImage(internal_handle,imageHandle); |
283 |
} |
|
296 |
} |
284 |
|
|
297 |
|
285 |
/** |
|
298 |
/** |
286 |
* Sets the receiver's text. |
|
299 |
* Sets the receiver's text. |
287 |
* <p> |
|
300 |
* <p> |
288 |
* This method sets the widget label. The label may include |
|
301 |
* This method sets the widget label. The label may include |
289 |
* the mnemonic character and line delimiters. |
|
302 |
* the mnemonic character and line delimiters. |
290 |
* </p> |
|
303 |
* </p> |
291 |
* <p> |
|
304 |
* <p> |
292 |
* Mnemonics are indicated by an '&' that causes the next |
|
305 |
* Mnemonics are indicated by an '&' that causes the next |
293 |
* character to be the mnemonic. When the user presses a |
|
306 |
* character to be the mnemonic. When the user presses a |
294 |
* key sequence that matches the mnemonic, focus is assigned |
|
307 |
* key sequence that matches the mnemonic, focus is assigned |
295 |
* to the control that follows the label. On most platforms, |
|
308 |
* to the control that follows the label. On most platforms, |
296 |
* the mnemonic appears underlined but may be emphasised in a |
|
309 |
* the mnemonic appears underlined but may be emphasised in a |
297 |
* platform specific manner. The mnemonic indicator character |
|
310 |
* platform specific manner. The mnemonic indicator character |
298 |
*'&' can be escaped by doubling it in the string, causing |
|
311 |
*'&' can be escaped by doubling it in the string, causing |
299 |
* a single '&' to be displayed. |
|
312 |
* a single '&' to be displayed. |
300 |
* </p> |
|
313 |
* </p> |
301 |
* |
|
314 |
* |
302 |
* @param string the new text |
|
315 |
* @param string the new text |
303 |
* |
|
316 |
* |
304 |
* @exception IllegalArgumentException <ul> |
|
317 |
* @exception IllegalArgumentException <ul> |
305 |
* <li>ERROR_NULL_ARGUMENT - if the text is null</li> |
|
318 |
* <li>ERROR_NULL_ARGUMENT - if the text is null</li> |
306 |
* </ul> |
|
319 |
* </ul> |
307 |
* @exception SWTException <ul> |
|
320 |
* @exception SWTException <ul> |
308 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|
321 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
309 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|
322 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
310 |
* </ul> |
|
323 |
* </ul> |
311 |
*/ |
|
324 |
*/ |
312 |
public void setText(String string) { |
|
325 |
public void setText(String string) { |
313 |
checkWidget(); |
|
326 |
checkWidget(); |
314 |
if (string == null) error(SWT.ERROR_NULL_ARGUMENT); |
|
327 |
if (string == null) error(SWT.ERROR_NULL_ARGUMENT); |
315 |
if ((internal_style & SWT.SEPARATOR) != 0) return; |
|
328 |
if ((internal_style & SWT.SEPARATOR) != 0) return; |
316 |
text = string; |
|
329 |
text = string; |
317 |
OS.Label_SetText(internal_handle,string); |
|
330 |
OS.Label_SetText(internal_handle,string); |
318 |
// Passing 0 tells the native widget to stop displaying the image, |
|
331 |
// Passing 0 tells the native widget to stop displaying the image, |
319 |
// and since setText is the last call made, we should display text. |
|
332 |
// and since setText is the last call made, we should display text. |
320 |
OS.Label_SetImage(internal_handle,0); |
|
333 |
OS.Label_SetImage(internal_handle,0); |
321 |
} |
|
334 |
} |
322 |
|
|
335 |
|
323 |
boolean isTabGroup() { |
|
336 |
boolean isTabGroup() { |
324 |
return false; |
|
337 |
return false; |
325 |
} |
|
338 |
} |
326 |
boolean isTabItem () { |
|
339 |
boolean isTabItem () { |
327 |
return false; |
|
340 |
return false; |
328 |
} |
|
341 |
} |
329 |
|
|
342 |
|
330 |
} |
|
343 |
} |