GMF:如何让网格显示在background,而不是foreground

本文提供了一种在GMF中优化网格显示的方法,通过调整Layer的层级,避免网格覆盖图形,提升视觉效果。

前言

很久没写文章了,准备写一系列关于Eclipse RCP /Plugin的文章。 这些文章都是trouble shooting性质的,不准备写的很细,当你碰到这样的问题,google到时,能帮你把问题解决了,这就ok了。另外有些问题我也是不求甚解的,哈。

正文

GMF中,Grid,也就是用来对齐的网格,默认是显示在foreground的,这样网格就会覆盖在你的图形上面,看上去很糟糕。解决办法是在Editor中configureGraphicalViewer()方法添加如下代码

protected void configureGraphicalViewer() {
	super.configureGraphicalViewer();
	DiagramEditorContextMenuProvider provider = new DiagramEditorContextMenuProvider(this, getDiagramGraphicalViewer());
	getDiagramGraphicalViewer().setContextMenu(provider);
	getSite().registerContextMenu(ActionIds.DIAGRAM_EDITOR_CONTEXT_MENU, provider, getDiagramGraphicalViewer());
	
	//ADDED START
	DiagramRootEditPart root = (DiagramRootEditPart) getDiagramGraphicalViewer().getRootEditPart();
	Layer printableLayers = (Layer)root.getLayer(LayerConstants.PRINTABLE_LAYERS);
	Layer gridLayer = (Layer)root.getLayer(LayerConstants.GRID_LAYER);
	if (printableLayers != null && gridLayer != null){
		LayeredPane paneForPrintable = (LayeredPane)printableLayers.getParent();
		LayeredPane paneForGrid = (LayeredPane)gridLayer.getParent();
		if (paneForGrid == paneForPrintable) {
			paneForGrid.removeLayer(LayerConstants.GRID_LAYER);
			paneForGrid.addLayerBefore(gridLayer, LayerConstants.GRID_LAYER, LayerConstants.PRINTABLE_LAYERS);
		}
	}
	//ADDED END
}

 

解决方案来自http://www.eclipse.org/forums/index.php/t/296417/

转载于:https://www.cnblogs.com/Binhua-Liu/p/3266784.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值