--- /dev/null 2015-11-23 09:25:32.700005950 +0300 +++ new/src/java.desktop/windows/classes/sun/awt/windows/WTaskbarPeer.java 2015-11-23 09:33:03.802230452 +0300 @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package sun.awt.windows; + +import java.awt.AlphaComposite; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Taskbar.Feature; +import java.awt.peer.TaskbarPeer; +import java.awt.Window; +import java.awt.image.BufferedImage; +import java.awt.image.DataBufferInt; +import sun.awt.AWTAccessor; +import sun.awt.OSInfo; + +final public class WTaskbarPeer implements TaskbarPeer { + + private static boolean supported = false; + private static boolean initExecuted = false; + + private static synchronized void init() { + if (!initExecuted) { + supported = OSInfo.getWindowsVersion() + .compareTo(OSInfo.WINDOWS_7) >= 0 + && nativeInit(); + } + initExecuted = true; + } + + static boolean isTaskbarSupported() { + init(); + return supported; + } + + WTaskbarPeer() { + init(); + } + + @Override + public boolean isSupported(Feature feature) { + switch(feature) { + case ICON_BADGE_IMAGE_WINDOW: + case PROGRESS_STATE_WINDOW: + case PROGRESS_VALUE_WINDOW: + return supported; + case USER_ATTENTION_WINDOW: + return true; + default: + return false; + } + } + + private static int[] imageToArray(Image image) { + if (image == null) { + return null; + } + + int w = image.getWidth(null); + int h = image.getHeight(null); + + if (w < 0 || h < 0) { + return null; + } + + BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE); + Graphics2D g2 = bimg.createGraphics(); + g2.setComposite(AlphaComposite.Src); + g2.drawImage(image, 0, 0, null); + g2.dispose(); + + return ((DataBufferInt) bimg.getRaster().getDataBuffer()).getData(); + } + + @Override + public void setWindowIconBadge(Window window, final Image image) { + WWindowPeer wp = AWTAccessor.getComponentAccessor().getPeer(window); + if (wp != null) { + int w = 0; + int h = 0; + int[] buffer = imageToArray(image); + if (buffer != null) { + w = image.getWidth(null); + h = image.getHeight(null); + } + setOverlayIcon(wp.getHWnd(), buffer, w, h); + } + } + + @Override + public void requestWindowUserAttention(Window window) { + WWindowPeer wp = AWTAccessor.getComponentAccessor().getPeer(window); + if (wp != null) { + flashWindow(wp.getHWnd()); + } + } + + @Override + public void setWindowProgressValue(Window window, int value) { + WWindowPeer wp = AWTAccessor.getComponentAccessor().getPeer(window); + if (wp != null) { + setProgressValue(wp.getHWnd(), value); + } + } + + @Override + public void setWindowProgressState(Window window, int state) { + WWindowPeer wp = AWTAccessor.getComponentAccessor().getPeer(window); + if (wp != null) { + setProgressState(wp.getHWnd(), state); + } + } + + private static native boolean nativeInit(); + + private native void setProgressValue(long hwnd, int value); + + private native void setProgressState(long hwnd, int state); + + private native void setOverlayIcon(long hwnd, int[] badge, int width, int height); + + private native void flashWindow(long hWnd); + +}