37 /** |
38 /** |
38 * Constructor. |
39 * Constructor. |
39 * |
40 * |
40 * @param dflp DefaultFormLayoutPolicy |
41 * @param dflp DefaultFormLayoutPolicy |
41 */ |
42 */ |
42 GaugeLayouter(DefaultFormLayoutPolicy dflp) { |
43 GaugeLayouter(DefaultFormLayoutPolicy dflp) |
|
44 { |
43 super(dflp); |
45 super(dflp); |
44 } |
46 } |
45 |
47 |
46 /** |
48 /** |
47 * Creates the eSWT ProgressBar/Slider for this item. |
49 * Creates the eSWT ProgressBar/Slider for this item. |
48 */ |
50 */ |
49 Control eswtGetControl(Composite parent, Item item) { |
51 Control eswtGetControl(Composite parent, Item item) |
|
52 { |
50 return eswtCreateControl(parent, item); |
53 return eswtCreateControl(parent, item); |
51 } |
54 } |
52 |
55 |
53 /** |
56 /** |
54 * Construts a gauge control surrounded with composite. |
57 * Construts a gauge control surrounded with composite. |
55 */ |
58 */ |
56 static Control eswtCreateControl(Composite parent, Item item) { |
59 static Control eswtCreateControl(Composite parent, Item item) |
|
60 { |
57 Gauge gauge = (Gauge) item; |
61 Gauge gauge = (Gauge) item; |
58 // create an owning composite every time |
62 // create an owning composite every time |
59 Composite comp = new Composite(parent, SWT.NONE); |
63 Composite comp = new Composite(parent, SWT.NONE); |
60 |
64 |
61 if (gauge.isInteractive()) { |
65 if(gauge.isInteractive()) |
62 FormLayout layout = new FormLayout(); |
66 { |
|
67 FormLayout layout = new FormLayout(); |
63 layout.marginBottom = Style.pixelMetric(Style.QSTYLE_PM_LAYOUTBOTTOMMARGIN); |
68 layout.marginBottom = Style.pixelMetric(Style.QSTYLE_PM_LAYOUTBOTTOMMARGIN); |
64 layout.marginTop = Style.pixelMetric(Style.QSTYLE_PM_LAYOUTTOPMARGIN); |
69 layout.marginTop = Style.pixelMetric(Style.QSTYLE_PM_LAYOUTTOPMARGIN); |
65 layout.marginLeft = Style.pixelMetric(Style.QSTYLE_PM_LAYOUTLEFTMARGIN); |
70 layout.marginLeft = Style.pixelMetric(Style.QSTYLE_PM_LAYOUTLEFTMARGIN); |
66 layout.marginRight = Style.pixelMetric(Style.QSTYLE_PM_LAYOUTRIGHTMARGIN); |
71 layout.marginRight = Style.pixelMetric(Style.QSTYLE_PM_LAYOUTRIGHTMARGIN); |
67 layout.spacing = Style.pixelMetric(Style.QSTYLE_PM_LAYOUTVERTICALSPACING); |
72 layout.spacing = Style.pixelMetric(Style.QSTYLE_PM_LAYOUTVERTICALSPACING); |
68 comp.setLayout(layout); |
73 comp.setLayout(layout); |
69 |
74 |
70 // Current Value - Mutable Value |
75 // Current Value - Mutable Value |
71 Label currentlabel = new Label(comp, SWT.WRAP); |
76 Label currentlabel = new Label(comp, SWT.WRAP); |
72 currentlabel.setText(Integer.toString( gauge.getValue())); |
77 currentlabel.setText(Integer.toString(gauge.getValue())); |
73 currentlabel.setAlignment(SWT.LEAD); |
78 currentlabel.setAlignment(SWT.LEAD); |
74 |
79 |
75 FormData currLabelData = new FormData(); |
80 FormData currLabelData = new FormData(); |
76 currLabelData.left = new FormAttachment(0); |
81 currLabelData.left = new FormAttachment(0); |
77 currentlabel.setLayoutData(currLabelData); |
82 currentlabel.setLayoutData(currLabelData); |
78 |
83 |
79 Slider slider = new Slider(comp, SWT.HORIZONTAL); |
84 Slider slider = new Slider(comp, SWT.HORIZONTAL); |
80 slider.setMinimum(0); |
85 slider.setMinimum(0); |
81 slider.setMaximum(gauge.getMaxValue() + 1); |
86 slider.setMaximum(gauge.getMaxValue() + 1); |
82 slider.setSelection(gauge.getValue()); |
87 slider.setSelection(gauge.getValue()); |
83 slider.setIncrement(1); |
88 slider.setIncrement(1); |
84 slider.setPageIncrement(1); |
89 slider.setPageIncrement(1); |
85 |
90 |
86 FormData SliderLayoutData = new FormData(); |
91 FormData SliderLayoutData = new FormData(); |
87 SliderLayoutData.right = new FormAttachment(100); |
92 SliderLayoutData.right = new FormAttachment(100); |
88 SliderLayoutData.left = new FormAttachment(currentlabel); |
93 SliderLayoutData.left = new FormAttachment(currentlabel); |
89 slider.setLayoutData(SliderLayoutData); |
94 slider.setLayoutData(SliderLayoutData); |
90 |
95 |
91 // Min Value |
96 // Min Value |
92 Label minlabel = new Label(comp, SWT.WRAP); |
97 Label minlabel = new Label(comp, SWT.WRAP); |
93 minlabel.setText("0"); |
98 minlabel.setText("0"); |
94 minlabel.setAlignment(SWT.LEAD); |
99 minlabel.setAlignment(SWT.LEAD); |
95 |
100 |
96 FormData minLabelData = new FormData(); |
101 FormData minLabelData = new FormData(); |
97 minLabelData.left = new FormAttachment(slider, 0, SWT.LEFT); |
102 minLabelData.left = new FormAttachment(slider, 0, SWT.LEFT); |
98 minLabelData.top = new FormAttachment(slider); |
103 minLabelData.top = new FormAttachment(slider); |
99 minlabel.setLayoutData(minLabelData); |
104 minlabel.setLayoutData(minLabelData); |
100 |
105 |
101 // Max Value |
106 // Max Value |
102 Label maxlabel = new Label(comp, SWT.WRAP); |
107 Label maxlabel = new Label(comp, SWT.WRAP); |
103 maxlabel.setText(Integer.toString(gauge.getMaxValue()) ); |
108 maxlabel.setText(Integer.toString(gauge.getMaxValue())); |
104 maxlabel.setAlignment(SWT.LEAD); |
109 maxlabel.setAlignment(SWT.LEAD); |
105 |
110 |
106 FormData maxLabelData = new FormData(); |
111 FormData maxLabelData = new FormData(); |
107 maxLabelData.right = new FormAttachment(slider, 0, SWT.RIGHT); |
112 maxLabelData.right = new FormAttachment(slider, 0, SWT.RIGHT); |
108 maxLabelData.top = new FormAttachment(slider); |
113 maxLabelData.top = new FormAttachment(slider); |
109 maxlabel.setLayoutData(maxLabelData); |
114 maxlabel.setLayoutData(maxLabelData); |
110 } |
115 } |
111 else { |
116 else |
|
117 { |
112 ProgressBar progressBar = null; |
118 ProgressBar progressBar = null; |
113 if (gauge.isIndefinite()) { |
119 if(gauge.isIndefinite()) |
114 switch (gauge.getValue()) { |
120 { |
115 case Gauge.CONTINUOUS_IDLE: |
121 switch(gauge.getValue()) |
116 // TODO: eSWT support required |
122 { |
117 // Gauge like busy-state indicator with no activity: |
123 case Gauge.CONTINUOUS_IDLE: |
118 progressBar = new ProgressBar(comp, |
124 // TODO: eSWT support required |
119 SWT.HORIZONTAL | SWT.INDETERMINATE); |
125 // Gauge like busy-state indicator with no activity: |
120 break; |
126 progressBar = new ProgressBar(comp, |
121 case Gauge.CONTINUOUS_RUNNING: |
127 SWT.HORIZONTAL | SWT.INDETERMINATE); |
122 // Gauge like busy-state indicator: |
128 break; |
123 progressBar = new ProgressBar(comp, |
129 case Gauge.CONTINUOUS_RUNNING: |
124 SWT.HORIZONTAL | SWT.INDETERMINATE); |
130 // Gauge like busy-state indicator: |
125 break; |
131 progressBar = new ProgressBar(comp, |
126 case Gauge.INCREMENTAL_IDLE: |
132 SWT.HORIZONTAL | SWT.INDETERMINATE); |
127 // TODO: eSWT support required |
133 break; |
128 // Gauge like INCREMENTAL_UPDATING, but no activity. |
134 case Gauge.INCREMENTAL_IDLE: |
129 progressBar = new ProgressBar(comp, |
135 // TODO: eSWT support required |
130 SWT.HORIZONTAL | SWT.INDETERMINATE); |
136 // Gauge like INCREMENTAL_UPDATING, but no activity. |
131 break; |
137 progressBar = new ProgressBar(comp, |
132 case Gauge.INCREMENTAL_UPDATING: |
138 SWT.HORIZONTAL | SWT.INDETERMINATE); |
133 // TODO: eSWT support required |
139 break; |
134 // Gauge which is updated on calling Gauge.setValue(). |
140 case Gauge.INCREMENTAL_UPDATING: |
135 progressBar = new ProgressBar(comp, |
141 // TODO: eSWT support required |
136 SWT.HORIZONTAL | SWT.INDETERMINATE); |
142 // Gauge which is updated on calling Gauge.setValue(). |
137 break; |
143 progressBar = new ProgressBar(comp, |
138 default: |
144 SWT.HORIZONTAL | SWT.INDETERMINATE); |
139 // This is error and will cause NullPointerException |
145 break; |
140 // later in this method. Gauge-class takes care that |
146 default: |
141 // this is never executed. |
147 // This is error and will cause NullPointerException |
142 Logger.warning("Unexpected gauge value: " + gauge.getValue()); |
148 // later in this method. Gauge-class takes care that |
143 break; |
149 // this is never executed. |
|
150 Logger.warning("Unexpected gauge value: " + gauge.getValue()); |
|
151 break; |
144 } |
152 } |
145 } |
153 } |
146 else { |
154 else |
|
155 { |
147 progressBar = new ProgressBar(comp, SWT.HORIZONTAL); |
156 progressBar = new ProgressBar(comp, SWT.HORIZONTAL); |
148 progressBar.setMaximum(gauge.getMaxValue() + 1); |
157 progressBar.setMaximum(gauge.getMaxValue() + 1); |
149 progressBar.setSelection(gauge.getValue()); |
158 progressBar.setSelection(gauge.getValue()); |
150 } |
159 } |
151 } |
160 } |
154 } |
163 } |
155 |
164 |
156 /** |
165 /** |
157 * Set the size of the layouted Control. |
166 * Set the size of the layouted Control. |
158 */ |
167 */ |
159 void eswtResizeControl(Item item, Control control, int width, int height) { |
168 void eswtResizeControl(Item item, Control control, int width, int height) |
|
169 { |
160 super.eswtResizeControl(item, control, width, height); |
170 super.eswtResizeControl(item, control, width, height); |
161 control.getParent().setSize(width, height); |
171 control.getParent().setSize(width, height); |
162 // This will move gauge to the center of the screen: |
172 // This will move gauge to the center of the screen: |
163 control.setLocation((width - control.getBounds().width) / 2, |
173 control.setLocation((width - control.getBounds().width) / 2, |
164 control.getLocation().y); |
174 control.getLocation().y); |
165 } |
175 } |
166 |
176 |
167 /** |
177 /** |
168 * Add listeners to Layouter specific control. |
178 * Add listeners to Layouter specific control. |
169 */ |
179 */ |
170 void eswtAddSpecificListeners(Item item, Control control) { |
180 void eswtAddSpecificListeners(Item item, Control control) |
|
181 { |
171 super.eswtAddSpecificListeners(item, control); |
182 super.eswtAddSpecificListeners(item, control); |
172 Gauge gauge = (Gauge) item; |
183 Gauge gauge = (Gauge) item; |
173 if (gauge.isInteractive()) { |
184 if(gauge.isInteractive()) |
|
185 { |
174 Slider slider = (Slider) control; |
186 Slider slider = (Slider) control; |
175 SelectionListener listener = new GaugeSelectionListener(gauge); |
187 SelectionListener listener = new GaugeSelectionListener(gauge); |
176 slider.addSelectionListener(listener); |
188 slider.addSelectionListener(listener); |
177 slider.setData(SELECTION_LISTENER, listener); |
189 slider.setData(SELECTION_LISTENER, listener); |
178 } |
190 } |
179 } |
191 } |
180 |
192 |
181 /** |
193 /** |
182 * Remove listeners from Layouter specific control. |
194 * Remove listeners from Layouter specific control. |
183 */ |
195 */ |
184 void eswtRemoveSpecificListeners(Item item, Control control) { |
196 void eswtRemoveSpecificListeners(Item item, Control control) |
|
197 { |
185 super.eswtRemoveSpecificListeners(item, control); |
198 super.eswtRemoveSpecificListeners(item, control); |
186 Gauge gauge = (Gauge) item; |
199 Gauge gauge = (Gauge) item; |
187 if (gauge.isInteractive()) { |
200 if(gauge.isInteractive()) |
|
201 { |
188 Slider slider = (Slider) control; |
202 Slider slider = (Slider) control; |
189 SelectionListener listener = (SelectionListener) slider |
203 SelectionListener listener = (SelectionListener) slider |
190 .getData(SELECTION_LISTENER); |
204 .getData(SELECTION_LISTENER); |
191 if (listener != null) { |
205 if(listener != null) |
|
206 { |
192 slider.removeSelectionListener(listener); |
207 slider.removeSelectionListener(listener); |
193 slider.setData(SELECTION_LISTENER, null); |
208 slider.setData(SELECTION_LISTENER, null); |
194 } |
209 } |
195 } |
210 } |
196 } |
211 } |
197 |
212 |
198 /** |
213 /** |
199 * Returns if this eSWT control is Layouter specific. |
214 * Returns if this eSWT control is Layouter specific. |
200 */ |
215 */ |
201 boolean eswtIsSpecificControl(Item item, Control control) { |
216 boolean eswtIsSpecificControl(Item item, Control control) |
202 if (((Gauge) item).isInteractive()) { |
217 { |
|
218 if(((Gauge) item).isInteractive()) |
|
219 { |
203 return (control instanceof Slider); |
220 return (control instanceof Slider); |
204 } |
221 } |
205 else { |
222 else |
|
223 { |
206 return (control instanceof ProgressBar); |
224 return (control instanceof ProgressBar); |
207 } |
225 } |
208 } |
226 } |
209 |
227 |
210 /** |
228 /** |
211 * Updates the values of Gauge. |
229 * Updates the values of Gauge. |
212 */ |
230 */ |
213 void eswtUpdateItem(Item item, Control control, int reason, Object param) { |
231 void eswtUpdateItem(Item item, Control control, int reason, Object param) |
214 Gauge gauge = (Gauge) item; |
232 { |
215 if (control instanceof ProgressBar) { |
233 Gauge gauge = (Gauge) item; |
|
234 if(control instanceof ProgressBar) |
|
235 { |
216 ((ProgressBar) control).setMaximum(gauge.getMaxValue() + 1); |
236 ((ProgressBar) control).setMaximum(gauge.getMaxValue() + 1); |
217 ((ProgressBar) control).setSelection(gauge.getValue()); |
237 ((ProgressBar) control).setSelection(gauge.getValue()); |
218 } |
238 } |
219 else if (control instanceof Slider) { |
239 else if(control instanceof Slider) |
|
240 { |
220 ((Slider) control).setMaximum(gauge.getMaxValue() + 1); |
241 ((Slider) control).setMaximum(gauge.getMaxValue() + 1); |
221 ((Slider) control).setSelection(gauge.getValue()); |
242 ((Slider) control).setSelection(gauge.getValue()); |
222 } |
243 } |
223 } |
244 } |
224 |
245 |
225 /** |
246 /** |
226 * Returns true if that key was consumed by Gauge. |
247 * Returns true if that key was consumed by Gauge. |
227 */ |
248 */ |
228 boolean eswtOfferKeyPressed(Item item, int key) { |
249 boolean eswtOfferKeyPressed(Item item, int key) |
229 Gauge gauge = (Gauge) item; |
250 { |
230 if (gauge.isInteractive()) { |
251 Gauge gauge = (Gauge) item; |
231 if (key == SWT.ARROW_RIGHT) { |
252 if(gauge.isInteractive()) |
|
253 { |
|
254 if(key == SWT.ARROW_RIGHT) |
|
255 { |
232 gauge.internalSetValue(gauge.getValue() + 1); |
256 gauge.internalSetValue(gauge.getValue() + 1); |
233 gauge.setLayout(gauge.internalGetLayout()); |
257 gauge.setLayout(gauge.internalGetLayout()); |
234 |
258 |
235 } |
259 } |
236 else if(key == SWT.ARROW_LEFT) { |
260 else if(key == SWT.ARROW_LEFT) |
237 gauge.internalSetValue(gauge.getValue() -1); |
261 { |
238 gauge.setLayout(gauge.internalGetLayout()); |
262 gauge.internalSetValue(gauge.getValue() -1); |
|
263 gauge.setLayout(gauge.internalGetLayout()); |
239 } |
264 } |
240 return true; |
265 return true; |
241 } |
266 } |
242 return false; |
267 return false; |
243 } |
268 } |