summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/applet/Applet.java17
-rw-r--r--java/applet/AppletContext.java2
-rw-r--r--java/applet/AppletStub.java3
-rw-r--r--java/applet/AudioClip.java3
-rw-r--r--java/awt/AWTEventMulticaster.java76
-rw-r--r--java/awt/AWTKeyStroke.java4
-rw-r--r--java/awt/Adjustable.java4
-rw-r--r--java/awt/Canvas.java8
-rw-r--r--java/awt/CardLayout.java7
-rw-r--r--java/awt/CheckboxMenuItem.java12
-rw-r--r--java/awt/Color.java6
-rw-r--r--java/awt/Component.java58
-rw-r--r--java/awt/Container.java35
-rw-r--r--java/awt/DefaultFocusTraversalPolicy.java24
-rw-r--r--java/awt/DefaultKeyboardFocusManager.java33
-rw-r--r--java/awt/EventDispatchThread.java11
-rw-r--r--java/awt/FileDialog.java3
-rw-r--r--java/awt/FlowLayout.java7
-rw-r--r--java/awt/Font.java29
-rw-r--r--java/awt/FontMetrics.java112
-rw-r--r--java/awt/Frame.java2
-rw-r--r--java/awt/Graphics2D.java7
-rw-r--r--java/awt/GraphicsEnvironment.java7
-rw-r--r--java/awt/GridBagConstraints.java11
-rw-r--r--java/awt/GridBagLayout.java4
-rw-r--r--java/awt/GridLayout.java5
-rw-r--r--java/awt/Image.java3
-rw-r--r--java/awt/KeyboardFocusManager.java11
-rw-r--r--java/awt/Label.java8
-rw-r--r--java/awt/List.java3
-rw-r--r--java/awt/MediaTracker.java4
-rw-r--r--java/awt/Menu.java49
-rw-r--r--java/awt/MenuBar.java86
-rw-r--r--java/awt/MenuComponent.java1053
-rw-r--r--java/awt/MenuItem.java4
-rw-r--r--java/awt/Panel.java37
-rw-r--r--java/awt/Point.java2
-rw-r--r--java/awt/Polygon.java2
-rw-r--r--java/awt/PopupMenu.java3
-rw-r--r--java/awt/Rectangle.java2
-rw-r--r--java/awt/ScrollPane.java3
-rw-r--r--java/awt/Scrollbar.java6
-rw-r--r--java/awt/Shape.java26
-rw-r--r--java/awt/SystemColor.java58
-rw-r--r--java/awt/TextArea.java69
-rw-r--r--java/awt/TextField.java4
-rw-r--r--java/awt/Toolkit.java6
-rw-r--r--java/awt/Window.java7
-rw-r--r--java/awt/color/ICC_Profile.java2
-rw-r--r--java/awt/datatransfer/Clipboard.java162
-rw-r--r--java/awt/datatransfer/ClipboardOwner.java3
-rw-r--r--java/awt/datatransfer/DataFlavor.java4
-rw-r--r--java/awt/datatransfer/StringSelection.java4
-rw-r--r--java/awt/datatransfer/SystemFlavorMap.java4
-rw-r--r--java/awt/dnd/Autoscroll.java5
-rw-r--r--java/awt/dnd/DropTarget.java5
-rw-r--r--java/awt/dnd/DropTargetContext.java6
-rw-r--r--java/awt/dnd/DropTargetDragEvent.java5
-rw-r--r--java/awt/dnd/package.html4
-rw-r--r--java/awt/dnd/peer/DropTargetContextPeer.java5
-rw-r--r--java/awt/event/AdjustmentEvent.java4
-rw-r--r--java/awt/event/InputEvent.java5
-rw-r--r--java/awt/event/InvocationEvent.java4
-rw-r--r--java/awt/event/KeyEvent.java5
-rw-r--r--java/awt/event/MouseEvent.java5
-rw-r--r--java/awt/font/TextLayout.java6
-rw-r--r--java/awt/geom/Arc2D.java133
-rw-r--r--java/awt/geom/Area.java98
-rw-r--r--java/awt/geom/CubicCurve2D.java11
-rw-r--r--java/awt/geom/Ellipse2D.java56
-rw-r--r--java/awt/geom/GeneralPath.java98
-rw-r--r--java/awt/geom/PathIterator.java4
-rw-r--r--java/awt/geom/Point2D.java11
-rw-r--r--java/awt/geom/QuadCurve2D.java11
-rw-r--r--java/awt/geom/Rectangle2D.java2
-rw-r--r--java/awt/im/InputContext.java8
-rw-r--r--java/awt/im/spi/InputMethodContext.java4
-rw-r--r--java/awt/image/AffineTransformOp.java13
-rw-r--r--java/awt/image/BandedSampleModel.java538
-rw-r--r--java/awt/image/BufferedImage.java26
-rw-r--r--java/awt/image/ColorModel.java89
-rw-r--r--java/awt/image/ComponentColorModel.java32
-rw-r--r--java/awt/image/ComponentSampleModel.java16
-rw-r--r--java/awt/image/CropImageFilter.java5
-rw-r--r--java/awt/image/DataBuffer.java231
-rw-r--r--java/awt/image/DataBufferByte.java105
-rw-r--r--java/awt/image/DataBufferDouble.java105
-rw-r--r--java/awt/image/DataBufferFloat.java105
-rw-r--r--java/awt/image/DataBufferInt.java108
-rw-r--r--java/awt/image/DataBufferShort.java105
-rw-r--r--java/awt/image/DataBufferUShort.java97
-rw-r--r--java/awt/image/DirectColorModel.java16
-rw-r--r--java/awt/image/IndexColorModel.java170
-rw-r--r--java/awt/image/MemoryImageSource.java4
-rw-r--r--java/awt/image/MultiPixelPackedSampleModel.java387
-rw-r--r--java/awt/image/PackedColorModel.java6
-rw-r--r--java/awt/image/PixelGrabber.java70
-rw-r--r--java/awt/image/Raster.java55
-rw-r--r--java/awt/image/RasterOp.java5
-rw-r--r--java/awt/image/RescaleOp.java210
-rw-r--r--java/awt/image/SinglePixelPackedSampleModel.java10
-rw-r--r--java/awt/peer/MenuBarPeer.java1
-rw-r--r--java/io/DeleteFileHelper.java5
-rw-r--r--java/io/ObjectInputStream.java13
-rw-r--r--java/io/ObjectOutputStream.java6
-rw-r--r--java/lang/Comparable.java19
-rw-r--r--java/lang/Runtime.java26
-rw-r--r--java/lang/StackTraceElement.java14
-rw-r--r--java/lang/System.java2
-rw-r--r--java/lang/Throwable.java2
-rw-r--r--java/net/Inet4Address.java3
-rw-r--r--java/net/Socket.java5
-rw-r--r--java/net/URL.java4
-rw-r--r--java/net/URLClassLoader.java39
-rw-r--r--java/net/URLConnection.java143
-rw-r--r--java/nio/ByteBuffer.java20
-rw-r--r--java/nio/CharBuffer.java18
-rw-r--r--java/nio/DoubleBuffer.java20
-rw-r--r--java/nio/FloatBuffer.java20
-rw-r--r--java/nio/IntBuffer.java20
-rw-r--r--java/nio/LongBuffer.java20
-rw-r--r--java/nio/ShortBuffer.java20
-rw-r--r--java/security/BasicPermission.java16
-rw-r--r--java/security/cert/X509CRLSelector.java445
-rw-r--r--java/security/cert/X509CertSelector.java1111
-rw-r--r--java/text/Format.java3
-rw-r--r--java/text/MessageFormat.java2
-rw-r--r--java/util/Arrays.java17
-rw-r--r--java/util/Calendar.java74
-rw-r--r--java/util/Collections.java26
-rw-r--r--java/util/TimeZone.java292
-rw-r--r--java/util/TreeMap.java9
-rw-r--r--java/util/logging/logging.properties42
133 files changed, 6339 insertions, 1236 deletions
diff --git a/java/applet/Applet.java b/java/applet/Applet.java
index 5990c6392..4fbf17c11 100644
--- a/java/applet/Applet.java
+++ b/java/applet/Applet.java
@@ -1,5 +1,5 @@
/* Applet.java -- Java base applet class
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -48,6 +48,7 @@ import java.io.ObjectInputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Locale;
+
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleState;
@@ -228,11 +229,11 @@ public class Applet extends Panel
{
try
{
- return getImage(new URL(url, name));
+ return getImage(new URL(url, name));
}
catch (MalformedURLException e)
{
- return null;
+ return null;
}
}
@@ -284,11 +285,11 @@ public class Applet extends Panel
{
try
{
- return getAudioClip(new URL(url, name));
+ return getAudioClip(new URL(url, name));
}
catch (MalformedURLException e)
{
- return null;
+ return null;
}
}
@@ -343,7 +344,7 @@ public class Applet extends Panel
AudioClip ac = getAudioClip(url);
try
{
- ac.play();
+ ac.play();
}
catch (Exception ignored)
{
@@ -364,7 +365,7 @@ public class Applet extends Panel
{
try
{
- getAudioClip(url, name).play();
+ getAudioClip(url, name).play();
}
catch (Exception ignored)
{
@@ -500,7 +501,7 @@ public class Applet extends Panel
{
AccessibleStateSet s = super.getAccessibleStateSet();
if (isActive())
- s.add(AccessibleState.ACTIVE);
+ s.add(AccessibleState.ACTIVE);
return s;
}
} // class AccessibleApplet
diff --git a/java/applet/AppletContext.java b/java/applet/AppletContext.java
index 7d44679fe..1e7053754 100644
--- a/java/applet/AppletContext.java
+++ b/java/applet/AppletContext.java
@@ -39,8 +39,8 @@ exception statement from your version. */
package java.applet;
import java.awt.Image;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Iterator;
diff --git a/java/applet/AppletStub.java b/java/applet/AppletStub.java
index 7694cc822..44722cc61 100644
--- a/java/applet/AppletStub.java
+++ b/java/applet/AppletStub.java
@@ -1,5 +1,5 @@
/* AppletStub.java -- low level interface to the browser
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,6 +35,7 @@ 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.applet;
import java.net.URL;
diff --git a/java/applet/AudioClip.java b/java/applet/AudioClip.java
index 41dd3be2a..531ab1739 100644
--- a/java/applet/AudioClip.java
+++ b/java/applet/AudioClip.java
@@ -1,5 +1,5 @@
/* AudioClip.java -- play an audio clip in an applet
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,6 +38,7 @@ exception statement from your version. */
package java.applet;
+
/**
* This interface provides a simple mechanism for playing audio clips.
* If multiple clips are played at once, the browser combines them into a
diff --git a/java/awt/AWTEventMulticaster.java b/java/awt/AWTEventMulticaster.java
index 58950ef0b..b26d1f35d 100644
--- a/java/awt/AWTEventMulticaster.java
+++ b/java/awt/AWTEventMulticaster.java
@@ -181,7 +181,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void componentResized(ComponentEvent e)
{
@@ -193,7 +193,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void componentMoved(ComponentEvent e)
{
@@ -205,7 +205,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void componentShown(ComponentEvent e)
{
@@ -217,7 +217,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void componentHidden(ComponentEvent e)
{
@@ -229,7 +229,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void componentAdded(ContainerEvent e)
{
@@ -241,7 +241,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void componentRemoved(ContainerEvent e)
{
@@ -253,7 +253,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void focusGained(FocusEvent e)
{
@@ -265,7 +265,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void focusLost(FocusEvent e)
{
@@ -277,7 +277,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void keyTyped(KeyEvent e)
{
@@ -289,7 +289,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void keyPressed(KeyEvent e)
{
@@ -301,7 +301,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void keyReleased(KeyEvent e)
{
@@ -313,7 +313,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void mouseClicked(MouseEvent e)
{
@@ -325,7 +325,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void mousePressed(MouseEvent e)
{
@@ -337,7 +337,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void mouseReleased(MouseEvent e)
{
@@ -349,7 +349,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void mouseEntered(MouseEvent e)
{
@@ -361,7 +361,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void mouseExited(MouseEvent e)
{
@@ -373,7 +373,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void mouseDragged(MouseEvent e)
{
@@ -385,7 +385,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void mouseMoved(MouseEvent e)
{
@@ -397,7 +397,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void windowOpened(WindowEvent e)
{
@@ -409,7 +409,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void windowClosing(WindowEvent e)
{
@@ -421,7 +421,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void windowClosed(WindowEvent e)
{
@@ -433,7 +433,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void windowIconified(WindowEvent e)
{
@@ -445,7 +445,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void windowDeiconified(WindowEvent e)
{
@@ -457,7 +457,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void windowActivated(WindowEvent e)
{
@@ -469,7 +469,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void windowDeactivated(WindowEvent e)
{
@@ -481,7 +481,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
* @since 1.4
*/
public void windowStateChanged(WindowEvent e)
@@ -494,7 +494,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
* @since 1.4
*/
public void windowGainedFocus(WindowEvent e)
@@ -507,7 +507,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
* @since 1.4
*/
public void windowLostFocus(WindowEvent e)
@@ -520,7 +520,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void actionPerformed(ActionEvent e)
{
@@ -532,7 +532,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void itemStateChanged(ItemEvent e)
{
@@ -544,7 +544,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void adjustmentValueChanged(AdjustmentEvent e)
{
@@ -556,7 +556,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
*/
public void textValueChanged(TextEvent e)
{
@@ -568,7 +568,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
* @since 1.2
*/
public void inputMethodTextChanged(InputMethodEvent e)
@@ -581,7 +581,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
* @since 1.2
*/
public void caretPositionChanged(InputMethodEvent e)
@@ -594,7 +594,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
* @since 1.3
*/
public void hierarchyChanged(HierarchyEvent e)
@@ -607,7 +607,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
* @since 1.3
*/
public void ancestorMoved(HierarchyEvent e)
@@ -620,7 +620,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
* @since 1.3
*/
public void ancestorResized(HierarchyEvent e)
@@ -633,7 +633,7 @@ public class AWTEventMulticaster
* Handles this event by dispatching it to the "a" and "b" listener
* instances.
*
- * @param event the event to handle
+ * @param e the event to handle
* @since 1.4
*/
public void mouseWheelMoved(MouseWheelEvent e)
diff --git a/java/awt/AWTKeyStroke.java b/java/awt/AWTKeyStroke.java
index 4e012972d..dc3a76e73 100644
--- a/java/awt/AWTKeyStroke.java
+++ b/java/awt/AWTKeyStroke.java
@@ -1,5 +1,5 @@
/* AWTKeyStroke.java -- an immutable key stroke
- Copyright (C) 2002, 2005 Free Software Foundation
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation
This file is part of GNU Classpath.
@@ -48,9 +48,9 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
-import java.util.Map;
import java.util.HashMap;
import java.util.LinkedHashMap;
+import java.util.Map;
import java.util.StringTokenizer;
/**
diff --git a/java/awt/Adjustable.java b/java/awt/Adjustable.java
index 58116e4e5..815c77ca9 100644
--- a/java/awt/Adjustable.java
+++ b/java/awt/Adjustable.java
@@ -157,7 +157,7 @@ public interface Adjustable
* Adds a listener that will receive adjustment events for this object.
*
* @param listener the adjustment listener to add
- * @see AdjustmentEvent
+ * @see java.awt.event.AdjustmentEvent
*/
void addAdjustmentListener(AdjustmentListener listener);
@@ -165,7 +165,7 @@ public interface Adjustable
* Removes an adjustment listener from this object.
*
* @param listener the adjustment listener to remove
- * @see AdjustmentEvent
+ * @see java.awt.event.AdjustmentEvent
*/
void removeAdjustmentListener(AdjustmentListener listener);
} // interface Adjustable
diff --git a/java/awt/Canvas.java b/java/awt/Canvas.java
index a244b34dc..1bb48e4de 100644
--- a/java/awt/Canvas.java
+++ b/java/awt/Canvas.java
@@ -1,4 +1,5 @@
-/* Copyright (C) 1999, 2000, 2002 Free Software Foundation
+/* Canvas.java --
+ Copyright (C) 1999, 2000, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -40,6 +41,7 @@ package java.awt;
import java.awt.image.BufferStrategy;
import java.awt.peer.ComponentPeer;
import java.io.Serializable;
+
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
@@ -136,6 +138,10 @@ public class Canvas
protected class AccessibleAWTCanvas
extends AccessibleAWTComponent
{
+ /**
+ * For compatability with Sun's JDK
+ */
+ private static final long serialVersionUID = -6325592262103146699L;
/**
* Constructor for the accessible canvas.
diff --git a/java/awt/CardLayout.java b/java/awt/CardLayout.java
index fa4f4ec0f..6e17daab1 100644
--- a/java/awt/CardLayout.java
+++ b/java/awt/CardLayout.java
@@ -1,6 +1,5 @@
-// CardLayout.java - Card-based layout engine
-
-/* Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation
+/* CardLayout.java -- Card-based layout engine
+ Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -39,9 +38,9 @@ exception statement from your version. */
package java.awt;
+import java.io.Serializable;
import java.util.Enumeration;
import java.util.Hashtable;
-import java.io.Serializable;
/** This class implements a card-based layout scheme. Each included
* component is treated as a card. Only one card can be shown at a
diff --git a/java/awt/CheckboxMenuItem.java b/java/awt/CheckboxMenuItem.java
index c7df075b3..0630c302b 100644
--- a/java/awt/CheckboxMenuItem.java
+++ b/java/awt/CheckboxMenuItem.java
@@ -1,5 +1,5 @@
/* CheckboxMenuItem.java -- A menu option with a checkbox on it.
- Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -41,7 +41,6 @@ package java.awt;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.peer.CheckboxMenuItemPeer;
-import java.awt.peer.MenuItemPeer;
import java.util.EventListener;
/**
@@ -198,12 +197,9 @@ getSelectedObjects()
public synchronized void
addNotify()
{
- if (peer != null)
- {
- // This choice of toolkit seems unsatisfying, but I'm not sure
- // what else to do.
- peer = getToolkit().createCheckboxMenuItem(this);
- }
+ if (peer == null)
+ peer = getToolkit().createCheckboxMenuItem(this);
+
super.addNotify ();
}
diff --git a/java/awt/Color.java b/java/awt/Color.java
index c41117a6e..c32438521 100644
--- a/java/awt/Color.java
+++ b/java/awt/Color.java
@@ -506,7 +506,7 @@ public class Color implements Paint, Serializable
/**
* Returns the RGB value for this color, in the sRGB color space. The blue
- * value will be in bits 0-7, green in 8-15, red in 6-23, and alpha value in
+ * value will be in bits 0-7, green in 8-15, red in 16-23, and alpha value in
* 24-31.
*
* @return the RGB value for this color
@@ -772,9 +772,9 @@ public class Color implements Paint, Serializable
if (red == max)
array[0] = (green - blue) / delta;
else if (green == max)
- array[0] = 1 / 3 + (blue - red) / delta;
+ array[0] = 1f / 3 + (blue - red) / delta;
else
- array[0] = 2 / 3 + (red - green) / delta;
+ array[0] = 2f / 3 + (red - green) / delta;
if (array[0] < 0)
array[0]++;
}
diff --git a/java/awt/Component.java b/java/awt/Component.java
index 205976aae..f73c55204 100644
--- a/java/awt/Component.java
+++ b/java/awt/Component.java
@@ -1,5 +1,5 @@
/* Component.java -- a graphics component
- Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation
+ Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -47,17 +47,18 @@ import java.awt.event.FocusListener;
import java.awt.event.HierarchyBoundsListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
import java.awt.event.InputEvent;
import java.awt.event.InputMethodEvent;
import java.awt.event.InputMethodListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
-import java.awt.event.MouseWheelListener;
import java.awt.event.MouseWheelEvent;
+import java.awt.event.MouseWheelListener;
import java.awt.event.PaintEvent;
+import java.awt.event.WindowEvent;
import java.awt.im.InputContext;
import java.awt.im.InputMethodRequests;
import java.awt.image.BufferStrategy;
@@ -69,8 +70,8 @@ import java.awt.peer.ComponentPeer;
import java.awt.peer.LightweightPeer;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
-import java.io.ObjectInputStream;
import java.io.IOException;
+import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
@@ -83,6 +84,7 @@ import java.util.Iterator;
import java.util.Locale;
import java.util.Set;
import java.util.Vector;
+
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleComponent;
import javax.accessibility.AccessibleContext;
@@ -292,7 +294,7 @@ public abstract class Component
* @see #getLocale()
* @see #setLocale(Locale)
*/
- Locale locale;
+ Locale locale = Locale.getDefault ();
/**
* True if the object should ignore repaint events (usually because it is
@@ -2269,7 +2271,7 @@ public abstract class Component
{
boolean handled = handleEvent (e);
- if (!handled)
+ if (!handled && getParent() != null)
// FIXME: need to translate event coordinates to parent's
// coordinate space.
handled = getParent ().postEvent (e);
@@ -3432,7 +3434,7 @@ public abstract class Component
*/
public boolean isFocusTraversable()
{
- return enabled && visible && (peer == null || peer.isFocusTraversable());
+ return enabled && visible && (peer == null || isLightweight() || peer.isFocusTraversable());
}
/**
@@ -3447,7 +3449,11 @@ public abstract class Component
}
/**
- * Specify whether this component can receive focus.
+ * Specify whether this component can receive focus. This method also
+ * sets the {@link #isFocusTraversableOverridden} field to 1, which
+ * appears to be the undocumented way {@link
+ * DefaultFocusTraversalPolicy#accept()} determines whether to respect
+ * the {@link #isFocusable()} method of the component.
*
* @param focusable the new focusable status
* @since 1.4
@@ -3456,6 +3462,7 @@ public abstract class Component
{
firePropertyChange("focusable", this.focusable, focusable);
this.focusable = focusable;
+ this.isFocusTraversableOverridden = 1;
}
/**
@@ -3715,7 +3722,7 @@ public abstract class Component
Window toplevel = (Window) parent;
if (toplevel.isFocusableWindow ())
{
- if (peer != null)
+ if (peer != null && !isLightweight())
// This call will cause a FOCUS_GAINED event to be
// posted to the system event queue if the native
// windowing system grants the focus request.
@@ -3801,7 +3808,7 @@ public abstract class Component
Window toplevel = (Window) parent;
if (toplevel.isFocusableWindow ())
{
- if (peer != null)
+ if (peer != null && !isLightweight())
// This call will cause a FOCUS_GAINED event to be
// posted to the system event queue if the native
// windowing system grants the focus request.
@@ -3922,6 +3929,7 @@ public abstract class Component
if (focusedWindow == toplevel)
{
if (peer != null
+ && !isLightweight()
&& !(this instanceof Window))
// This call will cause a FOCUS_GAINED event to be
// posted to the system event queue if the native
@@ -4499,7 +4507,7 @@ p * <li>the set of backward traversal keys
*
* @return an AWT 1.0 event representing e
*/
- private Event translateEvent (AWTEvent e)
+ static Event translateEvent (AWTEvent e)
{
Component target = (Component) e.getSource ();
Event translated = null;
@@ -4691,6 +4699,7 @@ p * <li>the set of backward traversal keys
*
* @param e the event to dispatch
*/
+
void dispatchEventImpl (AWTEvent e)
{
Event oldEvent = translateEvent (e);
@@ -4699,7 +4708,30 @@ p * <li>the set of backward traversal keys
postEvent (oldEvent);
if (eventTypeEnabled (e.id))
- processEvent (e);
+ {
+ // the trick we use to communicate between dispatch and redispatch
+ // is to have KeyboardFocusManager.redispatch synchronize on the
+ // object itself. we then do not redispatch to KeyboardFocusManager
+ // if we are already holding the lock.
+ if (! Thread.holdsLock(e))
+ {
+ switch (e.id)
+ {
+ case WindowEvent.WINDOW_GAINED_FOCUS:
+ case WindowEvent.WINDOW_LOST_FOCUS:
+ case KeyEvent.KEY_PRESSED:
+ case KeyEvent.KEY_RELEASED:
+ case KeyEvent.KEY_TYPED:
+ case FocusEvent.FOCUS_GAINED:
+ case FocusEvent.FOCUS_LOST:
+ if (KeyboardFocusManager
+ .getCurrentKeyboardFocusManager()
+ .dispatchEvent(e))
+ return;
+ }
+ }
+ processEvent (e);
+ }
}
/**
diff --git a/java/awt/Container.java b/java/awt/Container.java
index f164afa89..778b72b86 100644
--- a/java/awt/Container.java
+++ b/java/awt/Container.java
@@ -35,27 +35,29 @@ 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 java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
-import java.awt.event.MouseEvent;
import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
import java.awt.peer.ContainerPeer;
import java.awt.peer.LightweightPeer;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
-import java.io.ObjectInputStream;
import java.io.IOException;
+import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.util.Collections;
import java.util.EventListener;
-import java.util.Iterator;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
+
import javax.accessibility.Accessible;
import javax.swing.SwingUtilities;
@@ -527,7 +529,7 @@ public class Container extends Component
/**
* Recursively invalidates the container tree.
*/
- private void invalidateTree()
+ void invalidateTree()
{
for (int i = 0; i < ncomponents; i++)
{
@@ -572,8 +574,8 @@ public class Container extends Component
}
/* children will call invalidate() when they are layed out. It
- is therefore imporant that valid is not set to true
- before after the children has been layed out. */
+ is therefore important that valid is not set to true
+ until after the children have been layed out. */
valid = true;
if (cPeer != null)
@@ -704,6 +706,8 @@ public class Container extends Component
{
if (!isShowing())
return;
+ // Paint self first.
+ super.paint(g);
// Visit heavyweights as well, in case they were
// erased when we cleared the background for this container.
visitChildren(g, GfxPaintVisitor.INSTANCE, false);
@@ -1507,10 +1511,11 @@ public class Container extends Component
void dispatchEventImpl(AWTEvent e)
{
// Give lightweight dispatcher a chance to handle it.
- if (dispatcher != null
+ if (eventTypeEnabled (e.id)
+ && dispatcher != null
&& dispatcher.handleEvent (e))
return;
-
+
if ((e.id <= ContainerEvent.CONTAINER_LAST
&& e.id >= ContainerEvent.CONTAINER_FIRST)
&& (containerListener != null
@@ -1588,7 +1593,6 @@ public class Container extends Component
{
if (dispatcher == null)
dispatcher = new LightweightDispatcher (this);
- dispatcher.enableEvents (component[i].eventMask);
}
@@ -1833,7 +1837,6 @@ class LightweightDispatcher implements Serializable
{
private static final long serialVersionUID = 5184291520170872969L;
private Container nativeContainer;
- private Component focus;
private Cursor nativeCursor;
private long eventMask;
@@ -1847,11 +1850,6 @@ class LightweightDispatcher implements Serializable
nativeContainer = c;
}
- void enableEvents(long l)
- {
- eventMask |= l;
- }
-
void acquireComponentForMouseEvent(MouseEvent me)
{
int x = me.getX ();
@@ -1951,9 +1949,6 @@ class LightweightDispatcher implements Serializable
boolean handleEvent(AWTEvent e)
{
- if ((eventMask & e.getID()) == 0)
- return false;
-
if (e instanceof MouseEvent)
{
MouseEvent me = (MouseEvent) e;
@@ -1991,10 +1986,6 @@ class LightweightDispatcher implements Serializable
e.consume();
}
}
- else if (e instanceof KeyEvent && focus != null)
- {
- focus.processKeyEvent((KeyEvent) e);
- }
return e.isConsumed();
}
diff --git a/java/awt/DefaultFocusTraversalPolicy.java b/java/awt/DefaultFocusTraversalPolicy.java
index 73b1e95a9..f49f386a1 100644
--- a/java/awt/DefaultFocusTraversalPolicy.java
+++ b/java/awt/DefaultFocusTraversalPolicy.java
@@ -92,19 +92,17 @@ public class DefaultFocusTraversalPolicy
&& comp.enabled)
{
if (comp.isFocusTraversableOverridden != 0
- && comp.isFocusTraversable ())
- return true;
- else
- {
- if (!(comp instanceof Canvas
- || comp instanceof Panel
- || comp instanceof Label
- || comp instanceof ScrollPane
- || comp instanceof Scrollbar
- || comp instanceof Window
- || comp.isLightweight ()))
- return true;
- }
+ && (comp.isFocusTraversable () || comp.isFocusable()))
+ return true;
+
+ if (!(comp instanceof Canvas
+ || comp instanceof Panel
+ || comp instanceof Label
+ || comp instanceof ScrollPane
+ || comp instanceof Scrollbar
+ || comp instanceof Window
+ || comp.isLightweight ()))
+ return true;
}
return false;
}
diff --git a/java/awt/DefaultKeyboardFocusManager.java b/java/awt/DefaultKeyboardFocusManager.java
index dec1d944a..3c0c30aa0 100644
--- a/java/awt/DefaultKeyboardFocusManager.java
+++ b/java/awt/DefaultKeyboardFocusManager.java
@@ -1,5 +1,5 @@
/* DefaultKeyboardFocusManager.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,8 +38,15 @@ exception statement from your version. */
package java.awt;
-import java.util.*;
-import java.awt.event.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.FocusEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.WindowEvent;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
// FIXME: finish documentation
public class DefaultKeyboardFocusManager extends KeyboardFocusManager
@@ -155,7 +162,7 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager
&& e.id != WindowEvent.WINDOW_DEACTIVATED)
return false;
- target.dispatchEvent (e);
+ redispatchEvent(target, e);
return true;
}
else if (e instanceof FocusEvent)
@@ -197,7 +204,7 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager
setGlobalPermanentFocusOwner (null);
}
- target.dispatchEvent (e);
+ redispatchEvent(target, e);
return true;
}
@@ -258,7 +265,7 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager
Component focusOwner = getGlobalPermanentFocusOwner ();
if (focusOwner != null)
- focusOwner.dispatchEvent (e);
+ redispatchEvent(focusOwner, e);
// Loop through all registered KeyEventPostProcessors, giving
// each a chance to process this event.
@@ -311,7 +318,7 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager
MenuItem item = menu.getItem (j);
MenuShortcut shortcut = item.getShortcut ();
- if (shortcut != null)
+ if (item.isEnabled() && shortcut != null)
{
// Dispatch a new ActionEvent if:
//
@@ -443,7 +450,8 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager
FocusTraversalPolicy policy = focusCycleRoot.getFocusTraversalPolicy ();
Component previous = policy.getComponentBefore (focusCycleRoot, focusComp);
- previous.requestFocusInWindow ();
+ if (previous != null)
+ previous.requestFocusInWindow ();
}
public void focusNextComponent (Component comp)
@@ -453,7 +461,8 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager
FocusTraversalPolicy policy = focusCycleRoot.getFocusTraversalPolicy ();
Component next = policy.getComponentAfter (focusCycleRoot, focusComp);
- next.requestFocusInWindow ();
+ if (next != null)
+ next.requestFocusInWindow ();
}
public void upFocusCycle (Component comp)
@@ -465,7 +474,8 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager
{
FocusTraversalPolicy policy = focusCycleRoot.getFocusTraversalPolicy ();
Component defaultComponent = policy.getDefaultComponent (focusCycleRoot);
- defaultComponent.requestFocusInWindow ();
+ if (defaultComponent != null)
+ defaultComponent.requestFocusInWindow ();
}
else
{
@@ -485,7 +495,8 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager
{
FocusTraversalPolicy policy = cont.getFocusTraversalPolicy ();
Component defaultComponent = policy.getDefaultComponent (cont);
- defaultComponent.requestFocusInWindow ();
+ if (defaultComponent != null)
+ defaultComponent.requestFocusInWindow ();
setGlobalCurrentFocusCycleRoot (cont);
}
}
diff --git a/java/awt/EventDispatchThread.java b/java/awt/EventDispatchThread.java
index 89b609557..097cc001b 100644
--- a/java/awt/EventDispatchThread.java
+++ b/java/awt/EventDispatchThread.java
@@ -1,4 +1,5 @@
-/* Copyright (C) 2000, 2002 Free Software Foundation
+/* EventDispatchThread.java -
+ Copyright (C) 2000, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -34,12 +35,12 @@ 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. */
-/** @author Bryce McKinlay */
-
-/* Status: believed complete, but untested. */
-
package java.awt;
+/**
+ * @author Bryce McKinlay
+ * @status believed complete, but untested.
+ */
class EventDispatchThread extends Thread
{
private static int dispatchThreadNum = 1;
diff --git a/java/awt/FileDialog.java b/java/awt/FileDialog.java
index 854d092f0..1af1de3b7 100644
--- a/java/awt/FileDialog.java
+++ b/java/awt/FileDialog.java
@@ -1,5 +1,5 @@
/* FileDialog.java -- A filename selection dialog box
- Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,7 +39,6 @@ exception statement from your version. */
package java.awt;
import java.awt.peer.FileDialogPeer;
-import java.awt.peer.DialogPeer;
import java.io.FilenameFilter;
import java.io.Serializable;
diff --git a/java/awt/FlowLayout.java b/java/awt/FlowLayout.java
index 98d74941e..a06d16611 100644
--- a/java/awt/FlowLayout.java
+++ b/java/awt/FlowLayout.java
@@ -1,6 +1,5 @@
-// FlowLayout.java - Grid-based layout engine
-
-/* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation
+/* FlowLayout.java -- Grid-based layout engine
+ Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -47,7 +46,7 @@ import java.io.Serializable;
* supports horizontal and vertical gaps. These are used for spacing
* between components.
*
- * @author Tom Tromey <tromey@redhat.com>
+ * @author Tom Tromey (tromey@redhat.com)
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public class FlowLayout implements LayoutManager, Serializable
diff --git a/java/awt/Font.java b/java/awt/Font.java
index 754e078d7..25a1d925b 100644
--- a/java/awt/Font.java
+++ b/java/awt/Font.java
@@ -38,35 +38,34 @@ exception statement from your version. */
package java.awt;
+import gnu.java.awt.ClasspathToolkit;
+import gnu.java.awt.peer.ClasspathFontPeer;
+
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.font.LineMetrics;
import java.awt.font.TextAttribute;
-import java.awt.font.TransformAttribute;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.peer.FontPeer;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.Serializable;
+import java.text.AttributedCharacterIterator;
+import java.text.CharacterIterator;
+import java.text.StringCharacterIterator;
+import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
-import java.util.HashMap;
import java.util.StringTokenizer;
-import java.text.CharacterIterator;
-import java.text.AttributedCharacterIterator;
-import java.text.StringCharacterIterator;
-
-import gnu.java.awt.ClasspathToolkit;
-import gnu.java.awt.peer.ClasspathFontPeer;
/**
- * This class represents a windowing system font.
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- * @author Warren Levy <warrenl@cygnus.com>
- * @author Graydon Hoare <graydon@redhat.com>
- */
+ * This class represents a windowing system font.
+ *
+ * @author Aaron M. Renn (arenn@urbanophile.com)
+ * @author Warren Levy (warrenl@cygnus.com)
+ * @author Graydon Hoare (graydon@redhat.com)
+ */
public class Font implements Serializable
{
diff --git a/java/awt/FontMetrics.java b/java/awt/FontMetrics.java
index cb76f5079..9fd1ac962 100644
--- a/java/awt/FontMetrics.java
+++ b/java/awt/FontMetrics.java
@@ -38,6 +38,10 @@ exception statement from your version. */
package java.awt;
+import java.awt.font.FontRenderContext;
+import java.awt.font.LineMetrics;
+import java.text.CharacterIterator;
+
// FIXME: I leave many methods basically unimplemented. This
// should be reviewed.
@@ -349,6 +353,114 @@ toString()
+ ",descent=" + getDescent() + ",height=" + getHeight() + "]");
}
+
+// Generic FontRenderContext used when getLineMetrics is called with a
+// plain Graphics object.
+private static final FontRenderContext gRC = new FontRenderContext(null,
+ false,
+ false);
+
+/**
+ * Returns a {@link LineMetrics} object constructed with the
+ * specified text and the {@link FontRenderContext} of the Graphics
+ * object when it is an instance of Graphics2D or a generic
+ * FontRenderContext with a null transform, not anti-aliased and not
+ * using fractional metrics.
+ *
+ * @param text The string to calculate metrics from.
+ * @param g The Graphics object that will be used.
+ *
+ * @return A new {@link LineMetrics} object.
+ */
+public LineMetrics getLineMetrics(String text, Graphics g)
+{
+ return getLineMetrics(text, 0, text.length(), g);
+}
+
+/**
+ * Returns a {@link LineMetrics} object constructed with the
+ * specified text and the {@link FontRenderContext} of the Graphics
+ * object when it is an instance of Graphics2D or a generic
+ * FontRenderContext with a null transform, not anti-aliased and not
+ * using fractional metrics.
+ *
+ * @param text The string to calculate metrics from.
+ * @param begin Index of first character in <code>text</code> to measure.
+ * @param limit Index of last character in <code>text</code> to measure.
+ * @param g The Graphics object that will be used.
+ *
+ * @return A new {@link LineMetrics} object.
+ *
+ * @throws IndexOutOfBoundsException if the range [begin, limit] is
+ * invalid in <code>text</code>.
+ */
+public LineMetrics getLineMetrics(String text, int begin,
+ int limit, Graphics g)
+{
+ FontRenderContext rc;
+ if (g instanceof Graphics2D)
+ rc = ((Graphics2D) g).getFontRenderContext();
+ else
+ rc = gRC;
+ return font.getLineMetrics(text, begin, limit, rc);
+}
+
+/**
+ * Returns a {@link LineMetrics} object constructed with the
+ * specified text and the {@link FontRenderContext} of the Graphics
+ * object when it is an instance of Graphics2D or a generic
+ * FontRenderContext with a null transform, not anti-aliased and not
+ * using fractional metrics.
+ *
+ * @param chars The string to calculate metrics from.
+ * @param begin Index of first character in <code>text</code> to measure.
+ * @param limit Index of last character in <code>text</code> to measure.
+ * @param g The Graphics object that will be used.
+ *
+ * @return A new {@link LineMetrics} object.
+ *
+ * @throws IndexOutOfBoundsException if the range [begin, limit] is
+ * invalid in <code>text</code>.
+ */
+public LineMetrics getLineMetrics(char[] chars, int begin,
+ int limit, Graphics g)
+{
+ FontRenderContext rc;
+ if (g instanceof Graphics2D)
+ rc = ((Graphics2D) g).getFontRenderContext();
+ else
+ rc = gRC;
+ return font.getLineMetrics(chars, begin, limit, rc);
+}
+
+/**
+ * Returns a {@link LineMetrics} object constructed with the
+ * specified text and the {@link FontRenderContext} of the Graphics
+ * object when it is an instance of Graphics2D or a generic
+ * FontRenderContext with a null transform, not anti-aliased and not
+ * using fractional metrics.
+ *
+ * @param rc The string to calculate metrics from.
+ * @param begin Index of first character in <code>text</code> to measure.
+ * @param limit Index of last character in <code>text</code> to measure.
+ * @param g The Graphics object that will be used.
+ *
+ * @return A new {@link LineMetrics} object.
+ *
+ * @throws IndexOutOfBoundsException if the range [begin, limit] is
+ * invalid in <code>text</code>.
+ */
+public LineMetrics getLineMetrics(CharacterIterator ci, int begin,
+ int limit, Graphics g)
+{
+ FontRenderContext rc;
+ if (g instanceof Graphics2D)
+ rc = ((Graphics2D) g).getFontRenderContext();
+ else
+ rc = gRC;
+ return font.getLineMetrics(ci, begin, limit, rc);
+}
+
} // class FontMetrics
diff --git a/java/awt/Frame.java b/java/awt/Frame.java
index 633f8604a..42d85bc79 100644
--- a/java/awt/Frame.java
+++ b/java/awt/Frame.java
@@ -39,7 +39,6 @@ exception statement from your version. */
package java.awt;
import java.awt.peer.FramePeer;
-import java.util.Enumeration;
import java.util.Vector;
/**
@@ -317,6 +316,7 @@ setMenuBar(MenuBar menuBar)
this.menuBar.removeNotify();
if (menuBar != null)
menuBar.addNotify();
+ invalidateTree ();
((FramePeer) peer).setMenuBar(menuBar);
}
this.menuBar = menuBar;
diff --git a/java/awt/Graphics2D.java b/java/awt/Graphics2D.java
index b35f08aa8..e16c2d8fb 100644
--- a/java/awt/Graphics2D.java
+++ b/java/awt/Graphics2D.java
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2002 Free Software Foundation
+/* Copyright (C) 2000, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -34,6 +34,7 @@ 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 java.awt.font.FontRenderContext;
@@ -41,12 +42,10 @@ import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
-import java.awt.image.RenderedImage;
import java.awt.image.ImageObserver;
+import java.awt.image.RenderedImage;
import java.awt.image.renderable.RenderableImage;
-
import java.text.AttributedCharacterIterator;
-
import java.util.Map;
/**
diff --git a/java/awt/GraphicsEnvironment.java b/java/awt/GraphicsEnvironment.java
index 2b4ce5128..b963f4bab 100644
--- a/java/awt/GraphicsEnvironment.java
+++ b/java/awt/GraphicsEnvironment.java
@@ -1,5 +1,5 @@
/* GraphicsEnvironment.java -- information about the graphics environment
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,16 +38,17 @@ exception statement from your version. */
package java.awt;
+import gnu.java.awt.ClasspathToolkit;
+
import java.awt.image.BufferedImage;
import java.util.Locale;
-import gnu.java.awt.ClasspathToolkit;
/**
* This descibes the collection of GraphicsDevice and Font objects available
* on a given platform. The resources might be local or remote, and specify
* the valid configurations for displaying graphics.
*
- * @author Eric Blake <ebb9@email.byu.edu>
+ * @author Eric Blake (ebb9@email.byu.edu)
* @see GraphicsDevice
* @see GraphicsConfiguration
* @since 1.4
diff --git a/java/awt/GridBagConstraints.java b/java/awt/GridBagConstraints.java
index 651cfdc19..2795b9ed9 100644
--- a/java/awt/GridBagConstraints.java
+++ b/java/awt/GridBagConstraints.java
@@ -1,6 +1,5 @@
-// GridBagConstraints.java - Constraints for GridBag layout manager
-
-/* Copyright (C) 2000, 2001, 2002 Free Software Foundation
+/* GridBagConstraints.java -- Constraints for GridBag layout manager
+ Copyright (C) 2000, 2001, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -41,8 +40,10 @@ package java.awt;
import java.io.Serializable;
-/** This specifies the constraints for a component managed by the
- * GridBagLayout layout manager. */
+/**
+ * This specifies the constraints for a component managed by the
+ * GridBagLayout layout manager.
+ */
public class GridBagConstraints implements Cloneable, Serializable
{
static final long serialVersionUID = -1000070633030801713L;
diff --git a/java/awt/GridBagLayout.java b/java/awt/GridBagLayout.java
index fa627f400..8f6716471 100644
--- a/java/awt/GridBagLayout.java
+++ b/java/awt/GridBagLayout.java
@@ -1,5 +1,5 @@
/* GridBagLayout - Layout manager for components according to GridBagConstraints
- Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -40,8 +40,8 @@ package java.awt;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.Hashtable;
import java.util.HashMap;
+import java.util.Hashtable;
/**
* @author Michael Koch <konqueror@gmx.de>
diff --git a/java/awt/GridLayout.java b/java/awt/GridLayout.java
index a8befc4c0..b98102d46 100644
--- a/java/awt/GridLayout.java
+++ b/java/awt/GridLayout.java
@@ -1,6 +1,5 @@
-// GridLayout.java - Grid-based layout engine
-
-/* Copyright (C) 1999, 2000, 2002 Free Software Foundation
+/* GridLayout.java -- Grid-based layout engine
+ Copyright (C) 1999, 2000, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
diff --git a/java/awt/Image.java b/java/awt/Image.java
index 451b092e6..37617719b 100644
--- a/java/awt/Image.java
+++ b/java/awt/Image.java
@@ -1,5 +1,5 @@
/* Image.java -- superclass for images
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,7 +38,6 @@ exception statement from your version. */
package java.awt;
-import java.awt.image.AreaAveragingScaleFilter;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
diff --git a/java/awt/KeyboardFocusManager.java b/java/awt/KeyboardFocusManager.java
index 15b9db556..eeb4f50ce 100644
--- a/java/awt/KeyboardFocusManager.java
+++ b/java/awt/KeyboardFocusManager.java
@@ -1,5 +1,5 @@
/* KeyboardFocusManager.java -- manage component focusing via the keyboard
- Copyright (C) 2002, 2005 Free Software Foundation
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation
This file is part of GNU Classpath.
@@ -38,8 +38,8 @@ exception statement from your version. */
package java.awt;
-import java.awt.event.KeyEvent;
import java.awt.event.FocusEvent;
+import java.awt.event.KeyEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.beans.PropertyVetoException;
@@ -1098,8 +1098,11 @@ public abstract class KeyboardFocusManager
*/
public final void redispatchEvent (Component target, AWTEvent e)
{
- e.setSource (target);
- dispatchEvent (e);
+ synchronized (e)
+ {
+ e.setSource (target);
+ target.dispatchEvent (e);
+ }
}
/**
diff --git a/java/awt/Label.java b/java/awt/Label.java
index 0cc92abe4..a98812ce8 100644
--- a/java/awt/Label.java
+++ b/java/awt/Label.java
@@ -1,5 +1,5 @@
/* Label.java -- Java label widget
- Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,6 +39,7 @@ exception statement from your version. */
package java.awt;
import java.awt.peer.LabelPeer;
+
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
@@ -259,6 +260,11 @@ protected class AccessibleAWTLabel
extends AccessibleAWTComponent
{
/**
+ * For compatability with Sun's JDK 1.4.2 rev. 5
+ */
+ private static final long serialVersionUID = -3568967560160480438L;
+
+ /**
* Constructor for the accessible label.
*/
public AccessibleAWTLabel()
diff --git a/java/awt/List.java b/java/awt/List.java
index 47177edc7..d79bcf6fb 100644
--- a/java/awt/List.java
+++ b/java/awt/List.java
@@ -1,5 +1,5 @@
/* List.java -- A listbox widget
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -45,6 +45,7 @@ import java.awt.event.ItemListener;
import java.awt.peer.ListPeer;
import java.util.EventListener;
import java.util.Vector;
+
import javax.accessibility.Accessible;
/**
diff --git a/java/awt/MediaTracker.java b/java/awt/MediaTracker.java
index d1df8b383..e69832d11 100644
--- a/java/awt/MediaTracker.java
+++ b/java/awt/MediaTracker.java
@@ -1,5 +1,5 @@
/* MediaTracker.java -- Class used for keeping track of images
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002i, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,8 +38,8 @@ exception statement from your version. */
package java.awt;
-import java.util.ArrayList;
import java.awt.image.ImageObserver;
+import java.util.ArrayList;
/**
* This class is used for keeping track of the status of various media
diff --git a/java/awt/Menu.java b/java/awt/Menu.java
index c6c4f214d..33391525a 100644
--- a/java/awt/Menu.java
+++ b/java/awt/Menu.java
@@ -40,8 +40,8 @@ package java.awt;
import java.awt.peer.MenuPeer;
import java.io.Serializable;
-import java.util.Vector;
import java.util.Enumeration;
+import java.util.Vector;
/**
* This class represents a pull down or tear off menu in Java's AWT.
@@ -72,17 +72,20 @@ private Vector items = new Vector();
/**
* @serial Flag indicating whether or not this menu is a tear off
*/
-private boolean isTearOff;
+private boolean tearOff;
/**
* @serial Indicates whether or not this is a help menu.
*/
private boolean isHelpMenu;
-// From the serialization spec. FIXME: what should it be?
-private int menuSerializedDataVersion;
+ /*
+ * @serial Unused in this implementation, but present in Sun's
+ * serialization spec. Value obtained via reflection.
+ */
+ private int menuSerializedDataVersion = 1;
-static final String separatorLabel = "-";
+static final transient String separatorLabel = "-";
/*************************************************************************/
@@ -134,7 +137,7 @@ Menu(String label, boolean isTearOff)
{
super(label);
- this.isTearOff = isTearOff;
+ tearOff = isTearOff;
if (label.equals("Help"))
isHelpMenu = true;
@@ -158,7 +161,7 @@ Menu(String label, boolean isTearOff)
public boolean
isTearOff()
{
- return(isTearOff);
+ return(tearOff);
}
/*************************************************************************/
@@ -251,8 +254,6 @@ add(String label)
* @param item The menu item to add.
* @param index The index of the menu item.
*
- * XXX: FIXME
- *
* @exception IllegalArgumentException If the index is less than zero.
* @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid.
*/
@@ -262,12 +263,26 @@ insert(MenuItem item, int index)
if (index < 0)
throw new IllegalArgumentException("Index is less than zero");
- items.insertElementAt(item, index);
+ MenuPeer peer = (MenuPeer) getPeer();
+ if (peer == null)
+ return;
- MenuPeer mp = (MenuPeer)getPeer();
- // FIXME: Need to add a peer method here.
-// if (mp != null)
-// mp.insertItem(item, index);
+ int count = getItemCount ();
+
+ if (index >= count)
+ peer.addItem (item);
+ else
+ {
+ for (int i = count - 1; i >= index; i--)
+ peer.delItem (i);
+
+ peer.addItem (item);
+
+ for (int i = index; i < count; i++)
+ peer.addItem ((MenuItem) items.elementAt (i));
+ }
+
+ items.insertElementAt(item, index);
}
/*************************************************************************/
@@ -305,8 +320,6 @@ addSeparator()
*
* @param index The index at which to insert a separator bar.
*
- * XXX: FIXME
- *
* @exception IllegalArgumentException If the index is less than zero.
* @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid.
*/
@@ -339,7 +352,7 @@ remove(int index)
/**
* Removes the specifed item from the menu. If the specified component
- * does not exist, this method does nothing. // FIXME: Right?
+ * does not exist, this method does nothing.
*
* @param item The component to remove.
*/
@@ -415,7 +428,7 @@ removeNotify()
public String
paramString()
{
- return (",isTearOff=" + isTearOff + ",isHelpMenu=" + isHelpMenu
+ return (",tearOff=" + tearOff + ",isHelpMenu=" + isHelpMenu
+ super.paramString());
}
diff --git a/java/awt/MenuBar.java b/java/awt/MenuBar.java
index fb2672900..0607a0526 100644
--- a/java/awt/MenuBar.java
+++ b/java/awt/MenuBar.java
@@ -45,14 +45,19 @@ import java.io.Serializable;
import java.util.Enumeration;
import java.util.Vector;
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRole;
+
/**
* This class implements a menu bar in the AWT system.
*
* @author Aaron M. Renn (arenn@urbanophile.com)
* @author Tom Tromey <tromey@redhat.com>
+ * @author Andrew John Hughes <gnu_andrew@member.fsf.org>
*/
public class MenuBar extends MenuComponent
- implements MenuContainer, Serializable
+ implements MenuContainer, Serializable, Accessible
{
/*
@@ -78,6 +83,14 @@ private Menu helpMenu;
*/
private Vector menus = new Vector();
+ /**
+ * The accessible context for this component.
+ *
+ * @see #getAccessibleContext()
+ * @serial ignored.
+ */
+ private transient AccessibleContext accessibleContext;
+
/*************************************************************************/
/*
@@ -128,17 +141,17 @@ setHelpMenu(Menu menu)
helpMenu.removeNotify ();
helpMenu.parent = null;
}
+ helpMenu = menu;
if (menu.parent != null)
menu.parent.remove (menu);
- if (menu.parent != null)
- menu.parent.remove (menu);
menu.parent = this;
+ MenuBarPeer peer = (MenuBarPeer) getPeer ();
if (peer != null)
{
- MenuBarPeer mp = (MenuBarPeer) peer;
- mp.addHelpMenu (menu);
+ menu.addNotify();
+ peer.addHelpMenu (menu);
}
}
@@ -163,8 +176,7 @@ add(Menu menu)
if (peer != null)
{
- MenuBarPeer mp = (MenuBarPeer) peer;
- mp.addMenu (menu);
+ menu.addNotify();
}
return(menu);
@@ -234,8 +246,7 @@ getMenuCount()
public int
countMenus()
{
- // FIXME: How does the help menu fit in here?
- return menus.size ();
+ return menus.size () + (getHelpMenu () == null ? 0 : 1);
}
/*************************************************************************/
@@ -269,6 +280,11 @@ addNotify()
Menu mi = (Menu)e.nextElement();
mi.addNotify();
}
+ if (helpMenu != null)
+ {
+ helpMenu.addNotify();
+ ((MenuBarPeer) peer).addHelpMenu(helpMenu);
+ }
}
/*************************************************************************/
@@ -353,4 +369,56 @@ deleteShortcut(MenuShortcut shortcut)
it.deleteShortcut ();
}
+/**
+ * Gets the AccessibleContext associated with this <code>MenuBar</code>.
+ * 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)
+ {
+ /* Create the context */
+ accessibleContext = new AccessibleAWTMenuBar();
+ }
+ return accessibleContext;
+}
+
+/**
+ * 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
+ */
+ private static final long serialVersionUID = -8577604491830083815L;
+
+ /**
+ * This is the default constructor, which simply calls the default
+ * constructor of the superclass.
+ */
+ protected AccessibleAWTMenuBar()
+ {
+ super();
+ }
+
+ /**
+ * Returns the accessible role relating to the menu bar.
+ *
+ * @return <code>AccessibleRole.MENU_BAR</code>.
+ */
+ public AccessibleRole getAccessibleRole()
+ {
+ return AccessibleRole.MENU_BAR;
+ }
+
+} // class AccessibleAWTMenuBar
+
} // class MenuBar
diff --git a/java/awt/MenuComponent.java b/java/awt/MenuComponent.java
index ccf2b4974..78adfaea6 100644
--- a/java/awt/MenuComponent.java
+++ b/java/awt/MenuComponent.java
@@ -1,5 +1,5 @@
/* MenuComponent.java -- Superclass of all AWT menu components
- Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,15 +38,24 @@ exception statement from your version. */
package java.awt;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
import java.awt.peer.MenuComponentPeer;
import java.io.Serializable;
+import java.util.Locale;
-// FIXME: Java 1.0 event model unimplemented
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleComponent;
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRole;
+import javax.accessibility.AccessibleSelection;
+import javax.accessibility.AccessibleStateSet;
/**
- * This is the superclass of all non-menu AWT widgets.
+ * This is the superclass of all menu AWT widgets.
*
* @author Aaron M. Renn (arenn@urbanophile.com)
+ * @author Andrew John Hughes <gnu_andrew@member.fsf.org>
*/
public abstract class MenuComponent implements Serializable
{
@@ -59,31 +68,101 @@ public abstract class MenuComponent implements Serializable
private static final long serialVersionUID = -4536902356223894379L;
/*************************************************************************/
-
+
/*
* Instance Variables
*/
- // FIXME: missing serialized fields `nameExplicitlySet',
- // `newEventsOnly', and `accessibleContext'.
+/**
+ * The font for this component.
+ *
+ * @see #getFont()
+ * @see #setFont(java.awt.Font)
+ * @serial the component's font.
+ */
+ private Font font;
+
+ /**
+ * The name of the component.
+ *
+ * @see #getName()
+ * @see #setName(String)
+ * @serial the component's name.
+ */
+ private String name;
+
+ /**
+ * The parent of this component.
+ *
+ * @see #getParent()
+ * @see #setParent(java.awt.MenuContainer)
+ * @serial ignored.
+ */
+ transient MenuContainer parent;
-// The font for this component
-private Font font;
+ /**
+ * The native peer for this component.
+ *
+ * @see #getPeer()
+ * @see #setPeer(java.awt.peer.MenuComponentPeer)
+ * @serial ignored.
+ */
+ transient MenuComponentPeer peer;
-// The name of the component
-private String name;
+ /**
+ * The synchronization locking object for this component.
+ *
+ * @serial ignored.
+ */
+ private transient Object tree_lock = this;
-// The parent of this component
-transient MenuContainer parent;
+ /**
+ * The toolkit for this object.
+ *
+ * @see #getToolkit()
+ * @serial ignored.
+ */
+ private static transient Toolkit toolkit = Toolkit.getDefaultToolkit();
-// The native peer for this componet
-transient MenuComponentPeer peer;
+ /**
+ * The accessible context for this component.
+ *
+ * @see #getAccessibleContext()
+ * @serial the accessibility information for this component.
+ */
+ private AccessibleContext accessibleContext;
-// The synchronization locking object for this component
-private transient Object tree_lock = this;
+ /**
+ * Was the name of the component set? This value defaults
+ * to false and becomes true after a call to <code>setName()</code>.
+ * Please note that this does not guarantee that name will then
+ * be non-null, as this may be the value passed to <code>setName()</code>.
+ *
+ * @see #setName(String)
+ * @serial true if the name value has been explicitly set by calling
+ * <code>setName()</code>.
+ */
+ private boolean nameExplicitlySet;
-// The toolkit for this object
-private static transient Toolkit toolkit = Toolkit.getDefaultToolkit();
+ /**
+ * Does this component handle new events? Events will be handled
+ * by this component if this is true. Otherwise, they will be forwarded
+ * up the component hierarchy. This implementation does not use this
+ * variable; it is merely provided for serialization compatability.
+ *
+ * @see #dispatchEvent(AWTEvent)
+ * @serial true if events are to be processed locally. Unused.
+ */
+ private boolean newEventsOnly;
+
+ /**
+ * The focus listener chain handler which deals with focus events for
+ * the accessible context of this component.
+ *
+ * @see AccessibleAWTMenuComponent#addFocusListener(java.awt.event.FocusListener)
+ * @serial ignored.
+ */
+ private transient FocusListener focusListener;
/*************************************************************************/
@@ -117,7 +196,13 @@ MenuComponent()
public Font
getFont()
{
- return(font);
+ if (font != null)
+ return font;
+
+ if (parent != null)
+ return parent.getFont ();
+
+ return null;
}
/*************************************************************************/
@@ -157,6 +242,7 @@ public void
setName(String name)
{
this.name = name;
+ nameExplicitlySet = true;
}
/*************************************************************************/
@@ -260,13 +346,14 @@ setTreeLock(Object tree_lock)
* AWT 1.0 event dispatcher.
*
* @deprecated Deprecated in favor of <code>dispatchEvent()</code>.
+ * @return true if the event was dispatched, false otherwise.
*/
public boolean
postEvent(Event event)
{
- return(false);
+ // This is overridden by subclasses that support events.
+ return false;
}
-
/*************************************************************************/
/**
@@ -274,17 +361,35 @@ postEvent(Event event)
*
* @param event The event to dispatch
*/
-public final void
-dispatchEvent(AWTEvent event)
+public final void dispatchEvent(AWTEvent event)
{
// See comment in Component.dispatchEvent().
dispatchEventImpl(event);
}
-void
-dispatchEventImpl(AWTEvent e)
+
+/**
+ * Implementation of dispatchEvent. Allows trusted package classes
+ * to dispatch additional events first. This implementation first
+ * translates <code>event</code> 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);
}
/*************************************************************************/
@@ -298,6 +403,25 @@ dispatchEventImpl(AWTEvent e)
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;
+ }
+ }
+ }
}
/*************************************************************************/
@@ -316,15 +440,884 @@ toString()
/*************************************************************************/
/**
- * Returns a debugging string for this component
- */
+ * Returns a debugging string for this component
+ */
protected String
paramString()
{
return "name=" + getName();
}
-// Accessibility API not yet implemented.
-// public AccessibleContext getAccessibleContext()
+/**
+ * Gets the AccessibleContext associated with this <code>MenuComponent</code>.
+ * As an abstract class, we return null. Concrete subclasses should return
+ * their implementation of the accessibility context.
+ *
+ * @return null.
+ */
+
+public AccessibleContext getAccessibleContext()
+{
+ return null;
+}
+
+/**
+ * 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
+{
+
+ /**
+ * 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()
+ {
+ }
+
+ /**
+ * Replaces or supplements the component's selection with the
+ * <code>Accessible</code> 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.
+ * <br />
+ * <br />
+ * 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 */
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * Clears the component's current selection. Following
+ * the calling of this method, no children of the component
+ * will be selected.
+ * <br />
+ * <br />
+ * 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.
+ * <br />
+ * <br />
+ * Please note that this method depends on a correctly implemented
+ * version of the <code>getBounds()</code> method. Subclasses
+ * must provide the bounding rectangle via <code>getBounds()</code>
+ * 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 <code>Accessible</code> 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.
+ * <br />
+ * <br />
+ * 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 the <code>Accessible</code> child at the supplied
+ * index within the list of children of this component.
+ * <br />
+ * <br />
+ * 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 <code>Accessible</code> child
+ * to retrieve.
+ * @return null.
+ */
+ public Accessible getAccessibleChild(int index)
+ {
+ return null;
+ }
+
+ /**
+ * Returns the number of children of this component which
+ * implement the <code>Accessible</code> interface. If
+ * all children of this component are accessible, then
+ * the returned value will be the same as the number of
+ * children.
+ * <br />
+ * <br />
+ *
+ * @return 0.
+ */
+ public int getAccessibleChildrenCount()
+ {
+ return 0;
+ }
+
+ /**
+ * Retrieves the <code>AccessibleComponent</code> associated
+ * with this accessible context and its component. As the
+ * context itself implements <code>AccessibleComponent</code>,
+ * this is the return value.
+ *
+ * @return the context itself.
+ */
+ public AccessibleComponent getAccessibleComponent()
+ {
+ return this;
+ }
+
+ /**
+ * Returns the accessible name for this menu component. This
+ * is the name given to the component, which may be null if
+ * not set using <code>setName()</code>.
+ * <br />
+ * <br />
+ * 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();
+ }
+
+ /**
+ * Retrieves the index of this component within its parent.
+ * If no parent exists, -1 is returned.
+ *
+ * @return -1 as the parent, a <code>MenuContainer</code>
+ * is not <code>Accessible</code>.
+ */
+ public int getAccessibleIndexInParent()
+ {
+ return -1;
+ }
+
+ /**
+ * Returns the accessible name of this component. This
+ * is the name given to the component, which may be null if
+ * not set using <code>setName()</code>.
+ * <br />
+ * <br />
+ * 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();
+ }
+
+ /**
+ * Returns the <code>Accessible</code> parent of this component.
+ * As the parent of a <code>MenuComponent</code> is a
+ * <code>MenuContainer</code>, which doesn't implement
+ * <code>Accessible</code>, this method returns null.
+ *
+ * @return null.
+ */
+ public Accessible getAccessibleParent()
+ {
+ return null;
+ }
+
+ /**
+ * Returns the accessible role of this component.
+ * <br />
+ * <br />
+ * The abstract implementation of this method returns
+ * <code>AccessibleRole.AWT_COMPONENT</code>,
+ * 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 <code>AccessibleRole.AWT_COMPONENT</code>.
+ */
+ public AccessibleRole getAccessibleRole()
+ {
+ return AccessibleRole.AWT_COMPONENT;
+ }
+
+ /**
+ * Retrieves the <code>AccessibleSelection</code> associated
+ * with this accessible context and its component. As the
+ * context itself implements <code>AccessibleSelection</code>,
+ * this is the return value.
+ *
+ * @return the context itself.
+ */
+ public AccessibleSelection getAccessibleSelection()
+ {
+ return this;
+ }
+
+ /**
+ * Retrieves the <code>Accessible</code> 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 <strong>selected
+ * children</strong>, and not the index of the child in
+ * the list of all <code>Accessible</code> children.
+ * <br />
+ * <br />
+ * 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 <code>Accessible</code>
+ * child.
+ */
+ public Accessible getAccessibleSelection(int index)
+ {
+ return null;
+ }
+
+ /**
+ * Returns a count of the number of <code>Accessible</code>
+ * children of this component which are currently selected.
+ * If there are no children currently selected, 0 is returned.
+ * <br />
+ * <br />
+ * 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;
+ }
+
+ /**
+ * Retrieves the current state of this component
+ * in an accessible form. For example, a given component
+ * may be visible, selected, disabled, etc.
+ * <br />
+ * <br />
+ * 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
+ * <code>PropertyChangeListener</code>s.
+ *
+ * @return an empty <code>AccessibleStateSet</code>.
+ */
+ public AccessibleStateSet getAccessibleStateSet()
+ {
+ return new AccessibleStateSet();
+ }
+
+ /**
+ * Returns the background color of the component, or null
+ * if this property is unsupported.
+ * <br />
+ * <br />
+ * 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;
+ }
+
+ /**
+ * Returns a <code>Rectangle</code> 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
+ * <code>MenuContainer</code>. null is returned if bounds
+ * are not supported by the component.
+ * <br />
+ * <br />
+ * 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;
+ }
+
+ /**
+ * Returns the <code>Cursor</code> displayed when the pointer
+ * is positioned over this component. Alternatively, null
+ * is returned if the component doesn't support the cursor
+ * property.
+ * <br />
+ * <br />
+ * 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();
+ }
+
+ /**
+ * Returns the <code>Font</code> used for text created by this component.
+ *
+ * @return the current font.
+ * @see #setFont(java.awt.Font)
+ */
+ public Font getFont()
+ {
+ return MenuComponent.this.getFont();
+ }
+
+ /**
+ * Retrieves information on the rendering and metrics of the supplied
+ * font. If font metrics are not supported by this component, null
+ * is returned.
+ * <br />
+ * <br />
+ * The abstract implementation of this method simply uses the toolkit
+ * to obtain the <code>FontMetrics</code>. 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);
+ }
+
+ /**
+ * Returns the foreground color of the component, or null
+ * if this property is unsupported.
+ * <br />
+ * <br />
+ * 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;
+ }
+
+ /**
+ * Returns the locale currently in use by this component.
+ * <br />
+ * <br />
+ * 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.
+ * <br />
+ * <br />
+ * Please note that this method depends on a correctly implemented
+ * version of the <code>getBounds()</code> method. Subclasses
+ * must provide the bounding rectangle via <code>getBounds()</code>
+ * 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.
+ * <br />
+ * <br />
+ * 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.
+ * <br />
+ * <br />
+ * Please note that this method depends on a correctly implemented
+ * version of the <code>getBounds()</code> method. Subclasses
+ * must provide the bounding rectangle via <code>getBounds()</code>
+ * 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.
+ * <br />
+ * <br />
+ * 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.
+ * <br />
+ * <br />
+ * 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 true if this component is included in the traversal
+ * of the current focus from one component to the other.
+ * <br />
+ * <br />
+ * 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.
+ * <br />
+ * <br />
+ * 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, <code>isShowing()</code> should be
+ * used.
+ * <br />
+ * <br />
+ * 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.
+ * <br />
+ * <br />
+ * 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 <code>Accessible</code> 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.
+ * <br />
+ * <br />
+ * 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 <code>Accessible</code> children of this component which
+ * it is possible to select. The component needs to support multiple
+ * selections.
+ * <br />
+ * <br />
+ * This abstract component provides a simplistic implementation of this
+ * method, which ignores the ability of the component to support multiple
+ * selections and simply uses <code>addAccessibleSelection</code> to
+ * add each <code>Accessible</code> child to the selection. The last
+ * <code>Accessible</code> 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.
+ * <br />
+ * <br />
+ * 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.
+ * <br />
+ * <br />
+ * 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 <code>getBounds()</code>.
+ * 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 <code>Cursor</code> used when the pointer is positioned over the
+ * component. Unspecified behaviour occurs when null is given as the new
+ * cursor.
+ * <br />
+ * <br />
+ * 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.
+ * <br />
+ * <br />
+ * 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 #getEnabled()
+ */
+ public void setEnabled(boolean enabled)
+ {
+ /* Ignored */
+ }
+
+ /**
+ * Sets the <code>Font</code> 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.
+ * <br />
+ * <br />
+ * 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.
+ * <br />
+ * <br />
+ * Please note that this method depends on a correctly implemented
+ * version of the <code>getBounds()</code> method. Subclasses
+ * must provide the bounding rectangle via <code>getBounds()</code>
+ * 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.
+ * <br />
+ * <br />
+ * Please note that this method depends on a correctly implemented
+ * version of the <code>getBounds()</code> method. Subclasses
+ * must provide the bounding rectangle via <code>getBounds()</code>
+ * 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, <code>isShowing()</code> should be
+ * used.
+ * <br />
+ * <br />
+ * 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 */
+ }
+
+} /* class AccessibleAWTMenuComponent */
+
-} // class Component
+} // class MenuComponent
diff --git a/java/awt/MenuItem.java b/java/awt/MenuItem.java
index 8511f698f..66c0a5f3a 100644
--- a/java/awt/MenuItem.java
+++ b/java/awt/MenuItem.java
@@ -54,8 +54,6 @@ public class MenuItem extends MenuComponent
implements Serializable
{
-// FIXME: The enabled event mask is not used at this time.
-
/*
* Static Variables
*/
@@ -77,7 +75,7 @@ private String actionCommand;
/**
* @serial Indicates whether or not this menu item is enabled.
*/
-private boolean enabled;
+private boolean enabled = true;
/**
* @serial The mask of events that are enabled for this menu item.
diff --git a/java/awt/Panel.java b/java/awt/Panel.java
index dbe322896..1795540ea 100644
--- a/java/awt/Panel.java
+++ b/java/awt/Panel.java
@@ -1,5 +1,5 @@
/* Panel.java -- Simple container object
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,7 +38,6 @@ exception statement from your version. */
package java.awt;
-import java.awt.event.PaintEvent;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
@@ -47,8 +46,8 @@ import javax.accessibility.AccessibleRole;
* A panel is a simple container class. It's default layout is the
* <code>FlowLayout</code> manager.
*
- * @author Aaron M. Renn <arenn@urbanophile.com>
- * @author Eric Blake <ebb9@email.byu.edu>
+ * @author Aaron M. Renn (arenn@urbanophile.com)
+ * @author Eric Blake (ebb9@email.byu.edu)
* @see FlowLayout
* @since 1.0
* @status updated to 1.4
@@ -98,36 +97,6 @@ public class Panel extends Container implements Accessible
}
/**
- * Consume initial application-requested paint event if it has not
- * already been consumed, and if the initial system-requested paint
- * event has not already been handled. Otherwise, call
- * super.dispatchEventImpl. These extra steps are required to
- * prevent a Panel from being painted twice when it is initially
- * shown.
- *
- * @param e the event to dispatch
- */
- void dispatchEventImpl (AWTEvent e)
- {
- if (e instanceof PaintEvent)
- {
- if (e.id == PaintEvent.UPDATE)
- {
- if (!initialUpdateConsumed
- && !initialSystemUpdateDone)
- {
- e.consume ();
- initialUpdateConsumed = true;
- }
- }
- else if (e.id == PaintEvent.PAINT)
- initialSystemUpdateDone = true;
- }
- else
- super.dispatchEventImpl (e);
- }
-
- /**
* Notifies this object to create its native peer.
*
* @see #isDisplayable()
diff --git a/java/awt/Point.java b/java/awt/Point.java
index 9d5126434..3731b4134 100644
--- a/java/awt/Point.java
+++ b/java/awt/Point.java
@@ -95,7 +95,7 @@ public class Point extends Point2D implements Serializable
* Initializes a new instance of <code>Point</code> with coordinates
* identical to the coordinates of the specified points.
*
- * @param point the point to copy the coordinates from
+ * @param p the point to copy the coordinates from
* @throws NullPointerException if p is null
*/
public Point(Point p)
diff --git a/java/awt/Polygon.java b/java/awt/Polygon.java
index 96c370aaf..36739e306 100644
--- a/java/awt/Polygon.java
+++ b/java/awt/Polygon.java
@@ -684,7 +684,7 @@ public class Polygon implements Shape, Serializable
* path iterator is not either.
*
* @param transform an optional transform to apply to the iterator
- * @param double the maximum distance for deviation from the real boundary
+ * @param flatness the maximum distance for deviation from the real boundary
* @return a new iterator over the boundary
* @since 1.2
*/
diff --git a/java/awt/PopupMenu.java b/java/awt/PopupMenu.java
index 83ffb35a8..fd953c328 100644
--- a/java/awt/PopupMenu.java
+++ b/java/awt/PopupMenu.java
@@ -1,5 +1,5 @@
/* PopupMenu.java -- An AWT popup menu
- Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,7 +38,6 @@ exception statement from your version. */
package java.awt;
-import java.awt.peer.MenuPeer;
import java.awt.peer.PopupMenuPeer;
/**
diff --git a/java/awt/Rectangle.java b/java/awt/Rectangle.java
index 5dc54116f..66190960a 100644
--- a/java/awt/Rectangle.java
+++ b/java/awt/Rectangle.java
@@ -338,7 +338,7 @@ public class Rectangle extends Rectangle2D implements Shape, Serializable
* its upper left corner.
*
* @return the point where this rectangle is located
- * @see setLocation(Point)
+ * @see #setLocation(Point)
* @since 1.1
*/
public Point getLocation()
diff --git a/java/awt/ScrollPane.java b/java/awt/ScrollPane.java
index 457df0c0e..abd5514d8 100644
--- a/java/awt/ScrollPane.java
+++ b/java/awt/ScrollPane.java
@@ -1,5 +1,5 @@
/* ScrollPane.java -- Scrolling window
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -41,6 +41,7 @@ package java.awt;
import java.awt.event.MouseEvent;
import java.awt.peer.ComponentPeer;
import java.awt.peer.ScrollPanePeer;
+
import javax.accessibility.Accessible;
/**
diff --git a/java/awt/Scrollbar.java b/java/awt/Scrollbar.java
index a01dc3ccd..d09a1682a 100644
--- a/java/awt/Scrollbar.java
+++ b/java/awt/Scrollbar.java
@@ -1,5 +1,6 @@
/* Scrollbar.java -- AWT Scrollbar widget
- Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,10 +39,11 @@ exception statement from your version. */
package java.awt;
-import java.awt.event.AdjustmentListener;
import java.awt.event.AdjustmentEvent;
+import java.awt.event.AdjustmentListener;
import java.awt.peer.ScrollbarPeer;
import java.util.EventListener;
+
import javax.accessibility.Accessible;
/**
diff --git a/java/awt/Shape.java b/java/awt/Shape.java
index 8d61c4a9a..47c97192a 100644
--- a/java/awt/Shape.java
+++ b/java/awt/Shape.java
@@ -57,8 +57,8 @@ import java.awt.geom.Rectangle2D;
* @author Aaron M. Renn <arenn@urbanophile.com>
* @see PathIterator
* @see AffineTransform
- * @see FlatteningPathIterator
- * @see GeneralPath
+ * @see java.awt.geom.FlatteningPathIterator
+ * @see java.awt.geom.GeneralPath
* @since 1.0
* @status updated to 1.4
*/
@@ -109,15 +109,15 @@ public interface Shape
* Test if a high-precision rectangle intersects the shape. This is true
* if any point in the rectangle is in the shape, with the caveat that the
* operation may include high probability estimates when the actual
- * calculation is prohibitively expensive. The {@link Area} class can
- * be used for more precise answers.
+ * calculation is prohibitively expensive. The {@link java.awt.geom.Area}
+ * class can be used for more precise answers.
*
* @param x the x coordinate of the rectangle
* @param y the y coordinate of the rectangle
* @param w the width of the rectangle, undefined results if negative
* @param h the height of the rectangle, undefined results if negative
* @return true if the rectangle intersects this shape
- * @see Area
+ * @see java.awt.geom.Area
* @since 1.2
*/
boolean intersects(double x, double y, double w, double h);
@@ -126,8 +126,8 @@ public interface Shape
* Test if a high-precision rectangle intersects the shape. This is true
* if any point in the rectangle is in the shape, with the caveat that the
* operation may include high probability estimates when the actual
- * calculation is prohibitively expensive. The {@link Area} class can
- * be used for more precise answers.
+ * calculation is prohibitively expensive. The {@link java.awt.geom.Area}
+ * class can be used for more precise answers.
*
* @param r the rectangle
* @return true if the rectangle intersects this shape
@@ -141,15 +141,15 @@ public interface Shape
* Test if a high-precision rectangle lies completely in the shape. This is
* true if all points in the rectangle are in the shape, with the caveat
* that the operation may include high probability estimates when the actual
- * calculation is prohibitively expensive. The {@link Area} class can
- * be used for more precise answers.
+ * calculation is prohibitively expensive. The {@link java.awt.geom.Area}
+ * class can be used for more precise answers.
*
* @param x the x coordinate of the rectangle
* @param y the y coordinate of the rectangle
* @param w the width of the rectangle, undefined results if negative
* @param h the height of the rectangle, undefined results if negative
* @return true if the rectangle is contained in this shape
- * @see Area
+ * @see java.awt.geom.Area
* @since 1.2
*/
boolean contains(double x, double y, double w, double h);
@@ -158,8 +158,8 @@ public interface Shape
* Test if a high-precision rectangle lies completely in the shape. This is
* true if all points in the rectangle are in the shape, with the caveat
* that the operation may include high probability estimates when the actual
- * calculation is prohibitively expensive. The {@link Area} class can
- * be used for more precise answers.
+ * calculation is prohibitively expensive. The {@link java.awt.geom.Area}
+ * class can be used for more precise answers.
*
* @param r the rectangle
* @return true if the rectangle is contained in this shape
@@ -195,7 +195,7 @@ public interface Shape
* iterations from future changes to the boundary, and document this fact.
*
* @param transform an optional transform to apply to the iterator
- * @param double the maximum distance for deviation from the real boundary
+ * @param flatness the maximum distance for deviation from the real boundary
* @return a new iterator over the boundary
* @since 1.2
*/
diff --git a/java/awt/SystemColor.java b/java/awt/SystemColor.java
index 5217677b7..3428fba3c 100644
--- a/java/awt/SystemColor.java
+++ b/java/awt/SystemColor.java
@@ -1,5 +1,5 @@
/* SystemColor.java -- access dynamic system color values
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,9 +38,9 @@ exception statement from your version. */
package java.awt;
-import java.awt.image.ColorModel;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
+import java.awt.image.ColorModel;
import java.io.Serializable;
/**
@@ -72,7 +72,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the desktop color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #desktop
*/
@@ -80,7 +80,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the active caption color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #activeCaption
*/
@@ -88,7 +88,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the active caption text color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #activeCaptionText
*/
@@ -96,7 +96,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the active caption border color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #activeCaptionBorder
*/
@@ -104,7 +104,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the inactive caption color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #inactiveCaption
*/
@@ -112,7 +112,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the inactive caption text color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #inactiveCaptionText
*/
@@ -120,7 +120,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the inactive caption border color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #inactiveCaptionBorder
*/
@@ -128,7 +128,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the window background color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #window
*/
@@ -136,7 +136,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the window border color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #windowBorder
*/
@@ -144,7 +144,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the window text color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #windowText
*/
@@ -152,7 +152,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the menu background color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #menu
*/
@@ -160,7 +160,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the menu text color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #menuText
*/
@@ -168,7 +168,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the text background color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #text
*/
@@ -176,7 +176,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the text foreground color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #textText
*/
@@ -184,7 +184,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the highlighted text background color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #textHighlight
*/
@@ -192,7 +192,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the highlighted text foreground color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #textHighlightText
*/
@@ -200,7 +200,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the inactive text foreground color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #textInactiveText
*/
@@ -208,7 +208,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the control background color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #control
*/
@@ -216,7 +216,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the control text color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #controlText
*/
@@ -224,7 +224,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the highlighted control background color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #controlHighlight
*/
@@ -232,7 +232,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the lightly highlighted control background color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #controlLtHighlight
*/
@@ -240,7 +240,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the shadowed control background color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #controlShadow
*/
@@ -248,7 +248,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the darkly shadowed control background color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #controlDkShadow
*/
@@ -256,7 +256,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the scrollbar background color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #scrollbar
*/
@@ -264,7 +264,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the info background color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #info
*/
@@ -272,7 +272,7 @@ public final class SystemColor extends Color implements Serializable
/**
* Array index of the info text color. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*
* @see #infoText
*/
@@ -280,7 +280,7 @@ public final class SystemColor extends Color implements Serializable
/**
* The number of system colors. Used by
- * {@link Toolkit#loadSystemColors()}.
+ * {@link Toolkit#loadSystemColors(int[])}.
*/
public static final int NUM_COLORS = 26;
diff --git a/java/awt/TextArea.java b/java/awt/TextArea.java
index 6355376df..ad246dede 100644
--- a/java/awt/TextArea.java
+++ b/java/awt/TextArea.java
@@ -1,45 +1,46 @@
/* TextArea.java -- A multi-line text entry component
Copyright (C) 1999, 2004 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., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 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. */
+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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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 java.awt.event.KeyEvent;
import java.awt.peer.ComponentPeer;
import java.awt.peer.TextAreaPeer;
-import java.awt.event.KeyEvent;
import java.util.HashSet;
import java.util.Set;
diff --git a/java/awt/TextField.java b/java/awt/TextField.java
index 1a783e27a..65a4790a9 100644
--- a/java/awt/TextField.java
+++ b/java/awt/TextField.java
@@ -1,5 +1,5 @@
/* TextField.java -- A one line text entry field
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -40,8 +40,8 @@ package java.awt;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.awt.peer.TextFieldPeer;
import java.awt.peer.ComponentPeer;
+import java.awt.peer.TextFieldPeer;
import java.util.EventListener;
/**
diff --git a/java/awt/Toolkit.java b/java/awt/Toolkit.java
index 2ee3f5089..b125263eb 100644
--- a/java/awt/Toolkit.java
+++ b/java/awt/Toolkit.java
@@ -53,8 +53,8 @@ import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.awt.peer.ButtonPeer;
import java.awt.peer.CanvasPeer;
-import java.awt.peer.CheckboxPeer;
import java.awt.peer.CheckboxMenuItemPeer;
+import java.awt.peer.CheckboxPeer;
import java.awt.peer.ChoicePeer;
import java.awt.peer.DialogPeer;
import java.awt.peer.FileDialogPeer;
@@ -63,13 +63,13 @@ import java.awt.peer.FramePeer;
import java.awt.peer.LabelPeer;
import java.awt.peer.LightweightPeer;
import java.awt.peer.ListPeer;
-import java.awt.peer.MenuPeer;
import java.awt.peer.MenuBarPeer;
import java.awt.peer.MenuItemPeer;
+import java.awt.peer.MenuPeer;
import java.awt.peer.PanelPeer;
import java.awt.peer.PopupMenuPeer;
-import java.awt.peer.ScrollbarPeer;
import java.awt.peer.ScrollPanePeer;
+import java.awt.peer.ScrollbarPeer;
import java.awt.peer.TextAreaPeer;
import java.awt.peer.TextFieldPeer;
import java.awt.peer.WindowPeer;
diff --git a/java/awt/Window.java b/java/awt/Window.java
index 7397a1c1c..b265da25e 100644
--- a/java/awt/Window.java
+++ b/java/awt/Window.java
@@ -1,5 +1,5 @@
/* Window.java --
- Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation
+ Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -48,11 +48,12 @@ import java.awt.event.WindowStateListener;
import java.awt.peer.WindowPeer;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
-import java.util.Iterator;
import java.util.EventListener;
+import java.util.Iterator;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Vector;
+
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
@@ -291,7 +292,7 @@ public class Window extends Container implements Accessible
initialFocusOwner = policy.getInitialComponent (this);
if (initialFocusOwner != null)
- initialFocusOwner.requestFocusInWindow (false);
+ initialFocusOwner.requestFocusInWindow ();
shown = true;
}
diff --git a/java/awt/color/ICC_Profile.java b/java/awt/color/ICC_Profile.java
index eb534ebff..b9ea5ed9f 100644
--- a/java/awt/color/ICC_Profile.java
+++ b/java/awt/color/ICC_Profile.java
@@ -40,8 +40,8 @@ package java.awt.color;
import java.io.FileInputStream;
import java.io.FileOutputStream;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamException;
diff --git a/java/awt/datatransfer/Clipboard.java b/java/awt/datatransfer/Clipboard.java
index 93bba7c1a..ca9b6ebdb 100644
--- a/java/awt/datatransfer/Clipboard.java
+++ b/java/awt/datatransfer/Clipboard.java
@@ -39,102 +39,76 @@ exception statement from your version. */
package java.awt.datatransfer;
/**
- * This class allows data to be transferred using a cut and paste type
- * mechanism.
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- */
-public class Clipboard
-{
-
-/*
- * Instance Variables
- */
-
-/**
- * The data being transferred.
- */
-protected Transferable contents;
-
-/**
- * The owner of this clipboard.
- */
-protected ClipboardOwner owner;
-
-// The clipboard name
-private String name;
-
-/*************************************************************************/
-
-/*
- * Constructors
- */
-
-/**
- * Initializes a new instance of <code>Clipboard</code> with the
- * specified name.
- *
- * @param name The clipboard name.
- */
-public
-Clipboard(String name)
-{
- this.name = name;
-}
-
-/*************************************************************************/
-
-/*
- * Instance Methods
+ * This class allows data to be transferred using a cut and paste type
+ * mechanism.
+ *
+ * @author Aaron M. Renn (arenn@urbanophile.com)
*/
-
-/**
- * Returns the name of the clipboard.
- */
-public String
-getName()
-{
- return(name);
-}
-
-/*************************************************************************/
-
-/**
- * Returns the contents of the clipboard.
- *
- * @param requestor The object requesting the contents.
- *
- * @exception IllegalStateException If the clipboard is currently unavailable
- */
-public synchronized Transferable
-getContents(Object requestor)
-{
- return(contents);
-}
-
-/*************************************************************************/
-
-/**
- * Sets the content and owner of this clipboard.
- * If the given owner is different from the current owner
- * then lostOwnership is called on the current owner.
- * XXX - is this called with the old or new contents.
- *
- * @param contents The new clipboard contents.
- * @param owner The new clipboard owner
- *
- * @exception IllegalStateException If the clipboard is currently unavailable
- */
-public synchronized void
-setContents(Transferable contents, ClipboardOwner owner)
+public class Clipboard
{
- if (this.owner != owner)
- if (this.owner != null)
- this.owner.lostOwnership(this, contents);
+ /**
+ * The data being transferred.
+ */
+ protected Transferable contents;
+
+ /**
+ * The owner of this clipboard.
+ */
+ protected ClipboardOwner owner;
+
+ // The clipboard name
+ private String name;
+
+ /**
+ * Initializes a new instance of <code>Clipboard</code> with the
+ * specified name.
+ *
+ * @param name The clipboard name.
+ */
+ public Clipboard(String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Returns the name of the clipboard.
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Returns the contents of the clipboard.
+ *
+ * @param requestor The object requesting the contents.
+ *
+ * @exception IllegalStateException If the clipboard is currently unavailable
+ */
+ public synchronized Transferable getContents(Object requestor)
+ {
+ return contents;
+ }
+
+ /**
+ * Sets the content and owner of this clipboard.
+ * If the given owner is different from the current owner
+ * then lostOwnership is called on the current owner.
+ * XXX - is this called with the old or new contents.
+ *
+ * @param contents The new clipboard contents.
+ * @param owner The new clipboard owner
+ *
+ * @exception IllegalStateException If the clipboard is currently unavailable
+ */
+ public synchronized void setContents(Transferable contents, ClipboardOwner owner)
+ {
+ if (this.owner != owner)
+ if (this.owner != null)
+ this.owner.lostOwnership(this, contents);
- this.owner = owner;
- this.contents = contents;
+ this.owner = owner;
+ this.contents = contents;
+ }
}
-} // class Clipboard
-
diff --git a/java/awt/datatransfer/ClipboardOwner.java b/java/awt/datatransfer/ClipboardOwner.java
index 28e58aae1..b5ca9e37d 100644
--- a/java/awt/datatransfer/ClipboardOwner.java
+++ b/java/awt/datatransfer/ClipboardOwner.java
@@ -53,6 +53,5 @@ public interface ClipboardOwner
* @param contents The contents of the clipboard which are no longer owned.
*/
void lostOwnership (Clipboard clipboard, Transferable contents);
-
-} // interface ClipboardOwner
+}
diff --git a/java/awt/datatransfer/DataFlavor.java b/java/awt/datatransfer/DataFlavor.java
index 3ec219119..7a9eb7169 100644
--- a/java/awt/datatransfer/DataFlavor.java
+++ b/java/awt/datatransfer/DataFlavor.java
@@ -39,11 +39,11 @@ exception statement from your version. */
package java.awt.datatransfer;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.io.IOException;
-import java.io.ObjectOutput;
import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.io.Reader;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
diff --git a/java/awt/datatransfer/StringSelection.java b/java/awt/datatransfer/StringSelection.java
index 51addb729..7d27db034 100644
--- a/java/awt/datatransfer/StringSelection.java
+++ b/java/awt/datatransfer/StringSelection.java
@@ -1,5 +1,5 @@
/* StringSelection.java -- Clipboard handler for text.
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,8 +38,8 @@ exception statement from your version. */
package java.awt.datatransfer;
-import java.io.StringReader;
import java.io.IOException;
+import java.io.StringReader;
/**
* This class transfers a string as plain text using the clipboard.
diff --git a/java/awt/datatransfer/SystemFlavorMap.java b/java/awt/datatransfer/SystemFlavorMap.java
index 7d914120e..826992b7c 100644
--- a/java/awt/datatransfer/SystemFlavorMap.java
+++ b/java/awt/datatransfer/SystemFlavorMap.java
@@ -1,5 +1,5 @@
/* SystemFlavorMap.java -- Maps between native flavor names and MIME types.
- Copyright (C) 2001 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,8 +39,8 @@ exception statement from your version. */
package java.awt.datatransfer;
import java.util.HashMap;
-import java.util.Map;
import java.util.List;
+import java.util.Map;
/**
* This class maps between native platform type names and DataFlavors.
diff --git a/java/awt/dnd/Autoscroll.java b/java/awt/dnd/Autoscroll.java
index 5c5233874..ae868c077 100644
--- a/java/awt/dnd/Autoscroll.java
+++ b/java/awt/dnd/Autoscroll.java
@@ -1,5 +1,5 @@
/* Autoscroll.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,10 +35,11 @@ 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.dnd;
-import java.awt.Point;
import java.awt.Insets;
+import java.awt.Point;
/**
* During DnD operations it is possible that a user may wish to drop the
diff --git a/java/awt/dnd/DropTarget.java b/java/awt/dnd/DropTarget.java
index 4063e206a..7379ca71c 100644
--- a/java/awt/dnd/DropTarget.java
+++ b/java/awt/dnd/DropTarget.java
@@ -1,5 +1,5 @@
/* DropTarget.java --
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,12 +35,13 @@ 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.dnd;
-import java.awt.Point;
import java.awt.Component;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
+import java.awt.Point;
import java.awt.datatransfer.FlavorMap;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
diff --git a/java/awt/dnd/DropTargetContext.java b/java/awt/dnd/DropTargetContext.java
index 7bf77ffe6..7e78869ac 100644
--- a/java/awt/dnd/DropTargetContext.java
+++ b/java/awt/dnd/DropTargetContext.java
@@ -1,5 +1,5 @@
/* DropTargetContext.java --
- Copyright (C) 2002, 2003, 2005 Free Software Foundation
+ Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,12 +37,12 @@ exception statement from your version. */
package java.awt.dnd;
-import java.io.Serializable;
-import java.io.IOException;
import java.awt.Component;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.IOException;
+import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
diff --git a/java/awt/dnd/DropTargetDragEvent.java b/java/awt/dnd/DropTargetDragEvent.java
index e95b2d1ae..d4a13ea46 100644
--- a/java/awt/dnd/DropTargetDragEvent.java
+++ b/java/awt/dnd/DropTargetDragEvent.java
@@ -1,5 +1,5 @@
/* DropTargetDragEvent.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,11 +35,12 @@ 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.dnd;
-import java.util.List;
import java.awt.Point;
import java.awt.datatransfer.DataFlavor;
+import java.util.List;
/**
* @since 1.2
diff --git a/java/awt/dnd/package.html b/java/awt/dnd/package.html
index 52a36c43e..4b2341331 100644
--- a/java/awt/dnd/package.html
+++ b/java/awt/dnd/package.html
@@ -1,6 +1,6 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!-- package.html - describes classes in java.awt.dnd package.
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -40,7 +40,7 @@ exception statement from your version. -->
<head><title>GNU Classpath - java.awt.dnd</title></head>
<body>
-<p>Events and listerners for drag and drop sources and targets.</p>
+<p>Events and listeners for drag and drop sources and targets.</p>
</body>
</html>
diff --git a/java/awt/dnd/peer/DropTargetContextPeer.java b/java/awt/dnd/peer/DropTargetContextPeer.java
index 239a43778..a2e3ba218 100644
--- a/java/awt/dnd/peer/DropTargetContextPeer.java
+++ b/java/awt/dnd/peer/DropTargetContextPeer.java
@@ -1,5 +1,5 @@
/* DropTargetContextPeer.java -- interface for drag-and-drop peers
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,11 +35,12 @@ 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.dnd.peer;
-import java.awt.dnd.DropTarget;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
+import java.awt.dnd.DropTarget;
import java.awt.dnd.InvalidDnDOperationException;
diff --git a/java/awt/event/AdjustmentEvent.java b/java/awt/event/AdjustmentEvent.java
index 48b208b5d..623dab5ea 100644
--- a/java/awt/event/AdjustmentEvent.java
+++ b/java/awt/event/AdjustmentEvent.java
@@ -1,5 +1,5 @@
/* AdjustmentEvent.java -- an adjustable value was changed
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,8 +38,8 @@ exception statement from your version. */
package java.awt.event;
-import java.awt.Adjustable;
import java.awt.AWTEvent;
+import java.awt.Adjustable;
/**
* This class represents an event that is generated when an adjustable
diff --git a/java/awt/event/InputEvent.java b/java/awt/event/InputEvent.java
index 1689e5114..169982cd2 100644
--- a/java/awt/event/InputEvent.java
+++ b/java/awt/event/InputEvent.java
@@ -1,5 +1,5 @@
/* InputEvent.java -- common superclass of component input events
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,9 +38,10 @@ exception statement from your version. */
package java.awt.event;
-import java.awt.Component;
import gnu.java.awt.EventModifier;
+import java.awt.Component;
+
/**
* This is the common superclass for all component input classes. These are
* passed to listeners before the component, so that listeners can consume
diff --git a/java/awt/event/InvocationEvent.java b/java/awt/event/InvocationEvent.java
index 76d4a5582..fb58595c7 100644
--- a/java/awt/event/InvocationEvent.java
+++ b/java/awt/event/InvocationEvent.java
@@ -1,5 +1,5 @@
/* InvocationEvent.java -- call a runnable when dispatched
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,8 +38,8 @@ exception statement from your version. */
package java.awt.event;
-import java.awt.ActiveEvent;
import java.awt.AWTEvent;
+import java.awt.ActiveEvent;
import java.awt.EventQueue;
/**
diff --git a/java/awt/event/KeyEvent.java b/java/awt/event/KeyEvent.java
index 455d7ee52..7212c0c97 100644
--- a/java/awt/event/KeyEvent.java
+++ b/java/awt/event/KeyEvent.java
@@ -1,5 +1,5 @@
/* KeyEvent.java -- event for key presses
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,10 +38,11 @@ exception statement from your version. */
package java.awt.event;
+import gnu.java.awt.EventModifier;
+
import java.awt.Component;
import java.io.IOException;
import java.io.ObjectInputStream;
-import gnu.java.awt.EventModifier;
/**
* This event is generated when a key is pressed or released. There are two
diff --git a/java/awt/event/MouseEvent.java b/java/awt/event/MouseEvent.java
index ac8804c24..7f3e014a2 100644
--- a/java/awt/event/MouseEvent.java
+++ b/java/awt/event/MouseEvent.java
@@ -1,5 +1,5 @@
/* MouseEvent.java -- a mouse event
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,11 +38,12 @@ exception statement from your version. */
package java.awt.event;
+import gnu.java.awt.EventModifier;
+
import java.awt.Component;
import java.awt.Point;
import java.io.IOException;
import java.io.ObjectInputStream;
-import gnu.java.awt.EventModifier;
/**
* This event is generated for a mouse event. There are three main categories
diff --git a/java/awt/font/TextLayout.java b/java/awt/font/TextLayout.java
index b58b5a583..aecbbe085 100644
--- a/java/awt/font/TextLayout.java
+++ b/java/awt/font/TextLayout.java
@@ -1,5 +1,5 @@
/* TextLayout.java
- Copyright (C) 2003 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -43,12 +43,10 @@ import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
-import java.text.CharacterIterator;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
+import java.text.CharacterIterator;
import java.util.Map;
-import java.awt.font.TextAttribute;
-
/**
* @author Michael Koch
diff --git a/java/awt/geom/Arc2D.java b/java/awt/geom/Arc2D.java
index 8d8e9dead..5e6d191f0 100644
--- a/java/awt/geom/Arc2D.java
+++ b/java/awt/geom/Arc2D.java
@@ -569,40 +569,83 @@ public abstract class Arc2D extends RectangularShape
|| contains(x + w, y + h))
return true;
- double mx = getX() + getWidth() / 2;
- double my = getY() + getHeight() / 2;
- double x1 = mx
- + getWidth() * Math.cos(Math.toRadians(getAngleStart())) / 2;
- double y1 = my
- - getHeight() * Math.sin(Math.toRadians(getAngleStart())) / 2;
- double x2 = mx
- + getWidth() * Math.cos(Math.toRadians(getAngleStart()
- + extent)) / 2;
- double y2 = my
- - getHeight() * Math.sin(Math.toRadians(getAngleStart()
- + extent)) / 2;
+ Rectangle2D rect = new Rectangle2D.Double(x, y, w, h);
+
+ double a = getWidth() / 2.0;
+ double b = getHeight() / 2.0;
+
+ double mx = getX() + a;
+ double my = getY() + b;
+ double x1 = mx + a * Math.cos(Math.toRadians(getAngleStart()));
+ double y1 = my - b * Math.sin(Math.toRadians(getAngleStart()));
+ double x2 = mx + a * Math.cos(Math.toRadians(getAngleStart() + extent));
+ double y2 = my - b * Math.sin(Math.toRadians(getAngleStart() + extent));
+
if (getArcType() != CHORD)
{
// check intersections against the pie radii
- if (Line2D.linesIntersect(mx, my, x1, y1, x, y, x + w, y)
- || Line2D.linesIntersect(mx, my, x1, y1, x + w, y, x + w, y + h)
- || Line2D.linesIntersect(mx, my, x1, y1, x, y, x, y + h)
- || Line2D.linesIntersect(mx, my, x1, y1, x, y + h, x + w, y + h))
+ if (rect.intersectsLine(mx, my, x1, y1))
return true;
-
- if (Line2D.linesIntersect(mx, my, x2, y2, x, y, x + w, y)
- || Line2D.linesIntersect(mx, my, x2, y2, x + w, y, x + w, y + h)
- || Line2D.linesIntersect(mx, my, x2, y2, x, y, x, y + h)
- || Line2D.linesIntersect(mx, my, x2, y2, x, y + h, x + w, y + h))
+ if (rect.intersectsLine(mx, my, x2, y2))
return true;
}
- else if (Line2D.linesIntersect(x1, y1, x2, y2, x, y, x + w, y)
- || Line2D.linesIntersect(x1, y1, x2, y2, x + w, y, x + w, y + h)
- || Line2D.linesIntersect(x1, y1, x2, y2, x, y, x, y + h)
- || Line2D.linesIntersect(x1, y1, x2, y2, x, y + h, x + w, y + h))
+ else// check the chord
+ if (rect.intersectsLine(x1, y1, x2, y2))
return true;
- if ((new Rectangle2D.Double(x, y, w, h)).contains(x1, y1))
+ // Check the Arc segment against the four edges
+ double dx;
+
+ // Check the Arc segment against the four edges
+ double dy;
+ dy = y - my;
+ dx = a * Math.sqrt(1 - ((dy * dy) / (b * b)));
+ if (! java.lang.Double.isNaN(dx))
+ {
+ if (mx + dx >= x && mx + dx <= x + w
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, dx))))
+ return true;
+ if (mx - dx >= x && mx - dx <= x + w
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, -dx))))
+ return true;
+ }
+ dy = (y + h) - my;
+ dx = a * Math.sqrt(1 - ((dy * dy) / (b * b)));
+ if (! java.lang.Double.isNaN(dx))
+ {
+ if (mx + dx >= x && mx + dx <= x + w
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, dx))))
+ return true;
+ if (mx - dx >= x && mx - dx <= x + w
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, -dx))))
+ return true;
+ }
+ dx = x - mx;
+ dy = b * Math.sqrt(1 - ((dx * dx) / (a * a)));
+ if (! java.lang.Double.isNaN(dy))
+ {
+ if (my + dy >= y && my + dy <= y + h
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, dx))))
+ return true;
+ if (my - dy >= y && my - dy <= y + h
+ && containsAngle(Math.toDegrees(Math.atan2(dy, dx))))
+ return true;
+ }
+
+ dx = (x + w) - mx;
+ dy = b * Math.sqrt(1 - ((dx * dx) / (a * a)));
+ if (! java.lang.Double.isNaN(dy))
+ {
+ if (my + dy >= y && my + dy <= y + h
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, dx))))
+ return true;
+ if (my - dy >= y && my - dy <= y + h
+ && containsAngle(Math.toDegrees(Math.atan2(dy, dx))))
+ return true;
+ }
+
+ // Check whether the arc is contained within the box
+ if (rect.contains(mx, my))
return true;
return false;
@@ -627,37 +670,27 @@ public abstract class Arc2D extends RectangularShape
&& contains(x + w, y + h)))
return false;
- double mx = getX() + getWidth() / 2;
- double my = getY() + getHeight() / 2;
- double x1 = mx
- + getWidth() * Math.cos(Math.toRadians(getAngleStart())) / 2;
- double y1 = my
- - getHeight() * Math.sin(Math.toRadians(getAngleStart())) / 2;
- double x2 = mx
- + getWidth() * Math.cos(Math.toRadians(getAngleStart()
- + extent)) / 2;
- double y2 = my
- - getHeight() * Math.sin(Math.toRadians(getAngleStart()
- + extent)) / 2;
+ Rectangle2D rect = new Rectangle2D.Double(x, y, w, h);
+
+ double a = getWidth() / 2.0;
+ double b = getHeight() / 2.0;
+
+ double mx = getX() + a;
+ double my = getY() + b;
+ double x1 = mx + a * Math.cos(Math.toRadians(getAngleStart()));
+ double y1 = my - b * Math.sin(Math.toRadians(getAngleStart()));
+ double x2 = mx + a * Math.cos(Math.toRadians(getAngleStart() + extent));
+ double y2 = my - b * Math.sin(Math.toRadians(getAngleStart() + extent));
if (getArcType() != CHORD)
{
// check intersections against the pie radii
- if (Line2D.linesIntersect(mx, my, x1, y1, x, y, x + w, y)
- || Line2D.linesIntersect(mx, my, x1, y1, x + w, y, x + w, y + h)
- || Line2D.linesIntersect(mx, my, x1, y1, x, y, x, y + h)
- || Line2D.linesIntersect(mx, my, x1, y1, x, y + h, x + w, y + h))
+ if (rect.intersectsLine(mx, my, x1, y1))
return false;
- if (Line2D.linesIntersect(mx, my, x2, y2, x, y, x + w, y)
- || Line2D.linesIntersect(mx, my, x2, y2, x + w, y, x + w, y + h)
- || Line2D.linesIntersect(mx, my, x2, y2, x, y, x, y + h)
- || Line2D.linesIntersect(mx, my, x2, y2, x, y + h, x + w, y + h))
+ if (rect.intersectsLine(mx, my, x2, y2))
return false;
}
- else if (Line2D.linesIntersect(x1, y1, x2, y2, x, y, x + w, y)
- || Line2D.linesIntersect(x1, y1, x2, y2, x + w, y, x + w, y + h)
- || Line2D.linesIntersect(x1, y1, x2, y2, x, y, x, y + h)
- || Line2D.linesIntersect(x1, y1, x2, y2, x, y + h, x + w, y + h))
+ else if (rect.intersectsLine(x1, y1, x2, y2))
return false;
return true;
}
diff --git a/java/awt/geom/Area.java b/java/awt/geom/Area.java
index 1297a0e01..705699567 100644
--- a/java/awt/geom/Area.java
+++ b/java/awt/geom/Area.java
@@ -124,6 +124,10 @@ public class Area implements Shape, Cloneable
* of non-self-intersecting subpaths, and any inner paths which
* are found redundant in accordance with the Shape's winding rule
* will not be included.
+ *
+ * @param s the shape (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if <code>s</code> is <code>null</code>.
*/
public Area(Shape s)
{
@@ -261,7 +265,8 @@ public class Area implements Shape, Cloneable
/**
* Performs a subtraction operation on this Area.<BR>
- * @param area - the area to be subtracted from this area.
+ * @param area the area to be subtracted from this area.
+ * @throws NullPointerException if <code>area</code> is <code>null</code>.
*/
public void subtract(Area area)
{
@@ -357,6 +362,7 @@ public class Area implements Shape, Cloneable
/**
* Performs an intersection operation on this Area.<BR>
* @param area - the area to be intersected with this area.
+ * @throws NullPointerException if <code>area</code> is <code>null</code>.
*/
public void intersect(Area area)
{
@@ -448,6 +454,7 @@ public class Area implements Shape, Cloneable
/**
* Performs an exclusive-or operation on this Area.<BR>
* @param area - the area to be XORed with this area.
+ * @throws NullPointerException if <code>area</code> is <code>null</code>.
*/
public void exclusiveOr(Area area)
{
@@ -584,6 +591,9 @@ public class Area implements Shape, Cloneable
*/
public boolean isRectangular()
{
+ if (isEmpty())
+ return true;
+
if (holes.size() != 0 || solids.size() != 1)
return false;
@@ -663,6 +673,8 @@ public class Area implements Shape, Cloneable
/**
* Returns the bounds of this object in Rectangle format.
* Please note that this may lead to loss of precision.
+ *
+ * @return The bounds.
* @see #getBounds2D()
*/
public Rectangle getBounds()
@@ -695,11 +707,17 @@ public class Area implements Shape, Cloneable
/**
* Compares two Areas.
- *
- * @return true if the areas are equal. False otherwise.
+ *
+ * @param area the area to compare against this area (<code>null</code>
+ * permitted).
+ * @return <code>true</code> if the areas are equal, and <code>false</code>
+ * otherwise.
*/
public boolean equals(Area area)
{
+ if (area == null)
+ return false;
+
if (! getBounds2D().equals(area.getBounds2D()))
return false;
@@ -736,7 +754,9 @@ public class Area implements Shape, Cloneable
}
/**
- * Transforms this area by the AffineTransform at
+ * Transforms this area by the AffineTransform at.
+ *
+ * @param at the transform.
*/
public void transform(AffineTransform at)
{
@@ -755,8 +775,10 @@ public class Area implements Shape, Cloneable
/**
* Returns a new Area equal to this one, transformed
- * by the AffineTransform at
+ * by the AffineTransform at.
+ * @param at the transform.
* @return the transformed area
+ * @throws NullPointerException if <code>at</code> is <code>null</code>.
*/
public Area createTransformedArea(AffineTransform at)
{
@@ -768,6 +790,8 @@ public class Area implements Shape, Cloneable
/**
* Determines if the point (x,y) is contained within this Area.
*
+ * @param x the x-coordinate of the point.
+ * @param y the y-coordinate of the point.
* @return true if the point is contained, false otherwise.
*/
public boolean contains(double x, double y)
@@ -787,7 +811,10 @@ public class Area implements Shape, Cloneable
/**
* Determines if the Point2D p is contained within this Area.
*
- * @return true if the point is contained, false otherwise.
+ * @param p the point.
+ * @return <code>true</code> if the point is contained, <code>false</code>
+ * otherwise.
+ * @throws NullPointerException if <code>p</code> is <code>null</code>.
*/
public boolean contains(Point2D p)
{
@@ -801,7 +828,12 @@ public class Area implements Shape, Cloneable
*
* This method should always produce the correct results, unlike for other
* classes in geom.
- * @return true if the rectangle is considered contained
+ *
+ * @param x the x-coordinate of the rectangle.
+ * @param y the y-coordinate of the rectangle.
+ * @param w the width of the the rectangle.
+ * @param h the height of the rectangle.
+ * @return <code>true</code> if the rectangle is considered contained
*/
public boolean contains(double x, double y, double w, double h)
{
@@ -853,7 +885,7 @@ public class Area implements Shape, Cloneable
Rectangle2D r = new Rectangle2D.Double(x, y, w, h);
for (int path = 0; path < holes.size(); path++)
if (! ((Segment) holes.elementAt(path)).isSegmentOutside(r))
- return false;
+ return false;
return true;
}
@@ -864,7 +896,11 @@ public class Area implements Shape, Cloneable
*
* This method should always produce the correct results, unlike for other
* classes in geom.
- * @return true if the rectangle is considered contained
+ *
+ * @param r the rectangle.
+ * @return <code>true</code> if the rectangle is considered contained
+ *
+ * @throws NullPointerException if <code>r</code> is <code>null</code>.
*/
public boolean contains(Rectangle2D r)
{
@@ -874,7 +910,13 @@ public class Area implements Shape, Cloneable
/**
* Determines if the rectangle specified by (x,y) as the upper-left
* and with width w and height h intersects any part of this Area.
- * @return true if the rectangle intersects the area, false otherwise.
+ *
+ * @param x the x-coordinate for the rectangle.
+ * @param y the y-coordinate for the rectangle.
+ * @param w the width of the rectangle.
+ * @param h the height of the rectangle.
+ * @return <code>true</code> if the rectangle intersects the area,
+ * <code>false</code> otherwise.
*/
public boolean intersects(double x, double y, double w, double h)
{
@@ -919,7 +961,7 @@ public class Area implements Shape, Cloneable
}
// Non-intersecting, Is any point inside?
- if (contains(x, y))
+ if (contains(x + w * 0.5, y + h * 0.5))
return true;
// What if the rectangle encloses the whole shape?
@@ -932,7 +974,11 @@ public class Area implements Shape, Cloneable
/**
* Determines if the Rectangle2D specified by r intersects any
* part of this Area.
- * @return true if the rectangle intersects the area, false otherwise.
+ * @param r the rectangle to test intersection with (<code>null</code>
+ * not permitted).
+ * @return <code>true</code> if the rectangle intersects the area,
+ * <code>false</code> otherwise.
+ * @throws NullPointerException if <code>r</code> is <code>null</code>.
*/
public boolean intersects(Rectangle2D r)
{
@@ -942,24 +988,31 @@ public class Area implements Shape, Cloneable
/**
* Returns a PathIterator object defining the contour of this Area,
* transformed by at.
+ *
+ * @param at the transform.
+ * @return A path iterator.
*/
public PathIterator getPathIterator(AffineTransform at)
{
return (new AreaIterator(at));
}
- //---------------------------------------------------------------------
- // Non-public methods and classes
-
/**
* Returns a flattened PathIterator object defining the contour of this
* Area, transformed by at and with a defined flatness.
+ *
+ * @param at the transform.
+ * @param flatness the flatness.
+ * @return A path iterator.
*/
public PathIterator getPathIterator(AffineTransform at, double flatness)
{
return new FlatteningPathIterator(getPathIterator(at), flatness);
}
+ //---------------------------------------------------------------------
+ // Non-public methods and classes
+
/**
* Private pathiterator object.
*/
@@ -2515,12 +2568,13 @@ public class Area implements Shape, Cloneable
return 0;
if (y0 == 0.0)
- y0 += EPSILON;
+ y0 -= EPSILON;
if (y1 == 0.0)
- y1 += EPSILON;
+ y1 -= EPSILON;
- if (Line2D.linesIntersect(x0, y0, x1, y1, 0.0, 0.0, Double.MAX_VALUE, 0.0))
+ if (Line2D.linesIntersect(x0, y0, x1, y1,
+ EPSILON, 0.0, Double.MAX_VALUE, 0.0))
return 1;
return 0;
}
@@ -2727,9 +2781,9 @@ public class Area implements Shape, Cloneable
if ((x0 > 0.0 || x1 > 0.0 || x2 > 0.0) && (y0 * y1 <= 0 || y1 * y2 <= 0))
{
if (y0 == 0.0)
- y0 += EPSILON;
+ y0 -= EPSILON;
if (y2 == 0.0)
- y2 += EPSILON;
+ y2 -= EPSILON;
r[0] = y0;
r[1] = 2 * (y1 - y0);
@@ -3139,9 +3193,9 @@ public class Area implements Shape, Cloneable
&& (y0 * y1 <= 0 || y1 * y2 <= 0 || y2 * y3 <= 0))
{
if (y0 == 0.0)
- y0 += EPSILON;
+ y0 -= EPSILON;
if (y3 == 0.0)
- y3 += EPSILON;
+ y3 -= EPSILON;
r[0] = y0;
r[1] = 3 * (y1 - y0);
diff --git a/java/awt/geom/CubicCurve2D.java b/java/awt/geom/CubicCurve2D.java
index 56b90e998..20373061d 100644
--- a/java/awt/geom/CubicCurve2D.java
+++ b/java/awt/geom/CubicCurve2D.java
@@ -59,6 +59,7 @@ import java.util.NoSuchElementException;
public abstract class CubicCurve2D implements Shape, Cloneable
{
private static final double BIG_VALUE = java.lang.Double.MAX_VALUE / 10.0;
+ private static final double EPSILON = 1E-10;
/**
* Constructs a new CubicCurve2D. Typical users will want to
@@ -1089,21 +1090,21 @@ public abstract class CubicCurve2D implements Shape, Cloneable
If this is not done, bad behaviour may result for points on that axis.*/
if (a0 == 0.0 || a3 == 0.0)
{
- double small = getFlatness() * (1E-10);
+ double small = getFlatness() * EPSILON;
if (a0 == 0.0)
- a0 += small;
+ a0 -= small;
if (a3 == 0.0)
- a3 += small;
+ a3 -= small;
}
if (useYaxis)
{
- if (Line2D.linesIntersect(b0, a0, b3, a3, 0.0, 0.0, distance, 0.0))
+ if (Line2D.linesIntersect(b0, a0, b3, a3, EPSILON, 0.0, distance, 0.0))
nCrossings++;
}
else
{
- if (Line2D.linesIntersect(a0, b0, a3, b3, 0.0, 0.0, 0.0, distance))
+ if (Line2D.linesIntersect(a0, b0, a3, b3, 0.0, EPSILON, 0.0, distance))
nCrossings++;
}
diff --git a/java/awt/geom/Ellipse2D.java b/java/awt/geom/Ellipse2D.java
index 209a2184b..bd64adf1e 100644
--- a/java/awt/geom/Ellipse2D.java
+++ b/java/awt/geom/Ellipse2D.java
@@ -101,6 +101,9 @@ public abstract class Ellipse2D extends RectangularShape
* Note: An ellipse cannot be represented exactly in PathIterator
* segments, the outline is thefore approximated with cubic
* Bezier segments.
+ *
+ * @param at an optional transform.
+ * @return A path iterator.
*/
public PathIterator getPathIterator(AffineTransform at)
{
@@ -139,6 +142,10 @@ public abstract class Ellipse2D extends RectangularShape
return false;
}
+ /**
+ * An {@link Ellipse2D} that stores its coordinates using <code>double</code>
+ * primitives.
+ */
public static class Double extends Ellipse2D
{
/**
@@ -162,7 +169,7 @@ public abstract class Ellipse2D extends RectangularShape
public double y;
/**
- * Creates a new Ellipse2D with an upper-right coordinate of (0,0)
+ * Creates a new Ellipse2D with an upper-left coordinate of (0,0)
* and a zero size.
*/
public Double()
@@ -172,11 +179,10 @@ public abstract class Ellipse2D extends RectangularShape
/**
* Creates a new Ellipse2D within a given rectangle
* using double-precision coordinates.<P>
- * @param x - x coordinate of the upper-right of the bounding rectangle
- * @param y - y coordinate of the upper-right of the bounding rectangle
+ * @param x - x coordinate of the upper-left of the bounding rectangle
+ * @param y - y coordinate of the upper-left of the bounding rectangle
* @param w - width of the ellipse
* @param h - height of the ellipse
- *
*/
public Double(double x, double y, double w, double h)
{
@@ -188,6 +194,7 @@ public abstract class Ellipse2D extends RectangularShape
/**
* Returns the bounding-box of the ellipse.
+ * @return The bounding box.
*/
public Rectangle2D getBounds2D()
{
@@ -196,6 +203,7 @@ public abstract class Ellipse2D extends RectangularShape
/**
* Returns the height of the ellipse.
+ * @return The height of the ellipse.
*/
public double getHeight()
{
@@ -204,6 +212,7 @@ public abstract class Ellipse2D extends RectangularShape
/**
* Returns the width of the ellipse.
+ * @return The width of the ellipse.
*/
public double getWidth()
{
@@ -213,6 +222,7 @@ public abstract class Ellipse2D extends RectangularShape
/**
* Returns x coordinate of the upper-left corner of
* the ellipse's bounding-box.
+ * @return The x coordinate.
*/
public double getX()
{
@@ -222,6 +232,7 @@ public abstract class Ellipse2D extends RectangularShape
/**
* Returns y coordinate of the upper-left corner of
* the ellipse's bounding-box.
+ * @return The y coordinate.
*/
public double getY()
{
@@ -229,7 +240,10 @@ public abstract class Ellipse2D extends RectangularShape
}
/**
- * Returns true if the ellipse encloses any area.
+ * Returns <code>true</code> if the ellipse encloses no area, and
+ * <code>false</code> otherwise.
+ *
+ * @return A boolean.
*/
public boolean isEmpty()
{
@@ -239,8 +253,8 @@ public abstract class Ellipse2D extends RectangularShape
/**
* Sets the geometry of the ellipse's bounding box.<P>
*
- * @param x - x coordinate of the upper-right of the bounding rectangle
- * @param y - y coordinate of the upper-right of the bounding rectangle
+ * @param x - x coordinate of the upper-left of the bounding rectangle
+ * @param y - y coordinate of the upper-left of the bounding rectangle
* @param w - width of the ellipse
* @param h - height of the ellipse
*/
@@ -253,6 +267,10 @@ public abstract class Ellipse2D extends RectangularShape
}
} // class Double
+ /**
+ * An {@link Ellipse2D} that stores its coordinates using <code>float</code>
+ * primitives.
+ */
public static class Float extends Ellipse2D
{
/**
@@ -276,7 +294,7 @@ public abstract class Ellipse2D extends RectangularShape
public float y;
/**
- * Creates a new Ellipse2D with an upper-right coordinate of (0,0)
+ * Creates a new Ellipse2D with an upper-left coordinate of (0,0)
* and a zero size.
*/
public Float()
@@ -286,8 +304,8 @@ public abstract class Ellipse2D extends RectangularShape
/**
* Creates a new Ellipse2D within a given rectangle
* using floating-point precision.<P>
- * @param x - x coordinate of the upper-right of the bounding rectangle
- * @param y - y coordinate of the upper-right of the bounding rectangle
+ * @param x - x coordinate of the upper-left of the bounding rectangle
+ * @param y - y coordinate of the upper-left of the bounding rectangle
* @param w - width of the ellipse
* @param h - height of the ellipse
*
@@ -302,6 +320,7 @@ public abstract class Ellipse2D extends RectangularShape
/**
* Returns the bounding-box of the ellipse.
+ * @return The bounding box.
*/
public Rectangle2D getBounds2D()
{
@@ -310,6 +329,7 @@ public abstract class Ellipse2D extends RectangularShape
/**
* Returns the height of the ellipse.
+ * @return The height of the ellipse.
*/
public double getHeight()
{
@@ -318,6 +338,7 @@ public abstract class Ellipse2D extends RectangularShape
/**
* Returns the width of the ellipse.
+ * @return The width of the ellipse.
*/
public double getWidth()
{
@@ -327,6 +348,7 @@ public abstract class Ellipse2D extends RectangularShape
/**
* Returns x coordinate of the upper-left corner of
* the ellipse's bounding-box.
+ * @return The x coordinate.
*/
public double getX()
{
@@ -336,6 +358,7 @@ public abstract class Ellipse2D extends RectangularShape
/**
* Returns y coordinate of the upper-left corner of
* the ellipse's bounding-box.
+ * @return The y coordinate.
*/
public double getY()
{
@@ -343,7 +366,10 @@ public abstract class Ellipse2D extends RectangularShape
}
/**
- * Returns true if the ellipse encloses any area.
+ * Returns <code>true</code> if the ellipse encloses no area, and
+ * <code>false</code> otherwise.
+ *
+ * @return A boolean.
*/
public boolean isEmpty()
{
@@ -353,8 +379,8 @@ public abstract class Ellipse2D extends RectangularShape
/**
* Sets the geometry of the ellipse's bounding box.<P>
*
- * @param x - x coordinate of the upper-right of the bounding rectangle
- * @param y - y coordinate of the upper-right of the bounding rectangle
+ * @param x - x coordinate of the upper-left of the bounding rectangle
+ * @param y - y coordinate of the upper-left of the bounding rectangle
* @param w - width of the ellipse
* @param h - height of the ellipse
*/
@@ -371,8 +397,8 @@ public abstract class Ellipse2D extends RectangularShape
*
* Note: This leads to a loss of precision.<P>
*
- * @param x - x coordinate of the upper-right of the bounding rectangle
- * @param y - y coordinate of the upper-right of the bounding rectangle
+ * @param x - x coordinate of the upper-left of the bounding rectangle
+ * @param y - y coordinate of the upper-left of the bounding rectangle
* @param w - width of the ellipse
* @param h - height of the ellipse
*/
diff --git a/java/awt/geom/GeneralPath.java b/java/awt/geom/GeneralPath.java
index 40182eabf..dfedb65bb 100644
--- a/java/awt/geom/GeneralPath.java
+++ b/java/awt/geom/GeneralPath.java
@@ -1,39 +1,40 @@
/* GeneralPath.java -- represents a shape built from subpaths
Copyright (C) 2002, 2003, 2004 Free Software Foundation
- 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., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 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. */
+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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.geom;
@@ -793,11 +794,11 @@ public final class GeneralPath implements Shape, Cloneable
y1 = firsty;
if (y0 == 0.0)
- y0 += epsilon;
+ y0 -= epsilon;
if (y1 == 0.0)
- y1 += epsilon;
- if (Line2D.linesIntersect(x0, y0, x1, y1, 0.0, 0.0, distance,
- 0.0))
+ y1 -= epsilon;
+ if (Line2D.linesIntersect(x0, y0, x1, y1,
+ epsilon, 0.0, distance, 0.0))
windingNumber += (y1 < y0) ? 1 : negative;
cx = firstx;
@@ -814,10 +815,11 @@ public final class GeneralPath implements Shape, Cloneable
y1 = firsty;
if (y0 == 0.0)
- y0 += epsilon;
+ y0 -= epsilon;
if (y1 == 0.0)
- y1 += epsilon;
- if (Line2D.linesIntersect(x0, y0, x1, y1, 0.0, 0.0, distance, 0.0))
+ y1 -= epsilon;
+ if (Line2D.linesIntersect(x0, y0, x1, y1,
+ epsilon, 0.0, distance, 0.0))
windingNumber += (y1 < y0) ? 1 : negative;
cx = firstx;
@@ -832,10 +834,11 @@ public final class GeneralPath implements Shape, Cloneable
y1 = ypoints[pos++] - (float) y;
if (y0 == 0.0)
- y0 += epsilon;
+ y0 -= epsilon;
if (y1 == 0.0)
- y1 += epsilon;
- if (Line2D.linesIntersect(x0, y0, x1, y1, 0.0, 0.0, distance, 0.0))
+ y1 -= epsilon;
+ if (Line2D.linesIntersect(x0, y0, x1, y1,
+ epsilon, 0.0, distance, 0.0))
windingNumber += (y1 < y0) ? 1 : negative;
cx = xpoints[pos - 1] - (float) x;
@@ -854,9 +857,9 @@ public final class GeneralPath implements Shape, Cloneable
&& (y0 * y1 <= 0 || y1 * y2 <= 0))
{
if (y0 == 0.0)
- y0 += epsilon;
+ y0 -= epsilon;
if (y2 == 0.0)
- y2 += epsilon;
+ y2 -= epsilon;
r[0] = y0;
r[1] = 2 * (y1 - y0);
@@ -897,9 +900,9 @@ public final class GeneralPath implements Shape, Cloneable
&& (y0 * y1 <= 0 || y1 * y2 <= 0 || y2 * y3 <= 0))
{
if (y0 == 0.0)
- y0 += epsilon;
+ y0 -= epsilon;
if (y3 == 0.0)
- y3 += epsilon;
+ y3 -= epsilon;
r[0] = y0;
r[1] = 3 * (y1 - y0);
@@ -942,3 +945,4 @@ public final class GeneralPath implements Shape, Cloneable
return (windingNumber);
}
} // class GeneralPath
+
diff --git a/java/awt/geom/PathIterator.java b/java/awt/geom/PathIterator.java
index 1fb0a46e0..8076b5c83 100644
--- a/java/awt/geom/PathIterator.java
+++ b/java/awt/geom/PathIterator.java
@@ -46,8 +46,8 @@ package java.awt.geom;
*
* @author Tom Tromey <tromey@cygnus.com>
* @author Eric Blake <ebb9@email.byu.edu>
- * @see Shape
- * @see Stroke
+ * @see java.awt.Shape
+ * @see java.awt.Stroke
* @see FlatteningPathIterator
* @since 1.2
* @status updated to 1.4
diff --git a/java/awt/geom/Point2D.java b/java/awt/geom/Point2D.java
index 48b12f67d..d27505fa4 100644
--- a/java/awt/geom/Point2D.java
+++ b/java/awt/geom/Point2D.java
@@ -1,5 +1,5 @@
/* Point2D.java -- generic point in 2-D space
- Copyright (C) 1999, 2000, 2002 Free Software Foundation
+ Copyright (C) 1999, 2000, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -35,6 +35,7 @@ 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.geom;
/**
@@ -42,8 +43,8 @@ package java.awt.geom;
* representation is left up to the subclass. Point includes two useful
* nested classes, for float and double storage respectively.
*
- * @author Per Bothner <bothner@cygnus.com>
- * @author Eric Blake <ebb9@email.byu.edu>
+ * @author Per Bothner (bothner@cygnus.com)
+ * @author Eric Blake (ebb9@email.byu.edu)
* @since 1.2
* @status updated to 1.4
*/
@@ -52,7 +53,7 @@ public abstract class Point2D implements Cloneable
/**
* The default constructor.
*
- * @see Point
+ * @see java.awt.Point
* @see Point2D.Float
* @see Point2D.Double
*/
@@ -120,7 +121,7 @@ public abstract class Point2D implements Cloneable
* @param y2 the y coordinate of point 2
* @return the distance from (x1,y1) to (x2,y2)
*/
- static public double distance(double x1, double y1, double x2, double y2)
+ public static double distance(double x1, double y1, double x2, double y2)
{
return Math.sqrt(distanceSq(x1, y1, x2, y2));
}
diff --git a/java/awt/geom/QuadCurve2D.java b/java/awt/geom/QuadCurve2D.java
index 0cc9eb46e..0376d5a01 100644
--- a/java/awt/geom/QuadCurve2D.java
+++ b/java/awt/geom/QuadCurve2D.java
@@ -59,6 +59,7 @@ import java.util.NoSuchElementException;
public abstract class QuadCurve2D implements Shape, Cloneable
{
private static final double BIG_VALUE = java.lang.Double.MAX_VALUE / 10.0;
+ private static final double EPSILON = 1E-10;
/**
* Constructs a new QuadCurve2D. Typical users will want to
@@ -962,12 +963,12 @@ public abstract class QuadCurve2D implements Shape, Cloneable
If this is not done,bad behaviour may result for points on that axis. */
if (a0 == 0.0 || a2 == 0.0)
{
- double small = getFlatness() * (1E-10);
+ double small = getFlatness() * EPSILON;
if (a0 == 0.0)
- a0 += small;
+ a0 -= small;
if (a2 == 0.0)
- a2 += small;
+ a2 -= small;
}
r[0] = a0;
@@ -990,12 +991,12 @@ public abstract class QuadCurve2D implements Shape, Cloneable
if (useYaxis)
{
- if (Line2D.linesIntersect(b0, a0, b2, a2, 0.0, 0.0, distance, 0.0))
+ if (Line2D.linesIntersect(b0, a0, b2, a2, EPSILON, 0.0, distance, 0.0))
nCrossings++;
}
else
{
- if (Line2D.linesIntersect(a0, b0, a2, b2, 0.0, 0.0, 0.0, distance))
+ if (Line2D.linesIntersect(a0, b0, a2, b2, 0.0, EPSILON, 0.0, distance))
nCrossings++;
}
diff --git a/java/awt/geom/Rectangle2D.java b/java/awt/geom/Rectangle2D.java
index 8203ca344..96baf336a 100644
--- a/java/awt/geom/Rectangle2D.java
+++ b/java/awt/geom/Rectangle2D.java
@@ -368,7 +368,7 @@ public abstract class Rectangle2D extends RectangularShape
*
* @param r the rectangle to add to this rectangle
* @throws NullPointerException if r is null
- * @see #union(Rectangle2D)
+ * @see #union(Rectangle2D, Rectangle2D, Rectangle2D)
*/
public void add(Rectangle2D r)
{
diff --git a/java/awt/im/InputContext.java b/java/awt/im/InputContext.java
index 1df1c9cd0..95d607113 100644
--- a/java/awt/im/InputContext.java
+++ b/java/awt/im/InputContext.java
@@ -1,5 +1,5 @@
/* InputContext.java -- provides the context for text input
- Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,22 +35,24 @@ 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.im;
+import gnu.java.util.EmptyEnumeration;
+
import java.awt.AWTEvent;
import java.awt.AWTException;
import java.awt.Component;
import java.awt.im.spi.InputMethod;
import java.awt.im.spi.InputMethodDescriptor;
import java.io.BufferedReader;
-import java.io.InputStreamReader;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
-import gnu.java.util.EmptyEnumeration;
/**
* Provides a context for controlling input methods and keyboard layouts.
diff --git a/java/awt/im/spi/InputMethodContext.java b/java/awt/im/spi/InputMethodContext.java
index c6f1faacc..73003f046 100644
--- a/java/awt/im/spi/InputMethodContext.java
+++ b/java/awt/im/spi/InputMethodContext.java
@@ -1,5 +1,5 @@
/* InputMethodContext.java -- communication between an input method and client
- Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,12 +35,14 @@ 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.im.spi;
import java.awt.Window;
import java.awt.font.TextHitInfo;
import java.awt.im.InputMethodRequests;
import java.text.AttributedCharacterIterator;
+
import javax.swing.JFrame;
/**
diff --git a/java/awt/image/AffineTransformOp.java b/java/awt/image/AffineTransformOp.java
index 6219635fa..45a896b31 100644
--- a/java/awt/image/AffineTransformOp.java
+++ b/java/awt/image/AffineTransformOp.java
@@ -1,6 +1,6 @@
/* AffineTransformOp.java -- This class performs affine
- * transformation between two images or rasters in 2
- * dimensions. Copyright (C) 2004 Free Software Foundation
+ transformation between two images or rasters in 2 dimensions.
+ Copyright (C) 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -38,11 +38,12 @@ exception statement from your version. */
package java.awt.image;
-import java.awt.*;
-import java.awt.Graphics;
import java.awt.Graphics2D;
-import java.awt.geom.*;
-
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
/**
* This class performs affine transformation between two images or
diff --git a/java/awt/image/BandedSampleModel.java b/java/awt/image/BandedSampleModel.java
new file mode 100644
index 000000000..cf5dcbac8
--- /dev/null
+++ b/java/awt/image/BandedSampleModel.java
@@ -0,0 +1,538 @@
+/* Copyright (C) 2004 Free Software Foundation
+
+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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.image;
+
+/**
+ * MultiPixelPackedSampleModel provides a single band model that supports
+ * multiple pixels in a single unit. Pixels have 2^n bits and 2^k pixels fit
+ * per data element.
+ *
+ * @author Jerry Quinn <jlquinn@optonline.net>
+ */
+public final class BandedSampleModel extends ComponentSampleModel
+{
+ private int scanlineStride;
+ private int[] bitMasks;
+ private int[] bitOffsets;
+ private int[] sampleSize;
+ private int dataBitOffset;
+ private int elemBits;
+ private int numberOfBits;
+ private int numElems;
+
+ public BandedSampleModel(int dataType, int w, int h, int numBands)
+ {
+ super(dataType, w, h, 1, w, new int[numBands]);
+ }
+
+ public BandedSampleModel(int dataType, int w, int h, int scanlineStride,
+ int[] bankIndices, int[] bandOffsets)
+ {
+ super(dataType, w, h, 1, scanlineStride, bankIndices, bandOffsets);
+ }
+
+ public SampleModel createCompatibleSampleModel(int w, int h)
+ {
+ // NOTE: blackdown 1.4.1 sets all offsets to 0. Sun's 1.4.2 docs
+ // disagree.
+
+ // Compress offsets so minimum is 0, others w*scanlineStride
+ int[] newoffsets = new int[bandOffsets.length];
+ int[] order = new int[bandOffsets.length];
+ for (int i=0; i < bandOffsets.length; i++)
+ order[i] = i;
+ // FIXME: This is N^2, but not a big issue, unless there's a lot of
+ // bands...
+ for (int i=0; i < bandOffsets.length; i++)
+ for (int j=i+1; j < bandOffsets.length; i++)
+ if (bankIndices[order[i]] > bankIndices[order[j]]
+ || (bankIndices[order[i]] == bankIndices[order[j]]
+ && bandOffsets[order[i]] > bandOffsets[order[j]]))
+ {
+ int t = order[i]; order[i] = order[j]; order[j] = t;
+ }
+ int bank = 0;
+ int offset = 0;
+ for (int i=0; i < bandOffsets.length; i++)
+ {
+ if (bankIndices[order[i]] != bank)
+ {
+ bank = bankIndices[order[i]];
+ offset = 0;
+ }
+ newoffsets[order[i]] = offset;
+ offset += w * scanlineStride;
+ }
+
+ return new BandedSampleModel(dataType, w, h, scanlineStride, bankIndices, newoffsets);
+ }
+
+
+ public SampleModel createSubsetSampleModel(int[] bands)
+ {
+ int[] newoff = new int[bands.length];
+ int[] newbanks = new int[bands.length];
+ for (int i=0; i < bands.length; i++)
+ {
+ int b = bands[i];
+ newoff[i] = bandOffsets[b];
+ newbanks[i] = bankIndices[b];
+ }
+
+ if (bands.length > bankIndices.length)
+ throw new
+ RasterFormatException("BandedSampleModel createSubsetSampleModel too"
+ +" many bands");
+
+ return new BandedSampleModel(dataType, width, height, scanlineStride,
+ newbanks, newoff);
+ }
+
+ /**
+ * Extract all samples of one pixel and return in an array of transfer type.
+ *
+ * Extracts the pixel at x, y from data and stores samples into the array
+ * obj. If obj is null, a new array of getTransferType() is created.
+ *
+ * @param x The x-coordinate of the pixel rectangle to store in <code>obj</code>.
+ * @param y The y-coordinate of the pixel rectangle to store in <code>obj</code>.
+ * @param obj The primitive array to store the pixels into or null to force creation.
+ * @param data The DataBuffer that is the source of the pixel data.
+ * @return The primitive array containing the pixel data.
+ * @see java.awt.image.SampleModel#getDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)
+ */
+ public Object getDataElements(int x, int y, Object obj,
+ DataBuffer data)
+ {
+ int pixel = getSample(x, y, 0, data);
+ switch (getTransferType())
+ {
+ case DataBuffer.TYPE_BYTE:
+ {
+ byte[] b = (byte[])obj;
+ if (b == null) b = new byte[numBands];
+ for (int i=0; i < numBands; i++)
+ b[i] = (byte)getSample(x, y, i, data);
+ return b;
+ }
+ case DataBuffer.TYPE_SHORT:
+ case DataBuffer.TYPE_USHORT:
+ {
+ short[] b = (short[])obj;
+ if (b == null) b = new short[numBands];
+ for (int i=0; i < numBands; i++)
+ b[i] = (short)getSample(x, y, i, data);
+ return b;
+ }
+ case DataBuffer.TYPE_INT:
+ {
+ int[] b = (int[])obj;
+ if (b == null) b = new int[numBands];
+ for (int i=0; i < numBands; i++)
+ b[i] = getSample(x, y, i, data);
+ return b;
+ }
+ case DataBuffer.TYPE_FLOAT:
+ {
+ float[] b = (float[])obj;
+ if (b == null) b = new float[numBands];
+ for (int i=0; i < numBands; i++)
+ b[i] = getSampleFloat(x, y, i, data);
+ return b;
+ }
+ case DataBuffer.TYPE_DOUBLE:
+ {
+ double[] b = (double[])obj;
+ if (b == null) b = new double[numBands];
+ for (int i=0; i < numBands; i++)
+ b[i] = getSample(x, y, i, data);
+ return b;
+ }
+
+ default:
+ // Seems like the only sensible thing to do.
+ throw new ClassCastException();
+ }
+ }
+
+ public int[] getPixel(int x, int y, int[] iArray, DataBuffer data)
+ {
+ if (iArray == null) iArray = new int[numBands];
+ for (int i=0; i < numBands; i++)
+ iArray[i] = getSample(x, y, 0, data);
+
+ return iArray;
+ }
+
+ /**
+ * Copy pixels from a region into an array.
+ *
+ * Copies the samples of the pixels in the rectangle starting at x, y that
+ * is w pixels wide and h scanlines high. When there is more than one band,
+ * the samples stored in order before the next pixel. This ordering isn't
+ * well specified in Sun's docs as of 1.4.2.
+ *
+ * If iArray is null, a new array is allocated, filled, and returned.
+ *
+ * @param x The x-coordinate of the pixel rectangle to store in
+ * <code>iArray</code>.
+ * @param y The y-coordinate of the pixel rectangle to store in
+ * <code>iArray</code>.
+ * @param w The width in pixels of the rectangle.
+ * @param h The height in pixels of the rectangle.
+ * @param iArray The int array to store the pixels into or null to force
+ * creation.
+ * @param data The DataBuffer that is the source of the pixel data.
+ * @return The primitive array containing the pixel data.
+ */
+ public int[] getPixels(int x, int y, int w, int h, int[] iArray,
+ DataBuffer data)
+ {
+ if (iArray == null) iArray = new int[w*h*numBands];
+ int outOffset = 0;
+ for (y=0; y<h; y++)
+ {
+ for (x=0; x<w;)
+ {
+ for (int b=0; b < numBands; b++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + x;
+ iArray[outOffset++] =
+ data.getElem(bankIndices[b], offset);
+ }
+ }
+ }
+ return iArray;
+ }
+
+ public int getSample(int x, int y, int b, DataBuffer data)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + x;
+ return data.getElem(bankIndices[b], offset);
+ }
+
+ public float getSampleFloat(int x, int y, int b, DataBuffer data)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + x;
+ return data.getElemFloat(bankIndices[b], offset);
+ }
+
+ public double getSampleDouble(int x, int y, int b, DataBuffer data)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + x;
+ return data.getElemDouble(bankIndices[b], offset);
+ }
+
+ /**
+ * Copy one band's samples from a region into an array.
+ *
+ * Copies from one band the samples of the pixels in the rectangle starting
+ * at x, y that is w pixels wide and h scanlines high.
+ *
+ * If iArray is null, a new array is allocated, filled, and returned.
+ *
+ * @param x The x-coordinate of the pixel rectangle to store in
+ * <code>iArray</code>.
+ * @param y The y-coordinate of the pixel rectangle to store in
+ * <code>iArray</code>.
+ * @param w The width in pixels of the rectangle.
+ * @param h The height in pixels of the rectangle.
+ * @param b The band to retrieve.
+ * @param iArray The int array to store the pixels into or null to force
+ * creation.
+ * @param data The DataBuffer that is the source of the pixel data.
+ * @return The primitive array containing the pixel data.
+ */
+ public int[] getSamples(int x, int y, int w, int h, int b, int[] iArray,
+ DataBuffer data)
+ {
+ if (iArray == null) iArray = new int[w*h];
+ int outOffset = 0;
+ for (y=0; y<h; y++)
+ {
+ for (x=0; x<w;)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + x;
+ iArray[outOffset++] =
+ data.getElem(bankIndices[b], offset);
+ }
+ }
+ return iArray;
+ }
+
+
+ /**
+ * Set the pixel at x, y to the value in the first element of the primitive
+ * array obj.
+ *
+ * @param x The x-coordinate of the data elements in <code>obj</code>.
+ * @param y The y-coordinate of the data elements in <code>obj</code>.
+ * @param obj The primitive array containing the data elements to set.
+ * @param data The DataBuffer to store the data elements into.
+ * @see java.awt.image.SampleModel#setDataElements(int, int, int, int, java.lang.Object, java.awt.image.DataBuffer)
+ */
+ public void setDataElements(int x, int y, Object obj, DataBuffer data)
+ {
+ int transferType = getTransferType();
+ if (getTransferType() != data.getDataType())
+ {
+ throw new IllegalArgumentException("transfer type ("+
+ getTransferType()+"), "+
+ "does not match data "+
+ "buffer type (" +
+ data.getDataType() +
+ ").");
+ }
+
+ int offset = y * scanlineStride + x;
+
+ try
+ {
+ switch (transferType)
+ {
+ case DataBuffer.TYPE_BYTE:
+ {
+ DataBufferByte out = (DataBufferByte) data;
+ byte[] in = (byte[]) obj;
+ for (int i=0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0];
+ return;
+ }
+ case DataBuffer.TYPE_SHORT:
+ {
+ DataBufferShort out = (DataBufferShort) data;
+ short[] in = (short[]) obj;
+ for (int i=0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0];
+ return;
+ }
+ case DataBuffer.TYPE_USHORT:
+ {
+ DataBufferUShort out = (DataBufferUShort) data;
+ short[] in = (short[]) obj;
+ for (int i=0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0];
+ return;
+ }
+ case DataBuffer.TYPE_INT:
+ {
+ DataBufferInt out = (DataBufferInt) data;
+ int[] in = (int[]) obj;
+ for (int i=0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0];
+ return;
+ }
+ case DataBuffer.TYPE_FLOAT:
+ {
+ DataBufferFloat out = (DataBufferFloat) data;
+ float[] in = (float[]) obj;
+ for (int i=0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0];
+ return;
+ }
+ case DataBuffer.TYPE_DOUBLE:
+ {
+ DataBufferDouble out = (DataBufferDouble) data;
+ double[] in = (double[]) obj;
+ for (int i=0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0];
+ return;
+ }
+ default:
+ throw new ClassCastException("Unsupported data type");
+ }
+ }
+ catch (ArrayIndexOutOfBoundsException aioobe)
+ {
+ String msg = "While writing data elements" +
+ ", x="+x+", y="+y+
+ ", width="+width+", height="+height+
+ ", scanlineStride="+scanlineStride+
+ ", offset="+offset+
+ ", data.getSize()="+data.getSize()+
+ ", data.getOffset()="+data.getOffset()+
+ ": " +
+ aioobe;
+ throw new ArrayIndexOutOfBoundsException(msg);
+ }
+ }
+
+ public void setPixel(int x, int y, int[] iArray, DataBuffer data)
+ {
+ for (int b=0; b < numBands; b++)
+ data.setElem(bankIndices[b], bandOffsets[b] + y * scanlineStride + x,
+ iArray[b]);
+ }
+
+ public void setPixels(int x, int y, int w, int h, int[] iArray,
+ DataBuffer data)
+ {
+ int inOffset = 0;
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = y * scanlineStride + (x + ww);
+ for (int b=0; b < numBands; b++)
+ data.setElem(bankIndices[b], bandOffsets[b] + offset,
+ iArray[inOffset++]);
+ }
+ y++;
+ }
+ }
+
+ public void setSample(int x, int y, int b, int s, DataBuffer data)
+ {
+ data.setElem(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s);
+ }
+
+ public void setSample(int x, int y, int b, float s, DataBuffer data)
+ {
+ data.setElemFloat(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s);
+ }
+
+ public void setSample(int x, int y, int b, double s, DataBuffer data)
+ {
+ data.setElemDouble(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s);
+ }
+
+ public void setSamples(int x, int y, int w, int h, int b, int[] iArray,
+ DataBuffer data)
+ {
+ int inOffset = 0;
+
+ switch (getTransferType())
+ {
+ case DataBuffer.TYPE_BYTE:
+ {
+ DataBufferByte out = (DataBufferByte) data;
+ byte[] bank = out.getData(bankIndices[b]);
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + (x + ww);
+ bank[offset] = (byte)iArray[inOffset++];
+ }
+ y++;
+ }
+ return;
+ }
+ case DataBuffer.TYPE_SHORT:
+ {
+ DataBufferShort out = (DataBufferShort) data;
+ short[] bank = out.getData(bankIndices[b]);
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + (x + ww);
+ bank[offset] = (short)iArray[inOffset++];
+ }
+ y++;
+ }
+ return;
+ }
+ case DataBuffer.TYPE_USHORT:
+ {
+ DataBufferShort out = (DataBufferShort) data;
+ short[] bank = out.getData(bankIndices[b]);
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + (x + ww);
+ bank[offset] = (short)iArray[inOffset++];
+ }
+ y++;
+ }
+ return;
+ }
+ case DataBuffer.TYPE_INT:
+ {
+ DataBufferInt out = (DataBufferInt) data;
+ int[] bank = out.getData(bankIndices[b]);
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + (x + ww);
+ bank[offset] = iArray[inOffset++];
+ }
+ y++;
+ }
+ return;
+ }
+ case DataBuffer.TYPE_FLOAT:
+ case DataBuffer.TYPE_DOUBLE:
+ break;
+ default:
+ throw new ClassCastException("Unsupported data type");
+ }
+
+ // Default implementation probably slower for float and double
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + (x + ww);
+ data.setElem(bankIndices[b], offset, iArray[inOffset++]);
+ }
+ y++;
+ }
+ }
+
+ /**
+ * Creates a String with some information about this SampleModel.
+ * @return A String describing this SampleModel.
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ StringBuffer result = new StringBuffer();
+ result.append(getClass().getName());
+ result.append("[");
+ result.append("scanlineStride=").append(scanlineStride);
+ for(int i=0; i < bitMasks.length; i+=1)
+ {
+ result.append(", mask[").append(i).append("]=0x").append(Integer.toHexString(bitMasks[i]));
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+}
diff --git a/java/awt/image/BufferedImage.java b/java/awt/image/BufferedImage.java
index b18779af1..723eeeb77 100644
--- a/java/awt/image/BufferedImage.java
+++ b/java/awt/image/BufferedImage.java
@@ -1,4 +1,5 @@
-/* Copyright (C) 2000, 2002, 2003 Free Software Foundation
+/* BufferedImage.java --
+ Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,6 +38,8 @@ exception statement from your version. */
package java.awt.image;
+import gnu.java.awt.ComponentDataBlitOp;
+
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
@@ -45,11 +48,10 @@ import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Transparency;
import java.awt.color.ColorSpace;
-import java.util.Hashtable;
-import java.util.Vector;
import java.util.HashSet;
+import java.util.Hashtable;
import java.util.Iterator;
-import gnu.java.awt.ComponentDataBlitOp;
+import java.util.Vector;
/**
* A buffered image always starts at coordinates (0, 0).
@@ -59,7 +61,7 @@ import gnu.java.awt.ComponentDataBlitOp;
* height of the image. This tile is always considered to be checked
* out.
*
- * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
+ * @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
*/
public class BufferedImage extends Image
implements WritableRenderedImage
@@ -79,20 +81,20 @@ public class BufferedImage extends Image
TYPE_BYTE_BINARY = 12,
TYPE_BYTE_INDEXED = 13;
- final static int[] bits3 = { 8, 8, 8 };
- final static int[] bits4 = { 8, 8, 8 };
- final static int[] bits1byte = { 8 };
- final static int[] bits1ushort = { 16 };
+ static final int[] bits3 = { 8, 8, 8 };
+ static final int[] bits4 = { 8, 8, 8 };
+ static final int[] bits1byte = { 8 };
+ static final int[] bits1ushort = { 16 };
- final static int[] masks_int = { 0x00ff0000,
+ static final int[] masks_int = { 0x00ff0000,
0x0000ff00,
0x000000ff,
DataBuffer.TYPE_INT };
- final static int[] masks_565 = { 0xf800,
+ static final int[] masks_565 = { 0xf800,
0x07e0,
0x001f,
DataBuffer.TYPE_USHORT};
- final static int[] masks_555 = { 0x7c00,
+ static final int[] masks_555 = { 0x7c00,
0x03e0,
0x001f,
DataBuffer.TYPE_USHORT};
diff --git a/java/awt/image/ColorModel.java b/java/awt/image/ColorModel.java
index 87ab94291..238bec1de 100644
--- a/java/awt/image/ColorModel.java
+++ b/java/awt/image/ColorModel.java
@@ -1,4 +1,5 @@
-/* Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation
+/* ColorModel.java --
+ Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,11 +38,12 @@ exception statement from your version. */
package java.awt.image;
-import java.util.Arrays;
+import gnu.java.awt.Buffers;
+
import java.awt.Point;
import java.awt.Transparency;
import java.awt.color.ColorSpace;
-import gnu.java.awt.Buffers;
+import java.util.Arrays;
/**
* A color model operates with colors in several formats:
@@ -76,8 +78,8 @@ import gnu.java.awt.Buffers;
*
* </ul>
*
- * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
- * @author C. Brian Jones <cbj@gnu.org>
+ * @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
+ * @author C. Brian Jones (cbj@gnu.org)
*/
public abstract class ColorModel implements Transparency
{
@@ -508,40 +510,89 @@ public abstract class ColorModel implements Transparency
* <code>(pixel == cm.getDataElement(cm.getComponents(pixel, null,
* 0), 0))</code>.
*
- * This method is typically overriden in subclasses to provide a
- * more efficient implementation.
+ * This method is overriden in subclasses since this abstract class throws
+ * UnsupportedOperationException().
*
- * @param arrays of unnormalized component samples of single
- * pixel. The scale and multiplication state of the samples are
- * according to the color model. Each component sample is stored
- * as a separate element in the array.
+ * @param components Array of unnormalized component samples of single
+ * pixel. The scale and multiplication state of the samples are according
+ * to the color model. Each component sample is stored as a separate element
+ * in the array.
+ * @param offset Position of the first value of the pixel in components.
*
* @return pixel value encoded according to the color model.
*/
public int getDataElement(int[] components, int offset)
{
- // subclasses has to implement this method.
+ // subclasses have to implement this method.
throw new UnsupportedOperationException();
}
+ /**
+ * Converts the normalized component samples from an array to a pixel
+ * value. I.e. composes the pixel from component samples, but does not
+ * perform any color conversion or scaling of the samples.
+ *
+ * This method is typically overriden in subclasses to provide a
+ * more efficient implementation. The method provided by this abstract
+ * class converts the components to unnormalized form and returns
+ * getDataElement(int[], int).
+ *
+ * @param components Array of normalized component samples of single pixel.
+ * The scale and multiplication state of the samples are according to the
+ * color model. Each component sample is stored as a separate element in the
+ * array.
+ * @param offset Position of the first value of the pixel in components.
+ *
+ * @return pixel value encoded according to the color model.
+ * @since 1.4
+ */
public int getDataElement (float[] components, int offset)
{
- // subclasses has to implement this method.
- throw new UnsupportedOperationException();
+ return
+ getDataElement(getUnnormalizedComponents(components, offset, null, 0),
+ 0);
}
public Object getDataElements(int[] components, int offset, Object obj)
{
- // subclasses has to implement this method.
+ // subclasses have to implement this method.
throw new UnsupportedOperationException();
}
- public int getDataElements (float[] components, Object obj)
+ /**
+ * Converts the normalized component samples from an array to an array of
+ * TransferType values. I.e. composes the pixel from component samples, but
+ * does not perform any color conversion or scaling of the samples.
+ *
+ * If obj is null, a new array of TransferType is allocated and returned.
+ * Otherwise the results are stored in obj and obj is returned. If obj is
+ * not long enough, ArrayIndexOutOfBounds is thrown. If obj is not an array
+ * of primitives, ClassCastException is thrown.
+ *
+ * This method is typically overriden in subclasses to provide a
+ * more efficient implementation. The method provided by this abstract
+ * class converts the components to unnormalized form and returns
+ * getDataElement(int[], int, Object).
+ *
+ * @param components Array of normalized component samples of single pixel.
+ * The scale and multiplication state of the samples are according to the
+ * color model. Each component sample is stored as a separate element in the
+ * array.
+ * @param offset Position of the first value of the pixel in components.
+ * @param obj Array of TransferType or null.
+ *
+ * @return pixel value encoded according to the color model.
+ * @throws ArrayIndexOutOfBounds
+ * @throws ClassCastException
+ * @since 1.4
+ */
+ public Object getDataElements(float[] components, int offset, Object obj)
{
- // subclasses has to implement this method.
- throw new UnsupportedOperationException();
+ return
+ getDataElements(getUnnormalizedComponents(components, offset, null, 0),
+ 0, obj);
}
-
+
public boolean equals(Object obj)
{
if (!(obj instanceof ColorModel)) return false;
diff --git a/java/awt/image/ComponentColorModel.java b/java/awt/image/ComponentColorModel.java
index 24d8b8ea6..3b3447953 100644
--- a/java/awt/image/ComponentColorModel.java
+++ b/java/awt/image/ComponentColorModel.java
@@ -1,4 +1,5 @@
-/* Copyright (C) 2000, 2002, 2004 Free Software Foundation
+/* ComponentColorModel.java --
+ Copyright (C) 2000, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,9 +38,10 @@ exception statement from your version. */
package java.awt.image;
+import gnu.java.awt.Buffers;
+
import java.awt.Point;
import java.awt.color.ColorSpace;
-import gnu.java.awt.Buffers;
public class ComponentColorModel extends ColorModel
{
@@ -60,6 +62,32 @@ public class ComponentColorModel extends ColorModel
transparency, transferType);
}
+ /**
+ * Construct a new ComponentColorModel.
+ *
+ * This constructor makes all bits of each sample significant, so for a
+ * transferType of DataBuffer.BYTE, the bits per sample is 8, etc. If
+ * both hasAlpha and isAlphaPremultiplied are true, color samples are
+ * assumed to be premultiplied by the alpha component. Transparency may be
+ * one of OPAQUE, BITMASK, or TRANSLUCENT.
+ *
+ * @param colorSpace The colorspace for this color model.
+ * @param hasAlpha True if there is an alpha component.
+ * @param isAlphaPremultiplied True if colors are already multiplied by
+ * alpha.
+ * @param transparency The type of alpha values.
+ * @param transferType Data type of pixel sample values.
+ * @since 1.4
+ */
+ public ComponentColorModel(ColorSpace colorSpace,
+ boolean hasAlpha,
+ boolean isAlphaPremultiplied,
+ int transparency, int transferType)
+ {
+ this(colorSpace, null, hasAlpha, isAlphaPremultiplied,
+ transparency, transferType);
+ }
+
public int getRed(int pixel)
{
if (getNumComponents()>1) throw new IllegalArgumentException();
diff --git a/java/awt/image/ComponentSampleModel.java b/java/awt/image/ComponentSampleModel.java
index c7b08b919..f121296f1 100644
--- a/java/awt/image/ComponentSampleModel.java
+++ b/java/awt/image/ComponentSampleModel.java
@@ -41,6 +41,21 @@ import gnu.java.awt.Buffers;
/* FIXME: This class does not yet support data type TYPE_SHORT */
/**
+ * ComponentSampleModel supports a flexible organization of pixel samples in
+ * memory, permitting pixel samples to be interleaved by band, by scanline,
+ * and by pixel.
+ *
+ * A DataBuffer for this sample model has K banks of data. Pixels have N
+ * samples, so there are N bands in the DataBuffer. Each band is completely
+ * contained in one bank of data, but a bank may contain more than one band.
+ * Each pixel sample is stored in a single data element.
+ *
+ * Within a bank, each band begins at an offset stored in bandOffsets. The
+ * banks containing the band is given by bankIndices. Within the bank, there
+ * are three dimensions - band, pixel, and scanline. The dimension ordering
+ * is controlled by bandOffset, pixelStride, and scanlineStride, which means
+ * that any combination of interleavings is supported.
+ *
* @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
*/
public class ComponentSampleModel extends SampleModel
@@ -86,6 +101,7 @@ public class ComponentSampleModel extends SampleModel
this.bandOffsets = bandOffsets;
this.bankIndices = bankIndices;
+ this.numBanks = 0;
for (int b=0; b<bankIndices.length; b++)
this.numBanks = Math.max(this.numBanks, bankIndices[b]+1);
diff --git a/java/awt/image/CropImageFilter.java b/java/awt/image/CropImageFilter.java
index c9a170b9b..a006d26d8 100644
--- a/java/awt/image/CropImageFilter.java
+++ b/java/awt/image/CropImageFilter.java
@@ -1,5 +1,5 @@
/* CropImageFilter.java -- Java class for cropping image filter
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,11 +38,10 @@ exception statement from your version. */
package java.awt.image;
-import java.util.Hashtable;
import java.awt.Rectangle;
+import java.util.Hashtable;
/**
- * <br>
* Currently this filter does almost nothing and needs to be implemented.
*
* @author C. Brian Jones (cbj@gnu.org)
diff --git a/java/awt/image/DataBuffer.java b/java/awt/image/DataBuffer.java
index 967e1a26c..b921953ec 100644
--- a/java/awt/image/DataBuffer.java
+++ b/java/awt/image/DataBuffer.java
@@ -45,12 +45,45 @@ package java.awt.image;
*/
public abstract class DataBuffer
{
+ /**
+ * A constant representng a data type that uses <code>byte</code> primitives
+ * as the storage unit.
+ */
public static final int TYPE_BYTE = 0;
+
+ /**
+ * A constant representng a data type that uses <code>short</code>
+ * primitives as the storage unit.
+ */
public static final int TYPE_USHORT = 1;
+
+ /**
+ * A constant representng a data type that uses <code>short</code>
+ * primitives as the storage unit.
+ */
public static final int TYPE_SHORT = 2;
+
+ /**
+ * A constant representng a data type that uses <code>int</code>
+ * primitives as the storage unit.
+ */
public static final int TYPE_INT = 3;
+
+ /**
+ * A constant representng a data type that uses <code>float</code>
+ * primitives as the storage unit.
+ */
public static final int TYPE_FLOAT = 4;
+
+ /**
+ * A constant representng a data type that uses <code>double</code>
+ * primitives as the storage unit.
+ */
public static final int TYPE_DOUBLE = 5;
+
+ /**
+ * A constant representng an undefined data type.
+ */
public static final int TYPE_UNDEFINED = 32;
/** The type of the data elements stored in the data buffer. */
@@ -68,18 +101,57 @@ public abstract class DataBuffer
/** Offset into each bank. */
protected int[] offsets;
+ /**
+ * Creates a new <code>DataBuffer</code> with the specified data type and
+ * size. The <code>dataType</code> should be one of the constants
+ * {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, {@link #TYPE_USHORT},
+ * {@link #TYPE_INT}, {@link #TYPE_FLOAT} and {@link #TYPE_DOUBLE}.
+ * <p>
+ * The physical (array-based) storage is allocated by a subclass.
+ *
+ * @param dataType the data type.
+ * @param size the number of elements in the buffer.
+ */
protected DataBuffer(int dataType, int size)
{
this.dataType = dataType;
this.size = size;
}
+ /**
+ * Creates a new <code>DataBuffer</code> with the specified data type,
+ * size and number of banks. The <code>dataType</code> should be one of
+ * the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT},
+ * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and
+ * {@link #TYPE_DOUBLE}.
+ * <p>
+ * The physical (array-based) storage is allocated by a subclass.
+ *
+ * @param dataType the data type.
+ * @param size the number of elements in the buffer.
+ * @param numBanks the number of data banks.
+ */
protected DataBuffer(int dataType, int size, int numBanks) {
this(dataType, size);
banks = numBanks;
offsets = new int[numBanks];
}
+ /**
+ * Creates a new <code>DataBuffer</code> with the specified data type,
+ * size and number of banks. An offset (which applies to all banks) is
+ * also specified. The <code>dataType</code> should be one of
+ * the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT},
+ * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and
+ * {@link #TYPE_DOUBLE}.
+ * <p>
+ * The physical (array-based) storage is allocated by a subclass.
+ *
+ * @param dataType the data type.
+ * @param size the number of elements in the buffer.
+ * @param numBanks the number of data banks.
+ * @param offset the offset to the first element for all banks.
+ */
protected DataBuffer(int dataType, int size, int numBanks, int offset) {
this(dataType, size, numBanks);
@@ -88,6 +160,24 @@ public abstract class DataBuffer
this.offset = offset;
}
+ /**
+ * Creates a new <code>DataBuffer</code> with the specified data type,
+ * size and number of banks. An offset (which applies to all banks) is
+ * also specified. The <code>dataType</code> should be one of
+ * the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT},
+ * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and
+ * {@link #TYPE_DOUBLE}.
+ * <p>
+ * The physical (array-based) storage is allocated by a subclass.
+ *
+ * @param dataType the data type.
+ * @param size the number of elements in the buffer.
+ * @param numBanks the number of data banks.
+ * @param offsets the offsets to the first element for all banks.
+ *
+ * @throws ArrayIndexOutOfBoundsException if
+ * <code>numBanks != offsets.length</code>.
+ */
protected DataBuffer(int dataType, int size, int numBanks, int[] offsets) {
this(dataType, size);
if (numBanks != offsets.length)
@@ -99,6 +189,17 @@ public abstract class DataBuffer
offset = offsets[0];
}
+ /**
+ * Returns the size (number of bits) of the specified data type. Valid types
+ * are defined by the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT},
+ * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and
+ * {@link #TYPE_DOUBLE}.
+ *
+ * @param dataType the data type.
+ * @return The number of bits for the specified data type.
+ * @throws IllegalArgumentException if <code>dataType < 0</code> or
+ * <code>dataType > TYPE_DOUBLE</code>.
+ */
public static int getDataTypeSize(int dataType) {
// Maybe this should be a lookup table instead.
switch (dataType)
@@ -118,21 +219,45 @@ public abstract class DataBuffer
}
}
+ /**
+ * Returns the type of the data elements in the data buffer. Valid types
+ * are defined by the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT},
+ * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and
+ * {@link #TYPE_DOUBLE}.
+ *
+ * @return The type.
+ */
public int getDataType()
{
return dataType;
}
+ /**
+ * Returns the size of the data buffer.
+ *
+ * @return The size.
+ */
public int getSize()
{
return size;
}
+ /**
+ * Returns the element offset for the first data bank.
+ *
+ * @return The element offset.
+ */
public int getOffset()
{
return offset;
}
+ /**
+ * Returns the offsets for all the data banks used by this
+ * <code>DataBuffer</code>.
+ *
+ * @return The offsets.
+ */
public int[] getOffsets()
{
if (offsets == null)
@@ -144,60 +269,166 @@ public abstract class DataBuffer
return offsets;
}
+ /**
+ * Returns the number of data banks for this <code>DataBuffer</code>.
+ * @return The number of data banks.
+ */
public int getNumBanks()
{
return banks;
}
+ /**
+ * Returns an element from the first data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int i)
{
return getElem(0, i);
}
+ /**
+ * Returns an element from a particular data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public abstract int getElem(int bank, int i);
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int i, int val)
{
setElem(0, i, val);
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public abstract void setElem(int bank, int i, int val);
+ /**
+ * Returns an element from the first data bank, converted to a
+ * <code>float</code>. The offset (specified in the constructor) is added
+ * to <code>i</code> before accessing the underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public float getElemFloat(int i)
{
return getElem(i);
}
+ /**
+ * Returns an element from a particular data bank, converted to a
+ * <code>float</code>. The offset (specified in the constructor) is
+ * added to <code>i</code> before accessing the underlying data array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public float getElemFloat(int bank, int i)
{
return getElem(bank, i);
}
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElemFloat(int i, float val)
{
setElem(i, (int) val);
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElemFloat(int bank, int i, float val)
{
setElem(bank, i, (int) val);
}
+ /**
+ * Returns an element from the first data bank, converted to a
+ * <code>double</code>. The offset (specified in the constructor) is added
+ * to <code>i</code> before accessing the underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public double getElemDouble(int i)
{
return getElem(i);
}
+ /**
+ * Returns an element from a particular data bank, converted to a
+ * <code>double</code>. The offset (specified in the constructor) is
+ * added to <code>i</code> before accessing the underlying data array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public double getElemDouble(int bank, int i)
{
return getElem(bank, i);
}
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElemDouble(int i, double val)
{
setElem(i, (int) val);
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElemDouble(int bank, int i, double val)
{
setElem(bank, i, (int) val);
diff --git a/java/awt/image/DataBufferByte.java b/java/awt/image/DataBufferByte.java
index 84df55106..fd16f11ac 100644
--- a/java/awt/image/DataBufferByte.java
+++ b/java/awt/image/DataBufferByte.java
@@ -54,12 +54,25 @@ public final class DataBufferByte extends DataBuffer
private byte[] data;
private byte[][] bankData;
+ /**
+ * Creates a new data buffer with a single data bank containing the
+ * specified number of <code>byte</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ */
public DataBufferByte(int size)
{
super(TYPE_BYTE, size);
data = new byte[size];
}
+ /**
+ * Creates a new data buffer with the specified number of data banks,
+ * each containing the specified number of <code>byte</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ * @param numBanks the number of data banks.
+ */
public DataBufferByte(int size, int numBanks)
{
super(TYPE_BYTE, size, numBanks);
@@ -67,18 +80,49 @@ public final class DataBufferByte extends DataBuffer
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data bank.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ */
public DataBufferByte(byte[] dataArray, int size)
{
super(TYPE_BYTE, size);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data bank, with
+ * the specified offset to the first element.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ * @param offset the offset to the first element in the array.
+ */
public DataBufferByte(byte[] dataArray, int size, int offset)
{
super(TYPE_BYTE, size, 1, offset);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data banks.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferByte(byte[][] dataArray, int size)
{
super(TYPE_BYTE, size, dataArray.length);
@@ -86,6 +130,17 @@ public final class DataBufferByte extends DataBuffer
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data banks, with
+ * the specified offsets to the first element in each bank.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ * @param offsets the offsets to the first element in each data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferByte(byte[][] dataArray, int size, int[] offsets)
{
super(TYPE_BYTE, size, dataArray.length, offsets);
@@ -93,37 +148,87 @@ public final class DataBufferByte extends DataBuffer
data = bankData[0];
}
+ /**
+ * Returns the first data bank.
+ *
+ * @return The first data bank.
+ */
public byte[] getData()
{
return data;
}
+ /**
+ * Returns a data bank.
+ *
+ * @param bank the bank index.
+ * @return A data bank.
+ */
public byte[] getData(int bank)
{
return bankData[bank];
}
+ /**
+ * Returns the array underlying this <code>DataBuffer</code>.
+ *
+ * @return The data banks.
+ */
public byte[][] getBankData()
{
return bankData;
}
+ /**
+ * Returns an element from the first data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int i)
{
return data[i+offset] & 0xff; // get unsigned byte as int
}
+ /**
+ * Returns an element from a particular data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int bank, int i)
{
// get unsigned byte as int
return bankData[bank][i+offsets[bank]] & 0xff;
}
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int i, int val)
{
data[i+offset] = (byte) val;
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int bank, int i, int val)
{
bankData[bank][i+offsets[bank]] = (byte) val;
diff --git a/java/awt/image/DataBufferDouble.java b/java/awt/image/DataBufferDouble.java
index b1291f416..2d90ac863 100644
--- a/java/awt/image/DataBufferDouble.java
+++ b/java/awt/image/DataBufferDouble.java
@@ -58,12 +58,25 @@ public final class DataBufferDouble
private double[] data;
private double[][] bankData;
+ /**
+ * Creates a new data buffer with a single data bank containing the
+ * specified number of <code>double</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ */
public DataBufferDouble(int size)
{
super(TYPE_DOUBLE, size);
data = new double[size];
}
+ /**
+ * Creates a new data buffer with the specified number of data banks,
+ * each containing the specified number of <code>double</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ * @param numBanks the number of data banks.
+ */
public DataBufferDouble(int size, int numBanks)
{
super(TYPE_DOUBLE, size, numBanks);
@@ -71,18 +84,49 @@ public final class DataBufferDouble
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data bank.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ */
public DataBufferDouble(double[] dataArray, int size)
{
super(TYPE_DOUBLE, size);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data bank, with
+ * the specified offset to the first element.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ * @param offset the offset to the first element in the array.
+ */
public DataBufferDouble(double[] dataArray, int size, int offset)
{
super(TYPE_DOUBLE, size, 1, offset);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data banks.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferDouble(double[][] dataArray, int size)
{
super(TYPE_DOUBLE, size, dataArray.length);
@@ -90,6 +134,17 @@ public final class DataBufferDouble
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data banks, with
+ * the specified offsets to the first element in each bank.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ * @param offsets the offsets to the first element in each data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferDouble(double[][] dataArray, int size, int[] offsets)
{
super(TYPE_DOUBLE, size, dataArray.length, offsets);
@@ -97,36 +152,86 @@ public final class DataBufferDouble
data = bankData[0];
}
+ /**
+ * Returns the first data bank.
+ *
+ * @return The first data bank.
+ */
public double[] getData()
{
return data;
}
+ /**
+ * Returns a data bank.
+ *
+ * @param bank the bank index.
+ * @return A data bank.
+ */
public double[] getData(int bank)
{
return bankData[bank];
}
+ /**
+ * Returns the array underlying this <code>DataBuffer</code>.
+ *
+ * @return The data banks.
+ */
public double[][] getBankData()
{
return bankData;
}
+ /**
+ * Returns an element from the first data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int i)
{
return (int) data[i+offset];
}
+ /**
+ * Returns an element from a particular data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int bank, int i)
{
return (int) bankData[bank][i+offsets[bank]];
}
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int i, int val)
{
data[i+offset] = (double) val;
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int bank, int i, int val)
{
bankData[bank][i+offsets[bank]] = (double) val;
diff --git a/java/awt/image/DataBufferFloat.java b/java/awt/image/DataBufferFloat.java
index b2d88c16b..da614789a 100644
--- a/java/awt/image/DataBufferFloat.java
+++ b/java/awt/image/DataBufferFloat.java
@@ -56,12 +56,25 @@ public final class DataBufferFloat
private float[] data;
private float[][] bankData;
+ /**
+ * Creates a new data buffer with a single data bank containing the
+ * specified number of <code>float</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ */
public DataBufferFloat(int size)
{
super(TYPE_FLOAT, size);
data = new float[size];
}
+ /**
+ * Creates a new data buffer with the specified number of data banks,
+ * each containing the specified number of <code>float</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ * @param numBanks the number of data banks.
+ */
public DataBufferFloat(int size, int numBanks)
{
super(TYPE_FLOAT, size, numBanks);
@@ -69,18 +82,49 @@ public final class DataBufferFloat
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data bank.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ */
public DataBufferFloat(float[] dataArray, int size)
{
super(TYPE_FLOAT, size);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data bank, with
+ * the specified offset to the first element.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ * @param offset the offset to the first element in the array.
+ */
public DataBufferFloat(float[] dataArray, int size, int offset)
{
super(TYPE_FLOAT, size, 1, offset);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data banks.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferFloat(float[][] dataArray, int size)
{
super(TYPE_FLOAT, size, dataArray.length);
@@ -88,6 +132,17 @@ public final class DataBufferFloat
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data banks, with
+ * the specified offsets to the first element in each bank.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ * @param offsets the offsets to the first element in each data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferFloat(float[][] dataArray, int size, int[] offsets)
{
super(TYPE_FLOAT, size, dataArray.length, offsets);
@@ -95,36 +150,86 @@ public final class DataBufferFloat
data = bankData[0];
}
+ /**
+ * Returns the first data bank.
+ *
+ * @return The first data bank.
+ */
public float[] getData()
{
return data;
}
+ /**
+ * Returns a data bank.
+ *
+ * @param bank the bank index.
+ * @return A data bank.
+ */
public float[] getData(int bank)
{
return bankData[bank];
}
+ /**
+ * Returns the array underlying this <code>DataBuffer</code>.
+ *
+ * @return The data banks.
+ */
public float[][] getBankData()
{
return bankData;
}
+ /**
+ * Returns an element from the first data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int i)
{
return (int) data[i+offset];
}
+ /**
+ * Returns an element from a particular data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int bank, int i)
{
return (int) bankData[bank][i+offsets[bank]];
}
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int i, int val)
{
data[i+offset] = (float) val;
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int bank, int i, int val)
{
bankData[bank][i+offsets[bank]] = (float) val;
diff --git a/java/awt/image/DataBufferInt.java b/java/awt/image/DataBufferInt.java
index 54308fefd..87922c5c1 100644
--- a/java/awt/image/DataBufferInt.java
+++ b/java/awt/image/DataBufferInt.java
@@ -54,12 +54,25 @@ public final class DataBufferInt extends DataBuffer
private int[] data;
private int[][] bankData;
+ /**
+ * Creates a new data buffer with a single data bank containing the
+ * specified number of <code>int</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ */
public DataBufferInt(int size)
{
super(TYPE_INT, size);
data = new int[size];
}
+ /**
+ * Creates a new data buffer with the specified number of data banks,
+ * each containing the specified number of <code>int</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ * @param numBanks the number of data banks.
+ */
public DataBufferInt(int size, int numBanks)
{
super(TYPE_INT, size, numBanks);
@@ -67,18 +80,49 @@ public final class DataBufferInt extends DataBuffer
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data bank.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ */
public DataBufferInt(int[] dataArray, int size)
{
super(TYPE_INT, size);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data bank, with
+ * the specified offset to the first element.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ * @param offset the offset to the first element in the array.
+ */
public DataBufferInt(int[] dataArray, int size, int offset)
{
super(TYPE_INT, size, 1, offset);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data banks.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferInt(int[][] dataArray, int size)
{
super(TYPE_INT, size, dataArray.length);
@@ -86,6 +130,17 @@ public final class DataBufferInt extends DataBuffer
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data banks, with
+ * the specified offsets to the first element in each bank.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ * @param offsets the offsets to the first element in each data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferInt(int[][] dataArray, int size, int[] offsets)
{
super(TYPE_INT, size, dataArray.length, offsets);
@@ -93,39 +148,88 @@ public final class DataBufferInt extends DataBuffer
data = bankData[0];
}
+ /**
+ * Returns the first data bank.
+ *
+ * @return The first data bank.
+ */
public int[] getData()
{
return data;
}
+ /**
+ * Returns a data bank.
+ *
+ * @param bank the bank index.
+ * @return A data bank.
+ */
public int[] getData(int bank)
{
return bankData[bank];
}
+ /**
+ * Returns the array underlying this <code>DataBuffer</code>.
+ *
+ * @return The data banks.
+ */
public int[][] getBankData()
{
return bankData;
}
+ /**
+ * Returns an element from the first data bank. The <code>offset</code> is
+ * added to the specified index before accessing the underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int i)
{
return data[i+offset];
}
+ /**
+ * Returns an element from a particular data bank. The <code>offset</code>
+ * is added to the specified index before accessing the underlying data
+ * array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int bank, int i)
{
// get unsigned int as int
return bankData[bank][i+offsets[bank]];
}
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int i, int val)
{
- data[i+offset] = (int) val;
+ data[i+offset] = val;
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int bank, int i, int val)
{
- bankData[bank][i+offsets[bank]] = (int) val;
+ bankData[bank][i+offsets[bank]] = val;
}
}
diff --git a/java/awt/image/DataBufferShort.java b/java/awt/image/DataBufferShort.java
index 7a5c39424..4dad5fbc3 100644
--- a/java/awt/image/DataBufferShort.java
+++ b/java/awt/image/DataBufferShort.java
@@ -54,12 +54,25 @@ public final class DataBufferShort extends DataBuffer
private short[] data;
private short[][] bankData;
+ /**
+ * Creates a new data buffer with a single data bank containing the
+ * specified number of <code>short</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ */
public DataBufferShort(int size)
{
super(TYPE_SHORT, size);
data = new short[size];
}
+ /**
+ * Creates a new data buffer with the specified number of data banks,
+ * each containing the specified number of <code>short</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ * @param numBanks the number of data banks.
+ */
public DataBufferShort(int size, int numBanks)
{
super(TYPE_SHORT, size, numBanks);
@@ -67,18 +80,49 @@ public final class DataBufferShort extends DataBuffer
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data bank.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ */
public DataBufferShort(short[] dataArray, int size)
{
super(TYPE_SHORT, size);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data bank, with
+ * the specified offset to the first element.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ * @param offset the offset to the first element in the array.
+ */
public DataBufferShort(short[] dataArray, int size, int offset)
{
super(TYPE_SHORT, size, 1, offset);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data banks.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferShort(short[][] dataArray, int size)
{
super(TYPE_SHORT, size, dataArray.length);
@@ -86,6 +130,17 @@ public final class DataBufferShort extends DataBuffer
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data banks, with
+ * the specified offsets to the first element in each bank.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ * @param offsets the offsets to the first element in each data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferShort(short[][] dataArray, int size, int[] offsets)
{
super(TYPE_SHORT, size, dataArray.length, offsets);
@@ -93,36 +148,86 @@ public final class DataBufferShort extends DataBuffer
data = bankData[0];
}
+ /**
+ * Returns the first data bank.
+ *
+ * @return The first data bank.
+ */
public short[] getData()
{
return data;
}
+ /**
+ * Returns a data bank.
+ *
+ * @param bank the bank index.
+ * @return A data bank.
+ */
public short[] getData(int bank)
{
return bankData[bank];
}
+ /**
+ * Returns the array underlying this <code>DataBuffer</code>.
+ *
+ * @return The data banks.
+ */
public short[][] getBankData()
{
return bankData;
}
+ /**
+ * Returns an element from the first data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int i)
{
return data[i+offset];
}
+ /**
+ * Returns an element from a particular data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int bank, int i)
{
return bankData[bank][i+offsets[bank]];
}
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int i, int val)
{
data[i+offset] = (short) val;
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int bank, int i, int val)
{
bankData[bank][i+offsets[bank]] = (short) val;
diff --git a/java/awt/image/DataBufferUShort.java b/java/awt/image/DataBufferUShort.java
index e11b4ab10..a1abb26c5 100644
--- a/java/awt/image/DataBufferUShort.java
+++ b/java/awt/image/DataBufferUShort.java
@@ -54,12 +54,25 @@ public final class DataBufferUShort extends DataBuffer
private short[] data;
private short[][] bankData;
+ /**
+ * Creates a new data buffer with a single data bank containing the
+ * specified number of <code>short</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ */
public DataBufferUShort(int size)
{
super(TYPE_USHORT, size);
data = new short[size];
}
+ /**
+ * Creates a new data buffer with the specified number of data banks,
+ * each containing the specified number of <code>short</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ * @param numBanks the number of data banks.
+ */
public DataBufferUShort(int size, int numBanks)
{
super(TYPE_USHORT, size, numBanks);
@@ -67,18 +80,41 @@ public final class DataBufferUShort extends DataBuffer
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data bank.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ */
public DataBufferUShort(short[] dataArray, int size)
{
super(TYPE_USHORT, size);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data bank, with
+ * the specified offset to the first element.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ * @param offset the offset to the first element in the array.
+ */
public DataBufferUShort(short[] dataArray, int size, int offset)
{
super(TYPE_USHORT, size, 1, offset);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data banks.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferUShort(short[][] dataArray, int size)
{
super(TYPE_USHORT, size, dataArray.length);
@@ -86,6 +122,17 @@ public final class DataBufferUShort extends DataBuffer
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data banks, with
+ * the specified offsets to the first element in each bank.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ * @param offsets the offsets to the first element in each data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferUShort(short[][] dataArray, int size, int[] offsets)
{
super(TYPE_USHORT, size, dataArray.length, offsets);
@@ -93,37 +140,87 @@ public final class DataBufferUShort extends DataBuffer
data = bankData[0];
}
+ /**
+ * Returns the first data bank.
+ *
+ * @return The first data bank.
+ */
public short[] getData()
{
return data;
}
+ /**
+ * Returns a data bank.
+ *
+ * @param bank the bank index.
+ * @return A data bank.
+ */
public short[] getData(int bank)
{
return bankData[bank];
}
+ /**
+ * Returns the array underlying this <code>DataBuffer</code>.
+ *
+ * @return The data banks.
+ */
public short[][] getBankData()
{
return bankData;
}
+ /**
+ * Returns an element from the first data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int i)
{
return data[i+offset] & 0xffff; // get unsigned short as int
}
+ /**
+ * Returns an element from a particular data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int bank, int i)
{
// get unsigned short as int
return bankData[bank][i+offsets[bank]] & 0xffff;
}
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int i, int val)
{
data[i+offset] = (short) val;
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int bank, int i, int val)
{
bankData[bank][i+offsets[bank]] = (short) val;
diff --git a/java/awt/image/DirectColorModel.java b/java/awt/image/DirectColorModel.java
index 3ac43cf25..7fa6e8974 100644
--- a/java/awt/image/DirectColorModel.java
+++ b/java/awt/image/DirectColorModel.java
@@ -1,4 +1,5 @@
-/* Copyright (C) 1999, 2000, 2002 Free Software Foundation
+/* DirectColorModel.java --
+ Copyright (C) 1999, 2000, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,13 +38,14 @@ exception statement from your version. */
package java.awt.image;
+import gnu.java.awt.Buffers;
+
import java.awt.Point;
import java.awt.Transparency;
import java.awt.color.ColorSpace;
-import gnu.java.awt.Buffers;
/**
- * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
+ * @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
* @author C. Brian Jones (cbj@gnu.org)
* @author Mark Benvenuto (mcb54@columbia.edu)
*/
@@ -162,7 +164,7 @@ public class DirectColorModel extends PackedColorModel
return extractAndScaleSample(pixel, 3);
}
- private final int extractAndNormalizeSample(int pixel, int component)
+ private int extractAndNormalizeSample(int pixel, int component)
{
int value = extractAndScaleSample(pixel, component);
if (hasAlpha() && isAlphaPremultiplied())
@@ -170,7 +172,7 @@ public class DirectColorModel extends PackedColorModel
return value;
}
- private final int extractAndScaleSample(int pixel, int component)
+ private int extractAndScaleSample(int pixel, int component)
{
int field = pixel & getMask(component);
int to8BitShift =
@@ -303,7 +305,7 @@ public class DirectColorModel extends PackedColorModel
* @param highBit the position of the most significant bit in the
* val parameter.
*/
- private final int valueToField(int val, int component, int highBit)
+ private int valueToField(int val, int component, int highBit)
{
int toFieldShift =
getComponentSize(component) + shifts[component] - highBit;
@@ -317,7 +319,7 @@ public class DirectColorModel extends PackedColorModel
* Converts a 16 bit value to the correct field bits based on the
* information derived from the field masks.
*/
- private final int value16ToField(int val, int component)
+ private int value16ToField(int val, int component)
{
int toFieldShift = getComponentSize(component) + shifts[component] - 16;
return (toFieldShift>0) ?
diff --git a/java/awt/image/IndexColorModel.java b/java/awt/image/IndexColorModel.java
index 9ceb0bf09..8bc8b9dd1 100644
--- a/java/awt/image/IndexColorModel.java
+++ b/java/awt/image/IndexColorModel.java
@@ -38,7 +38,29 @@ exception statement from your version. */
package java.awt.image;
+import java.awt.color.ColorSpace;
+import java.math.BigInteger;
+
/**
+ * Color model similar to pseudo visual in X11.
+ *
+ * This color model maps linear pixel values to actual RGB and alpha colors.
+ * Thus, pixel values are indexes into the color map. Each color component is
+ * an 8-bit unsigned value.
+ *
+ * The IndexColorModel supports a map of valid pixels, allowing the
+ * representation of holes in the the color map. The valid map is represented
+ * as a BigInteger where each bit indicates the validity of the map entry with
+ * the same index.
+ *
+ * Colors can have alpha components for transparency support. If alpha
+ * component values aren't given, color values are opaque. The model also
+ * supports a reserved pixel value to represent completely transparent colors,
+ * no matter what the actual color component values are.
+ *
+ * IndexColorModel supports anywhere from 1 to 16 bit index values. The
+ * allowed transfer types are DataBuffer.TYPE_BYTE and DataBuffer.TYPE_USHORT.
+ *
* @author C. Brian Jones (cbj@gnu.org)
*/
public class IndexColorModel extends ColorModel
@@ -47,6 +69,7 @@ public class IndexColorModel extends ColorModel
private boolean opaque;
private int trans = -1;
private int[] rgb;
+ private BigInteger validBits = new BigInteger("0");
/**
* Each array much contain <code>size</code> elements. For each
@@ -127,6 +150,10 @@ public class IndexColorModel extends ColorModel
| (blues[i] & 0xff));
}
}
+
+ // Generate a bigint with 1's for every pixel
+ validBits.setBit(size);
+ validBits.subtract(new BigInteger("1"));
}
/**
@@ -167,6 +194,79 @@ public class IndexColorModel extends ColorModel
map_size = size;
opaque = !hasAlpha;
this.trans = trans;
+ // Generate a bigint with 1's for every pixel
+ validBits.setBit(size);
+ validBits.subtract(new BigInteger("1"));
+ }
+
+ /**
+ * Each array much contain <code>size</code> elements. For each
+ * array, the i-th color is described by reds[i], greens[i],
+ * blues[i], alphas[i], unless alphas is not specified, then all the
+ * colors are opaque except for the transparent color.
+ *
+ * @param bits the number of bits needed to represent <code>size</code> colors
+ * @param size the number of colors in the color map
+ * @param cmap packed color components
+ * @param start the offset of the first color component in <code>cmap</code>
+ * @param hasAlpha <code>cmap</code> has alpha values
+ * @param trans the index of the transparent color
+ * @param transferType DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT
+ */
+ public IndexColorModel (int bits, int size, byte[] cmap, int start,
+ boolean hasAlpha, int trans, int transferType)
+ {
+ super(bits * 4, // total bits, sRGB, four channels
+ nArray(bits, 4), // bits for each channel
+ ColorSpace.getInstance(ColorSpace.CS_sRGB), // sRGB
+ true, // has alpha
+ false, // not premultiplied
+ TRANSLUCENT, transferType);
+ if (transferType != DataBuffer.TYPE_BYTE
+ && transferType != DataBuffer.TYPE_USHORT)
+ throw new IllegalArgumentException();
+ map_size = size;
+ opaque = !hasAlpha;
+ this.trans = trans;
+ // Generate a bigint with 1's for every pixel
+ validBits.setBit(size);
+ validBits.subtract(new BigInteger("1"));
+ }
+
+ /**
+ * Construct an IndexColorModel using a colormap with holes.
+ *
+ * The IndexColorModel is built from the array of ints defining the
+ * colormap. Each element contains red, green, blue, and alpha
+ * components. The ColorSpace is sRGB. The transparency value is
+ * automatically determined.
+ *
+ * This constructor permits indicating which colormap entries are valid,
+ * using the validBits argument. Each entry in cmap is valid if the
+ * corresponding bit in validBits is set.
+ *
+ * @param bits the number of bits needed to represent <code>size</code> colors
+ * @param size the number of colors in the color map
+ * @param cmap packed color components
+ * @param start the offset of the first color component in <code>cmap</code>
+ * @param transferType DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT
+ */
+ public IndexColorModel (int bits, int size, int[] cmap, int start,
+ int transferType, BigInteger validBits)
+ {
+ super(bits * 4, // total bits, sRGB, four channels
+ nArray(bits, 4), // bits for each channel
+ ColorSpace.getInstance(ColorSpace.CS_sRGB), // sRGB
+ true, // has alpha
+ false, // not premultiplied
+ TRANSLUCENT, transferType);
+ if (transferType != DataBuffer.TYPE_BYTE
+ && transferType != DataBuffer.TYPE_USHORT)
+ throw new IllegalArgumentException();
+ map_size = size;
+ opaque = false;
+ this.trans = -1;
+ this.validBits = validBits;
}
public final int getMapSize ()
@@ -279,11 +379,79 @@ public class IndexColorModel extends ColorModel
return 0;
}
- //pixel_bits is number of bits to be in generated mask
+ /**
+ * Get the RGB color values of all pixels in the map using the default
+ * RGB color model.
+ *
+ * @param rgb The destination array.
+ */
+ public final void getRGBs (int[] rgb)
+ {
+ System.arraycopy(this.rgb, 0, rgb, 0, map_size);
+ }
+
+ //pixel_bits is number of bits to be in generated mask
private int generateMask (int offset)
{
return (((2 << pixel_bits ) - 1) << (pixel_bits * offset));
}
+ /** Return true if pixel is valid, false otherwise. */
+ public boolean isValid(int pixel)
+ {
+ return validBits.testBit(pixel);
+ }
+
+ /** Return true if all pixels are valid, false otherwise. */
+ public boolean isValid()
+ {
+ // Generate a bigint with 1's for every pixel
+ BigInteger allbits = new BigInteger("0");
+ allbits.setBit(map_size);
+ allbits.subtract(new BigInteger("1"));
+ return allbits.equals(validBits);
+ }
+
+ /**
+ * Returns a BigInteger where each bit represents an entry in the color
+ * model. If the bit is on, the entry is valid.
+ */
+ public BigInteger getValidPixels()
+ {
+ return validBits;
+ }
+
+ /**
+ * Construct a BufferedImage with rgb pixel values from a Raster.
+ *
+ * Constructs a new BufferedImage in which each pixel is an RGBA int from
+ * a Raster with index-valued pixels. If this model has no alpha component
+ * or transparent pixel, the type of the new BufferedImage is TYPE_INT_RGB.
+ * Otherwise the type is TYPE_INT_ARGB. If forceARGB is true, the type is
+ * forced to be TYPE_INT_ARGB no matter what.
+ *
+ * @param raster The source of pixel values.
+ * @param forceARGB True if type must be TYPE_INT_ARGB.
+ * @return New BufferedImage with RBGA int pixel values.
+ */
+ public BufferedImage convertToIntDiscrete(Raster raster, boolean forceARGB)
+ {
+ int type = forceARGB ? BufferedImage.TYPE_INT_ARGB
+ : ((opaque && trans == -1) ? BufferedImage.TYPE_INT_RGB :
+ BufferedImage.TYPE_INT_ARGB);
+
+ // FIXME: assuming that raster has only 1 band since pixels are supposed
+ // to be int indexes.
+ // FIXME: it would likely be more efficient to fetch a complete array,
+ // but it would take much more memory.
+ // FIXME: I'm not sure if transparent pixels or alpha values need special
+ // handling here.
+ BufferedImage im = new BufferedImage(raster.width, raster.height, type);
+ for (int x = raster.minX; x < raster.width + raster.minX; x++)
+ for (int y = raster.minY; y < raster.height + raster.minY; y++)
+ im.setRGB(x, y, rgb[raster.getSample(x, y, 0)]);
+
+ return im;
+ }
}
diff --git a/java/awt/image/MemoryImageSource.java b/java/awt/image/MemoryImageSource.java
index 1228ed78f..8de4b842a 100644
--- a/java/awt/image/MemoryImageSource.java
+++ b/java/awt/image/MemoryImageSource.java
@@ -1,5 +1,5 @@
/* MemoryImageSource.java -- Java class for providing image data
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,8 +38,6 @@ exception statement from your version. */
package java.awt.image;
-import java.awt.Image;
-import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
diff --git a/java/awt/image/MultiPixelPackedSampleModel.java b/java/awt/image/MultiPixelPackedSampleModel.java
new file mode 100644
index 000000000..0525d37bd
--- /dev/null
+++ b/java/awt/image/MultiPixelPackedSampleModel.java
@@ -0,0 +1,387 @@
+/* Copyright (C) 2004 Free Software Foundation
+
+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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.image;
+
+import gnu.java.awt.Buffers;
+
+/**
+ * MultiPixelPackedSampleModel provides a single band model that supports
+ * multiple pixels in a single unit. Pixels have 2^n bits and 2^k pixels fit
+ * per data element.
+ *
+ * @author Jerry Quinn <jlquinn@optonline.net>
+ */
+public class MultiPixelPackedSampleModel extends SampleModel
+{
+ private int scanlineStride;
+ private int[] bitMasks;
+ private int[] bitOffsets;
+ private int[] sampleSize;
+ private int dataBitOffset;
+ private int elemBits;
+ private int numberOfBits;
+ private int numElems;
+
+ public MultiPixelPackedSampleModel(int dataType, int w, int h,
+ int numberOfBits)
+ {
+ this(dataType, w, h, 0, numberOfBits, 0);
+ }
+
+ public MultiPixelPackedSampleModel(int dataType, int w, int h,
+ int numberOfBits, int scanlineStride,
+ int dataBitOffset)
+ {
+ super(dataType, w, h, 1);
+
+ switch (dataType)
+ {
+ case DataBuffer.TYPE_BYTE:
+ elemBits = 8;
+ break;
+ case DataBuffer.TYPE_USHORT:
+ elemBits = 16;
+ break;
+ case DataBuffer.TYPE_INT:
+ elemBits = 32;
+ break;
+ default:
+ throw new IllegalArgumentException("MultiPixelPackedSampleModel"
+ + " unsupported dataType");
+ }
+
+ this.dataBitOffset = dataBitOffset;
+
+ this.numberOfBits = numberOfBits;
+ if (numberOfBits > elemBits)
+ throw new RasterFormatException("MultiPixelPackedSampleModel pixel size"
+ + " larger than dataType");
+ switch (numberOfBits)
+ {
+ case 1: case 2: case 4: case 8: case 16: case 32: break;
+ default:
+ throw new RasterFormatException("MultiPixelPackedSampleModel pixel"
+ + " size not 2^n bits");
+ }
+ numElems = elemBits / numberOfBits;
+
+ // Compute scan line large enough for w pixels.
+ if (scanlineStride == 0)
+ scanlineStride = ((dataBitOffset + w * numberOfBits) / elemBits) + 1;
+ this.scanlineStride = scanlineStride;
+
+
+ sampleSize = new int[1];
+ sampleSize[0] = numberOfBits;
+
+ bitMasks = new int[numElems];
+ bitOffsets = new int[numElems];
+ for (int i=0; i < numElems; i++)
+ {
+ bitOffsets[i] = numberOfBits * i;
+ bitMasks[i] = ((1 << numberOfBits) - 1) << bitOffsets[i];
+ }
+ }
+
+ public SampleModel createCompatibleSampleModel(int w, int h)
+ {
+ /* FIXME: We can avoid recalculation of bit offsets and sample
+ sizes here by passing these from the current instance to a
+ special private constructor. */
+ return new MultiPixelPackedSampleModel(dataType, w, h, numberOfBits);
+ }
+
+
+ /**
+ * Creates a DataBuffer for holding pixel data in the format and
+ * layout described by this SampleModel. The returned buffer will
+ * consist of one single bank.
+ */
+ public DataBuffer createDataBuffer()
+ {
+ int size;
+
+ // FIXME: The comment refers to SinglePixelPackedSampleModel. See if the
+ // same can be done for MultiPixelPackedSampleModel.
+ // We can save (scanlineStride - width) pixels at the very end of
+ // the buffer. The Sun reference implementation (J2SE 1.3.1 and
+ // 1.4.1_01) seems to do this; tested with Mauve test code.
+ size = scanlineStride * height;
+
+ return Buffers.createBuffer(getDataType(), size);
+ }
+
+
+ public int getNumDataElements()
+ {
+ return 1;
+ }
+
+ public int[] getSampleSize()
+ {
+ return sampleSize;
+ }
+
+ public int getSampleSize(int band)
+ {
+ return sampleSize[0];
+ }
+
+ public int getOffset(int x, int y)
+ {
+ return scanlineStride * y + ((dataBitOffset + x*numberOfBits) / elemBits);
+ }
+
+ public int getBitOffset(int x)
+ {
+ return (dataBitOffset + x*numberOfBits) % elemBits;
+ }
+
+ public int getDataBitOffset()
+ {
+ return dataBitOffset;
+ }
+
+ public int getScanlineStride()
+ {
+ return scanlineStride;
+ }
+
+ public int getPixelBitStride()
+ {
+ return numberOfBits;
+ }
+
+
+ public SampleModel createSubsetSampleModel(int[] bands)
+ {
+ int numBands = bands.length;
+ if (numBands != 1)
+ throw new RasterFormatException("MultiPixelPackedSampleModel only"
+ + " supports one band");
+
+ return new MultiPixelPackedSampleModel(dataType, width, height,
+ numberOfBits, scanlineStride,
+ dataBitOffset);
+ }
+
+ /**
+ * Extract one pixel and return in an array of transfer type.
+ *
+ * Extracts the pixel at x, y from data and stores into the 0th index of the
+ * array obj, since there is only one band. If obj is null, a new array of
+ * getTransferType() is created.
+ *
+ * @param x The x-coordinate of the pixel rectangle to store in <code>obj</code>.
+ * @param y The y-coordinate of the pixel rectangle to store in <code>obj</code>.
+ * @param obj The primitive array to store the pixels into or null to force creation.
+ * @param data The DataBuffer that is the source of the pixel data.
+ * @return The primitive array containing the pixel data.
+ * @see java.awt.image.SampleModel#getDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)
+ */
+ public Object getDataElements(int x, int y, Object obj,
+ DataBuffer data)
+ {
+ int pixel = getSample(x, y, 0, data);
+ switch (getTransferType())
+ {
+ case DataBuffer.TYPE_BYTE:
+ if (obj == null) obj = new byte[1];
+ ((byte[])obj)[0] = (byte)pixel;
+ return obj;
+ case DataBuffer.TYPE_USHORT:
+ if (obj == null) obj = new short[1];
+ ((short[])obj)[0] = (short)pixel;
+ return obj;
+ case DataBuffer.TYPE_INT:
+ if (obj == null) obj = new int[1];
+ ((int[])obj)[0] = pixel;
+ return obj;
+ default:
+ // Seems like the only sensible thing to do.
+ throw new ClassCastException();
+ }
+ }
+
+ public int[] getPixel(int x, int y, int[] iArray, DataBuffer data)
+ {
+ if (iArray == null) iArray = new int[1];
+ iArray[0] = getSample(x, y, 0, data);
+
+ return iArray;
+ }
+
+ public int[] getPixels(int x, int y, int w, int h, int[] iArray,
+ DataBuffer data)
+ {
+ int offset = getOffset(x, y);
+ if (iArray == null) iArray = new int[w*h];
+ int outOffset = 0;
+ for (y=0; y<h; y++)
+ {
+ int lineOffset = offset;
+ for (x=0; x<w;)
+ {
+ int samples = data.getElem(lineOffset++);
+ for (int b=0; b<numElems && x<w; b++)
+ {
+ iArray[outOffset++] = (samples & bitMasks[b]) >>> bitOffsets[b];
+ x++;
+ }
+ }
+ offset += scanlineStride;
+ }
+ return iArray;
+ }
+
+ public int getSample(int x, int y, int b, DataBuffer data)
+ {
+ int pos =
+ ((dataBitOffset + x * numberOfBits) % elemBits) / numberOfBits;
+ int offset = getOffset(x, y);
+ int samples = data.getElem(offset);
+ return (samples & bitMasks[pos]) >>> bitOffsets[pos];
+ }
+
+ /**
+ * Set the pixel at x, y to the value in the first element of the primitive
+ * array obj.
+ *
+ * @param x The x-coordinate of the data elements in <code>obj</code>.
+ * @param y The y-coordinate of the data elements in <code>obj</code>.
+ * @param obj The primitive array containing the data elements to set.
+ * @param data The DataBuffer to store the data elements into.
+ * @see java.awt.image.SampleModel#setDataElements(int, int, int, int, java.lang.Object, java.awt.image.DataBuffer)
+ */
+ public void setDataElements(int x, int y, Object obj, DataBuffer data)
+ {
+ int transferType = getTransferType();
+ if (getTransferType() != data.getDataType())
+ {
+ throw new IllegalArgumentException("transfer type ("+
+ getTransferType()+"), "+
+ "does not match data "+
+ "buffer type (" +
+ data.getDataType() +
+ ").");
+ }
+
+ int offset = getOffset(x, y);
+
+ try
+ {
+ switch (transferType)
+ {
+ case DataBuffer.TYPE_BYTE:
+ {
+ DataBufferByte out = (DataBufferByte) data;
+ byte[] in = (byte[]) obj;
+ out.getData()[offset] = in[0];
+ return;
+ }
+ case DataBuffer.TYPE_USHORT:
+ {
+ DataBufferUShort out = (DataBufferUShort) data;
+ short[] in = (short[]) obj;
+ out.getData()[offset] = in[0];
+ return;
+ }
+ case DataBuffer.TYPE_INT:
+ {
+ DataBufferInt out = (DataBufferInt) data;
+ int[] in = (int[]) obj;
+ out.getData()[offset] = in[0];
+ return;
+ }
+ default:
+ throw new ClassCastException("Unsupported data type");
+ }
+ }
+ catch (ArrayIndexOutOfBoundsException aioobe)
+ {
+ String msg = "While writing data elements" +
+ ", x="+x+", y="+y+
+ ", width="+width+", height="+height+
+ ", scanlineStride="+scanlineStride+
+ ", offset="+offset+
+ ", data.getSize()="+data.getSize()+
+ ", data.getOffset()="+data.getOffset()+
+ ": " +
+ aioobe;
+ throw new ArrayIndexOutOfBoundsException(msg);
+ }
+ }
+
+ public void setPixel(int x, int y, int[] iArray, DataBuffer data)
+ {
+ setSample(x, y, 0, iArray[0], data);
+ }
+
+ public void setSample(int x, int y, int b, int s, DataBuffer data)
+ {
+ int bitpos =
+ ((dataBitOffset + x * numberOfBits) % elemBits) / numberOfBits;
+ int offset = getOffset(x, y);
+
+ s = s << bitOffsets[bitpos];
+ s = s & bitMasks[bitpos];
+
+ int sample = data.getElem(offset);
+ sample |= s;
+ data.setElem(offset, sample);
+ }
+
+ /**
+ * Creates a String with some information about this SampleModel.
+ * @return A String describing this SampleModel.
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ StringBuffer result = new StringBuffer();
+ result.append(getClass().getName());
+ result.append("[");
+ result.append("scanlineStride=").append(scanlineStride);
+ for(int i=0; i < bitMasks.length; i+=1)
+ {
+ result.append(", mask[").append(i).append("]=0x").append(Integer.toHexString(bitMasks[i]));
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+}
diff --git a/java/awt/image/PackedColorModel.java b/java/awt/image/PackedColorModel.java
index 2d8b0e1ab..1f18cf68e 100644
--- a/java/awt/image/PackedColorModel.java
+++ b/java/awt/image/PackedColorModel.java
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2002 Free Software Foundation
+/* Copyright (C) 2000, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -34,11 +34,13 @@ 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.image;
+import gnu.java.awt.BitMaskExtent;
+
import java.awt.Point;
import java.awt.color.ColorSpace;
-import gnu.java.awt.BitMaskExtent;
/**
* @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
diff --git a/java/awt/image/PixelGrabber.java b/java/awt/image/PixelGrabber.java
index fd5c24a86..da50d1f70 100644
--- a/java/awt/image/PixelGrabber.java
+++ b/java/awt/image/PixelGrabber.java
@@ -1,39 +1,39 @@
/* PixelGrabber.java -- retrieve a subset of an image's data
- Copyright (C) 1999, 2003 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., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 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. */
+ Copyright (C) 1999, 2003, 2004 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.image;
diff --git a/java/awt/image/Raster.java b/java/awt/image/Raster.java
index 4fd194e2a..0db5aa10f 100644
--- a/java/awt/image/Raster.java
+++ b/java/awt/image/Raster.java
@@ -154,6 +154,35 @@ public class Raster
return createWritableRaster(sm, location);
}
+ public static WritableRaster createPackedRaster(int dataType,
+ int w, int h,
+ int bands, int bitsPerBand,
+ Point location)
+ {
+ if (bands <= 0 || (bands * bitsPerBand > getTypeBits(dataType)))
+ throw new IllegalArgumentException();
+
+ SampleModel sm;
+
+ if (bands == 1)
+ sm = new MultiPixelPackedSampleModel(dataType, w, h, bitsPerBand);
+ else
+ {
+ int[] bandMasks = new int[bands];
+ int mask = 0x1;
+ for (int bits = bitsPerBand; --bits != 0;)
+ mask = (mask << 1) | 0x1;
+ for (int i = 0; i < bands; i++)
+ {
+ bandMasks[i] = mask;
+ mask <<= bitsPerBand;
+ }
+
+ sm = new SinglePixelPackedSampleModel(dataType, w, h, bandMasks);
+ }
+ return createWritableRaster(sm, location);
+ }
+
public static WritableRaster
createInterleavedRaster(DataBuffer dataBuffer, int w, int h,
int scanlineStride, int pixelStride,
@@ -329,6 +358,11 @@ public class Raster
return height;
}
+ public final int getNumBands()
+ {
+ return numBands;
+ }
+
public final int getNumDataElements()
{
return numDataElements;
@@ -472,5 +506,24 @@ public class Raster
return result.toString();
}
-
+
+ // Map from datatype to bits
+ private static int getTypeBits(int dataType)
+ {
+ switch (dataType)
+ {
+ case DataBuffer.TYPE_BYTE:
+ return 8;
+ case DataBuffer.TYPE_USHORT:
+ case DataBuffer.TYPE_SHORT:
+ return 16;
+ case DataBuffer.TYPE_INT:
+ case DataBuffer.TYPE_FLOAT:
+ return 32;
+ case DataBuffer.TYPE_DOUBLE:
+ return 64;
+ default:
+ return 0;
+ }
+ }
}
diff --git a/java/awt/image/RasterOp.java b/java/awt/image/RasterOp.java
index 57961808e..84d47c119 100644
--- a/java/awt/image/RasterOp.java
+++ b/java/awt/image/RasterOp.java
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2002 Free Software Foundation
+/* Copyright (C) 2000, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -34,11 +34,12 @@ 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.image;
+import java.awt.RenderingHints;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
-import java.awt.RenderingHints;
public interface RasterOp {
diff --git a/java/awt/image/RescaleOp.java b/java/awt/image/RescaleOp.java
new file mode 100644
index 000000000..9235e0e14
--- /dev/null
+++ b/java/awt/image/RescaleOp.java
@@ -0,0 +1,210 @@
+/* Copyright (C) 2004 Free Software Foundation
+
+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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.image;
+
+import java.awt.RenderingHints;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.util.Arrays;
+
+/**
+ * @author Jerry Quinn <jlquinn@optonline.net>
+ *
+ */
+public class RescaleOp implements BufferedImageOp, RasterOp
+{
+ private float[] scale;
+ private float[] offsets;
+ private RenderingHints hints = null;
+
+ public RescaleOp(float[] scaleFactors,
+ float[] offsets,
+ RenderingHints hints)
+ {
+ this.scale = scaleFactors;
+ this.offsets = offsets;
+ this.hints = hints;
+ }
+
+ public RescaleOp(float scaleFactor,
+ float offset,
+ RenderingHints hints)
+ {
+ scale = new float[]{ scaleFactor };
+ offsets = new float[]{offset};
+ this.hints = hints;
+ }
+
+ public final float[] getScaleFactors(float[] scaleFactors)
+ {
+ if (scaleFactors == null)
+ scaleFactors = new float[scale.length];
+ System.arraycopy(scale, 0, scaleFactors, 0, scale.length);
+ return scaleFactors;
+ }
+
+ public final float[] getOffsets(float[] offsets)
+ {
+ if (offsets == null)
+ offsets = new float[this.offsets.length];
+ System.arraycopy(this.offsets, 0, offsets, 0, this.offsets.length);
+ return offsets;
+ }
+
+ public final int getNumFactors() { return scale.length; }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.BufferedImageOp#getRenderingHints()
+ */
+ public RenderingHints getRenderingHints() { return hints; }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.BufferedImageOp#filter(java.awt.image.BufferedImage, java.awt.image.BufferedImage)
+ */
+ public BufferedImage filter(BufferedImage src, BufferedImage dst) {
+ // TODO Make sure premultiplied alpha is handled correctly.
+ // TODO See that color conversion is handled.
+ // TODO figure out how to use rendering hints.
+ if (scale.length != offsets.length)
+ throw new IllegalArgumentException();
+
+ ColorModel scm = src.getColorModel();
+ if (dst == null) dst = createCompatibleDestImage(src, null);
+
+ WritableRaster wsrc = src.getRaster();
+ WritableRaster wdst = dst.getRaster();
+
+ // Share constant across colors except alpha
+ if (scale.length == 1 || scale.length == scm.getNumColorComponents())
+ {
+ // Construct a raster that doesn't include an alpha band.
+ int[] subbands = new int[scm.getNumColorComponents()];
+ for (int i=0; i < subbands.length; i++) subbands[i] = i;
+ wsrc =
+ wsrc.createWritableChild(wsrc.minX, wsrc.minY, wsrc.width, wsrc.height,
+ wsrc.minX, wsrc.minY, subbands);
+ }
+ // else all color bands
+
+ filter(wsrc, wdst);
+ return dst;
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.RasterOp#filter(java.awt.image.Raster, java.awt.image.WritableRaster)
+ */
+ public WritableRaster filter(Raster src, WritableRaster dest) {
+ if (dest == null) dest = src.createCompatibleWritableRaster();
+
+ // Required sanity checks
+ if (src.numBands != dest.numBands || scale.length != offsets.length)
+ throw new IllegalArgumentException();
+ if (scale.length != 1 && scale.length != src.numBands)
+ throw new IllegalArgumentException();
+
+ // Create scaling arrays if needed
+ float[] lscale = scale;
+ float[] loff = offsets;
+ if (scale.length == 1)
+ {
+ lscale = new float[src.numBands];
+ Arrays.fill(lscale, scale[0]);
+ loff = new float[src.numBands];
+ Arrays.fill(loff, offsets[0]);
+ }
+
+ // TODO The efficiency here can be improved for various data storage
+ // patterns, aka SampleModels.
+ float[] pixel = new float[src.numBands];
+ for (int y = src.minY; y < src.height- src.minY; y++)
+ for (int x = src.minX; x < src.width - src.minX; x++)
+ {
+ src.getPixel(x, y, pixel);
+ for (int b = 0; b < src.numBands; b++)
+ pixel[b] = pixel[b] * lscale[b] + loff[b];
+ dest.setPixel(x, y, pixel);
+ }
+ return dest;
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.BufferedImageOp#createCompatibleDestImage(java.awt.image.BufferedImage, java.awt.image.ColorModel)
+ */
+ public BufferedImage createCompatibleDestImage(BufferedImage src,
+ ColorModel dstCM)
+ {
+ if (dstCM == null) dstCM = src.getColorModel();
+ WritableRaster wr = src.getRaster().createCompatibleWritableRaster();
+ BufferedImage image
+ = new BufferedImage(dstCM, wr, src.isPremultiplied, null);
+ return image;
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.RasterOp#createCompatibleDestRaster(java.awt.image.Raster)
+ */
+ public WritableRaster createCompatibleDestRaster(Raster src)
+ {
+ return src.createCompatibleWritableRaster();
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.BufferedImageOp#getBounds2D(java.awt.image.BufferedImage)
+ */
+ public Rectangle2D getBounds2D(BufferedImage src)
+ {
+ return src.getRaster().getBounds();
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.RasterOp#getBounds2D(java.awt.image.Raster)
+ */
+ public Rectangle2D getBounds2D(Raster src)
+ {
+ return src.getBounds();
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.BufferedImageOp#getPoint2D(java.awt.geom.Point2D, java.awt.geom.Point2D)
+ */
+ public Point2D getPoint2D(Point2D src, Point2D dst) {
+ if (dst == null) dst = (Point2D) src.clone();
+ else dst.setLocation(src);
+ return dst;
+ }
+
+}
diff --git a/java/awt/image/SinglePixelPackedSampleModel.java b/java/awt/image/SinglePixelPackedSampleModel.java
index 578500dbd..9f49d836d 100644
--- a/java/awt/image/SinglePixelPackedSampleModel.java
+++ b/java/awt/image/SinglePixelPackedSampleModel.java
@@ -59,6 +59,16 @@ public class SinglePixelPackedSampleModel extends SampleModel
int scanlineStride, int[] bitMasks)
{
super(dataType, w, h, bitMasks.length);
+
+ switch (dataType)
+ {
+ case DataBuffer.TYPE_BYTE:
+ case DataBuffer.TYPE_USHORT:
+ case DataBuffer.TYPE_INT:
+ break;
+ default:
+ throw new IllegalArgumentException("SinglePixelPackedSampleModel unsupported dataType");
+ }
this.scanlineStride = scanlineStride;
this.bitMasks = bitMasks;
diff --git a/java/awt/peer/MenuBarPeer.java b/java/awt/peer/MenuBarPeer.java
index 38f57ecdb..6018c41b3 100644
--- a/java/awt/peer/MenuBarPeer.java
+++ b/java/awt/peer/MenuBarPeer.java
@@ -43,7 +43,6 @@ import java.awt.Menu;
public interface MenuBarPeer extends MenuComponentPeer
{
void addHelpMenu(Menu menu);
- void addMenu(Menu menu);
void delMenu(int index);
} // interface MenuBarPeer
diff --git a/java/io/DeleteFileHelper.java b/java/io/DeleteFileHelper.java
index 4445c983e..b4e986d56 100644
--- a/java/io/DeleteFileHelper.java
+++ b/java/io/DeleteFileHelper.java
@@ -47,7 +47,7 @@ import java.util.ArrayList;
* @author Michael Koch (konqueror@gmx.de)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
-public final class DeleteFileHelper extends Thread
+final class DeleteFileHelper extends Thread
{
private static ArrayList<File> filesToDelete;
@@ -67,7 +67,8 @@ public final class DeleteFileHelper extends Thread
}
catch (IllegalStateException e)
{
- // Shutdown is already in progress, so we can't register ours.
+ // Shutdown is already in progress, so we can't
+ // register ours.
}
return null;
diff --git a/java/io/ObjectInputStream.java b/java/io/ObjectInputStream.java
index 9d5dfca64..c71f9ceee 100644
--- a/java/io/ObjectInputStream.java
+++ b/java/io/ObjectInputStream.java
@@ -51,7 +51,6 @@ import java.util.Arrays;
import java.util.Hashtable;
import java.util.Vector;
-
/**
* @author Tom Tromey (tromey@redhat.com)
* @author Jeroen Frijters (jeroen@frijters.net)
@@ -307,6 +306,9 @@ public class ObjectInputStream extends InputStream
Object obj = newObject(clazz, osc.firstNonSerializableParent);
int handle = assignNewHandle(obj);
+ Object prevObject = this.currentObject;
+ ObjectStreamClass prevObjectStreamClass = this.currentObjectStreamClass;
+
this.currentObject = obj;
ObjectStreamClass[] hierarchy =
inputGetObjectStreamClasses(clazz);
@@ -354,8 +356,8 @@ public class ObjectInputStream extends InputStream
}
}
- this.currentObject = null;
- this.currentObjectStreamClass = null;
+ this.currentObject = prevObject;
+ this.currentObjectStreamClass = prevObjectStreamClass;
ret_val = processResolution(osc, obj, handle);
break;
@@ -1795,7 +1797,8 @@ public class ObjectInputStream extends InputStream
*/
private static native ClassLoader currentClassLoader (SecurityManager sm);
- private void callReadMethod (Method readObject, Class klass, Object obj) throws IOException
+ private void callReadMethod (Method readObject, Class klass, Object obj)
+ throws ClassNotFoundException, IOException
{
try
{
@@ -1809,6 +1812,8 @@ public class ObjectInputStream extends InputStream
throw (RuntimeException) exception;
if (exception instanceof IOException)
throw (IOException) exception;
+ if (exception instanceof ClassNotFoundException)
+ throw (ClassNotFoundException) exception;
throw new IOException("Exception thrown from readObject() on " +
klass + ": " + exception.getClass().getName());
diff --git a/java/io/ObjectOutputStream.java b/java/io/ObjectOutputStream.java
index d86b26f16..ca6a1541a 100644
--- a/java/io/ObjectOutputStream.java
+++ b/java/io/ObjectOutputStream.java
@@ -338,6 +338,8 @@ public class ObjectOutputStream extends OutputStream
if (obj instanceof Serializable)
{
+ Object prevObject = this.currentObject;
+ ObjectStreamClass prevObjectStreamClass = this.currentObjectStreamClass;
currentObject = obj;
ObjectStreamClass[] hierarchy =
ObjectStreamClass.getObjectStreamClasses(clazz);
@@ -366,8 +368,8 @@ public class ObjectOutputStream extends OutputStream
}
}
- currentObject = null;
- currentObjectStreamClass = null;
+ this.currentObject = prevObject;
+ this.currentObjectStreamClass = prevObjectStreamClass;
currentPutField = null;
break;
}
diff --git a/java/lang/Comparable.java b/java/lang/Comparable.java
index d8b7b2a50..c8d8073d9 100644
--- a/java/lang/Comparable.java
+++ b/java/lang/Comparable.java
@@ -52,18 +52,19 @@ package java.lang;
*
* <p>Lists, arrays, and sets of objects that implement this interface can
* be sorted automatically, without the need for an explicit
- * {@link Comparator}. Note that <code>e1.compareTo(null)</code> should
- * throw an Exception; as should comparison between incompatible classes.
+ * {@link java.util.Comparator}. Note that <code>e1.compareTo(null)</code>
+ * should throw an Exception; as should comparison between incompatible
+ * classes.
*
* @author Geoff Berry
* @author Warren Levy <warrenl@cygnus.com>
- * @see Comparator
- * @see Collections#sort(List)
- * @see Arrays#sort(Object[])
- * @see SortedSet
- * @see SortedMap
- * @see TreeSet
- * @see TreeMap
+ * @see java.util.Comparator
+ * @see java.util.Collections#sort(java.util.List)
+ * @see java.util.Arrays#sort(Object[])
+ * @see java.util.SortedSet
+ * @see java.util.SortedMap
+ * @see java.util.TreeSet
+ * @see java.util.TreeMap
* @since 1.2
* @status updated to 1.5
*/
diff --git a/java/lang/Runtime.java b/java/lang/Runtime.java
index 44fa10bc2..52c46602c 100644
--- a/java/lang/Runtime.java
+++ b/java/lang/Runtime.java
@@ -664,19 +664,25 @@ public class Runtime
*/
public void load(String filename)
{
+ SecurityManager sm = securityManager; // Be thread-safe!
+ if (sm != null)
+ sm.checkLink(filename);
if (loadLib(filename) == 0)
throw new UnsatisfiedLinkError("Could not load library " + filename);
}
- // Private version of load(String) that doesn't throw Exception on
- // load error, but it does do security checks (which can throw
- // SecurityExceptions). Convenience method for early bootstrap
- // process.
- private int loadLib(String filename)
+ /**
+ * Do a security check on the filename and then load the native library.
+ *
+ * @param filename the file to load
+ * @return 0 on failure, nonzero on success
+ * @throws SecurityException if file read permission is denied
+ */
+ private static int loadLib(String filename)
{
SecurityManager sm = securityManager; // Be thread-safe!
if (sm != null)
- sm.checkLink(filename);
+ sm.checkRead(filename);
return VMRuntime.nativeLoad(filename);
}
@@ -702,6 +708,10 @@ public class Runtime
*/
public void loadLibrary(String libname)
{
+ SecurityManager sm = securityManager; // Be thread-safe!
+ if (sm != null)
+ sm.checkLink(libname);
+
String filename;
ClassLoader cl = VMSecurityManager.currentClassLoader();
if (cl != null)
@@ -709,15 +719,15 @@ public class Runtime
filename = cl.findLibrary(libname);
if (filename != null)
{
- // Use loadLib so no UnsatisfiedLinkError are thrown.
if (loadLib(filename) != 0)
return;
+ else
+ throw new UnsatisfiedLinkError("Could not load library " + filename);
}
}
filename = System.mapLibraryName(libname);
for (int i = 0; i < libpath.length; i++)
- // Use loadLib so no UnsatisfiedLinkError are thrown.
if (loadLib(libpath[i] + filename) != 0)
return;
diff --git a/java/lang/StackTraceElement.java b/java/lang/StackTraceElement.java
index d9e8a31b7..e1e07f3fb 100644
--- a/java/lang/StackTraceElement.java
+++ b/java/lang/StackTraceElement.java
@@ -77,7 +77,7 @@ public class StackTraceElement implements Serializable
*
* @serial the enclosing class, if known
*/
- private final String className;
+ private final String declaringClass;
/**
* The method name in the class, null if unknown.
@@ -106,7 +106,7 @@ public class StackTraceElement implements Serializable
{
this.fileName = fileName;
this.lineNumber = lineNumber;
- this.className = className;
+ this.declaringClass = className;
this.methodName = methodName;
this.isNative = isNative;
}
@@ -142,7 +142,7 @@ public class StackTraceElement implements Serializable
*/
public String getClassName()
{
- return className;
+ return declaringClass;
}
/**
@@ -183,9 +183,9 @@ public class StackTraceElement implements Serializable
public String toString()
{
StringBuffer sb = new StringBuffer();
- if (className != null)
+ if (declaringClass != null)
{
- sb.append(className);
+ sb.append(declaringClass);
if (methodName != null)
sb.append('.');
}
@@ -217,7 +217,7 @@ public class StackTraceElement implements Serializable
StackTraceElement e = (StackTraceElement) o;
return equals(fileName, e.fileName)
&& lineNumber == e.lineNumber
- && equals(className, e.className)
+ && equals(declaringClass, e.declaringClass)
&& equals(methodName, e.methodName);
}
@@ -230,7 +230,7 @@ public class StackTraceElement implements Serializable
*/
public int hashCode()
{
- return hashCode(fileName) ^ lineNumber ^ hashCode(className)
+ return hashCode(fileName) ^ lineNumber ^ hashCode(declaringClass)
^ hashCode(methodName);
}
diff --git a/java/lang/System.java b/java/lang/System.java
index 49e9ee0a4..115f6b6a8 100644
--- a/java/lang/System.java
+++ b/java/lang/System.java
@@ -624,6 +624,8 @@ public final class System
* @throws NullPointerException
* @throws SecurityException if permission is denied
* @since 1.5
+ * @specnote This method was deprecated in some JDK releases, but
+ * was restored in 1.5.
*/
public static String getenv(String name)
{
diff --git a/java/lang/Throwable.java b/java/lang/Throwable.java
index 0d7a9466a..5d29684fb 100644
--- a/java/lang/Throwable.java
+++ b/java/lang/Throwable.java
@@ -402,7 +402,7 @@ public class Throwable implements Serializable
private static class StaticData
{
- private final static String nl;
+ final static String nl;
static
{
diff --git a/java/net/Inet4Address.java b/java/net/Inet4Address.java
index 5b8ddc171..54643fb2e 100644
--- a/java/net/Inet4Address.java
+++ b/java/net/Inet4Address.java
@@ -55,6 +55,9 @@ import java.util.Arrays;
*/
public final class Inet4Address extends InetAddress
{
+ /**
+ * For compatability with Sun's JDK 1.4.2 rev. 5
+ */
static final long serialVersionUID = 3286316764910316507L;
/**
diff --git a/java/net/Socket.java b/java/net/Socket.java
index 8855958cf..80caced4e 100644
--- a/java/net/Socket.java
+++ b/java/net/Socket.java
@@ -479,7 +479,8 @@ public class Socket
/**
* Returns the local address to which this socket is bound. If this socket
- * is not connected, then <code>null</code> is returned.
+ * is not connected, then a wildcard address, for which
+ * @see isAnyLocalAddress() is <code>true</code>, is returned.
*
* @return The local address
*
@@ -488,7 +489,7 @@ public class Socket
public InetAddress getLocalAddress()
{
if (! isBound())
- return null;
+ return InetAddress.ANY_IF;
InetAddress addr = null;
diff --git a/java/net/URL.java b/java/net/URL.java
index 92ae1143a..e8899a5fd 100644
--- a/java/net/URL.java
+++ b/java/net/URL.java
@@ -407,6 +407,7 @@ public final class URL implements Serializable
host = context.host;
port = context.port;
file = context.file;
+ userInfo = context.userInfo;
if (file == null || file.length() == 0)
file = "/";
authority = context.authority;
@@ -421,6 +422,7 @@ public final class URL implements Serializable
host = context.host;
port = context.port;
file = context.file;
+ userInfo = context.userInfo;
if (file == null || file.length() == 0)
file = "/";
authority = context.authority;
@@ -622,6 +624,8 @@ public final class URL implements Serializable
*/
public String getUserInfo()
{
+ if (userInfo != null)
+ return userInfo;
int at = (host == null) ? -1 : host.indexOf('@');
return at < 0 ? null : host.substring(0, at);
}
diff --git a/java/net/URLClassLoader.java b/java/net/URLClassLoader.java
index 5c7b682b1..901a81fa4 100644
--- a/java/net/URLClassLoader.java
+++ b/java/net/URLClassLoader.java
@@ -35,6 +35,7 @@ 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.net;
import java.io.ByteArrayOutputStream;
@@ -59,7 +60,6 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
-
/**
* A secure class loader that can load classes and resources from
* multiple locations. Given an array of <code>URL</code>s this class
@@ -656,11 +656,12 @@ public class URLClassLoader extends SecureClassLoader
if (loader == null)
{
String file = newUrl.getFile();
+ String protocol = newUrl.getProtocol();
// Check that it is not a directory
if (! (file.endsWith("/") || file.endsWith(File.separator)))
loader = new JarURLLoader(this, newUrl);
- else if ("file".equals(newUrl.getProtocol()))
+ else if ("file".equals(protocol))
loader = new FileURLLoader(this, newUrl);
else
loader = new RemoteURLLoader(this, newUrl);
@@ -811,14 +812,18 @@ public class URLClassLoader extends SecureClassLoader
// And finally construct the class!
SecurityManager sm = System.getSecurityManager();
if (sm != null && securityContext != null)
- return (Class) AccessController.doPrivileged(new PrivilegedAction()
- {
- public Object run()
+ {
+ return (Class)AccessController.doPrivileged
+ (new PrivilegedAction()
{
- return defineClass(className, classData, 0,
- classData.length, source);
- }
- }, securityContext);
+ public Object run()
+ {
+ return defineClass(className, classData,
+ 0, classData.length,
+ source);
+ }
+ }, securityContext);
+ }
else
return defineClass(className, classData, 0, classData.length, source);
}
@@ -955,13 +960,17 @@ public class URLClassLoader extends SecureClassLoader
// If the file end in / it must be an directory.
if (file.endsWith("/") || file.endsWith(File.separator))
- // Grant permission to read everything in that directory and
- // all subdirectories.
- permissions.add(new FilePermission(file + "-", "read"));
+ {
+ // Grant permission to read everything in that directory and
+ // all subdirectories.
+ permissions.add(new FilePermission(file + "-", "read"));
+ }
else
- // It is a 'normal' file.
- // Grant permission to access that file.
- permissions.add(new FilePermission(file, "read"));
+ {
+ // It is a 'normal' file.
+ // Grant permission to access that file.
+ permissions.add(new FilePermission(file, "read"));
+ }
}
else
{
diff --git a/java/net/URLConnection.java b/java/net/URLConnection.java
index a4b8a9dc3..c9919e043 100644
--- a/java/net/URLConnection.java
+++ b/java/net/URLConnection.java
@@ -35,6 +35,7 @@ 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.net;
import java.io.IOException;
@@ -49,7 +50,6 @@ import java.util.Date;
import java.util.Locale;
import java.util.Map;
-
/**
* Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
@@ -84,8 +84,8 @@ import java.util.Map;
* by the actual content handlers as described in the description of that
* method.
*
- * @author Aaron M. Renn <arenn@urbanophile.com>
- * @author Warren Levy <warrenl@cygnus.com>
+ * @author Aaron M. Renn (arenn@urbanophile.com)
+ * @author Warren Levy (warrenl@cygnus.com)
*/
public abstract class URLConnection
{
@@ -160,13 +160,12 @@ public abstract class URLConnection
* This is the URL associated with this connection
*/
protected URL url;
-
private static SimpleDateFormat[] dateFormats;
private static boolean dateformats_initialized;
/* Cached ParsePosition, used when parsing dates. */
private ParsePosition position;
-
+
/**
* Creates a URL connection to a given URL. A real connection is not made.
* Use #connect to do this.
@@ -363,7 +362,7 @@ public abstract class URLConnection
{
if (! dateformats_initialized)
initializeDateFormats();
-
+
if (position == null)
position = new ParsePosition(0);
@@ -404,63 +403,46 @@ public abstract class URLConnection
}
/**
- * This method returns the content of the document pointed to by the URL
- * as an Object. The type of object depends on the MIME type of the
- * object and particular content hander loaded. Most text type content
- * handlers will return a subclass of InputStream. Images usually return
- * a class that implements ImageProducer. There is not guarantee what
- * type of object will be returned, however.
- * <p>
- * This class first determines the MIME type of the content, then creates
- * a ContentHandler object to process the input. If the ContentHandlerFactory
- * is set, then that object is called to load a content handler, otherwise
- * a class called gnu.java.net.content.&lt;content_type&gt; is tried.
- * The default class will also be used if the content handler factory returns
- * a null content handler.
- *
- * @exception IOException If an error occurs
+ * This method returns the content of the document pointed to by the
+ * URL as an Object. The type of object depends on the MIME type of
+ * the object and particular content hander loaded. Most text type
+ * content handlers will return a subclass of
+ * <code>InputStream</code>. Images usually return a class that
+ * implements <code>ImageProducer</code>. There is not guarantee
+ * what type of object will be returned, however.
+ *
+ * <p>This class first determines the MIME type of the content, then
+ * creates a ContentHandler object to process the input. If the
+ * <code>ContentHandlerFactory</code> is set, then that object is
+ * called to load a content handler, otherwise a class called
+ * gnu.java.net.content.&lt;content_type&gt; is tried. If this
+ * handler does not exist, the method will simple return the
+ * <code>InputStream</code> returned by
+ * <code>getInputStream()</code>. Note that the default
+ * implementation of <code>getInputStream()</code> throws a
+ * <code>UnknownServiceException</code> so subclasses are encouraged
+ * to override this method.</p>
+ *
+ * @exception IOException If an error with the connection occurs.
* @exception UnknownServiceException If the protocol does not support the
- * content type
+ * content type at all.
*/
public Object getContent() throws IOException
{
- // connect();
- String type = getContentType();
-
- // First try the factory
- ContentHandler ch = null;
+ if (!connected)
+ connect();
- if (factory != null)
- ch = factory.createContentHandler(type);
+ // FIXME: Doc indicates that other criteria should be applied as
+ // heuristics to determine the true content type, e.g. see
+ // guessContentTypeFromName() and guessContentTypeFromStream methods
+ // as well as FileNameMap class & fileNameMap field & get/set methods.
+ String type = getContentType();
+ ContentHandler ch = getContentHandler(type);
if (ch != null)
return ch.getContent(this);
- // Then try our default class
- try
- {
- Class cls =
- Class.forName("gnu.java.net.content." + type.replace('/', '.'));
-
- Object obj = cls.newInstance();
-
- if (! (obj instanceof ContentHandler))
- throw new UnknownServiceException(type);
-
- ch = (ContentHandler) obj;
- return ch.getContent(this);
- }
- catch (ClassNotFoundException e)
- {
- }
- catch (InstantiationException e)
- {
- }
- catch (IllegalAccessException e)
- {
- }
-
- throw new UnknownServiceException(type);
+ return getInputStream();
}
/**
@@ -926,7 +908,7 @@ public abstract class URLConnection
public static String guessContentTypeFromStream(InputStream is)
throws IOException
{
- return ("application/octet-stream");
+ return "application/octet-stream";
}
/**
@@ -957,9 +939,9 @@ public abstract class URLConnection
*
* @since 1.2
*/
- public static void setFileNameMap(FileNameMap map)
+ public static synchronized void setFileNameMap(FileNameMap map)
{
- // Throw an exception if an extant security mgr precludes
+ // Throw an exception if an extant security manager precludes
// setting the factory.
SecurityManager s = System.getSecurityManager();
if (s != null)
@@ -968,6 +950,53 @@ public abstract class URLConnection
fileNameMap = map;
}
+ private ContentHandler getContentHandler(String contentType)
+ {
+ // No content type so just handle it as the default.
+ if (contentType == null || contentType.equals(""))
+ return null;
+
+ ContentHandler handler = null;
+
+ // If a non-default factory has been set, use it.
+ if (factory != null)
+ handler = factory.createContentHandler(contentType);
+
+ // Then try our default class.
+ try
+ {
+ String typeClass = contentType.replace('/', '.');
+
+ // Deal with "Content-Type: text/html; charset=ISO-8859-1".
+ int parameterBegin = typeClass.indexOf(';');
+ if (parameterBegin >= 1)
+ typeClass = typeClass.substring(0, parameterBegin);
+
+ Class cls = Class.forName("gnu.java.net.content." + typeClass);
+ Object obj = cls.newInstance();
+
+ if (obj instanceof ContentHandler)
+ {
+ handler = (ContentHandler) obj;
+ return handler;
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ // Ignore.
+ }
+ catch (InstantiationException e)
+ {
+ // Ignore.
+ }
+ catch (IllegalAccessException e)
+ {
+ // Ignore.
+ }
+
+ return handler;
+ }
+
// We don't put these in a static initializer, because it creates problems
// with initializer co-dependency: SimpleDateFormat's constructors eventually
// depend on URLConnection (via the java.text.*Symbols classes).
diff --git a/java/nio/ByteBuffer.java b/java/nio/ByteBuffer.java
index 378e58827..e502e0031 100644
--- a/java/nio/ByteBuffer.java
+++ b/java/nio/ByteBuffer.java
@@ -260,11 +260,27 @@ public abstract class ByteBuffer extends Buffer
/**
* Calculates a hash code for this buffer.
+ *
+ * This is done with <code>int</code> arithmetic,
+ * where ** represents exponentiation, by this formula:<br>
+ * <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... +
+ * (s[limit()-1]+30)*31**(limit()-1)</code>.
+ * Where s is the buffer data. Note that the hashcode is dependent
+ * on buffer content, and therefore is not useful if the buffer
+ * content may change.
+ *
+ * @return the hash code
*/
public int hashCode ()
{
- // FIXME: Check what SUN calculates here.
- return super.hashCode ();
+ int hashCode = get(position()) + 31;
+ int multiplier = 1;
+ for (int i = position() + 1; i < limit(); ++i)
+ {
+ multiplier *= 31;
+ hashCode += (get(i) + 30)*multiplier;
+ }
+ return hashCode;
}
/**
diff --git a/java/nio/CharBuffer.java b/java/nio/CharBuffer.java
index 4ef257bed..700c56750 100644
--- a/java/nio/CharBuffer.java
+++ b/java/nio/CharBuffer.java
@@ -297,11 +297,25 @@ public abstract class CharBuffer extends Buffer
/**
* Calculates a hash code for this buffer.
+ *
+ * This is done with int arithmetic,
+ * where ** represents exponentiation, by this formula:<br>
+ * <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... +
+ * (s[limit()-1]+30)*31**(limit()-1)</code>.
+ * Where s is the buffer data. Note that the hashcode is dependent
+ * on buffer content, and therefore is not useful if the buffer
+ * content may change.
*/
public int hashCode ()
{
- // FIXME: Check what SUN calculates here.
- return super.hashCode ();
+ int hashCode = get(position()) + 31;
+ int multiplier = 1;
+ for (int i = position() + 1; i < limit(); ++i)
+ {
+ multiplier *= 31;
+ hashCode += (get(i) + 30)*multiplier;
+ }
+ return hashCode;
}
/**
diff --git a/java/nio/DoubleBuffer.java b/java/nio/DoubleBuffer.java
index 10055cd08..dd16ee049 100644
--- a/java/nio/DoubleBuffer.java
+++ b/java/nio/DoubleBuffer.java
@@ -243,11 +243,27 @@ public abstract class DoubleBuffer extends Buffer
/**
* Calculates a hash code for this buffer.
+ *
+ * This is done with <code>long</code> arithmetic,
+ * where ** represents exponentiation, by this formula:<br>
+ * <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... +
+ * (s[limit()-1]+30)*31**(limit()-1)</code>.
+ * Where s is the buffer data, in Double.doubleToLongBits() form
+ * Note that the hashcode is dependent on buffer content,
+ * and therefore is not useful if the buffer content may change.
+ *
+ * @return the hash code (casted to int)
*/
public int hashCode ()
{
- // FIXME: Check what SUN calculates here.
- return super.hashCode ();
+ long hashCode = Double.doubleToLongBits(get(position())) + 31;
+ long multiplier = 1;
+ for (int i = position() + 1; i < limit(); ++i)
+ {
+ multiplier *= 31;
+ hashCode += (Double.doubleToLongBits(get(i)) + 30)*multiplier;
+ }
+ return ((int)hashCode);
}
/**
diff --git a/java/nio/FloatBuffer.java b/java/nio/FloatBuffer.java
index 6d1950352..2ead8cbc4 100644
--- a/java/nio/FloatBuffer.java
+++ b/java/nio/FloatBuffer.java
@@ -243,11 +243,27 @@ public abstract class FloatBuffer extends Buffer
/**
* Calculates a hash code for this buffer.
+ *
+ * This is done with <code>int</code> arithmetic,
+ * where ** represents exponentiation, by this formula:<br>
+ * <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... +
+ * (s[limit()-1]+30)*31**(limit()-1)</code>.
+ * Where s is the buffer data, in Float.floatToIntBits() form
+ * Note that the hashcode is dependent on buffer content,
+ * and therefore is not useful if the buffer content may change.
+ *
+ * @return the hash code
*/
public int hashCode ()
{
- // FIXME: Check what SUN calculates here.
- return super.hashCode ();
+ int hashCode = Float.floatToIntBits(get(position())) + 31;
+ int multiplier = 1;
+ for (int i = position() + 1; i < limit(); ++i)
+ {
+ multiplier *= 31;
+ hashCode += (Float.floatToIntBits(get(i)) + 30)*multiplier;
+ }
+ return hashCode;
}
/**
diff --git a/java/nio/IntBuffer.java b/java/nio/IntBuffer.java
index 68a71db3b..814e0414b 100644
--- a/java/nio/IntBuffer.java
+++ b/java/nio/IntBuffer.java
@@ -243,11 +243,27 @@ public abstract class IntBuffer extends Buffer
/**
* Calculates a hash code for this buffer.
+ *
+ * This is done with <code>int</code> arithmetic,
+ * where ** represents exponentiation, by this formula:<br>
+ * <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... +
+ * (s[limit()-1]+30)*31**(limit()-1)</code>.
+ * Where s is the buffer data. Note that the hashcode is dependent
+ * on buffer content, and therefore is not useful if the buffer
+ * content may change.
+ *
+ * @return the hash code
*/
public int hashCode ()
{
- // FIXME: Check what SUN calculates here.
- return super.hashCode ();
+ int hashCode = get(position()) + 31;
+ int multiplier = 1;
+ for (int i = position() + 1; i < limit(); ++i)
+ {
+ multiplier *= 31;
+ hashCode += (get(i) + 30)*multiplier;
+ }
+ return hashCode;
}
/**
diff --git a/java/nio/LongBuffer.java b/java/nio/LongBuffer.java
index c4066b1d3..6e9ef34e8 100644
--- a/java/nio/LongBuffer.java
+++ b/java/nio/LongBuffer.java
@@ -243,11 +243,27 @@ public abstract class LongBuffer extends Buffer
/**
* Calculates a hash code for this buffer.
+ *
+ * This is done with <code>long</code> arithmetic,
+ * where ** represents exponentiation, by this formula:<br>
+ * <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... +
+ * (s[limit()-1]+30)*31**(limit()-1)</code>.
+ * Where s is the buffer data. Note that the hashcode is dependent
+ * on buffer content, and therefore is not useful if the buffer
+ * content may change.
+ *
+ * @return the hash code (casted to int)
*/
public int hashCode ()
{
- // FIXME: Check what SUN calculates here.
- return super.hashCode ();
+ long hashCode = get(position()) + 31;
+ long multiplier = 1;
+ for (int i = position() + 1; i < limit(); ++i)
+ {
+ multiplier *= 31;
+ hashCode += (get(i) + 30)*multiplier;
+ }
+ return ((int)hashCode);
}
/**
diff --git a/java/nio/ShortBuffer.java b/java/nio/ShortBuffer.java
index 083039101..db03076b6 100644
--- a/java/nio/ShortBuffer.java
+++ b/java/nio/ShortBuffer.java
@@ -243,11 +243,27 @@ public abstract class ShortBuffer extends Buffer
/**
* Calculates a hash code for this buffer.
+ *
+ * This is done with <code>int</code> arithmetic,
+ * where ** represents exponentiation, by this formula:<br>
+ * <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... +
+ * (s[limit()-1]+30)*31**(limit()-1)</code>.
+ * Where s is the buffer data. Note that the hashcode is dependent
+ * on buffer content, and therefore is not useful if the buffer
+ * content may change.
+ *
+ * @return the hash code
*/
public int hashCode ()
{
- // FIXME: Check what SUN calculates here.
- return super.hashCode ();
+ int hashCode = get(position()) + 31;
+ int multiplier = 1;
+ for (int i = position() + 1; i < limit(); ++i)
+ {
+ multiplier *= 31;
+ hashCode += (get(i) + 30)*multiplier;
+ }
+ return hashCode;
}
/**
diff --git a/java/security/BasicPermission.java b/java/security/BasicPermission.java
index b5ad225c7..446b9033f 100644
--- a/java/security/BasicPermission.java
+++ b/java/security/BasicPermission.java
@@ -81,9 +81,8 @@ public abstract class BasicPermission extends java.security.Permission
private static final long serialVersionUID = 6279438298436773498L;
/**
- * Create a new instance with the specified permission name. If the name
- * is empty, or contains an illegal wildcard character, an exception is
- * thrown.
+ * Create a new instance with the specified permission name. If the
+ * name is empty an exception is thrown.
*
* @param name the name of this permission
* @throws NullPointerException if name is null
@@ -92,12 +91,11 @@ public abstract class BasicPermission extends java.security.Permission
public BasicPermission(String name)
{
super(name);
- if (name.indexOf("*") != -1)
- {
- if ((! name.endsWith(".*") && ! name.equals("*"))
- || name.indexOf("*") != name.lastIndexOf("*"))
- throw new IllegalArgumentException("Bad wildcard: " + name);
- }
+
+ // This routine used to check for illegal wildcards, but no such
+ // requirement exists in the specification and Sun's runtime
+ // doesn't appear to do it.
+
if ("".equals(name))
throw new IllegalArgumentException("Empty name");
}
diff --git a/java/security/cert/X509CRLSelector.java b/java/security/cert/X509CRLSelector.java
new file mode 100644
index 000000000..a59791e67
--- /dev/null
+++ b/java/security/cert/X509CRLSelector.java
@@ -0,0 +1,445 @@
+/* X509CRLSelector.java -- selects X.509 CRLs by criteria.
+ Copyright (C) 2004 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.security.cert;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import java.math.BigInteger;
+
+import java.security.AccessController;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.security.auth.x500.X500Principal;
+
+import gnu.java.security.action.GetPropertyAction;
+import gnu.java.security.der.DERReader;
+import gnu.java.security.der.DERValue;
+
+/**
+ * A class for matching X.509 certificate revocation lists by criteria.
+ *
+ * <p>Use of this class requires extensive knowledge of the Internet
+ * Engineering Task Force's Public Key Infrastructure (X.509). The primary
+ * document describing this standard is <a
+ * href="http://www.ietf.org/rfc/rfc3280.txt">RFC 3280: Internet X.509
+ * Public Key Infrastructure Certificate and Certificate Revocation List
+ * (CRL) Profile</a>.
+ *
+ * <p>Note that this class is not thread-safe. If multiple threads will
+ * use or modify this class then they need to synchronize on the object.
+ *
+ * @author Casey Marshall (csm@gnu.org)
+ */
+public class X509CRLSelector implements CRLSelector, Cloneable
+{
+
+ // Fields.
+ // -------------------------------------------------------------------------
+
+ private static final String CRL_NUMBER_ID = "2.5.29.20";
+
+ private List issuerNames;
+ private BigInteger maxCrlNumber;
+ private BigInteger minCrlNumber;
+ private Date date;
+ private X509Certificate cert;
+
+ // Constructor.
+ // -------------------------------------------------------------------------
+
+ /**
+ * Creates a new CRL selector with no criteria enabled; i.e., every CRL
+ * will be matched.
+ */
+ public X509CRLSelector()
+ {
+ }
+
+ // Instance methods.
+ // -------------------------------------------------------------------------
+
+ /**
+ * Add an issuer name to the set of issuer names criteria, as the DER
+ * encoded form.
+ *
+ * @param name The name to add, as DER bytes.
+ * @throws IOException If the argument is not a valid DER-encoding.
+ */
+ public void addIssuerName(byte[] name) throws IOException
+ {
+ X500Principal p = null;
+ try
+ {
+ p = new X500Principal(name);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ IOException ioe = new IOException("malformed name");
+ ioe.initCause(iae);
+ throw ioe;
+ }
+ if (issuerNames == null)
+ issuerNames = new LinkedList();
+ issuerNames.add(p);
+ }
+
+ /**
+ * Add an issuer name to the set of issuer names criteria, as a
+ * String representation.
+ *
+ * @param name The name to add.
+ * @throws IOException If the argument is not a valid name.
+ */
+ public void addIssuerName(String name) throws IOException
+ {
+ X500Principal p = null;
+ try
+ {
+ p = new X500Principal(name);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ IOException ioe = new IOException("malformed name: " + name);
+ ioe.initCause(iae);
+ throw ioe;
+ }
+ if (issuerNames == null)
+ issuerNames = new LinkedList();
+ issuerNames.add(p);
+ }
+
+ /**
+ * Sets the issuer names criterion. Pass <code>null</code> to clear this
+ * value. CRLs matched by this selector must have an issuer name in this
+ * set.
+ *
+ * @param names The issuer names.
+ * @throws IOException If any of the elements in the collection is not
+ * a valid name.
+ */
+ public void setIssuerNames(Collection names) throws IOException
+ {
+ if (names == null)
+ {
+ issuerNames = null;
+ return;
+ }
+ List l = new ArrayList(names.size());
+ for (Iterator it = names.iterator(); it.hasNext(); )
+ {
+ Object o = it.next();
+ if (o instanceof X500Principal)
+ l.add(o);
+ else if (o instanceof String)
+ {
+ try
+ {
+ l.add(new X500Principal((String) o));
+ }
+ catch (IllegalArgumentException iae)
+ {
+ IOException ioe = new IOException("malformed name: " + o);
+ ioe.initCause(iae);
+ throw ioe;
+ }
+ }
+ else if (o instanceof byte[])
+ {
+ try
+ {
+ l.add(new X500Principal((byte[]) o));
+ }
+ catch (IllegalArgumentException iae)
+ {
+ IOException ioe = new IOException("malformed name");
+ ioe.initCause(iae);
+ throw ioe;
+ }
+ }
+ else if (o instanceof InputStream)
+ {
+ try
+ {
+ l.add(new X500Principal((InputStream) o));
+ }
+ catch (IllegalArgumentException iae)
+ {
+ IOException ioe = new IOException("malformed name");
+ ioe.initCause(iae);
+ throw ioe;
+ }
+ }
+ else
+ throw new IOException("not a valid name: " +
+ (o != null ? o.getClass().getName() : "null"));
+
+ }
+ issuerNames = l;
+ }
+
+ /**
+ * Returns the set of issuer names that are matched by this selector,
+ * or <code>null</code> if this criteria is not set. The returned
+ * collection is not modifiable.
+ *
+ * @return The set of issuer names.
+ */
+ public Collection getIssuerNames()
+ {
+ if (issuerNames != null)
+ return Collections.unmodifiableList(issuerNames);
+ else
+ return null;
+ }
+
+ /**
+ * Returns the maximum value of the CRLNumber extension present in
+ * CRLs matched by this selector, or <code>null</code> if this
+ * criteria is not set.
+ *
+ * @return The maximum CRL number.
+ */
+ public BigInteger getMaxCRL()
+ {
+ return maxCrlNumber;
+ }
+
+ /**
+ * Returns the minimum value of the CRLNumber extension present in
+ * CRLs matched by this selector, or <code>null</code> if this
+ * criteria is not set.
+ *
+ * @return The minimum CRL number.
+ */
+ public BigInteger getMinCRL()
+ {
+ return minCrlNumber;
+ }
+
+ /**
+ * Sets the maximum value of the CRLNumber extension present in CRLs
+ * matched by this selector. Specify <code>null</code> to clear this
+ * criterion.
+ *
+ * @param maxCrlNumber The maximum CRL number.
+ */
+ public void setMaxCRLNumber(BigInteger maxCrlNumber)
+ {
+ this.maxCrlNumber = maxCrlNumber;
+ }
+
+ /**
+ * Sets the minimum value of the CRLNumber extension present in CRLs
+ * matched by this selector. Specify <code>null</code> to clear this
+ * criterion.
+ *
+ * @param minCrlNumber The minimum CRL number.
+ */
+ public void setMinCRLNumber(BigInteger minCrlNumber)
+ {
+ this.minCrlNumber = minCrlNumber;
+ }
+
+ /**
+ * Returns the date when this CRL must be valid; that is, the date
+ * must be after the thisUpdate date, but before the nextUpdate date.
+ * Returns <code>null</code> if this criterion is not set.
+ *
+ * @return The date.
+ */
+ public Date getDateAndTime()
+ {
+ return date != null ? (Date) date.clone() : null;
+ }
+
+ /**
+ * Sets the date at which this CRL must be valid. Specify
+ * <code>null</code> to clear this criterion.
+ *
+ * @param date The date.
+ */
+ public void setDateAndTime(Date date)
+ {
+ this.date = date != null ? (Date) date.clone() : null;
+ }
+
+ /**
+ * Returns the certificate being checked, or <code>null</code> if this
+ * value is not set.
+ *
+ * @return The certificate.
+ */
+ public X509Certificate getCertificateChecking()
+ {
+ return cert;
+ }
+
+ /**
+ * Sets the certificate being checked. This is not a criterion, but
+ * info used by certificate store implementations to aid in searching.
+ *
+ * @param cert The certificate.
+ */
+ public void setCertificateChecking(X509Certificate cert)
+ {
+ this.cert = cert;
+ }
+
+ /**
+ * Returns a string representation of this selector. The string will
+ * only describe the enabled criteria, so if none are enabled this will
+ * return a string that contains little else besides the class name.
+ *
+ * @return The string.
+ */
+ public String toString()
+ {
+ StringBuffer str = new StringBuffer(X509CRLSelector.class.getName());
+ GetPropertyAction getProp = new GetPropertyAction("line.separator");
+ String nl = (String) AccessController.doPrivileged(getProp);
+ String eol = ";" + nl;
+
+ str.append(" {").append(nl);
+ if (issuerNames != null)
+ str.append(" issuer names = ").append(issuerNames).append(eol);
+ if (maxCrlNumber != null)
+ str.append(" max CRL = ").append(maxCrlNumber).append(eol);
+ if (minCrlNumber != null)
+ str.append(" min CRL = ").append(minCrlNumber).append(eol);
+ if (date != null)
+ str.append(" date = ").append(date).append(eol);
+ if (cert != null)
+ str.append(" certificate = ").append(cert).append(eol);
+ str.append("}").append(nl);
+ return str.toString();
+ }
+
+ /**
+ * Checks a CRL against the criteria of this selector, returning
+ * <code>true</code> if the given CRL matches all the criteria.
+ *
+ * @param _crl The CRL being checked.
+ * @return True if the CRL matches, false otherwise.
+ */
+ public boolean match(CRL _crl)
+ {
+ if (!(_crl instanceof X509CRL))
+ return false;
+ X509CRL crl = (X509CRL) _crl;
+ if (issuerNames != null)
+ {
+ if (!issuerNames.contains(crl.getIssuerX500Principal()))
+ return false;
+ }
+ BigInteger crlNumber = null;
+ if (maxCrlNumber != null)
+ {
+ byte[] b = crl.getExtensionValue(CRL_NUMBER_ID);
+ if (b == null)
+ return false;
+ try
+ {
+ DERValue val = DERReader.read(b);
+ if (!(val.getValue() instanceof BigInteger))
+ return false;
+ crlNumber = (BigInteger) val.getValue();
+ }
+ catch (IOException ioe)
+ {
+ return false;
+ }
+ if (maxCrlNumber.compareTo(crlNumber) < 0)
+ return false;
+ }
+ if (minCrlNumber != null)
+ {
+ if (crlNumber == null)
+ {
+ byte[] b = crl.getExtensionValue(CRL_NUMBER_ID);
+ if (b == null)
+ return false;
+ try
+ {
+ DERValue val = DERReader.read(b);
+ if (!(val.getValue() instanceof BigInteger))
+ return false;
+ crlNumber = (BigInteger) val.getValue();
+ }
+ catch (IOException ioe)
+ {
+ return false;
+ }
+ }
+ if (minCrlNumber.compareTo(crlNumber) > 0)
+ return false;
+ }
+ if (date != null)
+ {
+ if (date.compareTo(crl.getThisUpdate()) < 0 ||
+ date.compareTo(crl.getNextUpdate()) > 0)
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Returns a copy of this object.
+ *
+ * @return The copy.
+ */
+ public Object clone()
+ {
+ try
+ {
+ return super.clone();
+ }
+ catch (CloneNotSupportedException shouldNotHappen)
+ {
+ throw new Error(shouldNotHappen);
+ }
+ }
+}
diff --git a/java/security/cert/X509CertSelector.java b/java/security/cert/X509CertSelector.java
new file mode 100644
index 000000000..c7914c140
--- /dev/null
+++ b/java/security/cert/X509CertSelector.java
@@ -0,0 +1,1111 @@
+/* X509CertSelector.java -- selects X.509 certificates by criteria.
+ Copyright (C) 2004 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.security.cert;
+
+import java.io.IOException;
+
+import java.math.BigInteger;
+
+import java.security.AccessController;
+import java.security.KeyFactory;
+import java.security.PublicKey;
+import java.security.spec.X509EncodedKeySpec;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import javax.security.auth.x500.X500Principal;
+
+import gnu.java.security.OID;
+import gnu.java.security.action.GetPropertyAction;
+
+/**
+ * A concrete implementation of {@link CertSelector} for X.509 certificates,
+ * which allows a number of criteria to be set when accepting certificates,
+ * from validity dates, to issuer and subject distinguished names, to some
+ * of the various X.509 extensions.
+ *
+ * <p>Use of this class requires extensive knowledge of the Internet
+ * Engineering Task Force's Public Key Infrastructure (X.509). The primary
+ * document describing this standard is <a
+ * href="http://www.ietf.org/rfc/rfc3280.txt">RFC 3280: Internet X.509
+ * Public Key Infrastructure Certificate and Certificate Revocation List
+ * (CRL) Profile</a>.
+ *
+ * <p>Note that this class is not thread-safe. If multiple threads will
+ * use or modify this class then they need to synchronize on the object.
+ *
+ * @author Casey Marshall (csm@gnu.org)
+ */
+public class X509CertSelector implements CertSelector, Cloneable
+{
+
+ // Constants and fields.
+ // -------------------------------------------------------------------------
+
+ private static final String AUTH_KEY_ID = "2.5.29.35";
+ private static final String SUBJECT_KEY_ID = "2.5.29.14";
+ private static final String NAME_CONSTRAINTS_ID = "2.5.29.30";
+
+ private int basicConstraints;
+ private X509Certificate cert;
+ private BigInteger serialNo;
+ private X500Principal issuer;
+ private X500Principal subject;
+ private byte[] subjectKeyId;
+ private byte[] authKeyId;
+ private boolean[] keyUsage;
+ private Date certValid;
+ private OID sigId;
+ private PublicKey subjectKey;
+ private X509EncodedKeySpec subjectKeySpec;
+ private Set keyPurposeSet;
+ private List altNames;
+ private boolean matchAllNames;
+ private byte[] nameConstraints;
+ private Set policy;
+
+ // Constructors.
+ // ------------------------------------------------------------------------
+
+ /**
+ * Creates a new X.509 certificate selector. The new selector will be
+ * empty, and will accept any certificate (provided that it is an
+ * {@link X509Certificate}).
+ */
+ public X509CertSelector()
+ {
+ basicConstraints = -1;
+ }
+
+ // Instance methods.
+ // ------------------------------------------------------------------------
+
+ /**
+ * Returns the certificate criterion, or <code>null</code> if this value
+ * was not set.
+ *
+ * @return The certificate.
+ */
+ public X509Certificate getCertificate()
+ {
+ return cert;
+ }
+
+ /**
+ * Sets the certificate criterion. If set, only certificates that are
+ * equal to the certificate passed here will be accepted.
+ *
+ * @param cert The certificate.
+ */
+ public void setCertificate(X509Certificate cert)
+ {
+ this.cert = cert;
+ }
+
+ /**
+ * Returns the serial number criterion, or <code>null</code> if this
+ * value was not set.
+ *
+ * @return The serial number.
+ */
+ public BigInteger getSerialNumber()
+ {
+ return serialNo;
+ }
+
+ /**
+ * Sets the serial number of the desired certificate. Only certificates that
+ * contain this serial number are accepted.
+ *
+ * @param serialNo The serial number.
+ */
+ public void setSerialNumber(BigInteger serialNo)
+ {
+ this.serialNo = serialNo;
+ }
+
+ /**
+ * Returns the issuer criterion as a string, or <code>null</code> if this
+ * value was not set.
+ *
+ * @return The issuer.
+ */
+ public String getIssuerAsString()
+ {
+ if (issuer != null)
+ return issuer.getName();
+ else
+ return null;
+ }
+
+ /**
+ * Returns the issuer criterion as a sequence of DER bytes, or
+ * <code>null</code> if this value was not set.
+ *
+ * @return The issuer.
+ */
+ public byte[] getIssuerAsBytes() throws IOException
+ {
+ if (issuer != null)
+ return issuer.getEncoded();
+ else
+ return null;
+ }
+
+ /**
+ * Sets the issuer, specified as a string representation of the issuer's
+ * distinguished name. Only certificates issued by this issuer will
+ * be accepted.
+ *
+ * @param name The string representation of the issuer's distinguished name.
+ * @throws IOException If the given name is incorrectly formatted.
+ */
+ public void setIssuer(String name) throws IOException
+ {
+ if (name != null)
+ {
+ try
+ {
+ issuer = new X500Principal(name);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ throw new IOException(iae.getMessage());
+ }
+ }
+ else
+ issuer = null;
+ }
+
+ /**
+ * Sets the issuer, specified as the DER encoding of the issuer's
+ * distinguished name. Only certificates issued by this issuer will
+ * be accepted.
+ *
+ * @param name The DER encoding of the issuer's distinguished name.
+ * @throws IOException If the given name is incorrectly formatted.
+ */
+ public void setIssuer(byte[] name) throws IOException
+ {
+ if (name != null)
+ {
+ try
+ {
+ issuer = new X500Principal(name);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ throw new IOException(iae.getMessage());
+ }
+ }
+ else
+ issuer = null;
+ }
+
+ /**
+ * Returns the subject criterion as a string, of <code>null</code> if
+ * this value was not set.
+ *
+ * @return The subject.
+ */
+ public String getSubjectAsString()
+ {
+ if (subject != null)
+ return subject.getName();
+ else
+ return null;
+ }
+
+ /**
+ * Returns the subject criterion as a sequence of DER bytes, or
+ * <code>null</code> if this value is not set.
+ *
+ * @return The subject.
+ */
+ public byte[] getSubjectAsBytes() throws IOException
+ {
+ if (subject != null)
+ return subject.getEncoded();
+ else
+ return null;
+ }
+
+ /**
+ * Sets the subject, specified as a string representation of the
+ * subject's distinguished name. Only certificates with the given
+ * subject will be accepted.
+ *
+ * @param name The string representation of the subject's distinguished name.
+ * @throws IOException If the given name is incorrectly formatted.
+ */
+ public void setSubject(String name) throws IOException
+ {
+ if (name != null)
+ {
+ try
+ {
+ subject = new X500Principal(name);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ throw new IOException(iae.getMessage());
+ }
+ }
+ else
+ subject = null;
+ }
+
+ /**
+ * Sets the subject, specified as the DER encoding of the subject's
+ * distinguished name. Only certificates with the given subject will
+ * be accepted.
+ *
+ * @param name The DER encoding of the subject's distinguished name.
+ * @throws IOException If the given name is incorrectly formatted.
+ */
+ public void setSubject(byte[] name) throws IOException
+ {
+ if (name != null)
+ {
+ try
+ {
+ subject = new X500Principal(name);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ throw new IOException(iae.getMessage());
+ }
+ }
+ else
+ subject = null;
+ }
+
+ /**
+ * Returns the subject key identifier criterion, or <code>null</code> if
+ * this value was not set. Note that the byte array is cloned to prevent
+ * modification.
+ *
+ * @return The subject key identifier.
+ */
+ public byte[] getSubjectKeyIdentifier()
+ {
+ if (subjectKeyId != null)
+ return (byte[]) subjectKeyId.clone();
+ else
+ return null;
+ }
+
+ /**
+ * Sets the subject key identifier criterion, or <code>null</code> to clear
+ * this criterion. Note that the byte array is cloned to prevent modification.
+ *
+ * @param subjectKeyId The subject key identifier.
+ */
+ public void setSubjectKeyIdentifier(byte[] subjectKeyId)
+ {
+ this.subjectKeyId = subjectKeyId != null ? (byte[]) subjectKeyId.clone() :
+ null;
+ }
+
+ /**
+ * Returns the authority key identifier criterion, or <code>null</code> if
+ * this value was not set. Note that the byte array is cloned to prevent
+ * modification.
+ *
+ * @return The authority key identifier.
+ */
+ public byte[] getAuthorityKeyIdentifier()
+ {
+ if (authKeyId != null)
+ return (byte[]) authKeyId.clone();
+ else
+ return null;
+ }
+
+ /**
+ * Sets the authority key identifier criterion, or <code>null</code> to clear
+ * this criterion. Note that the byte array is cloned to prevent modification.
+ *
+ * @param subjectKeyId The subject key identifier.
+ */
+ public void setAuthorityKeyIdentifier(byte[] authKeyId)
+ {
+ this.authKeyId = authKeyId != null ? (byte[]) authKeyId.clone() : null;
+ }
+
+ /**
+ * Returns the date at which certificates must be valid, or <code>null</code>
+ * if this criterion was not set.
+ *
+ * @return The target certificate valitity date.
+ */
+ public Date getCertificateValid()
+ {
+ if (certValid != null)
+ return (Date) certValid.clone();
+ else
+ return null;
+ }
+
+ /**
+ * Sets the date at which certificates must be valid. Specify
+ * <code>null</code> to clear this criterion.
+ *
+ * @param certValid The certificate validity date.
+ */
+ public void setCertificateValid(Date certValid)
+ {
+ this.certValid = certValid != null ? (Date) certValid.clone() : null;
+ }
+
+ /**
+ * This method, and its related X.509 certificate extension &mdash; the
+ * private key usage period &mdash; is not supported under the Internet
+ * PKI for X.509 certificates (PKIX), described in RFC 3280. As such, this
+ * method is not supported either.
+ *
+ * <p>Do not use this method. It is not deprecated, as it is not deprecated
+ * in the Java standard, but it is basically a no-operation and simply
+ * returns <code>null</code>.
+ *
+ * @return Null.
+ */
+ public Date getPrivateKeyValid()
+ {
+ return null;
+ }
+
+ /**
+ * This method, and its related X.509 certificate extension &mdash; the
+ * private key usage period &mdash; is not supported under the Internet
+ * PKI for X.509 certificates (PKIX), described in RFC 3280. As such, this
+ * method is not supported either.
+ *
+ * <p>Do not use this method. It is not deprecated, as it is not deprecated
+ * in the Java standard, but it is basically a no-operation.
+ *
+ * @param UNUSED Is silently ignored.
+ */
+ public void setPrivateKeyValid(Date UNUSED)
+ {
+ }
+
+ /**
+ * Returns the public key algorithm ID that matching certificates must have,
+ * or <code>null</code> if this criterion was not set.
+ *
+ * @return The public key algorithm ID.
+ */
+ public String getSubjectPublicKeyAlgID()
+ {
+ return String.valueOf(sigId);
+ }
+
+ /**
+ * Sets the public key algorithm ID that matching certificates must have.
+ * Specify <code>null</code> to clear this criterion.
+ *
+ * @param sigId The public key ID.
+ * @throws IOException If the specified ID is not a valid object identifier.
+ */
+ public void setSubjectPublicKeyAlgID(String sigId) throws IOException
+ {
+ if (sigId != null)
+ {
+ try
+ {
+ OID oid = new OID(sigId);
+ int[] comp = oid.getIDs();
+ if (!checkOid(comp))
+ throw new IOException("malformed OID: " + sigId);
+ this.sigId = oid;
+ }
+ catch (IllegalArgumentException iae)
+ {
+ IOException ioe = new IOException("malformed OID: " + sigId);
+ ioe.initCause(iae);
+ throw ioe;
+ }
+ }
+ else
+ this.sigId = null;
+ }
+
+ /**
+ * Returns the subject public key criterion, or <code>null</code> if this
+ * value is not set.
+ *
+ * @return The subject public key.
+ */
+ public PublicKey getSubjectPublicKey()
+ {
+ return subjectKey;
+ }
+
+ /**
+ * Sets the subject public key criterion as an opaque representation.
+ * Specify <code>null</code> to clear this criterion.
+ *
+ * @param key The public key.
+ */
+ public void setSubjectPublicKey(PublicKey key)
+ {
+ this.subjectKey = key;
+ if (key == null)
+ {
+ subjectKeySpec = null;
+ return;
+ }
+ try
+ {
+ KeyFactory enc = KeyFactory.getInstance("X.509");
+ subjectKeySpec = (X509EncodedKeySpec)
+ enc.getKeySpec(key, X509EncodedKeySpec.class);
+ }
+ catch (Exception x)
+ {
+ subjectKey = null;
+ subjectKeySpec = null;
+ }
+ }
+
+ /**
+ * Sets the subject public key criterion as a DER-encoded key. Specify
+ * <code>null</code> to clear this value.
+ *
+ * @param key The DER-encoded key bytes.
+ * @throws IOException If the argument is not a valid DER-encoded key.
+ */
+ public void setSubjectPublicKey(byte[] key) throws IOException
+ {
+ if (key == null)
+ {
+ subjectKey = null;
+ subjectKeySpec = null;
+ return;
+ }
+ try
+ {
+ subjectKeySpec = new X509EncodedKeySpec(key);
+ KeyFactory enc = KeyFactory.getInstance("X.509");
+ subjectKey = enc.generatePublic(subjectKeySpec);
+ }
+ catch (Exception x)
+ {
+ subjectKey = null;
+ subjectKeySpec = null;
+ IOException ioe = new IOException(x.getMessage());
+ ioe.initCause(x);
+ throw ioe;
+ }
+ }
+
+ /**
+ * Returns the public key usage criterion, or <code>null</code> if this
+ * value is not set. Note that the array is cloned to prevent modification.
+ *
+ * @return The public key usage.
+ */
+ public boolean[] getKeyUsage()
+ {
+ if (keyUsage != null)
+ return (boolean[]) keyUsage.clone();
+ else
+ return null;
+ }
+
+ /**
+ * Sets the public key usage criterion. Specify <code>null</code> to clear
+ * this value.
+ *
+ * @param keyUsage The public key usage.
+ */
+ public void setKeyUsage(boolean[] keyUsage)
+ {
+ this.keyUsage = keyUsage != null ? (boolean[]) keyUsage.clone() : null;
+ }
+
+ /**
+ * Returns the set of extended key purpose IDs, as an unmodifiable set
+ * of OID strings. Returns <code>null</code> if this criterion is not
+ * set.
+ *
+ * @return The set of key purpose OIDs (strings).
+ */
+ public Set getExtendedKeyUsage()
+ {
+ if (keyPurposeSet != null)
+ return Collections.unmodifiableSet(keyPurposeSet);
+ else
+ return null;
+ }
+
+ /**
+ * Sets the extended key usage criterion, as a set of OID strings. Specify
+ * <code>null</code> to clear this value.
+ *
+ * @param keyPurposeSet The set of key purpose OIDs.
+ * @throws IOException If any element of the set is not a valid OID string.
+ */
+ public void setExtendedKeyUsage(Set keyPurposeSet) throws IOException
+ {
+ if (keyPurposeSet == null)
+ {
+ this.keyPurposeSet = null;
+ return;
+ }
+ Set s = new HashSet();
+ for (Iterator it = keyPurposeSet.iterator(); it.hasNext(); )
+ {
+ Object o = it.next();
+ if (!(o instanceof String))
+ throw new IOException("not a string: " + o);
+ try
+ {
+ OID oid = new OID((String) o);
+ int[] comp = oid.getIDs();
+ if (!checkOid(comp))
+ throw new IOException("malformed OID: " + o);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ IOException ioe = new IOException("malformed OID: " + o);
+ ioe.initCause(iae);
+ throw ioe;
+ }
+ }
+ this.keyPurposeSet = s;
+ }
+
+ /**
+ * Returns whether or not all specified alternative names must match.
+ * If false, a certificate is considered a match if <em>one</em> of the
+ * specified alternative names matches.
+ *
+ * @return true if all names must match.
+ */
+ public boolean getMatchAllSubjectAltNames()
+ {
+ return matchAllNames;
+ }
+
+ /**
+ * Sets whether or not all subject alternative names must be matched.
+ * If false, then a certificate will be considered a match if one
+ * alternative name matches.
+ *
+ * @param matchAllNames Whether or not all alternative names must be
+ * matched.
+ */
+ public void setMatchAllSubjectAltNames(boolean matchAllNames)
+ {
+ this.matchAllNames = matchAllNames;
+ }
+
+ /**
+ * Sets the subject alternative names critertion. Each element of the
+ * argument must be a {@link java.util.List} that contains exactly two
+ * elements: the first an {@link Integer}, representing the type of
+ * name, and the second either a {@link String} or a byte array,
+ * representing the name itself.
+ *
+ * @param altNames The alternative names.
+ * @throws IOException If any element of the argument is invalid.
+ */
+ public void setSubjectAlternativeNames(Collection altNames)
+ throws IOException
+ {
+ if (altNames == null)
+ {
+ this.altNames = null;
+ return;
+ }
+ List l = new ArrayList(altNames.size());
+ for (Iterator it = altNames.iterator(); it.hasNext(); )
+ {
+ Object o = it.next();
+ if (!(o instanceof List) || ((List) o).size() != 2 ||
+ !(((List) o).get(0) instanceof Integer) ||
+ !(((List) o).get(1) instanceof String) ||
+ !(((List) o).get(1) instanceof byte[]))
+ throw new IOException("illegal alternative name: " + o);
+ Integer i = (Integer) ((List) o).get(0);
+ if (i.intValue() < 0 || i.intValue() > 8)
+ throw new IOException("illegal alternative name: " + o +
+ ", bad id: " + i);
+ l.add(new ArrayList((List) o));
+ }
+ this.altNames = l;
+ }
+
+ /**
+ * Add a name to the subject alternative names criterion.
+ *
+ * @param id The type of name this is. Must be in the range [0,8].
+ * @param name The name.
+ * @throws IOException If the id is out of range, or if the name
+ * is null.
+ */
+ public void addSubjectAlternativeName(int id, String name)
+ throws IOException
+ {
+ if (id < 0 || id > 8 || name == null)
+ throw new IOException("illegal alternative name");
+ if (altNames == null)
+ altNames = new LinkedList();
+ ArrayList l = new ArrayList(2);
+ l.add(new Integer(id));
+ l.add(name);
+ altNames.add(l);
+ }
+
+ /**
+ * Add a name, as DER-encoded bytes, to the subject alternative names
+ * criterion.
+ *
+ * @param id The type of name this is.
+ */
+ public void addSubjectAlternativeName(int id, byte[] name)
+ throws IOException
+ {
+ if (id < 0 || id > 8 || name == null)
+ throw new IOException("illegal alternative name");
+ if (altNames == null)
+ altNames = new LinkedList();
+ ArrayList l = new ArrayList(2);
+ l.add(new Integer(id));
+ l.add(name);
+ altNames.add(l);
+ }
+
+ /**
+ * Returns the name constraints criterion, or <code>null</code> if this
+ * value is not set. Note that the byte array is cloned to prevent
+ * modification.
+ *
+ * @return The name constraints.
+ */
+ public byte[] getNameConstraints()
+ {
+ if (nameConstraints != null)
+ return (byte[]) nameConstraints.clone();
+ else
+ return null;
+ }
+
+ /**
+ * Sets the name constraints criterion; specify <code>null</code> to
+ * clear this criterion. Note that if non-null, the argument will be
+ * cloned to prevent modification.
+ *
+ * @param nameConstraints The new name constraints.
+ * @throws IOException If the argument is not a valid DER-encoded
+ * name constraints.
+ */
+ public void setNameConstraints(byte[] nameConstraints)
+ throws IOException
+ {
+ // FIXME check if the argument is valid.
+ this.nameConstraints = nameConstraints != null
+ ? (byte[]) nameConstraints.clone() : null;
+ }
+
+ /**
+ * Returns the basic constraints criterion, or -1 if this value is not set.
+ *
+ * @return The basic constraints.
+ */
+ public int getBasicConstraints()
+ {
+ return basicConstraints;
+ }
+
+ /**
+ * Sets the basic constraints criterion. Specify -1 to clear this parameter.
+ *
+ * @param basicConstraints The new basic constraints value.
+ */
+ public void setBasicConstraints(int basicConstraints)
+ {
+ if (basicConstraints < -1)
+ basicConstraints = -1;
+ this.basicConstraints = basicConstraints;
+ }
+
+ // The last two criteria not yet implemented are certificate policies
+ // and path-to-names. Both of these are somewhat advanced extensions
+ // (you could probably count the applications that actually use them
+ // on one hand), and they both have no support in the X509Certificate
+ // class.
+ //
+ // Not having support in X509Certificate is not always a problem; for
+ // example, we can compare DER-encoded values as byte arrays for some
+ // extensions. We can't, however, compare them if they are specified
+ // in a set (as policies are). We need to parse the actual value in the
+ // certificate, and check it against the specified set.
+
+ // FIXME
+// public void setPolicy(Set policy) throws IOException
+// {
+// if (policy != null)
+// {
+// for (Iterator it = policy.iterator(); it.hasNext(); )
+// try
+// {
+// OID oid = new OID((String) it.next());
+// int[] i = oid.getIDs();
+// if (!checkOid(i))
+// throw new IOException("invalid OID");
+// }
+// catch (Exception x)
+// {
+// throw new IOException("invalid OID");
+// }
+// }
+// this.policy = policy != null ? new HashSet(policy) : null;
+// }
+
+ // FIXME
+// public void setPathToNames(Collection names) throws IOException
+// {
+// if (names == null)
+// {
+// this.names = null;
+// return;
+// }
+// for (Iterator it = names.iterator(); it.hasNext(); )
+// {
+// try
+// {
+// List l = (List) it.next();
+// if (l.get(1) instanceof String)
+// addPathToName(((Integer)l.get(0)).intValue(), (String)l.get(1));
+// else
+// addPathToName(((Integer)l.get(0)).intValue(), (byte[])l.get(1));
+// }
+// catch (Exception x)
+// {
+// this.names = null;
+// throw new IOException("invalid names");
+// }
+// }
+// }
+
+ // FIXME
+// public void addPathToName(int id, String name) throws IOException
+// {
+// }
+
+ // FIXME
+// public void addPathToName(int id, byte[] name) throws IOException
+// {
+// }
+
+ // FIXME
+// public Collection getSubjectAlternativeNames()
+// {
+// return null;
+// }
+
+ // FIXME
+// public Set getPolicy()
+// {
+// return null;
+// }
+
+ // FIXME
+// public Collection getPathToNames()
+// {
+// return null;
+// }
+
+ /**
+ * Match a certificate. This method will check the given certificate
+ * against all the enabled criteria of this selector, and will return
+ * <code>true</code> if the given certificate matches.
+ *
+ * @param certificate The certificate to check.
+ * @return true if the certificate matches all criteria.
+ */
+ public boolean match(Certificate certificate)
+ {
+ if (!(certificate instanceof X509Certificate))
+ return false;
+ X509Certificate cert = (X509Certificate) certificate;
+ if (this.cert != null)
+ {
+ try
+ {
+ byte[] e1 = this.cert.getEncoded();
+ byte[] e2 = cert.getEncoded();
+ if (!Arrays.equals(e1, e2))
+ return false;
+ }
+ catch (CertificateEncodingException cee)
+ {
+ return false;
+ }
+ }
+ if (serialNo != null)
+ {
+ if (!serialNo.equals(cert.getSerialNumber()))
+ return false;
+ }
+ if (certValid != null)
+ {
+ try
+ {
+ cert.checkValidity(certValid);
+ }
+ catch (CertificateException ce)
+ {
+ return false;
+ }
+ }
+ if (issuer != null)
+ {
+ if (!issuer.equals(cert.getIssuerX500Principal()))
+ return false;
+ }
+ if (subject != null)
+ {
+ if (!subject.equals(cert.getSubjectX500Principal()))
+ return false;
+ }
+ if (sigId != null)
+ {
+ if (!sigId.equals(cert.getSigAlgOID()))
+ return false;
+ }
+ if (subjectKeyId != null)
+ {
+ byte[] b = cert.getExtensionValue(SUBJECT_KEY_ID);
+ if (!Arrays.equals(b, subjectKeyId))
+ return false;
+ }
+ if (authKeyId != null)
+ {
+ byte[] b = cert.getExtensionValue(AUTH_KEY_ID);
+ if (!Arrays.equals(b, authKeyId))
+ return false;
+ }
+ if (keyUsage != null)
+ {
+ boolean[] b = cert.getKeyUsage();
+ if (!Arrays.equals(b, keyUsage))
+ return false;
+ }
+ if (basicConstraints >= 0)
+ {
+ if (cert.getBasicConstraints() != basicConstraints)
+ return false;
+ }
+ if (keyPurposeSet != null)
+ {
+ List kp = null;
+ try
+ {
+ kp = cert.getExtendedKeyUsage();
+ }
+ catch (CertificateParsingException cpe)
+ {
+ return false;
+ }
+ if (kp == null)
+ return false;
+ for (Iterator it = keyPurposeSet.iterator(); it.hasNext(); )
+ {
+ if (!kp.contains(it.next()))
+ return false;
+ }
+ }
+ if (altNames != null)
+ {
+ Collection an = null;
+ try
+ {
+ an = cert.getSubjectAlternativeNames();
+ }
+ catch (CertificateParsingException cpe)
+ {
+ return false;
+ }
+ if (an == null)
+ return false;
+ int match = 0;
+ for (Iterator it = altNames.iterator(); it.hasNext(); )
+ {
+ List l = (List) it.next();
+ Integer id = (Integer) l.get(0);
+ String s = null;
+ byte[] b = null;
+ if (l.get(1) instanceof String)
+ s = (String) l.get(1);
+ else if (l.get(1) instanceof byte[])
+ b = (byte[]) l.get(1);
+ else
+ return false;
+ for (Iterator it2 = an.iterator(); it2.hasNext(); )
+ {
+ Object o = it2.next();
+ if (!(o instanceof List))
+ continue;
+ List l2 = (List) o;
+ if (l2.size() != 2)
+ continue;
+ if (!id.equals(l2.get(0)))
+ continue;
+ if (s != null && (l2.get(1) instanceof String) &&
+ s.equals(l2.get(1)))
+ match++;
+ else if (b != null && (l2.get(1) instanceof byte[]) &&
+ Arrays.equals(b, (byte[]) l2.get(1)))
+ match++;
+ }
+ if (match == 0 || (matchAllNames && match != altNames.size()))
+ return false;
+ }
+ }
+ if (nameConstraints != null)
+ {
+ byte[] nc = cert.getExtensionValue(NAME_CONSTRAINTS_ID);
+ if (!Arrays.equals(nameConstraints, nc))
+ return false;
+ }
+
+ // FIXME check policies.
+ // FIXME check path-to-names.
+
+ return true;
+ }
+
+ public String toString()
+ {
+ StringBuffer str = new StringBuffer(X509CertSelector.class.getName());
+ GetPropertyAction getProp = new GetPropertyAction("line.separator");
+ String nl = (String) AccessController.doPrivileged(getProp);
+ String eol = ";" + nl;
+ str.append(" {").append(nl);
+ if (cert != null)
+ str.append(" certificate = ").append(cert).append(eol);
+ if (basicConstraints >= 0)
+ str.append(" basic constraints = ").append(basicConstraints).append(eol);
+ if (serialNo != null)
+ str.append(" serial number = ").append(serialNo).append(eol);
+ if (certValid != null)
+ str.append(" valid date = ").append(certValid).append(eol);
+ if (issuer != null)
+ str.append(" issuer = ").append(issuer).append(eol);
+ if (subject != null)
+ str.append(" subject = ").append(subject).append(eol);
+ if (sigId != null)
+ str.append(" signature OID = ").append(sigId).append(eol);
+ if (subjectKey != null)
+ str.append(" subject public key = ").append(subjectKey).append(eol);
+ if (subjectKeyId != null)
+ {
+ str.append(" subject key ID = ");
+ for (int i = 0; i < subjectKeyId.length; i++)
+ {
+ str.append(Character.forDigit((subjectKeyId[i] & 0xF0) >>> 8, 16));
+ str.append(Character.forDigit((subjectKeyId[i] & 0x0F), 16));
+ if (i < subjectKeyId.length - 1)
+ str.append(':');
+ }
+ str.append(eol);
+ }
+ if (authKeyId != null)
+ {
+ str.append(" authority key ID = ");
+ for (int i = 0; i < authKeyId.length; i++)
+ {
+ str.append(Character.forDigit((authKeyId[i] & 0xF0) >>> 8, 16));
+ str.append(Character.forDigit((authKeyId[i] & 0x0F), 16));
+ if (i < authKeyId.length - 1)
+ str.append(':');
+ }
+ str.append(eol);
+ }
+ if (keyUsage != null)
+ {
+ str.append(" key usage = ");
+ for (int i = 0; i < keyUsage.length; i++)
+ str.append(keyUsage[i] ? '1' : '0');
+ str.append(eol);
+ }
+ if (keyPurposeSet != null)
+ str.append(" key purpose = ").append(keyPurposeSet).append(eol);
+ if (altNames != null)
+ str.append(" alternative names = ").append(altNames).append(eol);
+ if (nameConstraints != null)
+ str.append(" name constraints = <blob of data>").append(eol);
+ str.append("}").append(nl);
+ return str.toString();
+ }
+
+ public Object clone()
+ {
+ try
+ {
+ return super.clone();
+ }
+ catch (CloneNotSupportedException shouldNotHappen)
+ {
+ throw new Error(shouldNotHappen);
+ }
+ }
+
+ // Own methods.
+ // -------------------------------------------------------------------------
+
+ private static boolean checkOid(int[] oid)
+ {
+ return (oid != null && oid.length > 2 &&
+ (oid[0] >= 0 && oid[0] <= 2) && (oid[1] >= 0 && oid[1] <= 39));
+ }
+}
diff --git a/java/text/Format.java b/java/text/Format.java
index 7bc389eb7..6f15dc044 100644
--- a/java/text/Format.java
+++ b/java/text/Format.java
@@ -60,6 +60,9 @@ import java.io.Serializable;
*/
public abstract class Format implements Serializable, Cloneable
{
+ /**
+ * For compatability with Sun's JDK 1.4.2 rev. 5
+ */
static final long serialVersionUID = -299282585814624189L;
public static class Field extends AttributedCharacterIterator.Attribute
diff --git a/java/text/MessageFormat.java b/java/text/MessageFormat.java
index b12341255..1c681795f 100644
--- a/java/text/MessageFormat.java
+++ b/java/text/MessageFormat.java
@@ -165,7 +165,7 @@ public class MessageFormat extends Format
super("");
}
- private Field(String s)
+ protected Field(String s)
{
super(s);
}
diff --git a/java/util/Arrays.java b/java/util/Arrays.java
index b51a28b4b..e99c2c0e8 100644
--- a/java/util/Arrays.java
+++ b/java/util/Arrays.java
@@ -1020,7 +1020,7 @@ public class Arrays
/**
* Performs a recursive modified quicksort.
*
- * @param a the array to sort
+ * @param array the array to sort
* @param from the start index (inclusive)
* @param count the number of elements to sort
*/
@@ -1184,7 +1184,7 @@ public class Arrays
/**
* Performs a recursive modified quicksort.
*
- * @param a the array to sort
+ * @param array the array to sort
* @param from the start index (inclusive)
* @param count the number of elements to sort
*/
@@ -1348,7 +1348,7 @@ public class Arrays
/**
* Performs a recursive modified quicksort.
*
- * @param a the array to sort
+ * @param array the array to sort
* @param from the start index (inclusive)
* @param count the number of elements to sort
*/
@@ -1524,7 +1524,7 @@ public class Arrays
/**
* Performs a recursive modified quicksort.
*
- * @param a the array to sort
+ * @param array the array to sort
* @param from the start index (inclusive)
* @param count the number of elements to sort
*/
@@ -1700,7 +1700,7 @@ public class Arrays
/**
* Performs a recursive modified quicksort.
*
- * @param a the array to sort
+ * @param array the array to sort
* @param from the start index (inclusive)
* @param count the number of elements to sort
*/
@@ -1866,7 +1866,7 @@ public class Arrays
/**
* Performs a recursive modified quicksort.
*
- * @param a the array to sort
+ * @param array the array to sort
* @param from the start index (inclusive)
* @param count the number of elements to sort
*/
@@ -2036,7 +2036,7 @@ public class Arrays
/**
* Performs a recursive modified quicksort.
*
- * @param a the array to sort
+ * @param array the array to sort
* @param from the start index (inclusive)
* @param count the number of elements to sort
*/
@@ -2418,6 +2418,7 @@ public class Arrays
* with the supplied element.
*
* @param index The index at which to place the new object.
+ * @param element The new object.
* @return The object replaced by this operation.
*/
public E set(int index, E element)
@@ -2489,7 +2490,7 @@ public class Arrays
* is shrunk or enlarged to the size of the
* internal array, and filled with its objects.
*
- * @param The array to fill with the objects in this list.
+ * @param array The array to fill with the objects in this list.
* @return The array containing the objects in this list,
* which may or may not be == to array.
*/
diff --git a/java/util/Calendar.java b/java/util/Calendar.java
index fc49bf556..aa47d307d 100644
--- a/java/util/Calendar.java
+++ b/java/util/Calendar.java
@@ -42,6 +42,7 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
/**
@@ -437,6 +438,16 @@ public abstract class Calendar
return getInstance(TimeZone.getDefault(), locale);
}
+ /**
+ * Cache of locale->calendar-class mappings. This avoids having to do a ResourceBundle
+ * lookup for every getInstance call.
+ */
+ private static HashMap cache = new HashMap();
+
+ /** Preset argument types for calendar-class constructor lookup. */
+ private static Class[] ctorArgTypes
+ = new Class[] {TimeZone.class, Locale.class};
+
/**
* Creates a calendar representing the actual time, using the given
* time zone and locale.
@@ -445,29 +456,58 @@ public abstract class Calendar
*/
public static synchronized Calendar getInstance(TimeZone zone, Locale locale)
{
- String calendarClassName = null;
- ResourceBundle rb = getBundle(locale);
- calendarClassName = rb.getString("calendarClass");
- if (calendarClassName != null)
+ Class calendarClass = (Class) cache.get(locale);
+ Throwable exception = null;
+
+ try
{
- try
+ if (calendarClass == null)
{
- Class calendarClass = Class.forName(calendarClassName);
- if (Calendar.class.isAssignableFrom(calendarClass))
+ ResourceBundle rb = getBundle(locale);
+ String calendarClassName = rb.getString("calendarClass");
+
+ if (calendarClassName != null)
{
- return (Calendar) calendarClass.getConstructor(
- new Class[] { TimeZone.class, Locale.class}
- ).newInstance(new Object[] {zone, locale} );
+ calendarClass = Class.forName(calendarClassName);
+ if (Calendar.class.isAssignableFrom(calendarClass))
+ cache.put(locale, calendarClass);
}
}
- catch (ClassNotFoundException ex) {}
- catch (IllegalAccessException ex) {}
- catch (NoSuchMethodException ex) {}
- catch (InstantiationException ex) {}
- catch (InvocationTargetException ex) {}
- // XXX should we ignore these errors or throw an exception ?
+
+ // GregorianCalendar is by far the most common case. Optimize by
+ // avoiding reflection.
+ if (calendarClass == GregorianCalendar.class)
+ return new GregorianCalendar(zone, locale);
+
+ if (Calendar.class.isAssignableFrom(calendarClass))
+ {
+ Constructor ctor = calendarClass.getConstructor(ctorArgTypes);
+ return (Calendar) ctor.newInstance(new Object[] {zone, locale});
+ }
+ }
+ catch (ClassNotFoundException ex)
+ {
+ exception = ex;
+ }
+ catch (IllegalAccessException ex)
+ {
+ exception = ex;
+ }
+ catch (NoSuchMethodException ex)
+ {
+ exception = ex;
+ }
+ catch (InstantiationException ex)
+ {
+ exception = ex;
+ }
+ catch (InvocationTargetException ex)
+ {
+ exception = ex;
}
- return new GregorianCalendar(zone, locale);
+
+ throw new RuntimeException("Error instantiating calendar for locale " +
+ locale, exception);
}
/**
diff --git a/java/util/Collections.java b/java/util/Collections.java
index 1b14c5db5..d4926272e 100644
--- a/java/util/Collections.java
+++ b/java/util/Collections.java
@@ -576,14 +576,26 @@ public class Collections
{
ListIterator<T> itr = ((List<T>) l).listIterator();
int i = 0;
+ T o = itr.next(); // Assumes list is not empty (see isSequential)
+ boolean forward = true;
while (low <= hi)
{
pos = (low + hi) >> 1;
if (i < pos)
- for ( ; i != pos; i++, itr.next());
+ {
+ if (!forward)
+ itr.next(); // Changing direction first.
+ for ( ; i != pos; i++, o = itr.next());
+ forward = true;
+ }
else
- for ( ; i != pos; i--, itr.previous());
- final int d = compare(key, itr.next(), c);
+ {
+ if (forward)
+ itr.previous(); // Changing direction first.
+ for ( ; i != pos; i--, o = itr.previous());
+ forward = false;
+ }
+ final int d = compare(key, o, c);
if (d == 0)
return pos;
else if (d < 0)
@@ -1117,6 +1129,8 @@ public class Collections
public static void rotate(List<? super Object> list, int distance)
{
int size = list.size();
+ if (size == 0)
+ return;
distance %= size;
if (distance == 0)
return;
@@ -1711,10 +1725,10 @@ public class Collections
{
T[] a = (T[]) l.toArray();
Arrays.sort(a, c);
- ListIterator<T> i = l.listIterator(a.length);
- for (int pos = a.length; --pos >= 0; )
+ ListIterator<T> i = l.listIterator();
+ for (int pos = 0, alen = a.length; pos < alen; pos++)
{
- i.previous();
+ i.next();
i.set(a[pos]);
}
}
diff --git a/java/util/TimeZone.java b/java/util/TimeZone.java
index cc3c7a3d2..1e06e5356 100644
--- a/java/util/TimeZone.java
+++ b/java/util/TimeZone.java
@@ -38,9 +38,7 @@ exception statement from your version. */
package java.util;
-import gnu.classpath.Configuration;
-import java.io.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.DateFormatSymbols;
@@ -90,14 +88,9 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable
/**
* Tries to get the default TimeZone for this system if not already
* set. It will call <code>getDefaultTimeZone(String)</code> with
- * the result of
- * <code>System.getProperty("user.timezone")</code>,
- * <code>System.getenv("TZ")</code>,
- * <code>readTimeZoneFile("/etc/timezone")</code>,
- * <code>readtzFile("/etc/localtime")</code> and
- * <code>getDefaultTimeZoneId()</code>
- * till a supported TimeZone is found.
- * If every method fails GMT is returned.
+ * the result of <code>System.getProperty("user.timezone")</code>.
+ * If that fails it calls <code>VMTimeZone.getDefaultTimeZoneId()</code>.
+ * If that also fails GMT is returned.
*/
private static synchronized TimeZone defaultZone()
{
@@ -109,11 +102,6 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable
{
public Object run()
{
- if (Configuration.INIT_LOAD_LIBRARY)
- {
- System.loadLibrary("javautil");
- }
-
TimeZone zone = null;
// Prefer System property user.timezone.
@@ -121,37 +109,9 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable
if (tzid != null && !tzid.equals(""))
zone = getDefaultTimeZone(tzid);
- // See if TZ environment variable is set and accessible.
- if (zone == null)
- {
- tzid = System.getenv("TZ");
- if (tzid != null && !tzid.equals(""))
- zone = getDefaultTimeZone(tzid);
- }
-
- // Try to parse /etc/timezone.
+ // Try platfom specific way.
if (zone == null)
- {
- tzid = readTimeZoneFile("/etc/timezone");
- if (tzid != null && !tzid.equals(""))
- zone = getDefaultTimeZone(tzid);
- }
-
- // Try to parse /etc/localtime
- if (zone == null)
- {
- tzid = readtzFile("/etc/localtime");
- if (tzid != null && !tzid.equals(""))
- zone = getDefaultTimeZone(tzid);
- }
-
- // Try some system specific way
- if (zone == null)
- {
- tzid = getDefaultTimeZoneId();
- if (tzid != null && !tzid.equals(""))
- zone = getDefaultTimeZone(tzid);
- }
+ zone = VMTimeZone.getDefaultTimeZoneId();
// Fall back on GMT.
if (zone == null)
@@ -843,238 +803,6 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable
}
/**
- * This method returns a time zone id string which is in the form
- * (standard zone name) or (standard zone name)(GMT offset) or
- * (standard zone name)(GMT offset)(daylight time zone name). The
- * GMT offset can be in seconds, or where it is evenly divisible by
- * 3600, then it can be in hours. The offset must be the time to
- * add to the local time to get GMT. If a offset is given and the
- * time zone observes daylight saving then the (daylight time zone
- * name) must also be given (otherwise it is assumed the time zone
- * does not observe any daylight savings).
- * <p>
- * The result of this method is given to getDefaultTimeZone(String)
- * which tries to map the time zone id to a known TimeZone. See
- * that method on how the returned String is mapped to a real
- * TimeZone object.
- */
- private static native String getDefaultTimeZoneId();
-
- /**
- * Tries to read the time zone name from a file. Only the first
- * consecutive letters, digits, slashes, dashes and underscores are
- * read from the file. If the file cannot be read or an IOException
- * occurs null is returned.
- * <p>
- * The /etc/timezone file is not standard, but a lot of systems have
- * it. If it exist the first line always contains a string
- * describing the timezone of the host of domain. Some systems
- * contain a /etc/TIMEZONE file which is used to set the TZ
- * environment variable (which is checked before /etc/timezone is
- * read).
- */
- private static String readTimeZoneFile(String file)
- {
- File f = new File(file);
- if (!f.exists())
- return null;
-
- InputStreamReader isr = null;
- try
- {
- FileInputStream fis = new FileInputStream(f);
- BufferedInputStream bis = new BufferedInputStream(fis);
- isr = new InputStreamReader(bis);
-
- StringBuffer sb = new StringBuffer();
- int i = isr.read();
- while (i != -1)
- {
- char c = (char) i;
- if (Character.isLetter(c) || Character.isDigit(c)
- || c == '/' || c == '-' || c == '_')
- {
- sb.append(c);
- i = isr.read();
- }
- else
- break;
- }
- return sb.toString();
- }
- catch (IOException ioe)
- {
- // Parse error, not a proper tzfile.
- return null;
- }
- finally
- {
- try
- {
- if (isr != null)
- isr.close();
- }
- catch (IOException ioe)
- {
- // Error while close, nothing we can do.
- }
- }
- }
-
- /**
- * Tries to read a file as a "standard" tzfile and return a time
- * zone id string as expected by <code>getDefaultTimeZone(String)</code>.
- * If the file doesn't exist, an IOException occurs or it isn't a tzfile
- * that can be parsed null is returned.
- * <p>
- * The tzfile structure (as also used by glibc) is described in the Olson
- * tz database archive as can be found at
- * <code>ftp://elsie.nci.nih.gov/pub/</code>.
- * <p>
- * At least the following platforms support the tzdata file format
- * and /etc/localtime (GNU/Linux, Darwin, Solaris and FreeBSD at
- * least). Some systems (like Darwin) don't start the file with the
- * required magic bytes 'TZif', this implementation can handle
- * that).
- */
- private static String readtzFile(String file)
- {
- File f = new File(file);
- if (!f.exists())
- return null;
-
- DataInputStream dis = null;
- try
- {
- FileInputStream fis = new FileInputStream(f);
- BufferedInputStream bis = new BufferedInputStream(fis);
- dis = new DataInputStream(bis);
-
- // Make sure we are reading a tzfile.
- byte[] tzif = new byte[4];
- dis.readFully(tzif);
- if (tzif[0] == 'T' && tzif[1] == 'Z'
- && tzif[2] == 'i' && tzif[3] == 'f')
- // Reserved bytes, ttisgmtcnt, ttisstdcnt and leapcnt
- skipFully(dis, 16 + 3 * 4);
- else
- // Darwin has tzdata files that don't start with the TZif marker
- skipFully(dis, 16 + 3 * 4 - 4);
-
- int timecnt = dis.readInt();
- int typecnt = dis.readInt();
- if (typecnt > 0)
- {
- int charcnt = dis.readInt();
- // Transition times plus indexed transition times.
- skipFully(dis, timecnt * (4 + 1));
-
- // Get last gmt_offset and dst/non-dst time zone names.
- int abbrind = -1;
- int dst_abbrind = -1;
- int gmt_offset = 0;
- while (typecnt-- > 0)
- {
- // gmtoff
- int offset = dis.readInt();
- int dst = dis.readByte();
- if (dst == 0)
- {
- abbrind = dis.readByte();
- gmt_offset = offset;
- }
- else
- dst_abbrind = dis.readByte();
- }
-
- // gmt_offset is the offset you must add to UTC/GMT to
- // get the local time, we need the offset to add to
- // the local time to get UTC/GMT.
- gmt_offset *= -1;
-
- // Turn into hours if possible.
- if (gmt_offset % 3600 == 0)
- gmt_offset /= 3600;
-
- if (abbrind >= 0)
- {
- byte[] names = new byte[charcnt];
- dis.readFully(names);
- int j = abbrind;
- while (j < charcnt && names[j] != 0)
- j++;
-
- String zonename = new String(names, abbrind, j - abbrind,
- "ASCII");
-
- String dst_zonename;
- if (dst_abbrind >= 0)
- {
- j = dst_abbrind;
- while (j < charcnt && names[j] != 0)
- j++;
- dst_zonename = new String(names, dst_abbrind,
- j - dst_abbrind, "ASCII");
- }
- else
- dst_zonename = "";
-
- // Only use gmt offset when necessary.
- // Also special case GMT+/- timezones.
- String offset_string;
- if ("".equals(dst_zonename)
- && (gmt_offset == 0
- || zonename.startsWith("GMT+")
- || zonename.startsWith("GMT-")))
- offset_string = "";
- else
- offset_string = Integer.toString(gmt_offset);
-
- String id = zonename + offset_string + dst_zonename;
-
- return id;
- }
- }
-
- // Something didn't match while reading the file.
- return null;
- }
- catch (IOException ioe)
- {
- // Parse error, not a proper tzfile.
- return null;
- }
- finally
- {
- try
- {
- if (dis != null)
- dis.close();
- }
- catch(IOException ioe)
- {
- // Error while close, nothing we can do.
- }
- }
- }
-
- /**
- * Skips the requested number of bytes in the given InputStream.
- * Throws EOFException if not enough bytes could be skipped.
- * Negative numbers of bytes to skip are ignored.
- */
- private static void skipFully(InputStream is, long l) throws IOException
- {
- while (l > 0)
- {
- long k = is.skip(l);
- if (k <= 0)
- throw new EOFException();
- l -= k;
- }
- }
-
- /**
* Maps a time zone name (with optional GMT offset and daylight time
* zone name) to one of the known time zones. This method called
* with the result of <code>System.getProperty("user.timezone")</code>
@@ -1111,7 +839,7 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable
* The standard time zone name for The Netherlands is "Europe/Amsterdam",
* but can also be given as "CET-1CEST".
*/
- private static TimeZone getDefaultTimeZone(String sysTimeZoneId)
+ static TimeZone getDefaultTimeZone(String sysTimeZoneId)
{
// First find start of GMT offset info and any Daylight zone name.
int startGMToffset = 0;
@@ -1119,7 +847,11 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable
for (int i = 0; i < sysTimeZoneIdLength && startGMToffset == 0; i++)
{
char c = sysTimeZoneId.charAt(i);
- if (c == '+' || c == '-' || Character.isDigit(c))
+ if (Character.isDigit(c))
+ startGMToffset = i;
+ else if ((c == '+' || c == '-')
+ && i + 1 < sysTimeZoneIdLength
+ && Character.isDigit(sysTimeZoneId.charAt(i + 1)))
startGMToffset = i;
}
@@ -1152,7 +884,7 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable
// Offset could be in hours or seconds. Convert to millis.
// The offset is given as the time to add to local time to get GMT
// we need the time to add to GMT to get localtime.
- if (gmtOffset < 24)
+ if (Math.abs(gmtOffset) < 24)
gmtOffset *= 60 * 60;
gmtOffset *= -1000;
}
diff --git a/java/util/TreeMap.java b/java/util/TreeMap.java
index e03887833..9ab90f77e 100644
--- a/java/util/TreeMap.java
+++ b/java/util/TreeMap.java
@@ -130,7 +130,7 @@ public class TreeMap<K, V> extends AbstractMap<K, V>
/**
* The root node of this TreeMap.
*/
- private transient Node root = nil;
+ private transient Node root;
/**
* The size of this TreeMap. Package visible for use by nested classes.
@@ -213,6 +213,7 @@ public class TreeMap<K, V> extends AbstractMap<K, V>
public TreeMap(Comparator<? super K> c)
{
comparator = c;
+ fabricateTree(0);
}
/**
@@ -851,7 +852,11 @@ public class TreeMap<K, V> extends AbstractMap<K, V>
private void fabricateTree(final int count)
{
if (count == 0)
- return;
+ {
+ root = nil;
+ size = 0;
+ return;
+ }
// We color every row of nodes black, except for the overflow nodes.
// I believe that this is the optimal arrangement. We construct the tree
diff --git a/java/util/logging/logging.properties b/java/util/logging/logging.properties
deleted file mode 100644
index e7aabf485..000000000
--- a/java/util/logging/logging.properties
+++ /dev/null
@@ -1,42 +0,0 @@
-# Logging Configuration
-# ---------------------
-# By setting properties in this file, you can change the behavior
-# of the java.util.logging framework. Some examples are listed below.
-#
-#
-# To change the logging threshold of all loggers to the value
-# java.util.logging.Level.CONFIG, un-comment the following line:
-#
-# .level=CONFIG
-#
-#
-# To change the logging threshold of all loggers in the "foo.bar"
-# namespace to java.util.logging.Level.FINEST, un-comment the follwing
-# line. This will also affect any children, such as "foo.bar.baz".
-#
-# foo.bar.level=FINEST
-#
-#
-# To register a FileHandler for the "foo.bar" namespace and its
-# children, un-comment the following line. By default, the FileHandler
-# will write XML-formatted messages into a file "java0.log" in the
-# user's home directory.
-#
-# foo.bar.handlers=java.util.logging.FileHandler
-#
-#
-# To make a FileHandler use plain text instead of XML, and to place
-# the log file into a different location (such as /tmp/myfile.log
-# or /var/tmp/myfile.log), un-comment the following:
-#
-# java.util.logging.FileHandler.pattern=%t/myfile.log
-# java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
-#
-#
-# Logging can be configured in many ways. For more information, please
-# look at the documentation of the java.util.logging package.
-
-
-# Send log records to System.err, default to INFO per documentation.
-handlers = java.util.logging.ConsoleHandler
-.level = INFO