?? win32toolkit.java
字號:
/** * @(#)Win32Toolkit.java * * Copyright (c) 2001, JangHo Hwang * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * 3. Neither the name of the JangHo Hwang nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $Id: Win32Toolkit.java,v 1.2 2002/03/18 20:29:26 xrath Exp $ */package rath.tools;import java.awt.Color;import java.awt.Component;import java.awt.Graphics;import java.awt.Image;import java.awt.Polygon;import java.awt.Window;import java.awt.event.*;import java.awt.image.BufferedImage;import java.awt.image.ColorModel;import java.awt.image.DataBuffer;import java.awt.image.DataBufferInt;import java.awt.image.SampleModel;import java.awt.image.Raster;import rath.NotSupportedPlatformException;import rath.tools.tray.TrayIcon;import rath.tools.tray.TrayEventListener;import rath.tools.tray.TrayIconManager;/** * win32俊輯 力傍登綽 犁固樂綽 扁瓷甸闌 葷儈且 薦 樂綽 檔備惑磊努貳膠撈促. * <p> * 措何盒 Windows 拌凱俊輯 悼累竅瘤父, 漂瀝 皋家靛甸籃 Windows 2000俊輯父 * 悼累且 巴撈促. * * @author Jangho Hwang, windrath@hanmail.net * @version $Id: Win32Toolkit.java,v 1.2 2002/03/18 20:29:26 xrath Exp $ since 2001/12/05 */public class Win32Toolkit{ private static boolean isLoaded = false; /** * Win32 toolkit 牢膠畔膠甫 積己茄促. */ public static synchronized Win32Toolkit getInstance() throws NotSupportedPlatformException { if( !isLoaded ) { String os = System.getProperty("os.name"); if( !os.startsWith("Windows") ) throw new NotSupportedPlatformException(os); System.loadLibrary( "rath_awt" ); isLoaded = true; } return new Win32Toolkit(); } private Win32Toolkit() { } /** * 林絹柳 哪器懲飄甫 八籃禍欄肺 舅頗喉坊爹竅絆 transparency狼 捧疙檔甫 啊瘤檔廢 函版茄促. * 撈 皋家靛綽 <b>Windows 2000</b>撈惑俊輯父 累悼且 巴撈促. <br> * 肚茄 格利 哪器懲飄啊 Swing老 版快 * DirectDraw 可記闌 波林絹具 茄促. ddraw 可記闌 摻綽 規(guī)過籃 jvm闌 startup且錠 券版函薦甫 * 林綽 巴欄肺 力絹且 薦 樂促. * <p> * java <b>-Dsun.java2d.noddraw=true</b> AppMain ... * * @param comp 捧疙竅霸 父甸絆磊 竅綽 哪器懲飄 * @param transparency 捧疙檔. 0撈擱 肯傈 捧疙撈絆, 255擱 肯傈 閡捧疙撈促. */ public void makeTransparency( Window comp, int transparency ) { makeTransparency( comp, Color.black, transparency ); } /** * 林絹柳 哪器懲飄甫 blendColor肺 舅頗喉坊爹竅絆 transparency狼 捧疙檔甫 啊瘤檔廢 函版茄促. * 撈 皋家靛綽 <b>Windows 2000</b>撈惑俊輯父 累悼且 巴撈促. * 肚茄 格利 哪器懲飄啊 Swing老 版快 * DirectDraw 可記闌 波林絹具 茄促. ddraw 可記闌 摻綽 規(guī)過籃 jvm闌 startup且錠 券版函薦甫 * 林綽 巴欄肺 力絹且 薦 樂促. * <p> * java <b>-Dsun.java2d.noddraw=true</b> AppMain ... * * @param comp 捧疙竅霸 父甸絆磊 竅綽 哪器懲飄 * @param blendColor 泅犁綽 葷儈登瘤 臼綽促. (OS俊輯綽 力傍茄促) * @param transparency 捧疙檔. 0撈擱 肯傈 捧疙撈絆, 255擱 肯傈 閡捧疙撈促. */ public void makeTransparency( Window comp, Color blendColor, int transparency ) { if( comp==null ) throw new IllegalArgumentException( "comp is null" ); if( blendColor==null ) blendColor = Color.black; if( transparency < -1 || transparency > 255 ) throw new IllegalArgumentException( "transparency must be between -1 and 255" ); makeTransparency0( comp, blendColor.getRed(), blendColor.getGreen(), blendColor.getBlue(), transparency ); } private native void makeTransparency0( Window comp, int r, int g, int b, int transparency ); /** * 林絹柳 window甫 Polygon 康開父 焊咯瘤絆 唱贛瘤 康開籃 捧疙竅霸 父甸絹滾赴促. * 茄付叼肺 富竅磊擱 芒闌 別綽促. */ public void makePolygonRegion( Window window, Polygon p ) { if( window==null ) throw new IllegalArgumentException( "window is null" ); if( p==null ) throw new IllegalArgumentException( "polygon is null" ); makePolygonRegion0( window, p, true ); } private native void makePolygonRegion0( Window window, Polygon p, boolean redraw ); public void makeTopMost( Window window, boolean enable ) { makeTopMost0( window, enable ); } private native void makeTopMost0( Window window, boolean enable ); /** * Java狼 Image甫 啊瘤絆 HICON 按眉甫 積己竅咯 弊 勤甸闌 逞敗霖促. * 酒撈能撈 歹撈惑 鞘夸啊 絕絹瘤擱 館靛矯 destroyIcon 皋家靛甫 烹秦輯 * 且寸等 府家膠甫 錢絹林絹具 茄促. * <p> * 父距 null闌 逞變促擱, 0L撈 館券登霸 瞪 巴撈促. */ public long createIconFromImage( Image icon ) { if( icon==null ) return 0L; // 酒貳狼 藹籃 流立 郴 單膠農(nóng)啪俊輯 SM闌 掘絹客輯 竅靛內(nèi)爹竅看促. int w = 16; // Default icon width use GetSystemMetrics( SM_CXICON ); int h = 16; // Default icon height use GetSystemMetrics( SM_CYICON ); BufferedImage bi = new BufferedImage( w, h, BufferedImage.TYPE_INT_ARGB ); Graphics g = bi.getGraphics(); g.drawImage( icon, 0, 0, w, h, null ); g.dispose(); Raster raster = bi.getRaster(); DataBuffer dataBuffer = raster.getDataBuffer(); /* * 酒貳狼 內(nèi)靛綽 sun葷狼 WFramePeer.java 家膠甫 曼煉竅咯 芭狼 弊措肺 * 葷儈竅看促. 齲券闌 困茄 咯礬啊瘤 內(nèi)靛甫 力芭竅看絆, 己瓷氫惑闌 困茄 * 埃竄茄 內(nèi)靛甫 眠啊竅看促. */ ColorModel alphaCheck = bi.getColorModel(); //Create icon mask for transparent icons //Color icon, so only creating AND mask, not XOR mask byte iconmask[] = new byte[((w * h) + 7 / 8)]; byte tempAND; int bufIdx = 0; int maskIdx = 0; boolean isTransparent = false; int bufferSize = dataBuffer.getSize(); for (bufIdx = 0, maskIdx = 0; bufIdx < bufferSize && maskIdx < iconmask.length; maskIdx++) { tempAND = 0; for (int bitIdx = 0; bitIdx < 8 && bufIdx < bufferSize; bitIdx++) { //This seems wrong - shouldn't it be masked if alpha //ISN'T 0? 撈痢籃 唱肚茄 撈惑竅霸 積阿茄促. //牢埃利欄肺 關(guān)狼 內(nèi)靛綽 竅唱檔 撈秦且 薦 絕促 -.- if (alphaCheck.getAlpha(dataBuffer.getElem(bufIdx++)) == 0) { isTransparent = true; tempAND |= (byte)0x1; } else tempAND &= (byte)0xFE; if (bitIdx < 7) tempAND = (byte)(tempAND << 1); } iconmask[maskIdx] = tempAND; } if (!isTransparent) iconmask = null; /* * Scansize甫 備竅綽 內(nèi)靛綽 泅犁 力芭登菌促. 鞘夸竅促擱, * BufferedImage.getSampleModel肺 SampleModel闌 掘絹柯 饒 * 撈巴闌 SinglePixelPackedSampleModel肺 cast竅咯 getScanlineStride 皋家靛甫 * 葷儈竅檔廢 竅扼. */ return createIconFromRaster0( ((DataBufferInt)dataBuffer).getData(), iconmask, raster.getWidth(), raster.getWidth(), raster.getHeight()); } /** * 林絹柳 單撈磐肺何磐 HICON闌 積己竅咯, 弊 勤甸狼 器牢磐甫 館券茄促. */ private native long createIconFromRaster0( int[] data, byte[] maskData, int ss, int width, int height ); /** * 酒撈能 勤甸闌 皋葛府俊輯 力芭茄促. */ public native void destroyIcon( long iconHandle );};
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -