-
Notifications
You must be signed in to change notification settings - Fork 4
Decorators
greipadmin edited this page Dec 15, 2018
·
16 revisions
Decorators are graphical components to visualize data or images. You can also use all decorators for your own widgets.
IDecorator is the interface that is used by controls to paint decorators. All decorators must implement this interface. The base implementation is AbstractDecorator.
-
void doPaint(GC gc, int x, int y), paints the decorator to the specified GC. -
Point getSize(), returns the size of the decorator
AbstractDecorator is the base implementation of the IDecorator interface. All decorator implementations are subclasses of this abstract class.
-
AbstractDecorator(Control parent)-
parentthe parent control to paint the decorator
-
-
void dispose(), is called when the parent control is disposed -
Display getDisplay(), returns the display of the parent control -
Control getParent(), returns the parent control -
void redraw(), force decorator paintig by redrawing the parent control
Paint an image to the parent control. Supports all image formats supported by ImageLoaderplus animated GIFs.
-
void loadImage(InputStream stream), loads an image from input stream -
void loadImage(String filename), loads an image from the file -
void setImage(Image image), sets an image -
void scaleTo(final Point scaleTo), scales the image to the defined size
public static void main(final String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
// creates the decorator and sets the image
final ImageDecorator decorator = new ImageDecorator(shell);
decorator.setImage(display.getSystemImage(SWT.ICON_INFORMATION));
// adds a listener to paint the decorator
shell.addListener(SWT.Paint, e -> decorator.doPaint(e.gc, 100, 10));
shell.setText("Greip - ImageDecorator Example");
shell.setSize(300, 100);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}Displays an percentage value as animated graphic.
Displays an absolute value as animated graphic.
public static void main(final String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
// creates and configuere the decorator
final CountDecorator decorator = new CountDecorator(shell);
decorator.setForeground(display.getSystemColor(SWT.COLOR_DARK_RED));
decorator.showAnimation(true);
// set the decorators value
decorator.setValue(234);
// adds a listener to paint the decorator
shell.addListener(SWT.Paint, e -> decorator.doPaint(e.gc, 100, 10));
shell.setText("Greip - CountDecorator Example");
shell.setSize(300, 150);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}