Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Managing SWT resources in custom shapes(using a JFace ResourceManager linked to a Diagram)
Managing SWT resources in custom shapes [message #1733452] Fri, 27 May 2016 15:54 Go to next message
Erwin De Ley is currently offline Erwin De LeyFriend
Messages: 52
Registered: August 2013
Member
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
Re: Managing SWT resources in custom shapes [message #1733706 is a reply to message #1733452] Tue, 31 May 2016 07:43 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Erwin,

thanks for proposing this, I think this would be a nice extension to the Graphiti framework. The main usecase I see is in image handling which is currently all left to the tool. Of course this can also help with platform graphics algorithms, but there are at least according to my knowledge much less tools using that than tools using images.

It would be cool if you would like to contribute that to Graphiti, I would like to include it in the upcoming Graphiti release after Neon (for Neon we are already beyond API freeze, so I cannot add it there). To do so please create a bugzilla and either attach a patch there or even better directly propose the code change in Gerrit.

Thanks,
Michael
Re: Managing SWT resources in custom shapes [message #1733724 is a reply to message #1733706] Tue, 31 May 2016 08:58 Go to previous messageGo to next message
Erwin De Ley is currently offline Erwin De LeyFriend
Messages: 52
Registered: August 2013
Member
Sure thing!

I'll try to learn about using Gerrit, if that's too steep it'll be a patch...

I'll do that by the end of the month, now I'm busy preparing for EclipseCon...

cheers
erwin
Re: Managing SWT resources in custom shapes [message #1738436 is a reply to message #1733724] Tue, 19 July 2016 20:06 Go to previous message
Erwin De Ley is currently offline Erwin De LeyFriend
Messages: 52
Registered: August 2013
Member
Created https://bugs.eclipse.org/bugs/show_bug.cgi?id=498164

Now trying to get into gerrit Wink

cheers
erwin
Previous Topic:Save as ... Image, without editor
Next Topic:Call for funding to release a new Graphiti extension for CDO under EPL !
Goto Forum:
  


Current Time: Fri Apr 19 21:34:27 GMT 2024

Powered by FUDForum. Page generated in 0.03999 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top