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);
}

本文转自博客园八进制的博客,原文链接:GMF应用程序设置背景图片,如需转载请自行联系原博主。

上一篇:JavaScript动态控制网页元素事件


下一篇:MSBuild + MSILInect实现编译时AOP之预览