2012-05-29 24 views
1

我目前正在尝试使用Griffon 0.9.5和FlamingoBuilder创建应用程序。如何在Griffon中使用FlamingoBuilder创建功能区?

我中Application.groovy改变frameClass价值'org.jvnet.flamingo.ribbon.JRibbonFrame'并以带状添加到应用程序窗口试了几件事情。

我的第一次尝试是创建一个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。显示按钮。但是,我不确定这是否是Griffon的做事方式。 问题:有没有更好的方法来创建一个功能区?

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:没有这样的属性:文本 类: griffon.builder .flamingo.factory.RibbonApplicationMenuEntryPrimaryFactory

documentation of FlamingoBuilder状态,有一个text属性,当我删除文本属性我得到一个异常,因为text属性必须设置。我有点失落。这段代码有什么问题?

回答

1

恐怕第一个问题与应用程序()节点工厂vs ribbonFrame()工厂有关。您会发现,Griffon假定框架子类的行为与任何其他常规JFra​​me类似,但是JRibbonFrame以不同方式处理其子元素。这对于ApplicationFactory是不知道的,所以它将“失败”添加功能区任务,除非您像在第二个片段中显示的那样手动添加它们。

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

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

+0

感谢您的解释。你打算从[Insubstancial 7.1](http://insubstantial.posterous.com/insubstantial-71-release)支持Flamingo吗?我已经提出了自己制作FlamingoBuilder的想法。 –

+0

没错,Peacock(来自Insubstancial)就是要走的路。 FlamingoBuilder托管在https://github.com/griffon/flamingobuilder拉请求,欢迎:-) – aalmiray