Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Diagram background, can't add elements?
Diagram background, can't add elements? [message #171292] Sun, 03 February 2008 21:24 Go to next message
Eclipse UserFriend
Originally posted by: mail.micke.gmail.com

Hi all,
I'm experimenting with GMF trying to figure out how things work and ran
into a bit of a problem.

From various other posts I found a way of having an image background in
my diagram, but after adding the code below I cant create new
elements/nodes to it?

I created a FreeFormImageLayer class like this:

public class FreeFormImageLayer extends FreeformLayer {
Image image;
DiagramEditPart ownerEditPart;

public FreeFormImageLayer(final Image image, final DiagramEditPart
ownerEditPart){
this.image = image;
this.ownerEditPart = ownerEditPart;
}


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();

Rectangle r = getBounds().getCopy();
ownerEditPart.getFigure().translateToParent(r);
r.intersect(ownerEditPart.getFigure().getClientArea());

org.eclipse.swt.graphics.Rectangle imgBox = getImage().getBounds();

System.out.printf("r=(%d,%d,%d,%d)\n",
r.x, r.y, r.width, r.height);

System.out.printf("(%d,%d,%d,%d) -> (%d,%d,%d,%d)\n",
imgBox.x, imgBox.y, imgBox.width, imgBox.height,
targetRect.x, targetRect.y, targetRect.width, targetRect.height);

long t1 = System.currentTimeMillis();
System.out.println("Start draw image");
/*
graphics.drawImage(getImage(), 0, 0, imgBox.width, imgBox.height,
targetRect.x, targetRect.y, targetRect.width,
targetRect.height);
*/
System.out.println("Graphics absolute scale: "
+graphics.getAbsoluteScale());
graphics.drawImage(getImage(), 0, 0);
System.out.println("End draw image, took
"+(System.currentTimeMillis()-t1) +" ms");
}

super.paintFigure(graphics);
}

@Override
public Rectangle getFreeformExtent() {
// TODO Auto-generated method stub
//return super.getFreeformExtent();

return new Rectangle(0,0, image.getBounds().width/10,
image.getBounds().height/10);
}

}

Which I then add to my diagram edit part in its createFigure like this:

protected IFigure createFigure() {

System.out.println(getClass().getName() + " : In createFigure()");
image = null;
EObject eObj = ((Diagram)getModel()).getElement();
String fileStr =((Project)eObj).getMapFile();
fileStr = "/home/mikael/Desktop/mapClean.jpg";


createImages( fileStr );
ScalableLayeredPane pane = new ScalableLayeredPane();
pane.setBounds(new Rectangle(image.getBounds()));

imageLayer = new FreeFormImageLayer(image,this);

pane.add(imageLayer);
pane.add(contentPane = super.createFigure());
System.out.println(getClass().getName() +"End createFigure");

return pane;

}

void createImages(final String fileStr){

InputStream is;
try {
is = new FileInputStream(fileStr);
image = new Image(PlatformUI.getWorkbench().getDisplay(), is);

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//Thread.currentThread().getContextClassLoader().getResourc eAsStream(
fileStr );

if(image == null){
image = new Image(PlatformUI.getWorkbench().getDisplay(),300,300);
image.setBackground(ColorConstants.blue);
}

}

Please ignore all the print statements, I'm having another issue with
extremely slow (2.5 second) render times when zooming the slightest.

Any help really appreciated.

Cheers,
Micke
Re: Diagram background, can't add elements? [message #171363 is a reply to message #171292] Mon, 04 February 2008 22:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mail.micke.gmail.com

Anyone out there who has successfully managed to add a diagram
background which covers the entire diagram (not like the taipan example
which only covers the bottom right)?
If so I'd be gratefull if you could post your solution.

Cheers

