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
|
/* *************************************************************************
IT Mill Toolkit
Development of Browser User Interfaces Made Easy
Copyright (C) 2000-2006 IT Mill Ltd
*************************************************************************
This product is distributed under commercial license that can be found
from the product package on license.pdf. Use of this product might
require purchasing a commercial license from IT Mill Ltd. For guidelines
on usage, see licensing-guidelines.html
*************************************************************************
For more information, contact:
IT Mill Ltd phone: +358 2 4802 7180
Ruukinkatu 2-4 fax: +358 2 4802 7181
20540, Turku email: info@itmill.com
Finland company www: www.itmill.com
Primary source for information and releases: www.itmill.com
********************************************************************** */
package com.itmill.toolkit.ui;
import com.itmill.toolkit.data.Property;
import com.itmill.toolkit.data.util.ObjectProperty;
import com.itmill.toolkit.terminal.PaintException;
import com.itmill.toolkit.terminal.PaintTarget;
/**
* ProgressIndicator is component that shows user state of a process
* (like long computing or file upload)
*
* ProgressIndicator has two mainmodes. One for indeterminate processes and
* other (default) for processes which progress can be measured
*
* May view an other property that indicates progress 0...1
*
* @author IT Mill Ltd.
* @version @VERSION@
* @since 3.1
*/
public class ProgressIndicator
extends AbstractField
implements
Property,
Property.Viewer,
Property.ValueChangeListener {
/** Content mode, where the label contains only plain text. The getValue()
* result is coded to XML when painting.
*/
public static final int CONTENT_TEXT = 0;
/** Content mode, where the label contains preformatted text.
*/
public static final int CONTENT_PREFORMATTED = 1;
private boolean indeterminate = false;
private Property dataSource;
private int pollingInterval = 1000;
/** Creates an a new ProgressIndicator. */
public ProgressIndicator() {
setPropertyDataSource(new ObjectProperty(new Float(0), Float.class));
}
/** Creates a new instance of ProgressIndicator with given state. */
public ProgressIndicator(Float value) {
setPropertyDataSource(new ObjectProperty(value, Float.class));
}
/** Creates a new instance of ProgressIndicator with stae read from given datasource. */
public ProgressIndicator(Property contentSource) {
setPropertyDataSource(contentSource);
}
/** Get component UIDL tag.
* @return Component UIDL tag as string.
*/
public String getTag() {
return "progressindicator";
}
/** Set the component to read-only.
* Readonly is not used in ProgressIndicator.
* @param readOnly True to enable read-only mode, False to disable it
*/
public void setReadOnly(boolean readOnly) {
if (dataSource == null)
throw new IllegalStateException("Datasource must be se");
dataSource.setReadOnly(readOnly);
}
/** Is the component read-only ?
* Readonly is not used in ProgressIndicator - this returns allways false.
* @return True iff the component is in read only mode
*/
public boolean isReadOnly() {
if (dataSource == null)
throw new IllegalStateException("Datasource must be se");
return dataSource.isReadOnly();
}
/** Paint the content of this component.
* @param event PaintEvent.
*/
public void paintContent(PaintTarget target) throws PaintException {
target.addAttribute("indeterminate", indeterminate);
target.addAttribute("pollinginterval", pollingInterval);
target.addAttribute("state", this.getValue().toString());
}
/** Get the value of the ProgressIndicator.
* Value of the ProgressIndicator is Float between 0 and 1
* @return Value of the ProgressIndicator
*/
public Object getValue() {
if (dataSource == null)
throw new IllegalStateException("Datasource must be se");
return dataSource.getValue();
}
/** Set the value of the ProgressIndicator.
* Value of the ProgressIndicator is the Float between 0 and 1
* @param newValue New value of the ProgressIndicator
*/
public void setValue(Object newValue) {
if (dataSource == null)
throw new IllegalStateException("Datasource must be se");
this.dataSource.setValue(newValue);
}
public String toString() {
if (dataSource == null)
throw new IllegalStateException("Datasource must be se");
return dataSource.toString();
}
public Class getType() {
if (dataSource == null)
throw new IllegalStateException("Datasource must be se");
return dataSource.getType();
}
/** Get viewing data-source property. */
public Property getPropertyDataSource() {
return dataSource;
}
/** Set the property as data-source for viewing. */
public void setPropertyDataSource(Property newDataSource) {
// Stop listening the old data source changes
if (dataSource != null
&& Property.ValueChangeNotifier.class.isAssignableFrom(
dataSource.getClass()))
((Property.ValueChangeNotifier) dataSource).removeListener(this);
// Set the new data source
dataSource = newDataSource;
// Listen the new data source if possible
if (dataSource != null
&& Property.ValueChangeNotifier.class.isAssignableFrom(
dataSource.getClass()))
((Property.ValueChangeNotifier) dataSource).addListener(this);
}
/** Get the mode of ProgressIndicator.
*
* @return true if in indeterminate mode
*/
public boolean getContentMode() {
return indeterminate;
}
/**
* Set ProgressIndicator to indeterminate mode
*
* @param newValue true to set to indeterminate mode
*/
public void setIndeterminate(boolean newValue) {
indeterminate = newValue;
}
/**
* Set interval that compnent checks for progress
* @param newValue interval in milliseconds
*/
public void setPollingInterval(int newValue) {
pollingInterval = newValue;
}
/**
* Get interval that component checks for progress
* @return interval in milliseconds
*/
public int getPollingInterval() {
return pollingInterval;
}
}
|