KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
23  * The <code>GnomeSystemTrayService</code> interface is the contract for a
24  * native <code>SystemTray</code> implementation.
25  *
26  */

27 package org.jdesktop.jdic.tray.internal.impl;
28
29
30 import org.jdesktop.jdic.tray.internal.SystemTrayService;
31 import org.jdesktop.jdic.tray.internal.TrayIconService;
32 import org.jdesktop.jdic.tray.SystemTray;
33 import org.jdesktop.jdic.tray.TrayIcon;
34 import java.awt.Toolkit JavaDoc;
35 import sun.awt.EmbeddedFrame;
36
37
38 public class GnomeSystemTrayService implements SystemTrayService {
39
40     public GnomeSystemTrayService() {}
41      
42     public void addNotify() {}
43
44     public void addTrayIcon(TrayIcon ti, TrayIconService tis, int trayIndex) {
45         tis.addNotify();
46     }
47
48     // public void addTrayApplet(TrayApplet ta, int trayIndex) {}
49

50     public void removeTrayIcon(TrayIcon ti, TrayIconService tis, int trayIndex) {
51         ((GnomeTrayIconService)tis).remove();
52     }
53
54     // public void removeTrayApplet(TrayApplet ta, int trayIndex){}
55

56     static native boolean locateSystemTray();
57     static Thread JavaDoc display_thread;
58    
59     static native void eventLoop();
60     
61     static {
62         //
63
// Very important, we need to force AWT to get loaded before the
64
// native library libtray.so is loaded. Otherwise AWT will fail.
65
Toolkit JavaDoc t = Toolkit.getDefaultToolkit();
66
67         t.sync();
68
69         System.loadLibrary("tray");
70         GnomeSystemTrayService.initNative(System.getProperty("java.home"));
71         if (!locateSystemTray()) {
72             throw new Error JavaDoc("System Tray not Found !");
73         }
74
75         display_thread = new Thread JavaDoc(new Runnable JavaDoc() {
76             public void run() {
77                 eventLoop();
78             }
79         });
80         display_thread.setDaemon(true);
81         
82         display_thread.start();
83
84     }
85
86     static native void dockWindow(long window);
87     static native void initNative(String JavaDoc javaHome);
88
89 }
90
Popular Tags