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;
21:
22: import java.awt.Dimension;
23: import java.awt.Image;
24:
25: /**
26: * Provides factory for NativeCursor
27: */
28: public abstract class CursorFactory {
29: protected NativeCursor[] systemCursors = { null, null, null, null,
30: null, null, null, null, null, null, null, null, null, null, };
31:
32: /**
33: * Creates and returns NativeCursor for predefined
34: * Java Cursor
35: *
36: * @param type - type of predefined Java Cursor
37: * @return created cursor
38: */
39: public abstract NativeCursor createCursor(int type);
40:
41: /**
42: * Gets a cached instance of system(predefined) native cursor
43: * or creates a new one. This is a platform-independent method.
44: *
45: * @param type - type of predefined Java Cursor
46: * @return created cursor
47: */
48: public NativeCursor getCursor(int type) {
49: if (type >= 0 && type < systemCursors.length) {
50: NativeCursor cursor = systemCursors[type];
51: if (cursor == null) {
52: cursor = createCursor(type);
53: systemCursors[type] = cursor;
54: }
55: return cursor;
56: }
57: return null;
58: }
59:
60: /**
61: * Creates and returns custom NativeCursor from image
62: *
63: * @param img - image(source) to create cursor from
64: * @param xHotSpot - x coordinate of the hotspot relative to the source's origin
65: * @param yHotSpot - y coordinate of the hotspot relative to the source's origin
66: * @return created cursor
67: */
68: public abstract NativeCursor createCustomCursor(Image img,
69: int xHotSpot, int yHotSpot);
70:
71: /**
72: * Query native system for the best cursor size closest to specified dimensions
73: * @param prefWidth - preferred width
74: * @param prefHeight - preferred height
75: * @return closest supported dimensions to ones specified
76: */
77: public abstract Dimension getBestCursorSize(int prefWidth,
78: int prefHeight);
79:
80: /**
81: * @return maximum number of colors supported by custom cursors
82: */
83: public abstract int getMaximumCursorColors();
84: }
|