|
1 |
package org.txm.backtomedia.commands.function;
|
|
2 |
/*******************************************************************************
|
|
3 |
* Copyright (c) 2011 Laurent CARON.
|
|
4 |
* All rights reserved. This program and the accompanying materials
|
|
5 |
* are made available under the terms of the Eclipse Public License v1.0
|
|
6 |
* which accompanies this distribution, and is available at
|
|
7 |
* http://www.eclipse.org/legal/epl-v10.html
|
|
8 |
*
|
|
9 |
* Contributors:
|
|
10 |
* Laurent CARON (laurent.caron@gmail.com) - initial API and implementation
|
|
11 |
*******************************************************************************/
|
|
12 |
|
|
13 |
import java.awt.dnd.MouseDragGestureRecognizer;
|
|
14 |
import java.util.ArrayList;
|
|
15 |
import java.util.List;
|
|
16 |
|
|
17 |
import org.eclipse.swt.SWT;
|
|
18 |
import org.eclipse.swt.SWTException;
|
|
19 |
import org.eclipse.swt.events.PaintEvent;
|
|
20 |
import org.eclipse.swt.events.PaintListener;
|
|
21 |
import org.eclipse.swt.events.SelectionEvent;
|
|
22 |
import org.eclipse.swt.events.SelectionListener;
|
|
23 |
import org.eclipse.swt.graphics.GC;
|
|
24 |
import org.eclipse.swt.graphics.Image;
|
|
25 |
import org.eclipse.swt.graphics.Point;
|
|
26 |
import org.eclipse.swt.graphics.Rectangle;
|
|
27 |
import org.eclipse.swt.widgets.Canvas;
|
|
28 |
import org.eclipse.swt.widgets.Composite;
|
|
29 |
import org.eclipse.swt.widgets.Event;
|
|
30 |
import org.eclipse.swt.widgets.Listener;
|
|
31 |
import org.mihalis.opal.utils.SWTGraphicUtil;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* Instances of this class provide a slider with 2 buttons (min value, max
|
|
35 |
* value).
|
|
36 |
* <p>
|
|
37 |
* <dl>
|
|
38 |
* <dt><b>Styles:</b></dt>
|
|
39 |
* <dd>BORDER</dd>
|
|
40 |
* <dd>HORIZONTAL</dd>
|
|
41 |
* <dd>VERTICAL</dd> *
|
|
42 |
* <dt><b>Events:</b></dt>
|
|
43 |
* <dd>Selection</dd>
|
|
44 |
* </dl>
|
|
45 |
* </p>
|
|
46 |
*/
|
|
47 |
public class TripleRangeSlider extends Canvas {
|
|
48 |
|
|
49 |
public enum SELECTED_KNOB {NONE, UPPER, LOWER, MIDDLE };
|
|
50 |
|
|
51 |
private int minimum;
|
|
52 |
private int maximum;
|
|
53 |
private int lowerValue;
|
|
54 |
private int middleValue;
|
|
55 |
private int upperValue;
|
|
56 |
private final List<SelectionListener> listeners;
|
|
57 |
private final Image slider, sliderHover, sliderDrag, sliderSelected;
|
|
58 |
private final Image vSlider, vSliderHover, vSliderDrag, vSliderSelected;
|
|
59 |
private int orientation;
|
|
60 |
private int increment;
|
|
61 |
private int pageIncrement;
|
|
62 |
private SELECTED_KNOB lastSelected;
|
|
63 |
private boolean dragInProgress;
|
|
64 |
private Point coordUpper;
|
|
65 |
private boolean upperHover;
|
|
66 |
private Point coordMiddle;
|
|
67 |
private boolean middleHover;
|
|
68 |
private Point coordLower;
|
|
69 |
private boolean lowerHover;
|
|
70 |
private int previousUpperValue;
|
|
71 |
private int previousMiddleValue;
|
|
72 |
private int previousLowerValue;
|
|
73 |
|
|
74 |
/**
|
|
75 |
* Constructs a new instance of this class given its parent and a style
|
|
76 |
* value describing its behavior and appearance.
|
|
77 |
* <p>
|
|
78 |
* The style value is either one of the style constants defined in class
|
|
79 |
* <code>SWT</code> which is applicable to instances of this class, or must
|
|
80 |
* be built by <em>bitwise OR</em>'ing together (that is, using the
|
|
81 |
* <code>int</code> "|" operator) two or more of those <code>SWT</code>
|
|
82 |
* style constants. The class description lists the style constants that are
|
|
83 |
* applicable to the class. Style bits are also inherited from superclasses.
|
|
84 |
* </p>
|
|
85 |
*
|
|
86 |
* @param parent a composite control which will be the parent of the new
|
|
87 |
* instance (cannot be null)
|
|
88 |
* @param style the style of control to construct
|
|
89 |
*
|
|
90 |
* @exception IllegalArgumentException <ul>
|
|
91 |
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
|
|
92 |
* </ul>
|
|
93 |
* @exception SWTException <ul>
|
|
94 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
95 |
* thread that created the parent</li>
|
|
96 |
* </ul>
|
|
97 |
*
|
|
98 |
*/
|
|
99 |
public TripleRangeSlider(final Composite parent, final int style) {
|
|
100 |
super(parent, SWT.DOUBLE_BUFFERED | ((style & SWT.BORDER) == SWT.BORDER ? SWT.BORDER : SWT.NONE));
|
|
101 |
this.minimum = this.lowerValue = 0;
|
|
102 |
this.middleValue = 50;
|
|
103 |
this.maximum = this.upperValue = 100;
|
|
104 |
this.listeners = new ArrayList<SelectionListener>();
|
|
105 |
this.increment = 1;
|
|
106 |
this.pageIncrement = 10;
|
|
107 |
this.lastSelected = SELECTED_KNOB.NONE;
|
|
108 |
this.slider = new Image(getDisplay(), this.getClass().getClassLoader().getResourceAsStream("images/slider-normal.png")); //$NON-NLS-1$
|
|
109 |
this.sliderHover = new Image(getDisplay(), this.getClass().getClassLoader().getResourceAsStream("images/slider-hover.png")); //$NON-NLS-1$
|
|
110 |
this.sliderDrag = new Image(getDisplay(), this.getClass().getClassLoader().getResourceAsStream("images/slider-drag.png")); //$NON-NLS-1$
|
|
111 |
this.sliderSelected = new Image(getDisplay(), this.getClass().getClassLoader().getResourceAsStream("images/slider-selected.png")); //$NON-NLS-1$
|
|
112 |
|
|
113 |
this.vSlider = new Image(getDisplay(), this.getClass().getClassLoader().getResourceAsStream("images/h-slider-normal.png")); //$NON-NLS-1$
|
|
114 |
this.vSliderHover = new Image(getDisplay(), this.getClass().getClassLoader().getResourceAsStream("images/h-slider-hover.png")); //$NON-NLS-1$
|
|
115 |
this.vSliderDrag = new Image(getDisplay(), this.getClass().getClassLoader().getResourceAsStream("images/h-slider-drag.png")); //$NON-NLS-1$
|
|
116 |
this.vSliderSelected = new Image(getDisplay(), this.getClass().getClassLoader().getResourceAsStream("images/h-slider-selected.png")); //$NON-NLS-1$
|
|
117 |
|
|
118 |
if ((style & SWT.VERTICAL) == SWT.VERTICAL) {
|
|
119 |
this.orientation = SWT.VERTICAL;
|
|
120 |
} else {
|
|
121 |
this.orientation = SWT.HORIZONTAL;
|
|
122 |
}
|
|
123 |
|
|
124 |
this.addListener(SWT.Dispose, new Listener() {
|
|
125 |
@Override
|
|
126 |
public void handleEvent(final Event event) {
|
|
127 |
SWTGraphicUtil.dispose(TripleRangeSlider.this.slider);
|
|
128 |
SWTGraphicUtil.dispose(TripleRangeSlider.this.sliderHover);
|
|
129 |
SWTGraphicUtil.dispose(TripleRangeSlider.this.sliderDrag);
|
|
130 |
SWTGraphicUtil.dispose(TripleRangeSlider.this.sliderSelected);
|
|
131 |
|
|
132 |
SWTGraphicUtil.dispose(TripleRangeSlider.this.vSlider);
|
|
133 |
SWTGraphicUtil.dispose(TripleRangeSlider.this.vSliderHover);
|
|
134 |
SWTGraphicUtil.dispose(TripleRangeSlider.this.vSliderDrag);
|
|
135 |
SWTGraphicUtil.dispose(TripleRangeSlider.this.vSliderSelected);
|
|
136 |
}
|
|
137 |
});
|
|
138 |
|
|
139 |
addMouseListeners();
|
|
140 |
addListener(SWT.KeyDown, new Listener() {
|
|
141 |
|
|
142 |
@Override
|
|
143 |
public void handleEvent(final Event event) {
|
|
144 |
handleKeyDown(event);
|
|
145 |
}
|
|
146 |
});
|
|
147 |
addPaintListener(new PaintListener() {
|
|
148 |
@Override
|
|
149 |
public void paintControl(final PaintEvent e) {
|
|
150 |
drawWidget(e);
|
|
151 |
|
|
152 |
}
|
|
153 |
});
|
|
154 |
|
|
155 |
}
|
|
156 |
|
|
157 |
/**
|
|
158 |
* Add the mouse listeners (mouse up, mouse down, mouse move, mouse wheel)
|
|
159 |
*/
|
|
160 |
private void addMouseListeners() {
|
|
161 |
addListener(SWT.MouseDown, new Listener() {
|
|
162 |
@Override
|
|
163 |
public void handleEvent(final Event e) {
|
|
164 |
handleMouseDown(e);
|
|
165 |
}
|
|
166 |
});
|
|
167 |
|
|
168 |
addListener(SWT.MouseUp, new Listener() {
|
|
169 |
@Override
|
|
170 |
public void handleEvent(final Event e) {
|
|
171 |
handleMouseUp(e);
|
|
172 |
}
|
|
173 |
});
|
|
174 |
|
|
175 |
addListener(SWT.MouseMove, new Listener() {
|
|
176 |
@Override
|
|
177 |
public void handleEvent(final Event e) {
|
|
178 |
handleMouseMove(e);
|
|
179 |
}
|
|
180 |
});
|
|
181 |
|
|
182 |
addListener(SWT.MouseWheel, new Listener() {
|
|
183 |
@Override
|
|
184 |
public void handleEvent(final Event e) {
|
|
185 |
handleMouseWheel(e);
|
|
186 |
}
|
|
187 |
});
|
|
188 |
|
|
189 |
}
|
|
190 |
|
|
191 |
/**
|
|
192 |
* Code executed when the mouse is down
|
|
193 |
*
|
|
194 |
* @param e event
|
|
195 |
*/
|
|
196 |
private void handleMouseDown(final Event e) {
|
|
197 |
|
|
198 |
if (this.upperHover) {
|
|
199 |
this.dragInProgress = true;
|
|
200 |
this.lastSelected = SELECTED_KNOB.UPPER;
|
|
201 |
this.previousUpperValue = this.upperValue;
|
|
202 |
} else if (this.lowerHover) {
|
|
203 |
this.dragInProgress = true;
|
|
204 |
this.lastSelected = SELECTED_KNOB.LOWER;
|
|
205 |
this.previousLowerValue = this.lowerValue;
|
|
206 |
} else if (this.middleHover) {
|
|
207 |
this.dragInProgress = true;
|
|
208 |
this.lastSelected = SELECTED_KNOB.MIDDLE;
|
|
209 |
this.previousMiddleValue = this.middleValue;
|
|
210 |
} else {
|
|
211 |
this.dragInProgress = true;
|
|
212 |
//this.lastSelected = SELECTED_KNOB.NONE;
|
|
213 |
this.lastSelected = SELECTED_KNOB.MIDDLE;
|
|
214 |
this.previousMiddleValue = this.middleValue;
|
|
215 |
handleMouseMove(e);
|
|
216 |
}
|
|
217 |
//System.out.println("MouseDown : "+lastSelected);
|
|
218 |
}
|
|
219 |
|
|
220 |
/**
|
|
221 |
* Code executed when the mouse is up
|
|
222 |
*
|
|
223 |
* @param e event
|
|
224 |
*/
|
|
225 |
private void handleMouseUp(final Event e) {
|
|
226 |
if (!this.dragInProgress) {
|
|
227 |
return;
|
|
228 |
}
|
|
229 |
this.dragInProgress = false;
|
|
230 |
if (!fireSelectionListeners(e)) {
|
|
231 |
if (this.lastSelected == SELECTED_KNOB.UPPER) {
|
|
232 |
this.upperValue = this.previousUpperValue;
|
|
233 |
if (this.middleValue > this.upperValue) this.middleValue = upperValue;
|
|
234 |
} else if (this.lastSelected == SELECTED_KNOB.LOWER) {
|
|
235 |
this.lowerValue = this.previousLowerValue;
|
|
236 |
if (this.middleValue < this.lowerValue) this.middleValue = lowerValue;
|
|
237 |
} else {
|
|
238 |
this.middleValue = this.previousMiddleValue;
|
|
239 |
}
|
|
240 |
redraw();
|
|
241 |
}
|
|
242 |
}
|
|
243 |
|
|
244 |
/**
|
|
245 |
* Fire all selection listeners
|
|
246 |
*
|
|
247 |
* @param event selection event
|
|
248 |
* @return <code>true</code> if no listener cancels the selection,
|
|
249 |
* <code>false</code> otherwise
|
|
250 |
*/
|
|
251 |
private boolean fireSelectionListeners(final Event event) {
|
|
252 |
for (final SelectionListener selectionListener : this.listeners) {
|
|
253 |
final SelectionEvent selectionEvent = new SelectionEvent(event);
|
|
254 |
selectionListener.widgetSelected(selectionEvent);
|
|
255 |
if (!selectionEvent.doit) {
|
|
256 |
return false;
|
|
257 |
}
|
|
258 |
}
|
|
259 |
return true;
|
|
260 |
}
|
|
261 |
|
|
262 |
/**
|
|
263 |
* Code executed when the mouse pointer is moving
|
|
264 |
*
|
|
265 |
* @param e event
|
|
266 |
*/
|
|
267 |
private void handleMouseMove(final Event e) {
|
|
268 |
final int x = e.x, y = e.y;
|
|
269 |
final Image img = this.orientation == SWT.HORIZONTAL ? this.slider : this.vSlider;
|
|
270 |
this.upperHover = x >= this.coordUpper.x && x <= this.coordUpper.x + img.getBounds().width && y >= this.coordUpper.y && y <= this.coordUpper.y + img.getBounds().height;
|
|
271 |
this.middleHover = x >= this.coordMiddle.x && x <= this.coordMiddle.x + img.getBounds().width && y >= this.coordMiddle.y && y <= this.coordMiddle.y + img.getBounds().height;
|
|
272 |
this.lowerHover = x >= this.coordLower.x && x <= this.coordLower.x + img.getBounds().width && y >= this.coordLower.y && y <= this.coordLower.y + img.getBounds().height;
|
|
273 |
|
|
274 |
if (this.dragInProgress) {
|
|
275 |
if (this.orientation == SWT.HORIZONTAL) {
|
|
276 |
final int mouseValue = (int) ((x - 9f) / computePixelSizeForHorizonalSlider()) + this.minimum;
|
|
277 |
if (this.lastSelected == SELECTED_KNOB.UPPER) {
|
|
278 |
this.upperValue = (int) (Math.ceil(mouseValue / this.increment) * this.increment) - this.increment;
|
|
279 |
checkUpperValue();
|
|
280 |
} else if (this.lastSelected == SELECTED_KNOB.LOWER) {
|
|
281 |
this.lowerValue = (int) (Math.ceil(mouseValue / this.increment) * this.increment) - this.increment;
|
|
282 |
checkLowerValue();
|
|
283 |
} else {
|
|
284 |
this.middleValue = (int) (Math.ceil(mouseValue / this.increment) * this.increment) - this.increment;
|
|
285 |
checkMiddleValue();
|
|
286 |
}
|
|
287 |
|
|
288 |
} else {
|
|
289 |
final int mouseValue = (int) ((y - 9f) / computePixelSizeForVerticalSlider()) + this.minimum;
|
|
290 |
if (this.lastSelected == SELECTED_KNOB.UPPER) {
|
|
291 |
this.upperValue = (int) (Math.ceil(mouseValue / this.increment) * this.increment) - this.increment;
|
|
292 |
checkUpperValue();
|
|
293 |
} else if (this.lastSelected == SELECTED_KNOB.LOWER) {
|
|
294 |
this.lowerValue = (int) (Math.ceil(mouseValue / this.increment) * this.increment) - this.increment;
|
|
295 |
checkLowerValue();
|
|
296 |
} else {
|
|
297 |
this.middleValue = (int) (Math.ceil(mouseValue / this.increment) * this.increment) - this.increment;
|
|
298 |
checkMiddleValue();
|
|
299 |
}
|
|
300 |
}
|
|
301 |
}
|
|
302 |
|
|
303 |
redraw();
|
|
304 |
}
|
|
305 |
|
|
306 |
/**
|
|
307 |
* Code executed when the mouse wheel is activated
|
|
308 |
*
|
|
309 |
* @param e event
|
|
310 |
*/
|
|
311 |
private void handleMouseWheel(final Event e) {
|
|
312 |
if (this.lastSelected == SELECTED_KNOB.NONE) {
|
|
313 |
return;
|
|
314 |
}
|
|
315 |
|
|
316 |
if (this.lastSelected == SELECTED_KNOB.LOWER) {
|
|
317 |
this.lowerValue += e.count * this.increment;
|
|
318 |
checkLowerValue();
|
|
319 |
redraw();
|
|
320 |
} else if (this.lastSelected == SELECTED_KNOB.UPPER) {
|
|
321 |
this.upperValue += e.count * this.increment;
|
|
322 |
checkUpperValue();
|
|
323 |
redraw();
|
|
324 |
} else {
|
|
325 |
this.middleValue += e.count * this.increment;
|
|
326 |
checkMiddleValue();
|
|
327 |
redraw();
|
|
328 |
}
|
|
329 |
}
|
|
330 |
|
|
331 |
/**
|
|
332 |
* Check if the lower value is in ranges
|
|
333 |
*/
|
|
334 |
private void checkLowerValue() {
|
|
335 |
if (this.lowerValue < this.minimum) {
|
|
336 |
this.lowerValue = this.minimum;
|
|
337 |
}
|
|
338 |
if (this.lowerValue > this.maximum) {
|
|
339 |
this.lowerValue = this.maximum;
|
|
340 |
}
|
|
341 |
if (this.lowerValue > this.upperValue) {
|
|
342 |
this.lowerValue = this.upperValue;
|
|
343 |
}
|
|
344 |
}
|
|
345 |
|
|
346 |
/**
|
|
347 |
* Check if the middle value is in lowerValue and upperValue range
|
|
348 |
*/
|
|
349 |
private void checkMiddleValue() {
|
|
350 |
if (this.middleValue < this.lowerValue) {
|
|
351 |
this.middleValue = this.lowerValue;
|
|
352 |
}
|
|
353 |
if (this.middleValue > this.upperValue) {
|
|
354 |
this.middleValue = this.upperValue;
|
|
355 |
}
|
|
356 |
}
|
|
357 |
|
|
358 |
/**
|
|
359 |
* Check if the upper value is in ranges
|
|
360 |
*/
|
|
361 |
private void checkUpperValue() {
|
|
362 |
if (this.upperValue < this.minimum) {
|
|
363 |
this.upperValue = this.minimum;
|
|
364 |
}
|
|
365 |
if (this.upperValue > this.maximum) {
|
|
366 |
this.upperValue = this.maximum;
|
|
367 |
}
|
|
368 |
if (this.upperValue < this.lowerValue) {
|
|
369 |
this.upperValue = this.lowerValue;
|
|
370 |
}
|
|
371 |
}
|
|
372 |
|
|
373 |
/**
|
|
374 |
* Draws the widget
|
|
375 |
*
|
|
376 |
* @param e paint event
|
|
377 |
*/
|
|
378 |
private void drawWidget(final PaintEvent e) {
|
|
379 |
final Rectangle rect = this.getClientArea();
|
|
380 |
if (rect.width == 0 || rect.height == 0) {
|
|
381 |
return;
|
|
382 |
}
|
|
383 |
e.gc.setAdvanced(true);
|
|
384 |
e.gc.setAntialias(SWT.ON);
|
|
385 |
if (this.orientation == SWT.HORIZONTAL) {
|
|
386 |
drawHorizontalRangeSlider(e.gc);
|
|
387 |
} else {
|
|
388 |
drawVerticalRangeSlider(e.gc);
|
|
389 |
}
|
|
390 |
|
|
391 |
}
|
|
392 |
|
|
393 |
/**
|
|
394 |
* Draw the range slider (horizontal)
|
|
395 |
*
|
|
396 |
* @param gc graphic context
|
|
397 |
*/
|
|
398 |
private void drawHorizontalRangeSlider(final GC gc) {
|
|
399 |
drawBackgroundHorizontal(gc);
|
|
400 |
drawBarsHorizontal(gc);
|
|
401 |
this.coordUpper = drawHorizontalKnob(gc, this.upperValue, SELECTED_KNOB.UPPER);
|
|
402 |
this.coordMiddle = drawHorizontalKnob(gc, this.middleValue, SELECTED_KNOB.MIDDLE);
|
|
403 |
this.coordLower = drawHorizontalKnob(gc, this.lowerValue, SELECTED_KNOB.LOWER);
|
|
404 |
}
|
|
405 |
|
|
406 |
/**
|
|
407 |
* Draw the background
|
|
408 |
*
|
|
409 |
* @param gc graphic context
|
|
410 |
*/
|
|
411 |
private void drawBackgroundHorizontal(final GC gc) {
|
|
412 |
final Rectangle clientArea = this.getClientArea();
|
|
413 |
|
|
414 |
gc.setBackground(getBackground());
|
|
415 |
gc.fillRectangle(clientArea);
|
|
416 |
|
|
417 |
if (isEnabled()) {
|
|
418 |
gc.setForeground(getForeground());
|
|
419 |
} else {
|
|
420 |
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_GRAY));
|
|
421 |
}
|
|
422 |
gc.drawRoundRectangle(9, 9, clientArea.width - 20, clientArea.height - 20, 3, 3);
|
|
423 |
|
|
424 |
final float pixelSize = computePixelSizeForHorizonalSlider();
|
|
425 |
final int startX = (int) (pixelSize * this.lowerValue);
|
|
426 |
final int endX = (int) (pixelSize * this.upperValue);
|
|
427 |
if (isEnabled()) {
|
|
428 |
gc.setBackground(getForeground());
|
|
429 |
} else {
|
|
430 |
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_GRAY));
|
|
431 |
}
|
|
432 |
gc.fillRectangle(12 + startX, 9, endX - startX - 6, clientArea.height - 20);
|
|
433 |
|
|
434 |
}
|
|
435 |
|
|
436 |
/**
|
|
437 |
* @return how many pixels corresponds to 1 point of value
|
|
438 |
*/
|
|
439 |
private float computePixelSizeForHorizonalSlider() {
|
|
440 |
return (getClientArea().width - 20f) / (this.maximum - this.minimum);
|
|
441 |
}
|
|
442 |
|
|
443 |
/**
|
|
444 |
* Draw the bars
|
|
445 |
*
|
|
446 |
* @param gc graphic context
|
|
447 |
*/
|
|
448 |
private void drawBarsHorizontal(final GC gc) {
|
|
449 |
final Rectangle clientArea = this.getClientArea();
|
|
450 |
if (isEnabled()) {
|
|
451 |
gc.setForeground(getForeground());
|
|
452 |
} else {
|
|
453 |
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_GRAY));
|
|
454 |
}
|
|
455 |
|
|
456 |
final float pixelSize = computePixelSizeForHorizonalSlider();
|
|
457 |
for (int i = 1; i < 10; i++) {
|
|
458 |
final int x = (int) (9 + pixelSize * (this.maximum - this.minimum) / 10 * i);
|
|
459 |
gc.drawLine(x, 4, x, 7);
|
|
460 |
gc.drawLine(x, clientArea.height - 6, x, clientArea.height - 9);
|
|
461 |
}
|
|
462 |
|
|
463 |
}
|
|
464 |
|
|
465 |
/**
|
|
466 |
* Draws an horizontal knob
|
|
467 |
*
|
|
468 |
* @param gc graphic context
|
|
469 |
* @param value corresponding value
|
|
470 |
* @param knob if <code>true</code>, draws the upper knob. If
|
|
471 |
* <code>false</code>, draws the lower knob
|
|
472 |
* @return the coordinate of the upper left corner of the knob
|
|
473 |
*/
|
|
474 |
private Point drawHorizontalKnob(final GC gc, final int value, final SELECTED_KNOB knob) {
|
|
475 |
final float pixelSize = computePixelSizeForHorizonalSlider();
|
|
476 |
final int x = (int) (pixelSize * value);
|
|
477 |
Image image;
|
|
478 |
if (knob == SELECTED_KNOB.UPPER) {
|
|
479 |
if (this.upperHover) {
|
|
480 |
image = this.dragInProgress ? this.sliderDrag : this.sliderHover;
|
|
481 |
} else if (this.lastSelected == SELECTED_KNOB.UPPER) {
|
|
482 |
image = this.sliderSelected;
|
|
483 |
} else {
|
|
484 |
image = this.slider;
|
|
485 |
}
|
|
486 |
} else if (knob == SELECTED_KNOB.LOWER) {
|
|
487 |
if (this.lowerHover) {
|
|
488 |
image = this.dragInProgress ? this.sliderDrag : this.sliderHover;
|
|
489 |
} else if (this.lastSelected == SELECTED_KNOB.LOWER) {
|
|
490 |
image = this.sliderSelected;
|
|
491 |
} else {
|
|
492 |
image = this.slider;
|
|
493 |
}
|
|
494 |
} else {
|
|
495 |
if (this.middleHover) {
|
|
496 |
image = this.dragInProgress ? this.sliderDrag : this.sliderHover;
|
|
497 |
} else if (this.lastSelected == SELECTED_KNOB.MIDDLE) {
|
|
498 |
image = this.sliderSelected;
|
|
499 |
} else {
|
|
500 |
image = this.slider;
|
|
501 |
}
|
|
502 |
}
|
|
503 |
if (isEnabled()) {
|
|
504 |
gc.drawImage(image, x + 5, getClientArea().height / 2 - this.slider.getBounds().height / 2);
|
|
505 |
} else {
|
|
506 |
final Image temp = new Image(getDisplay(), image, SWT.IMAGE_DISABLE);
|
|
507 |
gc.drawImage(temp, x + 5, getClientArea().height / 2 - this.slider.getBounds().height / 2);
|
|
508 |
temp.dispose();
|
|
509 |
}
|
|
510 |
return new Point(x + 5, getClientArea().height / 2 - this.slider.getBounds().height / 2);
|
|
511 |
}
|
|
512 |
|
|
513 |
/**
|
|
514 |
* Draw the range slider (vertical)
|
|
515 |
*
|
|
516 |
* @param gc graphic context
|
|
517 |
*/
|
|
518 |
private void drawVerticalRangeSlider(final GC gc) {
|
|
519 |
drawBackgroundVertical(gc);
|
|
520 |
drawBarsVertical(gc);
|
|
521 |
this.coordUpper = drawVerticalKnob(gc, this.upperValue, SELECTED_KNOB.UPPER);
|
|
522 |
this.coordMiddle = drawVerticalKnob(gc, this.middleValue, SELECTED_KNOB.MIDDLE);
|
|
523 |
this.coordLower = drawVerticalKnob(gc, this.lowerValue, SELECTED_KNOB.LOWER);
|
|
524 |
}
|
|
525 |
|
|
526 |
/**
|
|
527 |
* Draws the background
|
|
528 |
*
|
|
529 |
* @param gc graphic context
|
|
530 |
*/
|
|
531 |
private void drawBackgroundVertical(final GC gc) {
|
|
532 |
final Rectangle clientArea = this.getClientArea();
|
|
533 |
gc.setBackground(getBackground());
|
|
534 |
gc.fillRectangle(clientArea);
|
|
535 |
|
|
536 |
if (isEnabled()) {
|
|
537 |
gc.setForeground(getForeground());
|
|
538 |
} else {
|
|
539 |
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_GRAY));
|
|
540 |
}
|
|
541 |
gc.drawRoundRectangle(9, 9, clientArea.width - 20, clientArea.height - 20, 3, 3);
|
|
542 |
|
|
543 |
final float pixelSize = computePixelSizeForVerticalSlider();
|
|
544 |
final int startY = (int) (pixelSize * this.lowerValue);
|
|
545 |
final int endY = (int) (pixelSize * this.upperValue);
|
|
546 |
if (isEnabled()) {
|
|
547 |
gc.setBackground(getForeground());
|
|
548 |
} else {
|
|
549 |
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_GRAY));
|
|
550 |
}
|
|
551 |
gc.fillRectangle(9, 12 + startY, clientArea.width - 20, endY - startY - 6);
|
|
552 |
|
|
553 |
}
|
|
554 |
|
|
555 |
/**
|
|
556 |
* @return how many pixels corresponds to 1 point of value
|
|
557 |
*/
|
|
558 |
private float computePixelSizeForVerticalSlider() {
|
|
559 |
return (getClientArea().height - 20f) / (this.maximum - this.minimum);
|
|
560 |
}
|
|
561 |
|
|
562 |
/**
|
|
563 |
* Draws the bars
|
|
564 |
*
|
|
565 |
* @param gc graphic context
|
|
566 |
*/
|
|
567 |
private void drawBarsVertical(final GC gc) {
|
|
568 |
final Rectangle clientArea = this.getClientArea();
|
|
569 |
if (isEnabled()) {
|
|
570 |
gc.setForeground(getForeground());
|
|
571 |
} else {
|
|
572 |
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_GRAY));
|
|
573 |
}
|
|
574 |
|
|
575 |
final float pixelSize = computePixelSizeForVerticalSlider();
|
|
576 |
for (int i = 1; i < 10; i++) {
|
|
577 |
final int y = (int) (9 + pixelSize * (this.maximum - this.minimum) / 10 * i);
|
|
578 |
gc.drawLine(4, y, 7, y);
|
|
579 |
gc.drawLine(clientArea.width - 6, y, clientArea.width - 9, y);
|
|
580 |
|
|
581 |
}
|
|
582 |
|
|
583 |
}
|
|
584 |
|
|
585 |
/**
|
|
586 |
* Draws a vertical knob
|
|
587 |
*
|
|
588 |
* @param gc graphic context
|
|
589 |
* @param value corresponding value
|
|
590 |
* @param knob if <code>true</code>, draws the upper knob. If
|
|
591 |
* <code>false</code>, draws the lower knob
|
|
592 |
* @return the coordinate of the upper left corner of the knob
|
|
593 |
*/
|
|
594 |
private Point drawVerticalKnob(final GC gc, final int value, final SELECTED_KNOB knob) {
|
|
595 |
final float pixelSize = computePixelSizeForVerticalSlider();
|
|
596 |
final int y = (int) (pixelSize * value);
|
|
597 |
|
|
598 |
Image image;
|
|
599 |
if (knob == SELECTED_KNOB.UPPER) {
|
|
600 |
if (this.upperHover) {
|
|
601 |
image = this.dragInProgress ? this.vSliderDrag : this.vSliderHover;
|
|
602 |
} else if (this.lastSelected == SELECTED_KNOB.UPPER) {
|
|
603 |
image = this.vSliderSelected;
|
|
604 |
} else {
|
|
605 |
image = this.vSlider;
|
|
606 |
}
|
|
607 |
} else if (knob == SELECTED_KNOB.LOWER) {
|
|
608 |
if (this.lowerHover) {
|
|
609 |
image = this.dragInProgress ? this.vSliderDrag : this.vSliderHover;
|
|
610 |
} else if (this.lastSelected == SELECTED_KNOB.LOWER) {
|
|
611 |
image = this.vSliderSelected;
|
|
612 |
} else {
|
|
613 |
image = this.vSlider;
|
|
614 |
}
|
|
615 |
} else { // MIDDLE
|
|
616 |
if (this.middleHover) {
|
|
617 |
image = this.dragInProgress ? this.vSliderDrag : this.vSliderHover;
|
|
618 |
} else if (this.lastSelected == SELECTED_KNOB.MIDDLE) {
|
|
619 |
image = this.vSliderSelected;
|
|
620 |
} else {
|
|
621 |
image = this.vSlider;
|
|
622 |
}
|
|
623 |
}
|
|
624 |
if (isEnabled()) {
|
|
625 |
gc.drawImage(image, getClientArea().width / 2 - 8, y + 2);
|
|
626 |
} else {
|
|
627 |
final Image temp = new Image(getDisplay(), image, SWT.IMAGE_DISABLE);
|
|
628 |
gc.drawImage(temp, getClientArea().width / 2 - 8, y + 2);
|
|
629 |
temp.dispose();
|
|
630 |
}
|
|
631 |
return new Point(getClientArea().width / 2 - 8, y + 2);
|
|
632 |
}
|
|
633 |
|
|
634 |
/**
|
|
635 |
* Code executed when a key is typed
|
|
636 |
*
|
|
637 |
* @param event event
|
|
638 |
*/
|
|
639 |
private void handleKeyDown(final Event event) {
|
|
640 |
|
|
641 |
boolean needRedraw = false;
|
|
642 |
|
|
643 |
if (this.lastSelected == SELECTED_KNOB.NONE) {
|
|
644 |
this.lastSelected = SELECTED_KNOB.LOWER;
|
|
645 |
}
|
|
646 |
|
|
647 |
switch (event.keyCode) {
|
|
648 |
case SWT.HOME:
|
|
649 |
if (this.lastSelected == SELECTED_KNOB.UPPER) {
|
|
650 |
this.upperValue = this.minimum;
|
|
651 |
} else if (this.lastSelected == SELECTED_KNOB.LOWER) {
|
|
652 |
this.lowerValue = this.minimum;
|
|
653 |
} else {
|
|
654 |
this.middleValue = this.minimum;
|
|
655 |
}
|
|
656 |
needRedraw = true;
|
|
657 |
break;
|
|
658 |
case SWT.END:
|
|
659 |
if (this.lastSelected == SELECTED_KNOB.UPPER) {
|
|
660 |
this.upperValue = this.maximum;
|
|
661 |
} if (this.lastSelected == SELECTED_KNOB.LOWER) {
|
|
662 |
this.lowerValue = this.maximum;
|
|
663 |
} else {
|
|
664 |
this.middleValue = this.maximum;
|
|
665 |
}
|
|
666 |
needRedraw = true;
|
|
667 |
break;
|
|
668 |
case SWT.PAGE_UP:
|
|
669 |
if (this.lastSelected == SELECTED_KNOB.UPPER) {
|
|
670 |
this.upperValue += this.pageIncrement;
|
|
671 |
} else if (this.lastSelected == SELECTED_KNOB.LOWER) {
|
|
672 |
this.lowerValue += this.pageIncrement;
|
|
673 |
} else {
|
|
674 |
this.middleValue += this.pageIncrement;
|
|
675 |
}
|
|
676 |
needRedraw = true;
|
|
677 |
break;
|
|
678 |
case SWT.PAGE_DOWN:
|
|
679 |
if (this.lastSelected == SELECTED_KNOB.UPPER) {
|
|
680 |
this.upperValue -= this.pageIncrement;
|
|
681 |
} else if (this.lastSelected == SELECTED_KNOB.LOWER) {
|
|
682 |
this.lowerValue -= this.pageIncrement;
|
|
683 |
} else {
|
|
684 |
this.middleValue -= this.pageIncrement;
|
|
685 |
}
|
|
686 |
needRedraw = true;
|
|
687 |
break;
|
|
688 |
case SWT.ARROW_LEFT:
|
|
689 |
case SWT.ARROW_UP:
|
|
690 |
if (this.lastSelected == SELECTED_KNOB.UPPER) {
|
|
691 |
this.upperValue -= this.increment;
|
|
692 |
} else if (this.lastSelected == SELECTED_KNOB.LOWER) {
|
|
693 |
this.lowerValue -= this.increment;
|
|
694 |
} else {
|
|
695 |
this.middleValue -= this.increment;
|
|
696 |
}
|
|
697 |
needRedraw = true;
|
|
698 |
break;
|
|
699 |
case SWT.ARROW_RIGHT:
|
|
700 |
case SWT.ARROW_DOWN:
|
|
701 |
if (this.lastSelected == SELECTED_KNOB.UPPER) {
|
|
702 |
this.upperValue += this.increment;
|
|
703 |
} else if (this.lastSelected == SELECTED_KNOB.LOWER) {
|
|
704 |
this.lowerValue += this.increment;
|
|
705 |
} else {
|
|
706 |
this.middleValue += this.increment;
|
|
707 |
}
|
|
708 |
needRedraw = true;
|
|
709 |
break;
|
|
710 |
}
|
|
711 |
|
|
712 |
if (needRedraw) {
|
|
713 |
if (this.lastSelected == SELECTED_KNOB.UPPER) {
|
|
714 |
checkUpperValue();
|
|
715 |
} else if (this.lastSelected == SELECTED_KNOB.LOWER) {
|
|
716 |
checkLowerValue();
|
|
717 |
} else {
|
|
718 |
checkMiddleValue();
|
|
719 |
}
|
|
720 |
redraw();
|
|
721 |
}
|
|
722 |
}
|
|
723 |
|
|
724 |
/**
|
|
725 |
* Adds the listener to the collection of listeners who will be notified
|
|
726 |
* when the user changes the receiver's value, by sending it one of the
|
|
727 |
* messages defined in the <code>SelectionListener</code> interface.
|
|
728 |
* <p>
|
|
729 |
* <code>widgetSelected</code> is called when the user changes the
|
|
730 |
* receiver's value. <code>widgetDefaultSelected</code> is not called.
|
|
731 |
* </p>
|
|
732 |
*
|
|
733 |
* @param listener the listener which should be notified
|
|
734 |
*
|
|
735 |
* @exception IllegalArgumentException <ul>
|
|
736 |
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
737 |
* </ul>
|
|
738 |
* @exception SWTException <ul>
|
|
739 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
740 |
* disposed</li>
|
|
741 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
742 |
* thread that created the receiver</li>
|
|
743 |
* </ul>
|
|
744 |
*
|
|
745 |
* @see SelectionListener
|
|
746 |
* @see #removeSelectionListener
|
|
747 |
*/
|
|
748 |
public void addSelectionListener(final SelectionListener listener) {
|
|
749 |
checkWidget();
|
|
750 |
this.listeners.add(listener);
|
|
751 |
}
|
|
752 |
|
|
753 |
/**
|
|
754 |
* @see org.eclipse.swt.widgets.Composite#computeSize(int, int, boolean)
|
|
755 |
*/
|
|
756 |
@Override
|
|
757 |
public Point computeSize(final int wHint, final int hHint, final boolean changed) {
|
|
758 |
final int width, height;
|
|
759 |
checkWidget();
|
|
760 |
if (this.orientation == SWT.HORIZONTAL) {
|
|
761 |
if (wHint < 100) {
|
|
762 |
width = 100;
|
|
763 |
} else {
|
|
764 |
width = wHint;
|
|
765 |
}
|
|
766 |
|
|
767 |
if (hHint < 30) {
|
|
768 |
height = 30;
|
|
769 |
} else {
|
|
770 |
height = hHint;
|
|
771 |
}
|
|
772 |
} else {
|
|
773 |
if (wHint < 30) {
|
|
774 |
width = 30;
|
|
775 |
} else {
|
|
776 |
width = wHint;
|
|
777 |
}
|
|
778 |
|
|
779 |
if (hHint < 100) {
|
|
780 |
height = 100;
|
|
781 |
} else {
|
|
782 |
height = hHint;
|
|
783 |
}
|
|
784 |
}
|
|
785 |
|
|
786 |
return new Point(width, height);
|
|
787 |
}
|
|
788 |
|
|
789 |
/**
|
|
790 |
* Returns the amount that the selected receiver's value will be modified by
|
|
791 |
* when the up/down (or right/left) arrows are pressed.
|
|
792 |
*
|
|
793 |
* @return the increment
|
|
794 |
*
|
|
795 |
* @exception SWTException <ul>
|
|
796 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
797 |
* disposed</li>
|
|
798 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
799 |
* thread that created the receiver</li>
|
|
800 |
* </ul>
|
|
801 |
*/
|
|
802 |
public int getIncrement() {
|
|
803 |
checkWidget();
|
|
804 |
return this.increment;
|
|
805 |
}
|
|
806 |
|
|
807 |
/**
|
|
808 |
* Returns the 'lower selection', which is the lower receiver's position.
|
|
809 |
*
|
|
810 |
* @return the selection
|
|
811 |
*
|
|
812 |
* @exception SWTException <ul>
|
|
813 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
814 |
* disposed</li>
|
|
815 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
816 |
* thread that created the receiver</li>
|
|
817 |
* </ul>
|
|
818 |
*/
|
|
819 |
public int getLowerValue() {
|
|
820 |
checkWidget();
|
|
821 |
return this.lowerValue;
|
|
822 |
}
|
|
823 |
|
|
824 |
public SELECTED_KNOB getLastSelectedKnob() {
|
|
825 |
return lastSelected;
|
|
826 |
}
|
|
827 |
|
|
828 |
/**
|
|
829 |
* Returns the 'middle selection', which is the middle receiver's position.
|
|
830 |
*
|
|
831 |
* @return the selection
|
|
832 |
*
|
|
833 |
* @exception SWTException <ul>
|
|
834 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
835 |
* disposed</li>
|
|
836 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
837 |
* thread that created the receiver</li>
|
|
838 |
* </ul>
|
|
839 |
*/
|
|
840 |
public int getMiddleValue() {
|
|
841 |
checkWidget();
|
|
842 |
return this.middleValue;
|
|
843 |
}
|
|
844 |
|
|
845 |
/**
|
|
846 |
* Returns the maximum value which the receiver will allow.
|
|
847 |
*
|
|
848 |
* @return the maximum
|
|
849 |
*
|
|
850 |
* @exception SWTException <ul>
|
|
851 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
852 |
* disposed</li>
|
|
853 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
854 |
* thread that created the receiver</li>
|
|
855 |
* </ul>
|
|
856 |
*/
|
|
857 |
public int getMaximum() {
|
|
858 |
checkWidget();
|
|
859 |
return this.maximum;
|
|
860 |
}
|
|
861 |
|
|
862 |
/**
|
|
863 |
* Returns the minimum value which the receiver will allow.
|
|
864 |
*
|
|
865 |
* @return the minimum
|
|
866 |
*
|
|
867 |
* @exception SWTException <ul>
|
|
868 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
869 |
* disposed</li>
|
|
870 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
871 |
* thread that created the receiver</li>
|
|
872 |
* </ul>
|
|
873 |
*/
|
|
874 |
public int getMinimum() {
|
|
875 |
checkWidget();
|
|
876 |
return this.minimum;
|
|
877 |
}
|
|
878 |
|
|
879 |
/**
|
|
880 |
* Returns the amount that the selected receiver's value will be modified by
|
|
881 |
* when the page increment/decrement areas are selected.
|
|
882 |
*
|
|
883 |
* @return the page increment
|
|
884 |
*
|
|
885 |
* @exception SWTException <ul>
|
|
886 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
887 |
* disposed</li>
|
|
888 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
889 |
* thread that created the receiver</li>
|
|
890 |
* </ul>
|
|
891 |
*/
|
|
892 |
public int getPageIncrement() {
|
|
893 |
checkWidget();
|
|
894 |
return this.pageIncrement;
|
|
895 |
}
|
|
896 |
|
|
897 |
/**
|
|
898 |
* Returns the 'selection', which is an array where the first element is the
|
|
899 |
* lower selection, and the second element is the upper selection
|
|
900 |
*
|
|
901 |
* @return the selection
|
|
902 |
*
|
|
903 |
* @exception SWTException <ul>
|
|
904 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
905 |
* disposed</li>
|
|
906 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
907 |
* thread that created the receiver</li>
|
|
908 |
* </ul>
|
|
909 |
*/
|
|
910 |
public int[] getSelection() {
|
|
911 |
checkWidget();
|
|
912 |
final int[] selection = new int[3];
|
|
913 |
selection[0] = this.lowerValue;
|
|
914 |
selection[1] = this.middleValue;
|
|
915 |
selection[2] = this.upperValue;
|
|
916 |
return selection;
|
|
917 |
}
|
|
918 |
|
|
919 |
/**
|
|
920 |
* Returns the 'upper selection', which is the upper receiver's position.
|
|
921 |
*
|
|
922 |
* @return the selection
|
|
923 |
*
|
|
924 |
* @exception SWTException <ul>
|
|
925 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
926 |
* disposed</li>
|
|
927 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
928 |
* thread that created the receiver</li>
|
|
929 |
* </ul>
|
|
930 |
*/
|
|
931 |
public int getUpperValue() {
|
|
932 |
checkWidget();
|
|
933 |
return this.upperValue;
|
|
934 |
}
|
|
935 |
|
|
936 |
/**
|
|
937 |
* Removes the listener from the collection of listeners who will be
|
|
938 |
* notified when the user changes the receiver's value.
|
|
939 |
*
|
|
940 |
* @param listener the listener which should no longer be notified
|
|
941 |
*
|
|
942 |
* @exception IllegalArgumentException <ul>
|
|
943 |
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
|
|
944 |
* </ul>
|
|
945 |
* @exception SWTException <ul>
|
|
946 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
947 |
* disposed</li>
|
|
948 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
949 |
* thread that created the receiver</li>
|
|
950 |
* </ul>
|
|
951 |
*
|
|
952 |
* @see SelectionListener
|
|
953 |
* @see #addSelectionListener
|
|
954 |
*/
|
|
955 |
public void removeSelectionListener(final SelectionListener listener) {
|
|
956 |
checkWidget();
|
|
957 |
this.listeners.remove(listener);
|
|
958 |
}
|
|
959 |
|
|
960 |
/**
|
|
961 |
* Sets the amount that the selected receiver's value will be modified by
|
|
962 |
* when the up/down (or right/left) arrows are pressed to the argument,
|
|
963 |
* which must be at least one.
|
|
964 |
*
|
|
965 |
* @param increment the new increment (must be greater than zero)
|
|
966 |
*
|
|
967 |
* @exception SWTException <ul>
|
|
968 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
969 |
* disposed</li>
|
|
970 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
971 |
* thread that created the receiver</li>
|
|
972 |
* </ul>
|
|
973 |
*/
|
|
974 |
public void setIncrement(final int increment) {
|
|
975 |
checkWidget();
|
|
976 |
this.increment = increment;
|
|
977 |
redraw();
|
|
978 |
}
|
|
979 |
|
|
980 |
/**
|
|
981 |
* Sets the 'lower selection', which is the receiver's lower value, to the
|
|
982 |
* argument which must be greater than or equal to zero.
|
|
983 |
*
|
|
984 |
* @param value the new selection (must be zero or greater)
|
|
985 |
*
|
|
986 |
* @exception SWTException <ul>
|
|
987 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
988 |
* disposed</li>
|
|
989 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
990 |
* thread that created the receiver</li>
|
|
991 |
* </ul>
|
|
992 |
*/
|
|
993 |
public void setLowerValue(final int value) {
|
|
994 |
checkWidget();
|
|
995 |
if (this.minimum <= value && value <= this.maximum && value <= this.upperValue) {
|
|
996 |
this.lowerValue = value;
|
|
997 |
|
|
998 |
if (middleValue < lowerValue) middleValue = lowerValue;
|
|
999 |
}
|
|
1000 |
|
|
1001 |
redraw();
|
|
1002 |
}
|
|
1003 |
|
|
1004 |
/**
|
|
1005 |
* Sets the maximum value that the receiver will allow. This new value will
|
|
1006 |
* be ignored if it is not greater than the receiver's current minimum
|
|
1007 |
* value. If the new maximum is applied then the receiver's selection value
|
|
1008 |
* will be adjusted if necessary to fall within its new range.
|
|
1009 |
*
|
|
1010 |
* @param value the new maximum, which must be greater than the current
|
|
1011 |
* minimum
|
|
1012 |
*
|
|
1013 |
* @exception SWTException <ul>
|
|
1014 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
1015 |
* disposed</li>
|
|
1016 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
1017 |
* thread that created the receiver</li>
|
|
1018 |
* </ul>
|
|
1019 |
*/
|
|
1020 |
public void setMaximum(final int value) {
|
|
1021 |
checkWidget();
|
|
1022 |
if (this.minimum <= value) {
|
|
1023 |
this.maximum = value;
|
|
1024 |
if (this.lowerValue > this.maximum) {
|
|
1025 |
this.lowerValue = this.maximum;
|
|
1026 |
}
|
|
1027 |
if (this.upperValue > this.maximum) {
|
|
1028 |
this.upperValue = this.maximum;
|
|
1029 |
}
|
|
1030 |
if (middleValue > this.maximum) {
|
|
1031 |
middleValue = maximum;
|
|
1032 |
}
|
|
1033 |
}
|
|
1034 |
redraw();
|
|
1035 |
}
|
|
1036 |
|
|
1037 |
/**
|
|
1038 |
* Sets the minimum value that the receiver will allow. This new value will
|
|
1039 |
* be ignored if it is negative or is not less than the receiver's current
|
|
1040 |
* maximum value. If the new minimum is applied then the receiver's
|
|
1041 |
* selection value will be adjusted if necessary to fall within its new
|
|
1042 |
* range.
|
|
1043 |
*
|
|
1044 |
* @param value the new minimum, which must be nonnegative and less than the
|
|
1045 |
* current maximum
|
|
1046 |
*
|
|
1047 |
* @exception SWTException <ul>
|
|
1048 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
1049 |
* disposed</li>
|
|
1050 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
1051 |
* thread that created the receiver</li>
|
|
1052 |
* </ul>
|
|
1053 |
*/
|
|
1054 |
public void setMinimum(final int value) {
|
|
1055 |
checkWidget();
|
|
1056 |
if (this.maximum >= value) {
|
|
1057 |
this.minimum = value;
|
|
1058 |
if (this.lowerValue < this.minimum) {
|
|
1059 |
this.lowerValue = this.minimum;
|
|
1060 |
}
|
|
1061 |
if (this.upperValue < this.minimum) {
|
|
1062 |
this.upperValue = this.minimum;
|
|
1063 |
}
|
|
1064 |
if (this.middleValue < this.minimum) {
|
|
1065 |
this.middleValue = this.minimum;
|
|
1066 |
}
|
|
1067 |
}
|
|
1068 |
redraw();
|
|
1069 |
}
|
|
1070 |
|
|
1071 |
/**
|
|
1072 |
* Sets the amount that the receiver's value will be modified by when the
|
|
1073 |
* page increment/decrement areas are selected to the argument, which must
|
|
1074 |
* be at least one.
|
|
1075 |
*
|
|
1076 |
* @param pageIncrement the page increment (must be greater than zero)
|
|
1077 |
*
|
|
1078 |
* @exception SWTException <ul>
|
|
1079 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
1080 |
* disposed</li>
|
|
1081 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
1082 |
* thread that created the receiver</li>
|
|
1083 |
* </ul>
|
|
1084 |
*/
|
|
1085 |
public void setPageIncrement(final int pageIncrement) {
|
|
1086 |
checkWidget();
|
|
1087 |
this.pageIncrement = pageIncrement;
|
|
1088 |
}
|
|
1089 |
|
|
1090 |
/**
|
|
1091 |
* Sets the 'selection', which is the receiver's value, to the argument
|
|
1092 |
* which must be greater than or equal to zero.
|
|
1093 |
*
|
|
1094 |
* @param value the new selection (first value is lower value, second value
|
|
1095 |
* is upper value)
|
|
1096 |
*
|
|
1097 |
* @exception SWTException <ul>
|
|
1098 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
1099 |
* disposed</li>
|
|
1100 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
1101 |
* thread that created the receiver</li>
|
|
1102 |
* </ul>
|
|
1103 |
*/
|
|
1104 |
public void setSelection(final int[] values) {
|
|
1105 |
if (values.length != 3) return;
|
|
1106 |
|
|
1107 |
checkWidget();
|
|
1108 |
setLowerValue(values[0]);
|
|
1109 |
setMiddleValue(values[1]);
|
|
1110 |
setUpperValue(values[2]);
|
|
1111 |
checkUpperValue();
|
|
1112 |
checkLowerValue();
|
|
1113 |
checkMiddleValue();
|
|
1114 |
redraw();
|
|
1115 |
}
|
|
1116 |
|
|
1117 |
/**
|
|
1118 |
* Sets the 'selection', which is the receiver's value, argument which must
|
|
1119 |
* be greater than or equal to zero.
|
|
1120 |
*
|
|
1121 |
* @param lowerValue the new lower selection (must be zero or greater)
|
|
1122 |
* @param upperValue the new upper selection (must be zero or greater)
|
|
1123 |
*
|
|
1124 |
* @exception SWTException <ul>
|
|
1125 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been
|
|
1126 |
* disposed</li>
|
|
1127 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
|
|
1128 |
* thread that created the receiver</li>
|
|
1129 |
* </ul>
|
|
1130 |
*/
|
|
1131 |
public void setSelection(final int lowerValue, final int middleValue, final int upperValue) {
|
|
1132 |
checkWidget();
|
|
1133 |
setLowerValue(lowerValue);
|
|
1134 |
setMiddleValue(middleValue);
|
|
1135 |
setUpperValue(upperValue);
|