GEF的RootEditPart对应的Figure是一个由多个Layer组成的LayeredPane,每个Layer负责包含不同类型的图形元素,如节点、连接、网格线等等。所以要让图形编辑器显示一个图片作为背景,可以在它们其中一个层里绘制这个图片,也可以添加一个层专门放置背景图片。在gef中所有的图形元件继承自Figure类。实现背景色和背景图的更改的必须实现Figure中部分类。
由源代码:
/**用于绘制元件和元件内的子元件系列
* Paints this Figure and its children.
* @param graphics The Graphics object used for painting
* @see #paintFigure(Graphics)
* @see #paintClientArea(Graphics)
* @see #paintBorder(Graphics)
*/
publicvoid paint(Graphics graphics) {
if (getLocalBackgroundColor() != null)
graphics.setBackgroundColor(getLocalBackgroundColor());
if (getLocalForegroundColor() != null)
graphics.setForegroundColor(getLocalForegroundColor());
if (font != null)
graphics.setFont(font);
graphics.pushState();
try {
paintFigure(graphics);
graphics.restoreState();
paintClientArea(graphics);
paintBorder(graphics);
} finally {
graphics.popState();
}
}
/**用于绘制边框border对象
* Paints the border associated with this Figure, if one exists.
* @param graphics The Graphics used to paint
* @see Border#paint(IFigure, Graphics, Insets)
* @since 2.0
*/
protectedvoid paintBorder(Graphics graphics) {
if (getBorder() != null)
getBorder().paint(this, graphics, NO_INSETS);
}
/**用于绘制所有子元件对象
* Paints this Figure's children. The caller must save the state of the graphics prior to
* calling this method, such that <code>graphics.restoreState()</code> may be called
* safely, and doing so will return the graphics to its original state when the method was
* entered.
* <P>
* This method must leave the Graphics in its original state upon return.
* @param graphics the graphics used to paint
* @since 2.0
*/
protectedvoid paintChildren(Graphics graphics) {
IFigure child;
Rectangle clip = Rectangle.SINGLETON;
for (int i = 0; i < children.size(); i++) {
child = (IFigure)children.get(i);
if (child.isVisible() && child.intersects(graphics.getClip(clip))) {
graphics.clipRect(child.getBounds());
child.paint(graphics);
graphics.restoreState();
}
}
}
/**绘制子元件区域对象
* Paints this Figure's client area. The client area is typically defined as the anything
* inside the Figure's {@link Border} or {@link Insets}, and by default includes the
* children of this Figure. On return, this method must leave the given Graphics in its
* initial state.
* @param graphics The Graphics used to paint
* @since 2.0
*/
protectedvoid paintClientArea(Graphics graphics) {
if (children.isEmpty())
return;
boolean optimizeClip = getBorder() == null || getBorder().isOpaque();
if (useLocalCoordinates()) {
graphics.translate(
getBounds().x + getInsets().left,
getBounds().y + getInsets().top);
if (!optimizeClip)
graphics.clipRect(getClientArea(PRIVATE_RECT));
graphics.pushState();
paintChildren(graphics);
graphics.popState();
graphics.restoreState();
} else {
if (optimizeClip)
paintChildren(graphics);
else {
graphics.clipRect(getClientArea(PRIVATE_RECT));
graphics.pushState();
paintChildren(graphics);
graphics.popState();
graphics.restoreState();
}
}
}
/** 绘制元件的背景等信息
* Paints this Figure's primary representation, or background. Changes made to the
* graphics to the graphics current state will not affect the subsequent calls to {@link
* #paintClientArea(Graphics)} and {@link #paintBorder(Graphics)}. Furthermore, it is safe
* to call <code>graphics.restoreState()</code> within this method, and doing so will
* restore the graphics to its original state upon entry.
* @param graphics The Graphics used to paint
* @since 2.0
*/
protectedvoid paintFigure(Graphics graphics) {
if (isOpaque())
graphics.fillRectangle(getBounds());
if (getBorder() instanceof AbstractBackground)
((AbstractBackground) getBorder()).paintBackground(this, graphics, NO_INSETS);
}
由上面的源代码可以看出:
/**
* 用来定制GraphicalViewer的各种信息
* 在这两个方法里我们配置了RootEditPart、用于创建 EditPart的EditPartFactory、
* Contents即Diagram对象和增加了拖放支持,拖动目标是当前 EditPartViewer,后面会看到拖动源就是调色板。
*/
/**
* 用来定制GraphicalViewer的各种信息
* 在这两个方法里我们配置了RootEditPart、用于创建 EditPart的EditPartFactory、
* Contents即Diagram对象和增加了拖放支持,拖动目标是当前 EditPartViewer,后面会看到拖动源就是调色板。
*/
@Override
protectedvoid configureGraphicalViewer() {
super.configureGraphicalViewer();
//添加背景图片
this.getGraphicalViewer().setRootEditPart(new ScalableFreeformRootEditPart(){
//可以注入自己设定的层
@Override
protected LayeredPane createPrintableLayers(){
LayeredPane layeredPane= super.createPrintableLayers();
layeredPane.add(new FreeformLayer(),PRIMARY_LAYER);
//可以添加自定一的层layer接口定义
layeredPane.add(new FreeformLayer(),CONNECTION_LAYER);
return layeredPane;
}
//添加背景色和背景图
@Override
protectedvoid createLayers(LayeredPane layeredPane) {
Layer layer=new FreeformLayer(){
protected
相关推荐
#### 一、GEF简介及背景 - **定义与功能**:GEF(Graphical Editor Framework)是Eclipse Tools Project中的一个重要组成部分,它提供了一个强大的框架来支持开发者创建复杂的图形用户界面(GUI)。GEF主要用于开发...
- GEF(Graphical Editing Framework)是一个用于构建图形编辑器的框架,主要用于创建UML图、流程图等复杂图形界面。GEF提供了一整套工具,帮助开发者高效地创建和编辑图形对象。 #### 二、SWT编程基础 **3.1 ...
街道级行政区划shp矢量数据,wgs84坐标系,下载直接使用
街道级行政区划shp数据,wgs84坐标系,直接下载使用。
街道级行政区划shp矢量数据,wgs84坐标系,下载直接使用
轻量级密码算法LBlock的FPGA优化实现.docx
街道级行政区划shp矢量数据,wgs84坐标系,下载直接使用
Git 资料 progit-zh-v2.1.1.pdf
街道级行政区划shp数据,wgs84坐标系,直接下载使用。
篮球计分器FPGA附程序..doc
街道级行政区划shp数据,wgs84坐标系,直接下载使用。
内容概要:本文档全面介绍了Linux开发的基础知识、应用场景、环境搭建、常用命令、Shell脚本编程以及C/C++和Python开发等内容。首先阐述了Linux开发的重要性及其在服务器端开发、嵌入式开发和系统运维等领域的广泛应用。接着详细讲解了如何选择合适的Linux发行版并安装系统,配置开发环境,包括安装必要的开发工具和配置SSH服务。文档还深入讲解了Linux基础命令,如文件和目录操作、文件内容查看与编辑、进程管理和权限管理。此外,介绍了Shell脚本编程的基本语法,包括变量、条件语句、循环语句和函数定义。针对C/C++和Python开发,文档分别讲解了编译器安装、程序编写与编译、调试方法及使用虚拟环境等内容。最后,简要介绍了Linux内核开发的相关知识,包括下载编译内核、内核模块开发等,并推荐了相关学习资源。 适合人群:对Linux开发感兴趣的初学者及有一定经验的研发人员,尤其是希望深入掌握Linux开发技能的开发者。 使用场景及目标:①掌握Linux开发环境的搭建与配置;②熟悉Linux基础命令和Shell脚本编程;③学习C/C++和Python在Linux下的开发流程;④了解Linux内核开发的基本概念和技术。 阅读建议:此文档内容丰富,涵盖面广,建议读者根据自身需求选择性阅读,并结合实际操作进行练习。特别是对于初学者,应先掌握基础命令和开发环境的搭建,再逐步深入到编程语言和内核开发的学习。
街道级行政区划shp数据,wgs84坐标系,直接下载使用。
街道级行政区划shp数据,wgs84坐标系,直接下载使用。
街道级行政区划shp数据,wgs84坐标系,直接使用。
内容概要:本文档《word练习题.docx》是一份详细的Word操作练习指南,涵盖了从基础到高级的各种功能。文档分为三个主要部分:内容编辑、页面布局和高效文档。内容编辑部分包括文本格式化、段落设置、项目编号、制表位、边框与底纹等练习;页面布局部分涉及分节符、分栏、页眉页脚、水印等设置;高效文档部分则聚焦于样式管理、导航窗格、题注、书签、超级链接、脚注与尾注、交叉引用等功能。每个练习都有具体的操作步骤,帮助用户掌握Word的各种实用技巧。 适合人群:适用于Word初学者及希望提高Word技能的中级用户,尤其是需要频繁使用Word进行文档编辑和排版的办公人员。 使用场景及目标:①帮助用户熟悉Word的基本操作,如文本编辑、格式设置等;②提升用户的文档排版能力,学会设置复杂的页面布局;③提高工作效率,掌握高效文档管理技巧,如样式应用、题注和交叉引用等。 其他说明:此文档不仅提供了具体的练习题目,还附带了详细的步骤说明,用户可以根据指引逐步完成每个练习。此外,文档中的一些练习涉及到智能文档和Office智能客户端的应用,有助于用户了解Word在企业级应用中的潜力。建议用户按照章节顺序逐步学习,实践每一个练习,以达到最佳的学习效果。
街道级行政区划shp数据,wgs84坐标系,直接下载使用。
全球腐败感知数据(2000-2023)——3000行 33个指标 关于数据集 该数据集包含3000行和33列,涵盖了2000年至2023年的腐败感知指数(CPI)数据和各种治理指标。它包括国家排名、分数和其他指标,如公共部门腐败、司法腐败、贿赂指数、商业道德、民主指数、法治、政府效率、经济指标和人类发展指数。 这些数据可用于: 腐败趋势分析 腐败对GDP、人类发展指数和治理的影响 跨国比较 数据可视化和机器学习模型 该数据集对研究人员、数据分析师、政策制定者和对研究全球腐败趋势非常有用。
毕业设计(论文) 基于FPGA的数字频率计设计.doc
街道级行政区划shp数据,wgs84坐标系,直接使用。