1 /* 2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.webkit; 27 28 import java.util.HashMap; 29 import java.util.Map; 30 31 import com.sun.webkit.graphics.WCImage; 32 import com.sun.webkit.graphics.WCImageFrame; 33 34 public abstract class CursorManager<T> { 35 36 public static final int POINTER = 0; 37 public static final int CROSS = 1; 38 public static final int HAND = 2; 39 public static final int MOVE = 3; 40 public static final int TEXT = 4; 41 public static final int WAIT = 5; 42 public static final int HELP = 6; 43 public static final int EAST_RESIZE = 7; 44 public static final int NORTH_RESIZE = 8; 45 public static final int NORTH_EAST_RESIZE = 9; 46 public static final int NORTH_WEST_RESIZE = 10; 47 public static final int SOUTH_RESIZE = 11; 48 public static final int SOUTH_EAST_RESIZE = 12; 49 public static final int SOUTH_WEST_RESIZE = 13; 50 public static final int WEST_RESIZE = 14; 51 public static final int NORTH_SOUTH_RESIZE = 15; 52 public static final int EAST_WEST_RESIZE = 16; 53 public static final int NORTH_EAST_SOUTH_WEST_RESIZE = 17; 54 public static final int NORTH_WEST_SOUTH_EAST_RESIZE = 18; 55 public static final int COLUMN_RESIZE = 19; 56 public static final int ROW_RESIZE = 20; 57 public static final int MIDDLE_PANNING = 21; 58 public static final int EAST_PANNING = 22; 59 public static final int NORTH_PANNING = 23; 60 public static final int NORTH_EAST_PANNING = 24; 61 public static final int NORTH_WEST_PANNING = 25; 62 public static final int SOUTH_PANNING = 26; 63 public static final int SOUTH_EAST_PANNING = 27; 64 public static final int SOUTH_WEST_PANNING = 28; 65 public static final int WEST_PANNING = 29; 66 public static final int VERTICAL_TEXT = 30; 67 public static final int CELL = 31; 68 public static final int CONTEXT_MENU = 32; 69 public static final int NO_DROP = 33; 70 public static final int NOT_ALLOWED = 34; 71 public static final int PROGRESS = 35; 72 public static final int ALIAS = 36; 73 public static final int ZOOM_IN = 37; 74 public static final int ZOOM_OUT = 38; 75 public static final int COPY = 39; 76 public static final int NONE = 40; 77 public static final int GRAB = 41; 78 public static final int GRABBING = 42; 79 80 private static CursorManager instance; 81 82 public static void setCursorManager(CursorManager manager) { 83 instance = manager; 84 } 85 86 public static CursorManager getCursorManager() { 87 return instance; 88 } 89 90 private final Map<Long, T> map = new HashMap<Long, T>(); 91 92 protected abstract T getCustomCursor(WCImage image, int hotspotX, int hotspotY); 93 94 protected abstract T getPredefinedCursor(int type); 95 96 private long getCustomCursorID(WCImageFrame frame, int hotspotX, int hotspotY) { 97 return putCursor(getCustomCursor(frame.getFrame(), hotspotX, hotspotY)); 98 } 99 100 private long getPredefinedCursorID(int type) { 101 return putCursor(getPredefinedCursor(type)); 102 } 103 104 public final T getCursor(long id) { 105 return this.map.get(id); 106 } 107 108 private long putCursor(T cursor) { 109 long id = cursor.hashCode(); 110 this.map.put(id, cursor); 111 return id; 112 } 113 }