Griffon SystemTray中的自动更新(时间)工具提示

时间:2010-12-04 14:20:31

标签: groovy java griffon

嘿 我正在考虑在一个非常简单的DeskTop应用程序中使用griffon我被要求编码。 90%的功能是从系统托盘上点击几下鼠标,就像“开始/选择/停止”。我需要的一件事是工具提示,它会每秒(或分钟,没关系;-))更新它的内容,计算某人处理某项特定任务的时间。

我的问题是:

  • 如何定期调用“Youre work for:$ {HourMin.since model.startedWorkingAt}”,以使tootip始终保持最新状态?使用此代码,只能在工具提示构建时调用一次。
  • 如何在应用程序生命周期内向popupMenu动态添加“操作”?

感谢您提出建议 - 解决此类问题的建议也非常有用。

actions {
  action(id: 'cutAction',
          name: 'Pokaż okno',
          closure: {
            trayIcon.displayMessage("Cut", "Cut some content", NONE)
          },
          mnemonic: 'T',
          accelerator: shortcut('X'),
          smallIcon: imageIcon(resource: "icons/cut.png", class: Console),
          shortDescription: 'Cut'
  )
//... more actions
}

systemTray {
  trayIcon(id: "trayIcon",
          resource: "/groovy/ui/ConsoleIcon.png",
          class: groovy.ui.Console,
          toolTip: {
            "Youre working for: ${HourMin.since model.startedWorkingAt}"
          },
          actionPerformed: {
//            todo do toggle
          }) {
    popupMenu {
      menuItem(cutAction)
      menuItem(copyAction)
      menuItem(pasteAction)
      separator()
      menuItem(exitAction)
    }
  }
}

2 个答案:

答案 0 :(得分:1)

您是否尝试过绑定GString?

toolTip: bind {
        "Youre working for: ${HourMin.since model.startedWorkingAt}"
      },

答案 1 :(得分:0)

我找到了一种方法,这是如何:

// in the controller
def updateSystemTimeTask = new TimerTask() {
  @Override
  void run() {
    onSystemTimeUpdate System.currentTimeMillis()
  }
}

def onSystemTimeUpdate(Long systemTime) {
  if (model.working) {
    view.systemTray.trayIcons[0].toolTip = "Pracujesz już ${HourMin.since model.startedWorkingAt}".toString()
  } else {
    view.systemTray.trayIcons[0].toolTip = = "Obecnie nie pracujesz."
  }
}

// ant this in the initialization method
def myTimer = new Timer().schedule updateSystemTimeTask, initialDelay, minute

我不确定这是否是最干净的方式,但我猜这很好,因为无论如何所有操作都在视图控制器中。

相关问题