- 浏览: 264497 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (152)
- lucene (5)
- java (12)
- eclipse (2)
- GEF (34)
- SWT/JFACE/PLUGIN (58)
- EMF (8)
- GMF (0)
- fckeditor (1)
- AIX (1)
- 云计算 (2)
- 使用 Grails 构建富 Internet 应用程序 (1)
- Grails (1)
- 动态调用动态语言 (2)
- W3C DOM (3)
- Google Maps (1)
- 优化 (1)
- WebSphere (1)
- NSIS (1)
- 计算机安全 (1)
- Mina (2)
- Draw2d (4)
- Compass (1)
- 原创诗集 (3)
- 人生 (1)
- 翻版 (1)
- OSGI (1)
- Ubuntu (2)
- Ireport (2)
最新评论
-
扬手就是一长鞭:
移动label也无法使得save可以执行。
让连线上的Label动起来吧 -
扬手就是一长鞭:
我的save是正常的,我添加删除node或者connectio ...
让连线上的Label动起来吧 -
扬手就是一长鞭:
我也是这扥写的,可是我双击label改变他的文字时,发现sav ...
让连线上的Label动起来吧 -
ae6623:
这段代码放到哪里??
控制拖拽范围 -
ae6623:
真牛!鼠标滚轮缩放GEF画布 ..
getGraphicalV ...
GEF实现用鼠标滑轮控制画布的放大与缩小
模型部分:
标尺提供者:
向导操作命令:
最后在编辑器中配置RulerComposite(因为GEF是支持RulerComposite的,所以配置就可以了)
最后在configureGraphicalViewer方法中调用configureRuler即可
public class ElementBase extends AbstractModel implements IAdaptable { /** * */ private static final long serialVersionUID = 1L; /** * 布局 */ private Rectangle layout; /** * 获得布局 * * @return */ public Rectangle getLayout() { return layout; } public void setLayout(Rectangle layout) { this.layout = layout; } /** * 垂直向导、水平向导 */ private Guide verticalGuide, horizontalGuide; public Guide getVerticalGuide() { return verticalGuide; } /** * 设置导航参数 * * @param verticalGuide */ public void setVerticalGuide(Guide verticalGuide) { this.verticalGuide = verticalGuide; } public Guide getHorizontalGuide() { return horizontalGuide; } public void setHorizontalGuide(Guide horizontalGuide) { this.horizontalGuide = horizontalGuide; } public Object getAdapter(Class adapter) { return null; }
/** * 向导 * * @author Ming.He * */ public class Guide implements Serializable { /** * */ private static final long serialVersionUID = 1L; /** * 对于一个向导, 当附件部分被改变时,这个属性通常用来通知监听者 */ public static final String PROPERTY_CHILDREN = "subparts changed"; /** * * Property used to notify listeners when the guide is re-positioned */ public static final String PROPERTY_POSITION = "position changed"; protected PropertyChangeSupport listeners = new PropertyChangeSupport(this); private Map map; /** * 定位 */ private int position; /** * 是否水平 */ private boolean horizontal; /** * * Empty default constructor */ public Guide() { // empty constructor } /** * * Constructor * * * * @param isHorizontal * * <code>true</code> if the guide is horizontal (i.e., placed on * * a vertical ruler) */ public Guide(boolean isHorizontal) { setHorizontal(isHorizontal); } /** * * @see PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener) */ public void addPropertyChangeListener(PropertyChangeListener listener) { listeners.addPropertyChangeListener(listener); } /* * * @TODO:Pratik use PositionConstants here */ /** * * Attaches the given part along the given edge to this guide. The * * LogicSubpart is also updated to reflect this attachment. * * * * @param part * * The part that is to be attached to this guide; if the part is * * already attached, its alignment is updated * * @param alignment * * -1 is left or top; 0, center; 1, right or bottom */ public void attachElement(ElementBase element, int alignment) { if (getMap().containsKey(element) && getAlignment(element) == alignment) return; getMap().put(element, alignment); Guide parent = isHorizontal() ? element.getHorizontalGuide() : element .getVerticalGuide(); if (parent != null && parent != this) { parent.detachElement(element); } if (isHorizontal()) { element.setHorizontalGuide(this); } else { element.setVerticalGuide(this); } listeners.firePropertyChange(PROPERTY_CHILDREN, null, element); } /** * * Detaches the given part from this guide. The LogicSubpart is also updated * * to reflect this change. * * * * @param part * * the part that is to be detached from this guide */ public void detachElement(ElementBase element) { if (getMap().containsKey(element)) { getMap().remove(element); if (isHorizontal()) { element.setHorizontalGuide(null); } else { element.setVerticalGuide(null); } listeners.firePropertyChange(PROPERTY_CHILDREN, null, element); } } /** * * This methods returns the edge along which the given part is attached to * * this guide. This information is used by * * {@link org.eclipse.gef.examples.logicdesigner.edit.LogicXYLayoutEditPolicy * * LogicXYLayoutEditPolicy} to determine whether to attach or detach a part * * from a guide during resize operations. * * * * @param part * * The part whose alignment has to be found * * @return an int representing the edge along which the given part is * * attached to this guide; 1 is bottom or right; 0, center; -1, top * * or left; -2 if the part is not attached to this guide * * @see org.eclipse.gef.examples.logicdesigner.edit.LogicXYLayoutEditPolicy#createChangeConstraintCommand(ChangeBoundsRequest, * EditPart, Object) */ public int getAlignment(ElementBase element) { if (getMap().get(element) != null) return ((Integer) getMap().get(element)).intValue(); return -2; } /** * * @return The Map containing all the parts attached to this guide, and * * their alignments; the keys are LogicSubparts and values are * * Integers */ public Map getMap() { if (map == null) { map = new Hashtable(); } return map; } /** * * @return the set of all the parts attached to this guide; a set is used * * because a part can only be attached to a guide along one edge. */ public Set getParts() { return getMap().keySet(); } /** * * @return the position/location of the guide (in pixels) */ public int getPosition() { return position; } /** * * @return <code>true</code> if the guide is horizontal (i.e., placed on a * * vertical ruler) */ public boolean isHorizontal() { return horizontal; } /** * * @see PropertyChangeSupport#removePropertyChangeListener(java.beans.PropertyChangeListener) */ public void removePropertyChangeListener(PropertyChangeListener listener) { listeners.removePropertyChangeListener(listener); } /** * * Sets the orientation of the guide * * * * @param isHorizontal * * <code>true</code> if this guide is to be placed on a vertical * * ruler */ public void setHorizontal(boolean isHorizontal) { horizontal = isHorizontal; } /** * * Sets the location of the guide * * * * @param offset * * The location of the guide (in pixels) */ public void setPosition(int offset) { if (position != offset) { int oldValue = position; position = offset; listeners.firePropertyChange(PROPERTY_POSITION, new Integer( oldValue), new Integer(position)); } } }
/** * 标尺 * * @author Ming.He * */ public class Ruler implements Serializable { public static final String PROPERTY_CHILDREN = "children changed"; public static final String PROPERTY_UNIT = "units changed"; static final long serialVersionUID = 1; protected PropertyChangeSupport listeners = new PropertyChangeSupport(this); private int unit; private boolean horizontal; private List<Guide> guides = new ArrayList<Guide>(); public Ruler(boolean isHorizontal) { this(isHorizontal, RulerProvider.UNIT_PIXELS); } public Ruler(boolean isHorizontal, int unit) { horizontal = isHorizontal; setUnit(unit); } public void addGuide(Guide guide) { if (!guides.contains(guide)) { guide.setHorizontal(!isHorizontal()); guides.add(guide); listeners.firePropertyChange(PROPERTY_CHILDREN, null, guide); } } public void addPropertyChangeListener(PropertyChangeListener listener) { listeners.addPropertyChangeListener(listener); } // the returned list should not be modified public List<Guide> getGuides() { return guides; } public int getUnit() { return unit; } public boolean isHidden() { return false; } public boolean isHorizontal() { return horizontal; } public void removeGuide(Guide guide) { if (guides.remove(guide)) { listeners.firePropertyChange(PROPERTY_CHILDREN, null, guide); } } public void removePropertyChangeListener(PropertyChangeListener listener) { listeners.removePropertyChangeListener(listener); } public void setHidden(boolean isHidden) { } public void setUnit(int newUnit) { if (unit != newUnit) { int oldUnit = unit; unit = newUnit; listeners.firePropertyChange(PROPERTY_UNIT, oldUnit, newUnit); } } }
标尺提供者:
/** * 编辑器标尺提供者 * * @author Ming.He * */ public class EditorRulerProvider extends RulerProvider { /** 标尺 */ private Ruler ruler; /** 标尺监听 */ private PropertyChangeListener rulerListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals(Ruler.PROPERTY_CHILDREN)) { Guide guide = (Guide) evt.getNewValue(); if (getGuides().contains(guide)) { guide.addPropertyChangeListener(guideListener); } else { guide.removePropertyChangeListener(guideListener); } for (int i = 0; i < listeners.size(); i++) { ((RulerChangeListener) listeners.get(i)) .notifyGuideReparented(guide); } } else { for (int i = 0; i < listeners.size(); i++) { ((RulerChangeListener) listeners.get(i)) .notifyUnitsChanged(ruler.getUnit()); } } } }; private PropertyChangeListener guideListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals(Guide.PROPERTY_CHILDREN)) { for (int i = 0; i < listeners.size(); i++) { ((RulerChangeListener) listeners.get(i)) .notifyPartAttachmentChanged(evt.getNewValue(), evt .getSource()); } } else { for (int i = 0; i < listeners.size(); i++) { ((RulerChangeListener) listeners.get(i)) .notifyGuideMoved(evt.getSource()); } } } }; public EditorRulerProvider(Ruler ruler) { this.ruler = ruler; this.ruler.addPropertyChangeListener(rulerListener); List guides = getGuides(); for (int i = 0; i < guides.size(); i++) { ((Guide) guides.get(i)) .addPropertyChangeListener(guideListener); } } public List getAttachedModelObjects(Object guide) { return new ArrayList(((Guide) guide).getParts()); } public Command getCreateGuideCommand(int position) { return new CreateGuideCommand(ruler, position); } public Command getDeleteGuideCommand(Object guide) { return new DeleteGuideCommand((Guide) guide, ruler); } public Command getMoveGuideCommand(Object guide, int pDelta) { return new MoveGuideCommand((Guide) guide, pDelta); } public int[] getGuidePositions() { List guides = getGuides(); int[] result = new int[guides.size()]; for (int i = 0; i < guides.size(); i++) { result[i] = ((Guide) guides.get(i)).getPosition(); } return result; } public Object getRuler() { return ruler; } public int getUnit() { return ruler.getUnit(); } public void setUnit(int newUnit) { ruler.setUnit(newUnit); } public int getGuidePosition(Object guide) { return ((Guide) guide).getPosition(); } public List getGuides() { return ruler.getGuides(); } }
向导操作命令:
/** * 创建向导命令 * * @author Ming.He * */ public class CreateGuideCommand extends Command { /** 向导 */ private Guide guide; /** 标尺 */ private Ruler parent; /** 位置 */ private int position; public CreateGuideCommand(Ruler parent, int position) { super("Create guide"); this.parent = parent; this.position = position; } public boolean canUndo() { return true; } public void execute() { if (guide == null) guide = new Guide(!parent.isHorizontal()); guide.setPosition(position); parent.addGuide(guide); } public void undo() { parent.removeGuide(guide); } }
/** * 删除向导命令 * @author Ming.He * */ public class DeleteGuideCommand extends Command { /** * 标尺 */ private Ruler parent; /** * 向导 */ private Guide guide; /** * 已创建的控制器 */ private Map oldParts; public DeleteGuideCommand(Guide guide, Ruler parent) { super("Delete guide"); this.guide = guide; this.parent = parent; } public boolean canUndo() { return true; } public void execute() { oldParts = new HashMap(guide.getMap()); Iterator iter = oldParts.keySet().iterator(); while (iter.hasNext()) { guide.detachElement((ElementBase) iter.next()); } parent.removeGuide(guide); } public void undo() { parent.addGuide(guide); Iterator iter = oldParts.keySet().iterator(); while (iter.hasNext()) { ElementBase element = (ElementBase) iter.next(); guide.attachElement(element, ((Integer) oldParts.get(element)).intValue()); } } }
/** * 移动向导命令 * @author Ming.He * */ public class MoveGuideCommand extends Command { /**三角定位*/ private int pDelta; /**向导*/ private Guide guide; public MoveGuideCommand(Guide guide, int positionDelta) { super("Move guide"); this.guide = guide; pDelta = positionDelta; } public void execute() { guide.setPosition(guide.getPosition() + pDelta); Iterator iter = guide.getParts().iterator(); while (iter.hasNext()) { ElementBase element = (ElementBase) iter.next(); Rectangle layout = element.getLayout().getCopy(); if (guide.isHorizontal()) { layout.y += pDelta; } else { layout.x += pDelta; } element.setLayout(layout); } } public void undo() { guide.setPosition(guide.getPosition() - pDelta); Iterator iter = guide.getParts().iterator(); while (iter.hasNext()) { ElementBase element = (ElementBase) iter.next(); Rectangle layout = element.getLayout().getCopy(); if (guide.isHorizontal()) { layout.y -= pDelta; } else { layout.x -= pDelta; } element.setLayout(layout); } } }
最后在编辑器中配置RulerComposite(因为GEF是支持RulerComposite的,所以配置就可以了)
/** 标尺容器 */ private RulerComposite rulerComp;// Override protected void createGraphicalViewer(Composite parent) { rulerComp = new RulerComposite(parent, SWT.NONE); super.createGraphicalViewer(rulerComp); rulerComp.setGraphicalViewer((ScrollingGraphicalViewer) getGraphicalViewer()); }
/** * 配置标尺 */ private void configureRuler() { GraphicalViewer viewer = getGraphicalViewer(); viewer.setProperty(RulerProvider.PROPERTY_VERTICAL_RULER, new EditorRulerProvider(new Ruler(false))); viewer.setProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER, new EditorRulerProvider(new Ruler(true))); viewer.setProperty(RulerProvider.PROPERTY_RULER_VISIBILITY, true); IAction action = new ToggleRulerVisibilityAction(getGraphicalViewer()); getActionRegistry().registerAction(action); }
最后在configureGraphicalViewer方法中调用configureRuler即可
发表评论
-
缺省将Palette展开
2011-07-29 17:37 1470/** 弹出调色板使用状态的首选项标识 */ priv ... -
Bendpoint随着图元位置的变化而变化
2011-04-15 11:33 1652我这里以gef.tutorial.step为例,在此工程基础修 ... -
图元间多条连线处理方式
2011-04-10 01:10 1298DiagramEditPart implements Laye ... -
给Figure添加滚动条
2011-04-10 00:53 1909Draw2d中有ScrollPane这样一个IFigure,它 ... -
去掉子节点句柄
2011-04-09 19:40 1285虽然可以通过给子节点添加SelectionPolicy来完成对 ... -
给DiagramEditPart添加Request
2011-01-14 00:16 1091实现ScalableFreeformRootEditPart中 ... -
缺省将FlyoutPalette放在左边
2010-12-30 22:49 1100重写FlyoutPaletteComposite.Flyout ... -
连线上加文字
2010-12-30 13:50 1557前面写了个连线上显示文字,直接用的label,那样确实简单,但 ... -
根据模型得到对应的控制器
2010-12-30 10:49 885(EditPart) getGraphicalViewer() ... -
创建连线后点击空白区域箭头恢复成默认样式
2010-12-29 21:39 1636关于连线创建的过程大家可以看http://blog.china ... -
GEF实现用鼠标滑轮控制画布的放大与缩小
2010-10-28 13:22 1911很简单哇,GEF已经实现了,一行代码我就不多说了,在confi ... -
实现GEF中editor的背景为网格
2010-05-13 17:32 1206在editor中的initializeGraphicalVie ... -
横向排列算法
2010-03-15 20:17 1165List<NetunitModel> childr ... -
星形排列算法
2010-03-15 20:15 1342List<NetunitModel> childr ... -
外部执行Command而Editor不提示已修改的解决办法
2009-12-21 16:19 1243理论:有些时候的需求往往不是通过plette来创建模型和连线以 ... -
选择或取消选择当前的EditPart,改变连线视图的连线样式
2009-12-21 14:45 1272在LineConnectionEditPart类中实现Abst ... -
自定义Decoration
2009-12-21 14:36 1377大家都知道new PolygonDecoration就表示带箭 ... -
让连线上的Label动起来吧
2009-12-19 12:24 1563大家都知道GEF中连线上的label默认是在线的中间,一旦要连 ... -
设置连线样式
2009-12-16 12:26 1624private void setConnectionShiap ... -
public忽悠了不少人啊
2009-12-09 16:29 1300当有人想继承org.eclipse.draw2d.graph中 ...
相关推荐
gef 绘图折线的实现方法。 gef API chm 格式
在GEF中property view 页面的实现!介绍了其实现的步骤方法!还结合了实例进行讲解!
实现gef模型连线间锚点的定位实现鼠标位置定位,就是鼠标在哪里,他的锚点就会在哪里!
基于GEF框架的SVG制作工具设计与实现
GEF入门必读 GEF入门系列 GEF-whole-upload 感谢八进制
我下的资源的打包,希望有帮助,包括:GEF_Tutorial,GEF实例,入门教程,GEF-whole-upload
GEF: Graphical Editing Framework <br>GEF是一套MVC Framework,它能帮你比较容易的建立图形化的编辑器,V(View)的部分常常是基于SWT的Draw2D,因此Draw2D也看作是GEF的一部分。依赖:org.eclipse.gef***, org...
目前的最新的GEF,用于eclipse是实现可视化。
gef开发实例 gef开发的好例子,比较简单的实现了MVC的架构
NULL 博文链接:https://wenzibenben.iteye.com/blog/1311056
GEF简易教程-学习GEF的入门教程,不错的gef入门教程
GEF-ALL-3.7 GEF-ALL-3.8 官方包。 GEF Draw2d 学习资料
GEF-II电场仪使用手册
GEF eclipse 插件
一本很好的GEF入门教程,通过实例详细的描述了GEF开发的全流程。
NULL 博文链接:https://yutianapple.iteye.com/blog/655732
这是我参考了一些其他资料,自己写的一个GEF示例程序。 在这个demo中你可以看到以下的功能: 1. 往画布上添加多种节点 2. 节点之间的连线 3. 节点内容的编辑功能 4. 删除连线 5. 删除节点 6. 对节点的拖动以改变...
Agenda Start things off What is GEF? GEF Demo Draw2d Overview Example GEF Overview Break Hands-on Activity: Shapes Example
与 其他一些MVC编辑框架相比,GEF的一个主要设计目标是尽量减少模型和视图之间的依赖,好处是可以根据需要选择任意模型和视图的组合,而不必受开发框架 的局限(不过实际上还是很少有脱离Draw2D的实现)。