Managing SWT resources in custom shapes [message #1733452] |
Fri, 27 May 2016 11:54  |
Eclipse User |
|
|
|
Related to a previous post about creating shapes from SVG, there was still a pending issue about managing SWT resources (fonts, colors, ...) that are created in the custom shapes. (thanks to Krisztian for remarking this)
To resolve that I have added a ResourceManager in our custom DiagramBehavior implementation, and I dispose it in an overridden DiagramBehavior.disposeAfterGefDispose().
As the DiagramBehavior instance for the current diagram is passed along in the IRenderContext to IGraphicsAlgorithmRendererFactory.createGraphicsAlgorithmRenderer(...) the actual shape implementations in there can then access the diagram's resource manager instance to create their stuff when needed.
And in that way, fonts, colors etc get reused while working in the same diagram (a feature of the JFace ResourceManager), and are all disposed when the diagram is closed.
I was wondering if this would not be useful to have on Graphiti's base DiagramBehavior?
Code is very simple to enable this :
public class TriqDiagramBehavior extends DiagramBehavior {
private ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources());
public TriqDiagramBehavior(IDiagramContainerUI diagramContainer) {
super(diagramContainer);
}
@Override
protected DefaultPaletteBehavior createPaletteBehaviour() {
return new TriqPaletteBehavior(this);
}
@Override
protected void disposeAfterGefDispose() {
super.disposeAfterGefDispose();
resourceManager.dispose();
}
/**
*
* @return the JFace ResourceManager to be used to create images, fonts etc for an open diagram.
*/
public ResourceManager getResourceManager() {
return resourceManager;
}
}
cheers
erwin
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03059 seconds