📄 gtktoolkit.java
字号:
/* GtkToolkit.java -- Implements an AWT Toolkit using GTK for peers Copyright (C) 1998, 1999, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package gnu.java.awt.peer.gtk;import gnu.classpath.Configuration;import gnu.java.awt.EmbeddedWindow;import gnu.java.awt.peer.ClasspathFontPeer;import gnu.java.awt.peer.ClasspathTextLayoutPeer;import gnu.java.awt.peer.EmbeddedWindowPeer;import java.awt.*;import java.awt.datatransfer.Clipboard;import java.awt.dnd.DragGestureEvent;import java.awt.dnd.peer.DragSourceContextPeer;import java.awt.font.FontRenderContext;import java.awt.im.InputMethodHighlight;import java.awt.image.BufferedImage;import java.awt.image.ColorModel;import java.awt.image.DirectColorModel;import java.awt.image.ImageConsumer;import java.awt.image.ImageObserver;import java.awt.image.ImageProducer;import java.awt.peer.*;import java.io.InputStream;import java.net.URL;import java.text.AttributedString;import java.util.HashMap;import java.util.HashSet;import java.util.Hashtable;import java.util.Iterator;import java.util.LinkedHashMap;import java.util.Map;import java.util.Properties;import javax.imageio.spi.IIORegistry;/* This class uses a deprecated method java.awt.peer.ComponentPeer.getPeer(). This merits comment. We are basically calling Sun's bluff on this one. We think Sun has deprecated it simply to discourage its use as it is bad programming style. However, we need to get at a component's peer in this class. If getPeer() ever goes away, we can implement a hash table that will keep up with every window's peer, but for now this is faster. *//** * This class accesses a system property called * <tt>gnu.java.awt.peer.gtk.Graphics</tt>. If the property is defined and * equal to "Graphics2D", the cairo-based GdkGraphics2D will be used in * drawing contexts. Any other value will cause the older GdkGraphics * object to be used. */public class GtkToolkit extends gnu.java.awt.ClasspathToolkit{ Hashtable containers = new Hashtable(); static EventQueue q; static boolean useGraphics2dSet; static boolean useGraphics2d; static Thread mainThread; public static boolean useGraphics2D() { if (useGraphics2dSet) return useGraphics2d; useGraphics2d = System.getProperty("gnu.java.awt.peer.gtk.Graphics", "Graphics").equals("Graphics2D"); useGraphics2dSet = true; return useGraphics2d; } static native void gtkInit(int portableNativeSync); static { if (Configuration.INIT_LOAD_LIBRARY) System.loadLibrary("gtkpeer"); int portableNativeSync; String portNatSyncProp = System.getProperty("gnu.classpath.awt.gtk.portable.native.sync"); if (portNatSyncProp == null) portableNativeSync = -1; // unset else if (Boolean.valueOf(portNatSyncProp).booleanValue()) portableNativeSync = 1; // true else portableNativeSync = 0; // false gtkInit(portableNativeSync); mainThread = new Thread ("GTK main thread") { public void run () { gtkMain (); } }; mainThread.start (); } public GtkToolkit () { } public native void beep(); private native void getScreenSizeDimensions(int[] xy); public int checkImage (Image image, int width, int height, ImageObserver observer) { int status = ImageObserver.ALLBITS | ImageObserver.WIDTH | ImageObserver.HEIGHT; if (image instanceof GtkImage) return ((GtkImage) image).checkImage (observer); if (observer != null) observer.imageUpdate (image, status, -1, -1, image.getWidth (observer), image.getHeight (observer)); return status; } /** * A helper class to return to clients in cases where a BufferedImage is * desired but its construction fails. */ private class GtkErrorImage extends Image { public GtkErrorImage() { } public int getWidth(ImageObserver observer) { return -1; } public int getHeight(ImageObserver observer) { return -1; } public ImageProducer getSource() { return new ImageProducer() { HashSet consumers = new HashSet(); public void addConsumer(ImageConsumer ic) { consumers.add(ic); } public boolean isConsumer(ImageConsumer ic) { return consumers.contains(ic); } public void removeConsumer(ImageConsumer ic) { consumers.remove(ic); } public void startProduction(ImageConsumer ic) { consumers.add(ic); Iterator i = consumers.iterator(); while(i.hasNext()) { ImageConsumer c = (ImageConsumer) i.next(); c.imageComplete(ImageConsumer.IMAGEERROR); } } public void requestTopDownLeftRightResend(ImageConsumer ic) { startProduction(ic); } }; } public Graphics getGraphics() { return null; } public Object getProperty(String name, ImageObserver observer) { return null; } public Image getScaledInstance(int width, int height, int flags) { return new GtkErrorImage(); } public void flush() { } } /** * Helper to return either a BufferedImage -- the argument -- or a * GtkErrorImage if the argument is null. */ private Image bufferedImageOrError(BufferedImage b) { if (b == null) return new GtkErrorImage(); else return b; } public Image createImage (String filename) { if (filename.length() == 0) return new GtkImage (); if (useGraphics2D()) return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (filename)); else return new GtkImage (filename); } public Image createImage (URL url) { if (useGraphics2D()) return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (url)); else return new GtkImage (url); } public Image createImage (ImageProducer producer) { if (useGraphics2D()) return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (producer)); else return new GtkImage (producer); } public Image createImage (byte[] imagedata, int imageoffset, int imagelength) { if (useGraphics2D()) return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (imagedata, imageoffset, imagelength)); else { byte[] datacopy = new byte[imagelength]; System.arraycopy (imagedata, imageoffset, datacopy, 0, imagelength); return new GtkImage (datacopy); } } /** * Creates an ImageProducer from the specified URL. The image is assumed * to be in a recognised format. * * @param url URL to read image data from. */ public ImageProducer createImageProducer(URL url) { return new GdkPixbufDecoder(url); } /** * Returns the native color model (which isn't the same as the default * ARGB color model, but doesn't have to be). */ public ColorModel getColorModel () { /* Return the GDK-native ABGR format */ return new DirectColorModel(32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000); } public String[] getFontList () { return (new String[] { "Dialog", "DialogInput", "Monospaced", "Serif", "SansSerif" }); } private class LRUCache extends LinkedHashMap {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -