Gef faq 1: Set a background image for the graphic editor

Source: Internet
Author: User

The figure corresponding to the GEF's rooteditpart is a layeredpane composed of multiple layers. Each layer contains different types of graphic elements, such as nodes, connections, and grid lines. Therefore, to make the graphic editor display an image as the background, you can draw the image in one of the layers, or add a layer to place the background image. I recommend using the latter:CodeThe following is a simple modification made on the basis of the previous gefpractice project:

Static Image bg_image = New Image ( Null , " C: \ bg.jpg " );

Protected   Void Configuregraphicalviewer (){
Super . Configuregraphicalviewer ();
Getgraphicalviewer (). setrooteditpart ( New Scalablefreeformrooteditpart (){

// Override the createlayers method of scalablefreeformrooteditpart to add your own layer.
Protected   Void Createlayers (layeredpane ){
Layer Layer =   New Freeformlayer (){
Protected   Void Paintfigure (Graphics graphics ){
Super . Paintfigure (graphics );
// Draw an image on the layer or draw other images as the background. The gridlines of GEF are an example.
Graphics. drawimage (bg_image, 0 , 0 );
}
};
Layeredpane. Add (layer );
Super . Createlayers (layeredpane );
}

});
Getgraphicalviewer (). seteditpartfactory ( New Partfactory ());
}

In this way, only the visible area of the editor is displayed, that is, the background image will scroll with the scroll bar. See.


Graphic editor with background image

Project download (the title of the background image is "C: \ bg.jpg ")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.