001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.replay;
025:
026: import jacareto.system.Environment;
027: import jacareto.system.EnvironmentMember;
028: import jacareto.toolkit.ResourceLoader;
029:
030: import java.awt.Cursor;
031: import java.awt.Image;
032: import java.awt.Point;
033:
034: import java.util.Hashtable;
035:
036: import javax.swing.ImageIcon;
037:
038: /**
039: * <p>
040: * Class which manages the cursor images for the pseudo mouse mode.
041: * </p>
042: *
043: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
044: * @version 1.01
045: */
046: public class CursorImages extends EnvironmentMember {
047: /** name of the default cursor. */
048: private static String defaultCursorName = Cursor
049: .getPredefinedCursor(Cursor.DEFAULT_CURSOR).getName();
050:
051: /** Maps cursor names to cursors. */
052: private Hashtable imageTable;
053:
054: /** Maps cursor names to hot spots. */
055: private Hashtable hotSpotTable;
056:
057: /** The directory with the default cursor images. */
058: private String cursorDir;
059:
060: /**
061: * Creates a new instance.
062: *
063: * @param env DOCUMENT ME!
064: * @param cursorDir the directory with the default cursor images
065: */
066: public CursorImages(Environment env, String cursorDir) {
067: super (env);
068: this .cursorDir = cursorDir;
069: imageTable = new Hashtable();
070: hotSpotTable = new Hashtable();
071: loadDefaultImages();
072: }
073:
074: /**
075: * Returns an image for the given cursor name, or the default image if the name is not known.
076: *
077: * @param cursorName DOCUMENT ME!
078: *
079: * @return DOCUMENT ME!
080: */
081: public Image getImage(String cursorName) {
082: if (imageTable.containsKey(cursorName)) {
083: return ((Image) imageTable.get(cursorName));
084: } else {
085: getLogger().debug(
086: getLanguage().getString(
087: "CursorImages.Msg.CursorNotKnown")
088: + " [" + cursorName + "]");
089:
090: return ((Image) imageTable.get(defaultCursorName));
091: }
092: }
093:
094: /**
095: * Returns an image for the given cursor, or the default image if the cursor is not known.
096: *
097: * @param cursor DOCUMENT ME!
098: *
099: * @return DOCUMENT ME!
100: */
101: public Image getImage(Cursor cursor) {
102: return getImage(cursor.getName());
103: }
104:
105: /**
106: * Returns the hot spot for the given cursor name, or the hot spot of the default cursor if the
107: * name is not known.
108: *
109: * @param cursorName DOCUMENT ME!
110: *
111: * @return DOCUMENT ME!
112: */
113: public Point getHotSpot(String cursorName) {
114: if (hotSpotTable.containsKey(cursorName)) {
115: return ((Point) hotSpotTable.get(cursorName));
116: } else {
117: return ((Point) hotSpotTable.get(defaultCursorName));
118: }
119: }
120:
121: /**
122: * Returns the hotspot of the given cursor, or the hot spot of the default cursor if the cursor
123: * is not known.
124: *
125: * @param cursor DOCUMENT ME!
126: *
127: * @return DOCUMENT ME!
128: */
129: public Point getHotSpot(Cursor cursor) {
130: return getHotSpot(cursor.getName());
131: }
132:
133: /**
134: * Loads the default cursor images.
135: */
136: private void loadDefaultImages() {
137: addCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)
138: .getName(), cursorDir + "/CROSSHAIR.gif", new Point(8,
139: 8));
140: addCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)
141: .getName(), cursorDir + "/DEFAULT.gif", new Point(0, 0));
142: addCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR)
143: .getName(), cursorDir + "/E_RESIZE.gif", new Point(10,
144: 4));
145: addCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)
146: .getName(), cursorDir + "/HAND.gif", new Point(5, 0));
147: addCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)
148: .getName(), cursorDir + "/MOVE.gif", new Point(10, 10));
149: addCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR)
150: .getName(), cursorDir + "/N_RESIZE.gif", new Point(4,
151: 10));
152: addCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR)
153: .getName(), cursorDir + "/NE_RESIZE.gif", new Point(7,
154: 7));
155: addCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR)
156: .getName(), cursorDir + "/NW_RESIZE.gif", new Point(7,
157: 7));
158: addCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR)
159: .getName(), cursorDir + "/S_RESIZE.gif", new Point(4,
160: 10));
161: addCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR)
162: .getName(), cursorDir + "/SE_RESIZE.gif", new Point(7,
163: 7));
164: addCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR)
165: .getName(), cursorDir + "/SW_RESIZE.gif", new Point(7,
166: 7));
167: addCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR)
168: .getName(), cursorDir + "/W_RESIZE.gif", new Point(10,
169: 4));
170: addCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)
171: .getName(), cursorDir + "/TEXT.gif", new Point(3, 7));
172: addCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)
173: .getName(), cursorDir + "/WAIT.gif", new Point(6, 11));
174: }
175:
176: /**
177: * Adds an image and a hot spot with a given cursor name.
178: *
179: * @param cursorName DOCUMENT ME!
180: * @param image DOCUMENT ME!
181: * @param hotSpot DOCUMENT ME!
182: */
183: public void addCursor(String cursorName, Image image, Point hotSpot) {
184: imageTable.put(cursorName, image);
185: hotSpotTable.put(cursorName, hotSpot);
186: }
187:
188: /**
189: * Adds an image given by the filename and a hot spot with a given cursor name.
190: *
191: * @param cursorName DOCUMENT ME!
192: * @param imageName DOCUMENT ME!
193: * @param hotSpot DOCUMENT ME!
194: */
195: public void addCursor(String cursorName, String imageName,
196: Point hotSpot) {
197: ImageIcon icon = null;
198: icon = ResourceLoader.getImageIcon(imageName);
199:
200: if (icon == null) {
201: icon = new ImageIcon(imageName);
202: }
203:
204: if (icon != null) {
205: addCursor(cursorName, icon.getImage(), hotSpot);
206: }
207: }
208: }
|