Mikael Andersson wrote:
> Hi all,
> I'm experimenting with GMF trying to figure out how things work and ran
> into a bit of a problem.
>
> From various other posts I found a way of having an image background in
> my diagram, but after adding the code below I cant create new
> elements/nodes to it?
>
> I created a FreeFormImageLayer class like this:
>
> public class FreeFormImageLayer extends FreeformLayer {
> Image image;
> DiagramEditPart ownerEditPart;
>
> public FreeFormImageLayer(final Image image, final DiagramEditPart
> ownerEditPart){
> this.image = image;
> this.ownerEditPart = ownerEditPart;
> }
>
>
> 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();
>
> Rectangle r = getBounds().getCopy();
> ownerEditPart.getFigure().translateToParent(r);
> r.intersect(ownerEditPart.getFigure().getClientArea());
>
> org.eclipse.swt.graphics.Rectangle imgBox =
> getImage().getBounds();
>
> System.out.printf("r=(%d,%d,%d,%d)\n",
> r.x, r.y, r.width, r.height);
>
> System.out.printf("(%d,%d,%d,%d) -> (%d,%d,%d,%d)\n",
> imgBox.x, imgBox.y, imgBox.width, imgBox.height,
> targetRect.x, targetRect.y, targetRect.width,
> targetRect.height);
>
> long t1 = System.currentTimeMillis();
> System.out.println("Start draw image");
> /*
> graphics.drawImage(getImage(), 0, 0, imgBox.width,
> imgBox.height,
> targetRect.x, targetRect.y, targetRect.width,
> targetRect.height);
> */
> System.out.println("Graphics absolute scale: "
> +graphics.getAbsoluteScale());
> graphics.drawImage(getImage(), 0, 0);
> System.out.println("End draw image, took
> "+(System.currentTimeMillis()-t1) +" ms");
> }
>
> super.paintFigure(graphics);
> }
>
> @Override
> public Rectangle getFreeformExtent() {
> // TODO Auto-generated method stub
> //return super.getFreeformExtent();
>
> return new Rectangle(0,0, image.getBounds().width/10,
> image.getBounds().height/10);
> }
>
> }
>
> Which I then add to my diagram edit part in its createFigure like this:
>
> protected IFigure createFigure() {
>
> System.out.println(getClass().getName() + " : In createFigure()");
> image = null;
> EObject eObj = ((Diagram)getModel()).getElement();
> String fileStr =((Project)eObj).getMapFile();
> fileStr = "/home/mikael/Desktop/mapClean.jpg";
>
>
> createImages( fileStr );
> ScalableLayeredPane pane = new ScalableLayeredPane();
> pane.setBounds(new Rectangle(image.getBounds()));
>
> imageLayer = new FreeFormImageLayer(image,this);
>
> pane.add(imageLayer);
> pane.add(contentPane = super.createFigure());
> System.out.println(getClass().getName() +"End createFigure");
>
> return pane;
>
> }
>
> void createImages(final String fileStr){
>
> InputStream is;
> try {
> is = new FileInputStream(fileStr);
> image = new Image(PlatformUI.getWorkbench().getDisplay(),
> is);
>
> } catch (FileNotFoundException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
>
> }//Thread.currentThread().getContextClassLoader().getResourc eAsStream(
> fileStr );
>
> if(image == null){
> image = new
> Image(PlatformUI.getWorkbench().getDisplay(),300,300);
> image.setBackground(ColorConstants.blue);
> }
>
> }
>
> Please ignore all the print statements, I'm having another issue with
> extremely slow (2.5 second) render times when zooming the slightest.
>
> Any help really appreciated.
>
> Cheers,
> Micke
Re: Diagram background, can't add elements? [message #171382 is a reply to message #171363] Tue, 05 February 2008 08:00 Go to previous messageGo to next message
Boris Blajer is currently offline Boris BlajerFriend
Messages: 217
Registered: July 2009
Senior Member
Hi Mikael,

I am not sure this has anything to do with your situation, but I
remember having problems with creating elements inside nodes when using
layers and layered panes. I overrode method isOpaque() to always return
false and that helped.

Best regards,
Boris


