/[classpath]/classpath/java/awt/AWTKeyStroke.java
ViewVC logotype

Diff of /classpath/java/awt/AWTKeyStroke.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by mark, Sat Jul 31 16:39:15 2004 UTC revision 1.5.2.1 by gnu_andrew, Mon Jan 10 18:25:45 2005 UTC
# Line 1  Line 1 
1  /* AWTKeyStroke.java -- an immutable key stroke  /* AWTKeyStroke.java -- an immutable key stroke
2     Copyright (C) 2002 Free Software Foundation     Copyright (C) 2002, 2005 Free Software Foundation
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 63  import java.util.StringTokenizer; Line 63  import java.util.StringTokenizer;
63   * instances of a subclass, using reflection, provided the subclass has a   * instances of a subclass, using reflection, provided the subclass has a
64   * no-arg constructor (of any accessibility).   * no-arg constructor (of any accessibility).
65   *   *
66   * @author Eric Blake <ebb9@email.byu.edu>   * @author Eric Blake (ebb9@email.byu.edu)
67     * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
68   * @see #getAWTKeyStroke(char)   * @see #getAWTKeyStroke(char)
69   * @since 1.4   * @since 1.4
70   * @status updated to 1.4   * @status updated to 1.4
# Line 84  public class AWTKeyStroke implements Ser Line 85  public class AWTKeyStroke implements Ser
85     * under the assumption that garbage collection of a new keystroke is     * under the assumption that garbage collection of a new keystroke is
86     * easy when we find the old one that it matches in the cache.     * easy when we find the old one that it matches in the cache.
87     */     */
88    private static final LinkedHashMap cache = new LinkedHashMap(11, 0.75f, true)    private static final LinkedHashMap<AWTKeyStroke,AWTKeyStroke> cache =
89        new LinkedHashMap<AWTKeyStroke,AWTKeyStroke>(11, 0.75f, true)
90    {    {
91      /** The largest the keystroke cache can grow. */      /** The largest the keystroke cache can grow. */
92      private static final int MAX_CACHE_SIZE = 2048;      private static final int MAX_CACHE_SIZE = 2048;
93    
94      /** Prune stale entries. */      /** Prune stale entries. */
95      protected boolean removeEldestEntry(Map.Entry eldest)      protected boolean removeEldestEntry(Map.Entry<AWTKeyStroke,AWTKeyStroke>
96                                            eldest)
97      {   // XXX - FIXME Use Map.Entry, not just Entry  as gcj 3.1 workaround.      {   // XXX - FIXME Use Map.Entry, not just Entry  as gcj 3.1 workaround.
98        return size() > MAX_CACHE_SIZE;        return size() > MAX_CACHE_SIZE;
99      }      }
# Line 112  public class AWTKeyStroke implements Ser Line 115  public class AWTKeyStroke implements Ser
115     *     *
116     * @see #getAWTKeyStroke(String)     * @see #getAWTKeyStroke(String)
117     */     */
118    private static final HashMap vktable = new HashMap();    private static final HashMap<String,Object> vktable = new HashMap<String,Object>();
119    static    static
120    {    {
121      // Using reflection saves the hassle of keeping this in sync with KeyEvent,      // Using reflection saves the hassle of keeping this in sync with KeyEvent,
# Line 227  public class AWTKeyStroke implements Ser Line 230  public class AWTKeyStroke implements Ser
230     * @throws IllegalArgumentException subclass doesn't have no-arg constructor     * @throws IllegalArgumentException subclass doesn't have no-arg constructor
231     * @throws ClassCastException subclass doesn't extend AWTKeyStroke     * @throws ClassCastException subclass doesn't extend AWTKeyStroke
232     */     */
233    protected static void registerSubclass(final Class subclass)    protected static void registerSubclass(final Class<?> subclass)
234    {    {
235      if (subclass == null)      if (subclass == null)
236        throw new IllegalArgumentException();        throw new IllegalArgumentException();
# Line 250  public class AWTKeyStroke implements Ser Line 253  public class AWTKeyStroke implements Ser
253                  throws NoSuchMethodException, InstantiationException,                  throws NoSuchMethodException, InstantiationException,
254                         IllegalAccessException, InvocationTargetException                         IllegalAccessException, InvocationTargetException
255                {                {
256                  Constructor c = subclass.getDeclaredConstructor(null);                  Constructor<?> c =
257                      subclass.getDeclaredConstructor((Class<?>[])null);
258                  c.setAccessible(true);                  c.setAccessible(true);
259                  // Create a new instance, to make sure that we can, and                  // Create a new instance, to make sure that we can, and
260                  // to cause any ClassCastException.                  // to cause any ClassCastException.
# Line 576  public class AWTKeyStroke implements Ser Line 580  public class AWTKeyStroke implements Ser
580     */     */
581    protected Object readResolve() throws ObjectStreamException    protected Object readResolve() throws ObjectStreamException
582    {    {
583      AWTKeyStroke s = (AWTKeyStroke) cache.get(this);      AWTKeyStroke s = cache.get(this);
584      if (s != null)      if (s != null)
585        return s;        return s;
586      cache.put(this, this);      cache.put(this, this);

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.5.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26