Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nobusue
Created October 11, 2010 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobusue/619816 to your computer and use it in GitHub Desktop.
Save nobusue/619816 to your computer and use it in GitHub Desktop.
// g100pon #29 growlみたいなの
// telnet等で50000番に接続し、メッセージを送信すると、タスクトレイから表示されます。
// Icon画像は適当に用意して下さい。
// (いろいろバグが残っていますが、ご笑納ください。。。)
//
// 参考リンク:
// http://www.javainthebox.net/laboratory/JavaSE6/trayicon/trayicon.html
// http://marcinfo.blogspot.com/2007/01/groovy-in-system-tray-as-of-java-1.html
import java.awt.*
def trayIcon = null
def exit = { e ->
println "Exiting ..."
System.exit(0)
}
if (SystemTray.isSupported()) {
def tray = SystemTray.getSystemTray()
def image = Toolkit.getDefaultToolkit().
getImage("groovy.png")
def popup = new PopupMenu()
popup.add(new MenuItem(label:"Exit", actionPerformed:exit))
trayIcon = new TrayIcon(image:image, tooltip:"Tray Demo",
popup:popup, imageAutoSize:true)
try {
tray.add(trayIcon)
} catch (AWTException e) {
println e
}
} else {
prinltn "System Tray not supported"
}
def server = new ServerSocket(50000)
while(true) {
server.accept { socket ->
socket.withStreams { input, output ->
def w = new PrintWriter(output)
w << "Enter message: "
w.flush()
def r = new InputStreamReader(input).readLine()
trayIcon.displayMessage('GNotifier', r, TrayIcon.MessageType.INFO)
w.close()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment