要为GMF应用程序的画布设置背景图片,可以覆盖XXXDiagramEditor的configureGraphicalViewer()方法,加入如下代码即可。不过加入背景图片后,网格线无法显示,有可能是图层顺序的问题。
/**
* @generated NOT
*/
protected void configureGraphicalViewer() {
super.configureGraphicalViewer();
//////Background Layer//////////////////
Layer backgroundLayer = new Layer() {
@Override
protected void paintFigure(Graphics graphics) {
super.paintFigure(graphics);
graphics.drawImage(NetworkDiagramEditorPlugin.getInstance().getBundledImage("images/worldmap_no_text.gif"), 0,
0);
}
};
backgroundLayer.setSize(4990, 2484);
////////////////////////////////////////
DiagramRootEditPart root = (DiagramRootEditPart) getDiagramGraphicalViewer().getRootEditPart();
LayeredPane printableLayers = (LayeredPane) root.getLayer(LayerConstants.PRINTABLE_LAYERS);
FreeformLayer extLabelsLayer = new FreeformLayer();
extLabelsLayer.setLayoutManager(new DelegatingLayout());
printableLayers.addLayerAfter(extLabelsLayer, NetworkEditPartFactory.EXTERNAL_NODE_LABELS_LAYER,
LayerConstants.PRIMARY_LAYER);
//////Insert Background Layer///////////
printableLayers.addLayerBefore(backgroundLayer, NetworkEditPartFactory.EXTERNAL_NODE_LABELS_LAYER,
LayerConstants.PRIMARY_LAYER);
////////////////////////////////////////
LayeredPane scalableLayers = (LayeredPane) root.getLayer(LayerConstants.SCALABLE_LAYERS);
FreeformLayer scaledFeedbackLayer = new FreeformLayer();
scaledFeedbackLayer.setEnabled(false);
scalableLayers.addLayerAfter(scaledFeedbackLayer, LayerConstants.SCALED_FEEDBACK_LAYER,
DiagramRootEditPart.DECORATION_UNPRINTABLE_LAYER);
}
参考资料
搬家前链接:https://www.cnblogs.com/bjzhanghao/archive/2007/03/13/673273.html
欢迎转载
请保留原始链接:https://bjzhanghao.com/p/2744
请保留原始链接:https://bjzhanghao.com/p/2744