1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package ziga.gui;
24
25 import java.awt.Frame;
26 import java.io.File;
27
28 import org.xnap.XNap;
29 import org.xnap.gui.XNapFrame;
30
31 /***
32 * Uses ziga.dll to iconify a frame.
33 *
34 * Adopted for XNap by Steffen Pingel.
35 *
36 * @version 0.1 11/30/2001
37 * @author Frederik Zimmer
38 */
39 public class WindowsDesktopIndicator {
40
41 private XNapFrame frame;
42 private int handler = 0;
43 /***
44 * Used by native code.
45 */
46 private int image = -1;
47
48 public WindowsDesktopIndicator(XNapFrame frame)
49 {
50 this.frame = frame;
51 }
52
53 public void exitApplication()
54 {
55 frame.exit(false);
56 }
57
58 protected void finalize()
59 {
60 freeImages();
61 nativeDisable();
62 }
63
64 protected void freeImages()
65 {
66 if (image != -1) {
67 nativeFreeImage(image);
68 }
69 }
70
71 public String getString(String key)
72 {
73 if (key.equals("desktopIndicator.exit")) {
74 return XNap.tr("Quit");
75 }
76 else if (key.equals("desktopIndicator.hide")) {
77 return XNap.tr("Hide XNap");
78 }
79 else if (key.equals("desktopIndicator.show")) {
80 return XNap.tr("Show XNap");
81 }
82 else {
83 return "";
84 }
85 }
86
87 public void hideFrame()
88 {
89 if (frame != null) {
90 frame.setVisible(false);
91 }
92 }
93
94 public int isFrameVisible()
95 {
96 if (frame != null) {
97 return frame.isVisible() ? 1 : 0;
98 }
99 else {
100 return 0;
101 }
102 }
103
104 /***
105 * Hides the desktop indicator.
106 */
107 public void hide()
108 {
109 nativeHide();
110 }
111
112 public boolean show(String iconPath, String tooltip)
113 {
114 if (image == -1) {
115 File f = new File(iconPath);
116 if (f.exists()) {
117 image = nativeLoadImage(f.getPath());
118 }
119 }
120
121 if (image != -1) {
122 nativeEnable(image, tooltip);
123 return true;
124 }
125
126 return false;
127 }
128
129 public void showFrame()
130 {
131 if (frame != null) {
132 hide();
133 frame.setState(Frame.NORMAL);
134 frame.setVisible(true);
135 frame.toFront();
136 frame.requestFocus();
137 }
138 }
139
140 /***
141 * Disabled status.
142 */
143 private synchronized native void nativeDisable();
144
145 /***
146 * Show.
147 */
148 private synchronized native void nativeEnable(int image, String tooltip);
149
150 private static synchronized native void nativeFreeImage(int image);
151
152 private static synchronized native int nativeLoadImage(String filename);
153
154 private static synchronized native int nativeLoadImageFromResource(int inResource);
155
156 /***
157 * Hide.
158 */
159 private synchronized native void nativeHide();
160
161 }