11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.awt.windows;
27
28 import java.awt.Graphics2D;
29 import java.awt.AWTEvent;
30 import java.awt.Frame;
31 import java.awt.PopupMenu;
32 import java.awt.Point;
33 import java.awt.TrayIcon;
34 import java.awt.Image;
35 import java.awt.peer.TrayIconPeer;
36 import java.awt.image.*;
37
38 import sun.awt.AWTAccessor;
39 import sun.awt.SunToolkit;
40 import sun.awt.image.IntegerComponentRaster;
41
42 final class WTrayIconPeer extends WObjectPeer implements TrayIconPeer {
43 static final int TRAY_ICON_WIDTH = 16;
44 static final int TRAY_ICON_HEIGHT = 16;
45 static final int TRAY_ICON_MASK_SIZE = (TRAY_ICON_WIDTH * TRAY_ICON_HEIGHT) / 8;
46
47 IconObserver observer = new IconObserver();
48 boolean firstUpdate = true;
49 Frame popupParent = new Frame("PopupMessageWindow");
50 PopupMenu popup;
51
52 @Override
53 protected void disposeImpl() {
54 if (popupParent != null) {
113 _displayMessage(caption, text, messageType);
114 }
115
116
117 // ***********************************************
118 // ***********************************************
119
120
121 synchronized void updateNativeImage(Image image) {
122 if (isDisposed())
123 return;
124
125 boolean autosize = ((TrayIcon)target).isImageAutoSize();
126
127 BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
128 BufferedImage.TYPE_INT_ARGB);
129 Graphics2D gr = bufImage.createGraphics();
130 if (gr != null) {
131 try {
132 gr.setPaintMode();
133
134 gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
135 (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);
136
137 createNativeImage(bufImage);
138
139 updateNativeIcon(!firstUpdate);
140 if (firstUpdate) firstUpdate = false;
141
142 } finally {
143 gr.dispose();
144 }
145 }
146 }
147
148 void createNativeImage(BufferedImage bimage) {
149 Raster raster = bimage.getRaster();
150 byte[] andMask = new byte[TRAY_ICON_MASK_SIZE];
151 int pixels[] = ((DataBufferInt)raster.getDataBuffer()).getData();
152 int npixels = pixels.length;
153 int ficW = raster.getWidth();
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.awt.windows;
27
28 import java.awt.Graphics2D;
29 import java.awt.AWTEvent;
30 import java.awt.Frame;
31 import java.awt.GraphicsConfiguration;
32 import java.awt.GraphicsDevice;
33 import java.awt.GraphicsEnvironment;
34 import java.awt.PopupMenu;
35 import java.awt.Point;
36 import java.awt.TrayIcon;
37 import java.awt.Image;
38 import java.awt.Insets;
39 import java.awt.Toolkit;
40 import java.awt.geom.AffineTransform;
41 import java.awt.peer.TrayIconPeer;
42 import java.awt.image.*;
43
44 import sun.awt.AWTAccessor;
45 import sun.awt.SunToolkit;
46 import sun.awt.image.IntegerComponentRaster;
47
48 final class WTrayIconPeer extends WObjectPeer implements TrayIconPeer {
49 static final int TRAY_ICON_WIDTH = 16;
50 static final int TRAY_ICON_HEIGHT = 16;
51 static final int TRAY_ICON_MASK_SIZE = (TRAY_ICON_WIDTH * TRAY_ICON_HEIGHT) / 8;
52
53 IconObserver observer = new IconObserver();
54 boolean firstUpdate = true;
55 Frame popupParent = new Frame("PopupMessageWindow");
56 PopupMenu popup;
57
58 @Override
59 protected void disposeImpl() {
60 if (popupParent != null) {
119 _displayMessage(caption, text, messageType);
120 }
121
122
123 // ***********************************************
124 // ***********************************************
125
126
127 synchronized void updateNativeImage(Image image) {
128 if (isDisposed())
129 return;
130
131 boolean autosize = ((TrayIcon)target).isImageAutoSize();
132
133 BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
134 BufferedImage.TYPE_INT_ARGB);
135 Graphics2D gr = bufImage.createGraphics();
136 if (gr != null) {
137 try {
138 gr.setPaintMode();
139 GraphicsEnvironment ge = GraphicsEnvironment.
140 getLocalGraphicsEnvironment();
141 Toolkit toolkit = Toolkit.getDefaultToolkit();
142 GraphicsDevice[] gds = ge.getScreenDevices();
143 GraphicsDevice device = ge.getDefaultScreenDevice();
144 Insets in = new Insets(0, 0, 0, 0);
145 for (GraphicsDevice gd : gds) {
146 GraphicsConfiguration gc = gd.getDefaultConfiguration();
147 Insets insets = toolkit.getScreenInsets(gc);
148 if (insets.bottom > in.bottom
149 || insets.top > in.top
150 || insets.left > in.left
151 || insets.right > in.right) {
152 in = insets;
153 device = gd;
154 }
155 }
156 AffineTransform tx = device.getDefaultConfiguration().
157 getDefaultTransform();
158 gr.setTransform(tx);
159 gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
160 (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);
161
162 createNativeImage(bufImage);
163
164 updateNativeIcon(!firstUpdate);
165 if (firstUpdate) firstUpdate = false;
166
167 } finally {
168 gr.dispose();
169 }
170 }
171 }
172
173 void createNativeImage(BufferedImage bimage) {
174 Raster raster = bimage.getRaster();
175 byte[] andMask = new byte[TRAY_ICON_MASK_SIZE];
176 int pixels[] = ((DataBufferInt)raster.getDataBuffer()).getData();
177 int npixels = pixels.length;
178 int ficW = raster.getWidth();
|