01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Michael Danilov
19: * @version $Revision$
20: */package org.apache.harmony.awt.wtk.linux;
21:
22: import org.apache.harmony.awt.internal.nls.Messages;
23: import org.apache.harmony.awt.nativebridge.linux.X11;
24:
25: class XServerConnection {
26:
27: private long display;
28:
29: private int screen;
30:
31: private final X11 x11;
32:
33: private static XServerConnection instance = new XServerConnection();
34:
35: private XServerConnection() {
36: this .x11 = X11.getInstance();
37: ;
38: display = x11.XOpenDisplay(0); //0 - we use default display only
39: if (display == 0) {
40: String name = System.getProperty("DISPLAY"); //$NON-NLS-1$
41: // awt.0F=Cannot open display '{0}'
42: throw new InternalError(Messages.getString("awt.0F", //$NON-NLS-1$
43: (name != null ? name : ""))); //$NON-NLS-1$
44: }
45:
46: screen = x11.XDefaultScreen(display);
47:
48: System.loadLibrary("gl");
49: init(display, screen);
50: }
51:
52: public static XServerConnection getInstance() {
53: return instance;
54: }
55:
56: public void close() {
57: x11.XCloseDisplay(display);
58: }
59:
60: public long getDisplay() {
61: return display;
62: }
63:
64: public int getScreen() {
65: return screen;
66: }
67:
68: private native void init(long display, int screen);
69: }
|