KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdic > tray > internal > impl > WinSystemTrayService


1 /*
2  * Copyright (C) 2004 Sun Microsystems, Inc. All rights reserved. Use is
3  * subject to license terms.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the Lesser GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  */

20
21 /**
22  * The <code>WinSystemTrayService</code> interface is the <code>SystemTray
23  * </code> implementation.
24  *
25  */

26 package org.jdesktop.jdic.tray.internal.impl;
27
28 import org.jdesktop.jdic.tray.internal.SystemTrayService;
29 import org.jdesktop.jdic.tray.internal.TrayIconService;
30 import org.jdesktop.jdic.tray.TrayIcon;
31 import java.awt.Toolkit JavaDoc;
32
33
34 public class WinSystemTrayService implements SystemTrayService {
35
36     public WinSystemTrayService() {}
37      
38     public void addNotify() {}
39
40     public void addTrayIcon(TrayIcon ti, TrayIconService tis, int trayIndex) {
41         WinTrayIconService trayIcon = (WinTrayIconService) tis;
42         trayIcon.addNotify();
43     }
44
45     public void removeTrayIcon(TrayIcon ti, TrayIconService tis, int trayIndex) {
46         WinTrayIconService trayIcon = (WinTrayIconService) tis;
47         trayIcon.remove();
48     }
49    
50     static Thread JavaDoc display_thread;
51     
52     static {
53         //
54
// Very important, we need to force AWT to get loaded before the
55
// native library libtray.so is loaded. Otherwise AWT will fail.
56
Toolkit JavaDoc t = Toolkit.getDefaultToolkit();
57         t.sync();
58         
59         display_thread = new DisplayThread();
60         display_thread.setDaemon(true);
61         synchronized(DisplayThread.class){
62             try{
63                 display_thread.start();
64                 DisplayThread.class.wait();
65             }catch(InterruptedException JavaDoc e){
66                 // ignore interrupted exception
67
}
68         }
69     }
70 }
71
72 class DisplayThread extends Thread JavaDoc{
73     private static native void initTray();
74     private static native void eventLoop();
75     static {
76         System.loadLibrary("tray");
77     }
78     public void run(){
79         synchronized(DisplayThread.class){
80             DisplayThread.initTray();
81             DisplayThread.class.notify();
82         }
83         DisplayThread.eventLoop();
84     }
85 }
Popular Tags