Source for gnu.gcj.xlib.Window

   1: /* Copyright (C) 2000  Free Software Foundation
   2: 
   3:    This file is part of libgcj.
   4: 
   5: This software is copyrighted work licensed under the terms of the
   6: Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
   7: details.  */
   8: 
   9: package gnu.gcj.xlib;
  10: 
  11: import gnu.gcj.RawData;
  12: import java.awt.Rectangle;
  13: 
  14: /**
  15:  * An X11 window.
  16:  *
  17:  * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
  18:  */
  19: public class Window extends Drawable
  20: {
  21:   // Must correspond with X.h definitions:
  22:   public static final int COPY_FROM_PARENT = 0;
  23:   public static final int INPUT_OUTPUT     = 1;
  24:   public static final int INPUT_ONLY       = 2;
  25: 
  26:   public Window(Window parent, Rectangle bounds,
  27:         WindowAttributes attributes)
  28:   {
  29:     this(parent, bounds, attributes, null);
  30:   }
  31:   
  32:   public Window(Window parent, Rectangle bounds,
  33:         WindowAttributes attributes, Visual visual)
  34:   {
  35:     this(parent, bounds, 0, attributes, COPY_FROM_PARENT, visual);
  36:   }
  37: 
  38:   public Window(Window parent, Rectangle bounds, int borderWidth,
  39:         WindowAttributes attributes, int windowIOClass,
  40:         Visual visual)
  41:   {
  42:     this(parent.display,
  43:      parent.createChildXID(bounds, borderWidth, attributes, 
  44:                    windowIOClass, visual));
  45:     this.owned = true;
  46:   }
  47: 
  48:   protected Window(Display display, int xid)
  49:   {
  50:     super(display, xid);
  51:     display.addXID(xid, this);
  52:   }
  53: 
  54:   protected void finalize()
  55:   {
  56:     display.removeXID(xid);
  57:     if (owned)
  58:       {
  59:     destroy();
  60:     owned = false;
  61:       }
  62:   }
  63: 
  64:   protected native void destroy();
  65: 
  66:   protected native int createChildXID(Rectangle bounds,
  67:                       int borderWidth,
  68:                       WindowAttributes attributes,
  69:                       int windowIOClass, 
  70:                       Visual visual);
  71: 
  72:   public native void setAttributes(WindowAttributes attributes);
  73: 
  74:   public native void map();
  75:   public native void unmap();
  76:   public native void toFront();
  77:   public native void toBack();
  78:   
  79:   protected boolean owned = false;
  80: 
  81:   public native void setProperty(int nameAtom, int typeAtom, byte[] data);
  82:   
  83:   public void setProperty(int nameAtom, int typeAtom, String data)
  84:   {
  85:     int length = data.length();
  86:     byte[] byteData = new byte[length];
  87:     
  88:     for (int i=0; i<length; i++)
  89:       byteData[i] = (byte) data.charAt(i);
  90: 
  91:     setProperty(nameAtom, typeAtom, byteData);
  92:   }
  93: 
  94:   public native void setWMProtocols(int[] atoms);
  95:   public native int[] getWMProtocols();
  96: 
  97:   public void setProperty(String nameAtom, String typeAtom, String data)
  98:   {
  99:     int xaName = display.getAtom(nameAtom);
 100:     int xaType = display.getAtom(typeAtom);
 101:     
 102:     setProperty(xaName, xaType, data);
 103:   }
 104: 
 105:   public native void setBounds(int x, int y, int width, int height);
 106: }