Source for gnu.java.awt.peer.gtk.GdkGraphicsEnvironment

   1: /* GdkGraphicsEnvironment.java -- information about the graphics environment
   2:    Copyright (C) 2004, 2005, 2006  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package gnu.java.awt.peer.gtk;
  40: 
  41: import gnu.classpath.Configuration;
  42: import gnu.java.awt.ClasspathGraphicsEnvironment;
  43: 
  44: import java.awt.Font;
  45: import java.awt.Graphics2D;
  46: import java.awt.GraphicsDevice;
  47: import java.awt.GraphicsEnvironment;
  48: import java.awt.HeadlessException;
  49: import java.awt.image.BufferedImage;
  50: import java.awt.image.ColorModel;
  51: import java.awt.image.Raster;
  52: import java.awt.image.SampleModel;
  53: import java.awt.image.WritableRaster;
  54: import java.util.Locale;
  55: 
  56: import gnu.classpath.Pointer;
  57: 
  58: public class GdkGraphicsEnvironment extends ClasspathGraphicsEnvironment
  59: {
  60:   private final int native_state = GtkGenericPeer.getUniqueInteger ();
  61: 
  62:   private GdkScreenGraphicsDevice defaultDevice;
  63: 
  64:   private GdkScreenGraphicsDevice[] devices;
  65: 
  66:   /**
  67:    * The pointer to the native display resource.
  68:    *
  69:    * This field is manipulated by native code. Don't change or remove
  70:    * without adjusting the native code.
  71:    */
  72:   private Pointer display;
  73: 
  74:   static
  75:   {
  76:     if (true) // GCJ LOCAL
  77:       {
  78:         System.loadLibrary("gtkpeer");
  79:       }
  80: 
  81:     GtkToolkit.initializeGlobalIDs();
  82:     initIDs();
  83:   }
  84: 
  85:   private static native void initIDs();
  86: 
  87:   public GdkGraphicsEnvironment ()
  88:   {
  89:     nativeInitState();
  90:   }
  91: 
  92:   native void nativeInitState();
  93: 
  94:   public GraphicsDevice[] getScreenDevices ()
  95:   {
  96:     if (devices == null)
  97:       {
  98:         devices = nativeGetScreenDevices();
  99:       }
 100: 
 101:     return (GraphicsDevice[]) devices.clone();
 102:   }
 103: 
 104:   private native GdkScreenGraphicsDevice[] nativeGetScreenDevices();
 105: 
 106:   public GraphicsDevice getDefaultScreenDevice ()
 107:   {
 108:     if (GraphicsEnvironment.isHeadless ())
 109:       throw new HeadlessException ();
 110: 
 111:     synchronized (GdkGraphicsEnvironment.class)
 112:       {
 113:         if (defaultDevice == null)
 114:           {
 115:             defaultDevice = nativeGetDefaultScreenDevice();
 116:           }
 117:       }
 118: 
 119:     return defaultDevice;
 120:   }
 121: 
 122:   private native GdkScreenGraphicsDevice nativeGetDefaultScreenDevice();
 123: 
 124:   public Graphics2D createGraphics (BufferedImage image)
 125:   {
 126:     Raster raster = image.getRaster();
 127:     if(raster instanceof CairoSurface)
 128:       return ((CairoSurface)raster).getGraphics();
 129: 
 130:     return new BufferedImageGraphics( image );
 131:   }
 132: 
 133:   private native int nativeGetNumFontFamilies();
 134:   private native void nativeGetFontFamilies(String[] family_names);
 135: 
 136:   public Font[] getAllFonts ()
 137:   {
 138:     throw new java.lang.UnsupportedOperationException ();
 139:   }
 140: 
 141:   public String[] getAvailableFontFamilyNames ()
 142:   {
 143:     String[] family_names;
 144:     int array_size;
 145: 
 146:     array_size = nativeGetNumFontFamilies();
 147:     family_names = new String[array_size];
 148: 
 149:     nativeGetFontFamilies(family_names);
 150:     return family_names;
 151:   }
 152: 
 153:   public String[] getAvailableFontFamilyNames (Locale l)
 154:   {
 155:     throw new java.lang.UnsupportedOperationException ();
 156:   }
 157: 
 158:   /**
 159:    * Used by GtkMouseInfoPeer.
 160:    */
 161:   native int[] getMouseCoordinates();
 162:   native boolean isWindowUnderMouse(GtkWindowPeer windowPeer);
 163: 
 164:   public WritableRaster createRaster(ColorModel cm, SampleModel sm)
 165:   {
 166:     if (CairoSurface.isCompatibleSampleModel(sm)
 167:         && CairoSurface.isCompatibleColorModel(cm))
 168:       return new CairoSurface(sm.getWidth(), sm.getHeight());
 169:     else
 170:       return null;
 171:   }
 172: }