Java Reference
In-Depth Information
canvas = new Canvas(canvasPanel, SWT.NONE);
canvas.setLayoutData(new RowData(200, 200));
canvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent paintEvent) {
final GC gc = paintEvent.gc;
final Color strokeColor = new Color(display, model.strokeColor);
gc.setBackground(strokeColor);
gc.fillRectangle(0, 0, 200, 200);
final Color fillColor = new Color(display, model.fillColor);
gc.setBackground(fillColor);
gc.fillRectangle(10, 10, 180, 180);
strokeColor.dispose();
fillColor.dispose();
}
});
Composite buttonPanel = new Composite(frame, SWT.NONE);
RowLayout buttonPanelLayout = new RowLayout(SWT.HORIZONTAL);
buttonPanelLayout.spacing = 10;
buttonPanelLayout.center = true;
buttonPanel.setLayout(buttonPanelLayout);
changeFillButton = new Button(buttonPanel, SWT.NONE);
changeFillButton.setText("Change Fill");
changeStrokeButton = new Button(buttonPanel, SWT.NONE);
changeStrokeButton.setText("Change Stroke");
mouseLocation = new Label(buttonPanel, SWT.NONE);
mouseLocation.setLayoutData(new RowData(50, 15));
frame.pack();
}
}
private static class Controller {
private View view;
private Controller(final Model model, final View view) {
this.view = view;
view.changeFillButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (model.fillColor.equals(model.LIGHT_GRAY)) {
model.fillColor = model.GRAY;
} else {
model.fillColor = model.LIGHT_GRAY;
}
view.canvas.redraw();
}
});
Search WWH ::




Custom Search