File: JideCursors.java

package info (click to toggle)
libjide-oss-java 3.7.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 13,264 kB
  • sloc: java: 89,463; xml: 268; makefile: 35
file content (342 lines) | stat: -rw-r--r-- 14,454 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*
 * @(#)JideCursors.java
 *
 * Copyright 2002 JIDE Software Inc. All rights reserved.
 */
package com.jidesoft.swing;

import com.jidesoft.plaf.UIDefaultsLookup;

import javax.swing.*;
import java.awt.*;

/**
 * A utility class that create additional cursors used by JIDE products.
 * <p/>
 * Notes: this class has to be public so that JIDE can use it in different packages, not meant to release to end user as
 * a public API. JIDE will not guarantee the class will remain as it is.
 */
public class JideCursors {

    /**
     * First id of Cursors used in JIDE products.
     */
    public static final int FIRST_CUSTOM_CURSOR = 20;

    /**
     * The horizontal split cursor type.
     */
    public static final int HSPLIT_CURSOR = 20;

    /**
     * The vertical split cursor type.
     */
    public static final int VSPLIT_CURSOR = 21;

    /**
     * The drag cursor type.
     */
    public static final int DRAG_CURSOR = 22;

    /**
     * The no-drop cursor type.
     */
    public static final int DRAG_STOP_CURSOR = 23;

    /**
     * The cursor point pointing to north side.
     */
    public static final int NORTH_CURSOR = 24;

    /**
     * The cursor point pointing to south side.
     */
    public static final int SOUTH_CURSOR = 25;

    /**
     * The cursor point pointing to east side.
     */
    public static final int EAST_CURSOR = 26;

    /**
     * The cursor point pointing to west side.
     */
    public static final int WEST_CURSOR = 27;

    /**
     * The cursor point pointing when dragged item will be in tabbed pane.
     */
    public static final int TAB_CURSOR = 28;

    /**
     * The cursor point when dragged item is floating.
     */
    public static final int FLOAT_CURSOR = 29;

    /**
     * The cursor point when dragged item will be inserted in between.
     */
    public static final int VERTICAL_CURSOR = 30;

    /**
     * The cursor point when dragged item will be inserted in between.
     */
    public static final int HORIZONTAL_CURSOR = 31;

    /**
     * The cursor point when dragged item will be inserted in between.
     */
    public static final int DELETE_CURSOR = 32;

    /**
     * The drag cursor type for text.
     */
    public static final int DRAG_TEXT_CURSOR = 33;

    /**
     * The no-drop cursor type for text.
     */
    public static final int DRAG_TEXT_STOP_CURSOR = 34;


    /**
     * The cursor for changing percentage.
     */
    public static final int PERCENTAGE_CURSOR = 35;

    /**
     * The cursor for moving toward east.
     */
    public static final int MOVE_EAST_CURSOR = 36;

    /**
     * The cursor for moving toward west.
     */
    public static final int MOVE_WEST_CURSOR = 37;

    /**
     * Last id of cursor used by JIDE products.
     */
    public static final int LAST_CUSTOM_CURSOR = 38;

    private static final Cursor[] predefined = new Cursor[LAST_CUSTOM_CURSOR - FIRST_CUSTOM_CURSOR + 1];

    static {
        for (int i = FIRST_CUSTOM_CURSOR; i < LAST_CUSTOM_CURSOR; i++)
            getPredefinedCursor(i);
    }

    /**
     * Returns a cursor object with the specified predefined type.
     *
     * @param type the type of predefined cursor
     * @throws IllegalArgumentException if the specified cursor type is invalid
     * @return the cursor associated with that type.
     */
    static public Cursor getPredefinedCursor(int type) {
        if (type < FIRST_CUSTOM_CURSOR || type > LAST_CUSTOM_CURSOR) {
            throw new IllegalArgumentException("illegal cursor type");
        }
        if (predefined[type - FIRST_CUSTOM_CURSOR] == null) {
            predefined[type - FIRST_CUSTOM_CURSOR] = createCursor(type);
        }
        return predefined[type - FIRST_CUSTOM_CURSOR];
    }

    /**
     * Sets a cursor object with the specified predefined type.
     *
     * @param type   the type of predefined cursor
     * @param cursor the cursor associated with that type
     * @throws IllegalArgumentException if the specified cursor type is invalid
     */
    public static void setPredefinedCursor(int type, Cursor cursor) {
        if (type < FIRST_CUSTOM_CURSOR || type > LAST_CUSTOM_CURSOR) {
            throw new IllegalArgumentException("illegal cursor type");
        }
        predefined[type - FIRST_CUSTOM_CURSOR] = cursor == null ? createCursor(type) : cursor;
    }

    /**
     * Creates a cursor specified by type.
     *
     * @param type cursor type
     * @return the cursor with that type
     */
    protected static Cursor createCursor(int type) {
        try {
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            Dimension bestSize = toolkit.getBestCursorSize(32, 32);
            int maxColor = toolkit.getMaximumCursorColors();
            switch (type) {
                case HSPLIT_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.hsplit");
                        if (icon == null)
                            return Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
                        return toolkit.createCustomCursor(icon.getImage(), new Point(15, 15), "Horizonal Split");
                    }
                    return Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
                }
                case VSPLIT_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.vsplit");
                        if (icon == null)
                            return Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR);
                        return toolkit.createCustomCursor(icon.getImage(), new Point(15, 15), "Vertical Split");
                    }
                    return Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR);
                }
                case DRAG_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.drag");
                        if (icon == null)
                            return Cursor.getDefaultCursor();
                        return toolkit.createCustomCursor(icon.getImage(), new Point(17, 12), "Drag");
                    }
                    return Cursor.getDefaultCursor();
                }
                case DRAG_STOP_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.dragStop");
                        if (icon == null)
                            return Cursor.getDefaultCursor();
                        return toolkit.createCustomCursor(icon.getImage(), new Point(17, 12), "Drag Stop");
                    }
                    return Cursor.getDefaultCursor();
                }
                case DRAG_TEXT_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.dragText");
                        if (icon == null)
                            return Cursor.getDefaultCursor();
                        return toolkit.createCustomCursor(icon.getImage(), new Point(0, 0), "Drag Text");
                    }
                    return Cursor.getDefaultCursor();
                }
                case DRAG_TEXT_STOP_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.dragTextStop");
                        if (icon == null)
                            return Cursor.getDefaultCursor();
                        return toolkit.createCustomCursor(icon.getImage(), new Point(15, 15), "Drag Text Stop");
                    }
                    return Cursor.getDefaultCursor();
                }
                case NORTH_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.north");
                        if (icon == null)
                            return Cursor.getDefaultCursor();
                        return toolkit.createCustomCursor(icon.getImage(), new Point(15, 10), "North");
                    }
                    return Cursor.getDefaultCursor();
                }
                case SOUTH_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.south");
                        if (icon == null)
                            return Cursor.getDefaultCursor();
                        return toolkit.createCustomCursor(icon.getImage(), new Point(15, 20), "South");
                    }
                    return Cursor.getDefaultCursor();
                }
                case EAST_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.east");
                        if (icon == null)
                            return Cursor.getDefaultCursor();
                        return toolkit.createCustomCursor(icon.getImage(), new Point(20, 15), "East");
                    }
                    return Cursor.getDefaultCursor();
                }
                case WEST_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.west");
                        if (icon == null)
                            return Cursor.getDefaultCursor();
                        return toolkit.createCustomCursor(icon.getImage(), new Point(10, 15), "West");
                    }
                    return Cursor.getDefaultCursor();
                }
                case TAB_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.tab");
                        if (icon == null)
                            return Cursor.getDefaultCursor();
                        return toolkit.createCustomCursor(icon.getImage(), new Point(15, 15), "Tabbed");
                    }
                    return Cursor.getDefaultCursor();
                }
                case FLOAT_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.float");
                        if (icon == null)
                            return Cursor.getDefaultCursor();
                        return toolkit.createCustomCursor(icon.getImage(), new Point(15, 15), "Floating");
                    }
                    return Cursor.getDefaultCursor();
                }
                case VERTICAL_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.vertical");
                        if (icon == null)
                            return Cursor.getDefaultCursor();
                        return toolkit.createCustomCursor(icon.getImage(), new Point(15, 15), "Vertical");
                    }
                    return Cursor.getDefaultCursor();
                }
                case HORIZONTAL_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.horizontal");
                        if (icon == null)
                            return Cursor.getDefaultCursor();
                        return toolkit.createCustomCursor(icon.getImage(), new Point(15, 15), "Horizontal");
                    }
                    return Cursor.getDefaultCursor();
                }
                case DELETE_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.delete");
                        if (icon == null)
                            return Cursor.getDefaultCursor();
                        return toolkit.createCustomCursor(icon.getImage(), new Point(10, 10), "Delete");
                    }
                    return Cursor.getDefaultCursor();
                }
                case PERCENTAGE_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.percentage");
                        if (icon == null)
                            return Cursor.getDefaultCursor();
                        return toolkit.createCustomCursor(icon.getImage(), new Point(20, 15), "Percentage");
                    }
                    return Cursor.getDefaultCursor();
                }
                case MOVE_EAST_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.moveEast");
                        if (icon == null)
                            return Cursor.getDefaultCursor();
                        return toolkit.createCustomCursor(icon.getImage(), new Point(11, 15), "Move East");
                    }
                    return Cursor.getDefaultCursor();
                }
                case MOVE_WEST_CURSOR: {
                    if (bestSize.width != 0 && maxColor > 3) {
                        ImageIcon icon = (ImageIcon) UIDefaultsLookup.getIcon("Cursor.moveWest");
                        if (icon == null)
                            return Cursor.getDefaultCursor();
                        return toolkit.createCustomCursor(icon.getImage(), new Point(20, 15), "Move West");
                    }
                    return Cursor.getDefaultCursor();
                }
            }
            return null;
        }
        catch (Exception e) {
            return Cursor.getDefaultCursor(); // mainly for HeadlessException.
        }
    }

}