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); }
参考:为图形编辑器设置背景图片