如何在格里芬用Flamingo Builder创建一个功能区?

时间:2012-05-29 21:55:04

标签: groovy griffon radiance-flamingo

我目前正在尝试使用Griffon 0.9.5和FlamingoBuilder创建一个应用程序。

我已将 Application.groovy frameClass的值更改为'org.jvnet.flamingo.ribbon.JRibbonFrame'并尝试了一些操作,以便在应用程序窗口中添加功能区。< / p>

我的第一次尝试是创建一个带有嵌套ribbonTask节点的ribbonBand节点。应用程序启动但按钮未显示。

application(title: 'test01',
        preferredSize: [320, 240],
        pack: true,
        locationByPlatform: true,
        iconImage: imageIcon('/griffon-icon-48x48.png').image,
        {
            ribbonTask(title: 'Start') {
                    ribbonBand(id: 'fooBarBand', title: 'FooBar', image: imageIcon('/griffon-icon-48x48.png').image) {
                        commandButton(id: 'fooButton', text: 'Foo', image: imageIcon('/griffon-icon-48x48.png').image)
                        commandButton(id: 'barButton', text: 'Bar', image: imageIcon('/griffon-icon-48x48.png').image)
                    }
            }

            // add content here
            label('Content Goes Here') // delete me
        }
)

Screenshot of first attempt


在我的第二次尝试中,我明确创建了RibbonTask并致电addTask。按钮显示。但是,我不确定这是否真的是格里芬的做事方式。 问题:有更好的方法来创建功能区吗?

application(title: 'test01',
        preferredSize: [320, 240],
        pack: true,
        locationByPlatform: true,
        iconImage: imageIcon('/griffon-icon-48x48.png').image,
        {
            ribbonBand(id: 'fooBarBand', title: 'FooBar', image: imageIcon('/griffon-icon-48x48.png').image) {
                commandButton(id: 'fooButton', text: 'Foo', image: imageIcon('/griffon-icon-48x48.png').image)
                commandButton(id: 'barButton', text: 'Bar', image: imageIcon('/griffon-icon-48x48.png').image)
            }
            current.ribbon.addTask new RibbonTask('Start', fooBarBand)

            // add content here
            label('Content Goes Here') // delete me
        }
)

Screenshot of second attempt


然后我尝试使用以下代码段添加ribbonApplicationMenu

        ribbonApplicationMenu(id: 'appMenu') {
            ribbonApplicationMenuEntryPrimary(id: 'quitMenuEntry', text: 'Quit',
                    entryKind: JCommandButton.CommandButtonKind.ACTION_ONLY,
                    image: imageIcon('/griffon-icon-48x48.png').image)
        }

然而,它不起作用。我得到以下运行时异常:

  

java.lang.RuntimeException:无法为其创建组件   'ribbonApplicationMenuEntryPrimary'原因:   groovy.lang.MissingPropertyException:没有这样的属性:text for   类:   griffon.builder.flamingo.factory.RibbonApplicationMenuEntryPrimaryFactory

documentation of FlamingoBuilder表示存在text属性,当我删除text属性时,我得到一个异常,因为必须设置text属性。我有点茫然。这段代码片有什么问题?

1 个答案:

答案 0 :(得分:1)

我担心第一个问题与application()node factory vs ribbonFrame()factory有关。你看,Griffon假设框架子类的行为与任何其他常规JFra​​me一样,但是JRibbonFrame以不同的方式处理它的子项。这不知道ApplicationFactory所以它“失败”添加功能区任务,除非你在第二个代码片段中显示时手动添加它们。

可以通过将父/子关系代码从ribbonFrame()移动到ribbonBand / ribbonTask工厂来解决此问题。这需要FlamingoBuilder的新版本。

现在关于第二个问题,这似乎是我们方面的一个错误。考虑到FlamingoBuilder在任何情况下都应该更新,我们也会解决这个问题。