From 8aa540d2f783474d1d2e06f16744bf67b9c1facc Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 10 Mar 2006 21:46:48 +0000 Subject: Imported GNU Classpath 0.90 Imported GNU Classpath 0.90 * scripts/makemake.tcl: Set gnu/java/awt/peer/swing to ignore. * gnu/classpath/jdwp/VMFrame.java (SIZE): New constant. * java/lang/VMCompiler.java: Use gnu.java.security.hash.MD5. * java/lang/Math.java: New override file. * java/lang/Character.java: Merged from Classpath. (start, end): Now 'int's. (canonicalName): New field. (CANONICAL_NAME, NO_SPACES_NAME, CONSTANT_NAME): New constants. (UnicodeBlock): Added argument. (of): New overload. (forName): New method. Updated unicode blocks. (sets): Updated. * sources.am: Regenerated. * Makefile.in: Likewise. From-SVN: r111942 --- libjava/classpath/java/awt/AWTEvent.java | 103 + libjava/classpath/java/awt/BasicStroke.java | 177 +- libjava/classpath/java/awt/BorderLayout.java | 123 +- libjava/classpath/java/awt/CardLayout.java | 26 +- libjava/classpath/java/awt/Checkbox.java | 27 +- libjava/classpath/java/awt/Choice.java | 25 +- libjava/classpath/java/awt/Component.java | 265 +- libjava/classpath/java/awt/Container.java | 435 +--- libjava/classpath/java/awt/Cursor.java | 4 +- libjava/classpath/java/awt/Frame.java | 698 ++--- libjava/classpath/java/awt/Insets.java | 20 + .../classpath/java/awt/LightweightDispatcher.java | 200 ++ libjava/classpath/java/awt/Menu.java | 59 +- libjava/classpath/java/awt/MenuBar.java | 575 ++--- libjava/classpath/java/awt/MenuComponent.java | 2028 +++++++-------- libjava/classpath/java/awt/Scrollbar.java | 30 +- libjava/classpath/java/awt/TextField.java | 1 + libjava/classpath/java/awt/Toolkit.java | 226 +- libjava/classpath/java/awt/Window.java | 81 +- .../java/awt/datatransfer/DataFlavor.java | 50 +- libjava/classpath/java/awt/dnd/DragSource.java | 25 +- libjava/classpath/java/awt/doc-files/capjoin.png | Bin 0 -> 5325 bytes .../java/awt/event/AWTEventListenerProxy.java | 68 +- libjava/classpath/java/awt/peer/ComponentPeer.java | 284 +- libjava/classpath/java/awt/print/NoPrinterJob.java | 124 + libjava/classpath/java/awt/print/PageFormat.java | 437 ++-- libjava/classpath/java/awt/print/Pageable.java | 119 +- libjava/classpath/java/awt/print/Paper.java | 345 ++- .../classpath/java/awt/print/PrinterGraphics.java | 35 +- libjava/classpath/java/awt/print/PrinterJob.java | 4 +- .../java/beans/DefaultPersistenceDelegate.java | 17 + libjava/classpath/java/beans/Encoder.java | 45 +- .../classpath/java/beans/PersistenceDelegate.java | 5 +- .../java/beans/PropertyChangeSupport.java | 25 +- .../classpath/java/beans/PropertyDescriptor.java | 67 + libjava/classpath/java/beans/XMLDecoder.java | 6 +- libjava/classpath/java/beans/XMLEncoder.java | 2 + libjava/classpath/java/io/InputStream.java | 4 +- libjava/classpath/java/io/InputStreamReader.java | 20 +- libjava/classpath/java/io/ObjectInputStream.java | 19 +- libjava/classpath/java/io/ObjectOutputStream.java | 4 +- libjava/classpath/java/lang/Character.java | 2705 +++++++++++++++++--- .../java/lang/ClassNotFoundException.java | 5 +- libjava/classpath/java/lang/Math.java | 351 ++- libjava/classpath/java/lang/String.java | 70 +- libjava/classpath/java/lang/StringBuilder.java | 61 + libjava/classpath/java/lang/System.java | 17 + libjava/classpath/java/lang/Thread.java | 2 +- libjava/classpath/java/lang/reflect/Proxy.java | 44 +- libjava/classpath/java/math/BigDecimal.java | 17 +- libjava/classpath/java/math/BigInteger.java | 22 +- libjava/classpath/java/net/InetAddress.java | 4 +- libjava/classpath/java/net/SocketPermission.java | 384 +-- libjava/classpath/java/net/URI.java | 13 +- libjava/classpath/java/net/URL.java | 73 +- libjava/classpath/java/net/URLClassLoader.java | 48 +- libjava/classpath/java/net/URLConnection.java | 5 +- .../java/nio/BufferOverflowException.java | 2 + .../java/nio/BufferUnderflowException.java | 2 + .../classpath/java/nio/InvalidMarkException.java | 2 + .../java/nio/ReadOnlyBufferException.java | 2 + .../nio/channels/AlreadyConnectedException.java | 2 + .../nio/channels/AsynchronousCloseException.java | 2 + .../java/nio/channels/CancelledKeyException.java | 2 + libjava/classpath/java/nio/channels/Channels.java | 1 + .../nio/channels/ClosedByInterruptException.java | 2 + .../java/nio/channels/ClosedChannelException.java | 2 + .../java/nio/channels/ClosedSelectorException.java | 2 + .../nio/channels/ConnectionPendingException.java | 2 + .../java/nio/channels/DatagramChannel.java | 2 - .../classpath/java/nio/channels/FileChannel.java | 8 +- .../channels/FileLockInterruptionException.java | 2 + .../nio/channels/IllegalBlockingModeException.java | 2 + .../nio/channels/IllegalSelectorException.java | 2 + .../nio/channels/NoConnectionPendingException.java | 2 + .../nio/channels/NonReadableChannelException.java | 2 + .../nio/channels/NonWritableChannelException.java | 2 + .../java/nio/channels/NotYetBoundException.java | 2 + .../nio/channels/NotYetConnectedException.java | 2 + .../nio/channels/OverlappingFileLockException.java | 2 + .../nio/channels/UnresolvedAddressException.java | 2 + .../channels/UnsupportedAddressTypeException.java | 2 + .../channels/spi/AbstractInterruptibleChannel.java | 2 +- .../java/nio/charset/CharacterCodingException.java | 2 + .../java/nio/charset/CoderMalfunctionError.java | 2 + .../java/nio/charset/MalformedInputException.java | 2 + .../nio/charset/UnmappableCharacterException.java | 2 + libjava/classpath/java/rmi/AccessException.java | 5 +- .../classpath/java/rmi/AlreadyBoundException.java | 7 +- libjava/classpath/java/rmi/MarshalledObject.java | 103 +- libjava/classpath/java/rmi/Naming.java | 226 +- .../classpath/java/rmi/NoSuchObjectException.java | 9 +- libjava/classpath/java/rmi/NotBoundException.java | 11 +- .../classpath/java/rmi/RMISecurityException.java | 14 +- libjava/classpath/java/rmi/Remote.java | 19 +- libjava/classpath/java/rmi/RemoteException.java | 5 +- .../classpath/java/rmi/StubNotFoundException.java | 7 +- libjava/classpath/java/rmi/dgc/DGC.java | 39 +- libjava/classpath/java/rmi/dgc/Lease.java | 69 +- libjava/classpath/java/rmi/package.html | 2 +- libjava/classpath/java/rmi/registry/Registry.java | 24 +- .../classpath/java/rmi/server/RMIClassLoader.java | 30 +- .../rmi/server/RemoteObjectInvocationHandler.java | 221 ++ libjava/classpath/java/rmi/server/RemoteRef.java | 64 +- libjava/classpath/java/rmi/server/RemoteStub.java | 23 +- .../java/rmi/server/UnicastRemoteObject.java | 213 +- .../java/security/AlgorithmParameterGenerator.java | 197 +- .../java/security/AlgorithmParameters.java | 250 +- .../classpath/java/security/DigestException.java | 24 +- .../java/security/GeneralSecurityException.java | 24 +- libjava/classpath/java/security/Identity.java | 263 +- libjava/classpath/java/security/IdentityScope.java | 168 +- .../InvalidAlgorithmParameterException.java | 24 +- .../java/security/InvalidKeyException.java | 24 +- libjava/classpath/java/security/KeyException.java | 24 +- libjava/classpath/java/security/KeyFactory.java | 204 +- .../java/security/KeyManagementException.java | 24 +- .../classpath/java/security/KeyPairGenerator.java | 294 +-- .../classpath/java/security/KeyStoreException.java | 24 +- libjava/classpath/java/security/MessageDigest.java | 257 +- .../java/security/NoSuchAlgorithmException.java | 24 +- libjava/classpath/java/security/Policy.java | 175 +- .../classpath/java/security/ProtectionDomain.java | 137 +- .../classpath/java/security/ProviderException.java | 24 +- libjava/classpath/java/security/SecureRandom.java | 3 +- libjava/classpath/java/security/Security.java | 394 ++- libjava/classpath/java/security/Signature.java | 527 ++-- .../java/security/SignatureException.java | 24 +- libjava/classpath/java/security/SignatureSpi.java | 290 +-- libjava/classpath/java/security/SignedObject.java | 177 +- libjava/classpath/java/security/Signer.java | 92 +- .../classpath/java/security/cert/CRLException.java | 26 +- .../cert/CertificateEncodingException.java | 26 +- .../java/security/cert/CertificateException.java | 26 +- .../security/cert/CertificateParsingException.java | 26 +- .../interfaces/RSAMultiPrimePrivateCrtKey.java | 27 +- .../security/spec/InvalidKeySpecException.java | 26 +- .../java/security/spec/PSSParameterSpec.java | 25 +- .../spec/RSAMultiPrimePrivateCrtKeySpec.java | 78 +- .../java/security/spec/RSAOtherPrimeInfo.java | 35 +- .../classpath/java/util/AbstractCollection.java | 16 +- libjava/classpath/java/util/ResourceBundle.java | 6 +- libjava/classpath/java/util/jar/Attributes.java | 5 +- .../classpath/java/util/logging/FileHandler.java | 2 +- .../classpath/java/util/logging/LogManager.java | 53 +- .../java/util/logging/SimpleFormatter.java | 10 + .../java/util/prefs/AbstractPreferences.java | 184 +- .../classpath/java/util/prefs/NodeChangeEvent.java | 22 +- .../java/util/prefs/PreferenceChangeEvent.java | 22 +- libjava/classpath/java/util/prefs/Preferences.java | 36 +- libjava/classpath/java/util/regex/MatchResult.java | 81 + libjava/classpath/java/util/regex/Matcher.java | 25 +- .../java/util/regex/PatternSyntaxException.java | 1 + libjava/classpath/java/util/zip/ZipConstants.java | 10 +- libjava/classpath/java/util/zip/ZipFile.java | 397 +-- .../classpath/java/util/zip/ZipOutputStream.java | 12 +- 156 files changed, 10426 insertions(+), 6204 deletions(-) create mode 100644 libjava/classpath/java/awt/LightweightDispatcher.java create mode 100644 libjava/classpath/java/awt/doc-files/capjoin.png create mode 100644 libjava/classpath/java/awt/print/NoPrinterJob.java create mode 100644 libjava/classpath/java/rmi/server/RemoteObjectInvocationHandler.java create mode 100644 libjava/classpath/java/util/regex/MatchResult.java (limited to 'libjava/classpath/java') diff --git a/libjava/classpath/java/awt/AWTEvent.java b/libjava/classpath/java/awt/AWTEvent.java index ad9533f..d10433c 100644 --- a/libjava/classpath/java/awt/AWTEvent.java +++ b/libjava/classpath/java/awt/AWTEvent.java @@ -39,6 +39,19 @@ exception statement from your version. */ package java.awt; +import java.awt.event.ActionEvent; +import java.awt.event.AdjustmentEvent; +import java.awt.event.ComponentEvent; +import java.awt.event.ContainerEvent; +import java.awt.event.FocusEvent; +import java.awt.event.InputMethodEvent; +import java.awt.event.InvocationEvent; +import java.awt.event.ItemEvent; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.awt.event.PaintEvent; +import java.awt.event.TextEvent; +import java.awt.event.WindowEvent; import java.util.EventObject; /** @@ -275,4 +288,94 @@ public abstract class AWTEvent extends EventObject { return consumed; } + + /** + * Converts an event id to the appropriate event mask. + * + * @param id the event id + * + * @return the event mask for the specified id + */ + static long eventIdToMask(int id) + { + long mask = 0; + switch (id) + { + case ActionEvent.ACTION_PERFORMED: + mask = ACTION_EVENT_MASK; + break; + case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED: + mask = ADJUSTMENT_EVENT_MASK; + break; + case ComponentEvent.COMPONENT_MOVED: + case ComponentEvent.COMPONENT_RESIZED: + case ComponentEvent.COMPONENT_SHOWN: + case ComponentEvent.COMPONENT_HIDDEN: + mask = COMPONENT_EVENT_MASK; + break; + case ContainerEvent.COMPONENT_ADDED: + case ContainerEvent.COMPONENT_REMOVED: + mask = CONTAINER_EVENT_MASK; + break; + case FocusEvent.FOCUS_GAINED: + case FocusEvent.FOCUS_LOST: + mask = FOCUS_EVENT_MASK; + break; + case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED: + case InputMethodEvent.CARET_POSITION_CHANGED: + mask = INPUT_METHOD_EVENT_MASK; + break; + case InvocationEvent.INVOCATION_DEFAULT: + mask = INVOCATION_EVENT_MASK; + break; + case ItemEvent.ITEM_STATE_CHANGED: + mask = ITEM_EVENT_MASK; + break; + case KeyEvent.KEY_TYPED: + case KeyEvent.KEY_PRESSED: + case KeyEvent.KEY_RELEASED: + mask = KEY_EVENT_MASK; + break; + case MouseEvent.MOUSE_CLICKED: + case MouseEvent.MOUSE_PRESSED: + case MouseEvent.MOUSE_RELEASED: + mask = MOUSE_EVENT_MASK; + break; + case MouseEvent.MOUSE_MOVED: + case MouseEvent.MOUSE_ENTERED: + case MouseEvent.MOUSE_EXITED: + case MouseEvent.MOUSE_DRAGGED: + mask = MOUSE_MOTION_EVENT_MASK; + break; + case MouseEvent.MOUSE_WHEEL: + mask = MOUSE_WHEEL_EVENT_MASK; + break; + case PaintEvent.PAINT: + case PaintEvent.UPDATE: + mask = PAINT_EVENT_MASK; + break; + case TextEvent.TEXT_VALUE_CHANGED: + mask = TEXT_EVENT_MASK; + break; + case WindowEvent.WINDOW_OPENED: + case WindowEvent.WINDOW_CLOSING: + case WindowEvent.WINDOW_CLOSED: + case WindowEvent.WINDOW_ICONIFIED: + case WindowEvent.WINDOW_DEICONIFIED: + case WindowEvent.WINDOW_ACTIVATED: + case WindowEvent.WINDOW_DEACTIVATED: + mask = WINDOW_EVENT_MASK; + break; + case WindowEvent.WINDOW_GAINED_FOCUS: + case WindowEvent.WINDOW_LOST_FOCUS: + mask = WINDOW_FOCUS_EVENT_MASK; + break; + case WindowEvent.WINDOW_STATE_CHANGED: + mask = WINDOW_STATE_EVENT_MASK; + break; + default: + mask = 0; + } + return mask; + } } // class AWTEvent diff --git a/libjava/classpath/java/awt/BasicStroke.java b/libjava/classpath/java/awt/BasicStroke.java index bb008e4..4eece75 100644 --- a/libjava/classpath/java/awt/BasicStroke.java +++ b/libjava/classpath/java/awt/BasicStroke.java @@ -1,5 +1,5 @@ /* BasicStroke.java -- - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -41,38 +41,89 @@ package java.awt; import java.util.Arrays; /** - * STUB CLASS ONLY + * A general purpose {@link Stroke} implementation that can represent a wide + * variety of line styles for use with subclasses of {@link Graphics2D}. + *

+ * The line cap and join styles can be set using the options illustrated + * here: + *

+ * Illustration of line cap and join styles + *

+ * A dash array can be used to specify lines with alternating opaque and + * transparent sections. */ public class BasicStroke implements Stroke { + /** + * Indicates a mitered line join style. See the class overview for an + * illustration. + */ public static final int JOIN_MITER = 0; + + /** + * Indicates a rounded line join style. See the class overview for an + * illustration. + */ public static final int JOIN_ROUND = 1; + + /** + * Indicates a bevelled line join style. See the class overview for an + * illustration. + */ public static final int JOIN_BEVEL = 2; + /** + * Indicates a flat line cap style. See the class overview for an + * illustration. + */ public static final int CAP_BUTT = 0; + + /** + * Indicates a rounded line cap style. See the class overview for an + * illustration. + */ public static final int CAP_ROUND = 1; + + /** + * Indicates a square line cap style. See the class overview for an + * illustration. + */ public static final int CAP_SQUARE = 2; + /** The stroke width. */ private final float width; + + /** The line cap style. */ private final int cap; + + /** The line join style. */ private final int join; + + /** The miter limit. */ private final float limit; + + /** The dash array. */ private final float[] dash; + + /** The dash phase. */ private final float phase; /** - * Creates a basic stroke. + * Creates a new BasicStroke instance with the given attributes. * - * @param width May not be negative . - * @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE. - * @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER. - * @param miterlimit the limit to trim the miter join. The miterlimit must be + * @param width the line width (>= 0.0f). + * @param cap the line cap style (one of {@link #CAP_BUTT}, + * {@link #CAP_ROUND} or {@link #CAP_SQUARE}). + * @param join the line join style (one of {@link #JOIN_ROUND}, + * {@link #JOIN_BEVEL}, or {@link #JOIN_MITER}). + * @param miterlimit the limit to trim the miter join. The miterlimit must be * greater than or equal to 1.0f. * @param dash The array representing the dashing pattern. There must be at * least one non-zero entry. * @param dashPhase is negative and dash is not null. * - * @exception IllegalArgumentException If one input parameter doesn't meet + * @throws IllegalArgumentException If one input parameter doesn't meet * its needs. */ public BasicStroke(float width, int cap, int join, float miterlimit, @@ -122,15 +173,17 @@ public class BasicStroke implements Stroke } /** - * Creates a basic stroke. + * Creates a new BasicStroke instance with the given attributes. * - * @param width The width of the BasicStroke. May not be negative . - * @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE. - * @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER. + * @param width the line width (>= 0.0f). + * @param cap the line cap style (one of {@link #CAP_BUTT}, + * {@link #CAP_ROUND} or {@link #CAP_SQUARE}). + * @param join the line join style (one of {@link #JOIN_ROUND}, + * {@link #JOIN_BEVEL}, or {@link #JOIN_MITER}). * @param miterlimit the limit to trim the miter join. The miterlimit must be * greater than or equal to 1.0f. * - * @exception IllegalArgumentException If one input parameter doesn't meet + * @throws IllegalArgumentException If one input parameter doesn't meet * its needs. */ public BasicStroke(float width, int cap, int join, float miterlimit) @@ -139,15 +192,17 @@ public class BasicStroke implements Stroke } /** - * Creates a basic stroke. + * Creates a new BasicStroke instance with the given attributes. + * The miter limit defaults to 10.0. * - * @param width The width of the BasicStroke. May not be nehative. - * @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE. - * @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER. + * @param width the line width (>= 0.0f). + * @param cap the line cap style (one of {@link #CAP_BUTT}, + * {@link #CAP_ROUND} or {@link #CAP_SQUARE}). + * @param join the line join style (one of {@link #JOIN_ROUND}, + * {@link #JOIN_BEVEL}, or {@link #JOIN_MITER}). * - * @exception IllegalArgumentException If one input parameter doesn't meet + * @throws IllegalArgumentException If one input parameter doesn't meet * its needs. - * @exception IllegalArgumentException FIXME */ public BasicStroke(float width, int cap, int join) { @@ -155,11 +210,17 @@ public class BasicStroke implements Stroke } /** - * Creates a basic stroke. - * - * @param width The width of the BasicStroke. + * Creates a new BasicStroke instance with the given line + * width. The default values are: + *

+ * + * @param width the line width (>= 0.0f). * - * @exception IllegalArgumentException If width is negative. + * @throws IllegalArgumentException If width is negative. */ public BasicStroke(float width) { @@ -167,43 +228,92 @@ public class BasicStroke implements Stroke } /** - * Creates a basic stroke. + * Creates a new BasicStroke instance. The default values are: + * */ public BasicStroke() { this(1, CAP_SQUARE, JOIN_MITER, 10, null, 0); } + /** + * Creates a shape representing the stroked outline of the given shape. + * THIS METHOD IS NOT YET IMPLEMENTED. + * + * @param s the shape. + */ public Shape createStrokedShape(Shape s) { + // FIXME: Implement this throw new Error("not implemented"); } + /** + * Returns the line width. + * + * @return The line width. + */ public float getLineWidth() { return width; } + /** + * Returns a code indicating the line cap style (one of {@link #CAP_BUTT}, + * {@link #CAP_ROUND}, {@link #CAP_SQUARE}). + * + * @return A code indicating the line cap style. + */ public int getEndCap() { return cap; } + /** + * Returns a code indicating the line join style (one of {@link #JOIN_BEVEL}, + * {@link #JOIN_MITER} or {@link #JOIN_ROUND}). + * + * @return A code indicating the line join style. + */ public int getLineJoin() { return join; } + /** + * Returns the miter limit. + * + * @return The miter limit. + */ public float getMiterLimit() { return limit; } + /** + * Returns the dash array, which defines the length of alternate opaque and + * transparent sections in lines drawn with this stroke. If + * null, a continuous line will be drawn. + * + * @return The dash array (possibly null). + */ public float[] getDashArray() { return dash; } + /** + * Returns the dash phase for the stroke. This is the offset from the start + * of a path at which the pattern defined by {@link #getDashArray()} is + * rendered. + * + * @return The dash phase. + */ public float getDashPhase() { return phase; @@ -215,6 +325,8 @@ public class BasicStroke implements Stroke * (converted to int first with * Float.floatToIntBits() if the value is a * float). + * + * @return The hash code. */ public int hashCode() { @@ -233,9 +345,18 @@ public class BasicStroke implements Stroke } /** - * Returns true if the given Object is an instance of BasicStroke - * and the width, cap, join, limit, dash array and phase are all - * equal. + * Compares this BasicStroke for equality with an arbitrary + * object. This method returns true if and only if: + * + * + * @param o the object (null permitted). + * + * @return true if this stroke is equal to o and + * false otherwise. */ public boolean equals(Object o) { @@ -245,4 +366,4 @@ public class BasicStroke implements Stroke return width == s.width && cap == s.cap && join == s.join && limit == s.limit && Arrays.equals(dash, s.dash) && phase == s.phase; } -} // class BasicStroke +} diff --git a/libjava/classpath/java/awt/BorderLayout.java b/libjava/classpath/java/awt/BorderLayout.java index 7c8c582..50061ec 100644 --- a/libjava/classpath/java/awt/BorderLayout.java +++ b/libjava/classpath/java/awt/BorderLayout.java @@ -460,27 +460,30 @@ public class BorderLayout implements LayoutManager2, java.io.Serializable } /** - * Lays out the specified container according to the constraints - * in this object. - * + * Lays out the specified container according to the constraints in this + * object. + * * @param target The container to lay out. */ public void layoutContainer(Container target) { - synchronized (target.getTreeLock ()) + synchronized (target.getTreeLock()) { Insets i = target.getInsets(); + int top = i.top; + int bottom = target.height - i.bottom; + int left = i.left; + int right = target.width - i.right; - ComponentOrientation orient = target.getComponentOrientation (); - boolean left_to_right = orient.isLeftToRight (); + boolean left_to_right = target.getComponentOrientation().isLeftToRight(); Component my_north = north; Component my_east = east; Component my_south = south; Component my_west = west; - // Note that we currently don't handle vertical layouts. Neither - // does JDK 1.3. + // Note that we currently don't handle vertical layouts. + // Neither does JDK 1.3. if (firstLine != null) my_north = firstLine; if (lastLine != null) @@ -500,65 +503,42 @@ public class BorderLayout implements LayoutManager2, java.io.Serializable my_west = lastItem; } - Dimension c = calcCompSize(center, PREF); - Dimension n = calcCompSize(my_north, PREF); - Dimension s = calcCompSize(my_south, PREF); - Dimension e = calcCompSize(my_east, PREF); - Dimension w = calcCompSize(my_west, PREF); - int targetWidth = target.getWidth(); - int targetHeight = target.getHeight(); - - /* - <-> hgap <-> hgap - +----------------------------+ } - |t | } i.top - | +----------------------+ | --- y1 } - | |n | | - | +----------------------+ | } vgap - | +---+ +----------+ +---+ | --- y2 } } - | |w | |c | |e | | } hh - | +---+ +----------+ +---+ | } vgap } - | +----------------------+ | --- y3 } - | |s | | - | +----------------------+ | } - | | } i.bottom - +----------------------------+ } - |x1 |x2 |x3 - <----------------------> - <--> ww <--> - i.left i.right - */ - - int x1 = i.left; - int x2 = x1 + w.width + (w.width == 0 ? 0 : hgap); - int x3; - if (targetWidth <= i.right + e.width) - x3 = x2 + w.width + (w.width == 0 ? 0 : hgap); - else - x3 = targetWidth - i.right - e.width; - int ww = targetWidth - i.right - i.left; - - int y1 = i.top; - int y2 = y1 + n.height + (n.height == 0 ? 0 : vgap); - int midh = Math.max(e.height, Math.max(w.height, c.height)); - int y3; - if (targetHeight <= i.bottom + s.height) - y3 = y2 + midh + vgap; - else - y3 = targetHeight - i.bottom - s.height; - int hh = y3-y2-(s.height == 0 ? 0 : vgap); - - setBounds(center, x2, y2, x3-x2-(w.width == 0 ? 0 : hgap), hh); - setBounds(my_north, x1, y1, ww, n.height); - setBounds(my_south, x1, y3, ww, s.height); - setBounds(my_west, x1, y2, w.width, hh); - setBounds(my_east, x3, y2, e.width, hh); + if (my_north != null) + { + Dimension n = calcCompSize(my_north, PREF); + my_north.setBounds(left, top, right - left, n.height); + top += n.height + vgap; + } + + if (my_south != null) + { + Dimension s = calcCompSize(my_south, PREF); + my_south.setBounds(left, bottom - s.height, right - left, s.height); + bottom -= s.height + vgap; + } + + if (my_east != null) + { + Dimension e = calcCompSize(my_east, PREF); + my_east.setBounds(right - e.width, top, e.width, bottom - top); + right -= e.width + hgap; + } + + if (my_west != null) + { + Dimension w = calcCompSize(my_west, PREF); + my_west.setBounds(left, top, w.width, bottom - top); + left += w.width + hgap; + } + + if (center != null) + center.setBounds(left, top, right - left, bottom - top); } } /** * Returns a string representation of this layout manager. - * + * * @return A string representation of this object. */ public String toString() @@ -566,20 +546,9 @@ public class BorderLayout implements LayoutManager2, java.io.Serializable return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]"; } - /** - * This is a convenience method to set the bounds on a component. - * If the indicated component is null, nothing is done. - */ - private void setBounds(Component comp, int x, int y, int w, int h) - { - if (comp == null) - return; - comp.setBounds(x, y, w, h); - } - private Dimension calcCompSize(Component comp, int what) { - if (comp == null || !comp.isVisible()) + if (comp == null || ! comp.isVisible()) return new Dimension(0, 0); if (what == MIN) return comp.getMinimumSize(); @@ -589,12 +558,12 @@ public class BorderLayout implements LayoutManager2, java.io.Serializable } /** - * This is a helper function used to compute the various sizes for - * this layout. + * This is a helper function used to compute the various sizes for this + * layout. */ private Dimension calcSize(Container target, int what) { - synchronized (target.getTreeLock ()) + synchronized (target.getTreeLock()) { Insets ins = target.getInsets(); diff --git a/libjava/classpath/java/awt/CardLayout.java b/libjava/classpath/java/awt/CardLayout.java index 8582c5f..8b3fea2c 100644 --- a/libjava/classpath/java/awt/CardLayout.java +++ b/libjava/classpath/java/awt/CardLayout.java @@ -117,7 +117,7 @@ public class CardLayout implements LayoutManager2, Serializable /** * Cause the first component in the container to be displayed. * - * @param parent The parent container + * @param parent The parent container, not null. */ public void first (Container parent) { @@ -181,7 +181,7 @@ public class CardLayout implements LayoutManager2, Serializable /** * Cause the last component in the container to be displayed. * - * @param parent The parent container + * @param parent The parent container, not null. */ public void last (Container parent) { @@ -247,7 +247,7 @@ public class CardLayout implements LayoutManager2, Serializable * this current card is the last one in the deck, the first * component is displayed. * - * @param parent The parent container + * @param parent The parent container, not null. */ public void next (Container parent) { @@ -271,7 +271,7 @@ public class CardLayout implements LayoutManager2, Serializable * If this current card is the first one in the deck, the last * component is displayed. * - * @param parent The parent container + * @param parent The parent container, not null. */ public void previous (Container parent) { @@ -321,13 +321,19 @@ public class CardLayout implements LayoutManager2, Serializable /** * Cause the named component to be shown. If the component name is - * unknown, this method does nothing. + * unknown or null, this method does nothing. * - * @param parent The parent container - * @param name The name of the component to show + * @param parent The parent container, not null. + * @param name The name of the component to show */ public void show (Container parent, String name) { + if (name == null) + return; + + if (parent.getLayout() != this) + throw new IllegalArgumentException("parent's layout is not this CardLayout"); + Object target = tab.get (name); if (target != null) { @@ -362,9 +368,15 @@ public class CardLayout implements LayoutManager2, Serializable * * @param parent The parent container * @param what The type of goto: FIRST, LAST, NEXT or PREV + * + * @throws IllegalArgumentException if parent has not this + * CardLayout set as its layout. */ private void gotoComponent (Container parent, int what) { + if (parent.getLayout() != this) + throw new IllegalArgumentException("parent's layout is not this CardLayout"); + synchronized (parent.getTreeLock ()) { int num = parent.ncomponents; diff --git a/libjava/classpath/java/awt/Checkbox.java b/libjava/classpath/java/awt/Checkbox.java index 93f6092..eea443e 100644 --- a/libjava/classpath/java/awt/Checkbox.java +++ b/libjava/classpath/java/awt/Checkbox.java @@ -1,5 +1,6 @@ /* Checkbox.java -- An AWT checkbox widget - Copyright (C) 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2002, 2005, 2006 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -459,11 +460,14 @@ getState() public synchronized void setState(boolean state) { - this.state = state; - if (peer != null) + if (this.state != state) { - CheckboxPeer cp = (CheckboxPeer) peer; - cp.setState (state); + this.state = state; + if (peer != null) + { + CheckboxPeer cp = (CheckboxPeer) peer; + cp.setState (state); + } } } @@ -599,10 +603,15 @@ void dispatchEventImpl(AWTEvent e) { if (e.id <= ItemEvent.ITEM_LAST - && e.id >= ItemEvent.ITEM_FIRST - && (item_listeners != null - || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0)) - processEvent(e); + && e.id >= ItemEvent.ITEM_FIRST) + { + ItemEvent ie = (ItemEvent) e; + int itemState = ie.getStateChange(); + setState(itemState == ItemEvent.SELECTED ? true : false); + if (item_listeners != null + || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0) + processEvent(e); + } else super.dispatchEventImpl(e); } diff --git a/libjava/classpath/java/awt/Choice.java b/libjava/classpath/java/awt/Choice.java index df93c5b..2e55d19 100644 --- a/libjava/classpath/java/awt/Choice.java +++ b/libjava/classpath/java/awt/Choice.java @@ -468,15 +468,16 @@ getSelectedIndex() public synchronized void select(int index) { - if ((index < 0) || (index > getItemCount())) + if ((index < 0) || (index >= getItemCount())) throw new IllegalArgumentException("Bad index: " + index); - this.selectedIndex = index; - if (peer != null) - { + if (pItems.size() > 0) { + selectedIndex = index; ChoicePeer cp = (ChoicePeer) peer; - cp.select (index); - } + if (cp != null) { + cp.select(index); + } + } } /*************************************************************************/ @@ -573,18 +574,6 @@ processItemEvent(ItemEvent event) item_listeners.itemStateChanged(event); } -void -dispatchEventImpl(AWTEvent e) -{ - if (e.id <= ItemEvent.ITEM_LAST - && e.id >= ItemEvent.ITEM_FIRST - && (item_listeners != null - || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0)) - processEvent(e); - else - super.dispatchEventImpl(e); -} - /*************************************************************************/ /** diff --git a/libjava/classpath/java/awt/Component.java b/libjava/classpath/java/awt/Component.java index bd22ea3..de01fc1 100644 --- a/libjava/classpath/java/awt/Component.java +++ b/libjava/classpath/java/awt/Component.java @@ -1,5 +1,6 @@ /* Component.java -- a graphics component - Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation + Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2006 + Free Software Foundation This file is part of GNU Classpath. @@ -40,6 +41,7 @@ package java.awt; import java.awt.dnd.DropTarget; import java.awt.event.ActionEvent; +import java.awt.event.AdjustmentEvent; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.FocusEvent; @@ -900,7 +902,7 @@ public abstract class Component // Avoid NullPointerExceptions by creating a local reference. ComponentPeer currentPeer=peer; if (currentPeer != null) - currentPeer.setVisible(true); + currentPeer.show(); // The JDK repaints the component before invalidating the parent. // So do we. @@ -1388,18 +1390,20 @@ public abstract class Component int oldy = this.y; int oldwidth = this.width; int oldheight = this.height; - - if (this.x == x && this.y == y - && this.width == width && this.height == height) + + if (this.x == x && this.y == y && this.width == width + && this.height == height) return; - invalidate (); + + invalidate(); + this.x = x; this.y = y; this.width = width; this.height = height; if (peer != null) peer.setBounds (x, y, width, height); - + // Erase old bounds and repaint new bounds for lightweights. if (isLightweight() && isShowing()) { @@ -1598,16 +1602,18 @@ public abstract class Component public Dimension preferredSize() { if (prefSize == null) - if (peer == null) - return new Dimension(width, height); - else - prefSize = peer.getPreferredSize(); + { + if (peer == null) + prefSize = minimumSize(); + else + prefSize = peer.getPreferredSize(); + } return prefSize; } /** * Returns the component's minimum size. - * + * * @return the component's minimum size * @see #getPreferredSize() * @see LayoutManager @@ -1882,8 +1888,7 @@ public abstract class Component */ public void repaint() { - if (isShowing()) - repaint(0, 0, 0, width, height); + repaint(0, 0, 0, width, height); } /** @@ -1897,8 +1902,7 @@ public abstract class Component */ public void repaint(long tm) { - if (isShowing()) - repaint(tm, 0, 0, width, height); + repaint(tm, 0, 0, width, height); } /** @@ -1915,8 +1919,7 @@ public abstract class Component */ public void repaint(int x, int y, int w, int h) { - if (isShowing()) - repaint(0, x, y, w, h); + repaint(0, x, y, w, h); } /** @@ -2308,6 +2311,10 @@ public abstract class Component */ public final void dispatchEvent(AWTEvent e) { + Event oldEvent = translateEvent(e); + if (oldEvent != null) + postEvent (oldEvent); + // Some subclasses in the AWT package need to override this behavior, // hence the use of dispatchEventImpl(). dispatchEventImpl(e); @@ -3419,10 +3426,11 @@ public abstract class Component } /** - * Called to inform this component it has been added to a container. - * A native peer - if any - is created at this time. This method is - * called automatically by the AWT system and should not be called by - * user level code. + * Called when the parent of this Component is made visible or when + * the Component is added to an already visible Container and needs + * to be shown. A native peer - if any - is created at this + * time. This method is called automatically by the AWT system and + * should not be called by user level code. * * @see #isDisplayable() * @see #removeNotify() @@ -3431,6 +3439,8 @@ public abstract class Component { if (peer == null) peer = getToolkit().createComponent(this); + else if (parent != null && parent.isLightweight()) + new HeavyweightInLightweightListener(parent); /* Now that all the children has gotten their peers, we should have the event mask needed for this component and its lightweight subcomponents. */ @@ -4481,6 +4491,109 @@ p *
  • the set of backward traversal keys } /** + * Report a change in a bound property to any registered property listeners. + * + * @param propertyName the property that changed + * @param oldValue the old property value + * @param newValue the new property value + * + * @since 1.5 + */ + public void firePropertyChange(String propertyName, byte oldValue, + byte newValue) + { + if (changeSupport != null) + changeSupport.firePropertyChange(propertyName, new Byte(oldValue), + new Byte(newValue)); + } + + /** + * Report a change in a bound property to any registered property listeners. + * + * @param propertyName the property that changed + * @param oldValue the old property value + * @param newValue the new property value + * + * @since 1.5 + */ + public void firePropertyChange(String propertyName, char oldValue, + char newValue) + { + if (changeSupport != null) + changeSupport.firePropertyChange(propertyName, new Character(oldValue), + new Character(newValue)); + } + + /** + * Report a change in a bound property to any registered property listeners. + * + * @param propertyName the property that changed + * @param oldValue the old property value + * @param newValue the new property value + * + * @since 1.5 + */ + public void firePropertyChange(String propertyName, short oldValue, + short newValue) + { + if (changeSupport != null) + changeSupport.firePropertyChange(propertyName, new Short(oldValue), + new Short(newValue)); + } + + /** + * Report a change in a bound property to any registered property listeners. + * + * @param propertyName the property that changed + * @param oldValue the old property value + * @param newValue the new property value + * + * @since 1.5 + */ + public void firePropertyChange(String propertyName, long oldValue, + long newValue) + { + if (changeSupport != null) + changeSupport.firePropertyChange(propertyName, new Long(oldValue), + new Long(newValue)); + } + + /** + * Report a change in a bound property to any registered property listeners. + * + * @param propertyName the property that changed + * @param oldValue the old property value + * @param newValue the new property value + * + * @since 1.5 + */ + public void firePropertyChange(String propertyName, float oldValue, + float newValue) + { + if (changeSupport != null) + changeSupport.firePropertyChange(propertyName, new Float(oldValue), + new Float(newValue)); + } + + + /** + * Report a change in a bound property to any registered property listeners. + * + * @param propertyName the property that changed + * @param oldValue the old property value + * @param newValue the new property value + * + * @since 1.5 + */ + public void firePropertyChange(String propertyName, double oldValue, + double newValue) + { + if (changeSupport != null) + changeSupport.firePropertyChange(propertyName, new Double(oldValue), + new Double(newValue)); + } + + /** * Sets the text layout orientation of this component. New components default * to UNKNOWN (which behaves like LEFT_TO_RIGHT). This method affects only * the current component, while @@ -4597,7 +4710,7 @@ p *
  • the set of backward traversal keys */ static Event translateEvent (AWTEvent e) { - Component target = (Component) e.getSource (); + Object target = e.getSource (); Event translated = null; if (e instanceof InputEvent) @@ -4770,6 +4883,25 @@ p *
  • the set of backward traversal keys 0, 0, oldKey, oldMods); } } + else if (e instanceof AdjustmentEvent) + { + AdjustmentEvent ae = (AdjustmentEvent) e; + int type = ae.getAdjustmentType(); + int oldType; + if (type == AdjustmentEvent.BLOCK_DECREMENT) + oldType = Event.SCROLL_PAGE_UP; + else if (type == AdjustmentEvent.BLOCK_INCREMENT) + oldType = Event.SCROLL_PAGE_DOWN; + else if (type == AdjustmentEvent.TRACK) + oldType = Event.SCROLL_ABSOLUTE; + else if (type == AdjustmentEvent.UNIT_DECREMENT) + oldType = Event.SCROLL_LINE_UP; + else if (type == AdjustmentEvent.UNIT_INCREMENT) + oldType = Event.SCROLL_LINE_DOWN; + else + oldType = type; + translated = new Event(target, oldType, new Integer(ae.getValue())); + } else if (e instanceof ActionEvent) translated = new Event (target, Event.ACTION_EVENT, ((ActionEvent) e).getActionCommand ()); @@ -4790,16 +4922,16 @@ p *
  • the set of backward traversal keys void dispatchEventImpl(AWTEvent e) { - Event oldEvent = translateEvent (e); + // Give toolkit a chance to dispatch the event + // to globally registered listeners. + Toolkit.getDefaultToolkit().globalDispatchEvent(e); + // This boolean tells us not to process focus events when the focus // opposite component is the same as the focus component. boolean ignoreFocus = (e instanceof FocusEvent && ((FocusEvent)e).getComponent() == ((FocusEvent)e).getOppositeComponent()); - if (oldEvent != null) - postEvent (oldEvent); - if (eventTypeEnabled (e.id)) { // the trick we use to communicate between dispatch and redispatch @@ -4925,16 +5057,6 @@ p *
  • the set of backward traversal keys Rectangle r1 = queuedEvent.getUpdateRect(); Rectangle r2 = newEvent.getUpdateRect(); Rectangle union = r1.union(r2); - - int r1a = r1.width * r1.height; - int r2a = r2.width * r2.height; - int ua = union.width * union.height; - - if (ua > (r1a+r2a)*2) - return null; - /* The 2 factor should maybe be reconsidered. Perhaps 3/2 - would be better? */ - newEvent.setUpdateRect(union); return newEvent; } @@ -5014,9 +5136,76 @@ p *
  • the set of backward traversal keys s.writeObject(null); } - + // Nested classes. + + /** + * This class fixes the bounds for a Heavyweight component that + * is placed inside a Lightweight container. When the lightweight is + * moved or resized, setBounds for the lightweight peer does nothing. + * Therefore, it was never moved on the screen. This class is + * attached to the lightweight, and it adjusts the position and size + * of the peer when notified. + * This is the same for show and hide. + */ + class HeavyweightInLightweightListener + implements ComponentListener + { + + /** + * Constructor. Adds component listener to lightweight parent. + * + * @param parent - the lightweight container. + */ + public HeavyweightInLightweightListener(Container parent) + { + parent.addComponentListener(this); + } + + /** + * This method is called when the component is resized. + * + * @param event the ComponentEvent indicating the resize + */ + public void componentResized(ComponentEvent event) + { + // Nothing to do here, componentMoved will be called. + } + + /** + * This method is called when the component is moved. + * + * @param event the ComponentEvent indicating the move + */ + public void componentMoved(ComponentEvent event) + { + if (peer != null) + peer.setBounds(x, y, width, height); + } + + /** + * This method is called when the component is made visible. + * + * @param event the ComponentEvent indicating the visibility + */ + public void componentShown(ComponentEvent event) + { + if (isShowing()) + peer.show(); + } + /** + * This method is called when the component is hidden. + * + * @param event the ComponentEvent indicating the visibility + */ + public void componentHidden(ComponentEvent event) + { + if (!isShowing()) + peer.hide(); + } + } + /** * This class provides accessibility support for subclasses of container. * diff --git a/libjava/classpath/java/awt/Container.java b/libjava/classpath/java/awt/Container.java index 67f0ed1..41892ca 100644 --- a/libjava/classpath/java/awt/Container.java +++ b/libjava/classpath/java/awt/Container.java @@ -1,5 +1,6 @@ /* Container.java -- parent container class in AWT - Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005 Free Software Foundation + Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation This file is part of GNU Classpath. @@ -42,12 +43,10 @@ import java.awt.event.ComponentListener; import java.awt.event.ContainerEvent; import java.awt.event.ContainerListener; import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; import java.awt.peer.ComponentPeer; import java.awt.peer.ContainerPeer; import java.awt.peer.LightweightPeer; import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -62,8 +61,6 @@ import java.util.Set; import javax.accessibility.Accessible; -import gnu.java.awt.AWTUtilities; - /** * A generic window toolkit object that acts as a container for other objects. * Components are tracked in a list, and new elements are at the end of the @@ -88,11 +85,14 @@ public class Container extends Component Component[] component; LayoutManager layoutMgr; - LightweightDispatcher dispatcher; - Dimension maxSize; /** + * Keeps track if the Container was cleared during a paint/update. + */ + private boolean backCleared; + + /** * @since 1.4 */ boolean focusCycleRoot; @@ -101,7 +101,6 @@ public class Container extends Component /* Anything else is non-serializable, and should be declared "transient". */ transient ContainerListener containerListener; - transient PropertyChangeSupport changeSupport; /** The focus traversal policy that determines how focus is transferred between this Container and its children. */ @@ -187,25 +186,6 @@ public class Container extends Component } /** - * Swaps the components at position i and j, in the container. - */ - - protected void swapComponents (int i, int j) - { - synchronized (getTreeLock ()) - { - if (i < 0 - || i >= component.length - || j < 0 - || j >= component.length) - throw new ArrayIndexOutOfBoundsException (); - Component tmp = component[i]; - component[i] = component[j]; - component[j] = tmp; - } - } - - /** * Returns the insets for this container, which is the space used for * borders, the margin, etc. * @@ -385,6 +365,8 @@ public class Container extends Component // Notify the layout manager. if (layoutMgr != null) { + // If we have a LayoutManager2 the constraints are "real", + // otherwise they are the "name" of the Component to add. if (layoutMgr instanceof LayoutManager2) { LayoutManager2 lm2 = (LayoutManager2) layoutMgr; @@ -393,7 +375,7 @@ public class Container extends Component else if (constraints instanceof String) layoutMgr.addLayoutComponent((String) constraints, comp); else - layoutMgr.addLayoutComponent(null, comp); + layoutMgr.addLayoutComponent("", comp); } // We previously only sent an event when this container is showing. @@ -428,8 +410,7 @@ public class Container extends Component for (int j = 0; j < list.length; j++) r.removeComponentListener(list[j]); - if (r.isShowing()) - r.removeNotify(); + r.removeNotify(); System.arraycopy(component, index + 1, component, index, ncomponents - index - 1); @@ -777,16 +758,17 @@ public class Container extends Component * a superclass method so that lightweight components are properly * drawn. * - * @param g The graphics context for this paint job. + * @param g - The graphics context for this paint job. */ public void paint(Graphics g) { if (!isShowing()) return; - // Visit heavyweights as well, in case they were - // erased when we cleared the background for this container. - visitChildren(g, GfxPaintVisitor.INSTANCE, false); + // Visit heavyweights if the background was cleared + // for this container. + visitChildren(g, GfxPaintVisitor.INSTANCE, !backCleared); + backCleared = false; } /** @@ -817,8 +799,11 @@ public class Container extends Component // also not cleared. So we do a check on !(peer instanceof LightweightPeer) // instead. ComponentPeer p = peer; - if (p != null && !(p instanceof LightweightPeer)) - g.clearRect(0, 0, getWidth(), getHeight()); + if (p != null && ! (p instanceof LightweightPeer)) + { + g.clearRect(0, 0, getWidth(), getHeight()); + backCleared = true; + } paint(g); } @@ -1557,28 +1542,105 @@ public class Container extends Component if (orientation == null) throw new NullPointerException (); } - + public void addPropertyChangeListener (PropertyChangeListener listener) { - if (listener == null) - return; - - if (changeSupport == null) - changeSupport = new PropertyChangeSupport (this); - - changeSupport.addPropertyChangeListener (listener); + // TODO: Why is this overridden? + super.addPropertyChangeListener(listener); } - - public void addPropertyChangeListener (String name, + + public void addPropertyChangeListener (String propertyName, PropertyChangeListener listener) { - if (listener == null) - return; - - if (changeSupport == null) - changeSupport = new PropertyChangeSupport (this); + // TODO: Why is this overridden? + super.addPropertyChangeListener(propertyName, listener); + } + + + /** + * Sets the Z ordering for the component comp to + * index. Components with lower Z order paint above components + * with higher Z order. + * + * @param comp the component for which to change the Z ordering + * @param index the index to set + * + * @throws NullPointerException if comp == null + * @throws IllegalArgumentException if comp is an ancestor of this container + * @throws IllegalArgumentException if index is not in + * [0, getComponentCount()] for moving between + * containers or [0, getComponentCount() - 1] for moving + * inside this container + * @throws IllegalArgumentException if comp == this + * @throws IllegalArgumentException if comp is a + * Window + * + * @see #getComponentZOrder(Component) + * + * @since 1.5 + */ + public final void setComponentZOrder(Component comp, int index) + { + if (comp == null) + throw new NullPointerException("comp must not be null"); + if (comp instanceof Container && ((Container) comp).isAncestorOf(this)) + throw new IllegalArgumentException("comp must not be an ancestor of " + + "this"); + if (comp instanceof Window) + throw new IllegalArgumentException("comp must not be a Window"); + + if (comp == this) + throw new IllegalArgumentException("cannot add component to itself"); + + // FIXME: Implement reparenting. + if ( comp.getParent() != this) + throw new AssertionError("Reparenting is not implemented yet"); + else + { + // Find current component index. + int currentIndex = getComponentZOrder(comp); + if (currentIndex < index) + { + System.arraycopy(component, currentIndex + 1, component, + currentIndex, index - currentIndex); + } + else + { + System.arraycopy(component, index, component, index + 1, + currentIndex - index); + } + component[index] = comp; + } + } - changeSupport.addPropertyChangeListener (name, listener); + /** + * Returns the Z ordering index of comp. If comp + * is not a child component of this Container, this returns -1. + * + * @param comp the component for which to query the Z ordering + * + * @return the Z ordering index of comp or -1 if + * comp is not a child of this Container + * + * @see #setComponentZOrder(Component, int) + * + * @since 1.5 + */ + public final int getComponentZOrder(Component comp) + { + int index = -1; + if (component != null) + { + for (int i = 0; i < component.length; i++) + { + if (component[i] == comp) + { + index = i; + break; + } + } + } + return index; } // Hidden helper methods. @@ -1600,17 +1662,17 @@ public class Container extends Component private void visitChildren(Graphics gfx, GfxVisitor visitor, boolean lightweightOnly) { - synchronized (getTreeLock ()) + synchronized (getTreeLock()) { for (int i = ncomponents - 1; i >= 0; --i) { Component comp = component[i]; boolean applicable = comp.isVisible() - && (comp.isLightweight() || !lightweightOnly); - + && (comp.isLightweight() || ! lightweightOnly); + if (applicable) visitChild(gfx, visitor, comp); - } + } } } @@ -1631,10 +1693,9 @@ public class Container extends Component Component comp) { Rectangle bounds = comp.getBounds(); - + if(!gfx.hitClip(bounds.x,bounds.y, bounds.width, bounds.height)) return; - Graphics g2 = gfx.create(bounds.x, bounds.y, bounds.width, bounds.height); try @@ -1649,17 +1710,18 @@ public class Container extends Component void dispatchEventImpl(AWTEvent e) { - // Give lightweight dispatcher a chance to handle it. - if (dispatcher != null && dispatcher.handleEvent (e)) - return; - - if ((e.id <= ContainerEvent.CONTAINER_LAST - && e.id >= ContainerEvent.CONTAINER_FIRST) - && (containerListener != null - || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0)) - processEvent(e); - else - super.dispatchEventImpl(e); + boolean dispatched = + LightweightDispatcher.getInstance().dispatchEvent(e); + if (! dispatched) + { + if ((e.id <= ContainerEvent.CONTAINER_LAST + && e.id >= ContainerEvent.CONTAINER_FIRST) + && (containerListener != null + || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0)) + processEvent(e); + else + super.dispatchEventImpl(e); + } } /** @@ -1743,15 +1805,6 @@ public class Container extends Component component[i].addNotify(); if (component[i].isLightweight ()) { - - // If we're not lightweight, and we just got a lightweight - // child, we need a lightweight dispatcher to feed it events. - if (!this.isLightweight() && dispatcher == null) - dispatcher = new LightweightDispatcher (this); - - if (dispatcher != null) - dispatcher.enableEvents(component[i].eventMask); - enableEvents(component[i].eventMask); if (peer != null && !isLightweight ()) enableEvents (AWTEvent.PAINT_EVENT_MASK); @@ -1998,229 +2051,3 @@ public class Container extends Component } // class AccessibleContainerHandler } // class AccessibleAWTContainer } // class Container - -/** - * There is a helper class implied from stack traces called - * LightweightDispatcher, but since it is not part of the public API, - * rather than mimic it exactly we write something which does "roughly - * the same thing". - */ -class LightweightDispatcher implements Serializable -{ - private static final long serialVersionUID = 5184291520170872969L; - private Container nativeContainer; - private Cursor nativeCursor; - private long eventMask; - - private transient Component pressedComponent; - private transient Component lastComponentEntered; - private transient int pressCount; - - LightweightDispatcher(Container c) - { - nativeContainer = c; - } - - void enableEvents(long l) - { - eventMask |= l; - } - - /** - * Returns the deepest visible descendent of parent that contains the - * specified location and that is not transparent and MouseListener-less. - * @param parent the root component to begin the search - * @param x the x coordinate - * @param y the y coordinate - * @return null if parent doesn't contain the location, - * parent if parent is not a container or has no child that contains the - * location, otherwise the appropriate component from the conditions - * above. - */ - Component getDeepestComponentForMouseEventAt(Component parent, int x, int y) - { - if (parent == null || (! parent.contains(x, y))) - return null; - - if (! (parent instanceof Container)) - return parent; - - Container c = (Container) parent; - return c.findComponentForMouseEventAt(x, y); - } - - Component acquireComponentForMouseEvent(MouseEvent me) - { - int x = me.getX (); - int y = me.getY (); - - Component mouseEventTarget = null; - // Find the candidate which should receive this event. - Component parent = nativeContainer; - Component candidate = null; - Point p = me.getPoint(); - while (candidate == null && parent != null) - { - candidate = getDeepestComponentForMouseEventAt(parent, p.x, p.y); - if (candidate == null || (candidate.eventMask & me.getID()) == 0) - { - candidate = null; - p = AWTUtilities.convertPoint(parent, p.x, p.y, parent.parent); - parent = parent.parent; - } - } - - // If the only candidate we found was the native container itself, - // don't dispatch any event at all. We only care about the lightweight - // children here. - if (candidate == nativeContainer) - candidate = null; - - // If our candidate is new, inform the old target we're leaving. - if (lastComponentEntered != null - && lastComponentEntered.isShowing() - && lastComponentEntered != candidate) - { - // Old candidate could have been removed from - // the nativeContainer so we check first. - if (AWTUtilities.isDescendingFrom(lastComponentEntered, - nativeContainer)) - { - Point tp = AWTUtilities.convertPoint(nativeContainer, - x, y, lastComponentEntered); - MouseEvent exited = new MouseEvent (lastComponentEntered, - MouseEvent.MOUSE_EXITED, - me.getWhen (), - me.getModifiersEx (), - tp.x, tp.y, - me.getClickCount (), - me.isPopupTrigger (), - me.getButton ()); - lastComponentEntered.dispatchEvent (exited); - } - lastComponentEntered = null; - } - - // If we have a candidate, maybe enter it. - if (candidate != null) - { - mouseEventTarget = candidate; - if (candidate.isLightweight() - && candidate.isShowing() - && candidate != nativeContainer - && candidate != lastComponentEntered) - { - lastComponentEntered = mouseEventTarget; - Point cp = AWTUtilities.convertPoint(nativeContainer, - x, y, lastComponentEntered); - MouseEvent entered = new MouseEvent (lastComponentEntered, - MouseEvent.MOUSE_ENTERED, - me.getWhen (), - me.getModifiersEx (), - cp.x, cp.y, - me.getClickCount (), - me.isPopupTrigger (), - me.getButton ()); - lastComponentEntered.dispatchEvent (entered); - } - } - - // Check which buttons where pressed except the last button that - // changed state. - int modifiers = me.getModifiersEx() & (MouseEvent.BUTTON1_DOWN_MASK - | MouseEvent.BUTTON2_DOWN_MASK - | MouseEvent.BUTTON3_DOWN_MASK); - switch(me.getButton()) - { - case MouseEvent.BUTTON1: - modifiers &= ~MouseEvent.BUTTON1_DOWN_MASK; - break; - case MouseEvent.BUTTON2: - modifiers &= ~MouseEvent.BUTTON2_DOWN_MASK; - break; - case MouseEvent.BUTTON3: - modifiers &= ~MouseEvent.BUTTON3_DOWN_MASK; - break; - } - - if (me.getID() == MouseEvent.MOUSE_RELEASED - || me.getID() == MouseEvent.MOUSE_PRESSED && modifiers > 0 - || me.getID() == MouseEvent.MOUSE_DRAGGED) - { - // If any of the following events occur while a button is held down, - // they should be dispatched to the same component to which the - // original MOUSE_PRESSED event was dispatched: - // - MOUSE_RELEASED: This is important for correct dragging - // behaviour, otherwise the release goes to an arbitrary component - // outside of the dragged component. OTOH, if there is no mouse - // drag while the mouse is pressed, the component under the mouse - // is the same as the previously pressed component anyway. - // - MOUSE_PRESSED: another button pressed while the first is held - // down - // - MOUSE_DRAGGED - if (AWTUtilities.isDescendingFrom(pressedComponent, nativeContainer)) - mouseEventTarget = pressedComponent; - } - else if (me.getID() == MouseEvent.MOUSE_CLICKED) - { - // Don't dispatch CLICKED events whose target is not the same as the - // target for the original PRESSED event. - if (candidate != pressedComponent) - { - mouseEventTarget = null; - pressCount = 0; - } - else if (pressCount == 0) - pressedComponent = null; - } - return mouseEventTarget; - } - - boolean handleEvent(AWTEvent e) - { - if (e instanceof MouseEvent) - { - MouseEvent me = (MouseEvent) e; - - // Make the LightWeightDispatcher reentrant. This is necessary when - // a lightweight component does its own modal event queue. - Component mouseEventTarget = acquireComponentForMouseEvent(me); - - // Avoid dispatching ENTERED and EXITED events twice. - if (mouseEventTarget != null - && mouseEventTarget.isShowing() - && e.getID() != MouseEvent.MOUSE_ENTERED - && e.getID() != MouseEvent.MOUSE_EXITED) - { - switch (e.getID()) - { - case MouseEvent.MOUSE_PRESSED: - if (pressCount++ == 0) - pressedComponent = mouseEventTarget; - break; - case MouseEvent.MOUSE_RELEASED: - // Clear our memory of the original PRESSED event, only if - // we're not expecting a CLICKED event after this. If - // there is a CLICKED event after this, it will do clean up. - if (--pressCount == 0 - && mouseEventTarget != pressedComponent) - { - pressedComponent = null; - pressCount = 0; - } - break; - } - - MouseEvent newEvt = - AWTUtilities.convertMouseEvent(nativeContainer, me, - mouseEventTarget); - mouseEventTarget.dispatchEvent(newEvt); - - if (newEvt.isConsumed()) - e.consume(); - } - } - - return e.isConsumed(); - } -} diff --git a/libjava/classpath/java/awt/Cursor.java b/libjava/classpath/java/awt/Cursor.java index 48a63f0..0ff987c 100644 --- a/libjava/classpath/java/awt/Cursor.java +++ b/libjava/classpath/java/awt/Cursor.java @@ -219,6 +219,8 @@ public class Cursor implements java.io.Serializable public String toString() { - return (this.getClass() + "[" + getName() + "]"); + return (this.getClass() + + "[type=" + getType() + + ",name=" + getName() + "]"); } } diff --git a/libjava/classpath/java/awt/Frame.java b/libjava/classpath/java/awt/Frame.java index d6651f8..7003dac 100644 --- a/libjava/classpath/java/awt/Frame.java +++ b/libjava/classpath/java/awt/Frame.java @@ -1,5 +1,6 @@ /* Frame.java -- AWT toplevel window - Copyright (C) 1999, 2000, 2002, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2002, 2004, 2005, 2006 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -57,143 +58,156 @@ import javax.accessibility.AccessibleStateSet; */ public class Frame extends Window implements MenuContainer { -/** - * Constant for the default cursor. - * @deprecated Replaced by Cursor.DEFAULT_CURSOR instead. - */ -public static final int DEFAULT_CURSOR = Cursor.DEFAULT_CURSOR; -/** - * Constant for a cross-hair cursor. - * @deprecated Use Cursor.CROSSHAIR_CURSOR instead. - */ -public static final int CROSSHAIR_CURSOR = Cursor.CROSSHAIR_CURSOR; + /** + * Constant for the default cursor. + * + * @deprecated Replaced by Cursor.DEFAULT_CURSOR instead. + */ + public static final int DEFAULT_CURSOR = Cursor.DEFAULT_CURSOR; -/** - * Constant for a cursor over a text field. - * @deprecated Use Cursor.TEXT_CURSOR instead. - */ -public static final int TEXT_CURSOR = Cursor.TEXT_CURSOR; + /** + * Constant for a cross-hair cursor. + * + * @deprecated Use Cursor.CROSSHAIR_CURSOR instead. + */ + public static final int CROSSHAIR_CURSOR = Cursor.CROSSHAIR_CURSOR; -/** - * Constant for a cursor to display while waiting for an action to complete. - * @deprecated Use Cursor.WAIT_CURSOR. - */ -public static final int WAIT_CURSOR = Cursor.WAIT_CURSOR; + /** + * Constant for a cursor over a text field. + * + * @deprecated Use Cursor.TEXT_CURSOR instead. + */ + public static final int TEXT_CURSOR = Cursor.TEXT_CURSOR; -/** - * Cursor used over SW corner of window decorations. - * @deprecated Use Cursor.SW_RESIZE_CURSOR instead. - */ -public static final int SW_RESIZE_CURSOR = Cursor.SW_RESIZE_CURSOR; + /** + * Constant for a cursor to display while waiting for an action to complete. + * + * @deprecated Use Cursor.WAIT_CURSOR. + */ + public static final int WAIT_CURSOR = Cursor.WAIT_CURSOR; -/** - * Cursor used over SE corner of window decorations. - * @deprecated Use Cursor.SE_RESIZE_CURSOR instead. - */ -public static final int SE_RESIZE_CURSOR = Cursor.SE_RESIZE_CURSOR; + /** + * Cursor used over SW corner of window decorations. + * + * @deprecated Use Cursor.SW_RESIZE_CURSOR instead. + */ + public static final int SW_RESIZE_CURSOR = Cursor.SW_RESIZE_CURSOR; -/** - * Cursor used over NW corner of window decorations. - * @deprecated Use Cursor.NW_RESIZE_CURSOR instead. - */ -public static final int NW_RESIZE_CURSOR = Cursor.NW_RESIZE_CURSOR; + /** + * Cursor used over SE corner of window decorations. + * @deprecated Use Cursor.SE_RESIZE_CURSOR instead. + */ + public static final int SE_RESIZE_CURSOR = Cursor.SE_RESIZE_CURSOR; -/** - * Cursor used over NE corner of window decorations. - * @deprecated Use Cursor.NE_RESIZE_CURSOR instead. - */ -public static final int NE_RESIZE_CURSOR = Cursor.NE_RESIZE_CURSOR; + /** + * Cursor used over NW corner of window decorations. + * + * @deprecated Use Cursor.NW_RESIZE_CURSOR instead. + */ + public static final int NW_RESIZE_CURSOR = Cursor.NW_RESIZE_CURSOR; -/** - * Cursor used over N edge of window decorations. - * @deprecated Use Cursor.N_RESIZE_CURSOR instead. - */ -public static final int N_RESIZE_CURSOR = Cursor.N_RESIZE_CURSOR; + /** + * Cursor used over NE corner of window decorations. + * + * @deprecated Use Cursor.NE_RESIZE_CURSOR instead. + */ + public static final int NE_RESIZE_CURSOR = Cursor.NE_RESIZE_CURSOR; -/** - * Cursor used over S edge of window decorations. - * @deprecated Use Cursor.S_RESIZE_CURSOR instead. - */ -public static final int S_RESIZE_CURSOR = Cursor.S_RESIZE_CURSOR; + /** + * Cursor used over N edge of window decorations. + * + * @deprecated Use Cursor.N_RESIZE_CURSOR instead. + */ + public static final int N_RESIZE_CURSOR = Cursor.N_RESIZE_CURSOR; -/** - * Cursor used over E edge of window decorations. - * @deprecated Use Cursor.E_RESIZE_CURSOR instead. - */ -public static final int E_RESIZE_CURSOR = Cursor.E_RESIZE_CURSOR; + /** + * Cursor used over S edge of window decorations. + * + * @deprecated Use Cursor.S_RESIZE_CURSOR instead. + */ + public static final int S_RESIZE_CURSOR = Cursor.S_RESIZE_CURSOR; -/** - * Cursor used over W edge of window decorations. - * @deprecated Use Cursor.W_RESIZE_CURSOR instead. - */ -public static final int W_RESIZE_CURSOR = Cursor.W_RESIZE_CURSOR; + /** + * Cursor used over E edge of window decorations. + * + * @deprecated Use Cursor.E_RESIZE_CURSOR instead. + */ + public static final int E_RESIZE_CURSOR = Cursor.E_RESIZE_CURSOR; -/** - * Constant for a hand cursor. - * @deprecated Use Cursor.HAND_CURSOR instead. - */ -public static final int HAND_CURSOR = Cursor.HAND_CURSOR; + /** + * Cursor used over W edge of window decorations. + * + * @deprecated Use Cursor.W_RESIZE_CURSOR instead. + */ + public static final int W_RESIZE_CURSOR = Cursor.W_RESIZE_CURSOR; -/** - * Constant for a cursor used during window move operations. - * @deprecated Use Cursor.MOVE_CURSOR instead. - */ -public static final int MOVE_CURSOR = Cursor.MOVE_CURSOR; + /** + * Constant for a hand cursor. + * + * @deprecated Use Cursor.HAND_CURSOR instead. + */ + public static final int HAND_CURSOR = Cursor.HAND_CURSOR; -public static final int ICONIFIED = 1; -public static final int MAXIMIZED_BOTH = 6; -public static final int MAXIMIZED_HORIZ = 2; -public static final int MAXIMIZED_VERT = 4; -public static final int NORMAL = 0; + /** + * Constant for a cursor used during window move operations. + * + * @deprecated Use Cursor.MOVE_CURSOR instead. + */ + public static final int MOVE_CURSOR = Cursor.MOVE_CURSOR; -// Serialization version constant -private static final long serialVersionUID = 2673458971256075116L; + public static final int ICONIFIED = 1; + public static final int MAXIMIZED_BOTH = 6; + public static final int MAXIMIZED_HORIZ = 2; + public static final int MAXIMIZED_VERT = 4; + public static final int NORMAL = 0; -/** - * @serial The version of the class data being serialized - * // FIXME: what is this value? - */ -private int frameSerializedDataVersion; +//Serialization version constant + private static final long serialVersionUID = 2673458971256075116L; -/** - * @serial Image used as the icon when this frame is minimized. - */ -private Image icon; + /** + * @serial The version of the class data being serialized + * FIXME: what is this value? + */ + private int frameSerializedDataVersion; -/** - * @serial Constant used by the JDK Motif peer set. Not used in - * this implementation. - */ -private boolean mbManagement; + /** + * @serial Image used as the icon when this frame is minimized. + */ + private Image icon; -/** - * @serial The menu bar for this frame. - */ -//private MenuBar menuBar = new MenuBar(); -private MenuBar menuBar; + /** + * @serial Constant used by the JDK Motif peer set. Not used in + * this implementation. + */ + private boolean mbManagement; -/** - * @serial A list of other top-level windows owned by this window. - */ -Vector ownedWindows = new Vector(); + /** + * @serial The menu bar for this frame. + */ + private MenuBar menuBar; -/** - * @serial Indicates whether or not this frame is resizable. - */ -private boolean resizable = true; + /** + * @serial A list of other top-level windows owned by this window. + */ + Vector ownedWindows = new Vector(); -/** - * @serial The state of this frame. - * // FIXME: What are the values here? - * This is package-private to avoid an accessor method. - */ -int state; + /** + * @serial Indicates whether or not this frame is resizable. + */ + private boolean resizable = true; -/** - * @serial The title of the frame. - */ -private String title = ""; + /** + * @serial The state of this frame. + * // FIXME: What are the values here? + * This is package-private to avoid an accessor method. + */ + int state; + + /** + * @serial The title of the frame. + */ + private String title = ""; /** * Maximized bounds for this frame. @@ -210,223 +224,235 @@ private String title = ""; */ private static transient long next_frame_number; -/** - * Initializes a new instance of Frame that is not visible - * and has no title. - */ -public -Frame() -{ - this(""); - noteFrame(this); -} + /** + * Initializes a new instance of Frame that is not visible + * and has no title. + */ + public Frame() + { + this(""); + noteFrame(this); + } -/** - * Initializes a new instance of Frame that is not visible - * and has the specified title. - * - * @param title The title of this frame. - */ -public -Frame(String title) -{ - super(); - this.title = title; - // Top-level frames are initially invisible. - visible = false; - noteFrame(this); -} + /** + * Initializes a new instance of Frame that is not visible + * and has the specified title. + * + * @param title the title of this frame + */ + public Frame(String title) + { + super(); + this.title = title; + // Top-level frames are initially invisible. + visible = false; + noteFrame(this); + } -public -Frame(GraphicsConfiguration gc) -{ - super(gc); - visible = false; - noteFrame(this); -} + public Frame(GraphicsConfiguration gc) + { + super(gc); + visible = false; + noteFrame(this); + } -public -Frame(String title, GraphicsConfiguration gc) -{ - super(gc); - setTitle(title); - visible = false; - noteFrame(this); -} + public Frame(String title, GraphicsConfiguration gc) + { + super(gc); + setTitle(title); + visible = false; + noteFrame(this); + } -/** - * Returns this frame's title string. - * - * @return This frame's title string. - */ -public String -getTitle() -{ - return(title); -} + /** + * Returns this frame's title string. + * + * @return this frame's title string + */ + public String getTitle() + { + return title; + } -/* - * Sets this frame's title to the specified value. - * - * @param title The new frame title. - */ -public synchronized void -setTitle(String title) -{ - this.title = title; - if (peer != null) - ((FramePeer) peer).setTitle(title); -} + /** + * Sets this frame's title to the specified value. + * + * @param title the new frame title + */ + public synchronized void setTitle(String title) + { + this.title = title; + if (peer != null) + ((FramePeer) peer).setTitle(title); + } -/** - * Returns this frame's icon. - * - * @return This frame's icon, or null if this frame does not - * have an icon. - */ -public Image -getIconImage() -{ - return(icon); -} + /** + * Returns this frame's icon. + * + * @return this frame's icon, or null if this frame does not + * have an icon + */ + public Image getIconImage() + { + return icon; + } -/** - * Sets this frame's icon to the specified value. - * - * @icon The new icon for this frame. - */ -public synchronized void -setIconImage(Image icon) -{ - this.icon = icon; - if (peer != null) - ((FramePeer) peer).setIconImage(icon); -} + /** + * Sets this frame's icon to the specified value. + * + * @icon the new icon for this frame + */ + public synchronized void setIconImage(Image icon) + { + this.icon = icon; + if (peer != null) + ((FramePeer) peer).setIconImage(icon); + } -/** - * Returns this frame's menu bar. - * - * @return This frame's menu bar, or null if this frame - * does not have a menu bar. - */ -public MenuBar -getMenuBar() -{ - return(menuBar); -} + /** + * Returns this frame's menu bar. + * + * @return this frame's menu bar, or null if this frame + * does not have a menu bar + */ + public MenuBar getMenuBar() + { + return menuBar; + } -/** - * Sets this frame's menu bar. - * - * @param menuBar The new menu bar for this frame. - */ -public synchronized void -setMenuBar(MenuBar menuBar) -{ - if (peer != null) + /** + * Sets this frame's menu bar. Removes any existing menu bar. If the + * given menu bar is part of another frame it will be removed from + * that frame. + * + * @param menuBar the new menu bar for this frame + */ + public synchronized void setMenuBar(MenuBar menuBar) { if (this.menuBar != null) - this.menuBar.removeNotify(); + remove(this.menuBar); + + this.menuBar = menuBar; if (menuBar != null) - menuBar.addNotify(); - invalidateTree (); - ((FramePeer) peer).setMenuBar(menuBar); + { + MenuContainer parent = menuBar.getParent(); + if (parent != null) + parent.remove(menuBar); + menuBar.setParent(this); + + if (peer != null) + { + if (menuBar != null) + menuBar.addNotify(); + invalidateTree(); + ((FramePeer) peer).setMenuBar(menuBar); + } + } } - this.menuBar = menuBar; -} -/** - * Tests whether or not this frame is resizable. This will be - * true by default. - * - * @return true if this frame is resizable, false - * otherwise. - */ -public boolean -isResizable() -{ - return(resizable); -} + /** + * Tests whether or not this frame is resizable. This will be + * true by default. + * + * @return true if this frame is resizable, false + * otherwise + */ + public boolean isResizable() + { + return resizable; + } -/** - * Sets the resizability of this frame to the specified value. - * - * @param resizable true to make the frame resizable, - * false to make it non-resizable. - */ -public synchronized void -setResizable(boolean resizable) -{ - this.resizable = resizable; - if (peer != null) - ((FramePeer) peer).setResizable(resizable); -} + /** + * Sets the resizability of this frame to the specified value. + * + * @param resizable true to make the frame resizable, + * false to make it non-resizable + */ + public synchronized void setResizable(boolean resizable) + { + this.resizable = resizable; + if (peer != null) + ((FramePeer) peer).setResizable(resizable); + } -/** - * Returns the cursor type of the cursor for this window. This will - * be one of the constants in this class. - * - * @return The cursor type for this frame. - * - * @deprecated Use Component.getCursor() instead. - */ -public int -getCursorType() -{ - return(getCursor().getType()); -} + /** + * Returns the cursor type of the cursor for this window. This will + * be one of the constants in this class. + * + * @return the cursor type for this frame + * + * @deprecated Use Component.getCursor() instead. + */ + public int getCursorType() + { + return getCursor().getType(); + } -/** - * Sets the cursor for this window to the specified type. The specified - * type should be one of the constants in this class. - * - * @param type The cursor type. - * - * @deprecated Use Component.setCursor(Cursor) instead. - */ -public void -setCursor(int type) -{ - setCursor(new Cursor(type)); -} + /** + * Sets the cursor for this window to the specified type. The specified + * type should be one of the constants in this class. + * + * @param type the cursor type + * + * @deprecated Use Component.setCursor(Cursor) instead. + */ + public void setCursor(int type) + { + setCursor(new Cursor(type)); + } -/** - * Removes the specified component from this frame's menu. - * - * @param menu The menu component to remove. - */ -public void -remove(MenuComponent menu) -{ - menuBar.remove(menu); -} + /** + * Removes the specified menu component from this frame. If it is + * the current MenuBar it is removed from the frame. If it is a + * Popup it is removed from this component. If it is any other menu + * component it is ignored. + * + * @param menu the menu component to remove + */ + public void remove(MenuComponent menu) + { + if (menu == menuBar) + { + if (menuBar != null) + { + if (peer != null) + { + ((FramePeer) peer).setMenuBar(null); + menuBar.removeNotify(); + } + menuBar.setParent(null); + } + menuBar = null; + } + else + super.remove(menu); + } -public void -addNotify() -{ - if (menuBar != null) - menuBar.addNotify(); - if (peer == null) - peer = getToolkit ().createFrame (this); + public void addNotify() + { + if (menuBar != null) + menuBar.addNotify(); + if (peer == null) + peer = getToolkit ().createFrame (this); - super.addNotify(); -} + super.addNotify(); + } -public void removeNotify() -{ - if (menuBar != null) - menuBar.removeNotify(); - super.removeNotify(); -} + public void removeNotify() + { + if (menuBar != null) + menuBar.removeNotify(); + super.removeNotify(); + } /** * Returns a debugging string describing this window. * - * @return A debugging string describing this window. + * @return a debugging string describing this window */ - protected String paramString () + protected String paramString() { - String title = getTitle (); + String title = getTitle(); String resizable = ""; if (isResizable ()) @@ -455,17 +481,17 @@ public void removeNotify() return super.paramString () + ",title=" + title + resizable + state; } -private static ArrayList weakFrames = new ArrayList(); + private static ArrayList weakFrames = new ArrayList(); -private static void noteFrame(Frame f) -{ - weakFrames.add(new WeakReference(f)); -} + private static void noteFrame(Frame f) + { + weakFrames.add(new WeakReference(f)); + } -public static Frame[] getFrames() -{ - int n = 0; - synchronized (weakFrames) + public static Frame[] getFrames() + { + int n = 0; + synchronized (weakFrames) { Iterator i = weakFrames.iterator(); while (i.hasNext()) @@ -490,32 +516,31 @@ public static Frame[] getFrames() return frames; } } -} + } - public void setState (int state) + public void setState(int state) { int current_state = getExtendedState (); if (state == NORMAL && (current_state & ICONIFIED) != 0) - setExtendedState (current_state | ICONIFIED); + setExtendedState(current_state | ICONIFIED); if (state == ICONIFIED && (current_state & ~ICONIFIED) == 0) - setExtendedState (current_state & ~ICONIFIED); + setExtendedState(current_state & ~ICONIFIED); } - public int getState () + public int getState() { - /* FIXME: State might have changed in the peer... Must check. */ - + // FIXME: State might have changed in the peer... Must check. return (state & ICONIFIED) != 0 ? ICONIFIED : NORMAL; } /** * @since 1.4 */ - public void setExtendedState (int state) + public void setExtendedState(int state) { this.state = state; } @@ -523,7 +548,7 @@ public static Frame[] getFrames() /** * @since 1.4 */ - public int getExtendedState () + public int getExtendedState() { return state; } @@ -531,7 +556,7 @@ public static Frame[] getFrames() /** * @since 1.4 */ - public void setMaximizedBounds (Rectangle maximizedBounds) + public void setMaximizedBounds(Rectangle maximizedBounds) { this.maximizedBounds = maximizedBounds; } @@ -539,11 +564,11 @@ public static Frame[] getFrames() /** * Returns the maximized bounds of this frame. * - * @return the maximized rectangle, may be null. + * @return the maximized rectangle, may be null * * @since 1.4 */ - public Rectangle getMaximizedBounds () + public Rectangle getMaximizedBounds() { return maximizedBounds; } @@ -553,7 +578,7 @@ public static Frame[] getFrames() * * @since 1.4 */ - public boolean isUndecorated () + public boolean isUndecorated() { return undecorated; } @@ -562,14 +587,14 @@ public static Frame[] getFrames() * Disables or enables decorations for this frame. This method can only be * called while the frame is not displayable. * - * @exception IllegalComponentStateException If this frame is displayable. + * @throws IllegalComponentStateException if this frame is displayable * * @since 1.4 */ - public void setUndecorated (boolean undecorated) + public void setUndecorated(boolean undecorated) { - if (isDisplayable ()) - throw new IllegalComponentStateException (); + if (isDisplayable()) + throw new IllegalComponentStateException(); this.undecorated = undecorated; } @@ -577,14 +602,14 @@ public static Frame[] getFrames() /** * Generate a unique name for this frame. * - * @return A unique name for this frame. + * @return a unique name for this frame */ - String generateName () + String generateName() { - return "frame" + getUniqueLong (); + return "frame" + getUniqueLong(); } - private static synchronized long getUniqueLong () + private static synchronized long getUniqueLong() { return next_frame_number++; } @@ -617,10 +642,9 @@ public static Frame[] getFrames() */ public AccessibleContext getAccessibleContext() { - /* Create the context if this is the first request */ + // Create the context if this is the first request. if (accessibleContext == null) accessibleContext = new AccessibleAWTFrame(); return accessibleContext; } - } diff --git a/libjava/classpath/java/awt/Insets.java b/libjava/classpath/java/awt/Insets.java index 7238a34..6d5bd12 100644 --- a/libjava/classpath/java/awt/Insets.java +++ b/libjava/classpath/java/awt/Insets.java @@ -100,11 +100,31 @@ public class Insets implements Cloneable, Serializable } /** + * Set the contents of this Insets object to the specified values. + * + * @param top the top inset + * @param left the left inset + * @param bottom the bottom inset + * @param right the right inset + * + * @since 1.5 + */ + public void set(int top, int left, int bottom, int right) + { + this.top = top; + this.left = left; + this.bottom = bottom; + this.right = right; + } + + /** * Tests whether this object is equal to the specified object. The other * object must be an instance of Insets with identical field values. * * @param obj the object to test against * @return true if the specified object is equal to this one + * + * @since 1.1 */ public boolean equals(Object obj) { diff --git a/libjava/classpath/java/awt/LightweightDispatcher.java b/libjava/classpath/java/awt/LightweightDispatcher.java new file mode 100644 index 0000000..6573b12 --- /dev/null +++ b/libjava/classpath/java/awt/LightweightDispatcher.java @@ -0,0 +1,200 @@ +/* LightweightDispatcher.java -- Dispatches mouse events to lightweights + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt; + +import gnu.java.awt.AWTUtilities; + +import java.awt.event.MouseEvent; +import java.util.WeakHashMap; + +/** + * Redispatches mouse events to lightweight components. The native peers know + * nothing about the lightweight components and thus mouse events are always + * targetted at Windows or heavyweight components. This class listenes directly + * on the eventqueue and dispatches mouse events to lightweight components. + * + * @author Roman Kennke (kennke@aicas.com) + */ +class LightweightDispatcher +{ + + /** + * Maps thread groups to lightweight dispatcher instances. We need to + * have one instance per thread group so that 2 or more applets or otherwise + * separated applications (like in OSGI) do not interfer with each other. + */ + private static WeakHashMap instances = new WeakHashMap(); + + /** + * The component that is the start of a mouse dragging. All MOUSE_DRAGGED + * events that follow the initial press must have the source set to this, + * as well as the MOUSE_RELEASED event following the dragging. + */ + private Component dragTarget; + + /** + * The last mouse event target. If the target changes, additional + * MOUSE_ENTERED and MOUSE_EXITED events must be dispatched. + */ + private Component lastTarget; + + /** + * Returns an instance of LightweightDispatcher for the current thread's + * thread group. + * + * @return an instance of LightweightDispatcher for the current thread's + * thread group + */ + static LightweightDispatcher getInstance() + { + Thread t = Thread.currentThread(); + ThreadGroup tg = t.getThreadGroup(); + LightweightDispatcher instance = (LightweightDispatcher) instances.get(tg); + if (instance == null) + { + instance = new LightweightDispatcher(); + instances.put(tg, instance); + } + return instance; + } + + /** + * Creates a new LightweightDispatcher. This is private to prevent access + * from outside. Use {@link #getInstance()} instead. + */ + private LightweightDispatcher() + { + // Nothing to do here. + } + + /** + * Receives notification if a mouse event passes along the eventqueue. + * + * @param event the event + */ + public boolean dispatchEvent(AWTEvent event) + { + boolean dispatched = false; + if (event instanceof MouseEvent && event.getSource() instanceof Window) + { + MouseEvent mouseEvent = (MouseEvent) event; + handleMouseEvent(mouseEvent); + dispatched = true; + } + return dispatched; + } + + /** + * Handles all mouse events that are targetted at toplevel containers + * (Window instances) and dispatches them to the correct lightweight child. + * + * @param ev the mouse event + */ + private void handleMouseEvent(MouseEvent ev) + { + Window window = (Window) ev.getSource(); + Component target = window.findComponentAt(ev.getX(), ev.getY()); + if (target != null && target.isLightweight()) + { + // Dispatch additional MOUSE_EXITED and MOUSE_ENTERED if event target + // is different from the last event target. + if (target != lastTarget) + { + if (lastTarget != null) + { + Point p1 = AWTUtilities.convertPoint(window, ev.getX(), + ev.getY(), lastTarget); + MouseEvent mouseExited = + new MouseEvent(lastTarget, MouseEvent.MOUSE_EXITED, + ev.getWhen(), ev.getModifiers(), p1.x, p1.y, + ev.getClickCount(), ev.isPopupTrigger()); + lastTarget.dispatchEvent(mouseExited); + } + Point p = AWTUtilities.convertPoint(window, ev.getX(), ev.getY(), + target); + MouseEvent mouseEntered = + new MouseEvent(target, MouseEvent.MOUSE_ENTERED, ev.getWhen(), + ev.getModifiers(), p.x, p.y, ev.getClickCount(), + ev.isPopupTrigger()); + target.dispatchEvent(mouseEntered); + } + + switch (ev.getID()) + { + case MouseEvent.MOUSE_PRESSED: + dragTarget = target; + break; + case MouseEvent.MOUSE_RELEASED: + if (dragTarget != null) + target = dragTarget; + dragTarget = null; + break; + case MouseEvent.MOUSE_CLICKED: + // When we receive a MOUSE_CLICKED, we set the target to the + // previous target, which must have been a MOUSE_RELEASED event. + // This is necessary for the case when the MOUSE_RELEASED has + // caused the original target (like an internal component) go + // away. + target = lastTarget; + break; + case MouseEvent.MOUSE_DRAGGED: + target = dragTarget; + break; + default: + // Do nothing in other cases. + break; + } + + lastTarget = target; + + Point targetCoordinates = + AWTUtilities.convertPoint(window, ev.getX(), ev.getY(), target); + int dx = targetCoordinates.x - ev.getX(); + int dy = targetCoordinates.y - ev.getY(); + ev.translatePoint(dx, dy); + ev.setSource(target); + target.dispatchEvent(ev); + + // We reset the event, so that the normal event dispatching is not + // influenced by this modified event. + ev.setSource(window); + ev.translatePoint(-dx, -dy); + } + } +} diff --git a/libjava/classpath/java/awt/Menu.java b/libjava/classpath/java/awt/Menu.java index 13ebb52..6daec72 100644 --- a/libjava/classpath/java/awt/Menu.java +++ b/libjava/classpath/java/awt/Menu.java @@ -1,5 +1,5 @@ /* Menu.java -- A Java AWT Menu - Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -220,15 +220,16 @@ getItem(int index) public MenuItem add(MenuItem item) { + MenuContainer parent = item.getParent(); + if (parent != null) + parent.remove(item); + items.addElement(item); - if (item.parent != null) - { - item.parent.remove(item); - } - item.parent = this; + item.setParent(this); if (peer != null) { + item.addNotify(); MenuPeer mp = (MenuPeer) peer; mp.addItem(item); } @@ -266,26 +267,33 @@ insert(MenuItem item, int index) if (index < 0) throw new IllegalArgumentException("Index is less than zero"); - MenuPeer peer = (MenuPeer) getPeer(); - if (peer == null) - return; - int count = getItemCount (); if (index >= count) - peer.addItem (item); + add(item); else { + MenuContainer parent = item.getParent(); + if (parent != null) + parent.remove(item); + + items.insertElementAt(item, index); + item.setParent(this); + + MenuPeer peer = (MenuPeer) getPeer(); + if (peer == null) + return; + for (int i = count - 1; i >= index; i--) - peer.delItem (i); + peer.delItem(i); - peer.addItem (item); + item.addNotify(); + peer.addItem(item); for (int i = index; i < count; i++) - peer.addItem ((MenuItem) items.elementAt (i)); + peer.addItem((MenuItem) items.elementAt (i)); } - items.insertElementAt(item, index); } /*************************************************************************/ @@ -344,11 +352,15 @@ insertSeparator(int index) public synchronized void remove(int index) { - items.removeElementAt(index); + MenuItem item = (MenuItem) items.remove(index); - MenuPeer mp = (MenuPeer)getPeer(); + MenuPeer mp = (MenuPeer) getPeer(); if (mp != null) - mp.delItem(index); + { + mp.delItem(index); + item.removeNotify(); + } + item.setParent(null); } /*************************************************************************/ @@ -393,14 +405,21 @@ removeAll() public void addNotify() { + MenuPeer peer = (MenuPeer) getPeer(); if (peer == null) - peer = getToolkit().createMenu(this); + { + peer = getToolkit().createMenu(this); + setPeer(peer); + } + Enumeration e = items.elements(); while (e.hasMoreElements()) { MenuItem mi = (MenuItem)e.nextElement(); mi.addNotify(); - } + peer.addItem(mi); + } + super.addNotify (); } diff --git a/libjava/classpath/java/awt/MenuBar.java b/libjava/classpath/java/awt/MenuBar.java index 4089fe1..3c6b915 100644 --- a/libjava/classpath/java/awt/MenuBar.java +++ b/libjava/classpath/java/awt/MenuBar.java @@ -1,5 +1,6 @@ /* MenuBar.java -- An AWT menu bar class - Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2006 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,7 +40,6 @@ exception statement from your version. */ package java.awt; import java.awt.peer.MenuBarPeer; -import java.awt.peer.MenuComponentPeer; import java.io.Serializable; import java.util.Enumeration; @@ -60,364 +60,311 @@ public class MenuBar extends MenuComponent implements MenuContainer, Serializable, Accessible { -/* - * Static Variables - */ +//Serialization Constant + private static final long serialVersionUID = -4930327919388951260L; -// Serialization Constant -private static final long serialVersionUID = -4930327919388951260L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * @serial The menu used for providing help information - */ -private Menu helpMenu; + /** + * @serial The menu used for providing help information + */ + private Menu helpMenu; -/** - * @serial The menus contained in this menu bar. - */ -private Vector menus = new Vector(); + /** + * @serial The menus contained in this menu bar. + */ + private Vector menus = new Vector(); /** - * The accessible context for this component. + * Initializes a new instance of MenuBar. * - * @see #getAccessibleContext() - * @serial ignored. + * @throws HeadlessException if GraphicsEnvironment.isHeadless() is true */ - private transient AccessibleContext accessibleContext; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of MenuBar. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -MenuBar() -{ - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Returns the help menu for this menu bar. This may be null. - * - * @return The help menu for this menu bar. - */ -public Menu -getHelpMenu() -{ - return(helpMenu); -} - -/*************************************************************************/ - -/** - * Sets the help menu for this menu bar. - * - * @param menu The new help menu for this menu bar. - */ -public synchronized void -setHelpMenu(Menu menu) -{ - if (helpMenu != null) - { - helpMenu.removeNotify (); - helpMenu.parent = null; - } - helpMenu = menu; - - if (menu.parent != null) - menu.parent.remove (menu); - menu.parent = this; - - MenuBarPeer peer = (MenuBarPeer) getPeer (); - if (peer != null) - { - menu.addNotify(); - peer.addHelpMenu (menu); - } -} - -/*************************************************************************/ - -/** Add a menu to this MenuBar. If the menu has already has a - * parent, it is first removed from its old parent before being - * added. - * - * @param menu The menu to add. - * - * @return The menu that was added. - */ -public synchronized Menu -add(Menu menu) -{ - if (menu.parent != null) - menu.parent.remove (menu); - - menu.parent = this; - menus.addElement(menu); - - if (peer != null) - { - menu.addNotify(); - } - - return(menu); -} - -/*************************************************************************/ + public MenuBar() + { + if (GraphicsEnvironment.isHeadless()) + throw new HeadlessException(); + } -/** - * Removes the menu at the specified index. - * - * @param index The index of the menu to remove from the menu bar. - */ -public synchronized void -remove(int index) -{ - Menu m = (Menu) menus.get (index); - menus.remove (index); - m.removeNotify (); - m.parent = null; + /** + * Returns the help menu for this menu bar. This may be null. + * + * @return the help menu for this menu bar + */ + public Menu getHelpMenu() + { + return helpMenu; + } - if (peer != null) - { - MenuBarPeer mp = (MenuBarPeer) peer; - mp.delMenu (index); - } -} + /** + * Sets the help menu for this menu bar. + * + * @param menu the new help menu for this menu bar + */ + public synchronized void setHelpMenu(Menu menu) + { + MenuBarPeer myPeer = (MenuBarPeer) getPeer (); + + if (helpMenu != null) + { + if (myPeer != null) + helpMenu.removeNotify(); + helpMenu.setParent(null); + } + helpMenu = menu; + + MenuContainer parent = menu.getParent(); + if (parent != null) + parent.remove(menu); + menu.setParent(this); + + if (myPeer != null) + { + menu.addNotify(); + myPeer.addHelpMenu(menu); + } + } -/*************************************************************************/ + /** + * Add a menu to this MenuBar. If the menu has already has a + * parent, it is first removed from its old parent before being + * added. + * + * @param menu the menu to add + * + * @return the menu that was added + */ + public synchronized Menu add(Menu menu) + { + MenuBarPeer myPeer = (MenuBarPeer) getPeer (); -/** - * Removes the specified menu from the menu bar. - * - * @param menu The menu to remove from the menu bar. - */ -public void -remove(MenuComponent menu) -{ - int index = menus.indexOf(menu); - if (index == -1) - return; + MenuContainer parent = menu.getParent(); + if (parent != null) + parent.remove(menu); - remove(index); -} + menus.addElement(menu); + menu.setParent(this); -/*************************************************************************/ + if (myPeer != null) + { + menu.addNotify(); + myPeer.addMenu(menu); + } + return menu; + } -/** - * Returns the number of elements in this menu bar. - * - * @return The number of elements in the menu bar. - */ -public int -getMenuCount() -{ - return countMenus (); -} + /** + * Removes the menu at the specified index. + * + * @param index the index of the menu to remove from the menu bar + */ + public synchronized void remove(int index) + { + Menu m = (Menu) menus.remove(index); + MenuBarPeer mp = (MenuBarPeer) getPeer(); -/*************************************************************************/ + if (mp != null) + m.removeNotify(); -/** - * Returns the number of elements in this menu bar. - * - * @return The number of elements in the menu bar. - * - * @deprecated This method is deprecated in favor of getMenuCount(). - */ -public int -countMenus() -{ - return menus.size () + (getHelpMenu () == null ? 0 : 1); -} + m.setParent(null); -/*************************************************************************/ + if (mp != null) + mp.delMenu(index); + } -/** - * Returns the menu at the specified index. - * - * @param index the index of the menu - * - * @return The requested menu. - * - * @exception ArrayIndexOutOfBoundsException If the index is not valid. - */ -public Menu -getMenu(int index) -{ - return((Menu)menus.elementAt(index)); -} + /** + * Removes the specified menu from the menu bar. + * + * @param menu the menu to remove from the menu bar + */ + public void remove(MenuComponent menu) + { + int index = menus.indexOf(menu); + if (index == -1) + return; -/*************************************************************************/ + remove(index); + } -/** - * Creates this object's native peer. - */ -public void -addNotify() -{ - if (getPeer() == null) - setPeer((MenuComponentPeer)getToolkit().createMenuBar(this)); - Enumeration e = menus.elements(); - while (e.hasMoreElements()) + /** + * Returns the number of elements in this menu bar. + * + * @return the number of elements in the menu bar + */ + public int getMenuCount() { - Menu mi = (Menu)e.nextElement(); - mi.addNotify(); + return countMenus(); } - if (helpMenu != null) + + /** + * Returns the number of elements in this menu bar. + * + * @return the number of elements in the menu bar + * + * @deprecated This method is deprecated in favor of + * getMenuCount(). + */ + public int countMenus() { - helpMenu.addNotify(); - ((MenuBarPeer) peer).addHelpMenu(helpMenu); + return menus.size() + (getHelpMenu() == null ? 0 : 1); } -} -/*************************************************************************/ - -/** - * Destroys this object's native peer. - */ -public void -removeNotify() -{ - Enumeration e = menus.elements(); - while (e.hasMoreElements()) + /** + * Returns the menu at the specified index. + * + * @param index the index of the menu + * + * @return the requested menu + * + * @throws ArrayIndexOutOfBoundsException if the index is not valid + */ + public Menu getMenu(int index) { - Menu mi = (Menu) e.nextElement(); - mi.removeNotify(); + return (Menu) menus.elementAt(index); } - super.removeNotify(); -} - -/*************************************************************************/ - -/** - * Returns a list of all shortcuts for the menus in this menu bar. - * - * @return A list of all shortcuts for the menus in this menu bar. - */ -public synchronized Enumeration -shortcuts() -{ - Vector shortcuts = new Vector(); - Enumeration e = menus.elements(); - - while (e.hasMoreElements()) - { - Menu menu = (Menu)e.nextElement(); - if (menu.getShortcut() != null) - shortcuts.addElement(menu.getShortcut()); - } - return(shortcuts.elements()); -} + /** + * Creates this object's native peer. + */ + public void addNotify() + { + MenuBarPeer peer = (MenuBarPeer) getPeer(); + if (peer == null) + { + peer = getToolkit().createMenuBar(this); + setPeer(peer); + } + + Enumeration e = menus.elements(); + while (e.hasMoreElements()) + { + Menu mi = (Menu)e.nextElement(); + mi.addNotify(); + peer.addMenu(mi); + } + + if (helpMenu != null) + { + helpMenu.addNotify(); + peer.addHelpMenu(helpMenu); + } + } -/*************************************************************************/ + /** + * Destroys this object's native peer. + */ + public void removeNotify() + { + Enumeration e = menus.elements(); + while (e.hasMoreElements()) + { + Menu mi = (Menu) e.nextElement(); + mi.removeNotify(); + } + super.removeNotify(); + } -/** - * Returns the menu item for the specified shortcut, or null - * if no such item exists. - * - * @param shortcut The shortcut to return the menu item for. - * - * @return The menu item for the specified shortcut. - */ -public MenuItem -getShortcutMenuItem(MenuShortcut shortcut) -{ - Enumeration e = menus.elements(); + /** + * Returns a list of all shortcuts for the menus in this menu bar. + * + * @return a list of all shortcuts for the menus in this menu bar + */ + public synchronized Enumeration shortcuts() + { + Vector shortcuts = new Vector(); + Enumeration e = menus.elements(); - while (e.hasMoreElements()) - { - Menu menu = (Menu)e.nextElement(); - MenuShortcut s = menu.getShortcut(); - if ((s != null) && (s.equals(shortcut))) - return(menu); - } + while (e.hasMoreElements()) + { + Menu menu = (Menu)e.nextElement(); + if (menu.getShortcut() != null) + shortcuts.addElement(menu.getShortcut()); + } - return(null); -} + return shortcuts.elements(); + } -/*************************************************************************/ + /** + * Returns the menu item for the specified shortcut, or null + * if no such item exists. + * + * @param shortcut the shortcut to return the menu item for + * + * @return the menu item for the specified shortcut + */ + public MenuItem getShortcutMenuItem(MenuShortcut shortcut) + { + Enumeration e = menus.elements(); -/** - * Deletes the specified menu shortcut. - * - * @param shortcut The shortcut to delete. - */ -public void -deleteShortcut(MenuShortcut shortcut) -{ - MenuItem it; - // This is a slow implementation, but it probably doesn't matter. - while ((it = getShortcutMenuItem (shortcut)) != null) - it.deleteShortcut (); -} + while (e.hasMoreElements()) + { + Menu menu = (Menu) e.nextElement(); + MenuShortcut s = menu.getShortcut(); + if ((s != null) && s.equals(shortcut)) + return menu; + } -/** - * Gets the AccessibleContext associated with this MenuBar. - * The context is created, if necessary. - * - * @return the associated context - */ -public AccessibleContext getAccessibleContext() -{ - /* Create the context if this is the first request */ - if (accessibleContext == null) - accessibleContext = new AccessibleAWTMenuBar(); - return accessibleContext; -} + return null; + } -/** - * This class provides accessibility support for AWT menu bars. - * - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - */ -protected class AccessibleAWTMenuBar - extends AccessibleAWTMenuComponent -{ - /** - * Compatible with JDK 1.4.2 revision 5 + * Deletes the specified menu shortcut. + * + * @param shortcut the shortcut to delete */ - private static final long serialVersionUID = -8577604491830083815L; + public void deleteShortcut(MenuShortcut shortcut) + { + MenuItem it; + // This is a slow implementation, but it probably doesn't matter. + while ((it = getShortcutMenuItem (shortcut)) != null) + it.deleteShortcut(); + } /** - * This is the default constructor, which simply calls the default - * constructor of the superclass. + * Gets the AccessibleContext associated with this MenuBar. + * The context is created, if necessary. + * + * @return the associated context */ - protected AccessibleAWTMenuBar() + public AccessibleContext getAccessibleContext() { - super(); + // Create the context if this is the first request. + if (accessibleContext == null) + accessibleContext = new AccessibleAWTMenuBar(); + return accessibleContext; } /** - * Returns the accessible role relating to the menu bar. + * This class provides accessibility support for AWT menu bars. * - * @return AccessibleRole.MENU_BAR. + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) */ - public AccessibleRole getAccessibleRole() + protected class AccessibleAWTMenuBar + extends AccessibleAWTMenuComponent { - return AccessibleRole.MENU_BAR; - } + + /** + * Compatible with JDK 1.4.2 revision 5 + */ + private static final long serialVersionUID = -8577604491830083815L; + + /** + * This is the default constructor, which simply calls the default + * constructor of the superclass. + */ + protected AccessibleAWTMenuBar() + { + super(); + } -} // class AccessibleAWTMenuBar + /** + * Returns the accessible role relating to the menu bar. + * + * @return AccessibleRole.MENU_BAR + */ + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.MENU_BAR; + } -} // class MenuBar + } + +} diff --git a/libjava/classpath/java/awt/MenuComponent.java b/libjava/classpath/java/awt/MenuComponent.java index 375d084..9bb8750 100644 --- a/libjava/classpath/java/awt/MenuComponent.java +++ b/libjava/classpath/java/awt/MenuComponent.java @@ -1,5 +1,6 @@ /* MenuComponent.java -- Superclass of all AWT menu components - Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -60,26 +61,16 @@ import javax.accessibility.AccessibleStateSet; public abstract class MenuComponent implements Serializable { -/* - * Static Variables - */ +//Serialization Constant + private static final long serialVersionUID = -4536902356223894379L; -// Serialization Constant -private static final long serialVersionUID = -4536902356223894379L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * The font for this component. - * - * @see #getFont() - * @see #setFont(java.awt.Font) - * @serial the component's font. - */ + /** + * The font for this component. + * + * @see #getFont() + * @see #setFont(java.awt.Font) + * @serial the component's font. + */ private Font font; /** @@ -165,1160 +156,1133 @@ private static final long serialVersionUID = -4536902356223894379L; */ transient FocusListener focusListener; -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Default constructor for subclasses. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -MenuComponent() -{ - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); -} - -/*************************************************************************/ - -/* - * Instance Methods - */ + /** + * Default constructor for subclasses. + * + * @throws HeadlessException ff GraphicsEnvironment.isHeadless() is true + */ + public MenuComponent() + { + if (GraphicsEnvironment.isHeadless()) + throw new HeadlessException(); + } /** * Returns the font in use for this component. * - * @return The font for this component. - */ -public Font -getFont() -{ - if (font != null) - return font; - - if (parent != null) - return parent.getFont (); - - return null; -} - -/*************************************************************************/ - -/** - * Sets the font for this component to the specified font. - * - * @param font The new font for this component. - */ -public void -setFont(Font font) -{ - this.font = font; -} - -/*************************************************************************/ - -/** - * Returns the name of this component. - * - * @return The name of this component. - */ -public String -getName() -{ - return(name); -} - -/*************************************************************************/ - -/** - * Sets the name of this component to the specified name. - * - * @param name The new name of this component. - */ -public void -setName(String name) -{ - this.name = name; - nameExplicitlySet = true; -} - -/*************************************************************************/ - -/** - * Returns the parent of this component. - * - * @return The parent of this component. - */ -public MenuContainer -getParent() -{ - return(parent); -} - -/*************************************************************************/ - -// Sets the parent of this component. -final void -setParent(MenuContainer parent) -{ - this.parent = parent; -} - -/*************************************************************************/ - -/** - * Returns the native windowing system peer for this component. - * - * @return The peer for this component. - * - * @deprecated - */ -public MenuComponentPeer -getPeer() -{ - return(peer); -} - -/*************************************************************************/ - -// Sets the peer for this component. -final void -setPeer(MenuComponentPeer peer) -{ - this.peer = peer; -} - -/*************************************************************************/ - -/** - * Destroys this component's native peer - */ -public void -removeNotify() -{ - if (peer != null) - peer.dispose(); - peer = null; -} - -/*************************************************************************/ - -/** - * Returns the toolkit in use for this component. - * - * @return The toolkit for this component. - */ -final Toolkit -getToolkit() -{ - return(toolkit); -} - -/*************************************************************************/ - -/** - * Returns the object used for synchronization locks on this component - * when performing tree and layout functions. - * - * @return The synchronization lock for this component. - */ -protected final Object -getTreeLock() -{ - return(tree_lock); -} - -/*************************************************************************/ - -// The sync lock object for this component. -final void -setTreeLock(Object tree_lock) -{ - this.tree_lock = tree_lock; -} - -/*************************************************************************/ - -/** - * AWT 1.0 event dispatcher. - * - * @deprecated Deprecated in favor of dispatchEvent(). - * @return true if the event was dispatched, false otherwise. - */ -public boolean -postEvent(Event event) -{ - // This is overridden by subclasses that support events. - return false; -} -/*************************************************************************/ - -/** - * Sends this event to this component or a subcomponent for processing. - * - * @param event The event to dispatch - */ -public final void dispatchEvent(AWTEvent event) -{ - // See comment in Component.dispatchEvent(). - dispatchEventImpl(event); -} - - -/** - * Implementation of dispatchEvent. Allows trusted package classes - * to dispatch additional events first. This implementation first - * translates event to an AWT 1.0 event and sends the - * result to {@link #postEvent}. The event is then - * passed on to {@link #processEvent} for local processing. - * - * @param event the event to dispatch. - */ -void dispatchEventImpl(AWTEvent event) -{ - Event oldStyleEvent; - - // This is overridden by subclasses that support events. - /* Convert AWT 1.1 event to AWT 1.0 event */ - oldStyleEvent = Component.translateEvent(event); - if (oldStyleEvent != null) - { - postEvent(oldStyleEvent); - } - /* Do local processing */ - processEvent(event); -} - -/*************************************************************************/ - -/** - * Processes the specified event. In this class, this method simply - * calls one of the more specific event handlers. - * - * @param event The event to process. - */ -protected void -processEvent(AWTEvent event) -{ - /* - Pass a focus event to the focus listener for - the accessibility context. - */ - if (event instanceof FocusEvent) - { - if (focusListener != null) - { - switch (event.id) - { - case FocusEvent.FOCUS_GAINED: - focusListener.focusGained((FocusEvent) event); - break; - case FocusEvent.FOCUS_LOST: - focusListener.focusLost((FocusEvent) event); - break; - } - } - } -} - -/*************************************************************************/ - -/** - * Returns a string representation of this component. - * - * @return A string representation of this component + * @return the font for this component */ -public String -toString() -{ - return this.getClass().getName() + "[" + paramString() + "]"; -} - -/*************************************************************************/ - -/** - * Returns a debugging string for this component - */ -protected String -paramString() -{ - return "name=" + getName(); -} - -/** - * Gets the AccessibleContext associated with this MenuComponent. - * As an abstract class, we return null. Concrete subclasses should return - * their implementation of the accessibility context. - * - * @return null. - */ - -public AccessibleContext getAccessibleContext() -{ - return null; -} + public Font getFont() + { + if (font != null) + return font; -/** - * This class provides a base for the accessibility support of menu - * components. - * - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - */ -protected abstract class AccessibleAWTMenuComponent - extends AccessibleContext - implements Serializable, AccessibleComponent, AccessibleSelection -{ + if (parent != null) + return parent.getFont(); - /** - * Compatible with JDK 1.4.2 revision 5 - */ - private static final long serialVersionUID = -4269533416223798698L; - - /** - * This is the default constructor. It should be called by - * concrete subclasses to ensure necessary groundwork is completed. - */ - protected AccessibleAWTMenuComponent() - { + return null; } /** - * Replaces or supplements the component's selection with the - * Accessible child at the supplied index. If - * the component supports multiple selection, the child is - * added to the current selection. Otherwise, the current - * selection becomes the specified child. If the child is - * already selected, nothing happens. - *
    - *
    - * As the existence of children can not be determined from - * this abstract class, the implementation of this method - * is left to subclasses. + * Sets the font for this component to the specified font. * - * @param index the index of the specified child within a - * zero-based list of the component's children. + * @param font the new font for this component */ - public void addAccessibleSelection(int index) + public void setFont(Font font) { - /* Subclasses with children should implement this */ + this.font = font; } /** - * Registers the specified focus listener to receive - * focus events from this component. + * Returns the name of this component. * - * @param listener the new focus listener. + * @return the name of this component */ - public void addFocusListener(FocusListener listener) + public String getName() { - /* - * Chain the new focus listener to the existing chain - * of focus listeners. Each new focus listener is - * coupled via multicasting to the existing chain. - */ - focusListener = AWTEventMulticaster.add(focusListener, listener); + return name; } /** - * Clears the component's current selection. Following - * the calling of this method, no children of the component - * will be selected. - *
    - *
    - * As the existence of children can not be determined from - * this abstract class, the implementation of this method - * is left to subclasses. - */ - public void clearAccessibleSelection() - { - } - - /** - * Returns true if the specified point lies within the - * component. The supplied co-ordinates are assumed to - * be relative to the co-ordinate system of the component - * itself. Thus, the point (0,0) is the upper left corner - * of this component. - *
    - *
    - * Please note that this method depends on a correctly implemented - * version of the getBounds() method. Subclasses - * must provide the bounding rectangle via getBounds() - * in order for this method to work. + * Sets the name of this component to the specified name. * - * @param point the point to check against this component. - * @return true if the point is within this component. - * @see #getBounds() + * @param name the new name of this component */ - public boolean contains(Point point) + public void setName(String name) { - /* - We can simply return the result of a - test for containment in the bounding rectangle - */ - return getBounds().contains(point); + this.name = name; + nameExplicitlySet = true; } /** - * Returns the Accessible child of this component present - * at the specified point. The supplied co-ordinates are - * assumed to be relative to the co-ordinate system of this - * component (the parent of any returned accessible). Thus, - * the point (0,0) is the upper left corner of this menu - * component. - *
    - *
    - * As the existence of children can not be determined from - * this abstract class, the implementation of this method - * is left to subclasses. + * Returns the parent of this component. * - * @param point the point at which the returned accessible - * is located. - * @return null. + * @return the parent of this component */ - public Accessible getAccessibleAt(Point point) + public MenuContainer getParent() { - return null; - } + return parent; + } /** - * Returns the Accessible child at the supplied - * index within the list of children of this component. - *
    - *
    - * As the existence of children can not be determined from - * this abstract class, the implementation of this method - * is left to subclasses. + * Sets the parent of this component. * - * @param index the index of the Accessible child - * to retrieve. - * @return null. + * @param parent the parent to set */ - public Accessible getAccessibleChild(int index) + final void setParent(MenuContainer parent) { - return null; + this.parent = parent; } /** - * Returns the number of children of this component which - * implement the Accessible interface. If - * all children of this component are accessible, then - * the returned value will be the same as the number of - * children. - *
    - *
    + * Returns the native windowing system peer for this component. + * + * @return the peer for this component * - * @return 0. + * @deprecated */ - public int getAccessibleChildrenCount() + public MenuComponentPeer getPeer() { - return 0; + return peer; } /** - * Retrieves the AccessibleComponent associated - * with this accessible context and its component. As the - * context itself implements AccessibleComponent, - * this is the return value. + * Sets the peer for this component. * - * @return the context itself. + * @param peer the peer to set */ - public AccessibleComponent getAccessibleComponent() + final void setPeer(MenuComponentPeer peer) { - return this; + this.peer = peer; } /** - * Returns the accessible name for this menu component. This - * is the name given to the component, which may be null if - * not set using setName(). - *
    - *
    - * The name is not the most appropriate description of this - * object. Subclasses should preferably provide a more - * accurate description. For example, a File menu could - * have the description `Lists commands related to the - * file system'. - * - * @return a description of the component. Currently, - * this is just the contents of the name property. - * @see MenuComponent#setName(String) + * Destroys this component's native peer */ - public String getAccessibleDescription() + public void removeNotify() { - return MenuComponent.this.getName(); + if (peer != null) + peer.dispose(); + peer = null; } /** - * Retrieves the index of this component within its parent. - * If no parent exists, -1 is returned. + * Returns the toolkit in use for this component. * - * @return -1 as the parent, a MenuContainer - * is not Accessible. + * @return the toolkit for this component */ - public int getAccessibleIndexInParent() + final Toolkit getToolkit() { - return -1; + return toolkit; } /** - * Returns the accessible name of this component. This - * is the name given to the component, which may be null if - * not set using setName(). - *
    - *
    - * The name property is not the most suitable string to return - * for this method. The string should be localized, and - * relevant to the operation of the component. For example, - * it could be the text of a menu item. However, this can - * not be used at this level of abstraction, so it is the - * responsibility of subclasses to provide a more appropriate - * name. + * Returns the object used for synchronization locks on this component + * when performing tree and layout functions. * - * @return a localized name for this component. Currently, this - * is just the contents of the name property. - * @see MenuComponent#setName(String) + * @return the synchronization lock for this component */ - public String getAccessibleName() + protected final Object getTreeLock() { - return MenuComponent.this.getName(); + return tree_lock; } /** - * Returns the Accessible parent of this component. - * As the parent of a MenuComponent is a - * MenuContainer, which doesn't implement - * Accessible, this method returns null. + * Sets the sync lock object for this component. * - * @return null. + * @param treeLock the sync lock to set */ - public Accessible getAccessibleParent() + final void setTreeLock(Object treeLock) { - return null; + this.tree_lock = treeLock; } /** - * Returns the accessible role of this component. - *
    - *
    - * The abstract implementation of this method returns - * AccessibleRole.AWT_COMPONENT, - * as the abstract component has no specific role. This - * method should be overridden by concrete subclasses, so - * as to return an appropriate role for the component. + * AWT 1.0 event dispatcher. * - * @return AccessibleRole.AWT_COMPONENT. + * @return true if the event was dispatched, false otherwise + * + * @deprecated Deprecated in favor of dispatchEvent(). */ - public AccessibleRole getAccessibleRole() + public boolean + postEvent(Event event) { - return AccessibleRole.AWT_COMPONENT; + boolean retVal = false; + MenuContainer parent = getParent(); + if (parent != null) + retVal = parent.postEvent(event); + + return retVal; } /** - * Retrieves the AccessibleSelection associated - * with this accessible context and its component. As the - * context itself implements AccessibleSelection, - * this is the return value. + * Sends this event to this component or a subcomponent for processing. * - * @return the context itself. + * @param event The event to dispatch */ - public AccessibleSelection getAccessibleSelection() + public final void dispatchEvent(AWTEvent event) { - return this; + // Convert AWT 1.1 event to AWT 1.0 event. + Event oldStyleEvent = Component.translateEvent(event); + if (oldStyleEvent != null) + { + postEvent(oldStyleEvent); + } + + // See comment in Component.dispatchEvent(). + dispatchEventImpl(event); } /** - * Retrieves the Accessible selected child - * at the specified index. If there are no selected children - * or the index is outside the range of selected children, - * null is returned. Please note that the index refers - * to the index of the child in the list of selected - * children, and not the index of the child in - * the list of all Accessible children. - *
    - *
    - * As the existence of children can not be determined from - * this abstract class, the implementation of this method - * is left to subclasses. + * Implementation of dispatchEvent. Allows trusted package classes + * to dispatch additional events first. This implementation first + * translates event to an AWT 1.0 event and sends the + * result to {@link #postEvent}. The event is then + * passed on to {@link #processEvent} for local processing. * - * @param index the index of the selected Accessible - * child. + * @param event the event to dispatch */ - public Accessible getAccessibleSelection(int index) + void dispatchEventImpl(AWTEvent event) { - return null; + // Do local processing. + processEvent(event); } /** - * Returns a count of the number of Accessible - * children of this component which are currently selected. - * If there are no children currently selected, 0 is returned. - *
    - *
    - * As the existence of children can not be determined from - * this abstract class, the implementation of this method - * is left to subclasses. - * - * @return 0. + * Processes the specified event. In this class, this method simply + * calls one of the more specific event handlers. + * + * @param event the event to process */ - public int getAccessibleSelectionCount() + protected void processEvent(AWTEvent event) { - return 0; + // Pass a focus event to the focus listener for + // the accessibility context. + if (event instanceof FocusEvent) + { + if (focusListener != null) + { + switch (event.id) + { + case FocusEvent.FOCUS_GAINED: + focusListener.focusGained((FocusEvent) event); + break; + case FocusEvent.FOCUS_LOST: + focusListener.focusLost((FocusEvent) event); + break; + } + } + } } /** - * Retrieves the current state of this component - * in an accessible form. For example, a given component - * may be visible, selected, disabled, etc. - *
    - *
    - * As this class tells us virtually nothing about the component, - * except for its name and font, no state information can be - * provided. This implementation thus returns an empty - * state set, and it is left to concrete subclasses to provide - * a more acceptable and relevant state set. Changes to these - * properties also need to be handled using - * PropertyChangeListeners. + * Returns a string representation of this component. * - * @return an empty AccessibleStateSet. + * @return a string representation of this component */ - public AccessibleStateSet getAccessibleStateSet() + public String toString() { - return new AccessibleStateSet(); + return getClass().getName() + "[" + paramString() + "]"; } /** - * Returns the background color of the component, or null - * if this property is unsupported. - *
    - *
    - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply returns the - * default system background color used for rendering menus. - * Concrete subclasses which handle the drawing of an onscreen - * menu component should override this method and provide - * the appropriate information. - * - * @return the default system background color for menus. - * @see #setBackground(java.awt.Color) + * Returns a debugging string for this component */ - public Color getBackground() + protected String paramString() { - return SystemColor.menu; + return "name=" + getName(); } /** - * Returns a Rectangle which represents the - * bounds of this component. The returned rectangle has the - * height and width of the component's bounds, and is positioned - * at a location relative to this component's parent, the - * MenuContainer. null is returned if bounds - * are not supported by the component. - *
    - *
    - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply returns null. - * Concrete subclasses which handle the drawing of an onscreen - * menu component should override this method and provide - * the appropriate information. + * Gets the AccessibleContext associated with this MenuComponent. + * As an abstract class, we return null. Concrete subclasses should return + * their implementation of the accessibility context. * - * @return null. - * @see #setBounds(java.awt.Rectangle) + * @return null */ - public Rectangle getBounds() + public AccessibleContext getAccessibleContext() { return null; } /** - * Returns the Cursor displayed when the pointer - * is positioned over this component. Alternatively, null - * is returned if the component doesn't support the cursor - * property. - *
    - *
    - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply returns the default - * system cursor. Concrete subclasses which handle the drawing - * of an onscreen menu component may override this method and provide - * the appropriate information. + * This class provides a base for the accessibility support of menu + * components. * - * @return the default system cursor. - * @see #setCursor(java.awt.Cursor) + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) */ - public Cursor getCursor() + protected abstract class AccessibleAWTMenuComponent + extends AccessibleContext + implements Serializable, AccessibleComponent, AccessibleSelection { - return Cursor.getDefaultCursor(); - } - /** - * Returns the Font used for text created by this component. - * - * @return the current font. - * @see #setFont(java.awt.Font) - */ - public Font getFont() - { - return MenuComponent.this.getFont(); - } + /** + * Compatible with JDK 1.4.2 revision 5 + */ + private static final long serialVersionUID = -4269533416223798698L; - /** - * Retrieves information on the rendering and metrics of the supplied - * font. If font metrics are not supported by this component, null - * is returned. - *
    - *
    - * The abstract implementation of this method simply uses the toolkit - * to obtain the FontMetrics. Concrete subclasses may - * find it more efficient to invoke their peer class directly, if one - * is available. - * - * @param font the font about which to retrieve rendering and metric - * information. - * @return the metrics of the given font, as provided by the system - * toolkit. - * @throws NullPointerException if the supplied font was null. - */ - public FontMetrics getFontMetrics(Font font) - { - return MenuComponent.this.getToolkit().getFontMetrics(font); - } + /** + * This is the default constructor. It should be called by + * concrete subclasses to ensure necessary groundwork is completed. + */ + protected AccessibleAWTMenuComponent() + { + // Nothing to do here. + } - /** - * Returns the foreground color of the component, or null - * if this property is unsupported. - *
    - *
    - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply returns the - * default system text color used for rendering menus. - * Concrete subclasses which handle the drawing of an onscreen - * menu component should override this method and provide - * the appropriate information. - * - * @return the default system text color for menus. - * @see #setForeground(java.awt.Color) - */ - public Color getForeground() - { - return SystemColor.menuText; - } + /** + * Replaces or supplements the component's selection with the + * Accessible child at the supplied index. If + * the component supports multiple selection, the child is + * added to the current selection. Otherwise, the current + * selection becomes the specified child. If the child is + * already selected, nothing happens. + *
    + *
    + * As the existence of children can not be determined from + * this abstract class, the implementation of this method + * is left to subclasses. + * + * @param index the index of the specified child within a + * zero-based list of the component's children + */ + public void addAccessibleSelection(int index) + { + // Subclasses with children should implement this. + } - /** - * Returns the locale currently in use by this component. - *
    - *
    - * This abstract class has no property relating to the - * locale used by the component, so this method simply - * returns the default locale for the current instance - * of the Java Virtual Machine (JVM). Concrete subclasses - * which maintain such a property should override this method - * and provide the locale information more accurately. - * - * @return the default locale for this JVM instance. - */ - public Locale getLocale() - { - return Locale.getDefault(); - } + /** + * Registers the specified focus listener to receive + * focus events from this component. + * + * @param listener the new focus listener + */ + public void addFocusListener(FocusListener listener) + { + // Chain the new focus listener to the existing chain + // of focus listeners. Each new focus listener is + // coupled via multicasting to the existing chain. + focusListener = AWTEventMulticaster.add(focusListener, listener); + } - /** - * Returns the location of the component, with co-ordinates - * relative to the parent component and using the co-ordinate - * space of the screen. Thus, the point (0,0) is the upper - * left corner of the parent component. - *
    - *
    - * Please note that this method depends on a correctly implemented - * version of the getBounds() method. Subclasses - * must provide the bounding rectangle via getBounds() - * in order for this method to work. - * - * @return the location of the component, relative to its parent. - * @see #setLocation(java.awt.Point) - */ - public Point getLocation() - { - /* Simply return the location of the bounding rectangle */ - return getBounds().getLocation(); - } + /** + * Clears the component's current selection. Following + * the calling of this method, no children of the component + * will be selected. + *
    + *
    + * As the existence of children can not be determined from + * this abstract class, the implementation of this method + * is left to subclasses. + */ + public void clearAccessibleSelection() + { + // Nothing to do here. + } - /** - * Returns the location of the component, with co-ordinates - * relative to the screen. Thus, the point (0,0) is the upper - * left corner of the screen. null is returned if the component - * is either not on screen or if this property is unsupported. - *
    - *
    - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply returns null. - * Concrete subclasses which handle the drawing of an onscreen - * menu component should override this method and provide - * the appropriate information. - * - * @return the location of the component, relative to the screen. - */ - public Point getLocationOnScreen() - { - return null; - } + /** + * Returns true if the specified point lies within the + * component. The supplied co-ordinates are assumed to + * be relative to the co-ordinate system of the component + * itself. Thus, the point (0,0) is the upper left corner + * of this component. + *
    + *
    + * Please note that this method depends on a correctly implemented + * version of the getBounds() method. Subclasses + * must provide the bounding rectangle via getBounds() + * in order for this method to work. + * + * @param point the point to check against this component + * @return true if the point is within this component + * @see #getBounds() + */ + public boolean contains(Point point) + { + // We can simply return the result of a + // test for containment in the bounding rectangle. + return getBounds().contains(point); + } - /** - * Returns the size of the component. - *
    - *
    - * Please note that this method depends on a correctly implemented - * version of the getBounds() method. Subclasses - * must provide the bounding rectangle via getBounds() - * in order for this method to work. - * - * @return the size of the component. - * @see #setSize(java.awt.Dimension) - */ - public Dimension getSize() - { - /* Simply return the size of the bounding rectangle */ - return getBounds().getSize(); - } + /** + * Returns the Accessible child of this component present + * at the specified point. The supplied co-ordinates are + * assumed to be relative to the co-ordinate system of this + * component (the parent of any returned accessible). Thus, + * the point (0,0) is the upper left corner of this menu + * component. + *
    + *
    + * As the existence of children can not be determined from + * this abstract class, the implementation of this method + * is left to subclasses. + * + * @param point the point at which the returned accessible + * is located + * @return null + */ + public Accessible getAccessibleAt(Point point) + { + return null; + } - /** - * Returns true if the accessible child specified by the supplied index - * is currently selected. - *
    - *
    - * As the existence of children can not be determined from - * this abstract class, the implementation of this method - * is left to subclasses. - * - * @param index the index of the accessible child to check for selection. - * @return false. - */ - public boolean isAccessibleChildSelected(int index) - { - return false; - } + /** + * Returns the Accessible child at the supplied + * index within the list of children of this component. + *
    + *
    + * As the existence of children can not be determined from + * this abstract class, the implementation of this method + * is left to subclasses. + * + * @param index the index of the Accessible child + * to retrieve + * + * @return null + */ + public Accessible getAccessibleChild(int index) + { + return null; + } - /** - * Returns true if this component is currently enabled. - *
    - *
    - * As this abstract component has no properties related to - * its enabled or disabled state, the implementation of this - * method is left to subclasses. - * - * @return false. - * @see #setEnabled(boolean) - */ - public boolean isEnabled() - { - return false; - } + /** + * Returns the number of children of this component which + * implement the Accessible interface. If + * all children of this component are accessible, then + * the returned value will be the same as the number of + * children. + *
    + *
    + * + * @return 0 + */ + public int getAccessibleChildrenCount() + { + return 0; + } - /** - * Returns true if this component is included in the traversal - * of the current focus from one component to the other. - *
    - *
    - * As this abstract component has no properties related to - * its ability to accept the focus, the implementation of this - * method is left to subclasses. - * - * @return false. - */ - public boolean isFocusTraversable() - { - return false; - } + /** + * Retrieves the AccessibleComponent associated + * with this accessible context and its component. As the + * context itself implements AccessibleComponent, + * this is the return value. + * + * @return the context itself + */ + public AccessibleComponent getAccessibleComponent() + { + return this; + } - /** - * Returns true if the component is being shown on screen. - * A component is determined to be shown if it is visible, - * and each parent component is also visible. Please note - * that, even when a component is showing, it may still be - * obscured by other components in front. This method only - * determines if the component is being drawn on the screen. - *
    - *
    - * As this abstract component and its parent have no properties - * relating to visibility, the implementation of this method is - * left to subclasses. - * - * @return false. - * @see #isVisible() - */ - public boolean isShowing() - { - return false; - } + /** + * Returns the accessible name for this menu component. This + * is the name given to the component, which may be null if + * not set using setName(). + *
    + *
    + * The name is not the most appropriate description of this + * object. Subclasses should preferably provide a more + * accurate description. For example, a File menu could + * have the description `Lists commands related to the + * file system'. + * + * @return a description of the component. Currently, + * this is just the contents of the name property + * + * @see MenuComponent#setName(String) + */ + public String getAccessibleDescription() + { + return MenuComponent.this.getName(); + } - /** - * Returns true if the component is visible. A component may - * be visible but not drawn on the screen if one of its parent - * components is not visible. To determine if the component is - * actually drawn on screen, isShowing() should be - * used. - *
    - *
    - * As this abstract component has no properties relating to its - * visibility, the implementation of this method is left to subclasses. - * - * @return false. - * @see #isShowing() - * @see #setVisible(boolean) - */ - public boolean isVisible() - { - return false; - } + /** + * Retrieves the index of this component within its parent. + * If no parent exists, -1 is returned. + * + * @return -1 as the parent, a MenuContainer + * is not Accessible + */ + public int getAccessibleIndexInParent() + { + return -1; + } - /** - * Removes the accessible child specified by the supplied index from - * the list of currently selected children. If the child specified - * is not selected, nothing happens. - *
    - *
    - * As the existence of children can not be determined from - * this abstract class, the implementation of this method - * is left to subclasses. - * - * @param index the index of the Accessible child. - */ - public void removeAccessibleSelection(int index) - { - /* Subclasses with children should implement this */ - } + /** + * Returns the accessible name of this component. This + * is the name given to the component, which may be null if + * not set using setName(). + *
    + *
    + * The name property is not the most suitable string to return + * for this method. The string should be localized, and + * relevant to the operation of the component. For example, + * it could be the text of a menu item. However, this can + * not be used at this level of abstraction, so it is the + * responsibility of subclasses to provide a more appropriate + * name. + * + * @return a localized name for this component. Currently, this + * is just the contents of the name property + * + * @see MenuComponent#setName(String) + */ + public String getAccessibleName() + { + return MenuComponent.this.getName(); + } - /** - * Removes the specified focus listener from the list of registered - * focus listeners for this component. - * - * @param listener the listener to remove. - */ - public void removeFocusListener(FocusListener listener) - { - /* Remove the focus listener from the chain */ - focusListener = AWTEventMulticaster.remove(focusListener, listener); - } + /** + * Returns the Accessible parent of this component. + * As the parent of a MenuComponent is a + * MenuContainer, which doesn't implement + * Accessible, this method returns null. + * + * @return null + */ + public Accessible getAccessibleParent() + { + return null; + } - /** - * Requests that this component gains focus. This depends on the - * component being focus traversable. - *
    - *
    - * As this abstract component has no properties relating to its - * focus traversability, or access to a peer with request focusing - * abilities, the implementation of this method is left to subclasses. - */ - public void requestFocus() - { - /* Ignored */ - } + /** + * Returns the accessible role of this component. + *
    + *
    + * The abstract implementation of this method returns + * AccessibleRole.AWT_COMPONENT, + * as the abstract component has no specific role. This + * method should be overridden by concrete subclasses, so + * as to return an appropriate role for the component. + * + * @return AccessibleRole.AWT_COMPONENT + */ + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.AWT_COMPONENT; + } - /** - * Selects all Accessible children of this component which - * it is possible to select. The component needs to support multiple - * selections. - *
    - *
    - * This abstract component provides a simplistic implementation of this - * method, which ignores the ability of the component to support multiple - * selections and simply uses addAccessibleSelection to - * add each Accessible child to the selection. The last - * Accessible component is thus selected for components - * which don't support multiple selections. Concrete implementations should - * override this with a more appopriate and efficient implementation, which - * properly takes into account the ability of the component to support multiple - * selections. - */ - public void selectAllAccessibleSelection() - { - /* Simply call addAccessibleSelection() on all accessible children */ - for (int a = 0; a < getAccessibleChildrenCount(); ++a) - { - addAccessibleSelection(a); - } - } + /** + * Retrieves the AccessibleSelection associated + * with this accessible context and its component. As the + * context itself implements AccessibleSelection, + * this is the return value. + * + * @return the context itself + */ + public AccessibleSelection getAccessibleSelection() + { + return this; + } - /** - * Sets the background color of the component to that specified. - * Unspecified behaviour occurs when null is given as the new - * background color. - *
    - *
    - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply ignores the supplied - * color and continues to use the default system color. - * Concrete subclasses which handle the drawing of an onscreen - * menu component should override this method and provide - * the appropriate information. - * - * @param color the new color to use for the background. - * @see #getBackground() - */ - public void setBackground(Color color) - { - /* Ignored */ - } + /** + * Retrieves the Accessible selected child + * at the specified index. If there are no selected children + * or the index is outside the range of selected children, + * null is returned. Please note that the index refers + * to the index of the child in the list of selected + * children, and not the index of the child in + * the list of all Accessible children. + *
    + *
    + * As the existence of children can not be determined from + * this abstract class, the implementation of this method + * is left to subclasses. + * + * @param index the index of the selected Accessible + * child + */ + public Accessible getAccessibleSelection(int index) + { + return null; + } - /** - * Sets the height and width of the component, and its position - * relative to this component's parent, to the values specified - * by the supplied rectangle. Unspecified behaviour occurs when - * null is given as the new bounds. - *
    - *
    - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply ignores the new - * rectangle and continues to return null from getBounds(). - * Concrete subclasses which handle the drawing of an onscreen - * menu component should override this method and provide - * the appropriate information. - * - * @param rectangle a rectangle which specifies the new bounds of - * the component. - * @see #getBounds() - */ - public void setBounds(Rectangle rectangle) - { - /* Ignored */ - } + /** + * Returns a count of the number of Accessible + * children of this component which are currently selected. + * If there are no children currently selected, 0 is returned. + *
    + *
    + * As the existence of children can not be determined from + * this abstract class, the implementation of this method + * is left to subclasses. + * + * @return 0 + */ + public int getAccessibleSelectionCount() + { + return 0; + } - /** - * Sets the Cursor used when the pointer is positioned over the - * component. Unspecified behaviour occurs when null is given as the new - * cursor. - *
    - *
    - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply ignores the new cursor - * and continues to return the default system cursor. Concrete - * subclasses which handle the drawing of an onscreen menu component - * may override this method and provide the appropriate information. - * - * @param cursor the new cursor to use. - * @see #getCursor() - */ - public void setCursor(Cursor cursor) - { - /* Ignored */ - } + /** + * Retrieves the current state of this component + * in an accessible form. For example, a given component + * may be visible, selected, disabled, etc. + *
    + *
    + * As this class tells us virtually nothing about the component, + * except for its name and font, no state information can be + * provided. This implementation thus returns an empty + * state set, and it is left to concrete subclasses to provide + * a more acceptable and relevant state set. Changes to these + * properties also need to be handled using + * PropertyChangeListeners. + * + * @return an empty AccessibleStateSet + */ + public AccessibleStateSet getAccessibleStateSet() + { + return new AccessibleStateSet(); + } - /** - * Sets the enabled/disabled state of this component. - *
    - *
    - * As this abstract component has no properties related to - * its enabled or disabled state, the implementation of this - * method is left to subclasses. - * - * @param enabled true if the component should be enabled, - * false otherwise. - * @see #isEnabled() - */ - public void setEnabled(boolean enabled) - { - /* Ignored */ - } + /** + * Returns the background color of the component, or null + * if this property is unsupported. + *
    + *
    + * This abstract class knows nothing about how the component + * is drawn on screen, so this method simply returns the + * default system background color used for rendering menus. + * Concrete subclasses which handle the drawing of an onscreen + * menu component should override this method and provide + * the appropriate information. + * + * @return the default system background color for menus + * + * @see #setBackground(java.awt.Color) + */ + public Color getBackground() + { + return SystemColor.menu; + } - /** - * Sets the Font used for text created by this component. - * Unspecified behaviour occurs when null is given as the new - * font. - * - * @param font the new font to use for text. - * @see #getFont() - */ - public void setFont(Font font) - { - /* Call the method of the enclosing component */ - MenuComponent.this.setFont(font); - } + /** + * Returns a Rectangle which represents the + * bounds of this component. The returned rectangle has the + * height and width of the component's bounds, and is positioned + * at a location relative to this component's parent, the + * MenuContainer. null is returned if bounds + * are not supported by the component. + *
    + *
    + * This abstract class knows nothing about how the component + * is drawn on screen, so this method simply returns null. + * Concrete subclasses which handle the drawing of an onscreen + * menu component should override this method and provide + * the appropriate information. + * + * @return null + * + * @see #setBounds(java.awt.Rectangle) + */ + public Rectangle getBounds() + { + return null; + } - /** - * Sets the foreground color of the component to that specified. - * Unspecified behaviour occurs when null is given as the new - * background color. - *
    - *
    - * This abstract class knows nothing about how the component - * is drawn on screen, so this method simply ignores the supplied - * color and continues to return the default system text color used - * for rendering menus. - * Concrete subclasses which handle the drawing of an onscreen - * menu component should override this method and provide - * the appropriate information. - * - * @param color the new foreground color. - * @see #getForeground() - */ - public void setForeground(Color color) - { - /* Ignored */ - } + /** + * Returns the Cursor displayed when the pointer + * is positioned over this component. Alternatively, null + * is returned if the component doesn't support the cursor + * property. + *
    + *
    + * This abstract class knows nothing about how the component + * is drawn on screen, so this method simply returns the default + * system cursor. Concrete subclasses which handle the drawing + * of an onscreen menu component may override this method and provide + * the appropriate information. + * + * @return the default system cursor + * + * @see #setCursor(java.awt.Cursor) + */ + public Cursor getCursor() + { + return Cursor.getDefaultCursor(); + } - /** - * Sets the location of the component, with co-ordinates - * relative to the parent component and using the co-ordinate - * space of the screen. Thus, the point (0,0) is the upper - * left corner of the parent component. - *
    - *
    - * Please note that this method depends on a correctly implemented - * version of the getBounds() method. Subclasses - * must provide the bounding rectangle via getBounds() - * in order for this method to work. - * - * @param point the location of the component, relative to its parent. - * @see #getLocation() - */ - public void setLocation(Point point) - { - getBounds().setLocation(point); - } + /** + * Returns the Font used for text created by this component. + * + * @return the current font + * + * @see #setFont(java.awt.Font) + */ + public Font getFont() + { + return MenuComponent.this.getFont(); + } - /** - * Sets the size of the component. - *
    - *
    - * Please note that this method depends on a correctly implemented - * version of the getBounds() method. Subclasses - * must provide the bounding rectangle via getBounds() - * in order for this method to work. - * - * @param size the new size of the component. - * @see #getSize() - */ - public void setSize(Dimension size) - { - getBounds().setSize(size); - } + /** + * Retrieves information on the rendering and metrics of the supplied + * font. If font metrics are not supported by this component, null + * is returned. + *
    + *
    + * The abstract implementation of this method simply uses the toolkit + * to obtain the FontMetrics. Concrete subclasses may + * find it more efficient to invoke their peer class directly, if one + * is available. + * + * @param font the font about which to retrieve rendering and metric + * information + * + * @return the metrics of the given font, as provided by the system + * toolkit + * + * @throws NullPointerException if the supplied font was null + */ + public FontMetrics getFontMetrics(Font font) + { + return MenuComponent.this.getToolkit().getFontMetrics(font); + } - /** - * Sets the visibility state of the component. A component may - * be visible but not drawn on the screen if one of its parent - * components is not visible. To determine if the component is - * actually drawn on screen, isShowing() should be - * used. - *
    - *
    - * As this abstract component has no properties relating to its - * visibility, the implementation of this method is left to subclasses. - * - * @param visibility the new visibility of the component -- true if - * the component is visible, false if not. - * @see #isShowing() - * @see #isVisible() - */ - public void setVisible(boolean visibility) - { - /* Ignored */ - } + /** + * Returns the foreground color of the component, or null + * if this property is unsupported. + *
    + *
    + * This abstract class knows nothing about how the component + * is drawn on screen, so this method simply returns the + * default system text color used for rendering menus. + * Concrete subclasses which handle the drawing of an onscreen + * menu component should override this method and provide + * the appropriate information. + * + * @return the default system text color for menus + * + * @see #setForeground(java.awt.Color) + */ + public Color getForeground() + { + return SystemColor.menuText; + } -} /* class AccessibleAWTMenuComponent */ - + /** + * Returns the locale currently in use by this component. + *
    + *
    + * This abstract class has no property relating to the + * locale used by the component, so this method simply + * returns the default locale for the current instance + * of the Java Virtual Machine (JVM). Concrete subclasses + * which maintain such a property should override this method + * and provide the locale information more accurately. + * + * @return the default locale for this JVM instance + */ + public Locale getLocale() + { + return Locale.getDefault(); + } + + /** + * Returns the location of the component, with co-ordinates + * relative to the parent component and using the co-ordinate + * space of the screen. Thus, the point (0,0) is the upper + * left corner of the parent component. + *
    + *
    + * Please note that this method depends on a correctly implemented + * version of the getBounds() method. Subclasses + * must provide the bounding rectangle via getBounds() + * in order for this method to work. + * + * @return the location of the component, relative to its parent + * + * @see #setLocation(java.awt.Point) + */ + public Point getLocation() + { + // Simply return the location of the bounding rectangle. + return getBounds().getLocation(); + } + + /** + * Returns the location of the component, with co-ordinates + * relative to the screen. Thus, the point (0,0) is the upper + * left corner of the screen. null is returned if the component + * is either not on screen or if this property is unsupported. + *
    + *
    + * This abstract class knows nothing about how the component + * is drawn on screen, so this method simply returns null. + * Concrete subclasses which handle the drawing of an onscreen + * menu component should override this method and provide + * the appropriate information. + * + * @return the location of the component, relative to the screen + */ + public Point getLocationOnScreen() + { + return null; + } + + /** + * Returns the size of the component. + *
    + *
    + * Please note that this method depends on a correctly implemented + * version of the getBounds() method. Subclasses + * must provide the bounding rectangle via getBounds() + * in order for this method to work. + * + * @return the size of the component + * + * @see #setSize(java.awt.Dimension) + */ + public Dimension getSize() + { + // Simply return the size of the bounding rectangle. + return getBounds().getSize(); + } + + /** + * Returns true if the accessible child specified by the supplied index + * is currently selected. + *
    + *
    + * As the existence of children can not be determined from + * this abstract class, the implementation of this method + * is left to subclasses. + * + * @param index the index of the accessible child to check for selection + * + * @return false + */ + public boolean isAccessibleChildSelected(int index) + { + return false; + } + + /** + * Returns true if this component is currently enabled. + *
    + *
    + * As this abstract component has no properties related to + * its enabled or disabled state, the implementation of this + * method is left to subclasses. + * + * @return false + * + * @see #setEnabled(boolean) + */ + public boolean isEnabled() + { + return false; + } -} // class MenuComponent + /** + * Returns true if this component is included in the traversal + * of the current focus from one component to the other. + *
    + *
    + * As this abstract component has no properties related to + * its ability to accept the focus, the implementation of this + * method is left to subclasses. + * + * @return false + */ + public boolean isFocusTraversable() + { + return false; + } + + /** + * Returns true if the component is being shown on screen. + * A component is determined to be shown if it is visible, + * and each parent component is also visible. Please note + * that, even when a component is showing, it may still be + * obscured by other components in front. This method only + * determines if the component is being drawn on the screen. + *
    + *
    + * As this abstract component and its parent have no properties + * relating to visibility, the implementation of this method is + * left to subclasses. + * + * @return false + * + * @see #isVisible() + */ + public boolean isShowing() + { + return false; + } + + /** + * Returns true if the component is visible. A component may + * be visible but not drawn on the screen if one of its parent + * components is not visible. To determine if the component is + * actually drawn on screen, isShowing() should be + * used. + *
    + *
    + * As this abstract component has no properties relating to its + * visibility, the implementation of this method is left to subclasses. + * + * @return false + * + * @see #isShowing() + * @see #setVisible(boolean) + */ + public boolean isVisible() + { + return false; + } + + /** + * Removes the accessible child specified by the supplied index from + * the list of currently selected children. If the child specified + * is not selected, nothing happens. + *
    + *
    + * As the existence of children can not be determined from + * this abstract class, the implementation of this method + * is left to subclasses. + * + * @param index the index of the Accessible child + */ + public void removeAccessibleSelection(int index) + { + // Subclasses with children should implement this. + } + + /** + * Removes the specified focus listener from the list of registered + * focus listeners for this component. + * + * @param listener the listener to remove + */ + public void removeFocusListener(FocusListener listener) + { + // Remove the focus listener from the chain. + focusListener = AWTEventMulticaster.remove(focusListener, listener); + } + + /** + * Requests that this component gains focus. This depends on the + * component being focus traversable. + *
    + *
    + * As this abstract component has no properties relating to its + * focus traversability, or access to a peer with request focusing + * abilities, the implementation of this method is left to subclasses. + */ + public void requestFocus() + { + // Ignored. + } + + /** + * Selects all Accessible children of this component which + * it is possible to select. The component needs to support multiple + * selections. + *
    + *
    + * This abstract component provides a simplistic implementation of this + * method, which ignores the ability of the component to support multiple + * selections and simply uses addAccessibleSelection to + * add each Accessible child to the selection. The last + * Accessible component is thus selected for components + * which don't support multiple selections. Concrete implementations should + * override this with a more appopriate and efficient implementation, which + * properly takes into account the ability of the component to support multiple + * selections. + */ + public void selectAllAccessibleSelection() + { + // Simply call addAccessibleSelection() on all accessible children. + for (int a = 0; a < getAccessibleChildrenCount(); ++a) + { + addAccessibleSelection(a); + } + } + + /** + * Sets the background color of the component to that specified. + * Unspecified behaviour occurs when null is given as the new + * background color. + *
    + *
    + * This abstract class knows nothing about how the component + * is drawn on screen, so this method simply ignores the supplied + * color and continues to use the default system color. + * Concrete subclasses which handle the drawing of an onscreen + * menu component should override this method and provide + * the appropriate information. + * + * @param color the new color to use for the background + * + * @see #getBackground() + */ + public void setBackground(Color color) + { + // Ignored. + } + + /** + * Sets the height and width of the component, and its position + * relative to this component's parent, to the values specified + * by the supplied rectangle. Unspecified behaviour occurs when + * null is given as the new bounds. + *
    + *
    + * This abstract class knows nothing about how the component + * is drawn on screen, so this method simply ignores the new + * rectangle and continues to return null from getBounds(). + * Concrete subclasses which handle the drawing of an onscreen + * menu component should override this method and provide + * the appropriate information. + * + * @param rectangle a rectangle which specifies the new bounds of + * the component + * + * @see #getBounds() + */ + public void setBounds(Rectangle rectangle) + { + // Ignored. + } + + /** + * Sets the Cursor used when the pointer is positioned over the + * component. Unspecified behaviour occurs when null is given as the new + * cursor. + *
    + *
    + * This abstract class knows nothing about how the component + * is drawn on screen, so this method simply ignores the new cursor + * and continues to return the default system cursor. Concrete + * subclasses which handle the drawing of an onscreen menu component + * may override this method and provide the appropriate information. + * + * @param cursor the new cursor to use + * + * @see #getCursor() + */ + public void setCursor(Cursor cursor) + { + // Ignored. + } + + /** + * Sets the enabled/disabled state of this component. + *
    + *
    + * As this abstract component has no properties related to + * its enabled or disabled state, the implementation of this + * method is left to subclasses. + * + * @param enabled true if the component should be enabled, + * false otherwise + * + * @see #isEnabled() + */ + public void setEnabled(boolean enabled) + { + // Ignored. + } + + /** + * Sets the Font used for text created by this component. + * Unspecified behaviour occurs when null is given as the new + * font. + * + * @param font the new font to use for text. + * @see #getFont() + */ + public void setFont(Font font) + { + // Call the method of the enclosing component. + MenuComponent.this.setFont(font); + } + + /** + * Sets the foreground color of the component to that specified. + * Unspecified behaviour occurs when null is given as the new + * background color. + *
    + *
    + * This abstract class knows nothing about how the component + * is drawn on screen, so this method simply ignores the supplied + * color and continues to return the default system text color used + * for rendering menus. + * Concrete subclasses which handle the drawing of an onscreen + * menu component should override this method and provide + * the appropriate information. + * + * @param color the new foreground color + * + * @see #getForeground() + */ + public void setForeground(Color color) + { + // Ignored. + } + + /** + * Sets the location of the component, with co-ordinates + * relative to the parent component and using the co-ordinate + * space of the screen. Thus, the point (0,0) is the upper + * left corner of the parent component. + *
    + *
    + * Please note that this method depends on a correctly implemented + * version of the getBounds() method. Subclasses + * must provide the bounding rectangle via getBounds() + * in order for this method to work. + * + * @param point the location of the component, relative to its parent + * + * @see #getLocation() + */ + public void setLocation(Point point) + { + getBounds().setLocation(point); + } + + /** + * Sets the size of the component. + *
    + *
    + * Please note that this method depends on a correctly implemented + * version of the getBounds() method. Subclasses + * must provide the bounding rectangle via getBounds() + * in order for this method to work. + * + * @param size the new size of the component + * + * @see #getSize() + */ + public void setSize(Dimension size) + { + getBounds().setSize(size); + } + + /** + * Sets the visibility state of the component. A component may + * be visible but not drawn on the screen if one of its parent + * components is not visible. To determine if the component is + * actually drawn on screen, isShowing() should be + * used. + *
    + *
    + * As this abstract component has no properties relating to its + * visibility, the implementation of this method is left to subclasses. + * + * @param visibility the new visibility of the component -- true if + * the component is visible, false if not + * + * @see #isShowing() + * @see #isVisible() + */ + public void setVisible(boolean visibility) + { + // Ignored. + } + + } + +} diff --git a/libjava/classpath/java/awt/Scrollbar.java b/libjava/classpath/java/awt/Scrollbar.java index 6e506c7..c078837 100644 --- a/libjava/classpath/java/awt/Scrollbar.java +++ b/libjava/classpath/java/awt/Scrollbar.java @@ -1,5 +1,5 @@ /* Scrollbar.java -- AWT Scrollbar widget - Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 + Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -593,13 +593,33 @@ public class Scrollbar extends Component implements Accessible, Adjustable adjustment_listeners.adjustmentValueChanged(event); } + /** + * Package private method to determine whether to call + * processEvent() or not. Will handle events from peer and update + * the current value. + */ void dispatchEventImpl(AWTEvent e) { if (e.id <= AdjustmentEvent.ADJUSTMENT_LAST - && e.id >= AdjustmentEvent.ADJUSTMENT_FIRST - && (adjustment_listeners != null - || (eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0)) - processEvent(e); + && e.id >= AdjustmentEvent.ADJUSTMENT_FIRST) + { + AdjustmentEvent ae = (AdjustmentEvent) e; + boolean adjusting = ae.getValueIsAdjusting(); + if (adjusting) + setValueIsAdjusting(true); + try + { + setValue(((AdjustmentEvent) e).getValue()); + if (adjustment_listeners != null + || (eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0) + processEvent(e); + } + finally + { + if (adjusting) + setValueIsAdjusting(false); + } + } else super.dispatchEventImpl(e); } diff --git a/libjava/classpath/java/awt/TextField.java b/libjava/classpath/java/awt/TextField.java index 3302a2e..23d3d91 100644 --- a/libjava/classpath/java/awt/TextField.java +++ b/libjava/classpath/java/awt/TextField.java @@ -397,6 +397,7 @@ addNotify() return; setPeer((ComponentPeer)getToolkit().createTextField(this)); + super.addNotify(); } /*************************************************************************/ diff --git a/libjava/classpath/java/awt/Toolkit.java b/libjava/classpath/java/awt/Toolkit.java index 2ca88b6..e2a4bc9 100644 --- a/libjava/classpath/java/awt/Toolkit.java +++ b/libjava/classpath/java/awt/Toolkit.java @@ -39,6 +39,8 @@ exception statement from your version. */ package java.awt; +import gnu.java.awt.peer.GLightweightPeer; + import java.awt.datatransfer.Clipboard; import java.awt.dnd.DragGestureEvent; import java.awt.dnd.DragGestureListener; @@ -46,6 +48,7 @@ import java.awt.dnd.DragGestureRecognizer; import java.awt.dnd.DragSource; import java.awt.dnd.peer.DragSourceContextPeer; import java.awt.event.AWTEventListener; +import java.awt.event.AWTEventListenerProxy; import java.awt.event.KeyEvent; import java.awt.im.InputMethodHighlight; import java.awt.image.ColorModel; @@ -76,6 +79,7 @@ import java.awt.peer.WindowPeer; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.net.URL; +import java.util.ArrayList; import java.util.Map; import java.util.Properties; @@ -114,10 +118,17 @@ public abstract class Toolkit = new PropertyChangeSupport(this); /** + * All registered AWTEventListener objects. This is package private, so the + * event queue can efficiently access this list. + */ + AWTEventListenerProxy[] awtEventListeners; + + /** * Default constructor for subclasses. */ public Toolkit() { + awtEventListeners = new AWTEventListenerProxy[0]; } /** @@ -349,7 +360,7 @@ public abstract class Toolkit */ protected LightweightPeer createComponent(Component target) { - return new gnu.java.awt.peer.GLightweightPeer (target); + return new GLightweightPeer(target); } /** @@ -462,7 +473,7 @@ public abstract class Toolkit */ public Insets getScreenInsets(GraphicsConfiguration gc) { - return null; + return new Insets(0, 0, 0, 0); } /** @@ -965,33 +976,230 @@ public abstract class Toolkit return desktopPropsSupport.getPropertyChangeListeners(name); } + /** + * Adds an AWTEventListener to this toolkit. This listener is informed about + * all events that pass the eventqueue that match the specified + * evenMask. The eventMask is an ORed combination + * of event masks as defined in {@link AWTEvent}. + * + * If a security manager is installed, it is asked first if an + * AWTPermission("listenToAllAWTEvents") is allowed. + * This may result in a SecurityException beeing thrown. + * + * It is not recommended to use this kind of notification for normal + * applications. It is intended solely for the purpose of debugging and to + * support special facilities. + * + * @param listener the listener to add + * @param eventMask the event mask of event types which the listener is + * interested in + * + * @since 1.2 + * + * @throws SecurityException if there is a SecurityManager that + * doesn't grant + * AWTPermission("listenToAllAWTEvents") + * + * @see #getAWTEventListeners() + * @see #getAWTEventListeners(long) + * @see #removeAWTEventListener(AWTEventListener) + */ public void addAWTEventListener(AWTEventListener listener, long eventMask) { - // SecurityManager s = System.getSecurityManager(); - // if (s != null) - // s.checkPermission(AWTPermission("listenToAllAWTEvents")); - // FIXME + // First we must check the security permissions. + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkPermission(new AWTPermission("listenToAllAWTEvents")); + + // Go through the list and check if the requested listener is already + // registered. + boolean found = false; + for (int i = 0; i < awtEventListeners.length; ++i) + { + AWTEventListenerProxy proxy = awtEventListeners[i]; + if (proxy.getListener() == listener) + { + found = true; + // Modify the proxies event mask to include the new event mask. + AWTEventListenerProxy newProxy = + new AWTEventListenerProxy(proxy.getEventMask() | eventMask, + listener); + awtEventListeners[i] = newProxy; + break; + } + } + + // If that listener was not found, then add it. + if (! found) + { + AWTEventListenerProxy proxy = + new AWTEventListenerProxy(eventMask, listener); + AWTEventListenerProxy[] newArray = + new AWTEventListenerProxy[awtEventListeners.length + 1]; + System.arraycopy(awtEventListeners, 0, newArray, 0, + awtEventListeners.length); + newArray[newArray.length - 1] = proxy; + awtEventListeners = newArray; + } } + /** + * Removes an AWT event listener from this toolkit. This listener is no + * longer informed of any event types it was registered in. + * + * If a security manager is installed, it is asked first if an + * AWTPermission("listenToAllAWTEvents") is allowed. + * This may result in a SecurityException beeing thrown. + * + * It is not recommended to use this kind of notification for normal + * applications. It is intended solely for the purpose of debugging and to + * support special facilities. + * + * @param listener the listener to remove + * + * @throws SecurityException if there is a SecurityManager that + * doesn't grant + * AWTPermission("listenToAllAWTEvents") + * + * @since 1.2 + * + * @see #addAWTEventListener(AWTEventListener, long) + * @see #getAWTEventListeners() + * @see #getAWTEventListeners(long) + */ public void removeAWTEventListener(AWTEventListener listener) { - // FIXME + // First we must check the security permissions. + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkPermission(new AWTPermission("listenToAllAWTEvents")); + + + // Find the index of the listener. + int index = -1; + for (int i = 0; i < awtEventListeners.length; ++i) + { + AWTEventListenerProxy proxy = awtEventListeners[i]; + if (proxy.getListener() == listener) + { + index = i; + break; + } + } + + // Copy over the arrays and leave out the removed element. + if (index != -1) + { + AWTEventListenerProxy[] newArray = + new AWTEventListenerProxy[awtEventListeners.length - 1]; + if (index > 0) + System.arraycopy(awtEventListeners, 0, newArray, 0, index); + if (index < awtEventListeners.length - 1) + System.arraycopy(awtEventListeners, index + 1, newArray, index, + awtEventListeners.length - index - 1); + awtEventListeners = newArray; + } } /** + * Returns all registered AWT event listeners. This method returns a copy of + * the listener array, so that application cannot trash the listener list. + * + * If a security manager is installed, it is asked first if an + * AWTPermission("listenToAllAWTEvents") is allowed. + * This may result in a SecurityException beeing thrown. + * + * It is not recommended to use this kind of notification for normal + * applications. It is intended solely for the purpose of debugging and to + * support special facilities. + * + * @return all registered AWT event listeners + * + * @throws SecurityException if there is a SecurityManager that + * doesn't grant + * AWTPermission("listenToAllAWTEvents") + * * @since 1.4 + * + * @see #addAWTEventListener(AWTEventListener, long) + * @see #removeAWTEventListener(AWTEventListener) + * @see #getAWTEventListeners(long) */ public AWTEventListener[] getAWTEventListeners() { - return null; + // First we must check the security permissions. + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkPermission(new AWTPermission("listenToAllAWTEvents")); + + // Create a copy of the array. + AWTEventListener[] copy = new AWTEventListener[awtEventListeners.length]; + System.arraycopy(awtEventListeners, 0, copy, 0, awtEventListeners.length); + return copy; } /** + * Returns all registered AWT event listeners that listen for events with + * the specified eventMask. This method returns a copy of + * the listener array, so that application cannot trash the listener list. + * + * If a security manager is installed, it is asked first if an + * AWTPermission("listenToAllAWTEvents") is allowed. + * This may result in a SecurityException beeing thrown. + * + * It is not recommended to use this kind of notification for normal + * applications. It is intended solely for the purpose of debugging and to + * support special facilities. + * + * @param mask the event mask + * + * @throws SecurityException if there is a SecurityManager that + * doesn't grant + * AWTPermission("listenToAllAWTEvents") + * + * * @since 1.4 + * + * @see #addAWTEventListener(AWTEventListener, long) + * @see #removeAWTEventListener(AWTEventListener) + * @see #getAWTEventListeners() */ public AWTEventListener[] getAWTEventListeners(long mask) { - return null; + // First we must check the security permissions. + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkPermission(new AWTPermission("listenToAllAWTEvents")); + + // Create a copy of the array with only the requested listeners in it. + ArrayList l = new ArrayList(awtEventListeners.length); + for (int i = 0; i < awtEventListeners.length; ++i) + { + if ((awtEventListeners[i].getEventMask() & mask) != 0) + l.add(awtEventListeners[i]); + } + + return (AWTEventListener[] ) l.toArray(new AWTEventListener[l.size()]); + } + + + /** + * Dispatches events to listeners registered to this Toolkit. This is called + * by {@link Component#dispatchEventImpl(AWTEvent)} in order to dispatch + * events globally. + * + * @param ev the event to dispatch + */ + void globalDispatchEvent(AWTEvent ev) + { + // We do not use the accessor methods here because they create new + // arrays each time. We must be very efficient, so we access this directly. + for (int i = 0; i < awtEventListeners.length; ++i) + { + AWTEventListenerProxy proxy = awtEventListeners[i]; + if ((proxy.getEventMask() & AWTEvent.eventIdToMask(ev.getID())) != 0) + proxy.eventDispatched(ev); + } } /** diff --git a/libjava/classpath/java/awt/Window.java b/libjava/classpath/java/awt/Window.java index f8a620d..71a8d38 100644 --- a/libjava/classpath/java/awt/Window.java +++ b/libjava/classpath/java/awt/Window.java @@ -281,50 +281,53 @@ public class Window extends Container implements Accessible public void show() { synchronized (getTreeLock()) - { - if (parent != null && !parent.isDisplayable()) - parent.addNotify(); - if (peer == null) - addNotify(); - - // Show visible owned windows. - Iterator e = ownedWindows.iterator(); - while(e.hasNext()) - { - Window w = (Window)(((Reference) e.next()).get()); - if (w != null) - { - if (w.isVisible()) - w.getPeer().setVisible(true); - } - else - // Remove null weak reference from ownedWindows. - // Unfortunately this can't be done in the Window's - // finalize method because there is no way to guarantee - // synchronous access to ownedWindows there. - e.remove(); - } - validate(); - super.show(); - toFront(); - - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - manager.setGlobalFocusedWindow (this); - - if (!shown) { - FocusTraversalPolicy policy = getFocusTraversalPolicy (); - Component initialFocusOwner = null; + if (parent != null && ! parent.isDisplayable()) + parent.addNotify(); + if (peer == null) + addNotify(); + + validate(); + if (visible) + toFront(); + else + { + super.show(); + // Show visible owned windows. + Iterator e = ownedWindows.iterator(); + while (e.hasNext()) + { + Window w = (Window) (((Reference) e.next()).get()); + if (w != null) + { + if (w.isVisible()) + w.getPeer().setVisible(true); + } + else + // Remove null weak reference from ownedWindows. + // Unfortunately this can't be done in the Window's + // finalize method because there is no way to guarantee + // synchronous access to ownedWindows there. + e.remove(); + } + } + KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + manager.setGlobalFocusedWindow(this); - if (policy != null) - initialFocusOwner = policy.getInitialComponent (this); + if (! shown) + { + FocusTraversalPolicy policy = getFocusTraversalPolicy(); + Component initialFocusOwner = null; - if (initialFocusOwner != null) - initialFocusOwner.requestFocusInWindow (); + if (policy != null) + initialFocusOwner = policy.getInitialComponent(this); - shown = true; + if (initialFocusOwner != null) + initialFocusOwner.requestFocusInWindow(); + + shown = true; + } } - } } public void hide() diff --git a/libjava/classpath/java/awt/datatransfer/DataFlavor.java b/libjava/classpath/java/awt/datatransfer/DataFlavor.java index 32bf4d6..788ae6d 100644 --- a/libjava/classpath/java/awt/datatransfer/DataFlavor.java +++ b/libjava/classpath/java/awt/datatransfer/DataFlavor.java @@ -157,38 +157,42 @@ public class DataFlavor implements java.io.Externalizable, Cloneable ClassLoader classLoader) throws ClassNotFoundException { + // Bootstrap try { - return(Class.forName(className)); + return Class.forName(className); } - catch(Exception e) { ; } - // Commented out for Java 1.1 - /* - try + catch(ClassNotFoundException cnfe) { - return(className.getClass().getClassLoader().findClass(className)); + // Ignored. } - catch(Exception e) { ; } + // System try { - return(ClassLoader.getSystemClassLoader().findClass(className)); + ClassLoader loader = ClassLoader.getSystemClassLoader(); + return Class.forName(className, true, loader); } - catch(Exception e) { ; } - */ - - // FIXME: What is the context class loader? - /* + catch(ClassNotFoundException cnfe) + { + // Ignored. + } + + // Context try { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + return Class.forName(className, true, loader); } - catch(Exception e) { ; } - */ - + catch(ClassNotFoundException cnfe) + { + // Ignored. + } + if (classLoader != null) - return(classLoader.loadClass(className)); - else - throw new ClassNotFoundException(className); + return Class.forName(className, true, classLoader); + + throw new ClassNotFoundException(className); } private static Class getRepresentationClassFromMime(String mimeString, @@ -203,7 +207,13 @@ public class DataFlavor implements java.io.Externalizable, Cloneable } catch(Exception e) { - throw new IllegalArgumentException("classname: " + e.getMessage()); + IllegalArgumentException iae; + iae = new IllegalArgumentException("mimeString: " + + mimeString + + " classLoader: " + + classLoader); + iae.initCause(e); + throw iae; } } else diff --git a/libjava/classpath/java/awt/dnd/DragSource.java b/libjava/classpath/java/awt/dnd/DragSource.java index 13ffc96..05eb670 100644 --- a/libjava/classpath/java/awt/dnd/DragSource.java +++ b/libjava/classpath/java/awt/dnd/DragSource.java @@ -90,7 +90,7 @@ public class DragSource implements Serializable */ public static DragSource getDefaultDragSource() { - return null; + return new DragSource(); } public static boolean isDragImageSupported() @@ -172,13 +172,34 @@ public class DragSource implements Serializable return flavorMap; } + /** + * Dummy DragGestureRecognizer when Toolkit doesn't support drag and drop. + */ + static class NoDragGestureRecognizer extends DragGestureRecognizer + { + NoDragGestureRecognizer(DragSource ds, Component c, int actions, + DragGestureListener dgl) + { + super(ds, c, actions, dgl); + } + + protected void registerListeners() { } + protected void unregisterListeners() { } + } + public DragGestureRecognizer createDragGestureRecognizer(Class recognizer, Component c, int actions, DragGestureListener dgl) { - return Toolkit.getDefaultToolkit () + DragGestureRecognizer dgr; + dgr = Toolkit.getDefaultToolkit () .createDragGestureRecognizer (recognizer, this, c, actions, dgl); + + if (dgr == null) + dgr = new NoDragGestureRecognizer(this, c, actions, dgl); + + return dgr; } public DragGestureRecognizer diff --git a/libjava/classpath/java/awt/doc-files/capjoin.png b/libjava/classpath/java/awt/doc-files/capjoin.png new file mode 100644 index 0000000..555dca9 Binary files /dev/null and b/libjava/classpath/java/awt/doc-files/capjoin.png differ diff --git a/libjava/classpath/java/awt/event/AWTEventListenerProxy.java b/libjava/classpath/java/awt/event/AWTEventListenerProxy.java index 3d9958b..55a4bfe 100644 --- a/libjava/classpath/java/awt/event/AWTEventListenerProxy.java +++ b/libjava/classpath/java/awt/event/AWTEventListenerProxy.java @@ -72,75 +72,15 @@ public class AWTEventListenerProxy extends EventListenerProxy } /** - * Forwards events on to the delegate if they meet the event mask. + * Forwards events on to the delegate. + * + * @param event the to forward to the delagate listener * - * @param event the property change event to filter * @throws NullPointerException if the delegate this was created with is null */ public void eventDispatched(AWTEvent event) { - int id = event == null ? 0 : event.getID(); - if (((mask & AWTEvent.ACTION_EVENT_MASK) != 0 - && event instanceof ActionEvent) - || ((mask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0 - && event instanceof AdjustmentEvent) - || ((mask & AWTEvent.COMPONENT_EVENT_MASK) != 0 - && event instanceof ComponentEvent - && (id >= ComponentEvent.COMPONENT_FIRST - && id <= ComponentEvent.COMPONENT_LAST)) - || ((mask & AWTEvent.CONTAINER_EVENT_MASK) != 0 - && event instanceof ContainerEvent) - || ((mask & AWTEvent.FOCUS_EVENT_MASK) != 0 - && event instanceof FocusEvent) - || ((mask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 - && event instanceof HierarchyEvent - && (id == HierarchyEvent.ANCESTOR_MOVED - || id == HierarchyEvent.ANCESTOR_RESIZED)) - || ((mask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 - && event instanceof HierarchyEvent - && id == HierarchyEvent.HIERARCHY_CHANGED) - || ((mask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 - && event instanceof InputMethodEvent) - || ((mask & AWTEvent.INVOCATION_EVENT_MASK) != 0 - && event instanceof InvocationEvent) - || ((mask & AWTEvent.ITEM_EVENT_MASK) != 0 - && event instanceof ItemEvent) - || ((mask & AWTEvent.KEY_EVENT_MASK) != 0 - && event instanceof KeyEvent) - || ((mask & AWTEvent.MOUSE_EVENT_MASK) != 0 - && event instanceof MouseEvent - && (id == MouseEvent.MOUSE_PRESSED - || id == MouseEvent.MOUSE_RELEASED - || id == MouseEvent.MOUSE_CLICKED - || id == MouseEvent.MOUSE_ENTERED - || id == MouseEvent.MOUSE_EXITED)) - || ((mask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 - && event instanceof MouseEvent - && (id == MouseEvent.MOUSE_MOVED - || id == MouseEvent.MOUSE_DRAGGED)) - || ((mask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0 - && event instanceof MouseWheelEvent) - || ((mask & AWTEvent.PAINT_EVENT_MASK) != 0 - && event instanceof PaintEvent) - || ((mask & AWTEvent.TEXT_EVENT_MASK) != 0 - && event instanceof TextEvent) - || ((mask & AWTEvent.WINDOW_EVENT_MASK) != 0 - && event instanceof WindowEvent - && (id == WindowEvent.WINDOW_OPENED - || id == WindowEvent.WINDOW_CLOSING - || id == WindowEvent.WINDOW_CLOSED - || id == WindowEvent.WINDOW_ICONIFIED - || id == WindowEvent.WINDOW_DEICONIFIED - || id == WindowEvent.WINDOW_ACTIVATED - || id == WindowEvent.WINDOW_DEACTIVATED)) - || ((mask & AWTEvent.WINDOW_FOCUS_EVENT_MASK) != 0 - && event instanceof WindowEvent - && (id == WindowEvent.WINDOW_GAINED_FOCUS - || id == WindowEvent.WINDOW_LOST_FOCUS)) - || ((mask & AWTEvent.WINDOW_STATE_EVENT_MASK) != 0 - && event instanceof WindowEvent - && id == WindowEvent.WINDOW_STATE_CHANGED)) - ((AWTEventListener) getListener()).eventDispatched(event); + ((AWTEventListener) getListener()).eventDispatched(event); } /** diff --git a/libjava/classpath/java/awt/peer/ComponentPeer.java b/libjava/classpath/java/awt/peer/ComponentPeer.java index 1ba1692..97b96f4 100644 --- a/libjava/classpath/java/awt/peer/ComponentPeer.java +++ b/libjava/classpath/java/awt/peer/ComponentPeer.java @@ -59,76 +59,344 @@ import java.awt.image.ImageObserver; import java.awt.image.ImageProducer; import java.awt.image.VolatileImage; +/** + * Defines the methods that a component peer is required to implement. + */ public interface ComponentPeer { + /** + * Returns the construction status of the specified image. This is called + * by {@link Component#checkImage(Image, int, int, ImageObserver)}. + * + * @param img the image + * @param width the width of the image + * @param height the height of the image + * @param ob the image observer to be notified of updates of the status + * + * @return a bitwise ORed set of ImageObserver flags + */ int checkImage(Image img, int width, int height, - ImageObserver ob); + ImageObserver ob); + + /** + * Creates an image by starting the specified image producer. This is called + * by {@link Component#createImage(ImageProducer)}. + * + * @param prod the image producer to be used to create the image + * + * @return the created image + */ Image createImage(ImageProducer prod); + + /** + * Creates an empty image with the specified width and + * height. + * + * @param width the width of the image to be created + * @param height the height of the image to be created + * + * @return the created image + */ Image createImage(int width, int height); + + /** + * Disables the component. This is called by {@link Component#disable()}. + */ void disable(); + + /** + * Disposes the component peer. This should release all resources held by the + * peer. This is called when the component is no longer in use. + */ void dispose(); + + /** + * Enables the component. This is called by {@link Component#enable()}. + */ void enable(); + + /** + * Returns the color model of the component. This is currently not used. + * + * @return the color model of the component + */ ColorModel getColorModel(); + + /** + * Returns the font metrics for the specified font. This is called by + * {@link Component#getFontMetrics(Font)}. + * + * @param f the font for which to query the font metrics + * + * @return the font metrics for the specified font + */ FontMetrics getFontMetrics(Font f); + + /** + * Returns a {@link Graphics} object suitable for drawing on this component. + * This is called by {@link Component#getGraphics()}. + * + * @return a graphics object suitable for drawing on this component + */ Graphics getGraphics(); + + /** + * Returns the location of this component in screen coordinates. This is + * called by {@link Component#getLocationOnScreen()}. + * + * @return the location of this component in screen coordinates + */ Point getLocationOnScreen(); + + /** + * Returns the minimum size for the component. This is called by + * {@link Component#getMinimumSize()}. + * + * @return the minimum size for the component + */ Dimension getMinimumSize(); + + /** + * Returns the preferred size for the component. This is called by + * {@link Component#getPreferredSize()}. + * + * @return the preferred size for the component + */ Dimension getPreferredSize(); + + /** + * Returns the toolkit that created this peer. + * + * @return the toolkit that created this peer + */ Toolkit getToolkit(); + + /** + * Handles the given event. This is called from + * {@link Component#dispatchEvent(AWTEvent)} to give the peer a chance to + * react to events for the component. + * + * @param e the event + */ void handleEvent(AWTEvent e); + + /** + * Makes the component invisible. This is called from + * {@link Component#hide()}. + */ void hide(); /** - * Part of the earlier 1.1 API, replaced by isFocusable(). + * Returns true if the component can receive keyboard input + * focus. This is called from {@link Component#isFocusTraversable()}. + * + * @specnote Part of the earlier 1.1 API, replaced by isFocusable(). */ boolean isFocusTraversable(); + + /** + * Returns true if the component can receive keyboard input + * focus. This is called from {@link Component#isFocusable()}. + */ boolean isFocusable(); + + /** + * Returns the minimum size for the component. This is called by + * {@link Component#minimumSize()}. + * + * @return the minimum size for the component + */ Dimension minimumSize(); + + /** + * Returns the preferred size for the component. This is called by + * {@link Component#getPreferredSize()}. + * + * @return the preferred size for the component + */ Dimension preferredSize(); + void paint(Graphics graphics); + + /** + * Prepares an image for rendering on this component. This is called by + * {@link Component#prepareImage(Image, int, int, ImageObserver)}. + * + * @param img the image to prepare + * @param width the desired width of the rendered image + * @param height the desired height of the rendered image + * @param ob the image observer to be notified of updates in the preparation + * process + * + * @return true if the image has been fully prepared, + * false otherwise (in which case the image observer + * receives updates) + */ boolean prepareImage(Image img, int width, int height, ImageObserver ob); + void print(Graphics graphics); + + /** + * Repaints the specified rectangle of this component. This is called from + * {@link Component#repaint(long, int, int, int, int)}. + * + * @param tm number of milliseconds to wait with repainting + * @param x the X coordinate of the upper left corner of the damaged rectangle + * @param y the Y coordinate of the upper left corner of the damaged rectangle + * @param width the width of the damaged rectangle + * @param height the height of the damaged rectangle + */ void repaint(long tm, int x, int y, int width, int height); /** - * Part of the earlier 1.1 API, apparently replaced by argument - * form of the same method. + * Requests that this component receives the focus. This is called from + * {@link Component#requestFocus()}. + * + * @specnote Part of the earlier 1.1 API, apparently replaced by argument + * form of the same method. */ void requestFocus(); - boolean requestFocus (Component source, boolean bool1, boolean bool2, long x); + /** + * Requests that this component receives the focus. This is called from + * {@link Component#requestFocus()}. + * + * @param source TODO + * @param bool1 TODO + * @param bool2 TODO + * @param x TODO + */ + boolean requestFocus(Component source, boolean bool1, boolean bool2, long x); + + /** + * Notifies the peer that the bounds of this component have changed. This + * is called by {@link Component#reshape(int, int, int, int)}. + * + * @param x the X coordinate of the upper left corner of the component + * @param y the Y coordinate of the upper left corner of the component + * @param width the width of the component + * @param height the height of the component + */ void reshape(int x, int y, int width, int height); + + /** + * Sets the background color of the component. This is called by + * {@link Component#setBackground(Color)}. + * + * @param color the background color to set + */ void setBackground(Color color); + + /** + * Notifies the peer that the bounds of this component have changed. This + * is called by {@link Component#setBounds(int, int, int, int)}. + * + * @param x the X coordinate of the upper left corner of the component + * @param y the Y coordinate of the upper left corner of the component + * @param width the width of the component + * @param height the height of the component + */ void setBounds(int x, int y, int width, int height); /** - * Part of the earlier 1.1 API, apparently no longer needed. + * Sets the cursor of the component. This is called by + * {@link Component#setCursor(Cursor)}. + * + * @specnote Part of the earlier 1.1 API, apparently no longer needed. */ void setCursor(Cursor cursor); + /** + * Sets the enabled/disabled state of this component. This is called by + * {@link Component#setEnabled(boolean)}. + * + * @param enabled true to enable the component, + * false to disable it + */ void setEnabled(boolean enabled); + + /** + * Sets the font of the component. This is called by + * {@link Component#setFont(Font)}. + * + * @param font the font to set + */ void setFont(Font font); + + /** + * Sets the foreground color of the component. This is called by + * {@link Component#setForeground(Color)}. + * + * @param color the foreground color to set + */ void setForeground(Color color); + + /** + * Sets the visibility state of the component. This is called by + * {@link Component#setVisible(boolean)}. + * + * @param visible true to make the component visible, + * false to make it invisible + */ void setVisible(boolean visible); + + /** + * Makes the component visible. This is called by {@link Component#show()}. + */ void show(); /** * Get the graphics configuration of the component. The color model * of the component can be derived from the configuration. + * + * @return the graphics configuration of the component */ GraphicsConfiguration getGraphicsConfiguration(); /** * Part of an older API, no longer needed. */ - void setEventMask (long mask); + void setEventMask(long mask); - // Methods below are introduced since 1.1 + /** + * Returns true if this component has been obscured, + * false otherwise. This will only work if + * {@link #canDetermineObscurity()} also returns true. + * + * @return true if this component has been obscured, + * false otherwise. + */ boolean isObscured(); + + /** + * Returns true if this component peer can determine if the + * component has been obscured, false otherwise. + * + * @return true if this component peer can determine if the + * component has been obscured, false otherwise + */ boolean canDetermineObscurity(); + + /** + * Coalesces the specified paint event. + * + * @param e the paint event + */ void coalescePaintEvent(PaintEvent e); + + /** + * Updates the cursor. + */ void updateCursorImmediately(); + + /** + * Returns true, if this component can handle wheel scrolling, + * false otherwise. + * + * @return true, if this component can handle wheel scrolling, + * false otherwise + */ boolean handlesWheelScrolling(); /** diff --git a/libjava/classpath/java/awt/print/NoPrinterJob.java b/libjava/classpath/java/awt/print/NoPrinterJob.java new file mode 100644 index 0000000..e9659a1 --- /dev/null +++ b/libjava/classpath/java/awt/print/NoPrinterJob.java @@ -0,0 +1,124 @@ +/* NoPrinterJob.java -- Fake PrinterJob that just signals no print service. + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt.print; + +/** + * Fake PrinterJob that just signals no print service. This is only + * here so applications can call + * PrintJob.getPrinterJob().getPrinterJob() and check + * that it returns null which indicates no actual + * printing support is available. + */ +class NoPrinterJob extends PrinterJob +{ + public int getCopies() + { + return 0; + } + + public void setCopies(int copies) + { + // Do nothing. + } + + public String getJobName() + { + return "NoPrinterJob"; + } + + public void setJobName(String job_name) + { + // Do nothing. + } + + public String getUserName() + { + return "NoUser"; + } + + public void cancel() + { + // Do nothing. + } + + public boolean isCancelled() + { + return true; + } + + public PageFormat defaultPage(PageFormat page_format) + { + return page_format; + } + + public PageFormat pageDialog(PageFormat page_format) + { + return page_format; + } + + public void print() throws PrinterException + { + throw new PrinterException("No printer"); + } + + public boolean printDialog() + { + return false; + } + + public void setPageable(Pageable pageable) + { + // Do nothing. + } + + public void setPrintable(Printable printable) + { + // Do nothing. + } + + public void setPrintable(Printable printable, PageFormat page_format) + { + // Do nothing. + } + + public PageFormat validatePage(PageFormat page_format) + { + return page_format; + } +} diff --git a/libjava/classpath/java/awt/print/PageFormat.java b/libjava/classpath/java/awt/print/PageFormat.java index 6399552..0a8aa3e 100644 --- a/libjava/classpath/java/awt/print/PageFormat.java +++ b/libjava/classpath/java/awt/print/PageFormat.java @@ -1,5 +1,5 @@ /* PageFormat.java -- Information about the page format - Copyright (C) 1999 Free Software Foundation, Inc. + Copyright (C) 1999, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,254 +39,195 @@ exception statement from your version. */ package java.awt.print; /** - * This class contains information about the desired page format to - * use for printing a particular set of pages. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class PageFormat implements Cloneable -{ - -/* - * Static Variables - */ - -/** - * A constant for a landscaped page orientation. Used by - * getOrientation and setOrientation. - */ -public static final int LANDSCAPE = 0; - -/** - * A constant for a portrait page orientation. Used by - * getOrientation and setOrientation. - */ -public static final int PORTRAIT = 1; - -/** - * A constant for a reversed landscaped page orientation. This is - * the orientation used by Macintosh's for landscape. The origin is - * in the upper right hand corner instead of the upper left. The - * X and Y axes are reversed. Used by getOrientation and - * setOrientation. - */ -public static final int REVERSE_LANDSCAPE = 2; - -/*************************************************************************/ - -/* - * Instance Variables + * This class contains information about the desired page format to use for + * printing a particular set of pages. + * + * @author Aaron M. Renn (arenn@urbanophile.com) */ - -// The page orientation -private int orientation; - -// The paper type -private Paper paper; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * This method creates a default page layout, which will be in portrait - * format. - */ -public -PageFormat() -{ - this.paper = new Paper(); - this.orientation = PORTRAIT; -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * This method returns the width of the page, in 1/72nd's of an inch. The - * "width" measured depends on orientation. - * - * @return The width of the page. - */ -public double -getWidth() -{ - return(paper.getWidth()); -} - -/*************************************************************************/ - -/** - * This method returns the height of the page, in 1/72nd's of an inch. - * The "height" measured depends on the orientation. - * - * @return The height of the page. - */ -public double -getHeight() -{ - return(paper.getHeight()); -} - -/*************************************************************************/ - -/** - * This method returns the X coordinate value of the upper leftmost - * drawable area of the paper. - * - * @return The upper leftmost imageable X coordinate. - */ -public double -getImageableX() -{ - return(paper.getImageableX()); -} - -/*************************************************************************/ - -/** - * This method returns the Y coordinate value of the upper leftmost - * drawable area of the paper. - * - * @return The upper leftmost imageable Y coordinate. - */ -public double -getImageableY() -{ - return(paper.getImageableY()); -} - -/*************************************************************************/ - -/** - * This method returns the imageable width of the paper, in 1/72nd's of - * an inch. - * - * @return The imageable width of the paper. - */ -public double -getImageableWidth() +public class PageFormat + implements Cloneable { - return(paper.getImageableWidth()); -} - -/*************************************************************************/ + /** + * A constant for a landscaped page orientation. Used by + * getOrientation and setOrientation. + */ + public static final int LANDSCAPE = 0; + + /** + * A constant for a portrait page orientation. Used by + * getOrientation and setOrientation. + */ + public static final int PORTRAIT = 1; + + /** + * A constant for a reversed landscaped page orientation. This is the + * orientation used by Macintosh's for landscape. The origin is in the + * upper right hand corner instead of the upper left. The X and Y axes + * are reversed. Used by getOrientation and + * setOrientation. + */ + public static final int REVERSE_LANDSCAPE = 2; + + // The page orientation + private int orientation; + + // The paper type + private Paper paper; + + /** + * This method creates a default page layout, which will be in portrait + * format. + */ + public PageFormat() + { + this.paper = new Paper(); + this.orientation = PORTRAIT; + } + + /** + * This method returns the width of the page, in 1/72nd's of an inch. The + * "width" measured depends on orientation. + * + * @return The width of the page. + */ + public double getWidth() + { + return paper.getWidth(); + } + + /** + * This method returns the height of the page, in 1/72nd's of an inch. The + * "height" measured depends on the orientation. + * + * @return The height of the page. + */ + public double getHeight() + { + return paper.getHeight(); + } + + /** + * This method returns the X coordinate value of the upper leftmost drawable + * area of the paper. + * + * @return The upper leftmost imageable X coordinate. + */ + public double getImageableX() + { + return paper.getImageableX(); + } + + /** + * This method returns the Y coordinate value of the upper leftmost drawable + * area of the paper. + * + * @return The upper leftmost imageable Y coordinate. + */ + public double getImageableY() + { + return paper.getImageableY(); + } + + /** + * This method returns the imageable width of the paper, in 1/72nd's of an + * inch. + * + * @return The imageable width of the paper. + */ + public double getImageableWidth() + { + return paper.getImageableWidth(); + } + + /** + * This method returns the imageable height of the paper, in 1/72nd's of an + * inch. + * + * @return The imageable height of the paper. + */ + public double getImageableHeight() + { + return paper.getImageableHeight(); + } + + /** + * Returns a copy of the paper object being used for this page + * format. + * + * @return A copy of the Paper object for this format. + */ + public Paper getPaper() + { + return (Paper) paper.clone(); + } + + /** + * Sets the Paper object to be used by this page format. + * + * @param paper The new Paper object for this page format. + */ + public void setPaper(Paper paper) + { + this.paper = paper; + } + + /** + * This method returns the current page orientation. The value returned will + * be one of the page orientation constants from this class. + * + * @return The current page orientation. + */ + public int getOrientation() + { + return orientation; + } + + /** + * This method sets the page orientation for this format to the specified + * value. It must be one of the page orientation constants from this class + * or an exception will be thrown. + * + * @param orientation The new page orientation. + * @exception IllegalArgumentException If the specified page orientation + * value is not one of the constants from this class. + */ + public void setOrientation(int orientation) throws IllegalArgumentException + { + if ((orientation != PORTRAIT) && (orientation != LANDSCAPE) + && (orientation != REVERSE_LANDSCAPE)) + throw new IllegalArgumentException("Bad page orientation value: " + + orientation); + + this.orientation = orientation; + } + + /** + * This method returns a matrix used for transforming user space coordinates + * to page coordinates. The value returned will be six doubles as described + * in java.awt.geom.AffineTransform. + * + * @return The transformation matrix for this page format. + */ + public double[] getMatrix() + { + throw new RuntimeException("Not implemented since I don't know what to do"); + } + + /** + * This method returns a copy of this object. + * + * @return A copy of this object. + */ + public Object clone() + { + try + { + return (super.clone()); + } + catch (CloneNotSupportedException e) + { + return (null); + } + } -/** - * This method returns the imageable height of the paper, in 1/72nd's of - * an inch. - * - * @return The imageable height of the paper. - */ -public double getImageableHeight() -{ - return(paper.getImageableHeight()); } - -/*************************************************************************/ - -/** - * Returns a copy of the paper object being used for this - * page format. - * - * @return A copy of the Paper object for this format. - */ -public Paper -getPaper() -{ - return((Paper)paper.clone()); -} - -/*************************************************************************/ - -/** - * Sets the Paper object to be used by this page format. - * - * @param paper The new Paper object for this page format. - */ -public void -setPaper(Paper paper) -{ - this.paper = paper; -} - -/*************************************************************************/ - -/** - * This method returns the current page orientation. The value returned - * will be one of the page orientation constants from this class. - * - * @return The current page orientation. - */ -public int -getOrientation() -{ - return(orientation); -} - -/*************************************************************************/ - -/** - * This method sets the page orientation for this format to the - * specified value. It must be one of the page orientation constants - * from this class or an exception will be thrown. - * - * @param orientation The new page orientation. - * - * @exception IllegalArgumentException If the specified page orientation - * value is not one of the constants from this class. - */ -public void -setOrientation(int orientation) throws IllegalArgumentException -{ - if ((orientation != PORTRAIT) && - (orientation != LANDSCAPE) && - (orientation != REVERSE_LANDSCAPE)) - throw new IllegalArgumentException("Bad page orientation value: " + - orientation); - - this.orientation = orientation; -} - -/*************************************************************************/ - -/** - * This method returns a matrix used for transforming user space - * coordinates to page coordinates. The value returned will be six - * doubles as described in java.awt.geom.AffineTransform. - * - * @return The transformation matrix for this page format. - */ -public double[] -getMatrix() -{ - throw new RuntimeException("Not implemented since I don't know what to do"); -} - -/*************************************************************************/ - -/** - * This method returns a copy of this object. - * - * @return A copy of this object. - */ -public Object -clone() -{ - try - { - return(super.clone()); - } - catch(CloneNotSupportedException e) - { - return(null); - } -} - -} // class PageFormat - diff --git a/libjava/classpath/java/awt/print/Pageable.java b/libjava/classpath/java/awt/print/Pageable.java index 12fa542..d61195a 100644 --- a/libjava/classpath/java/awt/print/Pageable.java +++ b/libjava/classpath/java/awt/print/Pageable.java @@ -1,5 +1,5 @@ /* Pageable.java -- Pages to be printed - Copyright (C) 1999 Free Software Foundation, Inc. + Copyright (C) 1999, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,75 +39,52 @@ exception statement from your version. */ package java.awt.print; /** - * This interface represents pages that are to be printed. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ + * This interface represents pages that are to be printed. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ public interface Pageable { - -/* - * Static Variables - */ - -/** - * This constant is returned when getNumberOfPages() - * cannot determine the number of pages available for printing. - */ -int UNKNOWN_NUMBER_OF_PAGES = -1; - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * This method returns the number of pages this object contains, or - * UNKNOWN_NUMBER_OF_PAGES if it cannot determine the number - * of pages to be printed. - * - * @return The number of pages to be printed, or - * UNKNOWN_NUMBER_OF_PAGES if this is unknown. - */ -int -getNumberOfPages(); - -/*************************************************************************/ - -/** - * This method returns the PageFormat instance for the - * specified page. Page numbers start at zero. An exception is thrown if - * the requested page does not exist. - * - * @param pageIndex The index of the page to return the - * PageFormat for. - * - * @return The PageFormat for the requested page. - * - * @exception IndexOutOfBoundsException If the requested page number does - * not exist. - */ -PageFormat -getPageFormat(int pageIndex) throws IndexOutOfBoundsException; - -/*************************************************************************/ - -/** - * This method returns the Printable instance for the - * specified page. Page numbers start at zero. An exception is thrown if - * the requested page does not exist. - * - * @param pageIndex The index of the page to return the - * Printable for. - * - * @return The Printable for the requested page. - * - * @exception IndexOutOfBoundsException If the requested page number does - * not exist. - */ -Printable -getPrintable(int pageIndex) throws IndexOutOfBoundsException; - -} // interface Pageable - + /** + * This constant is returned when getNumberOfPages() cannot + * determine the number of pages available for printing. + */ + int UNKNOWN_NUMBER_OF_PAGES = - 1; + + /** + * This method returns the number of pages this object contains, or + * UNKNOWN_NUMBER_OF_PAGES if it cannot determine the number + * of pages to be printed. + * + * @return The number of pages to be printed, or + * UNKNOWN_NUMBER_OF_PAGES if this is unknown. + */ + int getNumberOfPages(); + + /** + * This method returns the PageFormat instance for the + * specified page. Page numbers start at zero. An exception is thrown if the + * requested page does not exist. + * + * @param pageIndex The index of the page to return the + * PageFormat for. + * @return The PageFormat for the requested page. + * @exception IndexOutOfBoundsException If the requested page number does + * not exist. + */ + PageFormat getPageFormat(int pageIndex) throws IndexOutOfBoundsException; + + /** + * This method returns the Printable instance for the specified + * page. Page numbers start at zero. An exception is thrown if the requested + * page does not exist. + * + * @param pageIndex The index of the page to return the + * Printable for. + * @return The Printable for the requested page. + * @exception IndexOutOfBoundsException If the requested page number does + * not exist. + */ + Printable getPrintable(int pageIndex) throws IndexOutOfBoundsException; + +} diff --git a/libjava/classpath/java/awt/print/Paper.java b/libjava/classpath/java/awt/print/Paper.java index 4579da3..fb7ba91 100644 --- a/libjava/classpath/java/awt/print/Paper.java +++ b/libjava/classpath/java/awt/print/Paper.java @@ -1,5 +1,5 @@ /* Paper.java -- Information about a paper type. - Copyright (C) 1999 Free Software Foundation, Inc. + Copyright (C) 1999, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,198 +39,159 @@ exception statement from your version. */ package java.awt.print; /** - * This class describes a particular type of paper. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class Paper implements Cloneable -{ - -/* - * Instance Variables + * This class describes a particular type of paper. + * + * @author Aaron M. Renn (arenn@urbanophile.com) */ - -// Height of the paper -private double height; - -// Width of the paper -private double width; - -// Upper left imageable X coordinate -private double imageableX; - -// Upper left imageable Y coordinate -private double imageableY; - -// Imageable width of the page -private double imageableWidth; - -// Imageable height of the page -private double imageableHeight; - -/*************************************************************************/ - -/* - * Constructor - */ - -/** - * This method creates a letter sized paper with one inch margins - */ -public -Paper() -{ - width = 8.5 * 72; - height = 11 * 72; - imageableX = 72; - imageableY = 72; - imageableWidth = width - (2 * 72); - imageableHeight = height - (2 * 72); -} - -/*************************************************************************/ - -/** - * This method returns the height of the paper in 1/72nds of an inch. - * - * @return The height of the paper in 1/72nds of an inch. - */ -public double -getHeight() +public class Paper + implements Cloneable { - return(height); -} + // Height of the paper + private double height; + + // Width of the paper + private double width; + + // Upper left imageable X coordinate + private double imageableX; + + // Upper left imageable Y coordinate + private double imageableY; + + // Imageable width of the page + private double imageableWidth; + + // Imageable height of the page + private double imageableHeight; + + /** + * This method creates a letter sized paper with one inch margins + */ + public Paper() + { + width = 8.5 * 72; + height = 11 * 72; + imageableX = 72; + imageableY = 72; + imageableWidth = width - (2 * 72); + imageableHeight = height - (2 * 72); + } + + /** + * This method returns the height of the paper in 1/72nds of an inch. + * + * @return The height of the paper in 1/72nds of an inch. + */ + public double getHeight() + { + return height; + } + + /** + * Returns the width of the paper in 1/72nds of an inch. + * + * @return The width of the paper in 1/72nds of an inch. + */ + public double getWidth() + { + return width; + } + + /** + * This method returns the X coordinate of the upper left hand corner of the + * imageable area of the paper. + * + * @return The X coordinate of the upper left hand corner of the imageable + * area of the paper. + */ + public double getImageableX() + { + return imageableX; + } + + /** + * This method returns the Y coordinate of the upper left hand corner of the + * imageable area of the paper. + * + * @return The Y coordinate of the upper left hand corner of the imageable + * area of the paper. + */ + public double getImageableY() + { + return imageableY; + } + + /** + * Returns the width of the imageable area of the paper. + * + * @return The width of the imageable area of the paper. + */ + public double getImageableWidth() + { + return imageableWidth; + } + + /** + * Returns the height of the imageable area of the paper. + * + * @return The height of the imageable area of the paper. + */ + public double getImageableHeight() + { + return imageableHeight; + } + + /** + * This method sets the size of the paper to the specified width and height, + * which are specified in 1/72nds of an inch. + * + * @param width The width of the paper in 1/72nds of an inch. + * @param height The height of the paper in 1/72nds of an inch. + */ + public void setSize(double width, double height) + { + this.width = width; + this.height = height; + } + + /** + * This method sets the imageable area of the paper by specifying the + * coordinates of the upper left hand corner of that area, and its length + * and height. All values are in 1/72nds of an inch. + * + * @param imageableX The X coordinate of the upper left hand corner of the + * imageable area, in 1/72nds of an inch. + * @param imageableY The Y coordinate of the upper left hand corner of the + * imageable area, in 1/72nds of an inch. + * @param imageableWidth The width of the imageable area of the paper, in + * 1/72nds of an inch. + * @param imageableHeight The heigth of the imageable area of the paper, in + * 1/72nds of an inch. + */ + public void setImageableArea(double imageableX, double imageableY, + double imageableWidth, double imageableHeight) + { + this.imageableX = imageableX; + this.imageableY = imageableY; + this.imageableWidth = imageableWidth; + this.imageableHeight = imageableHeight; + } + + /** + * This method creates a copy of this object. + * + * @return A copy of this object. + */ + public Object clone() + { + try + { + return (super.clone()); + } + catch (CloneNotSupportedException e) + { + return (null); + } + } -/*************************************************************************/ - -/** - * Returns the width of the paper in 1/72nds of an inch. - * - * @return The width of the paper in 1/72nds of an inch. - */ -public double -getWidth() -{ - return(width); } - -/*************************************************************************/ - -/** - * This method returns the X coordinate of the upper left hand corner - * of the imageable area of the paper. - * - * @return The X coordinate of the upper left hand corner of the imageable - * area of the paper. - */ -public double -getImageableX() -{ - return(imageableX); -} - -/*************************************************************************/ - -/** - * This method returns the Y coordinate of the upper left hand corner - * of the imageable area of the paper. - * - * @return The Y coordinate of the upper left hand corner of the imageable - * area of the paper. - */ -public double -getImageableY() -{ - return(imageableY); -} - -/*************************************************************************/ - -/** - * Returns the width of the imageable area of the paper. - * - * @return The width of the imageable area of the paper. - */ -public double -getImageableWidth() -{ - return(imageableWidth); -} - -/*************************************************************************/ - -/** - * Returns the height of the imageable area of the paper. - * - * @return The height of the imageable area of the paper. - */ -public double -getImageableHeight() -{ - return(imageableHeight); -} - -/*************************************************************************/ - -/** - * This method sets the size of the paper to the specified width and - * height, which are specified in 1/72nds of an inch. - * - * @param width The width of the paper in 1/72nds of an inch. - * @param height The height of the paper in 1/72nds of an inch. - */ -public void -setSize(double width, double height) -{ - this.width = width; - this.height = height; -} - -/*************************************************************************/ - -/** - * This method sets the imageable area of the paper by specifying the - * coordinates of the upper left hand corner of that area, and its - * length and height. All values are in 1/72nds of an inch. - * - * @param imageableX The X coordinate of the upper left hand corner of - * the imageable area, in 1/72nds of an inch. - * @param imageableY The Y coordinate of the upper left hand corner of - * the imageable area, in 1/72nds of an inch. - * @param imageableWidth The width of the imageable area of the paper, - * in 1/72nds of an inch. - * @param imageableHeight The heigth of the imageable area of the paper, - * in 1/72nds of an inch. - */ -public void -setImageableArea(double imageableX, double imageableY, - double imageableWidth, double imageableHeight) -{ - this.imageableX = imageableX; - this.imageableY = imageableY; - this.imageableWidth = imageableWidth; - this.imageableHeight = imageableHeight; -} - -/*************************************************************************/ - -/** - * This method creates a copy of this object. - * - * @return A copy of this object. - */ -public Object -clone() -{ - try - { - return(super.clone()); - } - catch(CloneNotSupportedException e) - { - return(null); - } -} - -} // class Paper - diff --git a/libjava/classpath/java/awt/print/PrinterGraphics.java b/libjava/classpath/java/awt/print/PrinterGraphics.java index 5ca6419..62fde84 100644 --- a/libjava/classpath/java/awt/print/PrinterGraphics.java +++ b/libjava/classpath/java/awt/print/PrinterGraphics.java @@ -1,5 +1,5 @@ /* PrinterGraphics.java -- Hook to return print job controller. - Copyright (C) 1999 Free Software Foundation, Inc. + Copyright (C) 1999, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,23 +39,20 @@ exception statement from your version. */ package java.awt.print; /** - * This interface is implemented by the Graphics instance - * that is used for rendering pages. It provides a hook to return the - * object that is controlling the print job. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ + * This interface is implemented by the Graphics instance that is + * used for rendering pages. It provides a hook to return the object that is + * controlling the print job. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ public interface PrinterGraphics { - -/** - * This method returns the instance of PrinterJob that is - * controlling this print job. - * - * @return The PrinterJob that is controlling this print job. - */ -PrinterJob -getPrinterJob(); - -} // interface PrinterGraphics - + /** + * This method returns the instance of PrinterJob that is + * controlling this print job. + * + * @return The PrinterJob that is controlling this print job. + */ + PrinterJob getPrinterJob(); + +} diff --git a/libjava/classpath/java/awt/print/PrinterJob.java b/libjava/classpath/java/awt/print/PrinterJob.java index e1aeabc..7f67a6b 100644 --- a/libjava/classpath/java/awt/print/PrinterJob.java +++ b/libjava/classpath/java/awt/print/PrinterJob.java @@ -1,5 +1,5 @@ /* PrinterJob.java -- This job is the printer control class - Copyright (C) 1999, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -61,7 +61,7 @@ public abstract class PrinterJob public static PrinterJob getPrinterJob() { // FIXME: Need to fix this to load a default implementation instance. - return null; + return new NoPrinterJob(); } /** diff --git a/libjava/classpath/java/beans/DefaultPersistenceDelegate.java b/libjava/classpath/java/beans/DefaultPersistenceDelegate.java index 9dd1ae5..ca1041f 100644 --- a/libjava/classpath/java/beans/DefaultPersistenceDelegate.java +++ b/libjava/classpath/java/beans/DefaultPersistenceDelegate.java @@ -157,6 +157,23 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate protected void initialize(Class type, Object oldInstance, Object newInstance, Encoder out) { + // Calling the supertype's implementation of initialize makes it + // possible that descendants of classes like AbstractHashMap + // or Hashtable are serialized correctly. This mechanism grounds on + // two other facts: + // * Each class which has not registered a special purpose + // PersistenceDelegate is handled by a DefaultPersistenceDelegate + // instance. + // * PersistenceDelegate.initialize() is implemented in a way that it + // calls the initialize method of the superclass' persistence delegate. + super.initialize(type, oldInstance, newInstance, out); + + // Suppresses the writing of property setting statements when this delegate + // is not used for the exact instance type. By doing so the following code + // is called only once per object. + if (type != oldInstance.getClass()) + return; + try { PropertyDescriptor[] propertyDescs = Introspector.getBeanInfo( diff --git a/libjava/classpath/java/beans/Encoder.java b/libjava/classpath/java/beans/Encoder.java index 9b96aaa..b9d1358 100644 --- a/libjava/classpath/java/beans/Encoder.java +++ b/libjava/classpath/java/beans/Encoder.java @@ -1,5 +1,5 @@ /* Encoder.java - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,21 +38,16 @@ package java.beans; +import gnu.java.beans.DefaultExceptionListener; import gnu.java.beans.encoder.ArrayPersistenceDelegate; import gnu.java.beans.encoder.ClassPersistenceDelegate; import gnu.java.beans.encoder.CollectionPersistenceDelegate; import gnu.java.beans.encoder.MapPersistenceDelegate; import gnu.java.beans.encoder.PrimitivePersistenceDelegate; -import java.util.ArrayList; +import java.util.AbstractCollection; import java.util.HashMap; -import java.util.HashSet; import java.util.IdentityHashMap; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.TreeMap; -import java.util.TreeSet; -import java.util.Vector; /** * @author Robert Schuster (robertschuster@fsfe.org) @@ -123,31 +118,11 @@ public class Encoder delegates.put(Object[].class, new ArrayPersistenceDelegate()); pd = new CollectionPersistenceDelegate(); - delegates.put(ArrayList.class, pd); - delegates.put(LinkedList.class, pd); - delegates.put(Vector.class, pd); - delegates.put(HashSet.class, pd); - delegates.put(LinkedHashSet.class, pd); - delegates.put(TreeSet.class, pd); + delegates.put(AbstractCollection.class, pd); pd = new MapPersistenceDelegate(); - delegates.put(HashMap.class, pd); - delegates.put(TreeMap.class, pd); + delegates.put(java.util.AbstractMap.class, pd); delegates.put(java.util.Hashtable.class, pd); - delegates.put(java.util.IdentityHashMap.class, pd); - - delegates.put(java.util.LinkedHashMap.class, pd); - delegates.put(java.util.Properties.class, pd); - - delegates.put(java.awt.RenderingHints.class, pd); - delegates.put(java.util.WeakHashMap.class, pd); - delegates.put(javax.swing.UIDefaults.class, pd); - - // TODO: These classes need to be implemented first - //delegates.put(java.security.AuthProvider.class, pd); - //delegates.put(java.util.concurrent.ConcurrentHashMap.class, pd); - //delegates.put(java.util.EnumMap.class, pd); - //delegates.put(javax.management.openmbean.TabularDataSupport.class, pd); defaultPersistenceDelegate = new DefaultPersistenceDelegate(); delegates.put(Object.class, defaultPersistenceDelegate); @@ -194,14 +169,8 @@ public class Encoder */ public void setExceptionListener(ExceptionListener listener) { - exceptionListener = (listener != null) ? listener : new ExceptionListener() - { - public void exceptionThrown(Exception e) - { - System.err.println("exception thrown: " + e); - e.printStackTrace(); - } - }; + exceptionListener = (listener != null) + ? listener : DefaultExceptionListener.INSTANCE; } /** diff --git a/libjava/classpath/java/beans/PersistenceDelegate.java b/libjava/classpath/java/beans/PersistenceDelegate.java index b33cbcb..77953b6 100644 --- a/libjava/classpath/java/beans/PersistenceDelegate.java +++ b/libjava/classpath/java/beans/PersistenceDelegate.java @@ -59,9 +59,8 @@ public abstract class PersistenceDelegate { type = type.getSuperclass(); - PersistenceDelegate pd = out.getPersistenceDelegate( - oldInstance.getClass().getSuperclass()); - + PersistenceDelegate pd = out.getPersistenceDelegate(type); + pd.initialize(type, oldInstance, newInstance, out); } } diff --git a/libjava/classpath/java/beans/PropertyChangeSupport.java b/libjava/classpath/java/beans/PropertyChangeSupport.java index 991390b..e944e15 100644 --- a/libjava/classpath/java/beans/PropertyChangeSupport.java +++ b/libjava/classpath/java/beans/PropertyChangeSupport.java @@ -1,5 +1,6 @@ /* PropertyChangeSupport.java -- support to manage property change listeners - Copyright (C) 1998, 1999, 2000, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2002, 2005, 2006 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -120,14 +121,17 @@ public class PropertyChangeSupport implements Serializable * property change events will be sent to this listener. The listener add * is not unique: that is, n adds with the same listener will * result in n events being sent to that listener for every - * property change. Adding a null listener may cause a NullPointerException - * down the road. This method will unwrap a PropertyChangeListenerProxy, + * property change. Adding a null listener is silently ignored. + * This method will unwrap a PropertyChangeListenerProxy, * registering the underlying delegate to the named property list. * * @param l the listener to add */ public synchronized void addPropertyChangeListener(PropertyChangeListener l) { + if (l == null) + return; + if (l instanceof PropertyChangeListenerProxy) { PropertyChangeListenerProxy p = (PropertyChangeListenerProxy) l; @@ -216,8 +220,8 @@ public class PropertyChangeSupport implements Serializable * cumulative, too; if you are registered to listen to receive events on * all property changes, and then you register on a particular property, * you will receive change events for that property twice. Adding a null - * listener may cause a NullPointerException down the road. This method - * will unwrap a PropertyChangeListenerProxy, registering the underlying + * listener is silently ignored. This method will unwrap a + * PropertyChangeListenerProxy, registering the underlying * delegate to the named property list if the names match, and discarding * it otherwise. * @@ -228,6 +232,9 @@ public class PropertyChangeSupport implements Serializable public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener l) { + if (l == null) + return; + while (l instanceof PropertyChangeListenerProxy) { PropertyChangeListenerProxy p = (PropertyChangeListenerProxy) l; @@ -290,17 +297,16 @@ public class PropertyChangeSupport implements Serializable /** * Returns an array of all property change listeners registered under the - * given property name. If there are no registered listeners, this returns - * an empty array. + * given property name. If there are no registered listeners, or + * propertyName is null, this returns an empty array. * * @return the array of registered listeners - * @throws NullPointerException if propertyName is null * @since 1.4 */ public synchronized PropertyChangeListener[] getPropertyChangeListeners(String propertyName) { - if (children == null) + if (children == null || propertyName == null) return new PropertyChangeListener[0]; PropertyChangeSupport s = (PropertyChangeSupport) children.get(propertyName); @@ -455,7 +461,6 @@ public class PropertyChangeSupport implements Serializable * * @param propertyName the property that may be listened on * @return whether the property is being listened on - * @throws NullPointerException if propertyName is null */ public synchronized boolean hasListeners(String propertyName) { diff --git a/libjava/classpath/java/beans/PropertyDescriptor.java b/libjava/classpath/java/beans/PropertyDescriptor.java index a22d625..da2ca78 100644 --- a/libjava/classpath/java/beans/PropertyDescriptor.java +++ b/libjava/classpath/java/beans/PropertyDescriptor.java @@ -37,6 +37,8 @@ exception statement from your version. */ package java.beans; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; /** @@ -344,6 +346,71 @@ public class PropertyDescriptor extends FeatureDescriptor this.propertyEditorClass = propertyEditorClass; } + /** + * Instantiate a property editor using the property editor class. + * If no property editor class has been set, this will return null. + * If the editor class has a public constructor which takes a single + * argument, that will be used and the bean parameter will be passed + * to it. Otherwise, a public no-argument constructor will be used, + * if available. This method will return null if no constructor is + * found or if construction fails for any reason. + * @param bean the argument to the constructor + * @return a new PropertyEditor, or null on error + * @since 1.5 + */ + public PropertyEditor createPropertyEditor(Object bean) + { + if (propertyEditorClass == null) + return null; + Constructor c = findConstructor(propertyEditorClass, + new Class[] { Object.class }); + if (c != null) + return instantiateClass(c, new Object[] { bean }); + c = findConstructor(propertyEditorClass, null); + if (c != null) + return instantiateClass(c, null); + return null; + } + + // Helper method to look up a constructor and return null if it is not + // found. + private Constructor findConstructor(Class k, Class[] argTypes) + { + try + { + return k.getConstructor(argTypes); + } + catch (NoSuchMethodException _) + { + return null; + } + } + + // Helper method to instantiate an object but return null on error. + private PropertyEditor instantiateClass(Constructor c, Object[] args) + { + try + { + return (PropertyEditor) c.newInstance(args); + } + catch (InstantiationException _) + { + return null; + } + catch (InvocationTargetException _) + { + return null; + } + catch (IllegalAccessException _) + { + return null; + } + catch (ClassCastException _) + { + return null; + } + } + private void findMethods( Class beanClass, String getMethodName1, diff --git a/libjava/classpath/java/beans/XMLDecoder.java b/libjava/classpath/java/beans/XMLDecoder.java index 238fd6b..7618bb8 100644 --- a/libjava/classpath/java/beans/XMLDecoder.java +++ b/libjava/classpath/java/beans/XMLDecoder.java @@ -1,5 +1,5 @@ /* java.beans.XMLDecoder -- - Copyright (C) 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,7 +38,7 @@ exception statement from your version. */ package java.beans; -import gnu.java.beans.decoder.DefaultExceptionListener; +import gnu.java.beans.DefaultExceptionListener; import gnu.java.beans.decoder.PersistenceParser; import java.io.IOException; @@ -289,7 +289,7 @@ public class XMLDecoder // uses a default implementation when null if (listener == null) { - listener = new DefaultExceptionListener(); + listener = DefaultExceptionListener.INSTANCE; } exceptionListener = listener; } diff --git a/libjava/classpath/java/beans/XMLEncoder.java b/libjava/classpath/java/beans/XMLEncoder.java index f9cbe63..feff68b 100644 --- a/libjava/classpath/java/beans/XMLEncoder.java +++ b/libjava/classpath/java/beans/XMLEncoder.java @@ -168,6 +168,8 @@ public class XMLEncoder extends Encoder // an erroneous state to the ScanEngine without behaving different // to the JDK. scanEngine.revoke(); + + return; } writeObject(value); diff --git a/libjava/classpath/java/io/InputStream.java b/libjava/classpath/java/io/InputStream.java index 86d1cd7..e56197a 100644 --- a/libjava/classpath/java/io/InputStream.java +++ b/libjava/classpath/java/io/InputStream.java @@ -193,10 +193,8 @@ public abstract class InputStream */ public int read(byte[] b, int off, int len) throws IOException { - if (off < 0 || len < 0 || off + len > b.length) + if (off < 0 || len < 0 || b.length - off < len) throw new IndexOutOfBoundsException(); - if (b.length == 0) - return 0; int i, ch; diff --git a/libjava/classpath/java/io/InputStreamReader.java b/libjava/classpath/java/io/InputStreamReader.java index ef8fd45..936a03c 100644 --- a/libjava/classpath/java/io/InputStreamReader.java +++ b/libjava/classpath/java/io/InputStreamReader.java @@ -1,5 +1,6 @@ /* InputStreamReader.java -- Reader than transforms bytes to chars - Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,6 +39,7 @@ exception statement from your version. */ package java.io; +import gnu.classpath.SystemProperties; import gnu.java.nio.charset.EncodingHelper; import java.nio.ByteBuffer; @@ -145,7 +147,7 @@ public class InputStreamReader extends Reader this.in = in; try { - encoding = System.getProperty("file.encoding"); + encoding = SystemProperties.getProperty("file.encoding"); // Don't use NIO if avoidable if(EncodingHelper.isISOLatin1(encoding)) { @@ -231,12 +233,20 @@ public class InputStreamReader extends Reader * charset to decode the bytes in the InputStream into * characters. * - * @since 1.5 + * @since 1.4 */ public InputStreamReader(InputStream in, Charset charset) { + if (in == null) + throw new NullPointerException(); this.in = in; decoder = charset.newDecoder(); + try { + maxBytesPerChar = charset.newEncoder().maxBytesPerChar(); + } catch(UnsupportedOperationException _){ + maxBytesPerChar = 1f; + } + decoder.onMalformedInput(CodingErrorAction.REPLACE); decoder.onUnmappableCharacter(CodingErrorAction.REPLACE); decoder.reset(); @@ -247,9 +257,11 @@ public class InputStreamReader extends Reader * Creates an InputStreamReader that uses the given charset decoder * to decode the bytes in the InputStream into characters. * - * @since 1.5 + * @since 1.4 */ public InputStreamReader(InputStream in, CharsetDecoder decoder) { + if (in == null) + throw new NullPointerException(); this.in = in; this.decoder = decoder; diff --git a/libjava/classpath/java/io/ObjectInputStream.java b/libjava/classpath/java/io/ObjectInputStream.java index 750c698..91832f9 100644 --- a/libjava/classpath/java/io/ObjectInputStream.java +++ b/libjava/classpath/java/io/ObjectInputStream.java @@ -1,5 +1,5 @@ /* ObjectInputStream.java -- Class used to read serialized objects - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005 + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -555,8 +555,7 @@ public class ObjectInputStream extends InputStream classLookupTable.put(clazz, osc); setBlockDataMode(oldmode); - // find the first non-serializable, non-abstract - // class in clazz's inheritance hierarchy + // find the first non-serializable class in clazz's inheritance hierarchy Class first_nonserial = clazz.getSuperclass(); // Maybe it is a primitive class, those don't have a super class, // or Object itself. Otherwise we can keep getting the superclass @@ -565,9 +564,8 @@ public class ObjectInputStream extends InputStream if (first_nonserial == null) first_nonserial = clazz; else - while (Serializable.class.isAssignableFrom(first_nonserial) - || Modifier.isAbstract(first_nonserial.getModifiers())) - first_nonserial = first_nonserial.getSuperclass(); + while (Serializable.class.isAssignableFrom(first_nonserial)) + first_nonserial = first_nonserial.getSuperclass(); final Class local_constructor_class = first_nonserial; @@ -1596,7 +1594,14 @@ public class ObjectInputStream extends InputStream private void readNextBlock() throws IOException { - readNextBlock(this.realInputStream.readByte()); + byte marker = this.realInputStream.readByte(); + while (marker == TC_RESET) + { + if(dump) dumpElementln("RESET"); + clearHandles(); + marker = this.realInputStream.readByte(); + } + readNextBlock(marker); } private void readNextBlock(byte marker) throws IOException diff --git a/libjava/classpath/java/io/ObjectOutputStream.java b/libjava/classpath/java/io/ObjectOutputStream.java index 961d5e3..55a12e4 100644 --- a/libjava/classpath/java/io/ObjectOutputStream.java +++ b/libjava/classpath/java/io/ObjectOutputStream.java @@ -1,5 +1,5 @@ /* ObjectOutputStream.java -- Class used to write serialized objects - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -421,6 +421,8 @@ public class ObjectOutputStream extends OutputStream for (int i = 0; i < intfs.length; i++) realOutput.writeUTF(intfs[i].getName()); + assignNewHandle(osc); + boolean oldmode = setBlockDataMode(true); annotateProxyClass(osc.forClass()); setBlockDataMode(oldmode); diff --git a/libjava/classpath/java/lang/Character.java b/libjava/classpath/java/lang/Character.java index 3c88ff8..98ad147 100644 --- a/libjava/classpath/java/lang/Character.java +++ b/libjava/classpath/java/lang/Character.java @@ -41,6 +41,8 @@ package java.lang; import gnu.java.lang.CharData; import java.io.Serializable; +import java.text.Collator; +import java.util.Locale; /** * Wrapper class for the primitive char data type. In addition, this class @@ -133,10 +135,10 @@ public final class Character implements Serializable, Comparable * is in at most one of these blocks. * * This inner class was generated automatically from - * doc/unicode/Block-3.txt, by some perl scripts. + * doc/unicode/Blocks-4.0.0.txt, by some perl scripts. * This Unicode definition file can be found on the * http://www.unicode.org website. - * JDK 1.4 uses Unicode version 3.0.0. + * JDK 1.5 uses Unicode version 4.0.0. * * @author scripts/unicode-blocks.pl (written by Eric Blake) * @since 1.2 @@ -144,10 +146,18 @@ public final class Character implements Serializable, Comparable public static final class UnicodeBlock extends Subset { /** The start of the subset. */ - private final char start; + private final int start; /** The end of the subset. */ - private final char end; + private final int end; + + /** The canonical name of the block according to the Unicode standard. */ + private final String canonicalName; + + /** Constants for the forName() method */ + private static final int CANONICAL_NAME = 0; + private static final int NO_SPACES_NAME = 1; + private static final int CONSTANT_NAME = 2; /** * Constructor for strictly defined blocks. @@ -155,25 +165,46 @@ public final class Character implements Serializable, Comparable * @param start the start character of the range * @param end the end character of the range * @param name the block name + * @param canonicalName the name of the block as defined in the Unicode + * standard. */ - private UnicodeBlock(char start, char end, String name) + private UnicodeBlock(int start, int end, String name, + String canonicalName) { super(name); this.start = start; this.end = end; + this.canonicalName = canonicalName; } /** * Returns the Unicode character block which a character belongs to. + * Note: This method does not support the use of + * supplementary characters. For such support, of(int) + * should be used instead. * * @param ch the character to look up * @return the set it belongs to, or null if it is not in one */ public static UnicodeBlock of(char ch) { - // Special case, since SPECIALS contains two ranges. - if (ch == '\uFEFF') - return SPECIALS; + return of((int) ch); + } + + /** + * Returns the Unicode character block which a code point belongs to. + * + * @param codePoint the character to look up + * @return the set it belongs to, or null if it is not in one. + * @throws IllegalArgumentException if the specified code point is + * invalid. + * @since 1.5 + */ + public static UnicodeBlock of(int codePoint) + { + if (codePoint > MAX_CODE_POINT) + throw new IllegalArgumentException("The supplied integer value is " + + "too large to be a codepoint."); // Simple binary search for the correct block. int low = 0; int hi = sets.length - 1; @@ -181,9 +212,9 @@ public final class Character implements Serializable, Comparable { int mid = (low + hi) >> 1; UnicodeBlock b = sets[mid]; - if (ch < b.start) + if (codePoint < b.start) hi = mid - 1; - else if (ch > b.end) + else if (codePoint > b.end) low = mid + 1; else return b; @@ -192,703 +223,1300 @@ public final class Character implements Serializable, Comparable } /** + *

    + * Returns the UnicodeBlock with the given name, as defined + * by the Unicode standard. The version of Unicode in use is defined by + * the Character class, and the names are given in the + * Blocks-.txt file corresponding to that version. + * The name may be specified in one of three ways: + *

    + *
      + *
    1. The canonical, human-readable name used by the Unicode standard. + * This is the name with all spaces and hyphens retained. For example, + * `Basic Latin' retrieves the block, UnicodeBlock.BASIC_LATIN.
    2. + *
    3. The canonical name with all spaces removed e.g. `BasicLatin'.
    4. + *
    5. The name used for the constants specified by this class, which + * is the canonical name with all spaces and hyphens replaced with + * underscores e.g. `BASIC_LATIN'
    6. + *
    + *

    + * The names are compared case-insensitively using the case comparison + * associated with the U.S. English locale. The method recognises the + * previous names used for blocks as well as the current ones. At + * present, this simply means that the deprecated `SURROGATES_AREA' + * will be recognised by this method (the of() methods + * only return one of the three new surrogate blocks). + *

    + * + * @param blockName the name of the block to look up. + * @return the specified block. + * @throws NullPointerException if the blockName is + * null. + * @throws IllegalArgumentException if the name does not match any Unicode + * block. + * @since 1.5 + */ + public static final UnicodeBlock forName(String blockName) + { + int type; + if (blockName.indexOf(' ') != -1) + type = CANONICAL_NAME; + else if (blockName.indexOf('_') != -1) + type = CONSTANT_NAME; + else + type = NO_SPACES_NAME; + Collator usCollator = Collator.getInstance(Locale.US); + usCollator.setStrength(Collator.PRIMARY); + /* Special case for deprecated blocks not in sets */ + switch (type) + { + case CANONICAL_NAME: + if (usCollator.compare(blockName, "Surrogates Area") == 0) + return SURROGATES_AREA; + break; + case NO_SPACES_NAME: + if (usCollator.compare(blockName, "SurrogatesArea") == 0) + return SURROGATES_AREA; + break; + case CONSTANT_NAME: + if (usCollator.compare(blockName, "SURROGATES_AREA") == 0) + return SURROGATES_AREA; + break; + } + /* Other cases */ + int setLength = sets.length; + switch (type) + { + case CANONICAL_NAME: + for (int i = 0; i < setLength; i++) + { + UnicodeBlock block = sets[i]; + if (usCollator.compare(blockName, block.canonicalName) == 0) + return block; + } + break; + case NO_SPACES_NAME: + for (int i = 0; i < setLength; i++) + { + UnicodeBlock block = sets[i]; + String nsName = block.canonicalName.replaceAll(" ",""); + if (usCollator.compare(blockName, nsName) == 0) + return block; + } + break; + case CONSTANT_NAME: + for (int i = 0; i < setLength; i++) + { + UnicodeBlock block = sets[i]; + if (usCollator.compare(blockName, block.toString()) == 0) + return block; + } + break; + } + throw new IllegalArgumentException("No Unicode block found for " + + blockName + "."); + } + + /** * Basic Latin. - * '\u0000' - '\u007F'. + * 0x0000 - 0x007F. */ public static final UnicodeBlock BASIC_LATIN - = new UnicodeBlock('\u0000', '\u007F', - "BASIC_LATIN"); + = new UnicodeBlock(0x0000, 0x007F, + "BASIC_LATIN", + "Basic Latin"); /** * Latin-1 Supplement. - * '\u0080' - '\u00FF'. + * 0x0080 - 0x00FF. */ public static final UnicodeBlock LATIN_1_SUPPLEMENT - = new UnicodeBlock('\u0080', '\u00FF', - "LATIN_1_SUPPLEMENT"); + = new UnicodeBlock(0x0080, 0x00FF, + "LATIN_1_SUPPLEMENT", + "Latin-1 Supplement"); /** * Latin Extended-A. - * '\u0100' - '\u017F'. + * 0x0100 - 0x017F. */ public static final UnicodeBlock LATIN_EXTENDED_A - = new UnicodeBlock('\u0100', '\u017F', - "LATIN_EXTENDED_A"); + = new UnicodeBlock(0x0100, 0x017F, + "LATIN_EXTENDED_A", + "Latin Extended-A"); /** * Latin Extended-B. - * '\u0180' - '\u024F'. + * 0x0180 - 0x024F. */ public static final UnicodeBlock LATIN_EXTENDED_B - = new UnicodeBlock('\u0180', '\u024F', - "LATIN_EXTENDED_B"); + = new UnicodeBlock(0x0180, 0x024F, + "LATIN_EXTENDED_B", + "Latin Extended-B"); /** * IPA Extensions. - * '\u0250' - '\u02AF'. + * 0x0250 - 0x02AF. */ public static final UnicodeBlock IPA_EXTENSIONS - = new UnicodeBlock('\u0250', '\u02AF', - "IPA_EXTENSIONS"); + = new UnicodeBlock(0x0250, 0x02AF, + "IPA_EXTENSIONS", + "IPA Extensions"); /** * Spacing Modifier Letters. - * '\u02B0' - '\u02FF'. + * 0x02B0 - 0x02FF. */ public static final UnicodeBlock SPACING_MODIFIER_LETTERS - = new UnicodeBlock('\u02B0', '\u02FF', - "SPACING_MODIFIER_LETTERS"); + = new UnicodeBlock(0x02B0, 0x02FF, + "SPACING_MODIFIER_LETTERS", + "Spacing Modifier Letters"); /** * Combining Diacritical Marks. - * '\u0300' - '\u036F'. + * 0x0300 - 0x036F. */ public static final UnicodeBlock COMBINING_DIACRITICAL_MARKS - = new UnicodeBlock('\u0300', '\u036F', - "COMBINING_DIACRITICAL_MARKS"); + = new UnicodeBlock(0x0300, 0x036F, + "COMBINING_DIACRITICAL_MARKS", + "Combining Diacritical Marks"); /** * Greek. - * '\u0370' - '\u03FF'. + * 0x0370 - 0x03FF. */ public static final UnicodeBlock GREEK - = new UnicodeBlock('\u0370', '\u03FF', - "GREEK"); + = new UnicodeBlock(0x0370, 0x03FF, + "GREEK", + "Greek"); /** * Cyrillic. - * '\u0400' - '\u04FF'. + * 0x0400 - 0x04FF. */ public static final UnicodeBlock CYRILLIC - = new UnicodeBlock('\u0400', '\u04FF', - "CYRILLIC"); + = new UnicodeBlock(0x0400, 0x04FF, + "CYRILLIC", + "Cyrillic"); + + /** + * Cyrillic Supplementary. + * 0x0500 - 0x052F. + * @since 1.5 + */ + public static final UnicodeBlock CYRILLIC_SUPPLEMENTARY + = new UnicodeBlock(0x0500, 0x052F, + "CYRILLIC_SUPPLEMENTARY", + "Cyrillic Supplementary"); /** * Armenian. - * '\u0530' - '\u058F'. + * 0x0530 - 0x058F. */ public static final UnicodeBlock ARMENIAN - = new UnicodeBlock('\u0530', '\u058F', - "ARMENIAN"); + = new UnicodeBlock(0x0530, 0x058F, + "ARMENIAN", + "Armenian"); /** * Hebrew. - * '\u0590' - '\u05FF'. + * 0x0590 - 0x05FF. */ public static final UnicodeBlock HEBREW - = new UnicodeBlock('\u0590', '\u05FF', - "HEBREW"); + = new UnicodeBlock(0x0590, 0x05FF, + "HEBREW", + "Hebrew"); /** * Arabic. - * '\u0600' - '\u06FF'. + * 0x0600 - 0x06FF. */ public static final UnicodeBlock ARABIC - = new UnicodeBlock('\u0600', '\u06FF', - "ARABIC"); + = new UnicodeBlock(0x0600, 0x06FF, + "ARABIC", + "Arabic"); /** * Syriac. - * '\u0700' - '\u074F'. + * 0x0700 - 0x074F. * @since 1.4 */ public static final UnicodeBlock SYRIAC - = new UnicodeBlock('\u0700', '\u074F', - "SYRIAC"); + = new UnicodeBlock(0x0700, 0x074F, + "SYRIAC", + "Syriac"); /** * Thaana. - * '\u0780' - '\u07BF'. + * 0x0780 - 0x07BF. * @since 1.4 */ public static final UnicodeBlock THAANA - = new UnicodeBlock('\u0780', '\u07BF', - "THAANA"); + = new UnicodeBlock(0x0780, 0x07BF, + "THAANA", + "Thaana"); /** * Devanagari. - * '\u0900' - '\u097F'. + * 0x0900 - 0x097F. */ public static final UnicodeBlock DEVANAGARI - = new UnicodeBlock('\u0900', '\u097F', - "DEVANAGARI"); + = new UnicodeBlock(0x0900, 0x097F, + "DEVANAGARI", + "Devanagari"); /** * Bengali. - * '\u0980' - '\u09FF'. + * 0x0980 - 0x09FF. */ public static final UnicodeBlock BENGALI - = new UnicodeBlock('\u0980', '\u09FF', - "BENGALI"); + = new UnicodeBlock(0x0980, 0x09FF, + "BENGALI", + "Bengali"); /** * Gurmukhi. - * '\u0A00' - '\u0A7F'. + * 0x0A00 - 0x0A7F. */ public static final UnicodeBlock GURMUKHI - = new UnicodeBlock('\u0A00', '\u0A7F', - "GURMUKHI"); + = new UnicodeBlock(0x0A00, 0x0A7F, + "GURMUKHI", + "Gurmukhi"); /** * Gujarati. - * '\u0A80' - '\u0AFF'. + * 0x0A80 - 0x0AFF. */ public static final UnicodeBlock GUJARATI - = new UnicodeBlock('\u0A80', '\u0AFF', - "GUJARATI"); + = new UnicodeBlock(0x0A80, 0x0AFF, + "GUJARATI", + "Gujarati"); /** * Oriya. - * '\u0B00' - '\u0B7F'. + * 0x0B00 - 0x0B7F. */ public static final UnicodeBlock ORIYA - = new UnicodeBlock('\u0B00', '\u0B7F', - "ORIYA"); + = new UnicodeBlock(0x0B00, 0x0B7F, + "ORIYA", + "Oriya"); /** * Tamil. - * '\u0B80' - '\u0BFF'. + * 0x0B80 - 0x0BFF. */ public static final UnicodeBlock TAMIL - = new UnicodeBlock('\u0B80', '\u0BFF', - "TAMIL"); + = new UnicodeBlock(0x0B80, 0x0BFF, + "TAMIL", + "Tamil"); /** * Telugu. - * '\u0C00' - '\u0C7F'. + * 0x0C00 - 0x0C7F. */ public static final UnicodeBlock TELUGU - = new UnicodeBlock('\u0C00', '\u0C7F', - "TELUGU"); + = new UnicodeBlock(0x0C00, 0x0C7F, + "TELUGU", + "Telugu"); /** * Kannada. - * '\u0C80' - '\u0CFF'. + * 0x0C80 - 0x0CFF. */ public static final UnicodeBlock KANNADA - = new UnicodeBlock('\u0C80', '\u0CFF', - "KANNADA"); + = new UnicodeBlock(0x0C80, 0x0CFF, + "KANNADA", + "Kannada"); /** * Malayalam. - * '\u0D00' - '\u0D7F'. + * 0x0D00 - 0x0D7F. */ public static final UnicodeBlock MALAYALAM - = new UnicodeBlock('\u0D00', '\u0D7F', - "MALAYALAM"); + = new UnicodeBlock(0x0D00, 0x0D7F, + "MALAYALAM", + "Malayalam"); /** * Sinhala. - * '\u0D80' - '\u0DFF'. + * 0x0D80 - 0x0DFF. * @since 1.4 */ public static final UnicodeBlock SINHALA - = new UnicodeBlock('\u0D80', '\u0DFF', - "SINHALA"); + = new UnicodeBlock(0x0D80, 0x0DFF, + "SINHALA", + "Sinhala"); /** * Thai. - * '\u0E00' - '\u0E7F'. + * 0x0E00 - 0x0E7F. */ public static final UnicodeBlock THAI - = new UnicodeBlock('\u0E00', '\u0E7F', - "THAI"); + = new UnicodeBlock(0x0E00, 0x0E7F, + "THAI", + "Thai"); /** * Lao. - * '\u0E80' - '\u0EFF'. + * 0x0E80 - 0x0EFF. */ public static final UnicodeBlock LAO - = new UnicodeBlock('\u0E80', '\u0EFF', - "LAO"); + = new UnicodeBlock(0x0E80, 0x0EFF, + "LAO", + "Lao"); /** * Tibetan. - * '\u0F00' - '\u0FFF'. + * 0x0F00 - 0x0FFF. */ public static final UnicodeBlock TIBETAN - = new UnicodeBlock('\u0F00', '\u0FFF', - "TIBETAN"); + = new UnicodeBlock(0x0F00, 0x0FFF, + "TIBETAN", + "Tibetan"); /** * Myanmar. - * '\u1000' - '\u109F'. + * 0x1000 - 0x109F. * @since 1.4 */ public static final UnicodeBlock MYANMAR - = new UnicodeBlock('\u1000', '\u109F', - "MYANMAR"); + = new UnicodeBlock(0x1000, 0x109F, + "MYANMAR", + "Myanmar"); /** * Georgian. - * '\u10A0' - '\u10FF'. + * 0x10A0 - 0x10FF. */ public static final UnicodeBlock GEORGIAN - = new UnicodeBlock('\u10A0', '\u10FF', - "GEORGIAN"); + = new UnicodeBlock(0x10A0, 0x10FF, + "GEORGIAN", + "Georgian"); /** * Hangul Jamo. - * '\u1100' - '\u11FF'. + * 0x1100 - 0x11FF. */ public static final UnicodeBlock HANGUL_JAMO - = new UnicodeBlock('\u1100', '\u11FF', - "HANGUL_JAMO"); + = new UnicodeBlock(0x1100, 0x11FF, + "HANGUL_JAMO", + "Hangul Jamo"); /** * Ethiopic. - * '\u1200' - '\u137F'. + * 0x1200 - 0x137F. * @since 1.4 */ public static final UnicodeBlock ETHIOPIC - = new UnicodeBlock('\u1200', '\u137F', - "ETHIOPIC"); + = new UnicodeBlock(0x1200, 0x137F, + "ETHIOPIC", + "Ethiopic"); /** * Cherokee. - * '\u13A0' - '\u13FF'. + * 0x13A0 - 0x13FF. * @since 1.4 */ public static final UnicodeBlock CHEROKEE - = new UnicodeBlock('\u13A0', '\u13FF', - "CHEROKEE"); + = new UnicodeBlock(0x13A0, 0x13FF, + "CHEROKEE", + "Cherokee"); /** * Unified Canadian Aboriginal Syllabics. - * '\u1400' - '\u167F'. + * 0x1400 - 0x167F. * @since 1.4 */ public static final UnicodeBlock UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS - = new UnicodeBlock('\u1400', '\u167F', - "UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS"); + = new UnicodeBlock(0x1400, 0x167F, + "UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS", + "Unified Canadian Aboriginal Syllabics"); /** * Ogham. - * '\u1680' - '\u169F'. + * 0x1680 - 0x169F. * @since 1.4 */ public static final UnicodeBlock OGHAM - = new UnicodeBlock('\u1680', '\u169F', - "OGHAM"); + = new UnicodeBlock(0x1680, 0x169F, + "OGHAM", + "Ogham"); /** * Runic. - * '\u16A0' - '\u16FF'. + * 0x16A0 - 0x16FF. * @since 1.4 */ public static final UnicodeBlock RUNIC - = new UnicodeBlock('\u16A0', '\u16FF', - "RUNIC"); + = new UnicodeBlock(0x16A0, 0x16FF, + "RUNIC", + "Runic"); + + /** + * Tagalog. + * 0x1700 - 0x171F. + * @since 1.5 + */ + public static final UnicodeBlock TAGALOG + = new UnicodeBlock(0x1700, 0x171F, + "TAGALOG", + "Tagalog"); + + /** + * Hanunoo. + * 0x1720 - 0x173F. + * @since 1.5 + */ + public static final UnicodeBlock HANUNOO + = new UnicodeBlock(0x1720, 0x173F, + "HANUNOO", + "Hanunoo"); + + /** + * Buhid. + * 0x1740 - 0x175F. + * @since 1.5 + */ + public static final UnicodeBlock BUHID + = new UnicodeBlock(0x1740, 0x175F, + "BUHID", + "Buhid"); + + /** + * Tagbanwa. + * 0x1760 - 0x177F. + * @since 1.5 + */ + public static final UnicodeBlock TAGBANWA + = new UnicodeBlock(0x1760, 0x177F, + "TAGBANWA", + "Tagbanwa"); /** * Khmer. - * '\u1780' - '\u17FF'. + * 0x1780 - 0x17FF. * @since 1.4 */ public static final UnicodeBlock KHMER - = new UnicodeBlock('\u1780', '\u17FF', - "KHMER"); + = new UnicodeBlock(0x1780, 0x17FF, + "KHMER", + "Khmer"); /** * Mongolian. - * '\u1800' - '\u18AF'. + * 0x1800 - 0x18AF. * @since 1.4 */ public static final UnicodeBlock MONGOLIAN - = new UnicodeBlock('\u1800', '\u18AF', - "MONGOLIAN"); + = new UnicodeBlock(0x1800, 0x18AF, + "MONGOLIAN", + "Mongolian"); + + /** + * Limbu. + * 0x1900 - 0x194F. + * @since 1.5 + */ + public static final UnicodeBlock LIMBU + = new UnicodeBlock(0x1900, 0x194F, + "LIMBU", + "Limbu"); + + /** + * Tai Le. + * 0x1950 - 0x197F. + * @since 1.5 + */ + public static final UnicodeBlock TAI_LE + = new UnicodeBlock(0x1950, 0x197F, + "TAI_LE", + "Tai Le"); + + /** + * Khmer Symbols. + * 0x19E0 - 0x19FF. + * @since 1.5 + */ + public static final UnicodeBlock KHMER_SYMBOLS + = new UnicodeBlock(0x19E0, 0x19FF, + "KHMER_SYMBOLS", + "Khmer Symbols"); + + /** + * Phonetic Extensions. + * 0x1D00 - 0x1D7F. + * @since 1.5 + */ + public static final UnicodeBlock PHONETIC_EXTENSIONS + = new UnicodeBlock(0x1D00, 0x1D7F, + "PHONETIC_EXTENSIONS", + "Phonetic Extensions"); /** * Latin Extended Additional. - * '\u1E00' - '\u1EFF'. + * 0x1E00 - 0x1EFF. */ public static final UnicodeBlock LATIN_EXTENDED_ADDITIONAL - = new UnicodeBlock('\u1E00', '\u1EFF', - "LATIN_EXTENDED_ADDITIONAL"); + = new UnicodeBlock(0x1E00, 0x1EFF, + "LATIN_EXTENDED_ADDITIONAL", + "Latin Extended Additional"); /** * Greek Extended. - * '\u1F00' - '\u1FFF'. + * 0x1F00 - 0x1FFF. */ public static final UnicodeBlock GREEK_EXTENDED - = new UnicodeBlock('\u1F00', '\u1FFF', - "GREEK_EXTENDED"); + = new UnicodeBlock(0x1F00, 0x1FFF, + "GREEK_EXTENDED", + "Greek Extended"); /** * General Punctuation. - * '\u2000' - '\u206F'. + * 0x2000 - 0x206F. */ public static final UnicodeBlock GENERAL_PUNCTUATION - = new UnicodeBlock('\u2000', '\u206F', - "GENERAL_PUNCTUATION"); + = new UnicodeBlock(0x2000, 0x206F, + "GENERAL_PUNCTUATION", + "General Punctuation"); /** * Superscripts and Subscripts. - * '\u2070' - '\u209F'. + * 0x2070 - 0x209F. */ public static final UnicodeBlock SUPERSCRIPTS_AND_SUBSCRIPTS - = new UnicodeBlock('\u2070', '\u209F', - "SUPERSCRIPTS_AND_SUBSCRIPTS"); + = new UnicodeBlock(0x2070, 0x209F, + "SUPERSCRIPTS_AND_SUBSCRIPTS", + "Superscripts and Subscripts"); /** * Currency Symbols. - * '\u20A0' - '\u20CF'. + * 0x20A0 - 0x20CF. */ public static final UnicodeBlock CURRENCY_SYMBOLS - = new UnicodeBlock('\u20A0', '\u20CF', - "CURRENCY_SYMBOLS"); + = new UnicodeBlock(0x20A0, 0x20CF, + "CURRENCY_SYMBOLS", + "Currency Symbols"); /** * Combining Marks for Symbols. - * '\u20D0' - '\u20FF'. + * 0x20D0 - 0x20FF. */ public static final UnicodeBlock COMBINING_MARKS_FOR_SYMBOLS - = new UnicodeBlock('\u20D0', '\u20FF', - "COMBINING_MARKS_FOR_SYMBOLS"); + = new UnicodeBlock(0x20D0, 0x20FF, + "COMBINING_MARKS_FOR_SYMBOLS", + "Combining Marks for Symbols"); /** * Letterlike Symbols. - * '\u2100' - '\u214F'. + * 0x2100 - 0x214F. */ public static final UnicodeBlock LETTERLIKE_SYMBOLS - = new UnicodeBlock('\u2100', '\u214F', - "LETTERLIKE_SYMBOLS"); + = new UnicodeBlock(0x2100, 0x214F, + "LETTERLIKE_SYMBOLS", + "Letterlike Symbols"); /** * Number Forms. - * '\u2150' - '\u218F'. + * 0x2150 - 0x218F. */ public static final UnicodeBlock NUMBER_FORMS - = new UnicodeBlock('\u2150', '\u218F', - "NUMBER_FORMS"); + = new UnicodeBlock(0x2150, 0x218F, + "NUMBER_FORMS", + "Number Forms"); /** * Arrows. - * '\u2190' - '\u21FF'. + * 0x2190 - 0x21FF. */ public static final UnicodeBlock ARROWS - = new UnicodeBlock('\u2190', '\u21FF', - "ARROWS"); + = new UnicodeBlock(0x2190, 0x21FF, + "ARROWS", + "Arrows"); /** * Mathematical Operators. - * '\u2200' - '\u22FF'. + * 0x2200 - 0x22FF. */ public static final UnicodeBlock MATHEMATICAL_OPERATORS - = new UnicodeBlock('\u2200', '\u22FF', - "MATHEMATICAL_OPERATORS"); + = new UnicodeBlock(0x2200, 0x22FF, + "MATHEMATICAL_OPERATORS", + "Mathematical Operators"); /** * Miscellaneous Technical. - * '\u2300' - '\u23FF'. + * 0x2300 - 0x23FF. */ public static final UnicodeBlock MISCELLANEOUS_TECHNICAL - = new UnicodeBlock('\u2300', '\u23FF', - "MISCELLANEOUS_TECHNICAL"); + = new UnicodeBlock(0x2300, 0x23FF, + "MISCELLANEOUS_TECHNICAL", + "Miscellaneous Technical"); /** * Control Pictures. - * '\u2400' - '\u243F'. + * 0x2400 - 0x243F. */ public static final UnicodeBlock CONTROL_PICTURES - = new UnicodeBlock('\u2400', '\u243F', - "CONTROL_PICTURES"); + = new UnicodeBlock(0x2400, 0x243F, + "CONTROL_PICTURES", + "Control Pictures"); /** * Optical Character Recognition. - * '\u2440' - '\u245F'. + * 0x2440 - 0x245F. */ public static final UnicodeBlock OPTICAL_CHARACTER_RECOGNITION - = new UnicodeBlock('\u2440', '\u245F', - "OPTICAL_CHARACTER_RECOGNITION"); + = new UnicodeBlock(0x2440, 0x245F, + "OPTICAL_CHARACTER_RECOGNITION", + "Optical Character Recognition"); /** * Enclosed Alphanumerics. - * '\u2460' - '\u24FF'. + * 0x2460 - 0x24FF. */ public static final UnicodeBlock ENCLOSED_ALPHANUMERICS - = new UnicodeBlock('\u2460', '\u24FF', - "ENCLOSED_ALPHANUMERICS"); + = new UnicodeBlock(0x2460, 0x24FF, + "ENCLOSED_ALPHANUMERICS", + "Enclosed Alphanumerics"); /** * Box Drawing. - * '\u2500' - '\u257F'. + * 0x2500 - 0x257F. */ public static final UnicodeBlock BOX_DRAWING - = new UnicodeBlock('\u2500', '\u257F', - "BOX_DRAWING"); + = new UnicodeBlock(0x2500, 0x257F, + "BOX_DRAWING", + "Box Drawing"); /** * Block Elements. - * '\u2580' - '\u259F'. + * 0x2580 - 0x259F. */ public static final UnicodeBlock BLOCK_ELEMENTS - = new UnicodeBlock('\u2580', '\u259F', - "BLOCK_ELEMENTS"); + = new UnicodeBlock(0x2580, 0x259F, + "BLOCK_ELEMENTS", + "Block Elements"); /** * Geometric Shapes. - * '\u25A0' - '\u25FF'. + * 0x25A0 - 0x25FF. */ public static final UnicodeBlock GEOMETRIC_SHAPES - = new UnicodeBlock('\u25A0', '\u25FF', - "GEOMETRIC_SHAPES"); + = new UnicodeBlock(0x25A0, 0x25FF, + "GEOMETRIC_SHAPES", + "Geometric Shapes"); /** * Miscellaneous Symbols. - * '\u2600' - '\u26FF'. + * 0x2600 - 0x26FF. */ public static final UnicodeBlock MISCELLANEOUS_SYMBOLS - = new UnicodeBlock('\u2600', '\u26FF', - "MISCELLANEOUS_SYMBOLS"); + = new UnicodeBlock(0x2600, 0x26FF, + "MISCELLANEOUS_SYMBOLS", + "Miscellaneous Symbols"); /** * Dingbats. - * '\u2700' - '\u27BF'. + * 0x2700 - 0x27BF. */ public static final UnicodeBlock DINGBATS - = new UnicodeBlock('\u2700', '\u27BF', - "DINGBATS"); + = new UnicodeBlock(0x2700, 0x27BF, + "DINGBATS", + "Dingbats"); + + /** + * Miscellaneous Mathematical Symbols-A. + * 0x27C0 - 0x27EF. + * @since 1.5 + */ + public static final UnicodeBlock MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A + = new UnicodeBlock(0x27C0, 0x27EF, + "MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A", + "Miscellaneous Mathematical Symbols-A"); + + /** + * Supplemental Arrows-A. + * 0x27F0 - 0x27FF. + * @since 1.5 + */ + public static final UnicodeBlock SUPPLEMENTAL_ARROWS_A + = new UnicodeBlock(0x27F0, 0x27FF, + "SUPPLEMENTAL_ARROWS_A", + "Supplemental Arrows-A"); /** * Braille Patterns. - * '\u2800' - '\u28FF'. + * 0x2800 - 0x28FF. * @since 1.4 */ public static final UnicodeBlock BRAILLE_PATTERNS - = new UnicodeBlock('\u2800', '\u28FF', - "BRAILLE_PATTERNS"); + = new UnicodeBlock(0x2800, 0x28FF, + "BRAILLE_PATTERNS", + "Braille Patterns"); + + /** + * Supplemental Arrows-B. + * 0x2900 - 0x297F. + * @since 1.5 + */ + public static final UnicodeBlock SUPPLEMENTAL_ARROWS_B + = new UnicodeBlock(0x2900, 0x297F, + "SUPPLEMENTAL_ARROWS_B", + "Supplemental Arrows-B"); + + /** + * Miscellaneous Mathematical Symbols-B. + * 0x2980 - 0x29FF. + * @since 1.5 + */ + public static final UnicodeBlock MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B + = new UnicodeBlock(0x2980, 0x29FF, + "MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B", + "Miscellaneous Mathematical Symbols-B"); + + /** + * Supplemental Mathematical Operators. + * 0x2A00 - 0x2AFF. + * @since 1.5 + */ + public static final UnicodeBlock SUPPLEMENTAL_MATHEMATICAL_OPERATORS + = new UnicodeBlock(0x2A00, 0x2AFF, + "SUPPLEMENTAL_MATHEMATICAL_OPERATORS", + "Supplemental Mathematical Operators"); + + /** + * Miscellaneous Symbols and Arrows. + * 0x2B00 - 0x2BFF. + * @since 1.5 + */ + public static final UnicodeBlock MISCELLANEOUS_SYMBOLS_AND_ARROWS + = new UnicodeBlock(0x2B00, 0x2BFF, + "MISCELLANEOUS_SYMBOLS_AND_ARROWS", + "Miscellaneous Symbols and Arrows"); /** * CJK Radicals Supplement. - * '\u2E80' - '\u2EFF'. + * 0x2E80 - 0x2EFF. * @since 1.4 */ public static final UnicodeBlock CJK_RADICALS_SUPPLEMENT - = new UnicodeBlock('\u2E80', '\u2EFF', - "CJK_RADICALS_SUPPLEMENT"); + = new UnicodeBlock(0x2E80, 0x2EFF, + "CJK_RADICALS_SUPPLEMENT", + "CJK Radicals Supplement"); /** * Kangxi Radicals. - * '\u2F00' - '\u2FDF'. + * 0x2F00 - 0x2FDF. * @since 1.4 */ public static final UnicodeBlock KANGXI_RADICALS - = new UnicodeBlock('\u2F00', '\u2FDF', - "KANGXI_RADICALS"); + = new UnicodeBlock(0x2F00, 0x2FDF, + "KANGXI_RADICALS", + "Kangxi Radicals"); /** * Ideographic Description Characters. - * '\u2FF0' - '\u2FFF'. + * 0x2FF0 - 0x2FFF. * @since 1.4 */ public static final UnicodeBlock IDEOGRAPHIC_DESCRIPTION_CHARACTERS - = new UnicodeBlock('\u2FF0', '\u2FFF', - "IDEOGRAPHIC_DESCRIPTION_CHARACTERS"); + = new UnicodeBlock(0x2FF0, 0x2FFF, + "IDEOGRAPHIC_DESCRIPTION_CHARACTERS", + "Ideographic Description Characters"); /** * CJK Symbols and Punctuation. - * '\u3000' - '\u303F'. + * 0x3000 - 0x303F. */ public static final UnicodeBlock CJK_SYMBOLS_AND_PUNCTUATION - = new UnicodeBlock('\u3000', '\u303F', - "CJK_SYMBOLS_AND_PUNCTUATION"); + = new UnicodeBlock(0x3000, 0x303F, + "CJK_SYMBOLS_AND_PUNCTUATION", + "CJK Symbols and Punctuation"); /** * Hiragana. - * '\u3040' - '\u309F'. + * 0x3040 - 0x309F. */ public static final UnicodeBlock HIRAGANA - = new UnicodeBlock('\u3040', '\u309F', - "HIRAGANA"); + = new UnicodeBlock(0x3040, 0x309F, + "HIRAGANA", + "Hiragana"); /** * Katakana. - * '\u30A0' - '\u30FF'. + * 0x30A0 - 0x30FF. */ public static final UnicodeBlock KATAKANA - = new UnicodeBlock('\u30A0', '\u30FF', - "KATAKANA"); + = new UnicodeBlock(0x30A0, 0x30FF, + "KATAKANA", + "Katakana"); /** * Bopomofo. - * '\u3100' - '\u312F'. + * 0x3100 - 0x312F. */ public static final UnicodeBlock BOPOMOFO - = new UnicodeBlock('\u3100', '\u312F', - "BOPOMOFO"); + = new UnicodeBlock(0x3100, 0x312F, + "BOPOMOFO", + "Bopomofo"); /** * Hangul Compatibility Jamo. - * '\u3130' - '\u318F'. + * 0x3130 - 0x318F. */ public static final UnicodeBlock HANGUL_COMPATIBILITY_JAMO - = new UnicodeBlock('\u3130', '\u318F', - "HANGUL_COMPATIBILITY_JAMO"); + = new UnicodeBlock(0x3130, 0x318F, + "HANGUL_COMPATIBILITY_JAMO", + "Hangul Compatibility Jamo"); /** * Kanbun. - * '\u3190' - '\u319F'. + * 0x3190 - 0x319F. */ public static final UnicodeBlock KANBUN - = new UnicodeBlock('\u3190', '\u319F', - "KANBUN"); + = new UnicodeBlock(0x3190, 0x319F, + "KANBUN", + "Kanbun"); /** * Bopomofo Extended. - * '\u31A0' - '\u31BF'. + * 0x31A0 - 0x31BF. * @since 1.4 */ public static final UnicodeBlock BOPOMOFO_EXTENDED - = new UnicodeBlock('\u31A0', '\u31BF', - "BOPOMOFO_EXTENDED"); + = new UnicodeBlock(0x31A0, 0x31BF, + "BOPOMOFO_EXTENDED", + "Bopomofo Extended"); + + /** + * Katakana Phonetic Extensions. + * 0x31F0 - 0x31FF. + * @since 1.5 + */ + public static final UnicodeBlock KATAKANA_PHONETIC_EXTENSIONS + = new UnicodeBlock(0x31F0, 0x31FF, + "KATAKANA_PHONETIC_EXTENSIONS", + "Katakana Phonetic Extensions"); /** * Enclosed CJK Letters and Months. - * '\u3200' - '\u32FF'. + * 0x3200 - 0x32FF. */ public static final UnicodeBlock ENCLOSED_CJK_LETTERS_AND_MONTHS - = new UnicodeBlock('\u3200', '\u32FF', - "ENCLOSED_CJK_LETTERS_AND_MONTHS"); + = new UnicodeBlock(0x3200, 0x32FF, + "ENCLOSED_CJK_LETTERS_AND_MONTHS", + "Enclosed CJK Letters and Months"); /** * CJK Compatibility. - * '\u3300' - '\u33FF'. + * 0x3300 - 0x33FF. */ public static final UnicodeBlock CJK_COMPATIBILITY - = new UnicodeBlock('\u3300', '\u33FF', - "CJK_COMPATIBILITY"); + = new UnicodeBlock(0x3300, 0x33FF, + "CJK_COMPATIBILITY", + "CJK Compatibility"); /** * CJK Unified Ideographs Extension A. - * '\u3400' - '\u4DB5'. + * 0x3400 - 0x4DBF. * @since 1.4 */ public static final UnicodeBlock CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A - = new UnicodeBlock('\u3400', '\u4DB5', - "CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A"); + = new UnicodeBlock(0x3400, 0x4DBF, + "CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A", + "CJK Unified Ideographs Extension A"); + + /** + * Yijing Hexagram Symbols. + * 0x4DC0 - 0x4DFF. + * @since 1.5 + */ + public static final UnicodeBlock YIJING_HEXAGRAM_SYMBOLS + = new UnicodeBlock(0x4DC0, 0x4DFF, + "YIJING_HEXAGRAM_SYMBOLS", + "Yijing Hexagram Symbols"); /** * CJK Unified Ideographs. - * '\u4E00' - '\u9FFF'. + * 0x4E00 - 0x9FFF. */ public static final UnicodeBlock CJK_UNIFIED_IDEOGRAPHS - = new UnicodeBlock('\u4E00', '\u9FFF', - "CJK_UNIFIED_IDEOGRAPHS"); + = new UnicodeBlock(0x4E00, 0x9FFF, + "CJK_UNIFIED_IDEOGRAPHS", + "CJK Unified Ideographs"); /** * Yi Syllables. - * '\uA000' - '\uA48F'. + * 0xA000 - 0xA48F. * @since 1.4 */ public static final UnicodeBlock YI_SYLLABLES - = new UnicodeBlock('\uA000', '\uA48F', - "YI_SYLLABLES"); + = new UnicodeBlock(0xA000, 0xA48F, + "YI_SYLLABLES", + "Yi Syllables"); /** * Yi Radicals. - * '\uA490' - '\uA4CF'. + * 0xA490 - 0xA4CF. * @since 1.4 */ public static final UnicodeBlock YI_RADICALS - = new UnicodeBlock('\uA490', '\uA4CF', - "YI_RADICALS"); + = new UnicodeBlock(0xA490, 0xA4CF, + "YI_RADICALS", + "Yi Radicals"); /** * Hangul Syllables. - * '\uAC00' - '\uD7A3'. + * 0xAC00 - 0xD7AF. */ public static final UnicodeBlock HANGUL_SYLLABLES - = new UnicodeBlock('\uAC00', '\uD7A3', - "HANGUL_SYLLABLES"); + = new UnicodeBlock(0xAC00, 0xD7AF, + "HANGUL_SYLLABLES", + "Hangul Syllables"); /** - * Surrogates Area. - * '\uD800' - '\uDFFF'. + * High Surrogates. + * 0xD800 - 0xDB7F. + * @since 1.5 */ - public static final UnicodeBlock SURROGATES_AREA - = new UnicodeBlock('\uD800', '\uDFFF', - "SURROGATES_AREA"); + public static final UnicodeBlock HIGH_SURROGATES + = new UnicodeBlock(0xD800, 0xDB7F, + "HIGH_SURROGATES", + "High Surrogates"); + + /** + * High Private Use Surrogates. + * 0xDB80 - 0xDBFF. + * @since 1.5 + */ + public static final UnicodeBlock HIGH_PRIVATE_USE_SURROGATES + = new UnicodeBlock(0xDB80, 0xDBFF, + "HIGH_PRIVATE_USE_SURROGATES", + "High Private Use Surrogates"); + + /** + * Low Surrogates. + * 0xDC00 - 0xDFFF. + * @since 1.5 + */ + public static final UnicodeBlock LOW_SURROGATES + = new UnicodeBlock(0xDC00, 0xDFFF, + "LOW_SURROGATES", + "Low Surrogates"); /** * Private Use Area. - * '\uE000' - '\uF8FF'. + * 0xE000 - 0xF8FF. */ public static final UnicodeBlock PRIVATE_USE_AREA - = new UnicodeBlock('\uE000', '\uF8FF', - "PRIVATE_USE_AREA"); + = new UnicodeBlock(0xE000, 0xF8FF, + "PRIVATE_USE_AREA", + "Private Use Area"); /** * CJK Compatibility Ideographs. - * '\uF900' - '\uFAFF'. + * 0xF900 - 0xFAFF. */ public static final UnicodeBlock CJK_COMPATIBILITY_IDEOGRAPHS - = new UnicodeBlock('\uF900', '\uFAFF', - "CJK_COMPATIBILITY_IDEOGRAPHS"); + = new UnicodeBlock(0xF900, 0xFAFF, + "CJK_COMPATIBILITY_IDEOGRAPHS", + "CJK Compatibility Ideographs"); /** * Alphabetic Presentation Forms. - * '\uFB00' - '\uFB4F'. + * 0xFB00 - 0xFB4F. */ public static final UnicodeBlock ALPHABETIC_PRESENTATION_FORMS - = new UnicodeBlock('\uFB00', '\uFB4F', - "ALPHABETIC_PRESENTATION_FORMS"); + = new UnicodeBlock(0xFB00, 0xFB4F, + "ALPHABETIC_PRESENTATION_FORMS", + "Alphabetic Presentation Forms"); /** * Arabic Presentation Forms-A. - * '\uFB50' - '\uFDFF'. + * 0xFB50 - 0xFDFF. */ public static final UnicodeBlock ARABIC_PRESENTATION_FORMS_A - = new UnicodeBlock('\uFB50', '\uFDFF', - "ARABIC_PRESENTATION_FORMS_A"); + = new UnicodeBlock(0xFB50, 0xFDFF, + "ARABIC_PRESENTATION_FORMS_A", + "Arabic Presentation Forms-A"); + + /** + * Variation Selectors. + * 0xFE00 - 0xFE0F. + * @since 1.5 + */ + public static final UnicodeBlock VARIATION_SELECTORS + = new UnicodeBlock(0xFE00, 0xFE0F, + "VARIATION_SELECTORS", + "Variation Selectors"); /** * Combining Half Marks. - * '\uFE20' - '\uFE2F'. + * 0xFE20 - 0xFE2F. */ public static final UnicodeBlock COMBINING_HALF_MARKS - = new UnicodeBlock('\uFE20', '\uFE2F', - "COMBINING_HALF_MARKS"); + = new UnicodeBlock(0xFE20, 0xFE2F, + "COMBINING_HALF_MARKS", + "Combining Half Marks"); /** * CJK Compatibility Forms. - * '\uFE30' - '\uFE4F'. + * 0xFE30 - 0xFE4F. */ public static final UnicodeBlock CJK_COMPATIBILITY_FORMS - = new UnicodeBlock('\uFE30', '\uFE4F', - "CJK_COMPATIBILITY_FORMS"); + = new UnicodeBlock(0xFE30, 0xFE4F, + "CJK_COMPATIBILITY_FORMS", + "CJK Compatibility Forms"); /** * Small Form Variants. - * '\uFE50' - '\uFE6F'. + * 0xFE50 - 0xFE6F. */ public static final UnicodeBlock SMALL_FORM_VARIANTS - = new UnicodeBlock('\uFE50', '\uFE6F', - "SMALL_FORM_VARIANTS"); + = new UnicodeBlock(0xFE50, 0xFE6F, + "SMALL_FORM_VARIANTS", + "Small Form Variants"); /** * Arabic Presentation Forms-B. - * '\uFE70' - '\uFEFE'. + * 0xFE70 - 0xFEFF. */ public static final UnicodeBlock ARABIC_PRESENTATION_FORMS_B - = new UnicodeBlock('\uFE70', '\uFEFE', - "ARABIC_PRESENTATION_FORMS_B"); + = new UnicodeBlock(0xFE70, 0xFEFF, + "ARABIC_PRESENTATION_FORMS_B", + "Arabic Presentation Forms-B"); /** * Halfwidth and Fullwidth Forms. - * '\uFF00' - '\uFFEF'. + * 0xFF00 - 0xFFEF. */ public static final UnicodeBlock HALFWIDTH_AND_FULLWIDTH_FORMS - = new UnicodeBlock('\uFF00', '\uFFEF', - "HALFWIDTH_AND_FULLWIDTH_FORMS"); + = new UnicodeBlock(0xFF00, 0xFFEF, + "HALFWIDTH_AND_FULLWIDTH_FORMS", + "Halfwidth and Fullwidth Forms"); /** * Specials. - * '\uFEFF', '\uFFF0' - '\uFFFD'. + * 0xFFF0 - 0xFFFF. */ public static final UnicodeBlock SPECIALS - = new UnicodeBlock('\uFFF0', '\uFFFD', - "SPECIALS"); + = new UnicodeBlock(0xFFF0, 0xFFFF, + "SPECIALS", + "Specials"); + + /** + * Linear B Syllabary. + * 0x10000 - 0x1007F. + * @since 1.5 + */ + public static final UnicodeBlock LINEAR_B_SYLLABARY + = new UnicodeBlock(0x10000, 0x1007F, + "LINEAR_B_SYLLABARY", + "Linear B Syllabary"); + + /** + * Linear B Ideograms. + * 0x10080 - 0x100FF. + * @since 1.5 + */ + public static final UnicodeBlock LINEAR_B_IDEOGRAMS + = new UnicodeBlock(0x10080, 0x100FF, + "LINEAR_B_IDEOGRAMS", + "Linear B Ideograms"); + + /** + * Aegean Numbers. + * 0x10100 - 0x1013F. + * @since 1.5 + */ + public static final UnicodeBlock AEGEAN_NUMBERS + = new UnicodeBlock(0x10100, 0x1013F, + "AEGEAN_NUMBERS", + "Aegean Numbers"); + + /** + * Old Italic. + * 0x10300 - 0x1032F. + * @since 1.5 + */ + public static final UnicodeBlock OLD_ITALIC + = new UnicodeBlock(0x10300, 0x1032F, + "OLD_ITALIC", + "Old Italic"); + + /** + * Gothic. + * 0x10330 - 0x1034F. + * @since 1.5 + */ + public static final UnicodeBlock GOTHIC + = new UnicodeBlock(0x10330, 0x1034F, + "GOTHIC", + "Gothic"); + + /** + * Ugaritic. + * 0x10380 - 0x1039F. + * @since 1.5 + */ + public static final UnicodeBlock UGARITIC + = new UnicodeBlock(0x10380, 0x1039F, + "UGARITIC", + "Ugaritic"); + + /** + * Deseret. + * 0x10400 - 0x1044F. + * @since 1.5 + */ + public static final UnicodeBlock DESERET + = new UnicodeBlock(0x10400, 0x1044F, + "DESERET", + "Deseret"); + + /** + * Shavian. + * 0x10450 - 0x1047F. + * @since 1.5 + */ + public static final UnicodeBlock SHAVIAN + = new UnicodeBlock(0x10450, 0x1047F, + "SHAVIAN", + "Shavian"); + + /** + * Osmanya. + * 0x10480 - 0x104AF. + * @since 1.5 + */ + public static final UnicodeBlock OSMANYA + = new UnicodeBlock(0x10480, 0x104AF, + "OSMANYA", + "Osmanya"); + + /** + * Cypriot Syllabary. + * 0x10800 - 0x1083F. + * @since 1.5 + */ + public static final UnicodeBlock CYPRIOT_SYLLABARY + = new UnicodeBlock(0x10800, 0x1083F, + "CYPRIOT_SYLLABARY", + "Cypriot Syllabary"); + + /** + * Byzantine Musical Symbols. + * 0x1D000 - 0x1D0FF. + * @since 1.5 + */ + public static final UnicodeBlock BYZANTINE_MUSICAL_SYMBOLS + = new UnicodeBlock(0x1D000, 0x1D0FF, + "BYZANTINE_MUSICAL_SYMBOLS", + "Byzantine Musical Symbols"); + + /** + * Musical Symbols. + * 0x1D100 - 0x1D1FF. + * @since 1.5 + */ + public static final UnicodeBlock MUSICAL_SYMBOLS + = new UnicodeBlock(0x1D100, 0x1D1FF, + "MUSICAL_SYMBOLS", + "Musical Symbols"); + + /** + * Tai Xuan Jing Symbols. + * 0x1D300 - 0x1D35F. + * @since 1.5 + */ + public static final UnicodeBlock TAI_XUAN_JING_SYMBOLS + = new UnicodeBlock(0x1D300, 0x1D35F, + "TAI_XUAN_JING_SYMBOLS", + "Tai Xuan Jing Symbols"); + + /** + * Mathematical Alphanumeric Symbols. + * 0x1D400 - 0x1D7FF. + * @since 1.5 + */ + public static final UnicodeBlock MATHEMATICAL_ALPHANUMERIC_SYMBOLS + = new UnicodeBlock(0x1D400, 0x1D7FF, + "MATHEMATICAL_ALPHANUMERIC_SYMBOLS", + "Mathematical Alphanumeric Symbols"); + + /** + * CJK Unified Ideographs Extension B. + * 0x20000 - 0x2A6DF. + * @since 1.5 + */ + public static final UnicodeBlock CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B + = new UnicodeBlock(0x20000, 0x2A6DF, + "CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B", + "CJK Unified Ideographs Extension B"); + + /** + * CJK Compatibility Ideographs Supplement. + * 0x2F800 - 0x2FA1F. + * @since 1.5 + */ + public static final UnicodeBlock CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT + = new UnicodeBlock(0x2F800, 0x2FA1F, + "CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT", + "CJK Compatibility Ideographs Supplement"); + + /** + * Tags. + * 0xE0000 - 0xE007F. + * @since 1.5 + */ + public static final UnicodeBlock TAGS + = new UnicodeBlock(0xE0000, 0xE007F, + "TAGS", + "Tags"); + + /** + * Variation Selectors Supplement. + * 0xE0100 - 0xE01EF. + * @since 1.5 + */ + public static final UnicodeBlock VARIATION_SELECTORS_SUPPLEMENT + = new UnicodeBlock(0xE0100, 0xE01EF, + "VARIATION_SELECTORS_SUPPLEMENT", + "Variation Selectors Supplement"); + + /** + * Supplementary Private Use Area-A. + * 0xF0000 - 0xFFFFF. + * @since 1.5 + */ + public static final UnicodeBlock SUPPLEMENTARY_PRIVATE_USE_AREA_A + = new UnicodeBlock(0xF0000, 0xFFFFF, + "SUPPLEMENTARY_PRIVATE_USE_AREA_A", + "Supplementary Private Use Area-A"); + + /** + * Supplementary Private Use Area-B. + * 0x100000 - 0x10FFFF. + * @since 1.5 + */ + public static final UnicodeBlock SUPPLEMENTARY_PRIVATE_USE_AREA_B + = new UnicodeBlock(0x100000, 0x10FFFF, + "SUPPLEMENTARY_PRIVATE_USE_AREA_B", + "Supplementary Private Use Area-B"); + + /** + * Surrogates Area. + * 'D800' - 'DFFF'. + * @deprecated As of 1.5, the three areas, + * HIGH_SURROGATES, + * HIGH_PRIVATE_USE_SURROGATES + * and LOW_SURROGATES, as defined + * by the Unicode standard, should be used in preference to + * this. These are also returned from calls to of(int) + * and of(char). + */ + public static final UnicodeBlock SURROGATES_AREA + = new UnicodeBlock(0xD800, 0xDFFF, + "SURROGATES_AREA", + "Surrogates Area"); /** * The defined subsets. @@ -903,6 +1531,7 @@ public final class Character implements Serializable, Comparable COMBINING_DIACRITICAL_MARKS, GREEK, CYRILLIC, + CYRILLIC_SUPPLEMENTARY, ARMENIAN, HEBREW, ARABIC, @@ -929,8 +1558,16 @@ public final class Character implements Serializable, Comparable UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, OGHAM, RUNIC, + TAGALOG, + HANUNOO, + BUHID, + TAGBANWA, KHMER, MONGOLIAN, + LIMBU, + TAI_LE, + KHMER_SYMBOLS, + PHONETIC_EXTENSIONS, LATIN_EXTENDED_ADDITIONAL, GREEK_EXTENDED, GENERAL_PUNCTUATION, @@ -950,7 +1587,13 @@ public final class Character implements Serializable, Comparable GEOMETRIC_SHAPES, MISCELLANEOUS_SYMBOLS, DINGBATS, + MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A, + SUPPLEMENTAL_ARROWS_A, BRAILLE_PATTERNS, + SUPPLEMENTAL_ARROWS_B, + MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B, + SUPPLEMENTAL_MATHEMATICAL_OPERATORS, + MISCELLANEOUS_SYMBOLS_AND_ARROWS, CJK_RADICALS_SUPPLEMENT, KANGXI_RADICALS, IDEOGRAPHIC_DESCRIPTION_CHARACTERS, @@ -961,99 +1604,408 @@ public final class Character implements Serializable, Comparable HANGUL_COMPATIBILITY_JAMO, KANBUN, BOPOMOFO_EXTENDED, + KATAKANA_PHONETIC_EXTENSIONS, ENCLOSED_CJK_LETTERS_AND_MONTHS, CJK_COMPATIBILITY, CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A, + YIJING_HEXAGRAM_SYMBOLS, CJK_UNIFIED_IDEOGRAPHS, YI_SYLLABLES, YI_RADICALS, HANGUL_SYLLABLES, - SURROGATES_AREA, + HIGH_SURROGATES, + HIGH_PRIVATE_USE_SURROGATES, + LOW_SURROGATES, PRIVATE_USE_AREA, CJK_COMPATIBILITY_IDEOGRAPHS, ALPHABETIC_PRESENTATION_FORMS, ARABIC_PRESENTATION_FORMS_A, + VARIATION_SELECTORS, COMBINING_HALF_MARKS, CJK_COMPATIBILITY_FORMS, SMALL_FORM_VARIANTS, ARABIC_PRESENTATION_FORMS_B, HALFWIDTH_AND_FULLWIDTH_FORMS, SPECIALS, + LINEAR_B_SYLLABARY, + LINEAR_B_IDEOGRAMS, + AEGEAN_NUMBERS, + OLD_ITALIC, + GOTHIC, + UGARITIC, + DESERET, + SHAVIAN, + OSMANYA, + CYPRIOT_SYLLABARY, + BYZANTINE_MUSICAL_SYMBOLS, + MUSICAL_SYMBOLS, + TAI_XUAN_JING_SYMBOLS, + MATHEMATICAL_ALPHANUMERIC_SYMBOLS, + CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B, + CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT, + TAGS, + VARIATION_SELECTORS_SUPPLEMENT, + SUPPLEMENTARY_PRIVATE_USE_AREA_A, + SUPPLEMENTARY_PRIVATE_USE_AREA_B, }; } // class UnicodeBlock /** - * The immutable value of this Character. + * A class to encompass all the properties of characters in the + * private use blocks in the Unicode standard. This class extends + * UnassignedCharacters because the return type from getType() is + * different. + * @author Anthony Balkissoon abalkiss at redhat dot com * - * @serial the value of this Character - */ - private final char value; - - /** - * Compatible with JDK 1.0+. */ - private static final long serialVersionUID = 3786198910865385080L; - + private static class PrivateUseCharacters extends UnassignedCharacters + { + /** + * Returns the type of the character cp. + */ + static int getType(int cp) + { + // The upper 2 code points in any plane are considered unassigned, + // even in the private-use planes. + if ((cp & 0xffff) >= 0xfffe) + return UnassignedCharacters.getType(cp); + return PRIVATE_USE; + } + + /** + * Returns true if the character cp is defined. + */ + static boolean isDefined(int cp) + { + // The upper 2 code points in any plane are considered unassigned, + // even in the private-use planes. + if ((cp & 0xffff) >= 0xfffe) + return UnassignedCharacters.isDefined(cp); + return true; + } + + /** + * Gets the directionality for the character cp. + */ + static byte getDirectionality(int cp) + { + if ((cp & 0xffff) >= 0xfffe) + return UnassignedCharacters.getDirectionality(cp); + return DIRECTIONALITY_LEFT_TO_RIGHT; + } + } + /** - * Smallest value allowed for radix arguments in Java. This value is 2. + * A class to encompass all the properties of code points that are + * currently undefined in the Unicode standard. + * @author Anthony Balkissoon abalkiss at redhat dot com * - * @see #digit(char, int) - * @see #forDigit(int, int) - * @see Integer#toString(int, int) - * @see Integer#valueOf(String) */ - public static final int MIN_RADIX = 2; + private static class UnassignedCharacters + { + /** + * Returns the numeric value for the unassigned characters. + * @param cp the character + * @param radix the radix (not used) + * @return the numeric value of this character in this radix + */ + static int digit(int cp, int radix) + { + return -1; + } - /** - * Largest value allowed for radix arguments in Java. This value is 36. - * - * @see #digit(char, int) - * @see #forDigit(int, int) - * @see Integer#toString(int, int) - * @see Integer#valueOf(String) - */ - public static final int MAX_RADIX = 36; + /** + * Returns the Unicode directionality property for unassigned + * characters. + * @param cp the character + * @return DIRECTIONALITY_UNDEFINED + */ + static byte getDirectionality(int cp) + { + return DIRECTIONALITY_UNDEFINED; + } - /** - * The minimum value the char data type can hold. - * This value is '\\u0000'. - */ - public static final char MIN_VALUE = '\u0000'; + /** + * Returns -1, the numeric value for unassigned Unicode characters. + * @param cp the character + * @return -1 + */ + static int getNumericValue(int cp) + { + return -1; + } - /** - * The maximum value the char data type can hold. - * This value is '\\uFFFF'. - */ - public static final char MAX_VALUE = '\uFFFF'; + /** + * Returns UNASSIGNED, the type of unassigned Unicode characters. + * @param cp the character + * @return UNASSIGNED + */ + static int getType(int cp) + { + return UNASSIGNED; + } + + /** + * Returns false to indiciate that the character is not defined in the + * Unicode standard. + * @param cp the character + * @return false + */ + static boolean isDefined(int cp) + { + return false; + } - /** - * Class object representing the primitive char data type. - * - * @since 1.1 - */ - public static final Class TYPE = VMClassLoader.getPrimitiveClass('C'); + /** + * Returns false to indicate that the character is not a digit. + * @param cp the character + * @return false + */ + static boolean isDigit(int cp) + { + return false; + } - /** - * The number of bits needed to represent a char. - * @since 1.5 - */ - public static final int SIZE = 16; + /** + * Returns false to indicate that the character cannot be ignored + * within an identifier + * @param cp the character + * @return false + */ + static boolean isIdentifierIgnorable(int cp) + { + return false; + } - // This caches some Character values, and is used by boxing - // conversions via valueOf(). We must cache at least 0..127; - // this constant controls how much we actually cache. - private static final int MAX_CACHE = 127; - private static Character[] charCache = new Character[MAX_CACHE + 1]; + /** + * Returns false to indicate that the character cannot be part of a + * Java identifier. + * @param cp the character + * @return false + */ + static boolean isJavaIdentifierPart(int cp) + { + return false; + } - /** - * Lu = Letter, Uppercase (Informative). - * - * @since 1.1 - */ - public static final byte UPPERCASE_LETTER = 1; + /** + * Returns false to indicate that the character cannot be start a + * Java identifier. + * @param cp the character + * @return false + */ + static boolean isJavaIdentiferStart(int cp) + { + return false; + } - /** - * Ll = Letter, Lowercase (Informative). + /** + * Returns false to indicate that the character is not a letter. + * @param cp the character + * @return false + */ + static boolean isLetter(int cp) + { + return false; + } + + /** + * Returns false to indicate that the character cannot is neither a letter + * nor a digit. + * @param cp the character + * @return false + */ + static boolean isLetterOrDigit(int cp) + { + return false; + } + + /** + * Returns false to indicate that the character is not a lowercase letter. + * @param cp the character + * @return false + */ + static boolean isLowerCase(int cp) + { + return false; + } + + /** + * Returns false to indicate that the character cannot is not mirrored. + * @param cp the character + * @return false + */ + static boolean isMirrored(int cp) + { + return false; + } + + /** + * Returns false to indicate that the character is not a space character. + * @param cp the character + * @return false + */ + static boolean isSpaceChar(int cp) + { + return false; + } + + /** + * Returns false to indicate that the character it not a titlecase letter. + * @param cp the character + * @return false + */ + static boolean isTitleCase(int cp) + { + return false; + } + + /** + * Returns false to indicate that the character cannot be part of a + * Unicode identifier. + * @param cp the character + * @return false + */ + static boolean isUnicodeIdentifierPart(int cp) + { + return false; + } + + /** + * Returns false to indicate that the character cannot start a + * Unicode identifier. + * @param cp the character + * @return false + */ + static boolean isUnicodeIdentifierStart(int cp) + { + return false; + } + + /** + * Returns false to indicate that the character is not an uppercase letter. + * @param cp the character + * @return false + */ + static boolean isUpperCase(int cp) + { + return false; + } + + /** + * Returns false to indicate that the character is not a whitespace + * character. + * @param cp the character + * @return false + */ + static boolean isWhiteSpace(int cp) + { + return false; + } + + /** + * Returns cp to indicate this character has no lowercase conversion. + * @param cp the character + * @return cp + */ + static int toLowerCase(int cp) + { + return cp; + } + + /** + * Returns cp to indicate this character has no titlecase conversion. + * @param cp the character + * @return cp + */ + static int toTitleCase(int cp) + { + return cp; + } + + /** + * Returns cp to indicate this character has no uppercase conversion. + * @param cp the character + * @return cp + */ + static int toUpperCase(int cp) + { + return cp; + } + } + + /** + * The immutable value of this Character. + * + * @serial the value of this Character + */ + private final char value; + + /** + * Compatible with JDK 1.0+. + */ + private static final long serialVersionUID = 3786198910865385080L; + + /** + * Smallest value allowed for radix arguments in Java. This value is 2. + * + * @see #digit(char, int) + * @see #forDigit(int, int) + * @see Integer#toString(int, int) + * @see Integer#valueOf(String) + */ + public static final int MIN_RADIX = 2; + + /** + * Largest value allowed for radix arguments in Java. This value is 36. + * + * @see #digit(char, int) + * @see #forDigit(int, int) + * @see Integer#toString(int, int) + * @see Integer#valueOf(String) + */ + public static final int MAX_RADIX = 36; + + /** + * The minimum value the char data type can hold. + * This value is '\\u0000'. + */ + public static final char MIN_VALUE = '\u0000'; + + /** + * The maximum value the char data type can hold. + * This value is '\\uFFFF'. + */ + public static final char MAX_VALUE = '\uFFFF'; + + /** + * Class object representing the primitive char data type. + * + * @since 1.1 + */ + public static final Class TYPE = VMClassLoader.getPrimitiveClass('C'); + + /** + * The number of bits needed to represent a char. + * @since 1.5 + */ + public static final int SIZE = 16; + + // This caches some Character values, and is used by boxing + // conversions via valueOf(). We must cache at least 0..127; + // this constant controls how much we actually cache. + private static final int MAX_CACHE = 127; + private static Character[] charCache = new Character[MAX_CACHE + 1]; + + /** + * Lu = Letter, Uppercase (Informative). + * + * @since 1.1 + */ + public static final byte UPPERCASE_LETTER = 1; + + /** + * Ll = Letter, Lowercase (Informative). * * @since 1.1 */ @@ -1399,39 +2351,128 @@ public final class Character implements Serializable, Comparable /** * Stores unicode block offset lookup table. Exploit package visibility of * String.value to avoid copying the array. - * @see #readChar(char) + * @see #readCodePoint(int) * @see CharData#BLOCKS */ - private static final char[] blocks = String.zeroBasedStringValue(CharData.BLOCKS); + private static final char[][] blocks = + new char[][]{ + String.zeroBasedStringValue(CharData.BLOCKS[0]), + String.zeroBasedStringValue(CharData.BLOCKS[1]), + String.zeroBasedStringValue(CharData.BLOCKS[2]), + String.zeroBasedStringValue(CharData.BLOCKS[3]), + String.zeroBasedStringValue(CharData.BLOCKS[4]), + String.zeroBasedStringValue(CharData.BLOCKS[5]), + String.zeroBasedStringValue(CharData.BLOCKS[6]), + String.zeroBasedStringValue(CharData.BLOCKS[7]), + String.zeroBasedStringValue(CharData.BLOCKS[8]), + String.zeroBasedStringValue(CharData.BLOCKS[9]), + String.zeroBasedStringValue(CharData.BLOCKS[10]), + String.zeroBasedStringValue(CharData.BLOCKS[11]), + String.zeroBasedStringValue(CharData.BLOCKS[12]), + String.zeroBasedStringValue(CharData.BLOCKS[13]), + String.zeroBasedStringValue(CharData.BLOCKS[14]), + String.zeroBasedStringValue(CharData.BLOCKS[15]), + String.zeroBasedStringValue(CharData.BLOCKS[16])}; /** * Stores unicode attribute offset lookup table. Exploit package visibility * of String.value to avoid copying the array. * @see CharData#DATA - */ - private static final char[] data = String.zeroBasedStringValue(CharData.DATA); + */ + private static final char[][] data = + new char[][]{ + String.zeroBasedStringValue(CharData.DATA[0]), + String.zeroBasedStringValue(CharData.DATA[1]), + String.zeroBasedStringValue(CharData.DATA[2]), + String.zeroBasedStringValue(CharData.DATA[3]), + String.zeroBasedStringValue(CharData.DATA[4]), + String.zeroBasedStringValue(CharData.DATA[5]), + String.zeroBasedStringValue(CharData.DATA[6]), + String.zeroBasedStringValue(CharData.DATA[7]), + String.zeroBasedStringValue(CharData.DATA[8]), + String.zeroBasedStringValue(CharData.DATA[9]), + String.zeroBasedStringValue(CharData.DATA[10]), + String.zeroBasedStringValue(CharData.DATA[11]), + String.zeroBasedStringValue(CharData.DATA[12]), + String.zeroBasedStringValue(CharData.DATA[13]), + String.zeroBasedStringValue(CharData.DATA[14]), + String.zeroBasedStringValue(CharData.DATA[15]), + String.zeroBasedStringValue(CharData.DATA[16])}; /** * Stores unicode numeric value attribute table. Exploit package visibility * of String.value to avoid copying the array. * @see CharData#NUM_VALUE */ - private static final char[] numValue - = String.zeroBasedStringValue(CharData.NUM_VALUE); + private static final char[][] numValue = + new char[][]{ + String.zeroBasedStringValue(CharData.NUM_VALUE[0]), + String.zeroBasedStringValue(CharData.NUM_VALUE[1]), + String.zeroBasedStringValue(CharData.NUM_VALUE[2]), + String.zeroBasedStringValue(CharData.NUM_VALUE[3]), + String.zeroBasedStringValue(CharData.NUM_VALUE[4]), + String.zeroBasedStringValue(CharData.NUM_VALUE[5]), + String.zeroBasedStringValue(CharData.NUM_VALUE[6]), + String.zeroBasedStringValue(CharData.NUM_VALUE[7]), + String.zeroBasedStringValue(CharData.NUM_VALUE[8]), + String.zeroBasedStringValue(CharData.NUM_VALUE[9]), + String.zeroBasedStringValue(CharData.NUM_VALUE[10]), + String.zeroBasedStringValue(CharData.NUM_VALUE[11]), + String.zeroBasedStringValue(CharData.NUM_VALUE[12]), + String.zeroBasedStringValue(CharData.NUM_VALUE[13]), + String.zeroBasedStringValue(CharData.NUM_VALUE[14]), + String.zeroBasedStringValue(CharData.NUM_VALUE[15]), + String.zeroBasedStringValue(CharData.NUM_VALUE[16])}; /** * Stores unicode uppercase attribute table. Exploit package visibility * of String.value to avoid copying the array. * @see CharData#UPPER - */ - private static final char[] upper = String.zeroBasedStringValue(CharData.UPPER); + */ + private static final char[][] upper = + new char[][]{ + String.zeroBasedStringValue(CharData.UPPER[0]), + String.zeroBasedStringValue(CharData.UPPER[1]), + String.zeroBasedStringValue(CharData.UPPER[2]), + String.zeroBasedStringValue(CharData.UPPER[3]), + String.zeroBasedStringValue(CharData.UPPER[4]), + String.zeroBasedStringValue(CharData.UPPER[5]), + String.zeroBasedStringValue(CharData.UPPER[6]), + String.zeroBasedStringValue(CharData.UPPER[7]), + String.zeroBasedStringValue(CharData.UPPER[8]), + String.zeroBasedStringValue(CharData.UPPER[9]), + String.zeroBasedStringValue(CharData.UPPER[10]), + String.zeroBasedStringValue(CharData.UPPER[11]), + String.zeroBasedStringValue(CharData.UPPER[12]), + String.zeroBasedStringValue(CharData.UPPER[13]), + String.zeroBasedStringValue(CharData.UPPER[14]), + String.zeroBasedStringValue(CharData.UPPER[15]), + String.zeroBasedStringValue(CharData.UPPER[16])}; /** * Stores unicode lowercase attribute table. Exploit package visibility * of String.value to avoid copying the array. * @see CharData#LOWER */ - private static final char[] lower = String.zeroBasedStringValue(CharData.LOWER); + private static final char[][] lower = + new char[][]{ + String.zeroBasedStringValue(CharData.LOWER[0]), + String.zeroBasedStringValue(CharData.LOWER[1]), + String.zeroBasedStringValue(CharData.LOWER[2]), + String.zeroBasedStringValue(CharData.LOWER[3]), + String.zeroBasedStringValue(CharData.LOWER[4]), + String.zeroBasedStringValue(CharData.LOWER[5]), + String.zeroBasedStringValue(CharData.LOWER[6]), + String.zeroBasedStringValue(CharData.LOWER[7]), + String.zeroBasedStringValue(CharData.LOWER[8]), + String.zeroBasedStringValue(CharData.LOWER[9]), + String.zeroBasedStringValue(CharData.LOWER[10]), + String.zeroBasedStringValue(CharData.LOWER[11]), + String.zeroBasedStringValue(CharData.LOWER[12]), + String.zeroBasedStringValue(CharData.LOWER[13]), + String.zeroBasedStringValue(CharData.LOWER[14]), + String.zeroBasedStringValue(CharData.LOWER[15]), + String.zeroBasedStringValue(CharData.LOWER[16])}; /** * Stores unicode direction attribute table. Exploit package visibility @@ -1439,14 +2480,32 @@ public final class Character implements Serializable, Comparable * @see CharData#DIRECTION */ // Package visible for use by String. - static final char[] direction = String.zeroBasedStringValue(CharData.DIRECTION); + static final char[][] direction = + new char[][]{ + String.zeroBasedStringValue(CharData.DIRECTION[0]), + String.zeroBasedStringValue(CharData.DIRECTION[1]), + String.zeroBasedStringValue(CharData.DIRECTION[2]), + String.zeroBasedStringValue(CharData.DIRECTION[3]), + String.zeroBasedStringValue(CharData.DIRECTION[4]), + String.zeroBasedStringValue(CharData.DIRECTION[5]), + String.zeroBasedStringValue(CharData.DIRECTION[6]), + String.zeroBasedStringValue(CharData.DIRECTION[7]), + String.zeroBasedStringValue(CharData.DIRECTION[8]), + String.zeroBasedStringValue(CharData.DIRECTION[9]), + String.zeroBasedStringValue(CharData.DIRECTION[10]), + String.zeroBasedStringValue(CharData.DIRECTION[11]), + String.zeroBasedStringValue(CharData.DIRECTION[12]), + String.zeroBasedStringValue(CharData.DIRECTION[13]), + String.zeroBasedStringValue(CharData.DIRECTION[14]), + String.zeroBasedStringValue(CharData.DIRECTION[15]), + String.zeroBasedStringValue(CharData.DIRECTION[16])}; /** * Stores unicode titlecase table. Exploit package visibility of * String.value to avoid copying the array. * @see CharData#TITLE */ - private static final char[] title = String.zeroBasedStringValue(CharData.TITLE); + private static final char[] title = String.zeroBasedStringValue(CharData.TITLE); /** * Mask for grabbing the type out of the contents of data. @@ -1538,7 +2597,7 @@ public final class Character implements Serializable, Comparable * 5 bits are the character type, the next 2 bits are flags, and the top * 9 bits are the offset into the attribute tables. * - * @param ch the character to look up + * @param codePoint the character to look up * @return the character's attribute offset and type * @see #TYPE_MASK * @see #NO_BREAK_MASK @@ -1546,11 +2605,11 @@ public final class Character implements Serializable, Comparable * @see CharData#DATA * @see CharData#SHIFT */ - // Package visible for use in String. - static char readChar(char ch) + static char readCodePoint(int codePoint) { - // Perform 16-bit addition to find the correct entry in data. - return data[(char) (blocks[ch >> CharData.SHIFT] + ch)]; + int plane = codePoint >>> 16; + char offset = (char) (codePoint & 0xffff); + return data[plane][(char) (blocks[plane][offset >> CharData.SHIFT[plane]] + offset)]; } /** @@ -1623,7 +2682,8 @@ public final class Character implements Serializable, Comparable /** * Determines if a character is a Unicode lowercase letter. For example, - * 'a' is lowercase. + * 'a' is lowercase. Returns true if getType() returns + * LOWERCASE_LETTER. *
    * lowercase = [Ll] * @@ -1636,12 +2696,34 @@ public final class Character implements Serializable, Comparable */ public static boolean isLowerCase(char ch) { - return getType(ch) == LOWERCASE_LETTER; + return isLowerCase((int)ch); + } + + /** + * Determines if a character is a Unicode lowercase letter. For example, + * 'a' is lowercase. Returns true if getType() returns + * LOWERCASE_LETTER. + *
    + * lowercase = [Ll] + * + * @param codePoint character to test + * @return true if ch is a Unicode lowercase letter, else false + * @see #isUpperCase(char) + * @see #isTitleCase(char) + * @see #toLowerCase(char) + * @see #getType(char) + * + * @since 1.5 + */ + public static boolean isLowerCase(int codePoint) + { + return getType(codePoint) == LOWERCASE_LETTER; } /** * Determines if a character is a Unicode uppercase letter. For example, - * 'A' is uppercase. + * 'A' is uppercase. Returns true if getType() returns + * UPPERCASE_LETTER. *
    * uppercase = [Lu] * @@ -1654,12 +2736,34 @@ public final class Character implements Serializable, Comparable */ public static boolean isUpperCase(char ch) { - return getType(ch) == UPPERCASE_LETTER; + return isUpperCase((int)ch); + } + + /** + * Determines if a character is a Unicode uppercase letter. For example, + * 'A' is uppercase. Returns true if getType() returns + * UPPERCASE_LETTER. + *
    + * uppercase = [Lu] + * + * @param codePoint character to test + * @return true if ch is a Unicode uppercase letter, else false + * @see #isLowerCase(char) + * @see #isTitleCase(char) + * @see #toUpperCase(char) + * @see #getType(char) + * + * @since 1.5 + */ + public static boolean isUpperCase(int codePoint) + { + return getType(codePoint) == UPPERCASE_LETTER; } /** * Determines if a character is a Unicode titlecase letter. For example, * the character "Lj" (Latin capital L with small letter j) is titlecase. + * True if getType() returns TITLECASE_LETTER. *
    * titlecase = [Lt] * @@ -1672,12 +2776,35 @@ public final class Character implements Serializable, Comparable */ public static boolean isTitleCase(char ch) { - return getType(ch) == TITLECASE_LETTER; + return isTitleCase((int)ch); + } + + /** + * Determines if a character is a Unicode titlecase letter. For example, + * the character "Lj" (Latin capital L with small letter j) is titlecase. + * True if getType() returns TITLECASE_LETTER. + *
    + * titlecase = [Lt] + * + * @param codePoint character to test + * @return true if ch is a Unicode titlecase letter, else false + * @see #isLowerCase(char) + * @see #isUpperCase(char) + * @see #toTitleCase(char) + * @see #getType(char) + * + * @since 1.5 + */ + public static boolean isTitleCase(int codePoint) + { + return getType(codePoint) == TITLECASE_LETTER; } + /** * Determines if a character is a Unicode decimal digit. For example, - * '0' is a digit. + * '0' is a digit. A character is a Unicode digit if + * getType() returns DECIMAL_DIGIT_NUMBER. *
    * Unicode decimal digit = [Nd] * @@ -1689,7 +2816,28 @@ public final class Character implements Serializable, Comparable */ public static boolean isDigit(char ch) { - return getType(ch) == DECIMAL_DIGIT_NUMBER; + return isDigit((int)ch); + } + + /** + * Determines if a character is a Unicode decimal digit. For example, + * '0' is a digit. A character is a Unicode digit if + * getType() returns DECIMAL_DIGIT_NUMBER. + *
    + * Unicode decimal digit = [Nd] + * + * @param codePoint character to test + * @return true if ch is a Unicode decimal digit, else false + * @see #digit(char, int) + * @see #forDigit(int, int) + * @see #getType(char) + * + * @since 1.5 + */ + + public static boolean isDigit(int codePoint) + { + return getType(codePoint) == DECIMAL_DIGIT_NUMBER; } /** @@ -1709,12 +2857,37 @@ public final class Character implements Serializable, Comparable */ public static boolean isDefined(char ch) { - return getType(ch) != UNASSIGNED; + return isDefined((int)ch); + } + + /** + * Determines if a character is part of the Unicode Standard. This is an + * evolving standard, but covers every character in the data file. + *
    + * defined = not [Cn] + * + * @param codePoint character to test + * @return true if ch is a Unicode character, else false + * @see #isDigit(char) + * @see #isLetter(char) + * @see #isLetterOrDigit(char) + * @see #isLowerCase(char) + * @see #isTitleCase(char) + * @see #isUpperCase(char) + * + * @since 1.5 + */ + public static boolean isDefined(int codePoint) + { + return getType(codePoint) != UNASSIGNED; } /** * Determines if a character is a Unicode letter. Not all letters have case, * so this may return true when isLowerCase and isUpperCase return false. + * A character is a Unicode letter if getType() returns one of + * UPPERCASE_LETTER, LOWERCASE_LETTER, TITLECASE_LETTER, MODIFIER_LETTER, + * or OTHER_LETTER. *
    * letter = [Lu]|[Ll]|[Lt]|[Lm]|[Lo] * @@ -1732,49 +2905,301 @@ public final class Character implements Serializable, Comparable */ public static boolean isLetter(char ch) { - return ((1 << getType(ch)) - & ((1 << UPPERCASE_LETTER) - | (1 << LOWERCASE_LETTER) - | (1 << TITLECASE_LETTER) - | (1 << MODIFIER_LETTER) - | (1 << OTHER_LETTER))) != 0; + return isLetter((int)ch); } - + /** - * Determines if a character is a Unicode letter or a Unicode digit. This - * is the combination of isLetter and isDigit. + * Determines if a character is a Unicode letter. Not all letters have case, + * so this may return true when isLowerCase and isUpperCase return false. + * A character is a Unicode letter if getType() returns one of + * UPPERCASE_LETTER, LOWERCASE_LETTER, TITLECASE_LETTER, MODIFIER_LETTER, + * or OTHER_LETTER. *
    - * letter or digit = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nd] + * letter = [Lu]|[Ll]|[Lt]|[Lm]|[Lo] * - * @param ch character to test - * @return true if ch is a Unicode letter or a Unicode digit, else false + * @param codePoint character to test + * @return true if ch is a Unicode letter, else false * @see #isDigit(char) - * @see #isJavaIdentifierPart(char) + * @see #isJavaIdentifierStart(char) * @see #isJavaLetter(char) * @see #isJavaLetterOrDigit(char) - * @see #isLetter(char) - * @see #isUnicodeIdentifierPart(char) + * @see #isLetterOrDigit(char) + * @see #isLowerCase(char) + * @see #isTitleCase(char) + * @see #isUnicodeIdentifierStart(char) + * @see #isUpperCase(char) + * + * @since 1.5 */ - public static boolean isLetterOrDigit(char ch) + public static boolean isLetter(int codePoint) { - return ((1 << getType(ch)) - & ((1 << UPPERCASE_LETTER) - | (1 << LOWERCASE_LETTER) - | (1 << TITLECASE_LETTER) - | (1 << MODIFIER_LETTER) - | (1 << OTHER_LETTER) - | (1 << DECIMAL_DIGIT_NUMBER))) != 0; + return ((1 << getType(codePoint)) + & ((1 << UPPERCASE_LETTER) + | (1 << LOWERCASE_LETTER) + | (1 << TITLECASE_LETTER) + | (1 << MODIFIER_LETTER) + | (1 << OTHER_LETTER))) != 0; } - /** - * Determines if a character can start a Java identifier. This is the - * combination of isLetter, any character where getType returns - * LETTER_NUMBER, currency symbols (like '$'), and connecting punctuation - * (like '_'). - * - * @param ch character to test - * @return true if ch can start a Java identifier, else false - * @deprecated Replaced by {@link #isJavaIdentifierStart(char)} + * Returns the index into the given CharSequence that is offset + * codePointOffset code points from index. + * @param seq the CharSequence + * @param index the start position in the CharSequence + * @param codePointOffset the number of code points offset from the start + * position + * @return the index into the CharSequence that is codePointOffset code + * points offset from index + * + * @throws NullPointerException if seq is null + * @throws IndexOutOfBoundsException if index is negative or greater than the + * length of the sequence. + * @throws IndexOutOfBoundsException if codePointOffset is positive and the + * subsequence from index to the end of seq has fewer than codePointOffset + * code points + * @throws IndexOutOfBoundsException if codePointOffset is negative and the + * subsequence from the start of seq to index has fewer than + * (-codePointOffset) code points + * @since 1.5 + */ + public static int offsetByCodePoints(CharSequence seq, + int index, + int codePointOffset) + { + int len = seq.length(); + if (index < 0 || index > len) + throw new IndexOutOfBoundsException(); + + int numToGo = codePointOffset; + int offset = index; + int adjust = 1; + if (numToGo >= 0) + { + for (; numToGo > 0; offset++) + { + numToGo--; + if (Character.isHighSurrogate(seq.charAt(offset)) + && (offset + 1) < len + && Character.isLowSurrogate(seq.charAt(offset + 1))) + offset++; + } + return offset; + } + else + { + numToGo *= -1; + for (; numToGo > 0;) + { + numToGo--; + offset--; + if (Character.isLowSurrogate(seq.charAt(offset)) + && (offset - 1) >= 0 + && Character.isHighSurrogate(seq.charAt(offset - 1))) + offset--; + } + return offset; + } + } + + /** + * Returns the index into the given char subarray that is offset + * codePointOffset code points from index. + * @param a the char array + * @param start the start index of the subarray + * @param count the length of the subarray + * @param index the index to be offset + * @param codePointOffset the number of code points offset from index + * + * @return the index into the char array + * + * @throws NullPointerException if a is null + * @throws IndexOutOfBoundsException if start or count is negative or if + * start + count is greater than the length of the array + * @throws IndexOutOfBoundsException if index is less than start or larger + * than start + count + * @throws IndexOutOfBoundsException if codePointOffset is positive and the + * subarray from index to start + count - 1 has fewer than codePointOffset + * code points. + * @throws IndexOutOfBoundsException if codePointOffset is negative and the + * subarray from start to index - 1 has fewer than (-codePointOffset) code + * points + * + * @since 1.5 + */ + public static int offsetByCodePoints(char[] a, + int start, + int count, + int index, + int codePointOffset) + { + int len = a.length; + int end = start + count; + if (start < 0 || count < 0 || end > len || index < start || index > end) + throw new IndexOutOfBoundsException(); + + int numToGo = codePointOffset; + int offset = index; + int adjust = 1; + if (numToGo >= 0) + { + for (; numToGo > 0; offset++) + { + numToGo--; + if (Character.isHighSurrogate(a[offset]) + && (offset + 1) < len + && Character.isLowSurrogate(a[offset + 1])) + offset++; + } + return offset; + } + else + { + numToGo *= -1; + for (; numToGo > 0;) + { + numToGo--; + offset--; + if (Character.isLowSurrogate(a[offset]) + && (offset - 1) >= 0 + && Character.isHighSurrogate(a[offset - 1])) + offset--; + if (offset < start) + throw new IndexOutOfBoundsException(); + } + return offset; + } + + } + + /** + * Returns the number of Unicode code points in the specified range of the + * given CharSequence. The first char in the range is at position + * beginIndex and the last one is at position endIndex - 1. Paired + * surrogates (supplementary characters are represented by a pair of chars - + * one from the high surrogates and one from the low surrogates) + * count as just one code point. + * @param seq the CharSequence to inspect + * @param beginIndex the beginning of the range + * @param endIndex the end of the range + * @return the number of Unicode code points in the given range of the + * sequence + * @throws NullPointerException if seq is null + * @throws IndexOutOfBoundsException if beginIndex is negative, endIndex is + * larger than the length of seq, or if beginIndex is greater than endIndex. + * @since 1.5 + */ + public static int codePointCount(CharSequence seq, int beginIndex, + int endIndex) + { + int len = seq.length(); + if (beginIndex < 0 || endIndex > len || beginIndex > endIndex) + throw new IndexOutOfBoundsException(); + + int count = 0; + for (int i = beginIndex; i < endIndex; i++) + { + count++; + // If there is a pairing, count it only once. + if (isHighSurrogate(seq.charAt(i)) && (i + 1) < endIndex + && isLowSurrogate(seq.charAt(i + 1))) + i ++; + } + return count; + } + + /** + * Returns the number of Unicode code points in the specified range of the + * given char array. The first char in the range is at position + * offset and the length of the range is count. Paired surrogates + * (supplementary characters are represented by a pair of chars - + * one from the high surrogates and one from the low surrogates) + * count as just one code point. + * @param a the char array to inspect + * @param offset the beginning of the range + * @param count the length of the range + * @return the number of Unicode code points in the given range of the + * array + * @throws NullPointerException if a is null + * @throws IndexOutOfBoundsException if offset or count is negative or if + * offset + countendIndex is larger than the length of a. + * @since 1.5 + */ + public static int codePointCount(char[] a, int offset, + int count) + { + int len = a.length; + int end = offset + count; + if (offset < 0 || count < 0 || end > len) + throw new IndexOutOfBoundsException(); + + int counter = 0; + for (int i = offset; i < end; i++) + { + counter++; + // If there is a pairing, count it only once. + if (isHighSurrogate(a[i]) && (i + 1) < end + && isLowSurrogate(a[i + 1])) + i ++; + } + return counter; + } + + /** + * Determines if a character is a Unicode letter or a Unicode digit. This + * is the combination of isLetter and isDigit. + *
    + * letter or digit = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nd] + * + * @param ch character to test + * @return true if ch is a Unicode letter or a Unicode digit, else false + * @see #isDigit(char) + * @see #isJavaIdentifierPart(char) + * @see #isJavaLetter(char) + * @see #isJavaLetterOrDigit(char) + * @see #isLetter(char) + * @see #isUnicodeIdentifierPart(char) + */ + public static boolean isLetterOrDigit(char ch) + { + return isLetterOrDigit((int)ch); + } + + /** + * Determines if a character is a Unicode letter or a Unicode digit. This + * is the combination of isLetter and isDigit. + *
    + * letter or digit = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nd] + * + * @param codePoint character to test + * @return true if ch is a Unicode letter or a Unicode digit, else false + * @see #isDigit(char) + * @see #isJavaIdentifierPart(char) + * @see #isJavaLetter(char) + * @see #isJavaLetterOrDigit(char) + * @see #isLetter(char) + * @see #isUnicodeIdentifierPart(char) + * + * @since 1.5 + */ + public static boolean isLetterOrDigit(int codePoint) + { + return ((1 << getType(codePoint)) + & ((1 << UPPERCASE_LETTER) + | (1 << LOWERCASE_LETTER) + | (1 << TITLECASE_LETTER) + | (1 << MODIFIER_LETTER) + | (1 << OTHER_LETTER) + | (1 << DECIMAL_DIGIT_NUMBER))) != 0; + } + + /** + * Determines if a character can start a Java identifier. This is the + * combination of isLetter, any character where getType returns + * LETTER_NUMBER, currency symbols (like '$'), and connecting punctuation + * (like '_'). + * + * @param ch character to test + * @return true if ch can start a Java identifier, else false + * @deprecated Replaced by {@link #isJavaIdentifierStart(char)} * @see #isJavaLetterOrDigit(char) * @see #isJavaIdentifierStart(char) * @see #isJavaIdentifierPart(char) @@ -1827,7 +3252,27 @@ public final class Character implements Serializable, Comparable */ public static boolean isJavaIdentifierStart(char ch) { - return ((1 << getType(ch)) + return isJavaIdentifierStart((int)ch); + } + + /** + * Determines if a character can start a Java identifier. This is the + * combination of isLetter, any character where getType returns + * LETTER_NUMBER, currency symbols (like '$'), and connecting punctuation + * (like '_'). + *
    + * Java identifier start = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Sc]|[Pc] + * + * @param codePoint character to test + * @return true if ch can start a Java identifier, else false + * @see #isJavaIdentifierPart(char) + * @see #isLetter(char) + * @see #isUnicodeIdentifierStart(char) + * @since 1.5 + */ + public static boolean isJavaIdentifierStart(int codePoint) + { + return ((1 << getType(codePoint)) & ((1 << UPPERCASE_LETTER) | (1 << LOWERCASE_LETTER) | (1 << TITLECASE_LETTER) @@ -1837,7 +3282,7 @@ public final class Character implements Serializable, Comparable | (1 << CURRENCY_SYMBOL) | (1 << CONNECTOR_PUNCTUATION))) != 0; } - + /** * Determines if a character can follow the first letter in * a Java identifier. This is the combination of isJavaLetter (isLetter, @@ -1859,7 +3304,31 @@ public final class Character implements Serializable, Comparable */ public static boolean isJavaIdentifierPart(char ch) { - int category = getType(ch); + return isJavaIdentifierPart((int)ch); + } + + /** + * Determines if a character can follow the first letter in + * a Java identifier. This is the combination of isJavaLetter (isLetter, + * type of LETTER_NUMBER, currency, connecting punctuation) and digit, + * numeric letter (like Roman numerals), combining marks, non-spacing marks, + * or isIdentifierIgnorable. + *
    + * Java identifier extender = + * [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Sc]|[Pc]|[Mn]|[Mc]|[Nd]|[Cf] + * |U+0000-U+0008|U+000E-U+001B|U+007F-U+009F + * + * @param codePoint character to test + * @return true if ch can follow the first letter in a Java identifier + * @see #isIdentifierIgnorable(char) + * @see #isJavaIdentifierStart(char) + * @see #isLetterOrDigit(char) + * @see #isUnicodeIdentifierPart(char) + * @since 1.5 + */ + public static boolean isJavaIdentifierPart(int codePoint) + { + int category = getType(codePoint); return ((1 << category) & ((1 << UPPERCASE_LETTER) | (1 << LOWERCASE_LETTER) @@ -1873,7 +3342,7 @@ public final class Character implements Serializable, Comparable | (1 << CURRENCY_SYMBOL) | (1 << CONNECTOR_PUNCTUATION) | (1 << FORMAT))) != 0 - || (category == CONTROL && isIdentifierIgnorable(ch)); + || (category == CONTROL && isIdentifierIgnorable(codePoint)); } /** @@ -1892,7 +3361,26 @@ public final class Character implements Serializable, Comparable */ public static boolean isUnicodeIdentifierStart(char ch) { - return ((1 << getType(ch)) + return isUnicodeIdentifierStart((int)ch); + } + + /** + * Determines if a character can start a Unicode identifier. Only + * letters can start a Unicode identifier, but this includes characters + * in LETTER_NUMBER. + *
    + * Unicode identifier start = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl] + * + * @param codePoint character to test + * @return true if ch can start a Unicode identifier, else false + * @see #isJavaIdentifierStart(char) + * @see #isLetter(char) + * @see #isUnicodeIdentifierPart(char) + * @since 1.5 + */ + public static boolean isUnicodeIdentifierStart(int codePoint) + { + return ((1 << getType(codePoint)) & ((1 << UPPERCASE_LETTER) | (1 << LOWERCASE_LETTER) | (1 << TITLECASE_LETTER) @@ -1921,7 +3409,30 @@ public final class Character implements Serializable, Comparable */ public static boolean isUnicodeIdentifierPart(char ch) { - int category = getType(ch); + return isUnicodeIdentifierPart((int)ch); + } + + /** + * Determines if a character can follow the first letter in + * a Unicode identifier. This includes letters, connecting punctuation, + * digits, numeric letters, combining marks, non-spacing marks, and + * isIdentifierIgnorable. + *
    + * Unicode identifier extender = + * [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Mn]|[Mc]|[Nd]|[Pc]|[Cf]| + * |U+0000-U+0008|U+000E-U+001B|U+007F-U+009F + * + * @param codePoint character to test + * @return true if ch can follow the first letter in a Unicode identifier + * @see #isIdentifierIgnorable(char) + * @see #isJavaIdentifierPart(char) + * @see #isLetterOrDigit(char) + * @see #isUnicodeIdentifierStart(char) + * @since 1.5 + */ + public static boolean isUnicodeIdentifierPart(int codePoint) + { + int category = getType(codePoint); return ((1 << category) & ((1 << UPPERCASE_LETTER) | (1 << LOWERCASE_LETTER) @@ -1934,7 +3445,7 @@ public final class Character implements Serializable, Comparable | (1 << LETTER_NUMBER) | (1 << CONNECTOR_PUNCTUATION) | (1 << FORMAT))) != 0 - || (category == CONTROL && isIdentifierIgnorable(ch)); + || (category == CONTROL && isIdentifierIgnorable(codePoint)); } /** @@ -1955,9 +3466,32 @@ public final class Character implements Serializable, Comparable */ public static boolean isIdentifierIgnorable(char ch) { - return (ch <= '\u009F' && (ch < '\t' || ch >= '\u007F' - || (ch <= '\u001B' && ch >= '\u000E'))) - || getType(ch) == FORMAT; + return isIdentifierIgnorable((int)ch); + } + /** + * Determines if a character is ignorable in a Unicode identifier. This + * includes the non-whitespace ISO control characters ('\u0000' + * through '\u0008', '\u000E' through + * '\u001B', and '\u007F' through + * '\u009F'), and FORMAT characters. + *
    + * Unicode identifier ignorable = [Cf]|U+0000-U+0008|U+000E-U+001B + * |U+007F-U+009F + * + * @param codePoint character to test + * @return true if ch is ignorable in a Unicode or Java identifier + * @see #isJavaIdentifierPart(char) + * @see #isUnicodeIdentifierPart(char) + * @since 1.5 + */ + public static boolean isIdentifierIgnorable(int codePoint) + { + if ((codePoint >= 0 && codePoint <= 0x0008) + || (codePoint >= 0x000E && codePoint <= 0x001B) + || (codePoint >= 0x007F && codePoint <= 0x009F) + || getType(codePoint) == FORMAT) + return true; + return false; } /** @@ -1975,8 +3509,37 @@ public final class Character implements Serializable, Comparable */ public static char toLowerCase(char ch) { - // Signedness doesn't matter, as result is cast back to char. - return (char) (ch + lower[readChar(ch) >> 7]); + return (char) (lower[0][readCodePoint((int)ch) >>> 7] + ch); + } + + /** + * Converts a Unicode character into its lowercase equivalent mapping. + * If a mapping does not exist, then the character passed is returned. + * Note that isLowerCase(toLowerCase(ch)) does not always return true. + * + * @param codePoint character to convert to lowercase + * @return lowercase mapping of ch, or ch if lowercase mapping does + * not exist + * @see #isLowerCase(char) + * @see #isUpperCase(char) + * @see #toTitleCase(char) + * @see #toUpperCase(char) + * + * @since 1.5 + */ + public static int toLowerCase(int codePoint) + { + // If the code point is unassigned or in one of the private use areas + // then we delegate the call to the appropriate private static inner class. + int plane = codePoint >>> 16; + if (plane > 2 && plane < 14) + return UnassignedCharacters.toLowerCase(codePoint); + if (plane > 14) + return PrivateUseCharacters.toLowerCase(codePoint); + + // The short value stored in lower[plane] is the signed difference between + // codePoint and its lowercase conversion. + return ((short)lower[plane][readCodePoint(codePoint) >>> 7]) + codePoint; } /** @@ -1994,8 +3557,37 @@ public final class Character implements Serializable, Comparable */ public static char toUpperCase(char ch) { - // Signedness doesn't matter, as result is cast back to char. - return (char) (ch + upper[readChar(ch) >> 7]); + return (char) (upper[0][readCodePoint((int)ch) >>> 7] + ch); + } + + /** + * Converts a Unicode character into its uppercase equivalent mapping. + * If a mapping does not exist, then the character passed is returned. + * Note that isUpperCase(toUpperCase(ch)) does not always return true. + * + * @param codePoint character to convert to uppercase + * @return uppercase mapping of ch, or ch if uppercase mapping does + * not exist + * @see #isLowerCase(char) + * @see #isUpperCase(char) + * @see #toLowerCase(char) + * @see #toTitleCase(char) + * + * @since 1.5 + */ + public static int toUpperCase(int codePoint) + { + // If the code point is unassigned or in one of the private use areas + // then we delegate the call to the appropriate private static inner class. + int plane = codePoint >>> 16; + if (plane > 2 && plane < 14) + return UnassignedCharacters.toUpperCase(codePoint); + if (plane > 14) + return PrivateUseCharacters.toUpperCase(codePoint); + + // The short value stored in upper[plane] is the signed difference between + // codePoint and its uppercase conversion. + return ((short)upper[plane][readCodePoint(codePoint) >>> 7]) + codePoint; } /** @@ -2018,6 +3610,30 @@ public final class Character implements Serializable, Comparable return title[i + 1]; return toUpperCase(ch); } + + /** + * Converts a Unicode character into its titlecase equivalent mapping. + * If a mapping does not exist, then the character passed is returned. + * Note that isTitleCase(toTitleCase(ch)) does not always return true. + * + * @param codePoint character to convert to titlecase + * @return titlecase mapping of ch, or ch if titlecase mapping does + * not exist + * @see #isTitleCase(char) + * @see #toLowerCase(char) + * @see #toUpperCase(char) + * + * @since 1.5 + */ + public static int toTitleCase(int codePoint) + { + // As of Unicode 4.0.0 no characters outside of plane 0 have + // titlecase mappings that are different from their uppercase + // mapping. + if (codePoint < 0x10000) + return (int) toTitleCase((char)codePoint); + return toUpperCase(codePoint); + } /** * Converts a character into a digit of the specified radix. If the radix @@ -2041,20 +3657,68 @@ public final class Character implements Serializable, Comparable { if (radix < MIN_RADIX || radix > MAX_RADIX) return -1; - char attr = readChar(ch); + char attr = readCodePoint((int)ch); if (((1 << (attr & TYPE_MASK)) & ((1 << UPPERCASE_LETTER) | (1 << LOWERCASE_LETTER) | (1 << DECIMAL_DIGIT_NUMBER))) != 0) { // Signedness doesn't matter; 0xffff vs. -1 are both rejected. - int digit = numValue[attr >> 7]; + int digit = numValue[0][attr >> 7]; return (digit < radix) ? digit : -1; } return -1; } /** + * Converts a character into a digit of the specified radix. If the radix + * exceeds MIN_RADIX or MAX_RADIX, or if the result of getNumericValue(ch) + * exceeds the radix, or if ch is not a decimal digit or in the case + * insensitive set of 'a'-'z', the result is -1. + *
    + * character argument boundary = [Nd]|U+0041-U+005A|U+0061-U+007A + * |U+FF21-U+FF3A|U+FF41-U+FF5A + * + * @param codePoint character to convert into a digit + * @param radix radix in which ch is a digit + * @return digit which ch represents in radix, or -1 not a valid digit + * @see #MIN_RADIX + * @see #MAX_RADIX + * @see #forDigit(int, int) + * @see #isDigit(char) + * @see #getNumericValue(char) + */ + public static int digit(int codePoint, int radix) + { + if (radix < MIN_RADIX || radix > MAX_RADIX) + return -1; + + // If the code point is unassigned or in one of the private use areas + // then we delegate the call to the appropriate private static inner class. + int plane = codePoint >>> 16; + if (plane > 2 && plane < 14) + return UnassignedCharacters.digit(codePoint, radix); + if (plane > 14) + return PrivateUseCharacters.digit(codePoint, radix); + char attr = readCodePoint(codePoint); + if (((1 << (attr & TYPE_MASK)) + & ((1 << UPPERCASE_LETTER) + | (1 << LOWERCASE_LETTER) + | (1 << DECIMAL_DIGIT_NUMBER))) != 0) + { + // Signedness doesn't matter; 0xffff vs. -1 are both rejected. + int digit = numValue[plane][attr >> 7]; + + // If digit is less than or equal to -3 then the numerical value was + // too large to fit into numValue and is stored in CharData.LARGENUMS. + if (digit <= -3) + digit = CharData.LARGENUMS[-digit - 3]; + return (digit < radix) ? digit : -1; + } + return -1; + } + + /** * Returns the Unicode numeric value property of a character. For example, * '\\u216C' (the Roman numeral fifty) returns 50. * @@ -2084,7 +3748,53 @@ public final class Character implements Serializable, Comparable public static int getNumericValue(char ch) { // Treat numValue as signed. - return (short) numValue[readChar(ch) >> 7]; + return (short) numValue[0][readCodePoint((int)ch) >> 7]; + } + + /** + * Returns the Unicode numeric value property of a character. For example, + * '\\u216C' (the Roman numeral fifty) returns 50. + * + *

    This method also returns values for the letters A through Z, (not + * specified by Unicode), in these ranges: '\u0041' + * through '\u005A' (uppercase); '\u0061' + * through '\u007A' (lowercase); and '\uFF21' + * through '\uFF3A', '\uFF41' through + * '\uFF5A' (full width variants). + * + *

    If the character lacks a numeric value property, -1 is returned. + * If the character has a numeric value property which is not representable + * as a nonnegative integer, such as a fraction, -2 is returned. + * + * character argument boundary = [Nd]|[Nl]|[No]|U+0041-U+005A|U+0061-U+007A + * |U+FF21-U+FF3A|U+FF41-U+FF5A + * + * @param codePoint character from which the numeric value property will + * be retrieved + * @return the numeric value property of ch, or -1 if it does not exist, or + * -2 if it is not representable as a nonnegative integer + * @see #forDigit(int, int) + * @see #digit(char, int) + * @see #isDigit(char) + * @since 1.5 + */ + public static int getNumericValue(int codePoint) + { + // If the code point is unassigned or in one of the private use areas + // then we delegate the call to the appropriate private static inner class. + int plane = codePoint >>> 16; + if (plane > 2 && plane < 14) + return UnassignedCharacters.getNumericValue(codePoint); + if (plane > 14) + return PrivateUseCharacters.getNumericValue(codePoint); + + // If the value N found in numValue[plane] is less than or equal to -3 + // then the numeric value was too big to fit into 16 bits and is + // stored in CharData.LARGENUMS at offset (-N - 3). + short num = (short)numValue[plane][readCodePoint(codePoint) >> 7]; + if (num <= -3) + return CharData.LARGENUMS[-num - 3]; + return num; } /** @@ -2124,7 +3834,23 @@ public final class Character implements Serializable, Comparable */ public static boolean isSpaceChar(char ch) { - return ((1 << getType(ch)) + return isSpaceChar((int)ch); + } + + /** + * Determines if a character is a Unicode space character. This includes + * SPACE_SEPARATOR, LINE_SEPARATOR, and PARAGRAPH_SEPARATOR. + *
    + * Unicode space = [Zs]|[Zp]|[Zl] + * + * @param codePoint character to test + * @return true if ch is a Unicode space, else false + * @see #isWhitespace(char) + * @since 1.5 + */ + public static boolean isSpaceChar(int codePoint) + { + return ((1 << getType(codePoint)) & ((1 << SPACE_SEPARATOR) | (1 << LINE_SEPARATOR) | (1 << PARAGRAPH_SEPARATOR))) != 0; @@ -2149,13 +3875,41 @@ public final class Character implements Serializable, Comparable */ public static boolean isWhitespace(char ch) { - int attr = readChar(ch); + return isWhitespace((int) ch); + } + + /** + * Determines if a character is Java whitespace. This includes Unicode + * space characters (SPACE_SEPARATOR, LINE_SEPARATOR, and + * PARAGRAPH_SEPARATOR) except the non-breaking spaces + * ('\u00A0', '\u2007', and '\u202F'); + * and these characters: '\u0009', '\u000A', + * '\u000B', '\u000C', '\u000D', + * '\u001C', '\u001D', '\u001E', + * and '\u001F'. + *
    + * Java whitespace = ([Zs] not Nb)|[Zl]|[Zp]|U+0009-U+000D|U+001C-U+001F + * + * @param codePoint character to test + * @return true if ch is Java whitespace, else false + * @see #isSpaceChar(char) + * @since 1.5 + */ + public static boolean isWhitespace(int codePoint) + { + int plane = codePoint >>> 16; + if (plane > 2 && plane < 14) + return UnassignedCharacters.isWhiteSpace(codePoint); + if (plane > 14) + return PrivateUseCharacters.isWhiteSpace(codePoint); + + int attr = readCodePoint(codePoint); return ((((1 << (attr & TYPE_MASK)) & ((1 << SPACE_SEPARATOR) | (1 << LINE_SEPARATOR) | (1 << PARAGRAPH_SEPARATOR))) != 0) && (attr & NO_BREAK_MASK) == 0) - || (ch <= '\u001F' && ((1 << ch) + || (codePoint <= '\u001F' && ((1 << codePoint) & ((1 << '\t') | (1 << '\n') | (1 << '\u000B') @@ -2180,7 +3934,24 @@ public final class Character implements Serializable, Comparable */ public static boolean isISOControl(char ch) { - return getType(ch) == CONTROL; + return isISOControl((int)ch); + } + + /** + * Determines if the character is an ISO Control character. This is true + * if the code point is in the range [0, 0x001F] or if it is in the range + * [0x007F, 0x009F]. + * @param codePoint the character to check + * @return true if the character is in one of the above ranges + * + * @since 1.5 + */ + public static boolean isISOControl(int codePoint) + { + if ((codePoint >= 0 && codePoint <= 0x001F) + || (codePoint >= 0x007F && codePoint <= 0x009F)) + return true; + return false; } /** @@ -2222,7 +3993,58 @@ public final class Character implements Serializable, Comparable */ public static int getType(char ch) { - return readChar(ch) & TYPE_MASK; + return getType((int)ch); + } + + /** + * Returns the Unicode general category property of a character. + * + * @param codePoint character from which the general category property will + * be retrieved + * @return the character category property of ch as an integer + * @see #UNASSIGNED + * @see #UPPERCASE_LETTER + * @see #LOWERCASE_LETTER + * @see #TITLECASE_LETTER + * @see #MODIFIER_LETTER + * @see #OTHER_LETTER + * @see #NON_SPACING_MARK + * @see #ENCLOSING_MARK + * @see #COMBINING_SPACING_MARK + * @see #DECIMAL_DIGIT_NUMBER + * @see #LETTER_NUMBER + * @see #OTHER_NUMBER + * @see #SPACE_SEPARATOR + * @see #LINE_SEPARATOR + * @see #PARAGRAPH_SEPARATOR + * @see #CONTROL + * @see #FORMAT + * @see #PRIVATE_USE + * @see #SURROGATE + * @see #DASH_PUNCTUATION + * @see #START_PUNCTUATION + * @see #END_PUNCTUATION + * @see #CONNECTOR_PUNCTUATION + * @see #OTHER_PUNCTUATION + * @see #MATH_SYMBOL + * @see #CURRENCY_SYMBOL + * @see #MODIFIER_SYMBOL + * @see #INITIAL_QUOTE_PUNCTUATION + * @see #FINAL_QUOTE_PUNCTUATION + * + * @since 1.5 + */ + public static int getType(int codePoint) + { + // If the codePoint is unassigned or in one of the private use areas + // then we delegate the call to the appropriate private static inner class. + int plane = codePoint >>> 16; + if (plane > 2 && plane < 14) + return UnassignedCharacters.getType(codePoint); + if (plane > 14) + return PrivateUseCharacters.getType(codePoint); + + return readCodePoint(codePoint) & TYPE_MASK; } /** @@ -2279,9 +4101,51 @@ public final class Character implements Serializable, Comparable public static byte getDirectionality(char ch) { // The result will correctly be signed. - return (byte) (direction[readChar(ch) >> 7] >> 2); + return getDirectionality((int)ch); } - + + /** + * Returns the Unicode directionality property of the character. This + * is used in the visual ordering of text. + * + * @param codePoint the character to look up + * @return the directionality constant, or DIRECTIONALITY_UNDEFINED + * @see #DIRECTIONALITY_UNDEFINED + * @see #DIRECTIONALITY_LEFT_TO_RIGHT + * @see #DIRECTIONALITY_RIGHT_TO_LEFT + * @see #DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC + * @see #DIRECTIONALITY_EUROPEAN_NUMBER + * @see #DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR + * @see #DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR + * @see #DIRECTIONALITY_ARABIC_NUMBER + * @see #DIRECTIONALITY_COMMON_NUMBER_SEPARATOR + * @see #DIRECTIONALITY_NONSPACING_MARK + * @see #DIRECTIONALITY_BOUNDARY_NEUTRAL + * @see #DIRECTIONALITY_PARAGRAPH_SEPARATOR + * @see #DIRECTIONALITY_SEGMENT_SEPARATOR + * @see #DIRECTIONALITY_WHITESPACE + * @see #DIRECTIONALITY_OTHER_NEUTRALS + * @see #DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING + * @see #DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE + * @see #DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING + * @see #DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE + * @see #DIRECTIONALITY_POP_DIRECTIONAL_FORMAT + * @since 1.5 + */ + public static byte getDirectionality(int codePoint) + { + // If the code point is unassigned or in one of the private use areas + // then we delegate the call to the appropriate private static inner class. + int plane = codePoint >>> 16; + if (plane > 2 && plane < 14) + return UnassignedCharacters.getDirectionality(codePoint); + if (plane > 14) + return PrivateUseCharacters.getDirectionality(codePoint); + + // The result will correctly be signed. + return (byte) (direction[plane][readCodePoint(codePoint) >> 7] >> 2); + } + /** * Determines whether the character is mirrored according to Unicode. For * example, \u0028 (LEFT PARENTHESIS) appears as '(' in @@ -2293,7 +4157,29 @@ public final class Character implements Serializable, Comparable */ public static boolean isMirrored(char ch) { - return (readChar(ch) & MIRROR_MASK) != 0; + return (readCodePoint((int)ch) & MIRROR_MASK) != 0; + } + + /** + * Determines whether the character is mirrored according to Unicode. For + * example, \u0028 (LEFT PARENTHESIS) appears as '(' in + * left-to-right text, but ')' in right-to-left text. + * + * @param codePoint the character to look up + * @return true if the character is mirrored + * @since 1.5 + */ + public static boolean isMirrored(int codePoint) + { + // If the code point is unassigned or part of one of the private use areas + // then we delegate the call to the appropriate private static inner class. + int plane = codePoint >>> 16; + if (plane > 2 && plane < 14) + return UnassignedCharacters.isMirrored(codePoint); + if (plane > 14) + return PrivateUseCharacters.isMirrored(codePoint); + + return (readCodePoint(codePoint) & MIRROR_MASK) != 0; } /** @@ -2374,6 +4260,9 @@ public final class Character implements Serializable, Comparable */ public static char[] toChars(int codePoint) { + if (!isValidCodePoint(codePoint)) + throw new IllegalArgumentException("Illegal Unicode code point : " + + codePoint); char[] result = new char[charCount(codePoint)]; int ignore = toChars(codePoint, result, 0); return result; @@ -2591,7 +4480,7 @@ public final class Character implements Serializable, Comparable */ public static int codePointAt(char[] chars, int index, int limit) { - if (index < 0 || index >= limit || limit < 0 || limit >= chars.length) + if (index < 0 || index >= limit || limit < 0 || limit > chars.length) throw new IndexOutOfBoundsException(); char high = chars[index]; if (! isHighSurrogate(high) || ++index >= limit) diff --git a/libjava/classpath/java/lang/ClassNotFoundException.java b/libjava/classpath/java/lang/ClassNotFoundException.java index 6b6ae94..142bc5d 100644 --- a/libjava/classpath/java/lang/ClassNotFoundException.java +++ b/libjava/classpath/java/lang/ClassNotFoundException.java @@ -70,7 +70,7 @@ public class ClassNotFoundException extends Exception */ public ClassNotFoundException() { - this(null, null); + this(null); } /** @@ -81,7 +81,8 @@ public class ClassNotFoundException extends Exception */ public ClassNotFoundException(String s) { - this(s, null); + super(s); + ex = null; } /** diff --git a/libjava/classpath/java/lang/Math.java b/libjava/classpath/java/lang/Math.java index 08081e2..d7c8aa1 100644 --- a/libjava/classpath/java/lang/Math.java +++ b/libjava/classpath/java/lang/Math.java @@ -1,5 +1,5 @@ -/* java.lang.Math -- common mathematical functions, native allowed - Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc. +/* java.lang.Math -- common mathematical functions, native allowed (VMMath) + Copyright (C) 1998, 2001, 2002, 2003, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -52,26 +52,34 @@ import java.util.Random; * @author Paul Fisher * @author John Keiser * @author Eric Blake (ebb9@email.byu.edu) + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) * @since 1.0 */ public final class Math { - /** - * Math is non-instantiable - */ - private Math() - { - } + // FIXME - This is here because we need to load the "javalang" system + // library somewhere late in the bootstrap cycle. We cannot do this + // from VMSystem or VMRuntime since those are used to actually load + // the library. This is mainly here because historically Math was + // late enough in the bootstrap cycle to start using System after it + // was initialized (called from the java.util classes). static { if (Configuration.INIT_LOAD_LIBRARY) { - System.loadLibrary("javalang"); + System.loadLibrary("javalang"); } } /** + * Math is non-instantiable + */ + private Math() + { + } + + /** * A random number generator, initialized on first use. */ private static Random rand; @@ -298,7 +306,10 @@ public final class Math * @param a the angle (in radians) * @return sin(a) */ - public static native double sin(double a); + public static double sin(double a) + { + return VMMath.sin(a); + } /** * The trigonometric function cos. The cosine of NaN or infinity is @@ -307,7 +318,10 @@ public final class Math * @param a the angle (in radians) * @return cos(a) */ - public static native double cos(double a); + public static double cos(double a) + { + return VMMath.cos(a); + } /** * The trigonometric function tan. The tangent of NaN or infinity @@ -317,7 +331,10 @@ public final class Math * @param a the angle (in radians) * @return tan(a) */ - public static native double tan(double a); + public static double tan(double a) + { + return VMMath.tan(a); + } /** * The trigonometric function arcsin. The range of angles returned @@ -328,7 +345,10 @@ public final class Math * @param a the sin to turn back into an angle * @return arcsin(a) */ - public static native double asin(double a); + public static double asin(double a) + { + return VMMath.asin(a); + } /** * The trigonometric function arccos. The range of angles returned @@ -339,7 +359,10 @@ public final class Math * @param a the cos to turn back into an angle * @return arccos(a) */ - public static native double acos(double a); + public static double acos(double a) + { + return VMMath.acos(a); + } /** * The trigonometric function arcsin. The range of angles returned @@ -351,7 +374,10 @@ public final class Math * @return arcsin(a) * @see #atan2(double, double) */ - public static native double atan(double a); + public static double atan(double a) + { + return VMMath.atan(a); + } /** * A special version of the trigonometric function arctan, for @@ -400,7 +426,10 @@ public final class Math * @return theta in the conversion of (x, y) to (r, theta) * @see #atan(double) */ - public static native double atan2(double y, double x); + public static double atan2(double y, double x) + { + return VMMath.atan2(y,x); + } /** * Take ea. The opposite of log(). If the @@ -414,7 +443,10 @@ public final class Math * @see #log(double) * @see #pow(double, double) */ - public static native double exp(double a); + public static double exp(double a) + { + return VMMath.exp(a); + } /** * Take ln(a) (the natural log). The opposite of exp(). If the @@ -430,7 +462,10 @@ public final class Math * @return the natural log of a * @see #exp(double) */ - public static native double log(double a); + public static double log(double a) + { + return VMMath.log(a); + } /** * Take a square root. If the argument is NaN or negative, the result is @@ -438,13 +473,18 @@ public final class Math * infinity; and if the result is either zero, the result is the same. * This is accurate within the limits of doubles. * - *

    For other roots, use pow(a, 1 / rootNumber). + *

    For a cube root, use cbrt. For other roots, use + * pow(a, 1 / rootNumber).

    * * @param a the numeric argument * @return the square root of the argument + * @see #cbrt(double) * @see #pow(double, double) */ - public static native double sqrt(double a); + public static double sqrt(double a) + { + return VMMath.sqrt(a); + } /** * Raise a number to a power. Special cases: