帆软报表重要NorthRegionContainerPane 主要是设计器菜单栏的部分

楼主
插件开发者

前面分析了帆软报表设计器主界面采用了BorderLayout布局,如下图:

        

 1 NORTH布局部分,这个部分放到的NorthRegionContainerPane。他是设计器的Menu部分。下面来分析下这个类。

        1.1 构造函数

                

 public NorthRegionContainerPane() {
        ToolBarMenuDock ad = DesignerContext.getDesignerFrame().getToolBarMenuDock();
        this.setLayout(new BorderLayout());
        this.add(new UIMenuHighLight(), "South");
        this.add(this.initNorthEastPane(ad), "East");
    }

        可以看出这个类也是BorderLayout布局,South放的是UIMenuHighLight,这个应该是Menu的高亮部分 。

        1.2 initNorthEastPane方法

                

 protected JPanel initNorthEastPane(final ToolBarMenuDock ad) {
        final JPanel northEastPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
        GeneralContext.listenPluginRunningChanged(new PluginEventListener(-1) {
            public void on(PluginEvent event) {
                NorthRegionContainerPane.this.refreshNorthEastPane(northEastPane, ad);
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        if (DesignerContext.getDesignerFrame() != null) {
                            DesignerContext.getDesignerFrame().refresh();
                            DesignerContext.getDesignerFrame().repaint();
                        }
                    }
                });
            }
        }, new PluginFilter() {
            public boolean accept(PluginContext context) {
                return context.contain(PluginModule.ExtraDesign);
            }
        });
        this.refreshNorthEastPane(northEastPane, ad);
        return northEastPane;
    }

        上面创建的northEastPane,就是一个BorderLayout布局的空JPanel。

        1.3 看下refreshNorthEastPane

                

private void refreshNorthEastPane(final JPanel northEastPane, final ToolBarMenuDock ad) {
        northEastPane.removeAll();
        northEastPane.setLayout(new FlowLayout(2, 0, 0));
        northEastPane.add(LogMessageBar.getInstance());
        TitlePlaceProcessor processor = (TitlePlaceProcessor)ExtraDesignClassManager.getInstance().getSingle("TitlePlaceProcessor");
        if (processor != null) {
            final Component[] bbsLoginPane = new Component[]{null};
            OSSupportCenter.buildAction(new OSBasedAction() {
                public void execute(Object... objects) {
                    bbsLoginPane[0] = ad.createBBSLoginPane();
                }
            }, SupportOSImpl.USERINFOPANE);
            processor.hold(northEastPane, LogMessageBar.getInstance(), bbsLoginPane[0]);
        }

        northEastPane.add(ad.createAlphaFinePane());
        if (!DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isEnabled()) {
            ad.createAlphaFinePane().setVisible(false);
        }

        northEastPane.add(ad.createNotificationCenterPane());
        OSSupportCenter.buildAction(new OSBasedAction() {
            public void execute(Object... objects) {
                northEastPane.add(ad.createBBSLoginPane());
            }
        }, SupportOSImpl.USERINFOPANE);
    }

        将northEastPane的BorderLayout布局改为FlowLayout布局了,这个布局是将组件按照设置对齐方式从左向右排列,一行排满到下一行继续排列。这里对齐方式是2,表示从右往左。

        northEastPane.add(ad.createAlphaFinePane());

        northEastPane.add(ad.createNotificationCenterPane());

        northEastPane.add(ad.createBBSLoginPane())

                上面是增加三个JLabel组件,

从上面可以看出 这个部分应该就是设计器的:

        

 那么菜单那部分UI在哪创建的呢?

        其实他是在DesignerFrame的initMenuPane方法中创建的。

                

  protected void initMenuPane() {
        this.basePane.add(NorthRegionContainerPane.getInstance(), "North");
        this.resetToolkitByPlus((ToolBarMenuDockPlus)null);
    }

        他是在this.resetToolkitByPlus((ToolBarMenuDockPlus)null)创建的。这个方法会调用NorthRegionContainerPane.getInstance().resetToolkitByPlus(plus, this.ad)来创建的。具体的创建代码为:

        

