An SWT Canvas
can be used to provide custom rendering for a view. As a starting point for drawing a clock, the Canvas
will use drawArc()
to create a circle.
Remove the content of
ClockView
leaving behind an empty implementation of thesetFocus()
andcreatePartControl()
methods.Run the target Eclipse instance and see that
ClockView
is now empty.In the
createPartControl()
method, do the following:Create a new
Canvas
, which is a drawable widget.Add
PaintListener
to theCanvas
.Get
gc
fromPaintEvent
and calldrawArc()
to draw a circle.
The code will look like:
import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.widgets.*; import org.eclipse.ui.part.ViewPart; public class ClockView extends ViewPart { public void createPartControl(Composite parent) { final Canvas clock = new Canvas(parent,SWT.NONE); clock.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawArc(e.x,e...