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 Dmitry A. Durnev
19: * @version $Revision$
20: */package org.apache.harmony.awt.wtk.linux;
21:
22: import org.apache.harmony.awt.wtk.NativeCursor;
23:
24: import org.apache.harmony.awt.nativebridge.linux.X11;
25:
26: /**
27: * Implementation of NativeCursor for Linux(X11) platform.
28: */
29: public class LinuxCursor implements NativeCursor {
30: private static X11 x11 = X11.getInstance();
31: private final long display;
32: private final long cursorId;
33: private boolean system;
34: private boolean valid = true; //cursor is valid if it has not been destroyed yet
35:
36: LinuxCursor(final long id, final boolean system, long display) {
37: cursorId = id;
38: this .system = system;
39: this .display = display;
40: }
41:
42: LinuxCursor(final long id, long display) {
43: this (id, true, display);
44: }
45:
46: /**
47: * @see org.apache.harmony.awt.wtk.NativeCursor#setCursor(long)
48: */
49: public void setCursor(long winID) {
50: if (valid) {
51: x11.XDefineCursor(display, winID, cursorId);
52: }
53: }
54:
55: /**
56: * Destroys any non-system(user-defined cursor)
57: * @see org.apache.harmony.awt.wtk.NativeCursor#destroyCursor()
58: */
59: public void destroyCursor() {
60: if (!system) {
61: destroy();
62: }
63: }
64:
65: /**
66: * Destroys any cursor
67: */
68: void destroy() {
69: if (valid) {
70: x11.XFreeCursor(display, cursorId);
71: valid = false;
72: }
73: }
74:
75: /**
76: * @see org.apache.harmony.awt.wtk.NativeCursor#getId()
77: */
78: public long getId() {
79: return cursorId;
80: }
81:
82: }
|