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 the
ClockView
, leaving behind an empty implementation of thesetFocus
andcreatePartControl
methods.Run the target Eclipse instance and you will see that the
ClockView
is now empty.Create a new method called
drawClock
that takes aPaintEvent
, and use the graphics contextgc
from the event to draw the circle.In the
createPartControl
method, do the following:Create a
new Canvas
, which is a drawable widget.Add a
PaintListener
to theCanvas
that uses a method reference to thedrawClock
method.
The code will look like this:
package com.packtpub.e4.clock.ui.views; 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) ...