1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
|
/*
@ITMillApache2LicenseForJavaFiles@
*/
package com.itmill.toolkit.ui;
import java.util.Collection;
import java.util.EventListener;
import java.util.EventObject;
import java.util.Locale;
import com.itmill.toolkit.Application;
import com.itmill.toolkit.terminal.ErrorMessage;
import com.itmill.toolkit.terminal.Paintable;
import com.itmill.toolkit.terminal.Resource;
import com.itmill.toolkit.terminal.VariableOwner;
/**
* The top-level component interface which must be implemented by all UI
* components that use IT Mill Toolkit.
*
* @author IT Mill Ltd.
* @version
* @VERSION@
* @since 3.0
*/
public interface Component extends Paintable, VariableOwner {
/**
* Gets style for component. Multiple styles are joined with spaces.
*
* @return the component's styleValue of property style.
*/
public String getStyleName();
/**
* Sets and replaces all previous style names of the component. This method
* will trigger a
* {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}.
*
* @param style
* the new style of the component.
*/
public void setStyleName(String style);
/**
* Adds style name to component. Handling additional style names is terminal
* specific, but in web browser environment they will most likely become CSS
* classes as given on server side.
*
* This method will trigger a
* {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}.
*
* @param style
* the new style to be added to the component
*/
public void addStyleName(String style);
/**
* Removes given style name from component.
*
* @param style
* the style to be removed
*/
public void removeStyleName(String style);
/**
* <p>
* Tests if the component is enabled or not. All the variable change events
* are blocked from disabled components. Also the component should visually
* indicate that it is disabled (by shading the component for example). All
* hidden (isVisible() == false) components must return false.
* </p>
*
* <p>
* Components should be enabled by default.
* </p>
*
* @return <code>true</code> if the component is enabled,
* <code>false</code> if not.
* @see VariableOwner#isEnabled()
*/
public boolean isEnabled();
/**
* Enables or disables the component. Being enabled means that the component
* can be edited. This method will trigger a
* {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}.
*
* @param enabled
* the boolean value specifying if the component should be
* enabled after the call or not
*/
public void setEnabled(boolean enabled);
/**
* Tests if the component is visible or not. Visibility defines if the
* component is shown in the UI or not. Default is <code>true</code>.
*
* @return <code>true</code> if the component is visible in the UI,
* <code>false</code> if not
*/
public boolean isVisible();
/**
* Sets the components visibility status. Visibility defines if the
* component is shown in the UI or not.
*
* @param visible
* the Boolean value specifying if the component should be
* visible after the call or not.
*/
public void setVisible(boolean visible);
/**
* Gets the visual parent of the component. The components can be nested but
* one component can have only one parent.
*
* @return the parent component.
*/
public Component getParent();
/**
* Sets the component's parent component.
*
* <p>
* This method calls automatically {@link #attach()} if the parent is
* attached to a window (or is itself a window}, and {@link #detach()} if
* <code>parent</code> is set <code>null</code>, but the component was
* in the application.
* </p>
*
* <p>
* This method is rarely called directly. Instead the
* {@link ComponentContainer#addComponent(Component)} method is used to add
* components to container, which call this method implicitly.
*
* @param parent
* the new parent component.
*/
public void setParent(Component parent);
/**
* Tests if the component is in read-only mode.
*
* @return <code>true</code> if the component is in read-only mode,
* <code>false</code> if not.
*/
public boolean isReadOnly();
/**
* Sets the component's to read-only mode to the specified state. This
* method will trigger a
* {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}.
*
* @param readOnly
* the boolean value specifying if the component should be in
* read-only mode after the call or not.
*/
public void setReadOnly(boolean readOnly);
/**
* Gets the caption of the component. Caption is the visible name of the
* component.
*
* @return the component's caption <code>String</code>.
*/
public String getCaption();
/**
* Gets the component's icon. A component may have a graphical icon
* associated with it, this method retrieves it if it is defined.
*
* @return the component's icon or <code>null</code> if it not defined.
*/
public Resource getIcon();
/**
* Gets the component's parent window. If the component does not yet belong
* to a window <code>null</code> is returned.
*
* @return the parent window of the component or <code>null</code>.
*/
public Window getWindow();
/**
* Gets the component's parent application. If the component does not yet
* belong to a application <code>null</code> is returned.
*
* @return the parent application of the component or <code>null</code>.
*/
public Application getApplication();
/**
* <p>
* Notifies the component that it is connected to an application. This
* method is always called before the component is first time painted and is
* suitable to be extended. The <code>getApplication</code> and
* <code>getWindow</code> methods might return <code>null</code> before
* this method is called.
* </p>
*
* <p>
* The caller of this method is {@link #setParent(Component)} if the parent
* is already in the application. If the parent is not in the application,
* it must call the {@link #attach()} for all its children when it will be
* added to the application.
* </p>
*/
public void attach();
/**
* Notifies the component that it is detached from the application.
* <p>
* The {@link #getApplication()} and {@link #getWindow()} methods might
* return <code>null</code> after this method is called.
* </p>
*
* <p>
* The caller of this method is {@link #setParent(Component)} if the parent
* is in the application. When the parent is detached from the application
* it is its response to call {@link #detach()} for all the children and to
* detach itself from the terminal.
* </p>
*/
public void detach();
/**
* Gets the locale of this component.
*
* @return This component's locale. If this component does not have a
* locale, the locale of its parent is returned. Eventually locale
* of application is returned. If application does not have its own
* locale the locale is determined by
* <code>Locale.getDefautlt</code>. Returns null if the component
* does not have its own locale and has not yet been added to a
* containment hierarchy such that the locale can be determined from
* the containing parent.
*/
public Locale getLocale();
/**
* The children must call this method when they need repainting. The call
* must be made event in the case the children sent the repaint request
* themselves.
*
* @param alreadyNotified
* the collection of repaint request listeners that have been
* already notified by the child. This component should not
* renotify the listed listeners again. The container given
* as parameter must be modifiable as the component might
* modify it and pass it forwards. Null parameter is
* interpreted as empty collection.
*/
public void childRequestedRepaint(Collection alreadyNotified);
/* Component event framework *************************************** */
/**
* Superclass of all component originated <code>Event</code>s.
*/
public class Event extends EventObject {
/**
* Serial generated by eclipse.
*/
private static final long serialVersionUID = 4048791277653274933L;
/**
* Constructs a new event with a specified source component.
*
* @param source
* the source component of the event.
*/
public Event(Component source) {
super(source);
}
}
/**
* Listener interface for receiving <code>Component.Event</code>s.
*/
public interface Listener extends EventListener {
/**
* Notifies the listener of a component event.
*
* @param event
* the event that has occured.
*/
public void componentEvent(Component.Event event);
}
/**
* Registers a new component event listener for this component.
*
* @param listener
* the new Listener to be registered.
*/
public void addListener(Component.Listener listener);
/**
* Removes a previously registered component event listener from this
* component.
*
* @param listener
* the listener to be removed.
*/
public void removeListener(Component.Listener listener);
/**
* Class of all component originated <code>ErrorEvent</code>s.
*/
public class ErrorEvent extends Event {
/**
* Serial generated by eclipse.
*/
private static final long serialVersionUID = 4051323457293857333L;
private final ErrorMessage message;
/**
* Constructs a new event with a specified source component.
*
* @param message
* the error message.
* @param component
* the source component.
*/
public ErrorEvent(ErrorMessage message, Component component) {
super(component);
this.message = message;
}
/**
* Gets the error message.
*
* @return the error message.
*/
public ErrorMessage getErrorMessage() {
return message;
}
}
/**
* Listener interface for receiving <code>Component.Errors</code>s.
*/
public interface ErrorListener extends EventListener {
/**
* Notifies the listener of a component error.
*
* @param event
* the event that has occured.
*/
public void componentError(Component.ErrorEvent event);
}
/**
* Interface implemented by components which can obtain input focus.
*/
public interface Focusable {
/**
* Sets the focus to this component.
*/
public void focus();
/**
* Gets the Tabulator index of this Focusable component.
*
* @return the Positive tab order of this focusable. Negative of zero
* means unspecified tab order.
*/
public int getTabIndex();
/**
* Sets the Tabulator index of this Focusable component.
*
* @param tabIndex
* the Positive tab order of this focusable. Negative of
* zero means unspecified tab order.
*/
public void setTabIndex(int tabIndex);
/**
* Gets the unique ID of focusable. This will be used to move input
* focus directly to this component.
*
* @return the Unique id of focusable.
*/
public long getFocusableId();
}
}
|