001: /*
002: * @(#)JideCursors.java
003: *
004: * Copyright 2002 JIDE Software Inc. All rights reserved.
005: */
006: package com.jidesoft.swing;
007:
008: import com.jidesoft.plaf.UIDefaultsLookup;
009:
010: import javax.swing.*;
011: import java.awt.*;
012:
013: /**
014: * A utility class that create additional cursors used by JIDE products.
015: * <p/>
016: * Notes: this class has to be public so that JIDE can use it in different packages,
017: * not meant to release to end user as a public API. JIDE will not gurantee the class
018: * will remain as it is.
019: */
020: public class JideCursors {
021:
022: /**
023: * First id of Cursors used in JIDE products.
024: */
025: public static final int FIRST_CUSTOM_CURSOR = 20;
026:
027: /**
028: * The horizontal split cursor type.
029: */
030: public static final int HSPLIT_CURSOR = 20;
031:
032: /**
033: * The vertical split cursor type.
034: */
035: public static final int VSPLIT_CURSOR = 21;
036:
037: /**
038: * The drag cursor type.
039: */
040: public static final int DRAG_CURSOR = 22;
041:
042: /**
043: * The no-drop cursor type.
044: */
045: public static final int DRAG_STOP_CURSOR = 23;
046:
047: /**
048: * The cursor point pointing to north side.
049: */
050: public static final int NORTH_CURSOR = 24;
051:
052: /**
053: * The cursor point pointing to south side.
054: */
055: public static final int SOUTH_CURSOR = 25;
056:
057: /**
058: * The cursor point pointing to east side.
059: */
060: public static final int EAST_CURSOR = 26;
061:
062: /**
063: * The cursor point pointing to west side.
064: */
065: public static final int WEST_CURSOR = 27;
066:
067: /**
068: * The cursor point pointing when dragged item will be in tabbed pane.
069: */
070: public static final int TAB_CURSOR = 28;
071:
072: /**
073: * The cursor point when dragged item is floating.
074: */
075: public static final int FLOAT_CURSOR = 29;
076:
077: /**
078: * The cursor point when dragged item will be inserted in between.
079: */
080: public static final int VERTICAL_CURSOR = 30;
081:
082: /**
083: * The cursor point when dragged item will be inserted in between.
084: */
085: public static final int HORIZONTAL_CURSOR = 31;
086:
087: /**
088: * The cursor point when dragged item will be inserted in between.
089: */
090: public static final int DELETE_CURSOR = 32;
091:
092: /**
093: * The drag cursor type for text.
094: */
095: public static final int DRAG_TEXT_CURSOR = 33;
096:
097: /**
098: * The no-drop cursor type for text.
099: */
100: public static final int DRAG_TEXT_STOP_CURSOR = 34;
101:
102: /**
103: * Last id of cursor used by JIDE products.
104: */
105: public static final int LAST_CUSTOM_CURSOR = 35;
106:
107: private static final Cursor[] predefined = new Cursor[LAST_CUSTOM_CURSOR
108: - FIRST_CUSTOM_CURSOR + 1];
109:
110: static {
111: for (int i = FIRST_CUSTOM_CURSOR; i < LAST_CUSTOM_CURSOR; i++)
112: getPredefinedCursor(i);
113: }
114:
115: /**
116: * Returns a cursor object with the specified predefined type.
117: *
118: * @param type the type of predefined cursor
119: * @throws IllegalArgumentException if the specified cursor type is
120: * invalid
121: */
122: static public Cursor getPredefinedCursor(int type) {
123: if (type < FIRST_CUSTOM_CURSOR || type > LAST_CUSTOM_CURSOR) {
124: throw new IllegalArgumentException("illegal cursor type");
125: }
126: if (predefined[type - FIRST_CUSTOM_CURSOR] == null) {
127: predefined[type - FIRST_CUSTOM_CURSOR] = createCursor(type);
128: }
129: return predefined[type - FIRST_CUSTOM_CURSOR];
130: }
131:
132: /**
133: * Creates a cursor specified by type.
134: *
135: * @param type cursor type
136: * @return the cursor with that type
137: */
138: protected static Cursor createCursor(int type) {
139: Toolkit toolkit = Toolkit.getDefaultToolkit();
140: Dimension bestSize = toolkit.getBestCursorSize(32, 32);
141: int maxColor = toolkit.getMaximumCursorColors();
142: switch (type) {
143: case HSPLIT_CURSOR: {
144: if (bestSize.width != 0 && maxColor > 3) {
145: ImageIcon icon = (ImageIcon) UIDefaultsLookup
146: .getIcon("Cursor.hsplit");
147: if (icon == null)
148: return Cursor
149: .getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
150: return toolkit.createCustomCursor(icon.getImage(),
151: new Point(15, 15), "Horizonal Split");
152: }
153: return Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
154: }
155: case VSPLIT_CURSOR: {
156: if (bestSize.width != 0 && maxColor > 3) {
157: ImageIcon icon = (ImageIcon) UIDefaultsLookup
158: .getIcon("Cursor.vsplit");
159: if (icon == null)
160: return Cursor
161: .getPredefinedCursor(Cursor.S_RESIZE_CURSOR);
162: return toolkit.createCustomCursor(icon.getImage(),
163: new Point(15, 15), "Vertical Split");
164: }
165: return Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR);
166: }
167: case DRAG_CURSOR: {
168: if (bestSize.width != 0 && maxColor > 3) {
169: ImageIcon icon = (ImageIcon) UIDefaultsLookup
170: .getIcon("Cursor.drag");
171: if (icon == null)
172: return Cursor.getDefaultCursor();
173: return toolkit.createCustomCursor(icon.getImage(),
174: new Point(17, 12), "Drag");
175: }
176: return Cursor.getDefaultCursor();
177: }
178: case DRAG_STOP_CURSOR: {
179: if (bestSize.width != 0 && maxColor > 3) {
180: ImageIcon icon = (ImageIcon) UIDefaultsLookup
181: .getIcon("Cursor.dragStop");
182: if (icon == null)
183: return Cursor.getDefaultCursor();
184: return toolkit.createCustomCursor(icon.getImage(),
185: new Point(17, 12), "Drag Stop");
186: }
187: return Cursor.getDefaultCursor();
188: }
189: case DRAG_TEXT_CURSOR: {
190: if (bestSize.width != 0 && maxColor > 3) {
191: ImageIcon icon = (ImageIcon) UIDefaultsLookup
192: .getIcon("Cursor.dragText");
193: if (icon == null)
194: return Cursor.getDefaultCursor();
195: return toolkit.createCustomCursor(icon.getImage(),
196: new Point(0, 0), "Drag Text");
197: }
198: return Cursor.getDefaultCursor();
199: }
200: case DRAG_TEXT_STOP_CURSOR: {
201: if (bestSize.width != 0 && maxColor > 3) {
202: ImageIcon icon = (ImageIcon) UIDefaultsLookup
203: .getIcon("Cursor.dragTextStop");
204: if (icon == null)
205: return Cursor.getDefaultCursor();
206: return toolkit.createCustomCursor(icon.getImage(),
207: new Point(15, 15), "Drag Text Stop");
208: }
209: return Cursor.getDefaultCursor();
210: }
211: case NORTH_CURSOR: {
212: if (bestSize.width != 0 && maxColor > 3) {
213: ImageIcon icon = (ImageIcon) UIDefaultsLookup
214: .getIcon("Cursor.north");
215: if (icon == null)
216: return Cursor.getDefaultCursor();
217: return toolkit.createCustomCursor(icon.getImage(),
218: new Point(15, 10), "North");
219: }
220: return Cursor.getDefaultCursor();
221: }
222: case SOUTH_CURSOR: {
223: if (bestSize.width != 0 && maxColor > 3) {
224: ImageIcon icon = (ImageIcon) UIDefaultsLookup
225: .getIcon("Cursor.south");
226: if (icon == null)
227: return Cursor.getDefaultCursor();
228: return toolkit.createCustomCursor(icon.getImage(),
229: new Point(15, 20), "South");
230: }
231: return Cursor.getDefaultCursor();
232: }
233: case EAST_CURSOR: {
234: if (bestSize.width != 0 && maxColor > 3) {
235: ImageIcon icon = (ImageIcon) UIDefaultsLookup
236: .getIcon("Cursor.east");
237: if (icon == null)
238: return Cursor.getDefaultCursor();
239: return toolkit.createCustomCursor(icon.getImage(),
240: new Point(20, 15), "East");
241: }
242: return Cursor.getDefaultCursor();
243: }
244: case WEST_CURSOR: {
245: if (bestSize.width != 0 && maxColor > 3) {
246: ImageIcon icon = (ImageIcon) UIDefaultsLookup
247: .getIcon("Cursor.west");
248: if (icon == null)
249: return Cursor.getDefaultCursor();
250: return toolkit.createCustomCursor(icon.getImage(),
251: new Point(10, 15), "West");
252: }
253: return Cursor.getDefaultCursor();
254: }
255: case TAB_CURSOR: {
256: if (bestSize.width != 0 && maxColor > 3) {
257: ImageIcon icon = (ImageIcon) UIDefaultsLookup
258: .getIcon("Cursor.tab");
259: if (icon == null)
260: return Cursor.getDefaultCursor();
261: return toolkit.createCustomCursor(icon.getImage(),
262: new Point(15, 15), "Tabbed");
263: }
264: return Cursor.getDefaultCursor();
265: }
266: case FLOAT_CURSOR: {
267: if (bestSize.width != 0 && maxColor > 3) {
268: ImageIcon icon = (ImageIcon) UIDefaultsLookup
269: .getIcon("Cursor.float");
270: if (icon == null)
271: return Cursor.getDefaultCursor();
272: return toolkit.createCustomCursor(icon.getImage(),
273: new Point(15, 15), "Floating");
274: }
275: return Cursor.getDefaultCursor();
276: }
277: case VERTICAL_CURSOR: {
278: if (bestSize.width != 0 && maxColor > 3) {
279: ImageIcon icon = (ImageIcon) UIDefaultsLookup
280: .getIcon("Cursor.vertical");
281: if (icon == null)
282: return Cursor.getDefaultCursor();
283: return toolkit.createCustomCursor(icon.getImage(),
284: new Point(15, 15), "Vertical");
285: }
286: return Cursor.getDefaultCursor();
287: }
288: case HORIZONTAL_CURSOR: {
289: if (bestSize.width != 0 && maxColor > 3) {
290: ImageIcon icon = (ImageIcon) UIDefaultsLookup
291: .getIcon("Cursor.horizontal");
292: if (icon == null)
293: return Cursor.getDefaultCursor();
294: return toolkit.createCustomCursor(icon.getImage(),
295: new Point(15, 15), "Horizontal");
296: }
297: return Cursor.getDefaultCursor();
298: }
299: case DELETE_CURSOR: {
300: if (bestSize.width != 0 && maxColor > 3) {
301: ImageIcon icon = (ImageIcon) UIDefaultsLookup
302: .getIcon("Cursor.delete");
303: if (icon == null)
304: return Cursor.getDefaultCursor();
305: return toolkit.createCustomCursor(icon.getImage(),
306: new Point(10, 10), "Delete");
307: }
308: return Cursor.getDefaultCursor();
309: }
310: }
311: return null;
312: }
313:
314: }
|