Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How can I create new geometrical shapes?
How can I create new geometrical shapes? [message #201104] Fri, 28 October 2005 22:33 Go to next message
Eclipse UserFriend
Originally posted by: ciulbecca.yahoo.it

How can I create new geometrical shapes to increase the shapes of draw2d
with the same feature?
Re: How can I create new geometrical shapes? [message #201134 is a reply to message #201104] Sat, 29 October 2005 21:07 Go to previous messageGo to next message
venkataramana m is currently offline venkataramana mFriend
Messages: 86
Registered: July 2009
Member
Follow the steps below ...
1. Create a new class (say Triangle) as subclass of Shape.
2. Implement outlineShape and fillShape methods for your new class (Triange). Use the methods available with the Graphics parameter passed to those two methods.

Graphics has methods like ...
public abstract class Graphics
{
	public final void drawArc(Rectangle r, int offset, int length) 

	public abstract void fillArc(int x, int y, int w, int h, int offset, int length)

	public final void drawLine(Point p1, Point p2)

	public final void drawOval(Rectangle r) 

	public final void fillOval(Rectangle r)

	public abstract void drawPolygon(PointList points)

	public abstract void fillPolygon(PointList points)

	public final void drawRectangle(Rectangle r) 

	public final void fillRectangle(Rectangle r)

	public abstract void drawText(String s, int x, int y)

	...
}


Thats it. You should be get going with wonderful geometrical shapes close to your heart.

Thanks
Venkat
Re: How can I create new geometrical shapes? [message #201148 is a reply to message #201134] Sun, 30 October 2005 10:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ciulbecca.yahoo.it

thanks venkataramana,
I have now a rhombus,...how can i do a connectionanchor like
elliptseanchor or chopboxanchor for the bounds of my new figure?...the
chopboxanchor leave empty space!
Re: How can I create new geometrical shapes? [message #201155 is a reply to message #201148] Sun, 30 October 2005 12:02 Go to previous messageGo to next message
venkataramana m is currently offline venkataramana mFriend
Messages: 86
Registered: July 2009
Member
I could not understand your question clearly. If you are looking for how to make connection-ends of different shapes, then may go through some sample tutorials listed below.

Check this link. http://www.eclipse.org/gef/reference/articles.html

You will get many references to tutorials and worked examples.

1. To start with read http://www.eclipse.org/gef/reference/GEF%20Tutorial%202005.p pt

2. Then read the Draw2D example from http://eclipse.org/articles/Article-GEF-Draw2d/GEF-Draw2d.ht ml

3. Then go ahead with Shapes example.http://eclipse.org/articles/Article-GEF-diagram-edit or/shape.html

4. After that I suggest you to go through Japanese GEF tutorials at http://www13.plala.or.jp/observe/index.html#draw2d
Though the samples are in Japanese, source-code could be understood very easily. The best examples available without any confusion for a novice.

5. After that, go to advanced examples like logic, flow, schema editors. etc.,

Thanks
~Venkat
Re: How can I create new geometrical shapes? [message #201163 is a reply to message #201155] Sun, 30 October 2005 20:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ciulbecca.yahoo.it

No....I could like to know how clip the connection against the bounds of
my polygonal figure without the standard chopbox.
Re: How can I create new geometrical shapes? [message #201202 is a reply to message #201163] Mon, 31 October 2005 06:32 Go to previous messageGo to next message
venkataramana m is currently offline venkataramana mFriend
Messages: 86
Registered: July 2009
Member
Try this anchor ...

class WhereYouPlaceThereYouGetAnchor extends AbstractConnectionAnchor
{
	private Point fLocation;
	private final int fRelativeDX;
	private final int fRelativeDY;
	
	public WhereYouPlaceThereYouGetAnchor(IFigure owner, Point p)
	{
		super(owner);
		fLocation = p;		
		
		Point ownerOrigin = getOwnerAbsoluteOrigin();//owner.getBounds().getLocation();
		fRelativeDX = p.x - ownerOrigin.x;
		fRelativeDY = p.y - ownerOrigin.y;
		
		//System.out.println("RelativeDX: " + fRelativeDX + " RelativeDY" + fRelativeDY);
	}
	
	private Point getOwnerAbsoluteOrigin() {
		Point ownerOrigin = getOwner().getBounds().getLocation();
		getOwner().translateToAbsolute(ownerOrigin);
		
		return ownerOrigin;
	}
	
	public Point getLocation(Point reference)
	{
		Point ownerOrigin = getOwnerAbsoluteOrigin();//getOwner().getBounds().getLocation();		 		
		Point newLocation = new Point(ownerOrigin.x + fRelativeDX, ownerOrigin.y + fRelativeDY);
		
		//System.out.println("OWNER_ORIGIN: " + ownerOrigin + " NEWLOCATION: " + newLocation);		
		
		return newLocation;
	}
	
	public Point getReferencePoint() {
		return getLocation(null);
	}
}

class GraphElementEditpart ...implements NodeEditpart
{
	public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart connection) {		
		//return new ChopboxAnchor(getFigure()); /* TODO Change anchors */
		return new WhereYouPlaceThereYouGetAnchor(getFigure(), 
				((GraphEdgeEditPart)connection).getGraphEdge().getSourceAnchorLocation());
	}

	public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart connection) {
		//return new ChopboxAnchor(getFigure()); /* TODO Change anchors */
		return new WhereYouPlaceThereYouGetAnchor(getFigure(), 
				((GraphEdgeEditPart)connection).getGraphEdge().getTargetAnchorLocation());
	}

	public ConnectionAnchor getSourceConnectionAnchor(Request request) {
		//return new ChopboxAnchor(getFigure()); /* TODO Change anchors */
		return new WhereYouPlaceThereYouGetAnchor(getFigure(), 
				((CreateConnectionRequest)request).getLocation());
	}

	public ConnectionAnchor getTargetConnectionAnchor(Request request) {
		//return new ChopboxAnchor(getFigure()); /* TODO Change anchors */
		return new WhereYouPlaceThereYouGetAnchor(getFigure(), 
				((CreateConnectionRequest)request).getLocation());
	}

}


From the CreateRequest, collect the position passed by getLocation() method and pass it to the constructor of WhereYouPlaceThereYouGetAnchor. Also pass the figure you are connecting to.

Whereever you click on a node, the connection stops there. So it can even be inside of your rhombus.

Thanks
Venkat
Re: How can I create new geometrical shapes? [message #201209 is a reply to message #201202] Mon, 31 October 2005 09:36 Go to previous message
Eclipse UserFriend
Originally posted by: ciulbecca.yahoo.it

In this part of code:..
[code/

class GraphElementEditpart ...implements NodeEditpart
{
public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart
connection) {
//return new ChopboxAnchor(getFigure()); /* TODO Change anchors */
return new WhereYouPlaceThereYouGetAnchor(getFigure(),
((GraphEdgeEditPart)connection).getGraphEdge().getSourceAnch orLocation());
}

public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart
connection) {
//return new ChopboxAnchor(getFigure()); /* TODO Change anchors */
return new WhereYouPlaceThereYouGetAnchor(getFigure(),
((GraphEdgeEditPart)connection).getGraphEdge().getTargetAnch orLocation());
}

public ConnectionAnchor getSourceConnectionAnchor(Request request) {
//return new ChopboxAnchor(getFigure()); /* TODO Change anchors */
return new WhereYouPlaceThereYouGetAnchor(getFigure(),
((CreateConnectionRequest)request).getLocation());
}

public ConnectionAnchor getTargetConnectionAnchor(Request request) {
//return new ChopboxAnchor(getFigure()); /* TODO Change anchors */
return new WhereYouPlaceThereYouGetAnchor(getFigure(),
((CreateConnectionRequest)request).getLocation());
}

}
/]code

How must rename or which import i must do to not obtain error in this part:
"GraphElementEditpart ..."
"GraphEdgeEditPart"
?

Thanks
Previous Topic:The presentation of the label text
Next Topic:Problem with GraphicalEditor and EditorPart
Goto Forum:
  


Current Time: Tue Nov 12 17:29:54 GMT 2024

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

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

Back to the top