RCP:给GEF编辑器添加网格和标尺。

网格和标尺效果如上图所示。
添加网格比较简单,也可以自己实现,主要思路是为编辑器添加一个GridLayer。但是还是建议参考eclipse自己的GEF样例来实现。
需要注意两个部分:
1、重写org.eclipse.gef.ui.parts.GraphicalEditor.configureGraphicalViewer(),加入以下部分
getGraphicalViewer().setProperty(
SnapToGrid.PROPERTY_GRID_ENABLED,
true);
// We keep grid visibility and enablement in sync
getGraphicalViewer().setProperty(
SnapToGrid.PROPERTY_GRID_VISIBLE,
true);
2、重写节点的EditPart的getAdapter方法
if (key == SnapToHelper.class) {
List snapStrategies = new ArrayList();
Boolean val = (Boolean) getViewer().getProperty(
RulerProvider.PROPERTY_RULER_VISIBILITY);
if (val != null && val.booleanValue())
snapStrategies.add(new SnapToGuides(this));
val = (Boolean) getViewer().getProperty(
SnapToGrid.PROPERTY_GRID_ENABLED);
if (val != null && val.booleanValue())
snapStrategies.add(new SnapToGrid(this));
int size = snapStrategies.size();
if (size == 0)
return null;
SnapToHelper delegates[] = new SnapToHelper[size];
for (int i = 0; i < size; i++)
delegates[i] = (SnapToHelper) snapStrategies.get(i);
return new CompoundSnapToHelper(delegates);
}
以上即可完成添加网格。
如果要添加标尺呢?GEF提供了RulerComposite,可以方便的完成这个操作。
我们可以注意到,早前的那张图里,标尺是占据着整个编辑器的外层的,于是我们可以想到,只要替换编辑器的Parent Compostie为RulerComposite即可完成。
所以,同样是重写createGraphicalViewer方法,加入一下代码:
rulerComp = new RulerComposite(parent, SWT.NONE);
super.createGraphicalViewer(rulerComp);
rulerComp
.setGraphicalViewer((ScrollingGraphicalViewer) getGraphicalViewer());
但是,这样还不能算是结束,还需要重写getGraphicalControl方法
protected Control getGraphicalControl() {
// return getGraphicalViewer().getControl();
return rulerComp;
}
//事实上,这一步并不是必要的,如果你把rulerComposite作为GraphicalViewer的Control,那么,这一步就是多余的。
完成了以上,就完成了网格和标尺的添加。
当然,你可能会注意到你的网格和图中的田字型网格并不一致,这是因为我重写了RootEditPart并且提供了自己的GridLayer。
RCP:给GEF编辑器添加网格和标尺。的更多相关文章
- RCP:给GEF编辑器添加拖拽辅助线
当图形边缘碰触时,会产生一条帮助拖拽的辅助线 这里需要三个类: 1.SnapToGeomotry 2.SnapToGuide(非必须) 3.SnapFeedbackPolicy
- GEF入门实例_总结_06_为编辑器添加内容
一.前言 本文承接上一节:GEF入门实例_总结_05_显示一个空白编辑器 在上一节我们为我们的插件添加了一个空白的编辑器,这一节我们将为此编辑器添加内容. 二.GEF的MVC模式 在此只简单总结一下, ...
- MyEclipse的html/JSP编辑器添加代码自动提示
http://lusterfly.iteye.com/blog/1872627 在myeclipse 9以前的版本中,我们如果要为html编辑器添加自动的代码提示可以这样操作: windows--&g ...
- Add an Editor to a Detail View 将编辑器添加到详细信息视图
In this lesson, you will learn how to add an editor to a Detail View. For this purpose, the Departme ...
- RCP:gef智能寻路算法(A star)
本路由继承自AbstactRouter,参数只有EditPart(编辑器内容控制器),gridLength(寻路用单元格大小),style(FLOYD,FLOYD_FLAT,FOUR_DIR). 字符 ...
- C++、GDAL创建shapefile,并向矢量文件中添加网格
//总体来说这个过程就是构建数据源->构建层->构建要素->构建形状->关闭数据源. //要包含的GDAL头文件 #include <gdal_priv.h> #i ...
- 启用div作为编辑器 添加contentEditalbe属性
1.自从HTML5中新引入了contentEditalbe属性以后,div就与textarea一样,可以作为最常用的编辑器使用. 1.启用div作为编辑器 让div进入编辑状态很简单,只需要: 复制代 ...
- FCKEditor编辑器添加中文字体的方法
默认情况下,FCKEditor在进行文本编辑时,无法使用中文字体.让其添加中文字体的方法: 1.打开 fckconfig.js 文件,找到第154行(大概),会发现: 程序代码: FCKConfig. ...
- phpcms编辑器添加一键排版控件
CKEditor添加一键排版插件实例,大家都知道phpcms也是ckeditor编辑器,那么如果增加这个一键排版这个牛逼功能呢增加好了后,效果图是这样的 废话不多说,直接说步骤第一步:config.j ...
随机推荐
- ebtables hook
1 概述 netfliter框架不仅仅在ipv4中有应用,bridge,ipv4,ipv6,decnet 这四种协议中都有应用,其中ipv4中又分开了arp和ip的两种 其实netfliter是个大的 ...
- nginx+tomcat负载均衡
最近练习nginx+tomcat负载均衡.根据一些资料整理了大体思路,最终实现了1个nginx+2个tomcat负载均衡. 安装JDK 1>进入安装目录,给所有用户添加可执行的权限 #chmod ...
- Flask备注三(Context)
Flask备注三(Context) Flask支持不同的应用场景下,对应不同的local context(本地上下文环境),用来提供当前环境下的资源.lcoal context和全局变量以及局部变量最 ...
- spring mvc(1):基础入门
依赖 pom.xml ( maven ) <properties> <spring.version>3.0.5.RELEASE</spring.version> ...
- springMVC 相对于 Structs 的优势
智者说,没有经过自己的思考和估量,就不能接受别人的东西.资料只能是一个参考,至于是否正确,还得自己去分辨 SpringMVC相对于Structs的几个优势: 1.springMVC安全性更高,stru ...
- 第三次作业——《K米评测》
第三次作业--<K米评测> 一.调研.评测 上手体验 APP的图标做的不错,一眼就知道和KTV唱歌相关的 点进去就是连接包箱的界面和直播界面,把软件最重要的两个功能展示出来了,一目了然 热 ...
- cassandra指定数据库路径
参考 https://docs.datastax.com/en/cassandra/2.1/cassandra/configuration/configCassandra_yaml_r.html 我们 ...
- css3中的字体样式
text-overform:ellipsis省略号/clip裁剪. overform:hidden溢出隐藏文字. 但是text-overflow只是用来说明文字溢出时用什么方式显示,要实现溢出时产生省 ...
- python核心编程笔记
1.python的对象是通过引用传递的. 2.多元赋值: x, y = y, x
- Android中的桌面快捷方式
一.判断是否已有快捷方式 private String getAuthorityFromPermission(Context context, String permission){ if (perm ...