Mikael Andersson wrote:
> Anyone out there who has successfully managed to add a diagram
> background which covers the entire diagram (not like the taipan example
> which only covers the bottom right)?
> If so I'd be gratefull if you could post your solution.
>
> Cheers
>
> Mikael Andersson wrote:
>> Hi all,
>> I'm experimenting with GMF trying to figure out how things work and
>> ran into a bit of a problem.
>>
>> From various other posts I found a way of having an image background
>> in my diagram, but after adding the code below I cant create new
>> elements/nodes to it?
>>
>> I created a FreeFormImageLayer class like this:
>>
>> public class FreeFormImageLayer extends FreeformLayer {
>> Image image;
>> DiagramEditPart ownerEditPart;
>> public FreeFormImageLayer(final Image image, final
>> DiagramEditPart ownerEditPart){
>> this.image = image;
>> this.ownerEditPart = ownerEditPart;
>> }
>>
>> 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();
>> Rectangle r = getBounds().getCopy();
>> ownerEditPart.getFigure().translateToParent(r);
>> r.intersect(ownerEditPart.getFigure().getClientArea());
>> org.eclipse.swt.graphics.Rectangle imgBox =
>> getImage().getBounds();
>> System.out.printf("r=(%d,%d,%d,%d)\n",
>> r.x, r.y, r.width, r.height);
>> System.out.printf("(%d,%d,%d,%d) ->
>> (%d,%d,%d,%d)\n",
>> imgBox.x, imgBox.y, imgBox.width, imgBox.height,
>> targetRect.x, targetRect.y, targetRect.width,
>> targetRect.height);
>> long t1 = System.currentTimeMillis();
>> System.out.println("Start draw image");
>> /*
>> graphics.drawImage(getImage(), 0, 0, imgBox.width,
>> imgBox.height,
>> targetRect.x, targetRect.y, targetRect.width,
>> targetRect.height);
>> */
>> System.out.println("Graphics absolute scale: "
>> +graphics.getAbsoluteScale());
>> graphics.drawImage(getImage(), 0, 0);
>> System.out.println("End draw image, took
>> "+(System.currentTimeMillis()-t1) +" ms");
>> }
>> super.paintFigure(graphics);
>> }
>>
>> @Override
>> public Rectangle getFreeformExtent() {
>> // TODO Auto-generated method stub
>> //return super.getFreeformExtent();
>> return new Rectangle(0,0, image.getBounds().width/10,
>> image.getBounds().height/10);
>> }
>>
>> }
>>
>> Which I then add to my diagram edit part in its createFigure like this:
>>
>> protected IFigure createFigure() {
>>
>> System.out.println(getClass().getName() + " : In
>> createFigure()");
>> image = null; EObject eObj =
>> ((Diagram)getModel()).getElement();
>> String fileStr =((Project)eObj).getMapFile();
>> fileStr = "/home/mikael/Desktop/mapClean.jpg";
>> createImages( fileStr );
>> ScalableLayeredPane pane = new ScalableLayeredPane();
>> pane.setBounds(new Rectangle(image.getBounds()));
>> imageLayer = new FreeFormImageLayer(image,this);
>> pane.add(imageLayer);
>> pane.add(contentPane = super.createFigure());
>> System.out.println(getClass().getName() +"End createFigure");
>> return pane;
>>
>> }
>> void createImages(final String fileStr){
>> InputStream is;
>> try {
>> is = new FileInputStream(fileStr);
>> image = new Image(PlatformUI.getWorkbench().getDisplay(),
>> is); } catch (FileNotFoundException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>>
>> }//Thread.currentThread().getContextClassLoader().getResourc eAsStream(
>> fileStr );
>> if(image == null){
>> image = new
>> Image(PlatformUI.getWorkbench().getDisplay(),300,300);
>> image.setBackground(ColorConstants.blue);
>> }
>> }
>>
>> Please ignore all the print statements, I'm having another issue with
>> extremely slow (2.5 second) render times when zooming the slightest.
>>
>> Any help really appreciated.
>>
>> Cheers,
>> Micke
Re: Diagram background, can't add elements? [message #171628 is a reply to message #171382] Tue, 05 February 2008 22:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mail.micke.gmail.com

