📄 gtktoolkit.java
字号:
/* GtkToolkit.java -- Implements an AWT Toolkit using GTK for peers Copyright (C) 1998, 1999, 2002, 2003, 2004, 2005, 2006 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; } /** * Helper to return either a Image -- the argument -- or a * GtkImage with the errorLoading flag set if the argument is null. */ private Image imageOrError(Image b) { if (b == null) return GtkImage.getErrorImage(); else return b; } public Image createImage (String filename) { if (filename.length() == 0) return new GtkImage (); Image image; try { if (useGraphics2D()) image = GdkPixbufDecoder.createBufferedImage(filename); else image = new GtkImage(filename); } catch (IllegalArgumentException iae) { image = null; } return imageOrError(image); } public Image createImage (URL url) { Image image; try { if (useGraphics2D()) image = GdkPixbufDecoder.createBufferedImage(url); else image = new GtkImage(url); } catch (IllegalArgumentException iae) { image = null; } return imageOrError(image); } public Image createImage (ImageProducer producer) { Image image; try { if (useGraphics2D()) image = GdkPixbufDecoder.createBufferedImage(producer); else image = new GtkImage(producer); } catch (IllegalArgumentException iae) { image = null; } return imageOrError(image); } public Image createImage (byte[] imagedata, int imageoffset, int imagelength) { Image image; try { if (useGraphics2D()) image = GdkPixbufDecoder.createBufferedImage(imagedata, imageoffset, imagelength); else { byte[] datacopy = new byte[imagelength]; System.arraycopy(imagedata, imageoffset, datacopy, 0, imagelength); return new GtkImage(datacopy); } } catch (IllegalArgumentException iae) { image = null; } return imageOrError(image); } /** * 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 { int max_entries; public LRUCache(int max) { super(max, 0.75f, true); max_entries = max; } protected boolean removeEldestEntry(Map.Entry eldest) { return size() > max_entries; } } private LRUCache fontCache = new LRUCache(50); private LRUCache metricsCache = new LRUCache(50); private LRUCache imageCache = new LRUCache(50); public FontMetrics getFontMetrics (Font font) { synchronized (metricsCache) { if (metricsCache.containsKey(font)) return (FontMetrics) metricsCache.get(font); } FontMetrics m = new GdkFontMetrics (font); synchronized (metricsCache)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -