1 /* Copyright (C) 1999, 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 java.util.Dictionary;
12 import java.util.Hashtable;
13 import java.util.Vector;
14 import java.util.Enumeration;
15 
16 import gnu.gcj.RawData;
17 
18 /**
19  * A connection to an X11 display.
20  *
21  * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
22  */
23 
24 public class Display
25 {
26   static
27   {
staticInit()28     staticInit();
29   }
30 
Display()31   public Display()
32   {
33     init();
34   }
35 
staticInit()36   private static native void staticInit();
init()37   private native void init();
finalize()38   protected native void finalize();
39 
40   RawData display = null;
41 
42   /* TODO?: Rather than storing such data here, we might consider
43      using the context manager facilities provided by Xlib... */
44   private Dictionary xids = new Hashtable();
45 
addXID(int xid, XID window)46   protected final void addXID(int xid, XID window)
47   {
48     xids.put(new Integer(xid), window);
49   }
50 
removeXID(int xid)51   protected final void removeXID(int xid)
52   {
53     xids.remove(new Integer(xid));
54   }
55 
getDefaultRootWindow()56   public final Window getDefaultRootWindow()
57   {
58     int rootXID = getDefaultRootWindowXID();
59     return getWindow(rootXID);
60   }
61 
getXID(int xid)62   public final XID getXID(int xid)
63   {
64     return (XID) xids.get(new Integer(xid));
65   }
66 
getWindow(int xid)67   public final Window getWindow(int xid)
68   {
69     Window window = (Window) getXID(xid);
70     if (window == null)
71       {
72 	window = new Window(this, xid);
73 	addXID(xid, window);
74       }
75     return window;
76   }
77 
getDefaultScreen()78   public final Screen getDefaultScreen()
79   {
80     /* Screens objects are not cached since they are lightweight.
81        We just create a new object when requested. */
82     return new Screen(this, getDefaultScreenNumber());
83   }
84 
getDefaultScreenNumber()85   public final native int getDefaultScreenNumber();
86 
getDefaultRootWindowXID()87   private final native int getDefaultRootWindowXID();
88 
89   private Dictionary atoms = new Hashtable();
90 
getAtom(String name)91   public final int getAtom(String name)
92   {
93     Integer atomInt = (Integer) atoms.get(name);
94     if (atomInt == null)
95       return internAtom(name);
96     return atomInt.intValue();
97   }
98 
99   // TODO?: cache reverse lookup too?
getAtomName(int atom)100   public final native String getAtomName(int atom);
101 
internAtom(String name)102   private final native int internAtom(String name);
103 
flush()104   public native void flush();
105 }
106