Thanks for the suggestion Boris, unfortunately it didn't help. Overrode
the isOpaque method on my FreeFormImageLayer class.

Another thing I've noticed is that changing propeties for the Diagram
object in the properties view doesn't work properly.
After entering a String and pressing enter it goes blank, but when
clicking on the field, selecting it, the value entered is displayed.

Cheers

Boris Blajer wrote:
> Hi Mikael,
>
> I am not sure this has anything to do with your situation, but I
> remember having problems with creating elements inside nodes when using
> layers and layered panes. I overrode method isOpaque() to always return
> false and that helped.
>
> Best regards,
> Boris
>
>
> Mikael Andersson wrote:
>> Anyone out there who has successfully managed to add a diagram
>> background which covers the entire diagram (not like the taipan
>> example which only covers the bottom right)?
>> If so I'd be gratefull if you could post your solution.
>>
>> Cheers
>>
>> Mikael Andersson wrote:
>>> Hi all,
>>> I'm experimenting with GMF trying to figure out how things work and
>>> ran into a bit of a problem.
>>>
>>> From various other posts I found a way of having an image background
>>> in my diagram, but after adding the code below I cant create new
>>> elements/nodes to it?
>>>
>>> I created a FreeFormImageLayer class like this:
>>>
>>> public class FreeFormImageLayer extends FreeformLayer {
>>> Image image;
>>> DiagramEditPart ownerEditPart;
>>> public FreeFormImageLayer(final Image image, final
>>> DiagramEditPart ownerEditPart){
>>> this.image = image;
>>> this.ownerEditPart = ownerEditPart;
>>> }
>>> 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();
>>> Rectangle r = getBounds().getCopy();
>>> ownerEditPart.getFigure().translateToParent(r);
>>> r.intersect(ownerEditPart.getFigure().getClientArea());
>>> org.eclipse.swt.graphics.Rectangle imgBox =
>>> getImage().getBounds();
>>> System.out.printf("r=(%d,%d,%d,%d)\n",
>>> r.x, r.y, r.width, r.height);
>>> System.out.printf("(%d,%d,%d,%d) ->
>>> (%d,%d,%d,%d)\n",
>>> imgBox.x, imgBox.y, imgBox.width, imgBox.height,
>>> targetRect.x, targetRect.y, targetRect.width,
>>> targetRect.height);
>>> long t1 = System.currentTimeMillis();
>>> System.out.println("Start draw image");
>>> /*
>>> graphics.drawImage(getImage(), 0, 0, imgBox.width,
>>> imgBox.height,
>>> targetRect.x, targetRect.y, targetRect.width,
>>> targetRect.height);
>>> */
>>> System.out.println("Graphics absolute scale: "
>>> +graphics.getAbsoluteScale());
>>> graphics.drawImage(getImage(), 0, 0);
>>> System.out.println("End draw image, took
>>> "+(System.currentTimeMillis()-t1) +" ms");
>>> }
>>> super.paintFigure(graphics);
>>> }
>>>
>>> @Override
>>> public Rectangle getFreeformExtent() {
>>> // TODO Auto-generated method stub
>>> //return super.getFreeformExtent();
>>> return new Rectangle(0,0, image.getBounds().width/10,
>>> image.getBounds().height/10);
>>> }
>>>
>>> }
>>>
>>> Which I then add to my diagram edit part in its createFigure like this:
>>>
>>> protected IFigure createFigure() {
>>>
>>> System.out.println(getClass().getName() + " : In
>>> createFigure()");
>>> image = null; EObject eObj =
>>> ((Diagram)getModel()).getElement();
>>> String fileStr =((Project)eObj).getMapFile();
>>> fileStr = "/home/mikael/Desktop/mapClean.jpg";
>>> createImages( fileStr );
>>> ScalableLayeredPane pane = new ScalableLayeredPane();
>>> pane.setBounds(new Rectangle(image.getBounds()));
>>> imageLayer = new FreeFormImageLayer(image,this);
>>> pane.add(imageLayer);
>>> pane.add(contentPane = super.createFigure());
>>> System.out.println(getClass().getName() +"End createFigure");
>>> return pane;
>>>
>>> }
>>> void createImages(final String fileStr){
>>> InputStream is;
>>> try {
>>> is = new FileInputStream(fileStr);
>>> image = new Image(PlatformUI.getWorkbench().getDisplay(),
>>> is); } catch (FileNotFoundException e) {
>>> // TODO Auto-generated catch block
>>> e.printStackTrace();
>>>
>>> }//Thread.currentThread().getContextClassLoader().getResourc eAsStream(
>>> fileStr );
>>> if(image == null){
>>> image = new
>>> Image(PlatformUI.getWorkbench().getDisplay(),300,300);
>>> image.setBackground(ColorConstants.blue);
>>> }
>>> }
>>>
>>> Please ignore all the print statements, I'm having another issue with
>>> extremely slow (2.5 second) render times when zooming the slightest.
>>>
>>> Any help really appreciated.
>>>
>>> Cheers,
>>> Micke
Re: Diagram background, can't add elements? [message #171954 is a reply to message #171292] Sat, 09 February 2008 14:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mail.micke.gmail.com

Hi

Due to the lack of replies I suspect that; the question wasn't very
clear , this is not a gmf problem or a RTFM issue.

Would be nice top pinpoint which of the three it is, would be very
grateful if someone with a bit of experience could reply. Because I'm at
the point of giving up on this.

Cheers,
Micke

Mikael Andersson wrote:
> Hi all,
> I'm experimenting with GMF trying to figure out how things work and ran
> into a bit of a problem.
>
> From various other posts I found a way of having an image background in
> my diagram, but after adding the code below I cant create new
> elements/nodes to it?
>
> I created a FreeFormImageLayer class like this:
>
> public class FreeFormImageLayer extends FreeformLayer {
> Image image;
> DiagramEditPart ownerEditPart;
>
> public FreeFormImageLayer(final Image image, final DiagramEditPart
> ownerEditPart){
> this.image = image;
> this.ownerEditPart = ownerEditPart;
> }
>
>
> 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();
>
> Rectangle r = getBounds().getCopy();
> ownerEditPart.getFigure().translateToParent(r);
> r.intersect(ownerEditPart.getFigure().getClientArea());
>
> org.eclipse.swt.graphics.Rectangle imgBox =
> getImage().getBounds();
>
> System.out.printf("r=(%d,%d,%d,%d)\n",
> r.x, r.y, r.width, r.height);
>
> System.out.printf("(%d,%d,%d,%d) -> (%d,%d,%d,%d)\n",
> imgBox.x, imgBox.y, imgBox.width, imgBox.height,
> targetRect.x, targetRect.y, targetRect.width,
> targetRect.height);
>
> long t1 = System.currentTimeMillis();
> System.out.println("Start draw image");
> /*
> graphics.drawImage(getImage(), 0, 0, imgBox.width,
> imgBox.height,
> targetRect.x, targetRect.y, targetRect.width,
> targetRect.height);
> */
> System.out.println("Graphics absolute scale: "
> +graphics.getAbsoluteScale());
> graphics.drawImage(getImage(), 0, 0);
> System.out.println("End draw image, took
> "+(System.currentTimeMillis()-t1) +" ms");
> }
>
> super.paintFigure(graphics);
> }
>
> @Override
> public Rectangle getFreeformExtent() {
> // TODO Auto-generated method stub
> //return super.getFreeformExtent();
>
> return new Rectangle(0,0, image.getBounds().width/10,
> image.getBounds().height/10);
> }
>
> }
>
> Which I then add to my diagram edit part in its createFigure like this:
>
> protected IFigure createFigure() {
>
> System.out.println(getClass().getName() + " : In createFigure()");
> image = null;
> EObject eObj = ((Diagram)getModel()).getElement();
> String fileStr =((Project)eObj).getMapFile();
> fileStr = "/home/mikael/Desktop/mapClean.jpg";
>
>
> createImages( fileStr );
> ScalableLayeredPane pane = new ScalableLayeredPane();
> pane.setBounds(new Rectangle(image.getBounds()));
>
> imageLayer = new FreeFormImageLayer(image,this);
>
> pane.add(imageLayer);
> pane.add(contentPane = super.createFigure());
> System.out.println(getClass().getName() +"End createFigure");
>
> return pane;
>
> }
>
> void createImages(final String fileStr){
>
> InputStream is;
> try {
> is = new FileInputStream(fileStr);
> image = new Image(PlatformUI.getWorkbench().getDisplay(),
> is);
>
> } catch (FileNotFoundException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
>
> }//Thread.currentThread().getContextClassLoader().getResourc eAsStream(
> fileStr );
>
> if(image == null){
> image = new
> Image(PlatformUI.getWorkbench().getDisplay(),300,300);
> image.setBackground(ColorConstants.blue);
> }
>
> }
>
> Please ignore all the print statements, I'm having another issue with
> extremely slow (2.5 second) render times when zooming the slightest.
>
> Any help really appreciated.
>
> Cheers,
> Micke
Re: Diagram background, can't add elements? [message #172159 is a reply to message #171954] Mon, 11 February 2008 16:06 Go to previous messageGo to next message
Cherie Revells is currently offline Cherie RevellsFriend
Messages: 299
Registered: July 2009
Senior Member
Micke,

