Created
October 11, 2010 01:35
-
-
Save nobusue/619816 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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