canvas = new Canvas(shell, SWT.BORDER);
canvas.setCursor(cursor);
data = new FormData();
data.width = displayWidth;
data.height = displayHeight;
data.top = new FormAttachment(title, 5);
canvas.setLayoutData(data);
canvas.addListener(SWT.MouseDown, moveImageListener);
canvas.addListener(SWT.MouseUp, moveImageListener);
canvas.addListener(SWT.MouseMove, moveImageListener);
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent arg0) {
drawCurrentImage();
}
});
offset.x = (minWidth - currentImage.getBounds().width) / 2;
offset.y = (minHeight - currentImage.getBounds().height) / 2;
Label label = new Label(shell, SWT.WRAP);
//The label text depends on the presence of the scale,
//Thefore we delay the size computation as well as
//Assiging any FormData (layout) to it see (1)
//The Control to witch the Buttons OK and Cancel are going to be attached
//Depends on the presence of the scale
Control attach = label;
if (minZoomRatio < 1) {
scale = new Scale(shell, SWT.HORIZONTAL);
data = new FormData();
data.width = displayWidth;
data.top = new FormAttachment(label, 5);
scale.setLayoutData(data);
scale.setMaximum((int) (RESIZE_STEPS * maxZoomRatio));
scale.setMinimum((int) (RESIZE_STEPS * minZoomRatio));
scale.setIncrement((int) ((maxZoomRatio - minZoomRatio) * RESIZE_STEPS / 10));
scale.setPageIncrement((int) ((maxZoomRatio - minZoomRatio)
* RESIZE_STEPS / 10));
scale.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event arg0) {
final long timestamp = SystemTime.getCurrentTime();
lastUpdate = timestamp;
final int position = scale.getSelection();
AEThread t = new AEThread("") {
public void runSupport() {
try {
Thread.sleep(150);
} catch (Exception e) {
e.printStackTrace();
}
if (timestamp == lastUpdate) {
if (display != null && !display.isDisposed()) {
display.asyncExec(new Runnable() {
public void run() {
refreshCurrentImage(position);
}
});
}
}
}
};
t.setDaemon(true);
t.start();
}
});
attach = scale;
label.setText(MessageText.getString("ImageResizer.move.image.with.slider"));
} else {
label.setText(MessageText.getString("ImageResizer.move.image"));
}
// (1) Layout of the label, depending on the text in it
int width = label.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
if (width > displayWidth) {
width = displayWidth;
}
data = new FormData();
data.width = width;
data.top = new FormAttachment(canvas, 5);
data.left = new FormAttachment(canvas, 0, SWT.CENTER);
label.setLayoutData(data);
Button btnCancel = new Button(shell, SWT.PUSH);
btnCancel.setText("Cancel");
data = new FormData();
data.width = 70;
data.top = new FormAttachment(attach, 10);
data.right = new FormAttachment(100, -10);
btnCancel.setLayoutData(data);
btnCancel.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event arg0) {
result = null;
done = true;
dispose();
imageResizerListener.imageResized(result);
}
});
Button btnOk = new Button(shell, SWT.PUSH);
btnOk.setText("OK");
data = new FormData();
data.width = 70;
data.top = new FormAttachment(attach, 10);
data.right = new FormAttachment(btnCancel, -10);
btnOk.setLayoutData(data);
btnOk.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event arg0) {
result = computeResultImage();
done = true;