Remote NotificationsIntegrace desktopu a webu v Javě – jednoduše a bez závislostí!                                        ...
System Tray IconRemote Notifications            2
System Tray Iconimport java.awt.*;if (SystemTray.isSupported()) {    Image img = Toolkit.getDefaultToolkit().getImage("cof...
Windows SoundsRemote Notifications         4
Windows soundsimport java.awt.Toolkit;Runnable sound =    (Runnable) Toolkit.getDefaultToolkit().getDesktopProperty("win.s...
HTTP serverRemote Notifications                 6
HTTP serverimport com.sun.net.httpserver.*;HttpServer httpServer = HttpServer.create(new InetSocketAddress(80), 0);HttpHan...
HTTP serverimport com.sun.net.httpserver.*;HttpServer httpServer = HttpServer.create(new InetSocketAddress(80), 0);HttpHan...
Notifier                       https://github.com/kwart/NotifierRemote Notifications                                       9
Notifier – server     spustitelný JAR       –   $java -jar Notifier.jar [port [defaultIcon [soundDesktopProperty]]     výc...
Notifier – klienti     jakýkoliv běžný HTTP klient       –   firefox http://localhost:8811/teddy-bear     příkazová řádka ...
Zdrojové kódy ke stažení       –   https://github.com/kwart/Notifier     API dokumentace       –   System Tray           h...
Upcoming SlideShare
Loading in …5
×

Remote Notifications

1,593 views

Published on

Prezentace z jOpenSpace 2011.

Jak pomocí jedné třídy vytvořit system tray notifikátor pro vzdálené použití (běží jako HTTP server).

Více na:
https://github.com/kwart/Notifier

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,593
On SlideShare
0
From Embeds
0
Number of Embeds
316
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Remote Notifications

  1. 1. Remote NotificationsIntegrace desktopu a webu v Javě – jednoduše a bez závislostí! Josef Cacek Siemens IT Solutions and Services Brno
  2. 2. System Tray IconRemote Notifications 2
  3. 3. System Tray Iconimport java.awt.*;if (SystemTray.isSupported()) { Image img = Toolkit.getDefaultToolkit().getImage("coffee.png"); PopupMenu popup = // ... ; TrayIcon trayIcon = new TrayIcon(img, "My own tooltip", popup); trayIcon.setImageAutoSize(true); //trayIcon.addMouseListener(...); //The MOUSE_ENTERED and MOUSE_EXITED mouse events are not supported. SystemTray.getSystemTray().add(trayIcon); //... trayIcon.displayMessage("Title", "I like it.", TrayIcon.MessageType.INFO);}Remote Notifications 3
  4. 4. Windows SoundsRemote Notifications 4
  5. 5. Windows soundsimport java.awt.Toolkit;Runnable sound = (Runnable) Toolkit.getDefaultToolkit().getDesktopProperty("win.sound.asterisk");if (sound != null) { sound.run();}// "win.sound.*" properties:// default asterisk exclamation hand question// maximize minimize// menuCommand menuPopup// open close start exit// restoreDown restoreUpRemote Notifications 5
  6. 6. HTTP serverRemote Notifications 6
  7. 7. HTTP serverimport com.sun.net.httpserver.*;HttpServer httpServer = HttpServer.create(new InetSocketAddress(80), 0);HttpHandler handler = new HttpHandler() { public void handle(HttpExchange exchange) throws IOException { InputStream is = exchange.getRequestBody(); //... some logic here exchange.getResponseHeaders().add("Content-Type", "text/plain"); exchange.sendResponseHeaders(200, 0); // status - SC_OK, contentLength - chunked OutputStreamWriter osw = new OutputStreamWriter(exchange.getResponseBody()); osw.append("Hello world wide web!nQuery: " + exchange.getRequestURI().getQuery()); is.close(); osw.close(); }};httpServer.createContext("/", handler);httpServer.start();Remote Notifications 7
  8. 8. HTTP serverimport com.sun.net.httpserver.*;HttpServer httpServer = HttpServer.create(new InetSocketAddress(80), 0);HttpHandler handler = new HttpHandler() { public void handle(HttpExchange exchange) throws IOException { InputStream is = exchange.getRequestBody(); //... some logic here exchange.getResponseHeaders().add("Content-Type", "text/plain"); exchange.sendResponseHeaders(200, 0); // status - SC_OK, contentLength - chunked OutputStreamWriter osw = new OutputStreamWriter(exchange.getResponseBody()); osw.append("Hello world wide web!nQuery: " + exchange.getRequestURI().getQuery()); is.close(); osw.close(); }};httpServer.createContext("/", handler);httpServer.start();Remote Notifications 8
  9. 9. Notifier https://github.com/kwart/NotifierRemote Notifications 9
  10. 10. Notifier – server spustitelný JAR – $java -jar Notifier.jar [port [defaultIcon [soundDesktopProperty]] výchozí nastavení – port: 8811 – ikona: sun – zvuk: win.sound.asterisk události – jednoduchý klik – návrat k výchozí ikoně – dvojklik – ukončení programuRemote Notifications 10
  11. 11. Notifier – klienti jakýkoliv běžný HTTP klient – firefox http://localhost:8811/teddy-bear příkazová řádka – wget -O - http://localhost:8811/warning – curl -d "Build finished succesfully" http://localhost:8811/ok – curl -d "%sname: %smessage" --connect-timeout 3 http://10.0.2.2:8811/bubbleRemote Notifications 11
  12. 12. Zdrojové kódy ke stažení – https://github.com/kwart/Notifier API dokumentace – System Tray http://download.oracle.com/javase/6/docs/api/java/awt/SystemTray.html – Windows Sounds http://download.oracle.com/javase/1.4.2/docs/guide/swing/1.4/w2k_props.html – HTTP server http://download.oracle.com/javase/6/docs/jre/api/net/httpserver/spec/ šablona prezentace od Chih-Hao Tsai http://technology.chtsai.org/impress/Remote Notifications 12

×