Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Rectangle background image(How to set an image as backgrounf of rectangle)
Rectangle background image [message #825770] Wed, 21 March 2012 08:40 Go to next message
Ondra Netocny is currently offline Ondra NetocnyFriend
Messages: 12
Registered: July 2011
Junior Member
Hi, I am working on GMF aplication and I am quite new at GMF development. I am wondering if is there any possibility to set custom image as background of node/rectangle. I just need to draw a dashed line in the middle of rectangle, so I have tried to draw it programaticaly, but rectangle is also compartment node, so the drawing took place for child nodes. Since I have found out this, I am looking for way to set rectangle background image.
I wasnt able to find out any advice, but I think that there should be some way to achieve it. I would be very grateful for every advice.

Ondra

[Updated on: Wed, 21 March 2012 08:40]

Report message to a moderator

Re: Rectangle background image [message #825801 is a reply to message #825770] Wed, 21 March 2012 09:16 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

can you provide code of what you did?

Ralph
Re: Rectangle background image [message #832611 is a reply to message #825801] Fri, 30 March 2012 10:53 Go to previous messageGo to next message
Ondra Netocny is currently offline Ondra NetocnyFriend
Messages: 12
Registered: July 2011
Junior Member
I have created class MyRectangle, which I should be a background of compartment rectangle. The code of MyRectangle is something like this:
public class MyRectangle extends RoundedRectangle {
	
	public MyRectangle()
	{
		super();
		this.setOutline(false);
		this.setSize(100, 100);
	}
	
	@Override
	public void paintFigure(Graphics graphics)
	{
		super.paintFigure(graphics);
		graphics.setForegroundColor(ColorConstants.black);
		graphics.setForegroundColor(ColorConstants.black);
		graphics.setLineStyle(Graphics.LINE_DASH);
		graphics.setLineWidth(3);
		Rectangle r = getBounds();
		
		graphics.drawLine(
				new Point(r.x + r.width / 2, r.y + r.height * 0),
				new Point(r.x + r.width / 2, r.y + r.height * 1));

	}
}

And then I put this into compartment figure:
	public IFigure createFigure() {
		ResizableCompartmentFigure result = (ResizableCompartmentFigure) super
				.createFigure();
		MyRectangle rect = new MyRectangle();

		result.add(rect);

But this is not the right way, since MyRectangle took a space inside the compartment. Is there any posibility to set this as background?
Re: Rectangle background image [message #833351 is a reply to message #832611] Sat, 31 March 2012 10:29 Go to previous messageGo to next message
Andreas Muelder is currently offline Andreas MuelderFriend
Messages: 73
Registered: July 2011
Member
Hi,
what about overriding the paintFigure method of the ResizableCompartment?

ResizableCompartmentFigure figure = new ResizableCompartmentFigure(
				getCompartmentName(), getMapMode()) {
			@Override
			public void paint(Graphics graphics) {
				super.paintFigure(graphics);
				graphics.setForegroundColor(ColorConstants.black);
				graphics.setForegroundColor(ColorConstants.black);
				graphics.setLineStyle(Graphics.LINE_DASH);
				graphics.setLineWidth(3);
				Rectangle r = getBounds();

				graphics.drawLine(new Point(r.x + r.width / 2, r.y + r.height
						* 0), new Point(r.x + r.width / 2, r.y + r.height * 1));
			}
		};


Regards,
Andreas
Re: Rectangle background image [message #834190 is a reply to message #833351] Sun, 01 April 2012 14:59 Go to previous message
Ondra Netocny is currently offline Ondra NetocnyFriend
Messages: 12
Registered: July 2011
Junior Member
You have been faster, I found it too. Anyway, thanks a lot.
Previous Topic:Define OCL constrain for a modelElements association relationship
Next Topic:Moving figures in layout
Goto Forum:
  


Current Time: Fri Apr 19 12:21:33 GMT 2024

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

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

Back to the top