001/* Copyright (C) 1999, 2000, 2002  Free Software Foundation
002
003This file is part of GNU Classpath.
004
005GNU Classpath is free software; you can redistribute it and/or modify
006it under the terms of the GNU General Public License as published by
007the Free Software Foundation; either version 2, or (at your option)
008any later version.
009
010GNU Classpath is distributed in the hope that it will be useful, but
011WITHOUT ANY WARRANTY; without even the implied warranty of
012MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013General Public License for more details.
014
015You should have received a copy of the GNU General Public License
016along with GNU Classpath; see the file COPYING.  If not, write to the
017Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01802110-1301 USA.
019
020Linking this library statically or dynamically with other modules is
021making a combined work based on this library.  Thus, the terms and
022conditions of the GNU General Public License cover the whole
023combination.
024
025As a special exception, the copyright holders of this library give you
026permission to link this library with independent modules to produce an
027executable, regardless of the license terms of these independent
028modules, and to copy and distribute the resulting executable under
029terms of your choice, provided that you also meet, for each linked
030independent module, the terms and conditions of the license of that
031module.  An independent module is a module which is not derived from
032or based on this library.  If you modify this library, you may extend
033this exception to your version of the library, but you are not
034obligated to do so.  If you do not wish to do so, delete this
035exception statement from your version. */
036
037
038package java.awt;
039
040/**
041  * This class represents various predefined cursor types.
042  *
043  * @author Aaron M. Renn (arenn@urbanophile.com)
044  */
045public class Cursor implements java.io.Serializable
046{
047  static final long serialVersionUID = 8028237497568985504L;
048
049  /**
050  * Constant for the system default cursor type
051  */
052  public static final int DEFAULT_CURSOR = 0;
053
054  /**
055  * Constant for a cross-hair cursor.
056  */
057  public static final int CROSSHAIR_CURSOR = 1;
058
059  /**
060  * Constant for a cursor over a text field.
061  */
062  public static final int TEXT_CURSOR = 2;
063
064  /**
065  * Constant for a cursor to display while waiting for an action to complete.
066  */
067  public static final int WAIT_CURSOR = 3;
068
069  /**
070  * Cursor used over SW corner of window decorations.
071  */
072  public static final int SW_RESIZE_CURSOR = 4;
073
074  /**
075  * Cursor used over SE corner of window decorations.
076  */
077  public static final int SE_RESIZE_CURSOR = 5;
078
079  /**
080  * Cursor used over NW corner of window decorations.
081  */
082  public static final int NW_RESIZE_CURSOR = 6;
083
084  /**
085  * Cursor used over NE corner of window decorations.
086  */
087  public static final int NE_RESIZE_CURSOR = 7;
088
089  /**
090  * Cursor used over N edge of window decorations.
091  */
092  public static final int N_RESIZE_CURSOR = 8;
093
094  /**
095  * Cursor used over S edge of window decorations.
096  */
097  public static final int S_RESIZE_CURSOR = 9;
098
099  /**
100  * Cursor used over W edge of window decorations.
101  */
102  public static final int W_RESIZE_CURSOR = 10;
103
104  /**
105  * Cursor used over E edge of window decorations.
106  */
107  public static final int E_RESIZE_CURSOR = 11;
108
109  /**
110  * Constant for a hand cursor.
111  */
112  public static final int HAND_CURSOR = 12;
113
114  /**
115  * Constant for a cursor used during window move operations.
116  */
117  public static final int MOVE_CURSOR = 13;
118
119  private static String[] NAMES = { "Default Cursor", "Crosshair Cursor",
120                                  "Text Cursor", "Wait Cursor",
121                                  "Southwest Resize Cursor",
122                                  "Southeast Resize Cursor",
123                                  "Northwest Resize Cursor",
124                                  "Northeast Resize Cursor",
125                                  "North Resize Cursor", "South Resize Cursor",
126                                  "West Resize Cursor", "East Resize Cursor",
127                                  "Hand Cursor", "Move Cursor" };
128
129  public static final int CUSTOM_CURSOR    = 0xFFFFFFFF;
130
131  private static final int PREDEFINED_COUNT = 14;
132
133  protected static Cursor[] predefined = new Cursor[PREDEFINED_COUNT];
134  protected String name;
135
136  /**
137   * @serial The numeric id of this cursor.
138   */
139  int type;
140
141  /**
142   * Initializes a new instance of <code>Cursor</code> with the specified
143   * type.
144   *
145   * @param type The cursor type.
146   *
147   * @exception IllegalArgumentException If the specified cursor type is invalid
148   */
149  public Cursor(int type)
150  {
151    if (type < 0 || type >= PREDEFINED_COUNT)
152      throw new IllegalArgumentException ("invalid cursor " + type);
153
154    this.type = type;
155
156    name = NAMES[type];
157
158    // FIXME: lookup?
159  }
160
161  /** This constructor is used internally only.
162   * Application code should call Toolkit.createCustomCursor().
163   */
164  protected Cursor(String name)
165  {
166    this.name = name;
167    this.type = CUSTOM_CURSOR;
168  }
169
170  /**
171   * Returns an instance of <code>Cursor</code> for one of the specified
172   * predetermined types.
173   *
174   * @param type The type contant from this class.
175   *
176   * @return The requested predefined cursor.
177   *
178   * @exception IllegalArgumentException If the constant is not one of the
179   * predefined cursor type constants from this class.
180   */
181  public static Cursor getPredefinedCursor(int type)
182  {
183    if (type < 0 || type >= PREDEFINED_COUNT)
184      throw new IllegalArgumentException ("invalid cursor " + type);
185    if (predefined[type] == null)
186      predefined[type] = new Cursor(type);
187    return predefined[type];
188  }
189
190  /**
191   * Retrieves the system specific custom Cursor named Cursor names are,
192   * for example: "Invalid.16x16".
193   *
194   * @exception AWTException
195   * @exception HeadlessException If GraphicsEnvironment.isHeadless()
196   * returns true.
197   */
198  public static Cursor getSystemCustomCursor(String name)
199                                      throws AWTException
200  {
201    if (GraphicsEnvironment.isHeadless())
202      throw new HeadlessException ();
203
204    // FIXME
205    return null;
206  }
207
208  /**
209   * Returns an instance of the system default cursor type.
210   *
211   * @return The system default cursor.
212   */
213  public static Cursor getDefaultCursor()
214  {
215    return getPredefinedCursor(DEFAULT_CURSOR);
216  }
217
218  /**
219   * Returns the numeric type identifier for this cursor.
220   *
221   * @return The cursor id.
222   */
223  public int getType()
224  {
225    return type;
226  }
227
228  public String getName()
229  {
230    return name;
231  }
232
233  public String toString()
234  {
235    return (this.getClass()
236            + "[type=" + getType()
237            + ",name=" + getName() + "]");
238  }
239}