GEF问题与解决方案收集
来源:互联网 发布:草图大师 mac 编辑:程序博客网 时间:2024/06/17 23:42
1、GMF Label warp换行设置方法
在实例化WrappingLabel 时加入如下代码,此代码作用就是在图元初始化时被设置为可换行的Label:
public void setLabel(WrappingLabel figure) { figure.setTextWrap(true); figure.setAlignment(PositionConstants.CENTER); figure.setTextJustification(PositionConstants.CENTER); super.setLabel(figure); } protected DirectEditManager getManager() { if (manager == null) { /* Create custom text director which use wrap label editor */ setManager(new CustomTextDirectEditManager(this, CustomTextDirectEditManager.getTextCellEditorClass(this), AppreciationEditPartFactory.getTextCellEditorLocator(this))); } return manager;}protected void setManager(DirectEditManager manager) { this.manager = manager;}/*** @generated*/protected void performDirectEdit(Point eventLocation) { DirectEditManager mgr = getManager(); if (mgr instanceof TextDirectEditManager) { ((CustomTextDirectEditManager) getManager()).show(eventLocation .getSWTPoint()); } else { super.performDirectEdit(eventLocation); }}
注意:CustomTextDirectEditManager主要是用来定义CellEditor为WrapTextCellEditor,它是继承TextDirectEditManager。在实例化Editpart初始化Figure时,不能设置this.setMaximumSize这个方法,此方法主要是用来设置形状的最大尺寸,不然会导致不能换行。
2、连接线自动识别折线规则
首先连接线是PolylineConnectionEx类型,然后在DiagramConnectionsPreferencePage类中加入如下代码:
public static void initDefaults(IPreferenceStore preferenceStore) {preferenceStore.setDefault(IPreferenceConstants.PREF_LINE_STYLE,Routing.RECTILINEAR);}
3、在Figure中添加子Figure图形
在Editpart类中找到Figure类,然后覆写 paintChildren方法,这里是在图形里增加了两条垂直线,例子代码如下:
public void paintChildren(Graphics graphics) {graphics.drawLine(this.getBounds().getLocation().x + 10, this.getBounds().getLocation().y, this.getBounds().getLocation().x + 10, this.getBounds().getLocation().y+ this.getBounds().height);graphics.drawLine(this.getBounds().getLocation().x + this.getBounds().width- 10, this.getBounds().getLocation().y, this.getBounds().getLocation().x+ this.getBounds().width - 10, this.getBounds().getLocation().y + this.getBounds().height);
super.paintChildren(graphics);}
4、Figure中图形颜色渐变
渐变,意思就是颜色的数字会从一个RGB色值到另一个RGB色值的逐渐变化,这个是我自己的理解,代码如下:
protected void fillShape(Graphics graphics) {graphics.setBackgroundColor((new Color(null, 45, 112, 170)));graphics.setForegroundColor((new Color(null, 62, 132, 190)));graphics.fillGradient(getBounds(), true);super.fillShape(graphics);}
5、RectangleFigure设置透明不起作用
当你创建RectangleFigure时,如果需要设置透明度,通过直接this.setOpaque(false);这个方法是不起作用的,然而需要通过覆写paintFigure这个方法,方法中填写如下代码:
public void paintFigure(Graphics graphics) {if (!isOpaque()) {graphics.setAlpha(100);// 设置透明度this.setOpaque(false);}}
6、设置图形编辑器界面背景图片
增加一个层代码,如下:
import org.eclipse.draw2d.ColorConstants;import org.eclipse.draw2d.FreeformLayer;import org.eclipse.draw2d.Graphics;import org.eclipse.draw2d.geometry.Point;import org.eclipse.jface.resource.ImageDescriptor;import org.eclipse.swt.graphics.Image;public class BackGroundLayer extends FreeformLayer{public static final String BACK_GROUND_LAYER = "Back ground Layer"; private static final ImageDescriptor descriptor = null; private Image originalImage = descriptor.createImage(); public BackGroundLayer() { setOpaque(true); } @Override protected void paintFigure(Graphics graphics) { if (isOpaque()) { graphics.setForegroundColor(ColorConstants.white); graphics.setBackgroundColor(ColorConstants.white); graphics.fillGradient(getBounds(), true); graphics.setAlpha(100);// 设置透明度,背景还是颜色浅一点比较好 graphics.drawImage(originalImage, new Point(0, 0)); } }}
然后在*DiagramEditor图形编辑器代码方法configureGraphicalViewer中加入如下代码:
//设置背景图片DiagramRootEditPart root = (DiagramRootEditPart) getDiagramGraphicalViewer().getRootEditPart();LayeredPane printableLayers = (LayeredPane) root.getLayer(LayerConstants.PRINTABLE_LAYERS);BackGroundLayer backgroundLayer = new BackGroundLayer();printableLayers.addLayerBefore(backgroundLayer,BackGroundLayer.BACK_GROUND_LAYER, LayerConstants.PRIMARY_LAYER);
7、连接线颜色修改不起作用
问题主要是缺少了以下代码:
Edge edge = NotationFactory.eINSTANCE.createEdge();edge.getStyles().add(NotationFactory.eINSTANCE.createRoutingStyle());
8、让连接线自动弯曲与自动折线
自动弯曲代码如下:
Routing routing = Routing.get(Routing.RECTILINEAR_LITERAL.getName());if (routing != null) { ViewUtil.setStructuralFeatureValue(edge, NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing); ViewUtil.setStructuralFeatureValue(edge, NotationPackage.eINSTANCE.getRoundedCornersStyle_RoundedBendpointsRadius(), 10); ViewUtil.setStructuralFeatureValue(edge, NotationPackage.eINSTANCE.getRoutingStyle_ClosestDistance(), false); ViewUtil.setStructuralFeatureValue(edge, NotationPackage.eINSTANCE.getRoutingStyle_AvoidObstructions(), false); }
自动折线:
public static void initDefaults(IPreferenceStore preferenceStore) {preferenceStore.setDefault(IPreferenceConstants.PREF_LINE_STYLE,Routing.RECTILINEAR);}
9、图元的默认底色修改方法
通过*ViewProvider类,修改其中的一下代码就可以了,fillRGB就是默认的颜色:
org.eclipse.swt.graphics.RGB fillRGB = PreferenceConverter.getColor(prefStore, IPreferenceConstants.PREF_FILL_COLOR);ViewUtil.setStructuralFeatureValue(node,NotationPackage.eINSTANCE.getFillStyle_FillColor(),FigureUtilities.RGBToInteger(fillRGB));
- GEF问题与解决方案收集
- GEF-whole-upload教程中遇到的问题及解决方案
- rsync 错误与解决方案收集
- Gef与MVC体系结构
- 收集来的出错问题的解决方案!
- Oracle常见错误问题收集和解决方案
- gef
- GEF的弹出式菜单闪烁的问题
- GEF-自定义Request、Command与Action
- EBS R12设置 问题及Matelink解决方案收集
- MVC4 网站发布(整理+部分问题收集和解决方案)
- Android Studio开发工具异常与解决方案收集
- 上周问题总结与解决方案
- 产品与解决方案的问题。
- SampleGrabber开发问题与解决方案
- 项目中的问题与解决方案
- SampleGrabber开发问题与解决方案
- 哲学家就餐问题与解决方案
- 父类引用指向子类对象
- 图像处理常用概念
- Spring事务管理—aop:pointcut 属性expression格式说明
- Opencv2系列学习笔记2_2(图像的其它操作)
- Reed-Solomon Codes
- GEF问题与解决方案收集
- 猜数系统
- 周赛问题 福州 B - Somali Pirates
- Ubuntu打开终端的方法四种
- jquery取checkbox的状态
- UITextField 详解-- IOS (解决键盘遮住view及密文設定的问题实例)
- ant构建testNG测试输出测试报告
- R学习总结
- xdg-user-dirs