GMF学习系列(二) 一些知识点(续)
2011-10-26 17:14
274 查看
4、使用ConnectionHandler连接到canvas上已存在的图形或创建新的图形
覆盖XXXModelingAssistantProvider里的几个get方法,要连接到已存在的图形覆盖getRelTypesOnSourceAndTarget()方法,创建新的作为源的图形覆盖getRelTypesOnSource()和getTypesForTarget()方法,创建新的作为目标的图形应覆盖getRelTypesOnTarget()和getTypesForSource()方法。具体代码可参考LogicModelingAssistantProvider里的实现。
5 如何设置Compartment为自动填充父窗口
以工程中的Layer为例:
在****EditPart类的内部类****Figure的构造函数改为:
public BlueprintLayerFigure() {
ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
layout.setStretchMajorAxis(true);
layout.setStretchMinorAxis(true);
layout.setMinorAlignment(ConstrainedToolbarLayout.ALIGN_TOPLEFT);
//optional
layout.setVertical(true);
layout.setSpacing(5);
// add layout to make compartment rectangle can extend automatically while resizing parent node.
this.setLayoutManager(layout);
this.setBackgroundColor(THIS_BACK);
this.setPreferredSize(new Dimension(getMapMode().DPtoLP(850), getMapMode().DPtoLP(200)));
createContents();
}
但是这样的话,Name Label也会同时自动扩充,可以通过设定Name Label的最大高度来限制
****LayerNameFigure.setMaximumSize(new Dimension(1850,30));
6.确定连线中连线的锚点
找到相应的EditPart文件,添加四个方法,
/**
* @generated NOT
*/
@Override
public ConnectionAnchor getSourceConnectionAnchor(
ConnectionEditPart connEditPart) {
return new LinkAnchor(getFigure());
}
/**
* @generated NOT
*/
@Override
public ConnectionAnchor getSourceConnectionAnchor(Request request) {
return new LinkAnchor(getFigure());
}
/**
* @generated NOT
*/
@Override
public ConnectionAnchor getTargetConnectionAnchor(
ConnectionEditPart connEditPart) {
return new LinkAnchor(getFigure(), false);
}
/**
* @generated NOT
*/
@Override
public ConnectionAnchor getTargetConnectionAnchor(Request request) {
return new LinkAnchor(getFigure(), false);
}
可以使用系统提供的一些Anchor,也可以自定义Anchor。
自定义Anchor需要继承自AbstractConnectionAnchor,并实现getLocation方法。
本文中的是
import org.eclipse.draw2d.*;
import org.eclipse.draw2d.geometry.*;
public class LinkAnchor extends AbstractConnectionAnchor {
private boolean IsSource=true;
public LinkAnchor(IFigure figure)
{
super(figure);
}
public LinkAnchor(IFigure figure,boolean issource)
{
this(figure);
IsSource=issource;
}
public Point getLocation(Point loc)
{
Rectangle r = getOwner().getBounds();
int x = r.x+r.width/2;
int y = r.y+r.height;
if(!IsSource)
{
x = r.x+r.width/2;
y = r.y;
}
Point p = new Point(x,y);
getOwner().translateToAbsolute(p);
return p;
}
}
7.为了测试,在VariableContentProvider中添加了一些数据。在DesignProcessPropertySection中的createControl中添加了initialize()方法。
覆盖XXXModelingAssistantProvider里的几个get方法,要连接到已存在的图形覆盖getRelTypesOnSourceAndTarget()方法,创建新的作为源的图形覆盖getRelTypesOnSource()和getTypesForTarget()方法,创建新的作为目标的图形应覆盖getRelTypesOnTarget()和getTypesForSource()方法。具体代码可参考LogicModelingAssistantProvider里的实现。
5 如何设置Compartment为自动填充父窗口
以工程中的Layer为例:
在****EditPart类的内部类****Figure的构造函数改为:
public BlueprintLayerFigure() {
ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
layout.setStretchMajorAxis(true);
layout.setStretchMinorAxis(true);
layout.setMinorAlignment(ConstrainedToolbarLayout.ALIGN_TOPLEFT);
//optional
layout.setVertical(true);
layout.setSpacing(5);
// add layout to make compartment rectangle can extend automatically while resizing parent node.
this.setLayoutManager(layout);
this.setBackgroundColor(THIS_BACK);
this.setPreferredSize(new Dimension(getMapMode().DPtoLP(850), getMapMode().DPtoLP(200)));
createContents();
}
但是这样的话,Name Label也会同时自动扩充,可以通过设定Name Label的最大高度来限制
****LayerNameFigure.setMaximumSize(new Dimension(1850,30));
6.确定连线中连线的锚点
找到相应的EditPart文件,添加四个方法,
/**
* @generated NOT
*/
@Override
public ConnectionAnchor getSourceConnectionAnchor(
ConnectionEditPart connEditPart) {
return new LinkAnchor(getFigure());
}
/**
* @generated NOT
*/
@Override
public ConnectionAnchor getSourceConnectionAnchor(Request request) {
return new LinkAnchor(getFigure());
}
/**
* @generated NOT
*/
@Override
public ConnectionAnchor getTargetConnectionAnchor(
ConnectionEditPart connEditPart) {
return new LinkAnchor(getFigure(), false);
}
/**
* @generated NOT
*/
@Override
public ConnectionAnchor getTargetConnectionAnchor(Request request) {
return new LinkAnchor(getFigure(), false);
}
可以使用系统提供的一些Anchor,也可以自定义Anchor。
自定义Anchor需要继承自AbstractConnectionAnchor,并实现getLocation方法。
本文中的是
import org.eclipse.draw2d.*;
import org.eclipse.draw2d.geometry.*;
public class LinkAnchor extends AbstractConnectionAnchor {
private boolean IsSource=true;
public LinkAnchor(IFigure figure)
{
super(figure);
}
public LinkAnchor(IFigure figure,boolean issource)
{
this(figure);
IsSource=issource;
}
public Point getLocation(Point loc)
{
Rectangle r = getOwner().getBounds();
int x = r.x+r.width/2;
int y = r.y+r.height;
if(!IsSource)
{
x = r.x+r.width/2;
y = r.y;
}
Point p = new Point(x,y);
getOwner().translateToAbsolute(p);
return p;
}
}
7.为了测试,在VariableContentProvider中添加了一些数据。在DesignProcessPropertySection中的createControl中添加了initialize()方法。
相关文章推荐
- GMF学习系列(二) 一些知识点
- GMF学习系列(二) 一些知识点(续3)
- 关于rman duplicate 一些比較重要的知识点--系列三
- 关于rman duplicate 一些比较重要的知识点--系列三
- selenium2.0&WebDriver学习系列(一些需要注意的知识点)
- GMF学习系列(二) 一些知识点(续2)
- 关于Windows的一些知识点
- [kaggle系列 四] 通过mnist来研究神经网络的一些细节(1)
- ASP.net 2.0 中 WebResource.axd 管理资源的一些知识点
- 一些LinuxC的小知识点(二)
- java一些小知识点
- 移动端H5的一些基本知识点总结
- 给Java新手的一些建议----Java知识点归纳(J2EE and Web 部分)
- CSS一些知识点
- C#知识点总结系列
- 那些不能遗忘的知识点回顾----操作系统系列
- Python知识点:正负无穷的一些用法
- 项目管理系列:项目团队建设的一些经验
- 关于C++语言的一些小知识点
- html5一些知识点Canvas : Shadow,大家可以看下!