📄 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 可记阑 掺绰 规过篮 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 可记阑 掺绰 规过篮 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; // 酒贰狼 蔼篮 流立 郴 单胶农啪俊辑 SM阑 掘绢客辑 窍靛内爹窍看促. 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(); /* * 酒贰狼 内靛绰 sun荤狼 WFramePeer.java 家胶甫 曼炼窍咯 芭狼 弊措肺 * 荤侩窍看促. 龋券阑 困茄 咯矾啊瘤 内靛甫 力芭窍看绊, 己瓷氢惑阑 困茄 * 埃窜茄 内靛甫 眠啊窍看促. */ 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? 捞痢篮 唱肚茄 捞惑窍霸 积阿茄促. //牢埃利栏肺 关狼 内靛绰 窍唱档 捞秦且 荐 绝促 -.- 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甫 备窍绰 内靛绰 泅犁 力芭登菌促. 鞘夸窍促搁, * 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 );};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -