Reputation: 3086
Is it possible for a widget to inherit properties from its predecessor? For example, say I have the following code segment:
Display display=new Display();
Shell shell=new Shell(display, SWT.DIALOG_TRIM);
Image menu_background=new Image(display, "menu.jpg");
shell.setBackgroundImage(menu_background);
shell.setBounds(menu_background.getBounds());
shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
Group game_modes=new Group(shell,SWT.SHADOW_ETCHED_OUT);
game_modes.setText("Game Mode");
game_modes.setLocation(50, 170);
game_modes.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
...
...
...
The call for shell.setBackgroundMode(SWT.INHERIT_DEFAULT)
makes sure that the group widget will have the same background as its predecessor (is it called predecessor? I'm not familiar with the exact terms) - the shell.
But, how can I impose the shell properties on the group object in general? for example: the same TextStyle as the shell, or the same Font as the shell. (and yes, I know I didn't set any properties for the shell in the code above, except the background)
Is it even possible?
Upvotes: 1
Views: 1088
Reputation: 3304
With Eclipse 4.x you can style your application with CSS, applying same properties to controls from there (Vogella's tutorial). It is seems that it should be possible with 3.x as well (http://www.slideshare.net/toedter_k/css-styling-for-eclipse-rcp-3x-and-4x).
As by default With Eclipse 3.x, I'd say you can't force all children of the composite to have same properties, as a parent, you can only inherit a background.
In this case in order to always have the same properties, you may want to create your own framework which would produce custom styled widgets, which would create and style UI controls as required, for example:
public class WidgetFactory {
public static final Color BACKGROUND_DEFAULT = new Color(Display.getCurrent(), 224, 231, 255);
public static final String FONT_DEFAULT = "default";
private static FontRegistry fontRegistry = null;
static {
fontRegistry = new FontRegistry(Display.getCurrent());
putFont(FONT_DEFAULT, "Verdana", fontSizes.get(FONT_DEFAULT), SWT.NONE);
}
public static Composite createComposite(Composite parent, int numCols, boolean equalWidth, int gridDataStyle) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setFont(fontRegistry.get(FONT_DEFAULT));
composite.setBackground(BACKGROUND_DEFAULT);
GridData gridData = new GridData(gridDataStyle);
composite.setLayoutData(gridData);
GridLayout layout = new GridLayout(numCols, equalWidth);
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
composite.setLayout(layout);
return composite;
}
public static Label createLabel(Composite parent, String text, String toolTipText) {
Label theLabel = new Label(parent, SWT.NONE);
theLabel.setText(trim(text));
theLabel.setToolTipText(trim(toolTipText));
theLabel.setFont(fontRegistry.get(FONT_DEFAULT));
parent.setBackgroundMode(SWT.INHERIT_DEFAULT);
return theLabel;
}
}
There are some other styling options, possible with presentationFactory
extension point, thou I think it is out of your questions scope. Here is a short overview of what you can do with it.
Upvotes: 3