gtktoolkit.java
来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 671 行 · 第 1/2 页
JAVA
671 行
/* 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., 59 Temple Place, Suite 330, Boston, MA02111-1307 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.EmbeddedWindowSupport;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.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 implements EmbeddedWindowSupport{ Hashtable containers = new Hashtable(); static EventQueue q; static Clipboard systemClipboard; static boolean useGraphics2dSet; static boolean useGraphics2d; 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); } public GtkToolkit () { systemClipboard = new GtkClipboard (); } 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) { status = ((GtkImage) image).checkImage (); } 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 (useGraphics2D()) return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (filename)); else { GdkPixbufDecoder d = new GdkPixbufDecoder (filename); GtkImage image = new GtkImage (d, null); d.startProduction (image); return image; } } public Image createImage (URL url) { if (useGraphics2D()) return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (url)); else { GdkPixbufDecoder d = new GdkPixbufDecoder (url); GtkImage image = new GtkImage (d, null); d.startProduction (image); return image; } } public Image createImage (ImageProducer producer) { if (useGraphics2D()) return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (producer)); else { GtkImage image = new GtkImage (producer, null); producer.startProduction (image); return image; } } public Image createImage (byte[] imagedata, int imageoffset, int imagelength) { if (useGraphics2D()) return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (imagedata, imageoffset, imagelength)); else { GdkPixbufDecoder d = new GdkPixbufDecoder (imagedata, imageoffset, imagelength); GtkImage image = new GtkImage (d, null); d.startProduction (image); return 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); } public ColorModel getColorModel () { return ColorModel.getRGBdefault (); } 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; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?