I can still add ship shapes on a Taipan diagram even right on top of the
background image. I would suggest debugging your code and comparing
with what happens in the Taipan diagram. Without knowing anything about
what is going wrong, I would say a good starting point would be to put a
breakpoint in the CreationEditPolicy.getCommand() method and try
creating a shape.

Regards,
Cherie

Mikael Andersson wrote:
> Hi
>
> Due to the lack of replies I suspect that; the question wasn't very
> clear , this is not a gmf problem or a RTFM issue.
>
> Would be nice top pinpoint which of the three it is, would be very
> grateful if someone with a bit of experience could reply. Because I'm at
> the point of giving up on this.
>
> Cheers,
> Micke
>
> Mikael Andersson wrote:
>> Hi all,
>> I'm experimenting with GMF trying to figure out how things work and
>> ran into a bit of a problem.
>>
>> From various other posts I found a way of having an image background
>> in my diagram, but after adding the code below I cant create new
>> elements/nodes to it?
>>
>> I created a FreeFormImageLayer class like this:
>>
>> public class FreeFormImageLayer extends FreeformLayer {
>> Image image;
>> DiagramEditPart ownerEditPart;
>> public FreeFormImageLayer(final Image image, final
>> DiagramEditPart ownerEditPart){
>> this.image = image;
>> this.ownerEditPart = ownerEditPart;
>> }
>>
>> 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();
>> Rectangle r = getBounds().getCopy();
>> ownerEditPart.getFigure().translateToParent(r);
>> r.intersect(ownerEditPart.getFigure().getClientArea());
>> org.eclipse.swt.graphics.Rectangle imgBox =
>> getImage().getBounds();
>> System.out.printf("r=(%d,%d,%d,%d)\n",
>> r.x, r.y, r.width, r.height);
>> System.out.printf("(%d,%d,%d,%d) ->
>> (%d,%d,%d,%d)\n",
>> imgBox.x, imgBox.y, imgBox.width, imgBox.height,
>> targetRect.x, targetRect.y, targetRect.width,
>> targetRect.height);
>> long t1 = System.currentTimeMillis();
>> System.out.println("Start draw image");
>> /*
>> graphics.drawImage(getImage(), 0, 0, imgBox.width,
>> imgBox.height,
>> targetRect.x, targetRect.y, targetRect.width,
>> targetRect.height);
>> */
>> System.out.println("Graphics absolute scale: "
>> +graphics.getAbsoluteScale());
>> graphics.drawImage(getImage(), 0, 0);
>> System.out.println("End draw image, took
>> "+(System.currentTimeMillis()-t1) +" ms");
>> }
>> super.paintFigure(graphics);
>> }
>>
>> @Override
>> public Rectangle getFreeformExtent() {
>> // TODO Auto-generated method stub
>> //return super.getFreeformExtent();
>> return new Rectangle(0,0, image.getBounds().width/10,
>> image.getBounds().height/10);
>> }
>>
>> }
>>
>> Which I then add to my diagram edit part in its createFigure like this:
>>
>> protected IFigure createFigure() {
>>
>> System.out.println(getClass().getName() + " : In
>> createFigure()");
>> image = null; EObject eObj =
>> ((Diagram)getModel()).getElement();
>> String fileStr =((Project)eObj).getMapFile();
>> fileStr = "/home/mikael/Desktop/mapClean.jpg";
>> createImages( fileStr );
>> ScalableLayeredPane pane = new ScalableLayeredPane();
>> pane.setBounds(new Rectangle(image.getBounds()));
>> imageLayer = new FreeFormImageLayer(image,this);
>> pane.add(imageLayer);
>> pane.add(contentPane = super.createFigure());
>> System.out.println(getClass().getName() +"End createFigure");
>> return pane;
>>
>> }
>> void createImages(final String fileStr){
>> InputStream is;
>> try {
>> is = new FileInputStream(fileStr);
>> image = new Image(PlatformUI.getWorkbench().getDisplay(),
>> is); } catch (FileNotFoundException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>>
>> }//Thread.currentThread().getContextClassLoader().getResourc eAsStream(
>> fileStr );
>> if(image == null){
>> image = new
>> Image(PlatformUI.getWorkbench().getDisplay(),300,300);
>> image.setBackground(ColorConstants.blue);
>> }
>> }
>>
>> Please ignore all the print statements, I'm having another issue with
>> extremely slow (2.5 second) render times when zooming the slightest.
>>
>> Any help really appreciated.
>>
>> Cheers,
>> Micke
Re: Diagram background, can't add elements? [message #172241 is a reply to message #172159] Mon, 11 February 2008 22:28 Go to previous message
Eclipse UserFriend
Originally posted by: mail.micke.gmail.com

