Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » [Zest] setBackgroundImage() for Graph doesn't work
[Zest] setBackgroundImage() for Graph doesn't work [message #512362] Thu, 04 February 2010 18:55 Go to next message
philipp.hauer is currently offline philipp.hauerFriend
Messages: 13
Registered: February 2010
Junior Member
Hello,

I like to insert an image into the background of my graph.
public class GraphSnippet1 {

    public static void main(String[] args) {
        Display d = new Display();
        Shell shell = new Shell(d);
        shell.setLayout(new FillLayout());
        shell.setSize(400, 400);

        Graph graph = new Graph(shell, SWT.NONE);
        graph.setBackgroundImage(new Image(null, "res/image.png")); //doesn't work!
        //g.setBackground(new Color(null,255,0,0)); //works fine!

        GraphNode n = new GraphNode(graph, SWT.NONE, "Paper");
        GraphNode n2 = new GraphNode(graph, SWT.NONE, "Rock");
        new GraphConnection(graph, SWT.NONE, n, n2);
        graph.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);

        shell.open();
        while (!shell.isDisposed()) {
            while (!d.readAndDispatch()) {
                d.sleep();
            }
        }
    }
}


The setBackgroundImage()-method seems to do nothing, while setBackground() does work.

What's my mistake? Or is there any workaround?

Greetings
Philipp H.

[Updated on: Thu, 04 February 2010 18:58]

Report message to a moderator

Re: [Zest] setBackgroundImage() for Graph doesn't work [message #676307 is a reply to message #512362] Fri, 03 June 2011 15:19 Go to previous messageGo to next message
Mark Fenbers is currently offline Mark FenbersFriend
Messages: 48
Registered: July 2009
Location: Ohio, USA
Member
I have run into the same issue, but the image DOES get applied, but gets overwritten immediately because some built-in mechanism is painting over it with the background color right away. Try resizing the window (or hiding and showing it) and you might be able to see the background image for a microsecond or two before being covered over with the background color.

I still do not have a solution for you (or me) and it does seem to be a bug, but I can't believe it has gone on this long without being addressed.

Have you been enlightened to a solution either on or off this forum?

Mark
Re: [Zest] setBackgroundImage() for Graph doesn't work [message #676362 is a reply to message #512362] Fri, 03 June 2011 22:33 Go to previous messageGo to next message
Fabian Steeg is currently offline Fabian SteegFriend
Messages: 72
Registered: July 2009
Member
The root issue seems to be in FigureCanvas - I think it would make sense to file a bug at https://bugs.eclipse.org/bugs/enter_bug.cgi?product=GEF&component=draw2d&version=3.7

As a workaround I was able set an image on the parent and make the root figure transparent:

Graph graph = new Graph(shell, SWT.NONE);
graph.getLightweightSystem().getRootFigure().setOpaque(false);
shell.setBackgroundImage(new Image(null, "res/image.png"));

Re: [Zest] setBackgroundImage() for Graph doesn't work [message #681750 is a reply to message #676362] Thu, 09 June 2011 18:55 Go to previous messageGo to next message
Mark Fenbers is currently offline Mark FenbersFriend
Messages: 48
Registered: July 2009
Location: Ohio, USA
Member
I tried your setOpaque() idea and that works as a workaround! Thank you! I submitted a bug report.
Mark

P.S. Following up... the work-around has problems, too. It seems that certain dialog boxes (such as JFace File Choosers and Color Choosers, but not simple message boxes), cause the background image in the Graph to disappear again, as if the dialog box triggered some code that set the Graph's setOpaque() method back to true. I guess, the bottom line is that it needs to be fixed in the source code, not by work-arounds. Hopefully, the bug will be fixed in the next patch release...

[Updated on: Fri, 10 June 2011 15:27]

Report message to a moderator

Re: [Zest] setBackgroundImage() for Graph doesn't work [message #726371 is a reply to message #512362] Sat, 17 September 2011 17:13 Go to previous messageGo to next message
Hemanta Sapkota is currently offline Hemanta SapkotaFriend
Messages: 1
Registered: September 2011
Junior Member
    Graph g = new Graph(shell, SWT.NONE);
    ImageFigure iff = new ImageFigure();
    iff.setImage(AB_BG.createImage()); //AG_BG is an ImageDescriptor
    g.getLightweightSystem().getRootFigure().add(iff, 0); //Add at index 0.


Here's another workaround. Create an ImageFigure, set image and add it to root figure.
Re: [Zest] setBackgroundImage() for Graph doesn't work [message #726379 is a reply to message #726371] Sat, 17 September 2011 18:32 Go to previous message
Mark Fenbers is currently offline Mark FenbersFriend
Messages: 48
Registered: July 2009
Location: Ohio, USA
Member
Hemanta, I am glad you found an alternative work-around, but for some unknown reason, this approach does not work for me. I get a stack trace when the Graph is open()'d and it points to the ImageFigure I created being an invalid argument to the ...getRootFigure.add() method. I tried several things, but all indications are that my ImageFigure is indeed valid. So, I'm still stuck while I patiently wait for a true fix to be enacted...
Mark
Previous Topic:adding association connection to artifacts
Next Topic:marker link to EditPart
Goto Forum:
  


Current Time: Thu Dec 18 00:54:52 GMT 2014

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

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