Wednesday, April 18, 2007

Gradienting figures with colors

User interfaces are necessarily required to be as polished as a bride! Gradient-ing factors to be pretty crucial especially after the broad usage of Window-XP themes.

GEF, provides its implementation on through the ScaledGraphics implementation. However, the ScaledGraphics is not the only used Graphics implementation; making it difficult for object invocation.

The workaround for this would involve overriding the implementation of setBackgroundPattern. GMF's implementation RenderedMapModeGraphics doesn't serve the purpose as well. The Graphics is always set on the RootLayeredPane. Consequently it would require an implementation of the RootEditpart.

public void setBackgroundPattern(Device dev, float x1, float y1, float x2,
float y2, Color color1, Color color2) {
if (baseGraphics instanceof SWTGraphics) {
if (pattern != null) {
pattern.dispose();
}
pattern = new Pattern(dev, x1, y1, x2, y2, color1, color2);
baseGraphics.setBackgroundPattern(pattern);
return;
}
if (baseGraphics instanceof RenderedMapModeGraphics) {
((RenderedMapModeGraphics) baseGraphics).setBackgroundPattern(dev, x1,
y1, x2, y2, color1, color2);
return;
}
return;
}


Pattern being SWT.Pattern

Canonical Edit Policies

GMF has this add-on Editpolicy which handles the synchronization between the semantic and view models.

At times, it is evident that the connections being created or elements being created within a composite parent(one apart from the base edit part) do not refresh the model or even the connections. This is because of the difference in implementation from the base editpart ones.

Two methods that may be striking are the
1. refreshSemantic
2. refreshConnections - called from the refreshSemantic

The invocations for these cause refresh real time.

More on Canonical EditPolicies