Thanks for the hint, very valuable since I have no idea about where to
start:).
Will debug this asap, currently struggling a bit to find the necessary
source jars.

Thanks again,
Micke

Cherie Revells wrote:
> Micke,
>
> I can still add ship shapes on a Taipan diagram even right on top of the
> background image. I would suggest debugging your code and comparing
> with what happens in the Taipan diagram. Without knowing anything about
> what is going wrong, I would say a good starting point would be to put a
> breakpoint in the CreationEditPolicy.getCommand() method and try
> creating a shape.
>
> Regards,
> Cherie
>
> Mikael Andersson wrote:
>> Hi
>>
>> Due to the lack of replies I suspect that; the question wasn't very
>> clear , this is not a gmf problem or a RTFM issue.
>>
>> Would be nice top pinpoint which of the three it is, would be very
>> grateful if someone with a bit of experience could reply. Because I'm
>> at the point of giving up on this.
>>
>> Cheers,
>> Micke
>>
>> Mikael Andersson wrote:
>>> Hi all,
>>> I'm experimenting with GMF trying to figure out how things work and
>>> ran into a bit of a problem.
>>>
>>> From various other posts I found a way of having an image background
>>> in my diagram, but after adding the code below I cant create new
>>> elements/nodes to it?
>>>
>>> I created a FreeFormImageLayer class like this:
>>>
>>> public class FreeFormImageLayer extends FreeformLayer {
>>> Image image;
>>> DiagramEditPart ownerEditPart;
>>> public FreeFormImageLayer(final Image image, final
>>> DiagramEditPart ownerEditPart){
>>> this.image = image;
>>> this.ownerEditPart = ownerEditPart;
>>> }
>>> 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();
>>> Rectangle r = getBounds().getCopy();
>>> ownerEditPart.getFigure().translateToParent(r);
>>> r.intersect(ownerEditPart.getFigure().getClientArea());
>>> org.eclipse.swt.graphics.Rectangle imgBox =
>>> getImage().getBounds();
>>> System.out.printf("r=(%d,%d,%d,%d)\n",
>>> r.x, r.y, r.width, r.height);
>>> System.out.printf("(%d,%d,%d,%d) ->
>>> (%d,%d,%d,%d)\n",
>>> imgBox.x, imgBox.y, imgBox.width, imgBox.height,
>>> targetRect.x, targetRect.y, targetRect.width,
>>> targetRect.height);
>>> long t1 = System.currentTimeMillis();
>>> System.out.println("Start draw image");
>>> /*
>>> graphics.drawImage(getImage(), 0, 0, imgBox.width,
>>> imgBox.height,
>>> targetRect.x, targetRect.y, targetRect.width,
>>> targetRect.height);
>>> */
>>> System.out.println("Graphics absolute scale: "
>>> +graphics.getAbsoluteScale());
>>> graphics.drawImage(getImage(), 0, 0);
>>> System.out.println("End draw image, took
>>> "+(System.currentTimeMillis()-t1) +" ms");
>>> }
>>> super.paintFigure(graphics);
>>> }
>>>
>>> @Override
>>> public Rectangle getFreeformExtent() {
>>> // TODO Auto-generated method stub
>>> //return super.getFreeformExtent();
>>> return new Rectangle(0,0, image.getBounds().width/10,
>>> image.getBounds().height/10);
>>> }
>>>
>>> }
>>>
>>> Which I then add to my diagram edit part in its createFigure like this:
>>>
>>> protected IFigure createFigure() {
>>>
>>> System.out.println(getClass().getName() + " : In
>>> createFigure()");
>>> image = null; EObject eObj =
>>> ((Diagram)getModel()).getElement();
>>> String fileStr =((Project)eObj).getMapFile();
>>> fileStr = "/home/mikael/Desktop/mapClean.jpg";
>>> createImages( fileStr );
>>> ScalableLayeredPane pane = new ScalableLayeredPane();
>>> pane.setBounds(new Rectangle(image.getBounds()));
>>> imageLayer = new FreeFormImageLayer(image,this);
>>> pane.add(imageLayer);
>>> pane.add(contentPane = super.createFigure());
>>> System.out.println(getClass().getName() +"End createFigure");
>>> return pane;
>>>
>>> }
>>> void createImages(final String fileStr){
>>> InputStream is;
>>> try {
>>> is = new FileInputStream(fileStr);
>>> image = new Image(PlatformUI.getWorkbench().getDisplay(),
>>> is); } catch (FileNotFoundException e) {
>>> // TODO Auto-generated catch block
>>> e.printStackTrace();
>>>
>>> }//Thread.currentThread().getContextClassLoader().getResourc eAsStream(
>>> fileStr );
>>> if(image == null){
>>> image = new
>>> Image(PlatformUI.getWorkbench().getDisplay(),300,300);
>>> image.setBackground(ColorConstants.blue);
>>> }
>>> }
>>>
>>> Please ignore all the print statements, I'm having another issue with
>>> extremely slow (2.5 second) render times when zooming the slightest.
>>>
>>> Any help really appreciated.
>>>
>>> Cheers,
>>> Micke
Previous Topic:add a new instance Programatically in the editor view
Next Topic:Creating diagram from domain model programatically
Goto Forum:
  


Current Time: Tue Apr 23 09:31:57 GMT 2024

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

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

Back to the top