GEF由于偏向的是以圖形表達模型,所以圖形表達能力一直都沒有java2d強,rotation新聞組從2004年就有人陸續不斷的提,但是3.5好像
也沒有列入,不過社區的力量就是強大,有人了contribute一段支持旋轉的代碼。我拿到代碼之后做了一個例子,由于它的transform不是
draw2d提供的平臺相關性transform(如java2d所做的調用windows system api
驅動硬件),所以rotation的效果不是很好,線條有些模糊。

安裝:
打開 https://bugs.eclipse.org/bugs/show_bug.cgi?id=117012,將附件下載下來,解壓縮放到插件目錄 (plugins或者dropins)。由于這是兩個fragements,不能直接加到plugin的dependencies,參見 http://bongyee.blogspot.com/2009/02/plug-in-dependencies-depend-on.html提 供的解決辦法。
更新代碼支持旋轉
在GEF中任何特征基本都會在MVC即model, editpart, figure三個層面做改動,rotation也不例外。
1 在model object上加一個屬性int rotation_angle記錄當前旋轉角度,添加get/set方法,且在set方法中觸發一個event給對應的editpart。
2 在editpart的createFigure方法中返回一個RotatableRectangleFigure。
3 稍微有點麻煩的就是修改Editpart了。在diagram editpart中安裝繼承了xylayouteditpolicy的editpolicy都會給child editpart默認安裝一個resizableeditpolicy,這樣選中一個editpart是就會在figure上出現八個handle,用來 move和resize。如果要支持rotation,覆蓋默認的resiableeditpolicy為 RotatableResizableEditPolicy(捐獻提供),覆蓋方式為:
RotateCommand非常簡單,execute的時候設置模型的角度 += angleDelta,undo的時候 -= angleDelta。
4 響應模型觸發的rotation事件,更新figure。
歡迎大家來信msn多多交流
安裝:
打開 https://bugs.eclipse.org/bugs/show_bug.cgi?id=117012,將附件下載下來,解壓縮放到插件目錄 (plugins或者dropins)。由于這是兩個fragements,不能直接加到plugin的dependencies,參見 http://bongyee.blogspot.com/2009/02/plug-in-dependencies-depend-on.html提 供的解決辦法。
更新代碼支持旋轉
在GEF中任何特征基本都會在MVC即model, editpart, figure三個層面做改動,rotation也不例外。
1 在model object上加一個屬性int rotation_angle記錄當前旋轉角度,添加get/set方法,且在set方法中觸發一個event給對應的editpart。
2 在editpart的createFigure方法中返回一個RotatableRectangleFigure。
3 稍微有點麻煩的就是修改Editpart了。在diagram editpart中安裝繼承了xylayouteditpolicy的editpolicy都會給child editpart默認安裝一個resizableeditpolicy,這樣選中一個editpart是就會在figure上出現八個handle,用來 move和resize。如果要支持rotation,覆蓋默認的resiableeditpolicy為 RotatableResizableEditPolicy(捐獻提供),覆蓋方式為:
public class XXDiagramEditPart
{

protected void createEditPolicies() {
.
installEditPolicy(EditPolicy.LAYOUT_ROLE, new QQQXYLayoutEditPolicy());

}

}
{

protected void createEditPolicies() {

installEditPolicy(EditPolicy.LAYOUT_ROLE, new QQQXYLayoutEditPolicy());

}

}
public class QQQXYLayoutEditPolicy
{

protected EditPolicy createChildEditPolicy(EditPart child) {
if (child is RotatableChildEditPart)
{
return new RotatableResizableEditPolicy(true){
旋轉命令
protected Command getRotateCommand(
RotatableChangeBoundsRequest request) {
return new RotateCommand(getHost().getModel(), request.getAngleDelta());
}

}
}
}

}
{

protected EditPolicy createChildEditPolicy(EditPart child) {
if (child is RotatableChildEditPart)
{
return new RotatableResizableEditPolicy(true){

protected Command getRotateCommand(
RotatableChangeBoundsRequest request) {
return new RotateCommand(getHost().getModel(), request.getAngleDelta());
}

}
}
}

}
RotateCommand非常簡單,execute的時候設置模型的角度 += angleDelta,undo的時候 -= angleDelta。
4 響應模型觸發的rotation事件,更新figure。
public class MyRotatableEditPart //register as listener for model changing.
{

public void propertyChange(PropertyChangeEvent evt) {
if (evt is Rotation Event)
{
//更新figure
((RotatableRectangleFigure)getFigure()).setAngle(getModel().getRotationAngle());
}
}

{

public void propertyChange(PropertyChangeEvent evt) {
if (evt is Rotation Event)
{
//更新figure
((RotatableRectangleFigure)getFigure()).setAngle(getModel().getRotationAngle());
}
}

歡迎大家來信msn多多交流