public MenuDef[] menus(ToolBarMenuDockPlus plus) {
        clearPluginListeners();
        final List menuList = new ArrayList();
        menuList.add(this.createFileMenuDef(plus));
        MenuDef[] menuDefs = this.createTemplateShortCuts(plus);
        this.insertTemplateExtendMenu(plus, menuDefs);
        menuList.addAll(Arrays.asList(menuDefs));
        if (WorkContext.getCurrent() != null && WorkContext.getCurrent().isRoot()) {
            menuList.add(this.createServerMenuDef(plus));
        }

        menuList.add(this.createHelpMenuDef());
        LocaleCenter.buildAction(new LocaleAction() {
            public void execute() {
                ToolBarMenuDock.this.addCommunityMenuDef(menuList);
            }
        }, SupportLocaleImpl.COMMUNITY);
        this.addAllUpdateActionsToList(menuList);
        UpdateActionManager.getUpdateActionManager().setUpdateActions(this.shortCutsList);
        return (MenuDef[])menuList.toArray(new MenuDef[menuList.size()]);
    }

        可以看出 createFileMenuDef创建File一级菜单,createTemplateShortCuts创建模板一级菜单,createTemplateShortCuts的调用过程中,会调用com.fr.design.mainframe.ElementCasePaneDelegate的createInsertMenuDef,createCellMenuDef来创建插入,单元格菜单。

 createServerMenuDef创建服务器一级菜单,createHelpMenuDef创建帮助一级菜单,

下面看看创建File菜单的过程:

        

public MenuDef createFileMenuDef(ToolBarMenuDockPlus plus) {
        MenuDef menuDef;
        if (DesignerMode.isVcsMode()) {
            menuDef = VcsScene.createFileMenuDef(plus);
            this.insertMenu(menuDef, "file");
            return menuDef;
        } else {
            menuDef = new MenuDef(Toolkit.i18nText("Fine-Design_Basic_File"), 'F');
            ShortCut[] scs = new ShortCut[0];
            if (!DesignerMode.isAuthorityEditing()) {
                scs = this.createNewFileShortCuts();
            }

            if (!ArrayUtils.isEmpty(scs)) {
                menuDef.addShortCut(scs);
            }

            menuDef.addShortCut(this.openTemplateAction());
            menuDef.addShortCut(new OpenRecentReportMenuDef());
            this.addCloseCurrentTemplateAction(menuDef);
            scs = plus.shortcut4FileMenu();
            if (!ArrayUtils.isEmpty(scs)) {
                menuDef.addShortCut(SeparatorDef.DEFAULT);
                menuDef.addShortCut(scs);
                menuDef.addShortCut(SeparatorDef.DEFAULT);
            }

            this.addPreferenceAction(menuDef);
            this.addSwitchExistEnvAction(menuDef);
            menuDef.addShortCut(new ExitDesignerAction());
            this.insertMenu(menuDef, "file");
            return menuDef;
        }
    }

   首先这个方法是在com.fr.design.mainframe.toolbar.ToolBarMenuDock类中,

   创建菜单项的类是:MenuDef

  File菜单下的是通过 , 一共给File菜单添加了8个Action:

        NewWorkBookAction,NewPolyReportAction,OpenTemplateAction,OpenRecentReportMenuDef,CloseCurrentTemplateAction,PreferenceAction,SwitchExistEnv,ExitDesignerAction。

 所有的其他Action都在 fine-report-designer的com.fr.design.actions包下,看图:

        

         这些Action就是菜单栏上的功能,后面可以详细研究下

​   

更多内容:https://blog.csdn.net/sixingbugai?spm=1000.2115.3001.5343

分享扩散:

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

返回顶部 返回列表