Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » the problem I add a image in editor
the problem I add a image in editor [message #226628] Mon, 20 November 2006 03:15 Go to next message
Eclipse UserFriend
Originally posted by: jdenght.gmail.com

HI,Everyone:
I have add a image on diagram,when i open the editor,the image of the
diagram can not display normally.(the results in attachment1.png)
when I use Marquee tool select the diagram or drag the child of diagram,the
image will display Irregularly.(the results in attachment2.png)

how can i make the image in editor display normally?

many thanks!!!

the code add the image in diagramEditpart in createFigure method as follows:

protected IFigure createFigure() {
Figure figure = new FreeformLayer()
{
protected void paintFigure(Graphics graphics) {
super.paintFigure(graphics);
if(getDiagram().getBackgroudImage()!=null) {
File file = new File(getDiagram().getBackgroudImage());
if (file.isFile()) {
if (BG_IMAGE != null) {
BG_IMAGE = null;
}
FileInputStream input = null;
try {
input = new FileInputStream(file);
BG_IMAGE = new Image(null, input);
graphics.drawImage(BG_IMAGE, 0, 0);
} catch (FileNotFoundException e) {
BG_IMAGE.dispose();
try {
input.close();
} catch (IOException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}finally {
BG_IMAGE.dispose();
try {
input.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}

}
}

}
};
figure.repaint();
figure.setLayoutManager(new FreeformLayout());
return figure;
}





Re: the problem I add a image in editor [message #226664 is a reply to message #226628] Mon, 20 November 2006 20:20 Go to previous messageGo to next message
Alex Boyko is currently offline Alex BoykoFriend
Messages: 200
Registered: July 2009
Senior Member
Hi,

Although I couldn't look at the attached screen shots, I've tried to help
you out here by setting a background image for the logic diagram figure.
Below I'll provide a code snippet for the extended FreeFormLayer figure
(i.e. FreeFormLayerWithImageBGR figure). Essentially, this is the code
snippet you provided in your problem description with 2 differences:
1) Image is cached
2) Image is scaled to occupy the whole diagram.

Code snippet:

#######################################################
package org.eclipse.gef.examples.logicdesigner.figures;

import java.io.FileInputStream;

import org.eclipse.swt.graphics.Image;

import org.eclipse.ui.PlatformUI;

import org.eclipse.draw2d.FreeformLayer;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.geometry.Rectangle;


public class FreeFormLayerWithImageBGR
extends FreeformLayer {

Image image;

public FreeFormLayerWithImageBGR(String path) {
super();
try {
setImage(new Image(PlatformUI.getWorkbench().getDisplay(),
new FileInputStream(path)));
} catch (Exception e) {
System.out.println(e);
setImage(null);
}

}

public Image getImage() {
return image;
}


public void setImage(Image image) {
this.image = image;
}

protected void paintFigure(Graphics graphics) {
if (getImage() != null) {
Rectangle targetRect = getBounds().getCopy();
org.eclipse.swt.graphics.Rectangle imgBox =
getImage().getBounds();
graphics.drawImage(getImage(), 0, 0, imgBox.width,
imgBox.height,
targetRect.x, targetRect.y, targetRect.width,
targetRect.height);
}
super.paintFigure(graphics);
}
}
################################################

To set it up for logic example:
in LogicDiagramEditPart#createFigure() instead of:
IFigure f = new FreeFormLayer()

put

IFigure = new FreeFormLayerWithImageBGR("<full path to the image file>");
(Note: don't try SVG images)

Please try this out, let me know if this helps.

Cheers,
Alex
Re: the problem I add a image in editor [message #226712 is a reply to message #226664] Tue, 21 November 2006 07:01 Go to previous message
Eclipse UserFriend
Originally posted by: jdenght.gmail.com

Hi,alex:
Thanks very much for your code snippet,the problem has been resolved by the
way you provided!

Best wishes to you!

jdenght
"Alex Boyko" <aboyko@ca.ibm.com>
??????:123fc64be0654e219b04d96345025015$1@www.eclipse.org...
> Hi,
>
> Although I couldn't look at the attached screen shots, I've tried to help
> you out here by setting a background image for the logic diagram figure.
> Below I'll provide a code snippet for the extended FreeFormLayer figure
> (i.e. FreeFormLayerWithImageBGR figure). Essentially, this is the code
> snippet you provided in your problem description with 2 differences:
> 1) Image is cached
> 2) Image is scaled to occupy the whole diagram.
>
> Code snippet:
>
> #######################################################
> package org.eclipse.gef.examples.logicdesigner.figures;
>
> import java.io.FileInputStream;
>
> import org.eclipse.swt.graphics.Image;
>
> import org.eclipse.ui.PlatformUI;
>
> import org.eclipse.draw2d.FreeformLayer;
> import org.eclipse.draw2d.Graphics;
> import org.eclipse.draw2d.geometry.Rectangle;
>
>
> public class FreeFormLayerWithImageBGR
> extends FreeformLayer {
> Image image;
> public FreeFormLayerWithImageBGR(String path) {
> super();
> try {
> setImage(new Image(PlatformUI.getWorkbench().getDisplay(),
> new FileInputStream(path)));
> } catch (Exception e) {
> System.out.println(e);
> setImage(null);
> }
> }
> public Image getImage() {
> return image;
> }
>
> public void setImage(Image image) {
> this.image = image;
> }
>
> protected void paintFigure(Graphics graphics) {
> if (getImage() != null) {
> Rectangle targetRect = getBounds().getCopy();
> org.eclipse.swt.graphics.Rectangle imgBox =
> getImage().getBounds();
> graphics.drawImage(getImage(), 0, 0, imgBox.width,
> imgBox.height,
> targetRect.x, targetRect.y, targetRect.width,
> targetRect.height);
> }
> super.paintFigure(graphics);
> }
> }
> ################################################
>
> To set it up for logic example:
> in LogicDiagramEditPart#createFigure() instead of:
> IFigure f = new FreeFormLayer()
>
> put
>
> IFigure = new FreeFormLayerWithImageBGR("<full path to the image file>");
> (Note: don't try SVG images)
>
> Please try this out, let me know if this helps.
>
> Cheers,
> Alex
>
Previous Topic:Two palettes in the same editor
Next Topic:The proper layout - GMF version of datagrid (widget)
Goto Forum:
  


Current Time: Thu Apr 25 02:23:08 GMT 2024

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

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

Back to the top