Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Creating Elliptical Shape
Creating Elliptical Shape [message #173064] Wed, 20 February 2008 09:35 Go to next message
Toyin is currently offline ToyinFriend
Messages: 35
Registered: July 2009
Member
Hi People,

Please, has anyone tried working through the titorial - Learn Eclipse GMF
in 15 minutes; found on the link below:
http://www-128.ibm.com/developerworks/opensource/library/os- ecl-gmf/

I followed the tutorial word-for-word, but in the end, I could not create
any elliptical shape. Has any one successfully implemented this tutorial
or is there any other way to create other shapes or could it be that the
ecore model is incorrect? .

Thanks,
Toyin
Re: Creating Elliptical Shape [message #173072 is a reply to message #173064] Wed, 20 February 2008 10:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

Toyin Fakorede wrote:
is there any other way to create other shapes

Yep :)

If your want to create a shape of your own, you can use an image - or
create it easily in the graph.

Just switch the rectangle figure with a scalable polygon and fill in
points (+ colors, layout and label).

For an elliptical shape, there is already a predefined shape.


Tomas
Re: Creating Elliptical Shape [message #173472 is a reply to message #173072] Thu, 21 February 2008 16:31 Go to previous messageGo to next message
Toyin is currently offline ToyinFriend
Messages: 35
Registered: July 2009
Member
Please where and how do I create my own shape.
Sorry, Im still a novies.

Thanks


Toyin Fakorede wrote:
is there any other way to create other shapes

Yep :)

If your want to create a shape of your own, you can use an image - or
create it easily in the graph.

Just switch the rectangle figure with a scalable polygon and fill in
points (+ colors, layout and label).

For an elliptical shape, there is already a predefined shape.


Tomas
Re: Creating Elliptical Shape [message #173542 is a reply to message #173472] Fri, 22 February 2008 09:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

Toyin Fakorede wrote:
>
>
> Please where and how do I create my own shape.
You can either define it graphically in .graph by switching out your
rectangle in Figure Gallery -> Figure Descriptor, or you can do it with
code in your xyzEditPart, like this:

public class PropertyNodeFigure extends Ellipse {

private WrapLabel fFigurePropertyNodeNameFigure;

public PropertyNodeFigure() {

this.setLayoutManager(new StackLayout());
this.setForegroundColor(ColorConstants.black);
this.setBackgroundColor(ColorConstants.green);
this.setMinimumSize(new Dimension(getMapMode().DPtoLP(100),
getMapMode().DPtoLP(40)));
createContents();
}
....

> Sorry, Im still a novies.

We all are :)


>
> Thanks
>
>
> Toyin Fakorede wrote:
> is there any other way to create other shapes
>
> Yep :)
>
> If your want to create a shape of your own, you can use an image - or
> create it easily in the graph.
>
> Just switch the rectangle figure with a scalable polygon and fill in
> points (+ colors, layout and label).
>
> For an elliptical shape, there is already a predefined shape.
>
>
> Tomas
>
Re: Creating Elliptical Shape [message #174150 is a reply to message #173542] Mon, 25 February 2008 15:43 Go to previous messageGo to next message
Toyin is currently offline ToyinFriend
Messages: 35
Registered: July 2009
Member
Hi Tomas,

Many thanks for your help, Tomas. I tried your advice and it worked. Going
a step further, what if I want to create an unusual/irregular shape like -
a cloud. How do I go about it?
I realized that creating other shapes will involve modifying the
properties of other shapes e.g rectangle, polygons, ellipse e.t.c But
creating a cloud, Im not sure if I can modify other predefined shapes.

Please, what do I do?

Thanks alot :D,
Toyin
Re: Creating Elliptical Shape [message #174272 is a reply to message #174150] Mon, 25 February 2008 21:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

Toyin Fakorede wrote:
> Hi Tomas,
>
> Many thanks for your help, Tomas. I tried your advice and it worked.
> Going a step further, what if I want to create an unusual/irregular
> shape like - a cloud. How do I go about it?
> I realized that creating other shapes will involve modifying the
> properties of other shapes e.g rectangle, polygons, ellipse e.t.c But
> creating a cloud, Im not sure if I can modify other predefined shapes.
>
> Please, what do I do?

You have two options:
1. Create your customshape with template points in the graph, or by code
like below.


In class: xyzEditPart
public class xyzNodeFigure extends Shape {
....
public xyzNodeFigure() {
this.setLayoutManager(new StackLayout()); this.addPoint(new
Point(getMapMode().DPtoLP(50), getMapMode().DPtoLP(0)));

this.addPoint(new Point(getMapMode().DPtoLP(100),
getMapMode().DPtoLP(50)));

this.addPoint(new Point(getMapMode().DPtoLP(50),
getMapMode().DPtoLP(100)));

this.addPoint(new Point(getMapMode().DPtoLP(0),
getMapMode().DPtoLP(50)));

this.setForegroundColor(ColorConstants.black);
this.setBackgroundColor(ColorConstants.green);
createContents();
}

2. Since the above 2D method is unsuited to figures like a cloud - you
could use an svg image. That process is described here:

http://wiki.eclipse.org/GMF_Tutorial_BPMN#Custom_Figures_.28 SVG.29

If you need to create the figure from scratch, Incscape is a great tool.


Hope this helps,

Tomas Zijdemans
Re: Creating Elliptical Shape [message #174989 is a reply to message #174272] Fri, 29 February 2008 14:43 Go to previous messageGo to next message
Toyin is currently offline ToyinFriend
Messages: 35
Registered: July 2009
Member
Hi Tomas,

Thanks for your responses.
I tried using inkscape and followed the BPMN tutorial. However, I got some
errors.
Im posting the java code for you to view, just incase you find any errors:
The protected IFigure createNodeShape() is the method thats giving errors.
Please, I need your help. Thanks

package classmodel.diagram.edit.parts;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.StackLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
import org.eclipse.gef.requests.CreateRequest;
import
org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBordere dShapeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEdit Part;
import
org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSe lectionEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRo les;
import org.eclipse.gmf.runtime.diagram.ui.figures.BorderItemLocator ;
import
org.eclipse.gmf.runtime.draw2d.ui.render.figures.ScalableIma geFigure;
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure ;
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
import org.eclipse.gmf.runtime.notation.View;

import classmodel.diagram.edit.policies.ClassItemSemanticEditPolicy ;
import classmodel.diagram.part.ClassModelVisualIDRegistry;

/**
* @generated
*/
public class ClassEditPart extends AbstractBorderedShapeEditPart {

/**
* @generated
*/
public static final int VISUAL_ID = 1001;

/**
* @generated
*/
protected IFigure contentPane;

/**
* @generated
*/
protected IFigure primaryShape;

/**
* @generated
*/
public ClassEditPart(View view) {
super(view);
}

/**
* @generated
*/
protected void createDefaultEditPolicies() {

super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
new ClassItemSemanticEditPolicy());
installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
// XXX need an SCR to runtime to have another abstract superclass that
would let children add reasonable editpolicies
//
removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpoli cies.EditPolicyRoles.CONNECTION_HANDLES_ROLE);
}

/**
* @generated
*/
protected LayoutEditPolicy createLayoutEditPolicy() {
LayoutEditPolicy lep = new LayoutEditPolicy() {

protected EditPolicy createChildEditPolicy(EditPart child) {
if (child instanceof IBorderItemEditPart) {
return new BorderItemSelectionEditPolicy();
}
EditPolicy result = child
.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
if (result == null) {
result = new NonResizableEditPolicy();
}
return result;
}

protected Command getMoveChildrenCommand(Request request) {
return null;
}

protected Command getCreateCommand(CreateRequest request) {
return null;
}
};
return lep;
}

/**
* @generated NOT
*/
protected IFigure createNodeShape() {
URL url =
FileLocator.find(ClassModelDiagramEditorPlugin.getInstance() .getBundle(),
new Path("images/Cloud.svg"), null); //$NON-NLS-1$
return new ScalableImageFigure(RenderedImageFactory.getInstance(url),
true, true, true);
}

/**
* @generated
*/
public ScalableImageFigure getPrimaryShape() {
return (ScalableImageFigure) primaryShape;
}

/**
* @generated
*/
protected void addBorderItem(IFigure borderItemContainer,
IBorderItemEditPart borderItemEditPart) {
if (borderItemEditPart instanceof ClassNameEditPart) {
BorderItemLocator locator = new BorderItemLocator(getMainFigure(),
PositionConstants.SOUTH);
locator.setBorderItemOffset(new Dimension(-20, -20));
borderItemContainer.add(borderItemEditPart.getFigure(), locator);
} else {
super.addBorderItem(borderItemContainer, borderItemEditPart);
}
}

/**
* @generated
*/
protected NodeFigure createNodePlate() {
DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode()
.DPtoLP(40), getMapMode().DPtoLP(40));
return result;
}

/**
* Creates figure for this edit part.
*
* Body of this method does not depend on settings in generation model
* so you may safely remove <i>generated</i> tag and modify it.
*
* @generated
*/
protected NodeFigure createMainFigure() {
NodeFigure figure = createNodePlate();
figure.setLayoutManager(new StackLayout());
IFigure shape = createNodeShape();
figure.add(shape);
contentPane = setupContentPane(shape);
return figure;
}

/**
* Default implementation treats passed figure as content pane.
* Respects layout one may have set for generated figure.
* @param nodeShape instance of generated figure class
* @generated
*/
protected IFigure setupContentPane(IFigure nodeShape) {
return nodeShape; // use nodeShape itself as contentPane
}

/**
* @generated
*/
public IFigure getContentPane() {
if (contentPane != null) {
return contentPane;
}
return super.getContentPane();
}

/**
* @generated
*/
public EditPart getPrimaryChildEditPart() {
return getChildBySemanticHint(ClassModelVisualIDRegistry
.getType(ClassNameEditPart.VISUAL_ID));
}

}
Re: Creating Elliptical Shape [message #175005 is a reply to message #174989] Fri, 29 February 2008 17:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

Toyin Fakorede wrote:
> Hi Tomas,
>
> Thanks for your responses.
> I tried using inkscape and followed the BPMN tutorial. However, I got
> some errors. Im posting the java code for you to view, just incase you
> find any errors:
> The protected IFigure createNodeShape() is the method thats giving errors.
> Please, I need your help. Thanks

As I mentioned earlier, I've never tried this (but many here have!).

The only tip I can give is to search this newsgroup, and check out the
taipan example (you can see how it's done there)


Cheers,

Tomas Zijdemans
Re: Creating Elliptical Shape [message #175331 is a reply to message #175005] Tue, 04 March 2008 02:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: yuanqiulu.163.com

I can show the customed picture but it couldn't move and the editor cannot
be edited anymore.
Re: Creating Elliptical Shape [message #175385 is a reply to message #175331] Tue, 04 March 2008 09:51 Go to previous messageGo to next message
Toyin is currently offline ToyinFriend
Messages: 35
Registered: July 2009
Member
Hi QiuluYUAN,
I'm having problems with this line of code:
return new ScalableImageFigure(RenderedImageFactory.getInstance(url),
true, true, true);

The error message being displayed is - The method getInstance(URL) is
undefined for the type RenderedImageFactory.

Please, help.

Or could u mail me your source code for the xxxEditPart.java file.

Thanks.

Toyin
Re: Creating Elliptical Shape [message #175462 is a reply to message #175385] Tue, 04 March 2008 11:52 Go to previous messageGo to next message
Richard Gronback is currently offline Richard GronbackFriend
Messages: 605
Registered: July 2009
Senior Member
Which version of GMF are you using, and what URL class is imported? (you'll
need java.net.URL)

This code works fine with the latest GMF:

URL url = FileLocator.find(Activator.getDefault().getBundle(), new
Path("images" + IPath.SEPARATOR + "ievent.svg"), null);
return new
ScalableImageFigure(RenderedImageFactory.getInstance(url), true, true,
true);


On 3/4/08 4:51 AM, in article
62ec7bec8c81efd3fc5c6af716d8d6b8$1@www.eclipse.org, "Toyin Fakorede"
<fakoredejohnson5@yahoo.com> wrote:

> Hi QiuluYUAN,
> I'm having problems with this line of code:
> return new ScalableImageFigure(RenderedImageFactory.getInstance(url),
> true, true, true);
>
> The error message being displayed is - The method getInstance(URL) is
> undefined for the type RenderedImageFactory.
>
> Please, help.
>
> Or could u mail me your source code for the xxxEditPart.java file.
>
> Thanks.
>
> Toyin
>
>
Re: Creating Elliptical Shape [message #175501 is a reply to message #175385] Tue, 04 March 2008 13:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: yuanqiulu.163.com

The problem I mentioned above has been solved this afternoon.
The following are my codes(EmptyEditPart.java):
package webapplication.diagram.edit.parts;

import java.net.URL;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.StackLayout;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;

import org.eclipse.gef.commands.Command;

import org.eclipse.gef.editpolicies.LayoutEditPolicy;
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;

import org.eclipse.gef.requests.CreateRequest;

import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPa rt;

import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRo les;

import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbar Layout;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
import
org.eclipse.gmf.runtime.draw2d.ui.render.factory.RenderedIma geFactory;
import
org.eclipse.gmf.runtime.draw2d.ui.render.figures.ScalableIma geFigure;

import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure ;
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;

import org.eclipse.gmf.runtime.notation.View;

import
webapplication.diagram.edit.policies.ClientBrowserItemSemant icEditPolicy;

import webapplication.diagram.part.WebApplicationDiagramEditorPlugi n;
import webapplication.diagram.part.WebApplicationVisualIDRegistry;

/**
* @generated
*/
public class ClientBrowserEditPart extends ShapeNodeEditPart {

/**
* @generated
*/
public static final int VISUAL_ID = 2001;

/**
* @generated
*/
protected IFigure contentPane;

/**
* @generated
*/
protected IFigure primaryShape;

/**
* @generated
*/
public ClientBrowserEditPart(View view) {
super(view);
}

/**
* @generated
*/
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
new ClientBrowserItemSemanticEditPolicy());
installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());

}

/**
* @generated
*/
protected LayoutEditPolicy createLayoutEditPolicy() {
LayoutEditPolicy lep = new LayoutEditPolicy() {

protected EditPolicy createChildEditPolicy(EditPart child) {
EditPolicy result = child
.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
if (result == null) {
result = new NonResizableEditPolicy();
}
return result;
}

protected Command getMoveChildrenCommand(Request request) {
return null;
}

protected Command getCreateCommand(CreateRequest request) {
return null;
}
};
return lep;
}

/**
* @generated
*/
protected IFigure createNodeShape() {
URL url = FileLocator.find(WebApplicationDiagramEditorPlugin
.getInstance().getBundle(), new Path("icons/invoke.svg"), null);
return new ScalableImageFigure(RenderedImageFactory.getInstance(url),
true, true, true);
}

/**
* @generated
*/
public ScalableImageFigure getPrimaryShape() {
return (ScalableImageFigure) primaryShape;
}
/**
* @generated
*/
private org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel
fClientBrowserNameFigure;
/**
* @generated
*/
protected boolean addFixedChild(EditPart childEditPart) {
fClientBrowserNameFigure = new WrapLabel();
if (childEditPart instanceof ClientBrowserNameEditPart) {
((ClientBrowserNameEditPart) childEditPart)
.setLabel(fClientBrowserNameFigure);
return true;
}
return false;
}

/**
* @generated
*/
protected boolean removeFixedChild(EditPart childEditPart) {
return false;
}

/**
* @generated
*/
protected NodeFigure createNodePlate() {
DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode()
.DPtoLP(40), getMapMode().DPtoLP(40));
return result;
}

/**
* Creates figure for this edit part.
*
* Body of this method does not depend on settings in generation model
* so you may safely remove <i>generated</i> tag and modify it.
*
* @generated
*/
protected NodeFigure createNodeFigure() {
NodeFigure figure = createNodePlate();
figure.setLayoutManager(new StackLayout());
IFigure shape = createNodeShape();
figure.add(shape);
contentPane = setupContentPane(shape);
return figure;
}

/**
* Default implementation treats passed figure as content pane.
* Respects layout one may have set for generated figure.
* @param nodeShape instance of generated figure class
* @generated
*/
protected IFigure setupContentPane(IFigure nodeShape) {
if (nodeShape.getLayoutManager() == null) {
ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
layout.setSpacing(getMapMode().DPtoLP(5));
nodeShape.setLayoutManager(layout);
}
return nodeShape; // use nodeShape itself as contentPane
}

/**
* @generated
*/
public IFigure getContentPane() {
if (contentPane != null) {
return contentPane;
}
return super.getContentPane();
}

/**
* @generated
*/
public EditPart getPrimaryChildEditPart() {
return getChildBySemanticHint(WebApplicationVisualIDRegistry
.getType(ClientBrowserNameEditPart.VISUAL_ID));
}

/**
* @generated
*/
protected void addChildVisual(EditPart childEditPart, int index) {
if (addFixedChild(childEditPart)) {
return;
}
super.addChildVisual(childEditPart, -1);
}

/**
* @generated
*/
protected void removeChildVisual(EditPart childEditPart) {
if (removeFixedChild(childEditPart)) {
return;
}
super.removeChildVisual(childEditPart);
}

/**
* @generated
*/
public class ClientBrowserFigure extends
org.eclipse.draw2d.RectangleFigure {
/**
* @generated
*/
public ClientBrowserFigure() {
this.setFill(true);
this.setFillXOR(false);
this.setOutline(true);
this.setOutlineXOR(false);
this.setLineWidth(1);
this.setLineStyle(org.eclipse.draw2d.Graphics.LINE_SOLID);
createContents();
}

/**
* @generated
*/
private void createContents() {

org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel
clientBrowserNameFigure0 = new
org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel();
clientBrowserNameFigure0.setText("<...>");

this.add(clientBrowserNameFigure0);
setFigureClientBrowserNameFigure(clientBrowserNameFigure0);

}

/**
* @generated
*/
private void setFigureClientBrowserNameFigure(
org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig) {
fClientBrowserNameFigure = fig;
}

/**
* @generated
*/
private boolean myUseLocalCoordinates = false;

/**
* @generated
*/
protected boolean useLocalCoordinates() {
return myUseLocalCoordinates;
}

/**
* @generated
*/
protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
myUseLocalCoordinates = useLocalCoordinates;
}

}

}
Re: Creating Elliptical Shape [message #175951 is a reply to message #175501] Thu, 06 March 2008 10:30 Go to previous messageGo to next message
Toyin is currently offline ToyinFriend
Messages: 35
Registered: July 2009
Member
Hi,
Many thanks for your code and help so far.

I tried the codes, I cant just place the problem. When I used this code:

protected IFigure createNodeShape() {
URL url = FileLocator.find(ShapeDiagramEditorPlugin
getInstance().getBundle(), new Path("images/cloud.svg"), null);
return new ScalableImageFigure(RenderedImageFactory.getInstance(url),
true, true, true);
}

It kept underlining the getInstance(url) saying that it's undefined for
the type RenderedImageFactory.

When I used an alternative code:

protected IFigure createNodeShape() {URL url =
FileLocator.find(Activator.getDefault().getBundle(), new Path("images" +
IPath.SEPARATOR + "cloud.svg"), null);
return new
ScalableImageFigure(RenderedImageFactory.getInstance(url), true, true,
true);

I got 2 errors: 1. The method getDefault() is undefined for the type
Activator.
2. getInstance(url) is undefined for the type RenderedImageFactory.


Please, what further advise can you give.

Im using GMF version 2.0.1.v20071003 - 0000 Build id: 2.1M2

Thank you.
Re: Creating Elliptical Shape [message #176374 is a reply to message #175951] Fri, 07 March 2008 08:40 Go to previous message
Eclipse UserFriend
Originally posted by: yuanqiulu.163.com

Well
My gmf version is 1.0.0.v20061013-1330
Previous Topic:Figure position on the diagram
Next Topic:GMFGEN - can I put a 'generated not' entry?
Goto Forum:
  


Current Time: Fri Dec 27 13:56:45 GMT 2024

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

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

Back to the top