SWTSkinObjectSliderpublic class SWTSkinObjectSlider extends SWTSkinObjectBasic implements MouseMoveListener, MouseListener, PaintListener
Fields Summary |
---|
private org.eclipse.swt.graphics.Image | imageFG | private Object | imageFGLeft | private Object | imageFGRight | private org.eclipse.swt.widgets.Canvas | canvas | private org.eclipse.swt.graphics.Image | imageThumbRight | private org.eclipse.swt.graphics.Image | imageThumb | private org.eclipse.swt.graphics.Image | imageThumbLeft | private org.eclipse.swt.graphics.Image | imageBGRight | private org.eclipse.swt.graphics.Image | imageBG | private org.eclipse.swt.graphics.Image | imageBGLeft | private double | percent | private org.eclipse.swt.graphics.Rectangle | imageFGbounds | private org.eclipse.swt.graphics.Rectangle | imageBGbounds | private org.eclipse.swt.graphics.Rectangle | imageThumbBounds | private org.eclipse.swt.graphics.Point | maxSize | private boolean | mouseDown | private boolean | mouseMoveAdjusts | private ArrayList | listeners | private double | draggingPercent | private boolean | disabled |
Constructors Summary |
---|
public SWTSkinObjectSlider(SWTSkin skin, SWTSkinProperties skinProperties, String sID, String sConfigID, String[] typeParams, SWTSkinObject parent)
super(skin, skinProperties, sID, sConfigID, "slider", parent);
String sSuffix = ".complete";
ImageLoader imageLoader = skin.getImageLoader(properties);
Image[] images = imageLoader.getImages(sConfigID + sSuffix);
if (images.length == 1 && ImageLoader.isRealImage(images[0])) {
imageFG = images[0];
imageFGLeft = imageLoader.getImage(sConfigID + sSuffix + "-left");
imageFGRight = imageLoader.getImage(sConfigID + sSuffix + "-right");
} else if (images.length == 3 && ImageLoader.isRealImage(images[2])) {
imageFGLeft = images[0];
imageFG = images[1];
imageFGRight = images[2];
}
if (imageFG != null) {
imageFGbounds = imageFG.getBounds();
}
sSuffix = ".incomplete";
images = imageLoader.getImages(sConfigID + sSuffix);
if (images.length == 1 && ImageLoader.isRealImage(images[0])) {
imageBG = images[0];
imageBGLeft = imageLoader.getImage(sConfigID + sSuffix + "-left");
imageBGRight = imageLoader.getImage(sConfigID + sSuffix + "-right");
} else if (images.length == 3 && ImageLoader.isRealImage(images[2])) {
imageBGLeft = images[0];
imageBG = images[1];
imageBGRight = images[2];
}
if (imageBG != null) {
imageBGbounds = imageBG.getBounds();
}
sSuffix = ".thumb";
images = imageLoader.getImages(sConfigID + sSuffix);
if (images.length == 1) {
imageThumb = images[0];
imageThumbLeft = imageLoader.getImage(sConfigID + sSuffix + "-left");
imageThumbRight = imageLoader.getImage(sConfigID + sSuffix + "-right");
} else if (images.length == 3 && ImageLoader.isRealImage(images[2])) {
imageThumbLeft = images[0];
imageThumb = images[1];
imageThumbRight = images[2];
}
if (imageThumb != null) {
imageThumbBounds = imageThumb.getBounds();
}
maxSize = buildMaxSize(new Rectangle[] {
imageThumbBounds,
imageBGbounds,
imageFGbounds
});
if (skinProperties.getStringValue(sConfigID + ".width", "").equalsIgnoreCase(
"auto")) {
maxSize.x = 0;
}
int style = SWT.NONE;
if (skinProperties.getIntValue(sConfigID + ".border", 0) == 1) {
style |= SWT.BORDER;
}
Composite createOn;
if (parent == null) {
createOn = skin.getShell();
} else {
createOn = (Composite) parent.getControl();
}
canvas = new Canvas(createOn, style);
canvas.setLayoutData(new FormData(maxSize.x == 0 ? SWT.DEFAULT
: maxSize.x, maxSize.y));
canvas.setSize(SWT.DEFAULT, maxSize.y);
setControl(canvas);
canvas.addPaintListener(this);
canvas.addMouseListener(this);
canvas.addMouseMoveListener(this);
|
Methods Summary |
---|
public void | addListener(com.aelitis.azureus.ui.swt.skin.SWTSkinObjectSlider$SWTSkinListenerSliderSelection listener)
listeners.add(listener);
| private boolean | areDoublesEqual(double a, double b)
return Math.abs(a - b) < 0.000001;
| private org.eclipse.swt.graphics.Point | buildMaxSize(org.eclipse.swt.graphics.Rectangle[] bounds)
Point maxSize = new Point(0, 0);
for (int i = 0; i < bounds.length; i++) {
if (bounds[i] == null) {
continue;
}
if (bounds[i].width > maxSize.x) {
maxSize.x = bounds[i].width;
}
if (bounds[i].height > maxSize.y) {
maxSize.y = bounds[i].height;
}
}
return maxSize;
| public boolean | getMouseMoveAdjusts()
return mouseMoveAdjusts;
| public double | getPercent()
return percent;
| public boolean | isDisabled()
return disabled;
| public void | mouseDoubleClick(MouseEvent e)
| public void | mouseDown(MouseEvent e)
if (disabled) {
return;
}
mouseDown = true;
int offset = imageThumbBounds.width / 2;
int sizeX = maxSize.x;
if (maxSize.x == 0) {
sizeX = canvas.getClientArea().width;
}
float newPercent = (e.x - offset)
/ (float) (sizeX - imageThumbBounds.width);
if (mouseMoveAdjusts) {
setPercent(newPercent, true);
} else {
draggingPercent = validatePercent(newPercent, true);
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
if (canvas != null && !canvas.isDisposed()) {
canvas.redraw();
canvas.update();
}
}
});
}
| public void | mouseMove(MouseEvent e)
if (disabled) {
return;
}
if (mouseDown) {
int offset = imageThumbBounds.width / 2;
int sizeX = maxSize.x;
if (maxSize.x == 0) {
sizeX = canvas.getClientArea().width;
}
float newPercent = (e.x - offset)
/ (float) (sizeX - imageThumbBounds.width);
if (mouseMoveAdjusts) {
setPercent(newPercent, true);
} else {
draggingPercent = validatePercent(newPercent, true);
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
if (canvas != null && !canvas.isDisposed()) {
canvas.redraw();
canvas.update();
}
}
});
}
}
| public void | mouseUp(MouseEvent e)
if (disabled) {
return;
}
mouseDown = false;
if (!mouseMoveAdjusts) {
int offset = imageThumbBounds.width / 2;
int sizeX = maxSize.x;
if (maxSize.x == 0) {
sizeX = canvas.getClientArea().width;
}
float newPercent = (e.x - offset)
/ (float) (sizeX - imageThumbBounds.width);
setPercent(newPercent, true);
}
| public void | paintControl(PaintEvent e)
int fullWidth = maxSize.x == 0 || imageFGbounds == null
? canvas.getClientArea().width : imageFGbounds.width;
if (percent > 0 && imageFG != null) {
int xDrawTo = (int) (fullWidth * percent);
int xDrawToSrc = xDrawTo > imageFGbounds.width ? imageFGbounds.width
: xDrawTo;
int y = (maxSize.y - imageFGbounds.height) / 2;
e.gc.drawImage(imageFG, 0, 0, xDrawToSrc, imageFGbounds.height, 0, y,
xDrawTo, imageFGbounds.height);
}
if (percent < 100 && imageBG != null) {
int xDrawFrom = (int) (imageBGbounds.width * percent);
int xDrawWidth = imageBGbounds.width - xDrawFrom;
e.gc.drawImage(imageBG, xDrawFrom, 0, xDrawWidth, imageFGbounds.height,
xDrawFrom, 0, xDrawWidth, imageFGbounds.height);
}
int drawWidth = fullWidth - imageThumbBounds.width;
int xThumbPos = (int) ((mouseDown && !mouseMoveAdjusts ? draggingPercent : percent) * drawWidth);
e.gc.drawImage(imageThumb, xThumbPos, 0);
| public void | setDisabled(boolean disabled)
if (disabled == this.disabled) {
return;
}
this.disabled = disabled;
if (disabled) {
mouseDown = false;
}
| public void | setMouseMoveAdjusts(boolean mouseMoveAdjusts)
this.mouseMoveAdjusts = mouseMoveAdjusts;
| public void | setPercent(double percent)
setPercent(percent, false);
| private void | setPercent(double newPercent, boolean triggerListeners)
if (areDoublesEqual(percent, newPercent)) {
return;
}
newPercent = validatePercent(newPercent, triggerListeners);
if (areDoublesEqual(percent, newPercent)) {
return;
}
this.percent = newPercent;
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
if (canvas != null && !canvas.isDisposed()) {
canvas.redraw();
canvas.update();
}
}
});
if (triggerListeners) {
Object[] listenersArray = listeners.toArray();
for (int i = 0; i < listenersArray.length; i++) {
SWTSkinListenerSliderSelection l = (SWTSkinListenerSliderSelection) listenersArray[i];
l.selectionChanged(this.percent);
}
}
| private double | validatePercent(double percent, boolean triggerListeners)
if (triggerListeners) {
Object[] listenersArray = listeners.toArray();
for (int i = 0; i < listenersArray.length; i++) {
SWTSkinListenerSliderSelection l = (SWTSkinListenerSliderSelection) listenersArray[i];
Double changedPercent = l.selectionChanging(this.percent, percent);
if (changedPercent != null) {
return changedPercent.floatValue();
}
}
}
if (percent < 0) {
return 0;
} else if (percent > 1) {
return 1;
}
return percent;
|
|