diff options
author | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-03-10 21:46:48 +0000 |
---|---|---|
committer | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-03-10 21:46:48 +0000 |
commit | ce57ab760f69de6db452def7ffbf5b114a2d8694 (patch) | |
tree | ea38c56431c5d4528fb54254c3f8e50f517bede3 /libjava/classpath/java/awt | |
parent | 50996fe55769882de3f410896032c887f0ff0d04 (diff) | |
download | gcc-ce57ab760f69de6db452def7ffbf5b114a2d8694.tar.gz |
Imported GNU Classpath 0.90
* scripts/makemake.tcl: Set gnu/java/awt/peer/swing to ignore.
* gnu/classpath/jdwp/VMFrame.java (SIZE): New constant.
* java/lang/VMCompiler.java: Use gnu.java.security.hash.MD5.
* java/lang/Math.java: New override file.
* java/lang/Character.java: Merged from Classpath.
(start, end): Now 'int's.
(canonicalName): New field.
(CANONICAL_NAME, NO_SPACES_NAME, CONSTANT_NAME): New constants.
(UnicodeBlock): Added argument.
(of): New overload.
(forName): New method.
Updated unicode blocks.
(sets): Updated.
* sources.am: Regenerated.
* Makefile.in: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@111942 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/java/awt')
30 files changed, 3730 insertions, 2864 deletions
diff --git a/libjava/classpath/java/awt/AWTEvent.java b/libjava/classpath/java/awt/AWTEvent.java index ad9533f9c26..d10433cb3c3 100644 --- a/libjava/classpath/java/awt/AWTEvent.java +++ b/libjava/classpath/java/awt/AWTEvent.java @@ -39,6 +39,19 @@ exception statement from your version. */ package java.awt; +import java.awt.event.ActionEvent; +import java.awt.event.AdjustmentEvent; +import java.awt.event.ComponentEvent; +import java.awt.event.ContainerEvent; +import java.awt.event.FocusEvent; +import java.awt.event.InputMethodEvent; +import java.awt.event.InvocationEvent; +import java.awt.event.ItemEvent; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.awt.event.PaintEvent; +import java.awt.event.TextEvent; +import java.awt.event.WindowEvent; import java.util.EventObject; /** @@ -275,4 +288,94 @@ public abstract class AWTEvent extends EventObject { return consumed; } + + /** + * Converts an event id to the appropriate event mask. + * + * @param id the event id + * + * @return the event mask for the specified id + */ + static long eventIdToMask(int id) + { + long mask = 0; + switch (id) + { + case ActionEvent.ACTION_PERFORMED: + mask = ACTION_EVENT_MASK; + break; + case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED: + mask = ADJUSTMENT_EVENT_MASK; + break; + case ComponentEvent.COMPONENT_MOVED: + case ComponentEvent.COMPONENT_RESIZED: + case ComponentEvent.COMPONENT_SHOWN: + case ComponentEvent.COMPONENT_HIDDEN: + mask = COMPONENT_EVENT_MASK; + break; + case ContainerEvent.COMPONENT_ADDED: + case ContainerEvent.COMPONENT_REMOVED: + mask = CONTAINER_EVENT_MASK; + break; + case FocusEvent.FOCUS_GAINED: + case FocusEvent.FOCUS_LOST: + mask = FOCUS_EVENT_MASK; + break; + case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED: + case InputMethodEvent.CARET_POSITION_CHANGED: + mask = INPUT_METHOD_EVENT_MASK; + break; + case InvocationEvent.INVOCATION_DEFAULT: + mask = INVOCATION_EVENT_MASK; + break; + case ItemEvent.ITEM_STATE_CHANGED: + mask = ITEM_EVENT_MASK; + break; + case KeyEvent.KEY_TYPED: + case KeyEvent.KEY_PRESSED: + case KeyEvent.KEY_RELEASED: + mask = KEY_EVENT_MASK; + break; + case MouseEvent.MOUSE_CLICKED: + case MouseEvent.MOUSE_PRESSED: + case MouseEvent.MOUSE_RELEASED: + mask = MOUSE_EVENT_MASK; + break; + case MouseEvent.MOUSE_MOVED: + case MouseEvent.MOUSE_ENTERED: + case MouseEvent.MOUSE_EXITED: + case MouseEvent.MOUSE_DRAGGED: + mask = MOUSE_MOTION_EVENT_MASK; + break; + case MouseEvent.MOUSE_WHEEL: + mask = MOUSE_WHEEL_EVENT_MASK; + break; + case PaintEvent.PAINT: + case PaintEvent.UPDATE: + mask = PAINT_EVENT_MASK; + break; + case TextEvent.TEXT_VALUE_CHANGED: + mask = TEXT_EVENT_MASK; + break; + case WindowEvent.WINDOW_OPENED: + case WindowEvent.WINDOW_CLOSING: + case WindowEvent.WINDOW_CLOSED: + case WindowEvent.WINDOW_ICONIFIED: + case WindowEvent.WINDOW_DEICONIFIED: + case WindowEvent.WINDOW_ACTIVATED: + case WindowEvent.WINDOW_DEACTIVATED: + mask = WINDOW_EVENT_MASK; + break; + case WindowEvent.WINDOW_GAINED_FOCUS: + case WindowEvent.WINDOW_LOST_FOCUS: + mask = WINDOW_FOCUS_EVENT_MASK; + break; + case WindowEvent.WINDOW_STATE_CHANGED: + mask = WINDOW_STATE_EVENT_MASK; + break; + default: + mask = 0; + } + return mask; + } } // class AWTEvent diff --git a/libjava/classpath/java/awt/BasicStroke.java b/libjava/classpath/java/awt/BasicStroke.java index bb008e4c791..4eece75c995 100644 --- a/libjava/classpath/java/awt/BasicStroke.java +++ b/libjava/classpath/java/awt/BasicStroke.java @@ -1,5 +1,5 @@ /* BasicStroke.java -- - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -41,38 +41,89 @@ package java.awt; import java.util.Arrays; /** - * STUB CLASS ONLY + * A general purpose {@link Stroke} implementation that can represent a wide + * variety of line styles for use with subclasses of {@link Graphics2D}. + * <p> + * The line cap and join styles can be set using the options illustrated + * here: + * <p> + * <img src="doc-files/capjoin.png" width="350" height="180" + * alt="Illustration of line cap and join styles" /> + * <p> + * A dash array can be used to specify lines with alternating opaque and + * transparent sections. */ public class BasicStroke implements Stroke { + /** + * Indicates a mitered line join style. See the class overview for an + * illustration. + */ public static final int JOIN_MITER = 0; + + /** + * Indicates a rounded line join style. See the class overview for an + * illustration. + */ public static final int JOIN_ROUND = 1; + + /** + * Indicates a bevelled line join style. See the class overview for an + * illustration. + */ public static final int JOIN_BEVEL = 2; + /** + * Indicates a flat line cap style. See the class overview for an + * illustration. + */ public static final int CAP_BUTT = 0; + + /** + * Indicates a rounded line cap style. See the class overview for an + * illustration. + */ public static final int CAP_ROUND = 1; + + /** + * Indicates a square line cap style. See the class overview for an + * illustration. + */ public static final int CAP_SQUARE = 2; + /** The stroke width. */ private final float width; + + /** The line cap style. */ private final int cap; + + /** The line join style. */ private final int join; + + /** The miter limit. */ private final float limit; + + /** The dash array. */ private final float[] dash; + + /** The dash phase. */ private final float phase; /** - * Creates a basic stroke. + * Creates a new <code>BasicStroke</code> instance with the given attributes. * - * @param width May not be negative . - * @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE. - * @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER. - * @param miterlimit the limit to trim the miter join. The miterlimit must be + * @param width the line width (>= 0.0f). + * @param cap the line cap style (one of {@link #CAP_BUTT}, + * {@link #CAP_ROUND} or {@link #CAP_SQUARE}). + * @param join the line join style (one of {@link #JOIN_ROUND}, + * {@link #JOIN_BEVEL}, or {@link #JOIN_MITER}). + * @param miterlimit the limit to trim the miter join. The miterlimit must be * greater than or equal to 1.0f. * @param dash The array representing the dashing pattern. There must be at * least one non-zero entry. * @param dashPhase is negative and dash is not null. * - * @exception IllegalArgumentException If one input parameter doesn't meet + * @throws IllegalArgumentException If one input parameter doesn't meet * its needs. */ public BasicStroke(float width, int cap, int join, float miterlimit, @@ -122,15 +173,17 @@ public class BasicStroke implements Stroke } /** - * Creates a basic stroke. + * Creates a new <code>BasicStroke</code> instance with the given attributes. * - * @param width The width of the BasicStroke. May not be negative . - * @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE. - * @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER. + * @param width the line width (>= 0.0f). + * @param cap the line cap style (one of {@link #CAP_BUTT}, + * {@link #CAP_ROUND} or {@link #CAP_SQUARE}). + * @param join the line join style (one of {@link #JOIN_ROUND}, + * {@link #JOIN_BEVEL}, or {@link #JOIN_MITER}). * @param miterlimit the limit to trim the miter join. The miterlimit must be * greater than or equal to 1.0f. * - * @exception IllegalArgumentException If one input parameter doesn't meet + * @throws IllegalArgumentException If one input parameter doesn't meet * its needs. */ public BasicStroke(float width, int cap, int join, float miterlimit) @@ -139,15 +192,17 @@ public class BasicStroke implements Stroke } /** - * Creates a basic stroke. + * Creates a new <code>BasicStroke</code> instance with the given attributes. + * The miter limit defaults to <code>10.0</code>. * - * @param width The width of the BasicStroke. May not be nehative. - * @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE. - * @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER. + * @param width the line width (>= 0.0f). + * @param cap the line cap style (one of {@link #CAP_BUTT}, + * {@link #CAP_ROUND} or {@link #CAP_SQUARE}). + * @param join the line join style (one of {@link #JOIN_ROUND}, + * {@link #JOIN_BEVEL}, or {@link #JOIN_MITER}). * - * @exception IllegalArgumentException If one input parameter doesn't meet + * @throws IllegalArgumentException If one input parameter doesn't meet * its needs. - * @exception IllegalArgumentException FIXME */ public BasicStroke(float width, int cap, int join) { @@ -155,11 +210,17 @@ public class BasicStroke implements Stroke } /** - * Creates a basic stroke. - * - * @param width The width of the BasicStroke. + * Creates a new <code>BasicStroke</code> instance with the given line + * width. The default values are: + * <ul> + * <li>line cap style: {@link #CAP_SQUARE};</li> + * <li>line join style: {@link #JOIN_MITER};</li> + * <li>miter limit: <code>10.0f</code>. + * </ul> + * + * @param width the line width (>= 0.0f). * - * @exception IllegalArgumentException If width is negative. + * @throws IllegalArgumentException If <code>width</code> is negative. */ public BasicStroke(float width) { @@ -167,43 +228,92 @@ public class BasicStroke implements Stroke } /** - * Creates a basic stroke. + * Creates a new <code>BasicStroke</code> instance. The default values are: + * <ul> + * <li>line width: <code>1.0f</code>;</li> + * <li>line cap style: {@link #CAP_SQUARE};</li> + * <li>line join style: {@link #JOIN_MITER};</li> + * <li>miter limit: <code>10.0f</code>. + * </ul> */ public BasicStroke() { this(1, CAP_SQUARE, JOIN_MITER, 10, null, 0); } + /** + * Creates a shape representing the stroked outline of the given shape. + * THIS METHOD IS NOT YET IMPLEMENTED. + * + * @param s the shape. + */ public Shape createStrokedShape(Shape s) { + // FIXME: Implement this throw new Error("not implemented"); } + /** + * Returns the line width. + * + * @return The line width. + */ public float getLineWidth() { return width; } + /** + * Returns a code indicating the line cap style (one of {@link #CAP_BUTT}, + * {@link #CAP_ROUND}, {@link #CAP_SQUARE}). + * + * @return A code indicating the line cap style. + */ public int getEndCap() { return cap; } + /** + * Returns a code indicating the line join style (one of {@link #JOIN_BEVEL}, + * {@link #JOIN_MITER} or {@link #JOIN_ROUND}). + * + * @return A code indicating the line join style. + */ public int getLineJoin() { return join; } + /** + * Returns the miter limit. + * + * @return The miter limit. + */ public float getMiterLimit() { return limit; } + /** + * Returns the dash array, which defines the length of alternate opaque and + * transparent sections in lines drawn with this stroke. If + * <code>null</code>, a continuous line will be drawn. + * + * @return The dash array (possibly <code>null</code>). + */ public float[] getDashArray() { return dash; } + /** + * Returns the dash phase for the stroke. This is the offset from the start + * of a path at which the pattern defined by {@link #getDashArray()} is + * rendered. + * + * @return The dash phase. + */ public float getDashPhase() { return phase; @@ -215,6 +325,8 @@ public class BasicStroke implements Stroke * (converted to <code>int</code> first with * <code>Float.floatToIntBits()</code> if the value is a * <code>float</code>). + * + * @return The hash code. */ public int hashCode() { @@ -233,9 +345,18 @@ public class BasicStroke implements Stroke } /** - * Returns true if the given Object is an instance of BasicStroke - * and the width, cap, join, limit, dash array and phase are all - * equal. + * Compares this <code>BasicStroke</code> for equality with an arbitrary + * object. This method returns <code>true</code> if and only if: + * <ul> + * <li><code>o</code> is an instanceof <code>BasicStroke</code>;<li> + * <li>this object has the same width, line cap style, line join style, + * miter limit, dash array and dash phase as <code>o</code>.</li> + * </ul> + * + * @param o the object (<code>null</code> permitted). + * + * @return <code>true</code> if this stroke is equal to <code>o</code> and + * <code>false</code> otherwise. */ public boolean equals(Object o) { @@ -245,4 +366,4 @@ public class BasicStroke implements Stroke return width == s.width && cap == s.cap && join == s.join && limit == s.limit && Arrays.equals(dash, s.dash) && phase == s.phase; } -} // class BasicStroke +} diff --git a/libjava/classpath/java/awt/BorderLayout.java b/libjava/classpath/java/awt/BorderLayout.java index 7c8c582a96b..50061ec6771 100644 --- a/libjava/classpath/java/awt/BorderLayout.java +++ b/libjava/classpath/java/awt/BorderLayout.java @@ -460,27 +460,30 @@ public class BorderLayout implements LayoutManager2, java.io.Serializable } /** - * Lays out the specified container according to the constraints - * in this object. - * + * Lays out the specified container according to the constraints in this + * object. + * * @param target The container to lay out. */ public void layoutContainer(Container target) { - synchronized (target.getTreeLock ()) + synchronized (target.getTreeLock()) { Insets i = target.getInsets(); + int top = i.top; + int bottom = target.height - i.bottom; + int left = i.left; + int right = target.width - i.right; - ComponentOrientation orient = target.getComponentOrientation (); - boolean left_to_right = orient.isLeftToRight (); + boolean left_to_right = target.getComponentOrientation().isLeftToRight(); Component my_north = north; Component my_east = east; Component my_south = south; Component my_west = west; - // Note that we currently don't handle vertical layouts. Neither - // does JDK 1.3. + // Note that we currently don't handle vertical layouts. + // Neither does JDK 1.3. if (firstLine != null) my_north = firstLine; if (lastLine != null) @@ -500,65 +503,42 @@ public class BorderLayout implements LayoutManager2, java.io.Serializable my_west = lastItem; } - Dimension c = calcCompSize(center, PREF); - Dimension n = calcCompSize(my_north, PREF); - Dimension s = calcCompSize(my_south, PREF); - Dimension e = calcCompSize(my_east, PREF); - Dimension w = calcCompSize(my_west, PREF); - int targetWidth = target.getWidth(); - int targetHeight = target.getHeight(); - - /* - <-> hgap <-> hgap - +----------------------------+ } - |t | } i.top - | +----------------------+ | --- y1 } - | |n | | - | +----------------------+ | } vgap - | +---+ +----------+ +---+ | --- y2 } } - | |w | |c | |e | | } hh - | +---+ +----------+ +---+ | } vgap } - | +----------------------+ | --- y3 } - | |s | | - | +----------------------+ | } - | | } i.bottom - +----------------------------+ } - |x1 |x2 |x3 - <----------------------> - <--> ww <--> - i.left i.right - */ - - int x1 = i.left; - int x2 = x1 + w.width + (w.width == 0 ? 0 : hgap); - int x3; - if (targetWidth <= i.right + e.width) - x3 = x2 + w.width + (w.width == 0 ? 0 : hgap); - else - x3 = targetWidth - i.right - e.width; - int ww = targetWidth - i.right - i.left; - - int y1 = i.top; - int y2 = y1 + n.height + (n.height == 0 ? 0 : vgap); - int midh = Math.max(e.height, Math.max(w.height, c.height)); - int y3; - if (targetHeight <= i.bottom + s.height) - y3 = y2 + midh + vgap; - else - y3 = targetHeight - i.bottom - s.height; - int hh = y3-y2-(s.height == 0 ? 0 : vgap); - - setBounds(center, x2, y2, x3-x2-(w.width == 0 ? 0 : hgap), hh); - setBounds(my_north, x1, y1, ww, n.height); - setBounds(my_south, x1, y3, ww, s.height); - setBounds(my_west, x1, y2, w.width, hh); - setBounds(my_east, x3, y2, e.width, hh); + if (my_north != null) + { + Dimension n = calcCompSize(my_north, PREF); + my_north.setBounds(left, top, right - left, n.height); + top += n.height + vgap; + } + + if (my_south != null) + { + Dimension s = calcCompSize(my_south, PREF); + my_south.setBounds(left, bottom - s.height, right - left, s.height); + bottom -= s.height + vgap; + } + + if (my_east != null) + { + Dimension e = calcCompSize(my_east, PREF); + my_east.setBounds(right - e.width, top, e.width, bottom - top); + right -= e.width + hgap; + } + + if (my_west != null) + { + Dimension w = calcCompSize(my_west, PREF); + my_west.setBounds(left, top, w.width, bottom - top); + left += w.width + hgap; + } + + if (center != null) + center.setBounds(left, top, right - left, bottom - top); } } /** * Returns a string representation of this layout manager. - * + * * @return A string representation of this object. */ public String toString() @@ -566,20 +546,9 @@ public class BorderLayout implements LayoutManager2, java.io.Serializable return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]"; } - /** - * This is a convenience method to set the bounds on a component. - * If the indicated component is null, nothing is done. - */ - private void setBounds(Component comp, int x, int y, int w, int h) - { - if (comp == null) - return; - comp.setBounds(x, y, w, h); - } - private Dimension calcCompSize(Component comp, int what) { - if (comp == null || !comp.isVisible()) + if (comp == null || ! comp.isVisible()) return new Dimension(0, 0); if (what == MIN) return comp.getMinimumSize(); @@ -589,12 +558,12 @@ public class BorderLayout implements LayoutManager2, java.io.Serializable } /** - * This is a helper function used to compute the various sizes for - * this layout. + * This is a helper function used to compute the various sizes for this + * layout. */ private Dimension calcSize(Container target, int what) { - synchronized (target.getTreeLock ()) + synchronized (target.getTreeLock()) { Insets ins = target.getInsets(); diff --git a/libjava/classpath/java/awt/CardLayout.java b/libjava/classpath/java/awt/CardLayout.java index 8582c5f099b..8b3fea2ca23 100644 --- a/libjava/classpath/java/awt/CardLayout.java +++ b/libjava/classpath/java/awt/CardLayout.java @@ -117,7 +117,7 @@ public class CardLayout implements LayoutManager2, Serializable /** * Cause the first component in the container to be displayed. * - * @param parent The parent container + * @param parent The parent container, not <code>null</code>. */ public void first (Container parent) { @@ -181,7 +181,7 @@ public class CardLayout implements LayoutManager2, Serializable /** * Cause the last component in the container to be displayed. * - * @param parent The parent container + * @param parent The parent container, not <code>null</code>. */ public void last (Container parent) { @@ -247,7 +247,7 @@ public class CardLayout implements LayoutManager2, Serializable * this current card is the last one in the deck, the first * component is displayed. * - * @param parent The parent container + * @param parent The parent container, not <code>null</code>. */ public void next (Container parent) { @@ -271,7 +271,7 @@ public class CardLayout implements LayoutManager2, Serializable * If this current card is the first one in the deck, the last * component is displayed. * - * @param parent The parent container + * @param parent The parent container, not <code>null</code>. */ public void previous (Container parent) { @@ -321,13 +321,19 @@ public class CardLayout implements LayoutManager2, Serializable /** * Cause the named component to be shown. If the component name is - * unknown, this method does nothing. + * unknown or <code>null</code>, this method does nothing. * - * @param parent The parent container - * @param name The name of the component to show + * @param parent The parent container, not <code>null</code>. + * @param name The name of the component to show */ public void show (Container parent, String name) { + if (name == null) + return; + + if (parent.getLayout() != this) + throw new IllegalArgumentException("parent's layout is not this CardLayout"); + Object target = tab.get (name); if (target != null) { @@ -362,9 +368,15 @@ public class CardLayout implements LayoutManager2, Serializable * * @param parent The parent container * @param what The type of goto: FIRST, LAST, NEXT or PREV + * + * @throws IllegalArgumentException if parent has not this + * CardLayout set as its layout. */ private void gotoComponent (Container parent, int what) { + if (parent.getLayout() != this) + throw new IllegalArgumentException("parent's layout is not this CardLayout"); + synchronized (parent.getTreeLock ()) { int num = parent.ncomponents; diff --git a/libjava/classpath/java/awt/Checkbox.java b/libjava/classpath/java/awt/Checkbox.java index 93f60924723..eea443edf74 100644 --- a/libjava/classpath/java/awt/Checkbox.java +++ b/libjava/classpath/java/awt/Checkbox.java @@ -1,5 +1,6 @@ /* Checkbox.java -- An AWT checkbox widget - Copyright (C) 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2002, 2005, 2006 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -459,11 +460,14 @@ getState() public synchronized void setState(boolean state) { - this.state = state; - if (peer != null) + if (this.state != state) { - CheckboxPeer cp = (CheckboxPeer) peer; - cp.setState (state); + this.state = state; + if (peer != null) + { + CheckboxPeer cp = (CheckboxPeer) peer; + cp.setState (state); + } } } @@ -599,10 +603,15 @@ void dispatchEventImpl(AWTEvent e) { if (e.id <= ItemEvent.ITEM_LAST - && e.id >= ItemEvent.ITEM_FIRST - && (item_listeners != null - || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0)) - processEvent(e); + && e.id >= ItemEvent.ITEM_FIRST) + { + ItemEvent ie = (ItemEvent) e; + int itemState = ie.getStateChange(); + setState(itemState == ItemEvent.SELECTED ? true : false); + if (item_listeners != null + || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0) + processEvent(e); + } else super.dispatchEventImpl(e); } diff --git a/libjava/classpath/java/awt/Choice.java b/libjava/classpath/java/awt/Choice.java index df93c5b0742..2e55d19b2d5 100644 --- a/libjava/classpath/java/awt/Choice.java +++ b/libjava/classpath/java/awt/Choice.java @@ -468,15 +468,16 @@ getSelectedIndex() public synchronized void select(int index) { - if ((index < 0) || (index > getItemCount())) + if ((index < 0) || (index >= getItemCount())) throw new IllegalArgumentException("Bad index: " + index); - this.selectedIndex = index; - if (peer != null) - { + if (pItems.size() > 0) { + selectedIndex = index; ChoicePeer cp = (ChoicePeer) peer; - cp.select (index); - } + if (cp != null) { + cp.select(index); + } + } } /*************************************************************************/ @@ -573,18 +574,6 @@ processItemEvent(ItemEvent event) item_listeners.itemStateChanged(event); } -void -dispatchEventImpl(AWTEvent e) -{ - if (e.id <= ItemEvent.ITEM_LAST - && e.id >= ItemEvent.ITEM_FIRST - && (item_listeners != null - || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0)) - processEvent(e); - else - super.dispatchEventImpl(e); -} - /*************************************************************************/ /** diff --git a/libjava/classpath/java/awt/Component.java b/libjava/classpath/java/awt/Component.java index bd22ea3c984..de01fc1145b 100644 --- a/libjava/classpath/java/awt/Component.java +++ b/libjava/classpath/java/awt/Component.java @@ -1,5 +1,6 @@ /* Component.java -- a graphics component - Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation + Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2006 + Free Software Foundation This file is part of GNU Classpath. @@ -40,6 +41,7 @@ package java.awt; import java.awt.dnd.DropTarget; import java.awt.event.ActionEvent; +import java.awt.event.AdjustmentEvent; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.FocusEvent; @@ -900,7 +902,7 @@ public abstract class Component // Avoid NullPointerExceptions by creating a local reference. ComponentPeer currentPeer=peer; if (currentPeer != null) - currentPeer.setVisible(true); + currentPeer.show(); // The JDK repaints the component before invalidating the parent. // So do we. @@ -1388,18 +1390,20 @@ public abstract class Component int oldy = this.y; int oldwidth = this.width; int oldheight = this.height; - - if (this.x == x && this.y == y - && this.width == width && this.height == height) + + if (this.x == x && this.y == y && this.width == width + && this.height == height) return; - invalidate (); + + invalidate(); + this.x = x; this.y = y; this.width = width; this.height = height; if (peer != null) peer.setBounds (x, y, width, height); - + // Erase old bounds and repaint new bounds for lightweights. if (isLightweight() && isShowing()) { @@ -1598,16 +1602,18 @@ public abstract class Component public Dimension preferredSize() { if (prefSize == null) - if (peer == null) - return new Dimension(width, height); - else - prefSize = peer.getPreferredSize(); + { + if (peer == null) + prefSize = minimumSize(); + else + prefSize = peer.getPreferredSize(); + } return prefSize; } /** * Returns the component's minimum size. - * + * * @return the component's minimum size * @see #getPreferredSize() * @see LayoutManager @@ -1882,8 +1888,7 @@ public abstract class Component */ public void repaint() { - if (isShowing()) - repaint(0, 0, 0, width, height); + repaint(0, 0, 0, width, height); } /** @@ -1897,8 +1902,7 @@ public abstract class Component */ public void repaint(long tm) { - if (isShowing()) - repaint(tm, 0, 0, width, height); + repaint(tm, 0, 0, width, height); } /** @@ -1915,8 +1919,7 @@ public abstract class Component */ public void repaint(int x, int y, int w, int h) { - if (isShowing()) - repaint(0, x, y, w, h); + repaint(0, x, y, w, h); } /** @@ -2308,6 +2311,10 @@ public abstract class Component */ public final void dispatchEvent(AWTEvent e) { + Event oldEvent = translateEvent(e); + if (oldEvent != null) + postEvent (oldEvent); + // Some subclasses in the AWT package need to override this behavior, // hence the use of dispatchEventImpl(). dispatchEventImpl(e); @@ -3419,10 +3426,11 @@ public abstract class Component } /** - * Called to inform this component it has been added to a container. - * A native peer - if any - is created at this time. This method is - * called automatically by the AWT system and should not be called by - * user level code. + * Called when the parent of this Component is made visible or when + * the Component is added to an already visible Container and needs + * to be shown. A native peer - if any - is created at this + * time. This method is called automatically by the AWT system and + * should not be called by user level code. * * @see #isDisplayable() * @see #removeNotify() @@ -3431,6 +3439,8 @@ public abstract class Component { if (peer == null) peer = getToolkit().createComponent(this); + else if (parent != null && parent.isLightweight()) + new HeavyweightInLightweightListener(parent); /* Now that all the children has gotten their peers, we should have the event mask needed for this component and its lightweight subcomponents. */ @@ -4481,6 +4491,109 @@ p * <li>the set of backward traversal keys } /** + * Report a change in a bound property to any registered property listeners. + * + * @param propertyName the property that changed + * @param oldValue the old property value + * @param newValue the new property value + * + * @since 1.5 + */ + public void firePropertyChange(String propertyName, byte oldValue, + byte newValue) + { + if (changeSupport != null) + changeSupport.firePropertyChange(propertyName, new Byte(oldValue), + new Byte(newValue)); + } + + /** + * Report a change in a bound property to any registered property listeners. + * + * @param propertyName the property that changed + * @param oldValue the old property value + * @param newValue the new property value + * + * @since 1.5 + */ + public void firePropertyChange(String propertyName, char oldValue, + char newValue) + { + if (changeSupport != null) + changeSupport.firePropertyChange(propertyName, new Character(oldValue), + new Character(newValue)); + } + + /** + * Report a change in a bound property to any registered property listeners. + * + * @param propertyName the property that changed + * @param oldValue the old property value + * @param newValue the new property value + * + * @since 1.5 + */ + public void firePropertyChange(String propertyName, short oldValue, + short newValue) + { + if (changeSupport != null) + changeSupport.firePropertyChange(propertyName, new Short(oldValue), + new Short(newValue)); + } + + /** + * Report a change in a bound property to any registered property listeners. + * + * @param propertyName the property that changed + * @param oldValue the old property value + * @param newValue the new property value + * + * @since 1.5 + */ + public void firePropertyChange(String propertyName, long oldValue, + long newValue) + { + if (changeSupport != null) + changeSupport.firePropertyChange(propertyName, new Long(oldValue), + new Long(newValue)); + } + + /** + * Report a change in a bound property to any registered property listeners. + * + * @param propertyName the property that changed + * @param oldValue the old property value + * @param newValue the new property value + * + * @since 1.5 + */ + public void firePropertyChange(String propertyName, float oldValue, + float newValue) + { + if (changeSupport != null) + changeSupport.firePropertyChange(propertyName, new Float(oldValue), + new Float(newValue)); + } + + + /** + * Report a change in a bound property to any registered property listeners. + * + * @param propertyName the property that changed + * @param oldValue the old property value + * @param newValue the new property value + * + * @since 1.5 + */ + public void firePropertyChange(String propertyName, double oldValue, + double newValue) + { + if (changeSupport != null) + changeSupport.firePropertyChange(propertyName, new Double(oldValue), + new Double(newValue)); + } + + /** * Sets the text layout orientation of this component. New components default * to UNKNOWN (which behaves like LEFT_TO_RIGHT). This method affects only * the current component, while @@ -4597,7 +4710,7 @@ p * <li>the set of backward traversal keys */ static Event translateEvent (AWTEvent e) { - Component target = (Component) e.getSource (); + Object target = e.getSource (); Event translated = null; if (e instanceof InputEvent) @@ -4770,6 +4883,25 @@ p * <li>the set of backward traversal keys 0, 0, oldKey, oldMods); } } + else if (e instanceof AdjustmentEvent) + { + AdjustmentEvent ae = (AdjustmentEvent) e; + int type = ae.getAdjustmentType(); + int oldType; + if (type == AdjustmentEvent.BLOCK_DECREMENT) + oldType = Event.SCROLL_PAGE_UP; + else if (type == AdjustmentEvent.BLOCK_INCREMENT) + oldType = Event.SCROLL_PAGE_DOWN; + else if (type == AdjustmentEvent.TRACK) + oldType = Event.SCROLL_ABSOLUTE; + else if (type == AdjustmentEvent.UNIT_DECREMENT) + oldType = Event.SCROLL_LINE_UP; + else if (type == AdjustmentEvent.UNIT_INCREMENT) + oldType = Event.SCROLL_LINE_DOWN; + else + oldType = type; + translated = new Event(target, oldType, new Integer(ae.getValue())); + } else if (e instanceof ActionEvent) translated = new Event (target, Event.ACTION_EVENT, ((ActionEvent) e).getActionCommand ()); @@ -4790,16 +4922,16 @@ p * <li>the set of backward traversal keys void dispatchEventImpl(AWTEvent e) { - Event oldEvent = translateEvent (e); + // Give toolkit a chance to dispatch the event + // to globally registered listeners. + Toolkit.getDefaultToolkit().globalDispatchEvent(e); + // This boolean tells us not to process focus events when the focus // opposite component is the same as the focus component. boolean ignoreFocus = (e instanceof FocusEvent && ((FocusEvent)e).getComponent() == ((FocusEvent)e).getOppositeComponent()); - if (oldEvent != null) - postEvent (oldEvent); - if (eventTypeEnabled (e.id)) { // the trick we use to communicate between dispatch and redispatch @@ -4925,16 +5057,6 @@ p * <li>the set of backward traversal keys Rectangle r1 = queuedEvent.getUpdateRect(); Rectangle r2 = newEvent.getUpdateRect(); Rectangle union = r1.union(r2); - - int r1a = r1.width * r1.height; - int r2a = r2.width * r2.height; - int ua = union.width * union.height; - - if (ua > (r1a+r2a)*2) - return null; - /* The 2 factor should maybe be reconsidered. Perhaps 3/2 - would be better? */ - newEvent.setUpdateRect(union); return newEvent; } @@ -5014,9 +5136,76 @@ p * <li>the set of backward traversal keys s.writeObject(null); } - + // Nested classes. + + /** + * This class fixes the bounds for a Heavyweight component that + * is placed inside a Lightweight container. When the lightweight is + * moved or resized, setBounds for the lightweight peer does nothing. + * Therefore, it was never moved on the screen. This class is + * attached to the lightweight, and it adjusts the position and size + * of the peer when notified. + * This is the same for show and hide. + */ + class HeavyweightInLightweightListener + implements ComponentListener + { + + /** + * Constructor. Adds component listener to lightweight parent. + * + * @param parent - the lightweight container. + */ + public HeavyweightInLightweightListener(Container parent) + { + parent.addComponentListener(this); + } + + /** + * This method is called when the component is resized. + * + * @param event the <code>ComponentEvent</code> indicating the resize + */ + public void componentResized(ComponentEvent event) + { + // Nothing to do here, componentMoved will be called. + } + + /** + * This method is called when the component is moved. + * + * @param event the <code>ComponentEvent</code> indicating the move + */ + public void componentMoved(ComponentEvent event) + { + if (peer != null) + peer.setBounds(x, y, width, height); + } + + /** + * This method is called when the component is made visible. + * + * @param event the <code>ComponentEvent</code> indicating the visibility + */ + public void componentShown(ComponentEvent event) + { + if (isShowing()) + peer.show(); + } + /** + * This method is called when the component is hidden. + * + * @param event the <code>ComponentEvent</code> indicating the visibility + */ + public void componentHidden(ComponentEvent event) + { + if (!isShowing()) + peer.hide(); + } + } + /** * This class provides accessibility support for subclasses of container. * diff --git a/libjava/classpath/java/awt/Container.java b/libjava/classpath/java/awt/Container.java index 67f0ed184d4..41892caeafa 100644 --- a/libjava/classpath/java/awt/Container.java +++ b/libjava/classpath/java/awt/Container.java @@ -1,5 +1,6 @@ /* Container.java -- parent container class in AWT - Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005 Free Software Foundation + Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation This file is part of GNU Classpath. @@ -42,12 +43,10 @@ import java.awt.event.ComponentListener; import java.awt.event.ContainerEvent; import java.awt.event.ContainerListener; import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; import java.awt.peer.ComponentPeer; import java.awt.peer.ContainerPeer; import java.awt.peer.LightweightPeer; import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -62,8 +61,6 @@ import java.util.Set; import javax.accessibility.Accessible; -import gnu.java.awt.AWTUtilities; - /** * A generic window toolkit object that acts as a container for other objects. * Components are tracked in a list, and new elements are at the end of the @@ -88,11 +85,14 @@ public class Container extends Component Component[] component; LayoutManager layoutMgr; - LightweightDispatcher dispatcher; - Dimension maxSize; /** + * Keeps track if the Container was cleared during a paint/update. + */ + private boolean backCleared; + + /** * @since 1.4 */ boolean focusCycleRoot; @@ -101,7 +101,6 @@ public class Container extends Component /* Anything else is non-serializable, and should be declared "transient". */ transient ContainerListener containerListener; - transient PropertyChangeSupport changeSupport; /** The focus traversal policy that determines how focus is transferred between this Container and its children. */ @@ -187,25 +186,6 @@ public class Container extends Component } /** - * Swaps the components at position i and j, in the container. - */ - - protected void swapComponents (int i, int j) - { - synchronized (getTreeLock ()) - { - if (i < 0 - || i >= component.length - || j < 0 - || j >= component.length) - throw new ArrayIndexOutOfBoundsException (); - Component tmp = component[i]; - component[i] = component[j]; - component[j] = tmp; - } - } - - /** * Returns the insets for this container, which is the space used for * borders, the margin, etc. * @@ -385,6 +365,8 @@ public class Container extends Component // Notify the layout manager. if (layoutMgr != null) { + // If we have a LayoutManager2 the constraints are "real", + // otherwise they are the "name" of the Component to add. if (layoutMgr instanceof LayoutManager2) { LayoutManager2 lm2 = (LayoutManager2) layoutMgr; @@ -393,7 +375,7 @@ public class Container extends Component else if (constraints instanceof String) layoutMgr.addLayoutComponent((String) constraints, comp); else - layoutMgr.addLayoutComponent(null, comp); + layoutMgr.addLayoutComponent("", comp); } // We previously only sent an event when this container is showing. @@ -428,8 +410,7 @@ public class Container extends Component for (int j = 0; j < list.length; j++) r.removeComponentListener(list[j]); - if (r.isShowing()) - r.removeNotify(); + r.removeNotify(); System.arraycopy(component, index + 1, component, index, ncomponents - index - 1); @@ -777,16 +758,17 @@ public class Container extends Component * a superclass method so that lightweight components are properly * drawn. * - * @param g The graphics context for this paint job. + * @param g - The graphics context for this paint job. */ public void paint(Graphics g) { if (!isShowing()) return; - // Visit heavyweights as well, in case they were - // erased when we cleared the background for this container. - visitChildren(g, GfxPaintVisitor.INSTANCE, false); + // Visit heavyweights if the background was cleared + // for this container. + visitChildren(g, GfxPaintVisitor.INSTANCE, !backCleared); + backCleared = false; } /** @@ -817,8 +799,11 @@ public class Container extends Component // also not cleared. So we do a check on !(peer instanceof LightweightPeer) // instead. ComponentPeer p = peer; - if (p != null && !(p instanceof LightweightPeer)) - g.clearRect(0, 0, getWidth(), getHeight()); + if (p != null && ! (p instanceof LightweightPeer)) + { + g.clearRect(0, 0, getWidth(), getHeight()); + backCleared = true; + } paint(g); } @@ -1557,28 +1542,105 @@ public class Container extends Component if (orientation == null) throw new NullPointerException (); } - + public void addPropertyChangeListener (PropertyChangeListener listener) { - if (listener == null) - return; - - if (changeSupport == null) - changeSupport = new PropertyChangeSupport (this); - - changeSupport.addPropertyChangeListener (listener); + // TODO: Why is this overridden? + super.addPropertyChangeListener(listener); } - - public void addPropertyChangeListener (String name, + + public void addPropertyChangeListener (String propertyName, PropertyChangeListener listener) { - if (listener == null) - return; - - if (changeSupport == null) - changeSupport = new PropertyChangeSupport (this); + // TODO: Why is this overridden? + super.addPropertyChangeListener(propertyName, listener); + } + + + /** + * Sets the Z ordering for the component <code>comp</code> to + * <code>index</code>. Components with lower Z order paint above components + * with higher Z order. + * + * @param comp the component for which to change the Z ordering + * @param index the index to set + * + * @throws NullPointerException if <code>comp == null</code> + * @throws IllegalArgumentException if comp is an ancestor of this container + * @throws IllegalArgumentException if <code>index</code> is not in + * <code>[0, getComponentCount()]</code> for moving between + * containers or <code>[0, getComponentCount() - 1]</code> for moving + * inside this container + * @throws IllegalArgumentException if <code>comp == this</code> + * @throws IllegalArgumentException if <code>comp</code> is a + * <code>Window</code> + * + * @see #getComponentZOrder(Component) + * + * @since 1.5 + */ + public final void setComponentZOrder(Component comp, int index) + { + if (comp == null) + throw new NullPointerException("comp must not be null"); + if (comp instanceof Container && ((Container) comp).isAncestorOf(this)) + throw new IllegalArgumentException("comp must not be an ancestor of " + + "this"); + if (comp instanceof Window) + throw new IllegalArgumentException("comp must not be a Window"); + + if (comp == this) + throw new IllegalArgumentException("cannot add component to itself"); + + // FIXME: Implement reparenting. + if ( comp.getParent() != this) + throw new AssertionError("Reparenting is not implemented yet"); + else + { + // Find current component index. + int currentIndex = getComponentZOrder(comp); + if (currentIndex < index) + { + System.arraycopy(component, currentIndex + 1, component, + currentIndex, index - currentIndex); + } + else + { + System.arraycopy(component, index, component, index + 1, + currentIndex - index); + } + component[index] = comp; + } + } - changeSupport.addPropertyChangeListener (name, listener); + /** + * Returns the Z ordering index of <code>comp</code>. If <code>comp</code> + * is not a child component of this Container, this returns <code>-1</code>. + * + * @param comp the component for which to query the Z ordering + * + * @return the Z ordering index of <code>comp</code> or <code>-1</code> if + * <code>comp</code> is not a child of this Container + * + * @see #setComponentZOrder(Component, int) + * + * @since 1.5 + */ + public final int getComponentZOrder(Component comp) + { + int index = -1; + if (component != null) + { + for (int i = 0; i < component.length; i++) + { + if (component[i] == comp) + { + index = i; + break; + } + } + } + return index; } // Hidden helper methods. @@ -1600,17 +1662,17 @@ public class Container extends Component private void visitChildren(Graphics gfx, GfxVisitor visitor, boolean lightweightOnly) { - synchronized (getTreeLock ()) + synchronized (getTreeLock()) { for (int i = ncomponents - 1; i >= 0; --i) { Component comp = component[i]; boolean applicable = comp.isVisible() - && (comp.isLightweight() || !lightweightOnly); - + && (comp.isLightweight() || ! lightweightOnly); + if (applicable) visitChild(gfx, visitor, comp); - } + } } } @@ -1631,10 +1693,9 @@ public class Container extends Component Component comp) { Rectangle bounds = comp.getBounds(); - + if(!gfx.hitClip(bounds.x,bounds.y, bounds.width, bounds.height)) return; - Graphics g2 = gfx.create(bounds.x, bounds.y, bounds.width, bounds.height); try @@ -1649,17 +1710,18 @@ public class Container extends Component void dispatchEventImpl(AWTEvent e) { - // Give lightweight dispatcher a chance to handle it. - if (dispatcher != null && dispatcher.handleEvent (e)) - return; - - if ((e.id <= ContainerEvent.CONTAINER_LAST - && e.id >= ContainerEvent.CONTAINER_FIRST) - && (containerListener != null - || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0)) - processEvent(e); - else - super.dispatchEventImpl(e); + boolean dispatched = + LightweightDispatcher.getInstance().dispatchEvent(e); + if (! dispatched) + { + if ((e.id <= ContainerEvent.CONTAINER_LAST + && e.id >= ContainerEvent.CONTAINER_FIRST) + && (containerListener != null + || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0)) + processEvent(e); + else + super.dispatchEventImpl(e); + } } /** @@ -1743,15 +1805,6 @@ public class Container extends Component component[i].addNotify(); if (component[i].isLightweight ()) { - - // If we're not lightweight, and we just got a lightweight - // child, we need a lightweight dispatcher to feed it events. - if (!this.isLightweight() && dispatcher == null) - dispatcher = new LightweightDispatcher (this); - - if (dispatcher != null) - dispatcher.enableEvents(component[i].eventMask); - enableEvents(component[i].eventMask); if (peer != null && !isLightweight ()) enableEvents (AWTEvent.PAINT_EVENT_MASK); @@ -1998,229 +2051,3 @@ public class Container extends Component } // class AccessibleContainerHandler } // class AccessibleAWTContainer } // class Container - -/** - * There is a helper class implied from stack traces called - * LightweightDispatcher, but since it is not part of the public API, - * rather than mimic it exactly we write something which does "roughly - * the same thing". - */ -class LightweightDispatcher implements Serializable -{ - private static final long serialVersionUID = 5184291520170872969L; - private Container nativeContainer; - private Cursor nativeCursor; - private long eventMask; - - private transient Component pressedComponent; - private transient Component lastComponentEntered; - private transient int pressCount; - - LightweightDispatcher(Container c) - { - nativeContainer = c; - } - - void enableEvents(long l) - { - eventMask |= l; - } - - /** - * Returns the deepest visible descendent of parent that contains the - * specified location and that is not transparent and MouseListener-less. - * @param parent the root component to begin the search - * @param x the x coordinate - * @param y the y coordinate - * @return null if <code>parent</code> doesn't contain the location, - * parent if parent is not a container or has no child that contains the - * location, otherwise the appropriate component from the conditions - * above. - */ - Component getDeepestComponentForMouseEventAt(Component parent, int x, int y) - { - if (parent == null || (! parent.contains(x, y))) - return null; - - if (! (parent instanceof Container)) - return parent; - - Container c = (Container) parent; - return c.findComponentForMouseEventAt(x, y); - } - - Component acquireComponentForMouseEvent(MouseEvent me) - { - int x = me.getX (); - int y = me.getY (); - - Component mouseEventTarget = null; - // Find the candidate which should receive this event. - Component parent = nativeContainer; - Component candidate = null; - Point p = me.getPoint(); - while (candidate == null && parent != null) - { - candidate = getDeepestComponentForMouseEventAt(parent, p.x, p.y); - if (candidate == null || (candidate.eventMask & me.getID()) == 0) - { - candidate = null; - p = AWTUtilities.convertPoint(parent, p.x, p.y, parent.parent); - parent = parent.parent; - } - } - - // If the only candidate we found was the native container itself, - // don't dispatch any event at all. We only care about the lightweight - // children here. - if (candidate == nativeContainer) - candidate = null; - - // If our candidate is new, inform the old target we're leaving. - if (lastComponentEntered != null - && lastComponentEntered.isShowing() - && lastComponentEntered != candidate) - { - // Old candidate could have been removed from - // the nativeContainer so we check first. - if (AWTUtilities.isDescendingFrom(lastComponentEntered, - nativeContainer)) - { - Point tp = AWTUtilities.convertPoint(nativeContainer, - x, y, lastComponentEntered); - MouseEvent exited = new MouseEvent (lastComponentEntered, - MouseEvent.MOUSE_EXITED, - me.getWhen (), - me.getModifiersEx (), - tp.x, tp.y, - me.getClickCount (), - me.isPopupTrigger (), - me.getButton ()); - lastComponentEntered.dispatchEvent (exited); - } - lastComponentEntered = null; - } - - // If we have a candidate, maybe enter it. - if (candidate != null) - { - mouseEventTarget = candidate; - if (candidate.isLightweight() - && candidate.isShowing() - && candidate != nativeContainer - && candidate != lastComponentEntered) - { - lastComponentEntered = mouseEventTarget; - Point cp = AWTUtilities.convertPoint(nativeContainer, - x, y, lastComponentEntered); - MouseEvent entered = new MouseEvent (lastComponentEntered, - MouseEvent.MOUSE_ENTERED, - me.getWhen (), - me.getModifiersEx (), - cp.x, cp.y, - me.getClickCount (), - me.isPopupTrigger (), - me.getButton ()); - lastComponentEntered.dispatchEvent (entered); - } - } - - // Check which buttons where pressed except the last button that - // changed state. - int modifiers = me.getModifiersEx() & (MouseEvent.BUTTON1_DOWN_MASK - | MouseEvent.BUTTON2_DOWN_MASK - | MouseEvent.BUTTON3_DOWN_MASK); - switch(me.getButton()) - { - case MouseEvent.BUTTON1: - modifiers &= ~MouseEvent.BUTTON1_DOWN_MASK; - break; - case MouseEvent.BUTTON2: - modifiers &= ~MouseEvent.BUTTON2_DOWN_MASK; - break; - case MouseEvent.BUTTON3: - modifiers &= ~MouseEvent.BUTTON3_DOWN_MASK; - break; - } - - if (me.getID() == MouseEvent.MOUSE_RELEASED - || me.getID() == MouseEvent.MOUSE_PRESSED && modifiers > 0 - || me.getID() == MouseEvent.MOUSE_DRAGGED) - { - // If any of the following events occur while a button is held down, - // they should be dispatched to the same component to which the - // original MOUSE_PRESSED event was dispatched: - // - MOUSE_RELEASED: This is important for correct dragging - // behaviour, otherwise the release goes to an arbitrary component - // outside of the dragged component. OTOH, if there is no mouse - // drag while the mouse is pressed, the component under the mouse - // is the same as the previously pressed component anyway. - // - MOUSE_PRESSED: another button pressed while the first is held - // down - // - MOUSE_DRAGGED - if (AWTUtilities.isDescendingFrom(pressedComponent, nativeContainer)) - mouseEventTarget = pressedComponent; - } - else if (me.getID() == MouseEvent.MOUSE_CLICKED) - { - // Don't dispatch CLICKED events whose target is not the same as the - // target for the original PRESSED event. - if (candidate != pressedComponent) - { - mouseEventTarget = null; - pressCount = 0; - } - else if (pressCount == 0) - pressedComponent = null; - } - return mouseEventTarget; - } - - boolean handleEvent(AWTEvent e) - { - if (e instanceof MouseEvent) - { - MouseEvent me = (MouseEvent) e; - - // Make the LightWeightDispatcher reentrant. This is necessary when - // a lightweight component does its own modal event queue. - Component mouseEventTarget = acquireComponentForMouseEvent(me); - - // Avoid dispatching ENTERED and EXITED events twice. - if (mouseEventTarget != null - && mouseEventTarget.isShowing() - && e.getID() != MouseEvent.MOUSE_ENTERED - && e.getID() != MouseEvent.MOUSE_EXITED) - { - switch (e.getID()) - { - case MouseEvent.MOUSE_PRESSED: - if (pressCount++ == 0) - pressedComponent = mouseEventTarget; - break; - case MouseEvent.MOUSE_RELEASED: - // Clear our memory of the original PRESSED event, only if - // we're not expecting a CLICKED event after this. If - // there is a CLICKED event after this, it will do clean up. - if (--pressCount == 0 - && mouseEventTarget != pressedComponent) - { - pressedComponent = null; - pressCount = 0; - } - break; - } - - MouseEvent newEvt = - AWTUtilities.convertMouseEvent(nativeContainer, me, - mouseEventTarget); - mouseEventTarget.dispatchEvent(newEvt); - - if (newEvt.isConsumed()) - e.consume(); - } - } - - return e.isConsumed(); - } -} diff --git a/libjava/classpath/java/awt/Cursor.java b/libjava/classpath/java/awt/Cursor.java index 48a63f06f4f..0ff987cd9ed 100644 --- a/libjava/classpath/java/awt/Cursor.java +++ b/libjava/classpath/java/awt/Cursor.java @@ -219,6 +219,8 @@ public class Cursor implements java.io.Serializable public String toString() { - return (this.getClass() + "[" + getName() + "]"); + return (this.getClass() + + "[type=" + getType() + + ",name=" + getName() + "]"); } } diff --git a/libjava/classpath/java/awt/Frame.java b/libjava/classpath/java/awt/Frame.java index d6651f83e40..7003dac91fb 100644 --- a/libjava/classpath/java/awt/Frame.java +++ b/libjava/classpath/java/awt/Frame.java @@ -1,5 +1,6 @@ /* Frame.java -- AWT toplevel window - Copyright (C) 1999, 2000, 2002, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2002, 2004, 2005, 2006 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -57,143 +58,156 @@ import javax.accessibility.AccessibleStateSet; */ public class Frame extends Window implements MenuContainer { -/** - * Constant for the default cursor. - * @deprecated Replaced by <code>Cursor.DEFAULT_CURSOR</code> instead. - */ -public static final int DEFAULT_CURSOR = Cursor.DEFAULT_CURSOR; -/** - * Constant for a cross-hair cursor. - * @deprecated Use <code>Cursor.CROSSHAIR_CURSOR</code> instead. - */ -public static final int CROSSHAIR_CURSOR = Cursor.CROSSHAIR_CURSOR; + /** + * Constant for the default cursor. + * + * @deprecated Replaced by <code>Cursor.DEFAULT_CURSOR</code> instead. + */ + public static final int DEFAULT_CURSOR = Cursor.DEFAULT_CURSOR; -/** - * Constant for a cursor over a text field. - * @deprecated Use <code>Cursor.TEXT_CURSOR</code> instead. - */ -public static final int TEXT_CURSOR = Cursor.TEXT_CURSOR; + /** + * Constant for a cross-hair cursor. + * + * @deprecated Use <code>Cursor.CROSSHAIR_CURSOR</code> instead. + */ + public static final int CROSSHAIR_CURSOR = Cursor.CROSSHAIR_CURSOR; -/** - * Constant for a cursor to display while waiting for an action to complete. - * @deprecated Use <code>Cursor.WAIT_CURSOR</code>. - */ -public static final int WAIT_CURSOR = Cursor.WAIT_CURSOR; + /** + * Constant for a cursor over a text field. + * + * @deprecated Use <code>Cursor.TEXT_CURSOR</code> instead. + */ + public static final int TEXT_CURSOR = Cursor.TEXT_CURSOR; -/** - * Cursor used over SW corner of window decorations. - * @deprecated Use <code>Cursor.SW_RESIZE_CURSOR</code> instead. - */ -public static final int SW_RESIZE_CURSOR = Cursor.SW_RESIZE_CURSOR; + /** + * Constant for a cursor to display while waiting for an action to complete. + * + * @deprecated Use <code>Cursor.WAIT_CURSOR</code>. + */ + public static final int WAIT_CURSOR = Cursor.WAIT_CURSOR; -/** - * Cursor used over SE corner of window decorations. - * @deprecated Use <code>Cursor.SE_RESIZE_CURSOR</code> instead. - */ -public static final int SE_RESIZE_CURSOR = Cursor.SE_RESIZE_CURSOR; + /** + * Cursor used over SW corner of window decorations. + * + * @deprecated Use <code>Cursor.SW_RESIZE_CURSOR</code> instead. + */ + public static final int SW_RESIZE_CURSOR = Cursor.SW_RESIZE_CURSOR; -/** - * Cursor used over NW corner of window decorations. - * @deprecated Use <code>Cursor.NW_RESIZE_CURSOR</code> instead. - */ -public static final int NW_RESIZE_CURSOR = Cursor.NW_RESIZE_CURSOR; + /** + * Cursor used over SE corner of window decorations. + * @deprecated Use <code>Cursor.SE_RESIZE_CURSOR</code> instead. + */ + public static final int SE_RESIZE_CURSOR = Cursor.SE_RESIZE_CURSOR; -/** - * Cursor used over NE corner of window decorations. - * @deprecated Use <code>Cursor.NE_RESIZE_CURSOR</code> instead. - */ -public static final int NE_RESIZE_CURSOR = Cursor.NE_RESIZE_CURSOR; + /** + * Cursor used over NW corner of window decorations. + * + * @deprecated Use <code>Cursor.NW_RESIZE_CURSOR</code> instead. + */ + public static final int NW_RESIZE_CURSOR = Cursor.NW_RESIZE_CURSOR; -/** - * Cursor used over N edge of window decorations. - * @deprecated Use <code>Cursor.N_RESIZE_CURSOR</code> instead. - */ -public static final int N_RESIZE_CURSOR = Cursor.N_RESIZE_CURSOR; + /** + * Cursor used over NE corner of window decorations. + * + * @deprecated Use <code>Cursor.NE_RESIZE_CURSOR</code> instead. + */ + public static final int NE_RESIZE_CURSOR = Cursor.NE_RESIZE_CURSOR; -/** - * Cursor used over S edge of window decorations. - * @deprecated Use <code>Cursor.S_RESIZE_CURSOR</code> instead. - */ -public static final int S_RESIZE_CURSOR = Cursor.S_RESIZE_CURSOR; + /** + * Cursor used over N edge of window decorations. + * + * @deprecated Use <code>Cursor.N_RESIZE_CURSOR</code> instead. + */ + public static final int N_RESIZE_CURSOR = Cursor.N_RESIZE_CURSOR; -/** - * Cursor used over E edge of window decorations. - * @deprecated Use <code>Cursor.E_RESIZE_CURSOR</code> instead. - */ -public static final int E_RESIZE_CURSOR = Cursor.E_RESIZE_CURSOR; + /** + * Cursor used over S edge of window decorations. + * + * @deprecated Use <code>Cursor.S_RESIZE_CURSOR</code> instead. + */ + public static final int S_RESIZE_CURSOR = Cursor.S_RESIZE_CURSOR; -/** - * Cursor used over W edge of window decorations. - * @deprecated Use <code>Cursor.W_RESIZE_CURSOR</code> instead. - */ -public static final int W_RESIZE_CURSOR = Cursor.W_RESIZE_CURSOR; + /** + * Cursor used over E edge of window decorations. + * + * @deprecated Use <code>Cursor.E_RESIZE_CURSOR</code> instead. + */ + public static final int E_RESIZE_CURSOR = Cursor.E_RESIZE_CURSOR; -/** - * Constant for a hand cursor. - * @deprecated Use <code>Cursor.HAND_CURSOR</code> instead. - */ -public static final int HAND_CURSOR = Cursor.HAND_CURSOR; + /** + * Cursor used over W edge of window decorations. + * + * @deprecated Use <code>Cursor.W_RESIZE_CURSOR</code> instead. + */ + public static final int W_RESIZE_CURSOR = Cursor.W_RESIZE_CURSOR; -/** - * Constant for a cursor used during window move operations. - * @deprecated Use <code>Cursor.MOVE_CURSOR</code> instead. - */ -public static final int MOVE_CURSOR = Cursor.MOVE_CURSOR; + /** + * Constant for a hand cursor. + * + * @deprecated Use <code>Cursor.HAND_CURSOR</code> instead. + */ + public static final int HAND_CURSOR = Cursor.HAND_CURSOR; -public static final int ICONIFIED = 1; -public static final int MAXIMIZED_BOTH = 6; -public static final int MAXIMIZED_HORIZ = 2; -public static final int MAXIMIZED_VERT = 4; -public static final int NORMAL = 0; + /** + * Constant for a cursor used during window move operations. + * + * @deprecated Use <code>Cursor.MOVE_CURSOR</code> instead. + */ + public static final int MOVE_CURSOR = Cursor.MOVE_CURSOR; -// Serialization version constant -private static final long serialVersionUID = 2673458971256075116L; + public static final int ICONIFIED = 1; + public static final int MAXIMIZED_BOTH = 6; + public static final int MAXIMIZED_HORIZ = 2; + public static final int MAXIMIZED_VERT = 4; + public static final int NORMAL = 0; -/** - * @serial The version of the class data being serialized - * // FIXME: what is this value? - */ -private int frameSerializedDataVersion; +//Serialization version constant + private static final long serialVersionUID = 2673458971256075116L; -/** - * @serial Image used as the icon when this frame is minimized. - */ -private Image icon; + /** + * @serial The version of the class data being serialized + * FIXME: what is this value? + */ + private int frameSerializedDataVersion; -/** - * @serial Constant used by the JDK Motif peer set. Not used in - * this implementation. - */ -private boolean mbManagement; + /** + * @serial Image used as the icon when this frame is minimized. + */ + private Image icon; -/** - * @serial The menu bar for this frame. - */ -//private MenuBar menuBar = new MenuBar(); -private MenuBar menuBar; + /** + * @serial Constant used by the JDK Motif peer set. Not used in + * this implementation. + */ + private boolean mbManagement; -/** - * @serial A list of other top-level windows owned by this window. - */ -Vector ownedWindows = new Vector(); + /** + * @serial The menu bar for this frame. + */ + private MenuBar menuBar; -/** - * @serial Indicates whether or not this frame is resizable. - */ -private boolean resizable = true; + /** + * @serial A list of other top-level windows owned by this window. + */ + Vector ownedWindows = new Vector(); -/** - * @serial The state of this frame. - * // FIXME: What are the values here? - * This is package-private to avoid an accessor method. - */ -int state; + /** + * @serial Indicates whether or not this frame is resizable. + */ + private boolean resizable = true; -/** - * @serial The title of the frame. - */ -private String title = ""; + /** + * @serial The state of this frame. + * // FIXME: What are the values here? + * This is package-private to avoid an accessor method. + */ + int state; + + /** + * @serial The title of the frame. + */ + private String title = ""; /** * Maximized bounds for this frame. @@ -210,223 +224,235 @@ private String title = ""; */ private static transient long next_frame_number; -/** - * Initializes a new instance of <code>Frame</code> that is not visible - * and has no title. - */ -public -Frame() -{ - this(""); - noteFrame(this); -} + /** + * Initializes a new instance of <code>Frame</code> that is not visible + * and has no title. + */ + public Frame() + { + this(""); + noteFrame(this); + } -/** - * Initializes a new instance of <code>Frame</code> that is not visible - * and has the specified title. - * - * @param title The title of this frame. - */ -public -Frame(String title) -{ - super(); - this.title = title; - // Top-level frames are initially invisible. - visible = false; - noteFrame(this); -} + /** + * Initializes a new instance of <code>Frame</code> that is not visible + * and has the specified title. + * + * @param title the title of this frame + */ + public Frame(String title) + { + super(); + this.title = title; + // Top-level frames are initially invisible. + visible = false; + noteFrame(this); + } -public -Frame(GraphicsConfiguration gc) -{ - super(gc); - visible = false; - noteFrame(this); -} + public Frame(GraphicsConfiguration gc) + { + super(gc); + visible = false; + noteFrame(this); + } -public -Frame(String title, GraphicsConfiguration gc) -{ - super(gc); - setTitle(title); - visible = false; - noteFrame(this); -} + public Frame(String title, GraphicsConfiguration gc) + { + super(gc); + setTitle(title); + visible = false; + noteFrame(this); + } -/** - * Returns this frame's title string. - * - * @return This frame's title string. - */ -public String -getTitle() -{ - return(title); -} + /** + * Returns this frame's title string. + * + * @return this frame's title string + */ + public String getTitle() + { + return title; + } -/* - * Sets this frame's title to the specified value. - * - * @param title The new frame title. - */ -public synchronized void -setTitle(String title) -{ - this.title = title; - if (peer != null) - ((FramePeer) peer).setTitle(title); -} + /** + * Sets this frame's title to the specified value. + * + * @param title the new frame title + */ + public synchronized void setTitle(String title) + { + this.title = title; + if (peer != null) + ((FramePeer) peer).setTitle(title); + } -/** - * Returns this frame's icon. - * - * @return This frame's icon, or <code>null</code> if this frame does not - * have an icon. - */ -public Image -getIconImage() -{ - return(icon); -} + /** + * Returns this frame's icon. + * + * @return this frame's icon, or <code>null</code> if this frame does not + * have an icon + */ + public Image getIconImage() + { + return icon; + } -/** - * Sets this frame's icon to the specified value. - * - * @icon The new icon for this frame. - */ -public synchronized void -setIconImage(Image icon) -{ - this.icon = icon; - if (peer != null) - ((FramePeer) peer).setIconImage(icon); -} + /** + * Sets this frame's icon to the specified value. + * + * @icon the new icon for this frame + */ + public synchronized void setIconImage(Image icon) + { + this.icon = icon; + if (peer != null) + ((FramePeer) peer).setIconImage(icon); + } -/** - * Returns this frame's menu bar. - * - * @return This frame's menu bar, or <code>null</code> if this frame - * does not have a menu bar. - */ -public MenuBar -getMenuBar() -{ - return(menuBar); -} + /** + * Returns this frame's menu bar. + * + * @return this frame's menu bar, or <code>null</code> if this frame + * does not have a menu bar + */ + public MenuBar getMenuBar() + { + return menuBar; + } -/** - * Sets this frame's menu bar. - * - * @param menuBar The new menu bar for this frame. - */ -public synchronized void -setMenuBar(MenuBar menuBar) -{ - if (peer != null) + /** + * Sets this frame's menu bar. Removes any existing menu bar. If the + * given menu bar is part of another frame it will be removed from + * that frame. + * + * @param menuBar the new menu bar for this frame + */ + public synchronized void setMenuBar(MenuBar menuBar) { if (this.menuBar != null) - this.menuBar.removeNotify(); + remove(this.menuBar); + + this.menuBar = menuBar; if (menuBar != null) - menuBar.addNotify(); - invalidateTree (); - ((FramePeer) peer).setMenuBar(menuBar); + { + MenuContainer parent = menuBar.getParent(); + if (parent != null) + parent.remove(menuBar); + menuBar.setParent(this); + + if (peer != null) + { + if (menuBar != null) + menuBar.addNotify(); + invalidateTree(); + ((FramePeer) peer).setMenuBar(menuBar); + } + } } - this.menuBar = menuBar; -} -/** - * Tests whether or not this frame is resizable. This will be - * <code>true</code> by default. - * - * @return <code>true</code> if this frame is resizable, <code>false</code> - * otherwise. - */ -public boolean -isResizable() -{ - return(resizable); -} + /** + * Tests whether or not this frame is resizable. This will be + * <code>true</code> by default. + * + * @return <code>true</code> if this frame is resizable, <code>false</code> + * otherwise + */ + public boolean isResizable() + { + return resizable; + } -/** - * Sets the resizability of this frame to the specified value. - * - * @param resizable <code>true</code> to make the frame resizable, - * <code>false</code> to make it non-resizable. - */ -public synchronized void -setResizable(boolean resizable) -{ - this.resizable = resizable; - if (peer != null) - ((FramePeer) peer).setResizable(resizable); -} + /** + * Sets the resizability of this frame to the specified value. + * + * @param resizable <code>true</code> to make the frame resizable, + * <code>false</code> to make it non-resizable + */ + public synchronized void setResizable(boolean resizable) + { + this.resizable = resizable; + if (peer != null) + ((FramePeer) peer).setResizable(resizable); + } -/** - * Returns the cursor type of the cursor for this window. This will - * be one of the constants in this class. - * - * @return The cursor type for this frame. - * - * @deprecated Use <code>Component.getCursor()</code> instead. - */ -public int -getCursorType() -{ - return(getCursor().getType()); -} + /** + * Returns the cursor type of the cursor for this window. This will + * be one of the constants in this class. + * + * @return the cursor type for this frame + * + * @deprecated Use <code>Component.getCursor()</code> instead. + */ + public int getCursorType() + { + return getCursor().getType(); + } -/** - * Sets the cursor for this window to the specified type. The specified - * type should be one of the constants in this class. - * - * @param type The cursor type. - * - * @deprecated Use <code>Component.setCursor(Cursor)</code> instead. - */ -public void -setCursor(int type) -{ - setCursor(new Cursor(type)); -} + /** + * Sets the cursor for this window to the specified type. The specified + * type should be one of the constants in this class. + * + * @param type the cursor type + * + * @deprecated Use <code>Component.setCursor(Cursor)</code> instead. + */ + public void setCursor(int type) + { + setCursor(new Cursor(type)); + } -/** - * Removes the specified component from this frame's menu. - * - * @param menu The menu component to remove. - */ -public void -remove(MenuComponent menu) -{ - menuBar.remove(menu); -} + /** + * Removes the specified menu component from this frame. If it is + * the current MenuBar it is removed from the frame. If it is a + * Popup it is removed from this component. If it is any other menu + * component it is ignored. + * + * @param menu the menu component to remove + */ + public void remove(MenuComponent menu) + { + if (menu == menuBar) + { + if (menuBar != null) + { + if (peer != null) + { + ((FramePeer) peer).setMenuBar(null); + menuBar.removeNotify(); + } + menuBar.setParent(null); + } + menuBar = null; + } + else + super.remove(menu); + } -public void -addNotify() -{ - if (menuBar != null) - menuBar.addNotify(); - if (peer == null) - peer = getToolkit ().createFrame (this); + public void addNotify() + { + if (menuBar != null) + menuBar.addNotify(); + if (peer == null) + peer = getToolkit ().createFrame (this); - super.addNotify(); -} + super.addNotify(); + } -public void removeNotify() -{ - if (menuBar != null) - menuBar.removeNotify(); - super.removeNotify(); -} + public void removeNotify() + { + if (menuBar != null) + menuBar.removeNotify(); + super.removeNotify(); + } /** * Returns a debugging string describing this window. * - * @return A debugging string describing this window. + * @return a debugging string describing this window */ - protected String paramString () + protected String paramString() { - String title = getTitle (); + String title = getTitle(); String resizable = ""; if (isResizable ()) @@ -455,17 +481,17 @@ public void removeNotify() return super.paramString () + ",title=" + title + resizable + state; } -private static ArrayList weakFrames = new ArrayList(); + private static ArrayList weakFrames = new ArrayList(); -private static void noteFrame(Frame f) -{ - weakFrames.add(new WeakReference(f)); -} + private static void noteFrame(Frame f) + { + weakFrames.add(new WeakReference(f)); + } -public static Frame[] getFrames() -{ - int n = 0; - synchronized (weakFrames) + public static Frame[] getFrames() + { + int n = 0; + synchronized (weakFrames) { Iterator i = weakFrames.iterator(); while (i.hasNext()) @@ -490,32 +516,31 @@ public static Frame[] getFrames() return frames; } } -} + } - public void setState (int state) + public void setState(int state) { int current_state = getExtendedState (); if (state == NORMAL && (current_state & ICONIFIED) != 0) - setExtendedState (current_state | ICONIFIED); + setExtendedState(current_state | ICONIFIED); if (state == ICONIFIED && (current_state & ~ICONIFIED) == 0) - setExtendedState (current_state & ~ICONIFIED); + setExtendedState(current_state & ~ICONIFIED); } - public int getState () + public int getState() { - /* FIXME: State might have changed in the peer... Must check. */ - + // FIXME: State might have changed in the peer... Must check. return (state & ICONIFIED) != 0 ? ICONIFIED : NORMAL; } /** * @since 1.4 */ - public void setExtendedState (int state) + public void setExtendedState(int state) { this.state = state; } @@ -523,7 +548,7 @@ public static Frame[] getFrames() /** * @since 1.4 */ - public int getExtendedState () + public int getExtendedState() { return state; } @@ -531,7 +556,7 @@ public static Frame[] getFrames() /** * @since 1.4 */ - public void setMaximizedBounds (Rectangle maximizedBounds) + public void setMaximizedBounds(Rectangle maximizedBounds) { this.maximizedBounds = maximizedBounds; } @@ -539,11 +564,11 @@ public static Frame[] getFrames() /** * Returns the maximized bounds of this frame. * - * @return the maximized rectangle, may be null. + * @return the maximized rectangle, may be null * * @since 1.4 */ - public Rectangle getMaximizedBounds () + public Rectangle getMaximizedBounds() { return maximizedBounds; } @@ -553,7 +578,7 @@ public static Frame[] getFrames() * * @since 1.4 */ - public boolean isUndecorated () + public boolean isUndecorated() { return undecorated; } @@ -562,14 +587,14 @@ public static Frame[] getFrames() * Disables or enables decorations for this frame. This method can only be * called while the frame is not displayable. * - * @exception IllegalComponentStateException If this frame is displayable. + * @throws IllegalComponentStateException if this frame is displayable * * @since 1.4 */ - public void setUndecorated (boolean undecorated) + public void setUndecorated(boolean undecorated) { - if (isDisplayable ()) - throw new IllegalComponentStateException (); + if (isDisplayable()) + throw new IllegalComponentStateException(); this.undecorated = undecorated; } @@ -577,14 +602,14 @@ public static Frame[] getFrames() /** * Generate a unique name for this frame. * - * @return A unique name for this frame. + * @return a unique name for this frame */ - String generateName () + String generateName() { - return "frame" + getUniqueLong (); + return "frame" + getUniqueLong(); } - private static synchronized long getUniqueLong () + private static synchronized long getUniqueLong() { return next_frame_number++; } @@ -617,10 +642,9 @@ public static Frame[] getFrames() */ public AccessibleContext getAccessibleContext() { - /* Create the context if this is the first request */ + // Create the context if this is the first request. if (accessibleContext == null) accessibleContext = new AccessibleAWTFrame(); return accessibleContext; } - } diff --git a/libjava/classpath/java/awt/Insets.java b/libjava/classpath/java/awt/Insets.java index 7238a34e22a..6d5bd122e9d 100644 --- a/libjava/classpath/java/awt/Insets.java +++ b/libjava/classpath/java/awt/Insets.java @@ -100,11 +100,31 @@ public class Insets implements Cloneable, Serializable } /** + * Set the contents of this Insets object to the specified values. + * + * @param top the top inset + * @param left the left inset + * @param bottom the bottom inset + * @param right the right inset + * + * @since 1.5 + */ + public void set(int top, int left, int bottom, int right) + { + this.top = top; + this.left = left; + this.bottom = bottom; + this.right = right; + } + + /** * Tests whether this object is equal to the specified object. The other * object must be an instance of Insets with identical field values. * * @param obj the object to test against * @return true if the specified object is equal to this one + * + * @since 1.1 */ public boolean equals(Object obj) { diff --git a/libjava/classpath/java/awt/LightweightDispatcher.java b/libjava/classpath/java/awt/LightweightDispatcher.java new file mode 100644 index 00000000000..6573b128ec4 --- /dev/null +++ b/libjava/classpath/java/awt/LightweightDispatcher.java @@ -0,0 +1,200 @@ +/* LightweightDispatcher.java -- Dispatches mouse events to lightweights + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt; + +import gnu.java.awt.AWTUtilities; + +import java.awt.event.MouseEvent; +import java.util.WeakHashMap; + +/** + * Redispatches mouse events to lightweight components. The native peers know + * nothing about the lightweight components and thus mouse events are always + * targetted at Windows or heavyweight components. This class listenes directly + * on the eventqueue and dispatches mouse events to lightweight components. + * + * @author Roman Kennke (kennke@aicas.com) + */ +class LightweightDispatcher +{ + + /** + * Maps thread groups to lightweight dispatcher instances. We need to + * have one instance per thread group so that 2 or more applets or otherwise + * separated applications (like in OSGI) do not interfer with each other. + */ + private static WeakHashMap instances = new WeakHashMap(); + + /** + * The component that is the start of a mouse dragging. All MOUSE_DRAGGED + * events that follow the initial press must have the source set to this, + * as well as the MOUSE_RELEASED event following the dragging. + */ + private Component dragTarget; + + /** + * The last mouse event target. If the target changes, additional + * MOUSE_ENTERED and MOUSE_EXITED events must be dispatched. + */ + private Component lastTarget; + + /** + * Returns an instance of LightweightDispatcher for the current thread's + * thread group. + * + * @return an instance of LightweightDispatcher for the current thread's + * thread group + */ + static LightweightDispatcher getInstance() + { + Thread t = Thread.currentThread(); + ThreadGroup tg = t.getThreadGroup(); + LightweightDispatcher instance = (LightweightDispatcher) instances.get(tg); + if (instance == null) + { + instance = new LightweightDispatcher(); + instances.put(tg, instance); + } + return instance; + } + + /** + * Creates a new LightweightDispatcher. This is private to prevent access + * from outside. Use {@link #getInstance()} instead. + */ + private LightweightDispatcher() + { + // Nothing to do here. + } + + /** + * Receives notification if a mouse event passes along the eventqueue. + * + * @param event the event + */ + public boolean dispatchEvent(AWTEvent event) + { + boolean dispatched = false; + if (event instanceof MouseEvent && event.getSource() instanceof Window) + { + MouseEvent mouseEvent = (MouseEvent) event; + handleMouseEvent(mouseEvent); + dispatched = true; + } + return dispatched; + } + + /** + * Handles all mouse events that are targetted at toplevel containers + * (Window instances) and dispatches them to the correct lightweight child. + * + * @param ev the mouse event + */ + private void handleMouseEvent(MouseEvent ev) + { + Window window = (Window) ev.getSource(); + Component target = window.findComponentAt(ev.getX(), ev.getY()); + if (target != null && target.isLightweight()) + { + // Dispatch additional MOUSE_EXITED and MOUSE_ENTERED if event target + // is different from the last event target. + if (target != lastTarget) + { + if (lastTarget != null) + { + Point p1 = AWTUtilities.convertPoint(window, ev.getX(), + ev.getY(), lastTarget); + MouseEvent mouseExited = + new MouseEvent(lastTarget, MouseEvent.MOUSE_EXITED, + ev.getWhen(), ev.getModifiers(), p1.x, p1.y, + ev.getClickCount(), ev.isPopupTrigger()); + lastTarget.dispatchEvent(mouseExited); + } + Point p = AWTUtilities.convertPoint(window, ev.getX(), ev.getY(), + target); + MouseEvent mouseEntered = + new MouseEvent(target, MouseEvent.MOUSE_ENTERED, ev.getWhen(), + ev.getModifiers(), p.x, p.y, ev.getClickCount(), + ev.isPopupTrigger()); + target.dispatchEvent(mouseEntered); + } + + switch (ev.getID()) + { + case MouseEvent.MOUSE_PRESSED: + dragTarget = target; + break; + case MouseEvent.MOUSE_RELEASED: + if (dragTarget != null) + target = dragTarget; + dragTarget = null; + break; + case MouseEvent.MOUSE_CLICKED: + // When we receive a MOUSE_CLICKED, we set the target to the + // previous target, which must have been a MOUSE_RELEASED event. + // This is necessary for the case when the MOUSE_RELEASED has + // caused the original target (like an internal component) go + // away. + target = lastTarget; + break; + case MouseEvent.MOUSE_DRAGGED: + target = dragTarget; + break; + default: + // Do nothing in other cases. + break; + } + + lastTarget = target; + + Point targetCoordinates = + AWTUtilities.convertPoint(window, ev.getX(), ev.getY(), target); + int dx = targetCoordinates.x - ev.getX(); + int dy = targetCoordinates.y - ev.getY(); + ev.translatePoint(dx, dy); + ev.setSource(target); + target.dispatchEvent(ev); + + // We reset the event, so that the normal event dispatching is not + // influenced by this modified event. + ev.setSource(window); + ev.translatePoint(-dx, -dy); + } + } +} diff --git a/libjava/classpath/java/awt/Menu.java b/libjava/classpath/java/awt/Menu.java index 13ebb5211be..6daec72cf44 100644 --- a/libjava/classpath/java/awt/Menu.java +++ b/libjava/classpath/java/awt/Menu.java @@ -1,5 +1,5 @@ /* Menu.java -- A Java AWT Menu - Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -220,15 +220,16 @@ getItem(int index) public MenuItem add(MenuItem item) { + MenuContainer parent = item.getParent(); + if (parent != null) + parent.remove(item); + items.addElement(item); - if (item.parent != null) - { - item.parent.remove(item); - } - item.parent = this; + item.setParent(this); if (peer != null) { + item.addNotify(); MenuPeer mp = (MenuPeer) peer; mp.addItem(item); } @@ -266,26 +267,33 @@ insert(MenuItem item, int index) if (index < 0) throw new IllegalArgumentException("Index is less than zero"); - MenuPeer peer = (MenuPeer) getPeer(); - if (peer == null) - return; - int count = getItemCount (); if (index >= count) - peer.addItem (item); + add(item); else { + MenuContainer parent = item.getParent(); + if (parent != null) + parent.remove(item); + + items.insertElementAt(item, index); + item.setParent(this); + + MenuPeer peer = (MenuPeer) getPeer(); + if (peer == null) + return; + for (int i = count - 1; i >= index; i--) - peer.delItem (i); + peer.delItem(i); - peer.addItem (item); + item.addNotify(); + peer.addItem(item); for (int i = index; i < count; i++) - peer.addItem ((MenuItem) items.elementAt (i)); + peer.addItem((MenuItem) items.elementAt (i)); } - items.insertElementAt(item, index); } /*************************************************************************/ @@ -344,11 +352,15 @@ insertSeparator(int index) public synchronized void remove(int index) { - items.removeElementAt(index); + MenuItem item = (MenuItem) items.remove(index); - MenuPeer mp = (MenuPeer)getPeer(); + MenuPeer mp = (MenuPeer) getPeer(); if (mp != null) - mp.delItem(index); + { + mp.delItem(index); + item.removeNotify(); + } + item.setParent(null); } /*************************************************************************/ @@ -393,14 +405,21 @@ removeAll() public void addNotify() { + MenuPeer peer = (MenuPeer) getPeer(); if (peer == null) - peer = getToolkit().createMenu(this); + { + peer = getToolkit().createMenu(this); + setPeer(peer); + } + Enumeration e = items.elements(); while (e.hasMoreElements()) { MenuItem mi = (MenuItem)e.nextElement(); mi.addNotify(); - } + peer.addItem(mi); + } + super.addNotify (); } diff --git a/libjava/classpath/java/awt/MenuBar.java b/libjava/classpath/java/awt/MenuBar.java index 4089fe189e0..3c6b915649f 100644 --- a/libjava/classpath/java/awt/MenuBar.java +++ b/libjava/classpath/java/awt/MenuBar.java @@ -1,5 +1,6 @@ /* MenuBar.java -- An AWT menu bar class - Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2006 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,7 +40,6 @@ exception statement from your version. */ package java.awt; import java.awt.peer.MenuBarPeer; -import java.awt.peer.MenuComponentPeer; import java.io.Serializable; import java.util.Enumeration; @@ -60,364 +60,311 @@ public class MenuBar extends MenuComponent implements MenuContainer, Serializable, Accessible { -/* - * Static Variables - */ +//Serialization Constant + private static final long serialVersionUID = -4930327919388951260L; -// Serialization Constant -private static final long serialVersionUID = -4930327919388951260L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * @serial The menu used for providing help information - */ -private Menu helpMenu; + /** + * @serial The menu used for providing help information + */ + private Menu helpMenu; -/** - * @serial The menus contained in this menu bar. - */ -private Vector menus = new Vector(); + /** + * @serial The menus contained in this menu bar. + */ + private Vector menus = new Vector(); /** - * The accessible context for this component. + * Initializes a new instance of <code>MenuBar</code>. * - * @see #getAccessibleContext() - * @serial ignored. + * @throws HeadlessException if GraphicsEnvironment.isHeadless() is true */ - private transient AccessibleContext accessibleContext; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Initializes a new instance of <code>MenuBar</code>. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -MenuBar() -{ - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * Returns the help menu for this menu bar. This may be <code>null</code>. - * - * @return The help menu for this menu bar. - */ -public Menu -getHelpMenu() -{ - return(helpMenu); -} - -/*************************************************************************/ - -/** - * Sets the help menu for this menu bar. - * - * @param menu The new help menu for this menu bar. - */ -public synchronized void -setHelpMenu(Menu menu) -{ - if (helpMenu != null) - { - helpMenu.removeNotify (); - helpMenu.parent = null; - } - helpMenu = menu; - - if (menu.parent != null) - menu.parent.remove (menu); - menu.parent = this; - - MenuBarPeer peer = (MenuBarPeer) getPeer (); - if (peer != null) - { - menu.addNotify(); - peer.addHelpMenu (menu); - } -} - -/*************************************************************************/ - -/** Add a menu to this MenuBar. If the menu has already has a - * parent, it is first removed from its old parent before being - * added. - * - * @param menu The menu to add. - * - * @return The menu that was added. - */ -public synchronized Menu -add(Menu menu) -{ - if (menu.parent != null) - menu.parent.remove (menu); - - menu.parent = this; - menus.addElement(menu); - - if (peer != null) - { - menu.addNotify(); - } - - return(menu); -} - -/*************************************************************************/ + public MenuBar() + { + if (GraphicsEnvironment.isHeadless()) + throw new HeadlessException(); + } -/** - * Removes the menu at the specified index. - * - * @param index The index of the menu to remove from the menu bar. - */ -public synchronized void -remove(int index) -{ - Menu m = (Menu) menus.get (index); - menus.remove (index); - m.removeNotify (); - m.parent = null; + /** + * Returns the help menu for this menu bar. This may be <code>null</code>. + * + * @return the help menu for this menu bar + */ + public Menu getHelpMenu() + { + return helpMenu; + } - if (peer != null) - { - MenuBarPeer mp = (MenuBarPeer) peer; - mp.delMenu (index); - } -} + /** + * Sets the help menu for this menu bar. + * + * @param menu the new help menu for this menu bar + */ + public synchronized void setHelpMenu(Menu menu) + { + MenuBarPeer myPeer = (MenuBarPeer) getPeer (); + + if (helpMenu != null) + { + if (myPeer != null) + helpMenu.removeNotify(); + helpMenu.setParent(null); + } + helpMenu = menu; + + MenuContainer parent = menu.getParent(); + if (parent != null) + parent.remove(menu); + menu.setParent(this); + + if (myPeer != null) + { + menu.addNotify(); + myPeer.addHelpMenu(menu); + } + } -/*************************************************************************/ + /** + * Add a menu to this MenuBar. If the menu has already has a + * parent, it is first removed from its old parent before being + * added. + * + * @param menu the menu to add + * + * @return the menu that was added + */ + public synchronized Menu add(Menu menu) + { + MenuBarPeer myPeer = (MenuBarPeer) getPeer (); -/** - * Removes the specified menu from the menu bar. - * - * @param menu The menu to remove from the menu bar. - */ -public void -remove(MenuComponent menu) -{ - int index = menus.indexOf(menu); - if (index == -1) - return; + MenuContainer parent = menu.getParent(); + if (parent != null) + parent.remove(menu); - remove(index); -} + menus.addElement(menu); + menu.setParent(this); -/*************************************************************************/ + if (myPeer != null) + { + menu.addNotify(); + myPeer.addMenu(menu); + } + return menu; + } -/** - * Returns the number of elements in this menu bar. - * - * @return The number of elements in the menu bar. - */ -public int -getMenuCount() -{ - return countMenus (); -} + /** + * Removes the menu at the specified index. + * + * @param index the index of the menu to remove from the menu bar + */ + public synchronized void remove(int index) + { + Menu m = (Menu) menus.remove(index); + MenuBarPeer mp = (MenuBarPeer) getPeer(); -/*************************************************************************/ + if (mp != null) + m.removeNotify(); -/** - * Returns the number of elements in this menu bar. - * - * @return The number of elements in the menu bar. - * - * @deprecated This method is deprecated in favor of <code>getMenuCount()</code>. - */ -public int -countMenus() -{ - return menus.size () + (getHelpMenu () == null ? 0 : 1); -} + m.setParent(null); -/*************************************************************************/ + if (mp != null) + mp.delMenu(index); + } -/** - * Returns the menu at the specified index. - * - * @param index the index of the menu - * - * @return The requested menu. - * - * @exception ArrayIndexOutOfBoundsException If the index is not valid. - */ -public Menu -getMenu(int index) -{ - return((Menu)menus.elementAt(index)); -} + /** + * Removes the specified menu from the menu bar. + * + * @param menu the menu to remove from the menu bar + */ + public void remove(MenuComponent menu) + { + int index = menus.indexOf(menu); + if (index == -1) + return; -/*************************************************************************/ + remove(index); + } -/** - * Creates this object's native peer. - */ -public void -addNotify() -{ - if (getPeer() == null) - setPeer((MenuComponentPeer)getToolkit().createMenuBar(this)); - Enumeration e = menus.elements(); - while (e.hasMoreElements()) + /** + * Returns the number of elements in this menu bar. + * + * @return the number of elements in the menu bar + */ + public int getMenuCount() { - Menu mi = (Menu)e.nextElement(); - mi.addNotify(); + return countMenus(); } - if (helpMenu != null) + + /** + * Returns the number of elements in this menu bar. + * + * @return the number of elements in the menu bar + * + * @deprecated This method is deprecated in favor of + * <code>getMenuCount()</code>. + */ + public int countMenus() { - helpMenu.addNotify(); - ((MenuBarPeer) peer).addHelpMenu(helpMenu); + return menus.size() + (getHelpMenu() == null ? 0 : 1); } -} -/*************************************************************************/ - -/** - * Destroys this object's native peer. - */ -public void -removeNotify() -{ - Enumeration e = menus.elements(); - while (e.hasMoreElements()) + /** + * Returns the menu at the specified index. + * + * @param index the index of the menu + * + * @return the requested menu + * + * @throws ArrayIndexOutOfBoundsException if the index is not valid + */ + public Menu getMenu(int index) { - Menu mi = (Menu) e.nextElement(); - mi.removeNotify(); + return (Menu) menus.elementAt(index); } - super.removeNotify(); -} - -/*************************************************************************/ - -/** - * Returns a list of all shortcuts for the menus in this menu bar. - * - * @return A list of all shortcuts for the menus in this menu bar. - */ -public synchronized Enumeration -shortcuts() -{ - Vector shortcuts = new Vector(); - Enumeration e = menus.elements(); - - while (e.hasMoreElements()) - { - Menu menu = (Menu)e.nextElement(); - if (menu.getShortcut() != null) - shortcuts.addElement(menu.getShortcut()); - } - return(shortcuts.elements()); -} + /** + * Creates this object's native peer. + */ + public void addNotify() + { + MenuBarPeer peer = (MenuBarPeer) getPeer(); + if (peer == null) + { + peer = getToolkit().createMenuBar(this); + setPeer(peer); + } + + Enumeration e = menus.elements(); + while (e.hasMoreElements()) + { + Menu mi = (Menu)e.nextElement(); + mi.addNotify(); + peer.addMenu(mi); + } + + if (helpMenu != null) + { + helpMenu.addNotify(); + peer.addHelpMenu(helpMenu); + } + } -/*************************************************************************/ + /** + * Destroys this object's native peer. + */ + public void removeNotify() + { + Enumeration e = menus.elements(); + while (e.hasMoreElements()) + { + Menu mi = (Menu) e.nextElement(); + mi.removeNotify(); + } + super.removeNotify(); + } -/** - * Returns the menu item for the specified shortcut, or <code>null</code> - * if no such item exists. - * - * @param shortcut The shortcut to return the menu item for. - * - * @return The menu item for the specified shortcut. - */ -public MenuItem -getShortcutMenuItem(MenuShortcut shortcut) -{ - Enumeration e = menus.elements(); + /** + * Returns a list of all shortcuts for the menus in this menu bar. + * + * @return a list of all shortcuts for the menus in this menu bar + */ + public synchronized Enumeration shortcuts() + { + Vector shortcuts = new Vector(); + Enumeration e = menus.elements(); - while (e.hasMoreElements()) - { - Menu menu = (Menu)e.nextElement(); - MenuShortcut s = menu.getShortcut(); - if ((s != null) && (s.equals(shortcut))) - return(menu); - } + while (e.hasMoreElements()) + { + Menu menu = (Menu)e.nextElement(); + if (menu.getShortcut() != null) + shortcuts.addElement(menu.getShortcut()); + } - return(null); -} + return shortcuts.elements(); + } -/*************************************************************************/ + /** + * Returns the menu item for the specified shortcut, or <code>null</code> + * if no such item exists. + * + * @param shortcut the shortcut to return the menu item for + * + * @return the menu item for the specified shortcut + */ + public MenuItem getShortcutMenuItem(MenuShortcut shortcut) + { + Enumeration e = menus.elements(); -/** - * Deletes the specified menu shortcut. - * - * @param shortcut The shortcut to delete. - */ -public void -deleteShortcut(MenuShortcut shortcut) -{ - MenuItem it; - // This is a slow implementation, but it probably doesn't matter. - while ((it = getShortcutMenuItem (shortcut)) != null) - it.deleteShortcut (); -} + while (e.hasMoreElements()) + { + Menu menu = (Menu) e.nextElement(); + MenuShortcut s = menu.getShortcut(); + if ((s != null) && s.equals(shortcut)) + return menu; + } -/** - * Gets the AccessibleContext associated with this <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) - accessibleContext = new AccessibleAWTMenuBar(); - return accessibleContext; -} + return null; + } -/** - * This class provides accessibility support for AWT menu bars. - * - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - */ -protected class AccessibleAWTMenuBar - extends AccessibleAWTMenuComponent -{ - /** - * Compatible with JDK 1.4.2 revision 5 + * Deletes the specified menu shortcut. + * + * @param shortcut the shortcut to delete */ - private static final long serialVersionUID = -8577604491830083815L; + public void deleteShortcut(MenuShortcut shortcut) + { + MenuItem it; + // This is a slow implementation, but it probably doesn't matter. + while ((it = getShortcutMenuItem (shortcut)) != null) + it.deleteShortcut(); + } /** - * This is the default constructor, which simply calls the default - * constructor of the superclass. + * Gets the AccessibleContext associated with this <code>MenuBar</code>. + * The context is created, if necessary. + * + * @return the associated context */ - protected AccessibleAWTMenuBar() + public AccessibleContext getAccessibleContext() { - super(); + // Create the context if this is the first request. + if (accessibleContext == null) + accessibleContext = new AccessibleAWTMenuBar(); + return accessibleContext; } /** - * Returns the accessible role relating to the menu bar. + * This class provides accessibility support for AWT menu bars. * - * @return <code>AccessibleRole.MENU_BAR</code>. + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) */ - public AccessibleRole getAccessibleRole() + protected class AccessibleAWTMenuBar + extends AccessibleAWTMenuComponent { - return AccessibleRole.MENU_BAR; - } + + /** + * Compatible with JDK 1.4.2 revision 5 + */ + private static final long serialVersionUID = -8577604491830083815L; + + /** + * This is the default constructor, which simply calls the default + * constructor of the superclass. + */ + protected AccessibleAWTMenuBar() + { + super(); + } -} // class AccessibleAWTMenuBar + /** + * Returns the accessible role relating to the menu bar. + * + * @return <code>AccessibleRole.MENU_BAR</code> + */ + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.MENU_BAR; + } -} // class MenuBar + } + +} diff --git a/libjava/classpath/java/awt/MenuComponent.java b/libjava/classpath/java/awt/MenuComponent.java index 375d08436e0..9bb875069e0 100644 --- a/libjava/classpath/java/awt/MenuComponent.java +++ b/libjava/classpath/java/awt/MenuComponent.java @@ -1,5 +1,6 @@ /* MenuComponent.java -- Superclass of all AWT menu components - Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -60,26 +61,16 @@ import javax.accessibility.AccessibleStateSet; public abstract class MenuComponent implements Serializable { -/* - * Static Variables - */ +//Serialization Constant + private static final long serialVersionUID = -4536902356223894379L; -// Serialization Constant -private static final long serialVersionUID = -4536902356223894379L; - -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** - * The font for this component. - * - * @see #getFont() - * @see #setFont(java.awt.Font) - * @serial the component's font. - */ + /** + * The font for this component. + * + * @see #getFont() + * @see #setFont(java.awt.Font) + * @serial the component's font. + */ private Font font; /** @@ -165,1160 +156,1133 @@ private static final long serialVersionUID = -4536902356223894379L; */ transient FocusListener focusListener; -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * Default constructor for subclasses. - * - * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. - */ -public -MenuComponent() -{ - if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); -} - -/*************************************************************************/ - -/* - * Instance Methods - */ + /** + * Default constructor for subclasses. + * + * @throws HeadlessException ff GraphicsEnvironment.isHeadless() is true + */ + public MenuComponent() + { + if (GraphicsEnvironment.isHeadless()) + throw new HeadlessException(); + } /** * Returns the font in use for this component. * - * @return The font for this component. - */ -public Font -getFont() -{ - if (font != null) - return font; - - if (parent != null) - return parent.getFont (); - - return null; -} - -/*************************************************************************/ - -/** - * Sets the font for this component to the specified font. - * - * @param font The new font for this component. - */ -public void -setFont(Font font) -{ - this.font = font; -} - -/*************************************************************************/ - -/** - * Returns the name of this component. - * - * @return The name of this component. - */ -public String -getName() -{ - return(name); -} - -/*************************************************************************/ - -/** - * Sets the name of this component to the specified name. - * - * @param name The new name of this component. - */ -public void -setName(String name) -{ - this.name = name; - nameExplicitlySet = true; -} - -/*************************************************************************/ - -/** - * Returns the parent of this component. - * - * @return The parent of this component. - */ -public MenuContainer -getParent() -{ - return(parent); -} - -/*************************************************************************/ - -// Sets the parent of this component. -final void -setParent(MenuContainer parent) -{ - this.parent = parent; -} - -/*************************************************************************/ - -/** - * Returns the native windowing system peer for this component. - * - * @return The peer for this component. - * - * @deprecated - */ -public MenuComponentPeer -getPeer() -{ - return(peer); -} - -/*************************************************************************/ - -// Sets the peer for this component. -final void -setPeer(MenuComponentPeer peer) -{ - this.peer = peer; -} - -/*************************************************************************/ - -/** - * Destroys this component's native peer - */ -public void -removeNotify() -{ - if (peer != null) - peer.dispose(); - peer = null; -} - -/*************************************************************************/ - -/** - * Returns the toolkit in use for this component. - * - * @return The toolkit for this component. - */ -final Toolkit -getToolkit() -{ - return(toolkit); -} - -/*************************************************************************/ - -/** - * Returns the object used for synchronization locks on this component - * when performing tree and layout functions. - * - * @return The synchronization lock for this component. - */ -protected final Object -getTreeLock() -{ - return(tree_lock); -} - -/*************************************************************************/ - -// The sync lock object for this component. -final void -setTreeLock(Object tree_lock) -{ - this.tree_lock = tree_lock; -} - -/*************************************************************************/ - -/** - * AWT 1.0 event dispatcher. - * - * @deprecated Deprecated in favor of <code>dispatchEvent()</code>. - * @return true if the event was dispatched, false otherwise. - */ -public boolean -postEvent(Event event) -{ - // This is overridden by subclasses that support events. - return false; -} -/*************************************************************************/ - -/** - * Sends this event to this component or a subcomponent for processing. - * - * @param event The event to dispatch - */ -public final void dispatchEvent(AWTEvent event) -{ - // See comment in Component.dispatchEvent(). - dispatchEventImpl(event); -} - - -/** - * Implementation of dispatchEvent. Allows trusted package classes - * to dispatch additional events first. This implementation first - * translates <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); -} - -/*************************************************************************/ - -/** - * Processes the specified event. In this class, this method simply - * calls one of the more specific event handlers. - * - * @param event The event to process. - */ -protected void -processEvent(AWTEvent event) -{ - /* - Pass a focus event to the focus listener for - the accessibility context. - */ - if (event instanceof FocusEvent) - { - if (focusListener != null) - { - switch (event.id) - { - case FocusEvent.FOCUS_GAINED: - focusListener.focusGained((FocusEvent) event); - break; - case FocusEvent.FOCUS_LOST: - focusListener.focusLost((FocusEvent) event); - break; - } - } - } -} - -/*************************************************************************/ - -/** - * Returns a string representation of this component. - * - * @return A string representation of this component + * @return the font for this component */ -public String -toString() -{ - return this.getClass().getName() + "[" + paramString() + "]"; -} - -/*************************************************************************/ - -/** - * Returns a debugging string for this component - */ -protected String -paramString() -{ - return "name=" + getName(); -} - -/** - * Gets the AccessibleContext associated with this <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; -} + public Font getFont() + { + if (font != null) + return font; -/** - * This class provides a base for the accessibility support of menu - * components. - * - * @author Andrew John Hughes (gnu_andrew@member.fsf.org) - */ -protected abstract class AccessibleAWTMenuComponent - extends AccessibleContext - implements Serializable, AccessibleComponent, AccessibleSelection -{ + if (parent != null) + return parent.getFont(); - /** - * Compatible with JDK 1.4.2 revision 5 - */ - private static final long serialVersionUID = -4269533416223798698L; - - /** - * This is the default constructor. It should be called by - * concrete subclasses to ensure necessary groundwork is completed. - */ - protected AccessibleAWTMenuComponent() - { + return null; } /** - * Replaces or supplements the component's selection with the - * <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. + * Sets the font for this component to the specified font. * - * @param index the index of the specified child within a - * zero-based list of the component's children. + * @param font the new font for this component */ - public void addAccessibleSelection(int index) + public void setFont(Font font) { - /* Subclasses with children should implement this */ + this.font = font; } /** - * Registers the specified focus listener to receive - * focus events from this component. + * Returns the name of this component. * - * @param listener the new focus listener. + * @return the name of this component */ - public void addFocusListener(FocusListener listener) + public String getName() { - /* - * Chain the new focus listener to the existing chain - * of focus listeners. Each new focus listener is - * coupled via multicasting to the existing chain. - */ - focusListener = AWTEventMulticaster.add(focusListener, listener); + return name; } /** - * Clears the component's current selection. Following - * the calling of this method, no children of the component - * will be selected. - * <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. + * Sets the name of this component to the specified name. * - * @param point the point to check against this component. - * @return true if the point is within this component. - * @see #getBounds() + * @param name the new name of this component */ - public boolean contains(Point point) + public void setName(String name) { - /* - We can simply return the result of a - test for containment in the bounding rectangle - */ - return getBounds().contains(point); + this.name = name; + nameExplicitlySet = true; } /** - * Returns the <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. + * Returns the parent of this component. * - * @param point the point at which the returned accessible - * is located. - * @return null. + * @return the parent of this component */ - public Accessible getAccessibleAt(Point point) + public MenuContainer getParent() { - return null; - } + return parent; + } /** - * Returns the <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. + * Sets the parent of this component. * - * @param index the index of the <code>Accessible</code> child - * to retrieve. - * @return null. + * @param parent the parent to set */ - public Accessible getAccessibleChild(int index) + final void setParent(MenuContainer parent) { - return null; + this.parent = parent; } /** - * Returns the number of children of this component which - * implement the <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 /> + * Returns the native windowing system peer for this component. + * + * @return the peer for this component * - * @return 0. + * @deprecated */ - public int getAccessibleChildrenCount() + public MenuComponentPeer getPeer() { - return 0; + return peer; } /** - * Retrieves the <code>AccessibleComponent</code> associated - * with this accessible context and its component. As the - * context itself implements <code>AccessibleComponent</code>, - * this is the return value. + * Sets the peer for this component. * - * @return the context itself. + * @param peer the peer to set */ - public AccessibleComponent getAccessibleComponent() + final void setPeer(MenuComponentPeer peer) { - return this; + this.peer = peer; } /** - * Returns the accessible name for this menu component. This - * is the name given to the component, which may be null if - * not set using <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) + * Destroys this component's native peer */ - public String getAccessibleDescription() + public void removeNotify() { - return MenuComponent.this.getName(); + if (peer != null) + peer.dispose(); + peer = null; } /** - * Retrieves the index of this component within its parent. - * If no parent exists, -1 is returned. + * Returns the toolkit in use for this component. * - * @return -1 as the parent, a <code>MenuContainer</code> - * is not <code>Accessible</code>. + * @return the toolkit for this component */ - public int getAccessibleIndexInParent() + final Toolkit getToolkit() { - return -1; + return toolkit; } /** - * Returns the accessible name of this component. This - * is the name given to the component, which may be null if - * not set using <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. + * Returns the object used for synchronization locks on this component + * when performing tree and layout functions. * - * @return a localized name for this component. Currently, this - * is just the contents of the name property. - * @see MenuComponent#setName(String) + * @return the synchronization lock for this component */ - public String getAccessibleName() + protected final Object getTreeLock() { - return MenuComponent.this.getName(); + return tree_lock; } /** - * Returns the <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. + * Sets the sync lock object for this component. * - * @return null. + * @param treeLock the sync lock to set */ - public Accessible getAccessibleParent() + final void setTreeLock(Object treeLock) { - return null; + this.tree_lock = treeLock; } /** - * Returns the accessible role of this component. - * <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. + * AWT 1.0 event dispatcher. * - * @return <code>AccessibleRole.AWT_COMPONENT</code>. + * @return true if the event was dispatched, false otherwise + * + * @deprecated Deprecated in favor of <code>dispatchEvent()</code>. */ - public AccessibleRole getAccessibleRole() + public boolean + postEvent(Event event) { - return AccessibleRole.AWT_COMPONENT; + boolean retVal = false; + MenuContainer parent = getParent(); + if (parent != null) + retVal = parent.postEvent(event); + + return retVal; } /** - * Retrieves the <code>AccessibleSelection</code> associated - * with this accessible context and its component. As the - * context itself implements <code>AccessibleSelection</code>, - * this is the return value. + * Sends this event to this component or a subcomponent for processing. * - * @return the context itself. + * @param event The event to dispatch */ - public AccessibleSelection getAccessibleSelection() + public final void dispatchEvent(AWTEvent event) { - return this; + // Convert AWT 1.1 event to AWT 1.0 event. + Event oldStyleEvent = Component.translateEvent(event); + if (oldStyleEvent != null) + { + postEvent(oldStyleEvent); + } + + // See comment in Component.dispatchEvent(). + dispatchEventImpl(event); } /** - * Retrieves the <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. + * 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 index the index of the selected <code>Accessible</code> - * child. + * @param event the event to dispatch */ - public Accessible getAccessibleSelection(int index) + void dispatchEventImpl(AWTEvent event) { - return null; + // Do local processing. + processEvent(event); } /** - * Returns a count of the number of <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. + * Processes the specified event. In this class, this method simply + * calls one of the more specific event handlers. + * + * @param event the event to process */ - public int getAccessibleSelectionCount() + protected void processEvent(AWTEvent event) { - return 0; + // Pass a focus event to the focus listener for + // the accessibility context. + if (event instanceof FocusEvent) + { + if (focusListener != null) + { + switch (event.id) + { + case FocusEvent.FOCUS_GAINED: + focusListener.focusGained((FocusEvent) event); + break; + case FocusEvent.FOCUS_LOST: + focusListener.focusLost((FocusEvent) event); + break; + } + } + } } /** - * Retrieves the current state of this component - * in an accessible form. For example, a given component - * may be visible, selected, disabled, etc. - * <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. + * Returns a string representation of this component. * - * @return an empty <code>AccessibleStateSet</code>. + * @return a string representation of this component */ - public AccessibleStateSet getAccessibleStateSet() + public String toString() { - return new AccessibleStateSet(); + return getClass().getName() + "[" + paramString() + "]"; } /** - * Returns the background color of the component, or null - * if this property is unsupported. - * <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) + * Returns a debugging string for this component */ - public Color getBackground() + protected String paramString() { - return SystemColor.menu; + return "name=" + getName(); } /** - * 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. + * 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. - * @see #setBounds(java.awt.Rectangle) + * @return null */ - public Rectangle getBounds() + public AccessibleContext getAccessibleContext() { 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. + * This class provides a base for the accessibility support of menu + * components. * - * @return the default system cursor. - * @see #setCursor(java.awt.Cursor) + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) */ - public Cursor getCursor() + protected abstract class AccessibleAWTMenuComponent + extends AccessibleContext + implements Serializable, AccessibleComponent, AccessibleSelection { - return Cursor.getDefaultCursor(); - } - /** - * Returns the <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(); - } + /** + * Compatible with JDK 1.4.2 revision 5 + */ + private static final long serialVersionUID = -4269533416223798698L; - /** - * Retrieves information on the rendering and metrics of the supplied - * font. If font metrics are not supported by this component, null - * is returned. - * <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); - } + /** + * This is the default constructor. It should be called by + * concrete subclasses to ensure necessary groundwork is completed. + */ + protected AccessibleAWTMenuComponent() + { + // Nothing to do here. + } - /** - * Returns the foreground color of the component, or null - * if this property is unsupported. - * <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; - } + /** + * 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. + } - /** - * 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(); - } + /** + * Registers the specified focus listener to receive + * focus events from this component. + * + * @param listener the new focus listener + */ + public void addFocusListener(FocusListener listener) + { + // Chain the new focus listener to the existing chain + // of focus listeners. Each new focus listener is + // coupled via multicasting to the existing chain. + focusListener = AWTEventMulticaster.add(focusListener, listener); + } - /** - * Returns the location of the component, with co-ordinates - * relative to the parent component and using the co-ordinate - * space of the screen. Thus, the point (0,0) is the upper - * left corner of the parent component. - * <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(); - } + /** + * 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() + { + // Nothing to do here. + } - /** - * Returns the location of the component, with co-ordinates - * relative to the screen. Thus, the point (0,0) is the upper - * left corner of the screen. null is returned if the component - * is either not on screen or if this property is unsupported. - * <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 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 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 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 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 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 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 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; + } - /** - * 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; - } + /** + * 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 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 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(); + } - /** - * 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; - } + /** + * 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; + } - /** - * 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 */ - } + /** + * 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(); + } - /** - * Removes the specified focus listener from the list of registered - * focus listeners for this component. - * - * @param listener the listener to remove. - */ - public void removeFocusListener(FocusListener listener) - { - /* Remove the focus listener from the chain */ - focusListener = AWTEventMulticaster.remove(focusListener, listener); - } + /** + * Returns the <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; + } - /** - * 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 */ - } + /** + * 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; + } - /** - * 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); - } - } + /** + * 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; + } - /** - * 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 */ - } + /** + * 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; + } - /** - * 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 */ - } + /** + * 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; + } - /** - * 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 */ - } + /** + * 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(); + } - /** - * 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 #isEnabled() - */ - public void setEnabled(boolean enabled) - { - /* Ignored */ - } + /** + * 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; + } - /** - * 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); - } + /** + * 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; + } - /** - * 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 */ - } + /** + * 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(); + } - /** - * 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); - } + /** + * 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(); + } - /** - * 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); - } + /** + * 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); + } - /** - * 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 */ - } + /** + * 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; + } -} /* class AccessibleAWTMenuComponent */ - + /** + * 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; + } -} // class MenuComponent + /** + * 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 #isEnabled() + */ + 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. + } + + } + +} diff --git a/libjava/classpath/java/awt/Scrollbar.java b/libjava/classpath/java/awt/Scrollbar.java index 6e506c78584..c0788370b21 100644 --- a/libjava/classpath/java/awt/Scrollbar.java +++ b/libjava/classpath/java/awt/Scrollbar.java @@ -1,5 +1,5 @@ /* Scrollbar.java -- AWT Scrollbar widget - Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 + Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -593,13 +593,33 @@ public class Scrollbar extends Component implements Accessible, Adjustable adjustment_listeners.adjustmentValueChanged(event); } + /** + * Package private method to determine whether to call + * processEvent() or not. Will handle events from peer and update + * the current value. + */ void dispatchEventImpl(AWTEvent e) { if (e.id <= AdjustmentEvent.ADJUSTMENT_LAST - && e.id >= AdjustmentEvent.ADJUSTMENT_FIRST - && (adjustment_listeners != null - || (eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0)) - processEvent(e); + && e.id >= AdjustmentEvent.ADJUSTMENT_FIRST) + { + AdjustmentEvent ae = (AdjustmentEvent) e; + boolean adjusting = ae.getValueIsAdjusting(); + if (adjusting) + setValueIsAdjusting(true); + try + { + setValue(((AdjustmentEvent) e).getValue()); + if (adjustment_listeners != null + || (eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0) + processEvent(e); + } + finally + { + if (adjusting) + setValueIsAdjusting(false); + } + } else super.dispatchEventImpl(e); } diff --git a/libjava/classpath/java/awt/TextField.java b/libjava/classpath/java/awt/TextField.java index 3302a2eff89..23d3d918ff4 100644 --- a/libjava/classpath/java/awt/TextField.java +++ b/libjava/classpath/java/awt/TextField.java @@ -397,6 +397,7 @@ addNotify() return; setPeer((ComponentPeer)getToolkit().createTextField(this)); + super.addNotify(); } /*************************************************************************/ diff --git a/libjava/classpath/java/awt/Toolkit.java b/libjava/classpath/java/awt/Toolkit.java index 2ca88b6f598..e2a4bc92ea7 100644 --- a/libjava/classpath/java/awt/Toolkit.java +++ b/libjava/classpath/java/awt/Toolkit.java @@ -39,6 +39,8 @@ exception statement from your version. */ package java.awt; +import gnu.java.awt.peer.GLightweightPeer; + import java.awt.datatransfer.Clipboard; import java.awt.dnd.DragGestureEvent; import java.awt.dnd.DragGestureListener; @@ -46,6 +48,7 @@ import java.awt.dnd.DragGestureRecognizer; import java.awt.dnd.DragSource; import java.awt.dnd.peer.DragSourceContextPeer; import java.awt.event.AWTEventListener; +import java.awt.event.AWTEventListenerProxy; import java.awt.event.KeyEvent; import java.awt.im.InputMethodHighlight; import java.awt.image.ColorModel; @@ -76,6 +79,7 @@ import java.awt.peer.WindowPeer; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.net.URL; +import java.util.ArrayList; import java.util.Map; import java.util.Properties; @@ -114,10 +118,17 @@ public abstract class Toolkit = new PropertyChangeSupport(this); /** + * All registered AWTEventListener objects. This is package private, so the + * event queue can efficiently access this list. + */ + AWTEventListenerProxy[] awtEventListeners; + + /** * Default constructor for subclasses. */ public Toolkit() { + awtEventListeners = new AWTEventListenerProxy[0]; } /** @@ -349,7 +360,7 @@ public abstract class Toolkit */ protected LightweightPeer createComponent(Component target) { - return new gnu.java.awt.peer.GLightweightPeer (target); + return new GLightweightPeer(target); } /** @@ -462,7 +473,7 @@ public abstract class Toolkit */ public Insets getScreenInsets(GraphicsConfiguration gc) { - return null; + return new Insets(0, 0, 0, 0); } /** @@ -965,33 +976,230 @@ public abstract class Toolkit return desktopPropsSupport.getPropertyChangeListeners(name); } + /** + * Adds an AWTEventListener to this toolkit. This listener is informed about + * all events that pass the eventqueue that match the specified + * <code>evenMask</code>. The <code>eventMask</code> is an ORed combination + * of event masks as defined in {@link AWTEvent}. + * + * If a security manager is installed, it is asked first if an + * <code>AWTPermission("listenToAllAWTEvents")</code> is allowed. + * This may result in a <code>SecurityException</code> beeing thrown. + * + * It is not recommended to use this kind of notification for normal + * applications. It is intended solely for the purpose of debugging and to + * support special facilities. + * + * @param listener the listener to add + * @param eventMask the event mask of event types which the listener is + * interested in + * + * @since 1.2 + * + * @throws SecurityException if there is a <code>SecurityManager</code> that + * doesn't grant + * <code>AWTPermission("listenToAllAWTEvents")</code> + * + * @see #getAWTEventListeners() + * @see #getAWTEventListeners(long) + * @see #removeAWTEventListener(AWTEventListener) + */ public void addAWTEventListener(AWTEventListener listener, long eventMask) { - // SecurityManager s = System.getSecurityManager(); - // if (s != null) - // s.checkPermission(AWTPermission("listenToAllAWTEvents")); - // FIXME + // First we must check the security permissions. + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkPermission(new AWTPermission("listenToAllAWTEvents")); + + // Go through the list and check if the requested listener is already + // registered. + boolean found = false; + for (int i = 0; i < awtEventListeners.length; ++i) + { + AWTEventListenerProxy proxy = awtEventListeners[i]; + if (proxy.getListener() == listener) + { + found = true; + // Modify the proxies event mask to include the new event mask. + AWTEventListenerProxy newProxy = + new AWTEventListenerProxy(proxy.getEventMask() | eventMask, + listener); + awtEventListeners[i] = newProxy; + break; + } + } + + // If that listener was not found, then add it. + if (! found) + { + AWTEventListenerProxy proxy = + new AWTEventListenerProxy(eventMask, listener); + AWTEventListenerProxy[] newArray = + new AWTEventListenerProxy[awtEventListeners.length + 1]; + System.arraycopy(awtEventListeners, 0, newArray, 0, + awtEventListeners.length); + newArray[newArray.length - 1] = proxy; + awtEventListeners = newArray; + } } + /** + * Removes an AWT event listener from this toolkit. This listener is no + * longer informed of any event types it was registered in. + * + * If a security manager is installed, it is asked first if an + * <code>AWTPermission("listenToAllAWTEvents")</code> is allowed. + * This may result in a <code>SecurityException</code> beeing thrown. + * + * It is not recommended to use this kind of notification for normal + * applications. It is intended solely for the purpose of debugging and to + * support special facilities. + * + * @param listener the listener to remove + * + * @throws SecurityException if there is a <code>SecurityManager</code> that + * doesn't grant + * <code>AWTPermission("listenToAllAWTEvents")</code> + * + * @since 1.2 + * + * @see #addAWTEventListener(AWTEventListener, long) + * @see #getAWTEventListeners() + * @see #getAWTEventListeners(long) + */ public void removeAWTEventListener(AWTEventListener listener) { - // FIXME + // First we must check the security permissions. + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkPermission(new AWTPermission("listenToAllAWTEvents")); + + + // Find the index of the listener. + int index = -1; + for (int i = 0; i < awtEventListeners.length; ++i) + { + AWTEventListenerProxy proxy = awtEventListeners[i]; + if (proxy.getListener() == listener) + { + index = i; + break; + } + } + + // Copy over the arrays and leave out the removed element. + if (index != -1) + { + AWTEventListenerProxy[] newArray = + new AWTEventListenerProxy[awtEventListeners.length - 1]; + if (index > 0) + System.arraycopy(awtEventListeners, 0, newArray, 0, index); + if (index < awtEventListeners.length - 1) + System.arraycopy(awtEventListeners, index + 1, newArray, index, + awtEventListeners.length - index - 1); + awtEventListeners = newArray; + } } /** + * Returns all registered AWT event listeners. This method returns a copy of + * the listener array, so that application cannot trash the listener list. + * + * If a security manager is installed, it is asked first if an + * <code>AWTPermission("listenToAllAWTEvents")</code> is allowed. + * This may result in a <code>SecurityException</code> beeing thrown. + * + * It is not recommended to use this kind of notification for normal + * applications. It is intended solely for the purpose of debugging and to + * support special facilities. + * + * @return all registered AWT event listeners + * + * @throws SecurityException if there is a <code>SecurityManager</code> that + * doesn't grant + * <code>AWTPermission("listenToAllAWTEvents")</code> + * * @since 1.4 + * + * @see #addAWTEventListener(AWTEventListener, long) + * @see #removeAWTEventListener(AWTEventListener) + * @see #getAWTEventListeners(long) */ public AWTEventListener[] getAWTEventListeners() { - return null; + // First we must check the security permissions. + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkPermission(new AWTPermission("listenToAllAWTEvents")); + + // Create a copy of the array. + AWTEventListener[] copy = new AWTEventListener[awtEventListeners.length]; + System.arraycopy(awtEventListeners, 0, copy, 0, awtEventListeners.length); + return copy; } /** + * Returns all registered AWT event listeners that listen for events with + * the specified <code>eventMask</code>. This method returns a copy of + * the listener array, so that application cannot trash the listener list. + * + * If a security manager is installed, it is asked first if an + * <code>AWTPermission("listenToAllAWTEvents")</code> is allowed. + * This may result in a <code>SecurityException</code> beeing thrown. + * + * It is not recommended to use this kind of notification for normal + * applications. It is intended solely for the purpose of debugging and to + * support special facilities. + * + * @param mask the event mask + * + * @throws SecurityException if there is a <code>SecurityManager</code> that + * doesn't grant + * <code>AWTPermission("listenToAllAWTEvents")</code> + * + * * @since 1.4 + * + * @see #addAWTEventListener(AWTEventListener, long) + * @see #removeAWTEventListener(AWTEventListener) + * @see #getAWTEventListeners() */ public AWTEventListener[] getAWTEventListeners(long mask) { - return null; + // First we must check the security permissions. + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkPermission(new AWTPermission("listenToAllAWTEvents")); + + // Create a copy of the array with only the requested listeners in it. + ArrayList l = new ArrayList(awtEventListeners.length); + for (int i = 0; i < awtEventListeners.length; ++i) + { + if ((awtEventListeners[i].getEventMask() & mask) != 0) + l.add(awtEventListeners[i]); + } + + return (AWTEventListener[] ) l.toArray(new AWTEventListener[l.size()]); + } + + + /** + * Dispatches events to listeners registered to this Toolkit. This is called + * by {@link Component#dispatchEventImpl(AWTEvent)} in order to dispatch + * events globally. + * + * @param ev the event to dispatch + */ + void globalDispatchEvent(AWTEvent ev) + { + // We do not use the accessor methods here because they create new + // arrays each time. We must be very efficient, so we access this directly. + for (int i = 0; i < awtEventListeners.length; ++i) + { + AWTEventListenerProxy proxy = awtEventListeners[i]; + if ((proxy.getEventMask() & AWTEvent.eventIdToMask(ev.getID())) != 0) + proxy.eventDispatched(ev); + } } /** diff --git a/libjava/classpath/java/awt/Window.java b/libjava/classpath/java/awt/Window.java index f8a620daebd..71a8d388b30 100644 --- a/libjava/classpath/java/awt/Window.java +++ b/libjava/classpath/java/awt/Window.java @@ -281,50 +281,53 @@ public class Window extends Container implements Accessible public void show() { synchronized (getTreeLock()) - { - if (parent != null && !parent.isDisplayable()) - parent.addNotify(); - if (peer == null) - addNotify(); - - // Show visible owned windows. - Iterator e = ownedWindows.iterator(); - while(e.hasNext()) - { - Window w = (Window)(((Reference) e.next()).get()); - if (w != null) - { - if (w.isVisible()) - w.getPeer().setVisible(true); - } - else - // Remove null weak reference from ownedWindows. - // Unfortunately this can't be done in the Window's - // finalize method because there is no way to guarantee - // synchronous access to ownedWindows there. - e.remove(); - } - validate(); - super.show(); - toFront(); - - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - manager.setGlobalFocusedWindow (this); - - if (!shown) { - FocusTraversalPolicy policy = getFocusTraversalPolicy (); - Component initialFocusOwner = null; + if (parent != null && ! parent.isDisplayable()) + parent.addNotify(); + if (peer == null) + addNotify(); + + validate(); + if (visible) + toFront(); + else + { + super.show(); + // Show visible owned windows. + Iterator e = ownedWindows.iterator(); + while (e.hasNext()) + { + Window w = (Window) (((Reference) e.next()).get()); + if (w != null) + { + if (w.isVisible()) + w.getPeer().setVisible(true); + } + else + // Remove null weak reference from ownedWindows. + // Unfortunately this can't be done in the Window's + // finalize method because there is no way to guarantee + // synchronous access to ownedWindows there. + e.remove(); + } + } + KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + manager.setGlobalFocusedWindow(this); - if (policy != null) - initialFocusOwner = policy.getInitialComponent (this); + if (! shown) + { + FocusTraversalPolicy policy = getFocusTraversalPolicy(); + Component initialFocusOwner = null; - if (initialFocusOwner != null) - initialFocusOwner.requestFocusInWindow (); + if (policy != null) + initialFocusOwner = policy.getInitialComponent(this); - shown = true; + if (initialFocusOwner != null) + initialFocusOwner.requestFocusInWindow(); + + shown = true; + } } - } } public void hide() diff --git a/libjava/classpath/java/awt/datatransfer/DataFlavor.java b/libjava/classpath/java/awt/datatransfer/DataFlavor.java index 32bf4d6cf37..788ae6d6a52 100644 --- a/libjava/classpath/java/awt/datatransfer/DataFlavor.java +++ b/libjava/classpath/java/awt/datatransfer/DataFlavor.java @@ -157,38 +157,42 @@ public class DataFlavor implements java.io.Externalizable, Cloneable ClassLoader classLoader) throws ClassNotFoundException { + // Bootstrap try { - return(Class.forName(className)); + return Class.forName(className); } - catch(Exception e) { ; } - // Commented out for Java 1.1 - /* - try + catch(ClassNotFoundException cnfe) { - return(className.getClass().getClassLoader().findClass(className)); + // Ignored. } - catch(Exception e) { ; } + // System try { - return(ClassLoader.getSystemClassLoader().findClass(className)); + ClassLoader loader = ClassLoader.getSystemClassLoader(); + return Class.forName(className, true, loader); } - catch(Exception e) { ; } - */ - - // FIXME: What is the context class loader? - /* + catch(ClassNotFoundException cnfe) + { + // Ignored. + } + + // Context try { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + return Class.forName(className, true, loader); } - catch(Exception e) { ; } - */ - + catch(ClassNotFoundException cnfe) + { + // Ignored. + } + if (classLoader != null) - return(classLoader.loadClass(className)); - else - throw new ClassNotFoundException(className); + return Class.forName(className, true, classLoader); + + throw new ClassNotFoundException(className); } private static Class getRepresentationClassFromMime(String mimeString, @@ -203,7 +207,13 @@ public class DataFlavor implements java.io.Externalizable, Cloneable } catch(Exception e) { - throw new IllegalArgumentException("classname: " + e.getMessage()); + IllegalArgumentException iae; + iae = new IllegalArgumentException("mimeString: " + + mimeString + + " classLoader: " + + classLoader); + iae.initCause(e); + throw iae; } } else diff --git a/libjava/classpath/java/awt/dnd/DragSource.java b/libjava/classpath/java/awt/dnd/DragSource.java index 13ffc961510..05eb6709d47 100644 --- a/libjava/classpath/java/awt/dnd/DragSource.java +++ b/libjava/classpath/java/awt/dnd/DragSource.java @@ -90,7 +90,7 @@ public class DragSource implements Serializable */ public static DragSource getDefaultDragSource() { - return null; + return new DragSource(); } public static boolean isDragImageSupported() @@ -172,13 +172,34 @@ public class DragSource implements Serializable return flavorMap; } + /** + * Dummy DragGestureRecognizer when Toolkit doesn't support drag and drop. + */ + static class NoDragGestureRecognizer extends DragGestureRecognizer + { + NoDragGestureRecognizer(DragSource ds, Component c, int actions, + DragGestureListener dgl) + { + super(ds, c, actions, dgl); + } + + protected void registerListeners() { } + protected void unregisterListeners() { } + } + public DragGestureRecognizer createDragGestureRecognizer(Class recognizer, Component c, int actions, DragGestureListener dgl) { - return Toolkit.getDefaultToolkit () + DragGestureRecognizer dgr; + dgr = Toolkit.getDefaultToolkit () .createDragGestureRecognizer (recognizer, this, c, actions, dgl); + + if (dgr == null) + dgr = new NoDragGestureRecognizer(this, c, actions, dgl); + + return dgr; } public DragGestureRecognizer diff --git a/libjava/classpath/java/awt/doc-files/capjoin.png b/libjava/classpath/java/awt/doc-files/capjoin.png Binary files differnew file mode 100644 index 00000000000..555dca90132 --- /dev/null +++ b/libjava/classpath/java/awt/doc-files/capjoin.png diff --git a/libjava/classpath/java/awt/event/AWTEventListenerProxy.java b/libjava/classpath/java/awt/event/AWTEventListenerProxy.java index 3d9958b1abd..55a4bfe376a 100644 --- a/libjava/classpath/java/awt/event/AWTEventListenerProxy.java +++ b/libjava/classpath/java/awt/event/AWTEventListenerProxy.java @@ -72,75 +72,15 @@ public class AWTEventListenerProxy extends EventListenerProxy } /** - * Forwards events on to the delegate if they meet the event mask. + * Forwards events on to the delegate. + * + * @param event the to forward to the delagate listener * - * @param event the property change event to filter * @throws NullPointerException if the delegate this was created with is null */ public void eventDispatched(AWTEvent event) { - int id = event == null ? 0 : event.getID(); - if (((mask & AWTEvent.ACTION_EVENT_MASK) != 0 - && event instanceof ActionEvent) - || ((mask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0 - && event instanceof AdjustmentEvent) - || ((mask & AWTEvent.COMPONENT_EVENT_MASK) != 0 - && event instanceof ComponentEvent - && (id >= ComponentEvent.COMPONENT_FIRST - && id <= ComponentEvent.COMPONENT_LAST)) - || ((mask & AWTEvent.CONTAINER_EVENT_MASK) != 0 - && event instanceof ContainerEvent) - || ((mask & AWTEvent.FOCUS_EVENT_MASK) != 0 - && event instanceof FocusEvent) - || ((mask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 - && event instanceof HierarchyEvent - && (id == HierarchyEvent.ANCESTOR_MOVED - || id == HierarchyEvent.ANCESTOR_RESIZED)) - || ((mask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 - && event instanceof HierarchyEvent - && id == HierarchyEvent.HIERARCHY_CHANGED) - || ((mask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 - && event instanceof InputMethodEvent) - || ((mask & AWTEvent.INVOCATION_EVENT_MASK) != 0 - && event instanceof InvocationEvent) - || ((mask & AWTEvent.ITEM_EVENT_MASK) != 0 - && event instanceof ItemEvent) - || ((mask & AWTEvent.KEY_EVENT_MASK) != 0 - && event instanceof KeyEvent) - || ((mask & AWTEvent.MOUSE_EVENT_MASK) != 0 - && event instanceof MouseEvent - && (id == MouseEvent.MOUSE_PRESSED - || id == MouseEvent.MOUSE_RELEASED - || id == MouseEvent.MOUSE_CLICKED - || id == MouseEvent.MOUSE_ENTERED - || id == MouseEvent.MOUSE_EXITED)) - || ((mask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 - && event instanceof MouseEvent - && (id == MouseEvent.MOUSE_MOVED - || id == MouseEvent.MOUSE_DRAGGED)) - || ((mask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0 - && event instanceof MouseWheelEvent) - || ((mask & AWTEvent.PAINT_EVENT_MASK) != 0 - && event instanceof PaintEvent) - || ((mask & AWTEvent.TEXT_EVENT_MASK) != 0 - && event instanceof TextEvent) - || ((mask & AWTEvent.WINDOW_EVENT_MASK) != 0 - && event instanceof WindowEvent - && (id == WindowEvent.WINDOW_OPENED - || id == WindowEvent.WINDOW_CLOSING - || id == WindowEvent.WINDOW_CLOSED - || id == WindowEvent.WINDOW_ICONIFIED - || id == WindowEvent.WINDOW_DEICONIFIED - || id == WindowEvent.WINDOW_ACTIVATED - || id == WindowEvent.WINDOW_DEACTIVATED)) - || ((mask & AWTEvent.WINDOW_FOCUS_EVENT_MASK) != 0 - && event instanceof WindowEvent - && (id == WindowEvent.WINDOW_GAINED_FOCUS - || id == WindowEvent.WINDOW_LOST_FOCUS)) - || ((mask & AWTEvent.WINDOW_STATE_EVENT_MASK) != 0 - && event instanceof WindowEvent - && id == WindowEvent.WINDOW_STATE_CHANGED)) - ((AWTEventListener) getListener()).eventDispatched(event); + ((AWTEventListener) getListener()).eventDispatched(event); } /** diff --git a/libjava/classpath/java/awt/peer/ComponentPeer.java b/libjava/classpath/java/awt/peer/ComponentPeer.java index 1ba16923224..97b96f49cdb 100644 --- a/libjava/classpath/java/awt/peer/ComponentPeer.java +++ b/libjava/classpath/java/awt/peer/ComponentPeer.java @@ -59,76 +59,344 @@ import java.awt.image.ImageObserver; import java.awt.image.ImageProducer; import java.awt.image.VolatileImage; +/** + * Defines the methods that a component peer is required to implement. + */ public interface ComponentPeer { + /** + * Returns the construction status of the specified image. This is called + * by {@link Component#checkImage(Image, int, int, ImageObserver)}. + * + * @param img the image + * @param width the width of the image + * @param height the height of the image + * @param ob the image observer to be notified of updates of the status + * + * @return a bitwise ORed set of ImageObserver flags + */ int checkImage(Image img, int width, int height, - ImageObserver ob); + ImageObserver ob); + + /** + * Creates an image by starting the specified image producer. This is called + * by {@link Component#createImage(ImageProducer)}. + * + * @param prod the image producer to be used to create the image + * + * @return the created image + */ Image createImage(ImageProducer prod); + + /** + * Creates an empty image with the specified <code>width</code> and + * <code>height</code>. + * + * @param width the width of the image to be created + * @param height the height of the image to be created + * + * @return the created image + */ Image createImage(int width, int height); + + /** + * Disables the component. This is called by {@link Component#disable()}. + */ void disable(); + + /** + * Disposes the component peer. This should release all resources held by the + * peer. This is called when the component is no longer in use. + */ void dispose(); + + /** + * Enables the component. This is called by {@link Component#enable()}. + */ void enable(); + + /** + * Returns the color model of the component. This is currently not used. + * + * @return the color model of the component + */ ColorModel getColorModel(); + + /** + * Returns the font metrics for the specified font. This is called by + * {@link Component#getFontMetrics(Font)}. + * + * @param f the font for which to query the font metrics + * + * @return the font metrics for the specified font + */ FontMetrics getFontMetrics(Font f); + + /** + * Returns a {@link Graphics} object suitable for drawing on this component. + * This is called by {@link Component#getGraphics()}. + * + * @return a graphics object suitable for drawing on this component + */ Graphics getGraphics(); + + /** + * Returns the location of this component in screen coordinates. This is + * called by {@link Component#getLocationOnScreen()}. + * + * @return the location of this component in screen coordinates + */ Point getLocationOnScreen(); + + /** + * Returns the minimum size for the component. This is called by + * {@link Component#getMinimumSize()}. + * + * @return the minimum size for the component + */ Dimension getMinimumSize(); + + /** + * Returns the preferred size for the component. This is called by + * {@link Component#getPreferredSize()}. + * + * @return the preferred size for the component + */ Dimension getPreferredSize(); + + /** + * Returns the toolkit that created this peer. + * + * @return the toolkit that created this peer + */ Toolkit getToolkit(); + + /** + * Handles the given event. This is called from + * {@link Component#dispatchEvent(AWTEvent)} to give the peer a chance to + * react to events for the component. + * + * @param e the event + */ void handleEvent(AWTEvent e); + + /** + * Makes the component invisible. This is called from + * {@link Component#hide()}. + */ void hide(); /** - * Part of the earlier 1.1 API, replaced by isFocusable(). + * Returns <code>true</code> if the component can receive keyboard input + * focus. This is called from {@link Component#isFocusTraversable()}. + * + * @specnote Part of the earlier 1.1 API, replaced by isFocusable(). */ boolean isFocusTraversable(); + + /** + * Returns <code>true</code> if the component can receive keyboard input + * focus. This is called from {@link Component#isFocusable()}. + */ boolean isFocusable(); + + /** + * Returns the minimum size for the component. This is called by + * {@link Component#minimumSize()}. + * + * @return the minimum size for the component + */ Dimension minimumSize(); + + /** + * Returns the preferred size for the component. This is called by + * {@link Component#getPreferredSize()}. + * + * @return the preferred size for the component + */ Dimension preferredSize(); + void paint(Graphics graphics); + + /** + * Prepares an image for rendering on this component. This is called by + * {@link Component#prepareImage(Image, int, int, ImageObserver)}. + * + * @param img the image to prepare + * @param width the desired width of the rendered image + * @param height the desired height of the rendered image + * @param ob the image observer to be notified of updates in the preparation + * process + * + * @return <code>true</code> if the image has been fully prepared, + * <code>false</code> otherwise (in which case the image observer + * receives updates) + */ boolean prepareImage(Image img, int width, int height, ImageObserver ob); + void print(Graphics graphics); + + /** + * Repaints the specified rectangle of this component. This is called from + * {@link Component#repaint(long, int, int, int, int)}. + * + * @param tm number of milliseconds to wait with repainting + * @param x the X coordinate of the upper left corner of the damaged rectangle + * @param y the Y coordinate of the upper left corner of the damaged rectangle + * @param width the width of the damaged rectangle + * @param height the height of the damaged rectangle + */ void repaint(long tm, int x, int y, int width, int height); /** - * Part of the earlier 1.1 API, apparently replaced by argument - * form of the same method. + * Requests that this component receives the focus. This is called from + * {@link Component#requestFocus()}. + * + * @specnote Part of the earlier 1.1 API, apparently replaced by argument + * form of the same method. */ void requestFocus(); - boolean requestFocus (Component source, boolean bool1, boolean bool2, long x); + /** + * Requests that this component receives the focus. This is called from + * {@link Component#requestFocus()}. + * + * @param source TODO + * @param bool1 TODO + * @param bool2 TODO + * @param x TODO + */ + boolean requestFocus(Component source, boolean bool1, boolean bool2, long x); + + /** + * Notifies the peer that the bounds of this component have changed. This + * is called by {@link Component#reshape(int, int, int, int)}. + * + * @param x the X coordinate of the upper left corner of the component + * @param y the Y coordinate of the upper left corner of the component + * @param width the width of the component + * @param height the height of the component + */ void reshape(int x, int y, int width, int height); + + /** + * Sets the background color of the component. This is called by + * {@link Component#setBackground(Color)}. + * + * @param color the background color to set + */ void setBackground(Color color); + + /** + * Notifies the peer that the bounds of this component have changed. This + * is called by {@link Component#setBounds(int, int, int, int)}. + * + * @param x the X coordinate of the upper left corner of the component + * @param y the Y coordinate of the upper left corner of the component + * @param width the width of the component + * @param height the height of the component + */ void setBounds(int x, int y, int width, int height); /** - * Part of the earlier 1.1 API, apparently no longer needed. + * Sets the cursor of the component. This is called by + * {@link Component#setCursor(Cursor)}. + * + * @specnote Part of the earlier 1.1 API, apparently no longer needed. */ void setCursor(Cursor cursor); + /** + * Sets the enabled/disabled state of this component. This is called by + * {@link Component#setEnabled(boolean)}. + * + * @param enabled <code>true</code> to enable the component, + * <code>false</code> to disable it + */ void setEnabled(boolean enabled); + + /** + * Sets the font of the component. This is called by + * {@link Component#setFont(Font)}. + * + * @param font the font to set + */ void setFont(Font font); + + /** + * Sets the foreground color of the component. This is called by + * {@link Component#setForeground(Color)}. + * + * @param color the foreground color to set + */ void setForeground(Color color); + + /** + * Sets the visibility state of the component. This is called by + * {@link Component#setVisible(boolean)}. + * + * @param visible <code>true</code> to make the component visible, + * <code>false</code> to make it invisible + */ void setVisible(boolean visible); + + /** + * Makes the component visible. This is called by {@link Component#show()}. + */ void show(); /** * Get the graphics configuration of the component. The color model * of the component can be derived from the configuration. + * + * @return the graphics configuration of the component */ GraphicsConfiguration getGraphicsConfiguration(); /** * Part of an older API, no longer needed. */ - void setEventMask (long mask); + void setEventMask(long mask); - // Methods below are introduced since 1.1 + /** + * Returns <code>true</code> if this component has been obscured, + * <code>false</code> otherwise. This will only work if + * {@link #canDetermineObscurity()} also returns <code>true</code>. + * + * @return <code>true</code> if this component has been obscured, + * <code>false</code> otherwise. + */ boolean isObscured(); + + /** + * Returns <code>true</code> if this component peer can determine if the + * component has been obscured, <code>false</code> otherwise. + * + * @return <code>true</code> if this component peer can determine if the + * component has been obscured, <code>false</code> otherwise + */ boolean canDetermineObscurity(); + + /** + * Coalesces the specified paint event. + * + * @param e the paint event + */ void coalescePaintEvent(PaintEvent e); + + /** + * Updates the cursor. + */ void updateCursorImmediately(); + + /** + * Returns true, if this component can handle wheel scrolling, + * <code>false</code> otherwise. + * + * @return true, if this component can handle wheel scrolling, + * <code>false</code> otherwise + */ boolean handlesWheelScrolling(); /** diff --git a/libjava/classpath/java/awt/print/NoPrinterJob.java b/libjava/classpath/java/awt/print/NoPrinterJob.java new file mode 100644 index 00000000000..e9659a147e7 --- /dev/null +++ b/libjava/classpath/java/awt/print/NoPrinterJob.java @@ -0,0 +1,124 @@ +/* NoPrinterJob.java -- Fake PrinterJob that just signals no print service. + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt.print; + +/** + * Fake PrinterJob that just signals no print service. This is only + * here so applications can call + * <code>PrintJob.getPrinterJob().getPrinterJob()</code> and check + * that it returns <code>null</code> which indicates no actual + * printing support is available. + */ +class NoPrinterJob extends PrinterJob +{ + public int getCopies() + { + return 0; + } + + public void setCopies(int copies) + { + // Do nothing. + } + + public String getJobName() + { + return "NoPrinterJob"; + } + + public void setJobName(String job_name) + { + // Do nothing. + } + + public String getUserName() + { + return "NoUser"; + } + + public void cancel() + { + // Do nothing. + } + + public boolean isCancelled() + { + return true; + } + + public PageFormat defaultPage(PageFormat page_format) + { + return page_format; + } + + public PageFormat pageDialog(PageFormat page_format) + { + return page_format; + } + + public void print() throws PrinterException + { + throw new PrinterException("No printer"); + } + + public boolean printDialog() + { + return false; + } + + public void setPageable(Pageable pageable) + { + // Do nothing. + } + + public void setPrintable(Printable printable) + { + // Do nothing. + } + + public void setPrintable(Printable printable, PageFormat page_format) + { + // Do nothing. + } + + public PageFormat validatePage(PageFormat page_format) + { + return page_format; + } +} diff --git a/libjava/classpath/java/awt/print/PageFormat.java b/libjava/classpath/java/awt/print/PageFormat.java index 6399552de44..0a8aa3ed0eb 100644 --- a/libjava/classpath/java/awt/print/PageFormat.java +++ b/libjava/classpath/java/awt/print/PageFormat.java @@ -1,5 +1,5 @@ /* PageFormat.java -- Information about the page format - Copyright (C) 1999 Free Software Foundation, Inc. + Copyright (C) 1999, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,254 +39,195 @@ exception statement from your version. */ package java.awt.print; /** - * This class contains information about the desired page format to - * use for printing a particular set of pages. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class PageFormat implements Cloneable -{ - -/* - * Static Variables - */ - -/** - * A constant for a landscaped page orientation. Used by - * <code>getOrientation</code> and <code>setOrientation</code>. - */ -public static final int LANDSCAPE = 0; - -/** - * A constant for a portrait page orientation. Used by - * <code>getOrientation</code> and <code>setOrientation</code>. - */ -public static final int PORTRAIT = 1; - -/** - * A constant for a reversed landscaped page orientation. This is - * the orientation used by Macintosh's for landscape. The origin is - * in the upper right hand corner instead of the upper left. The - * X and Y axes are reversed. Used by <code>getOrientation</code> and - * <code>setOrientation</code>. - */ -public static final int REVERSE_LANDSCAPE = 2; - -/*************************************************************************/ - -/* - * Instance Variables + * This class contains information about the desired page format to use for + * printing a particular set of pages. + * + * @author Aaron M. Renn (arenn@urbanophile.com) */ - -// The page orientation -private int orientation; - -// The paper type -private Paper paper; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** - * This method creates a default page layout, which will be in portrait - * format. - */ -public -PageFormat() -{ - this.paper = new Paper(); - this.orientation = PORTRAIT; -} - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * This method returns the width of the page, in 1/72nd's of an inch. The - * "width" measured depends on orientation. - * - * @return The width of the page. - */ -public double -getWidth() -{ - return(paper.getWidth()); -} - -/*************************************************************************/ - -/** - * This method returns the height of the page, in 1/72nd's of an inch. - * The "height" measured depends on the orientation. - * - * @return The height of the page. - */ -public double -getHeight() -{ - return(paper.getHeight()); -} - -/*************************************************************************/ - -/** - * This method returns the X coordinate value of the upper leftmost - * drawable area of the paper. - * - * @return The upper leftmost imageable X coordinate. - */ -public double -getImageableX() -{ - return(paper.getImageableX()); -} - -/*************************************************************************/ - -/** - * This method returns the Y coordinate value of the upper leftmost - * drawable area of the paper. - * - * @return The upper leftmost imageable Y coordinate. - */ -public double -getImageableY() -{ - return(paper.getImageableY()); -} - -/*************************************************************************/ - -/** - * This method returns the imageable width of the paper, in 1/72nd's of - * an inch. - * - * @return The imageable width of the paper. - */ -public double -getImageableWidth() +public class PageFormat + implements Cloneable { - return(paper.getImageableWidth()); -} - -/*************************************************************************/ + /** + * A constant for a landscaped page orientation. Used by + * <code>getOrientation</code> and <code>setOrientation</code>. + */ + public static final int LANDSCAPE = 0; + + /** + * A constant for a portrait page orientation. Used by + * <code>getOrientation</code> and <code>setOrientation</code>. + */ + public static final int PORTRAIT = 1; + + /** + * A constant for a reversed landscaped page orientation. This is the + * orientation used by Macintosh's for landscape. The origin is in the + * upper right hand corner instead of the upper left. The X and Y axes + * are reversed. Used by <code>getOrientation</code> and + * <code>setOrientation</code>. + */ + public static final int REVERSE_LANDSCAPE = 2; + + // The page orientation + private int orientation; + + // The paper type + private Paper paper; + + /** + * This method creates a default page layout, which will be in portrait + * format. + */ + public PageFormat() + { + this.paper = new Paper(); + this.orientation = PORTRAIT; + } + + /** + * This method returns the width of the page, in 1/72nd's of an inch. The + * "width" measured depends on orientation. + * + * @return The width of the page. + */ + public double getWidth() + { + return paper.getWidth(); + } + + /** + * This method returns the height of the page, in 1/72nd's of an inch. The + * "height" measured depends on the orientation. + * + * @return The height of the page. + */ + public double getHeight() + { + return paper.getHeight(); + } + + /** + * This method returns the X coordinate value of the upper leftmost drawable + * area of the paper. + * + * @return The upper leftmost imageable X coordinate. + */ + public double getImageableX() + { + return paper.getImageableX(); + } + + /** + * This method returns the Y coordinate value of the upper leftmost drawable + * area of the paper. + * + * @return The upper leftmost imageable Y coordinate. + */ + public double getImageableY() + { + return paper.getImageableY(); + } + + /** + * This method returns the imageable width of the paper, in 1/72nd's of an + * inch. + * + * @return The imageable width of the paper. + */ + public double getImageableWidth() + { + return paper.getImageableWidth(); + } + + /** + * This method returns the imageable height of the paper, in 1/72nd's of an + * inch. + * + * @return The imageable height of the paper. + */ + public double getImageableHeight() + { + return paper.getImageableHeight(); + } + + /** + * Returns a copy of the <code>paper</code> object being used for this page + * format. + * + * @return A copy of the <code>Paper</code> object for this format. + */ + public Paper getPaper() + { + return (Paper) paper.clone(); + } + + /** + * Sets the <code>Paper</code> object to be used by this page format. + * + * @param paper The new <code>Paper</code> object for this page format. + */ + public void setPaper(Paper paper) + { + this.paper = paper; + } + + /** + * This method returns the current page orientation. The value returned will + * be one of the page orientation constants from this class. + * + * @return The current page orientation. + */ + public int getOrientation() + { + return orientation; + } + + /** + * This method sets the page orientation for this format to the specified + * value. It must be one of the page orientation constants from this class + * or an exception will be thrown. + * + * @param orientation The new page orientation. + * @exception IllegalArgumentException If the specified page orientation + * value is not one of the constants from this class. + */ + public void setOrientation(int orientation) throws IllegalArgumentException + { + if ((orientation != PORTRAIT) && (orientation != LANDSCAPE) + && (orientation != REVERSE_LANDSCAPE)) + throw new IllegalArgumentException("Bad page orientation value: " + + orientation); + + this.orientation = orientation; + } + + /** + * This method returns a matrix used for transforming user space coordinates + * to page coordinates. The value returned will be six doubles as described + * in <code>java.awt.geom.AffineTransform</code>. + * + * @return The transformation matrix for this page format. + */ + public double[] getMatrix() + { + throw new RuntimeException("Not implemented since I don't know what to do"); + } + + /** + * This method returns a copy of this object. + * + * @return A copy of this object. + */ + public Object clone() + { + try + { + return (super.clone()); + } + catch (CloneNotSupportedException e) + { + return (null); + } + } -/** - * This method returns the imageable height of the paper, in 1/72nd's of - * an inch. - * - * @return The imageable height of the paper. - */ -public double getImageableHeight() -{ - return(paper.getImageableHeight()); } - -/*************************************************************************/ - -/** - * Returns a copy of the <code>paper</code> object being used for this - * page format. - * - * @return A copy of the <code>Paper</code> object for this format. - */ -public Paper -getPaper() -{ - return((Paper)paper.clone()); -} - -/*************************************************************************/ - -/** - * Sets the <code>Paper</code> object to be used by this page format. - * - * @param paper The new <code>Paper</code> object for this page format. - */ -public void -setPaper(Paper paper) -{ - this.paper = paper; -} - -/*************************************************************************/ - -/** - * This method returns the current page orientation. The value returned - * will be one of the page orientation constants from this class. - * - * @return The current page orientation. - */ -public int -getOrientation() -{ - return(orientation); -} - -/*************************************************************************/ - -/** - * This method sets the page orientation for this format to the - * specified value. It must be one of the page orientation constants - * from this class or an exception will be thrown. - * - * @param orientation The new page orientation. - * - * @exception IllegalArgumentException If the specified page orientation - * value is not one of the constants from this class. - */ -public void -setOrientation(int orientation) throws IllegalArgumentException -{ - if ((orientation != PORTRAIT) && - (orientation != LANDSCAPE) && - (orientation != REVERSE_LANDSCAPE)) - throw new IllegalArgumentException("Bad page orientation value: " + - orientation); - - this.orientation = orientation; -} - -/*************************************************************************/ - -/** - * This method returns a matrix used for transforming user space - * coordinates to page coordinates. The value returned will be six - * doubles as described in <code>java.awt.geom.AffineTransform</code>. - * - * @return The transformation matrix for this page format. - */ -public double[] -getMatrix() -{ - throw new RuntimeException("Not implemented since I don't know what to do"); -} - -/*************************************************************************/ - -/** - * This method returns a copy of this object. - * - * @return A copy of this object. - */ -public Object -clone() -{ - try - { - return(super.clone()); - } - catch(CloneNotSupportedException e) - { - return(null); - } -} - -} // class PageFormat - diff --git a/libjava/classpath/java/awt/print/Pageable.java b/libjava/classpath/java/awt/print/Pageable.java index 12fa542a8c6..d61195a92f0 100644 --- a/libjava/classpath/java/awt/print/Pageable.java +++ b/libjava/classpath/java/awt/print/Pageable.java @@ -1,5 +1,5 @@ /* Pageable.java -- Pages to be printed - Copyright (C) 1999 Free Software Foundation, Inc. + Copyright (C) 1999, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,75 +39,52 @@ exception statement from your version. */ package java.awt.print; /** - * This interface represents pages that are to be printed. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ + * This interface represents pages that are to be printed. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ public interface Pageable { - -/* - * Static Variables - */ - -/** - * This constant is returned when <code>getNumberOfPages()</code> - * cannot determine the number of pages available for printing. - */ -int UNKNOWN_NUMBER_OF_PAGES = -1; - -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** - * This method returns the number of pages this object contains, or - * <code>UNKNOWN_NUMBER_OF_PAGES</code> if it cannot determine the number - * of pages to be printed. - * - * @return The number of pages to be printed, or - * <code>UNKNOWN_NUMBER_OF_PAGES</code> if this is unknown. - */ -int -getNumberOfPages(); - -/*************************************************************************/ - -/** - * This method returns the <code>PageFormat</code> instance for the - * specified page. Page numbers start at zero. An exception is thrown if - * the requested page does not exist. - * - * @param pageIndex The index of the page to return the - * <code>PageFormat</code> for. - * - * @return The <code>PageFormat</code> for the requested page. - * - * @exception IndexOutOfBoundsException If the requested page number does - * not exist. - */ -PageFormat -getPageFormat(int pageIndex) throws IndexOutOfBoundsException; - -/*************************************************************************/ - -/** - * This method returns the <code>Printable</code> instance for the - * specified page. Page numbers start at zero. An exception is thrown if - * the requested page does not exist. - * - * @param pageIndex The index of the page to return the - * <code>Printable</code> for. - * - * @return The <code>Printable</code> for the requested page. - * - * @exception IndexOutOfBoundsException If the requested page number does - * not exist. - */ -Printable -getPrintable(int pageIndex) throws IndexOutOfBoundsException; - -} // interface Pageable - + /** + * This constant is returned when <code>getNumberOfPages()</code> cannot + * determine the number of pages available for printing. + */ + int UNKNOWN_NUMBER_OF_PAGES = - 1; + + /** + * This method returns the number of pages this object contains, or + * <code>UNKNOWN_NUMBER_OF_PAGES</code> if it cannot determine the number + * of pages to be printed. + * + * @return The number of pages to be printed, or + * <code>UNKNOWN_NUMBER_OF_PAGES</code> if this is unknown. + */ + int getNumberOfPages(); + + /** + * This method returns the <code>PageFormat</code> instance for the + * specified page. Page numbers start at zero. An exception is thrown if the + * requested page does not exist. + * + * @param pageIndex The index of the page to return the + * <code>PageFormat</code> for. + * @return The <code>PageFormat</code> for the requested page. + * @exception IndexOutOfBoundsException If the requested page number does + * not exist. + */ + PageFormat getPageFormat(int pageIndex) throws IndexOutOfBoundsException; + + /** + * This method returns the <code>Printable</code> instance for the specified + * page. Page numbers start at zero. An exception is thrown if the requested + * page does not exist. + * + * @param pageIndex The index of the page to return the + * <code>Printable</code> for. + * @return The <code>Printable</code> for the requested page. + * @exception IndexOutOfBoundsException If the requested page number does + * not exist. + */ + Printable getPrintable(int pageIndex) throws IndexOutOfBoundsException; + +} diff --git a/libjava/classpath/java/awt/print/Paper.java b/libjava/classpath/java/awt/print/Paper.java index 4579da3ea3c..fb7ba91158f 100644 --- a/libjava/classpath/java/awt/print/Paper.java +++ b/libjava/classpath/java/awt/print/Paper.java @@ -1,5 +1,5 @@ /* Paper.java -- Information about a paper type. - Copyright (C) 1999 Free Software Foundation, Inc. + Copyright (C) 1999, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,198 +39,159 @@ exception statement from your version. */ package java.awt.print; /** - * This class describes a particular type of paper. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ -public class Paper implements Cloneable -{ - -/* - * Instance Variables + * This class describes a particular type of paper. + * + * @author Aaron M. Renn (arenn@urbanophile.com) */ - -// Height of the paper -private double height; - -// Width of the paper -private double width; - -// Upper left imageable X coordinate -private double imageableX; - -// Upper left imageable Y coordinate -private double imageableY; - -// Imageable width of the page -private double imageableWidth; - -// Imageable height of the page -private double imageableHeight; - -/*************************************************************************/ - -/* - * Constructor - */ - -/** - * This method creates a letter sized paper with one inch margins - */ -public -Paper() -{ - width = 8.5 * 72; - height = 11 * 72; - imageableX = 72; - imageableY = 72; - imageableWidth = width - (2 * 72); - imageableHeight = height - (2 * 72); -} - -/*************************************************************************/ - -/** - * This method returns the height of the paper in 1/72nds of an inch. - * - * @return The height of the paper in 1/72nds of an inch. - */ -public double -getHeight() +public class Paper + implements Cloneable { - return(height); -} + // Height of the paper + private double height; + + // Width of the paper + private double width; + + // Upper left imageable X coordinate + private double imageableX; + + // Upper left imageable Y coordinate + private double imageableY; + + // Imageable width of the page + private double imageableWidth; + + // Imageable height of the page + private double imageableHeight; + + /** + * This method creates a letter sized paper with one inch margins + */ + public Paper() + { + width = 8.5 * 72; + height = 11 * 72; + imageableX = 72; + imageableY = 72; + imageableWidth = width - (2 * 72); + imageableHeight = height - (2 * 72); + } + + /** + * This method returns the height of the paper in 1/72nds of an inch. + * + * @return The height of the paper in 1/72nds of an inch. + */ + public double getHeight() + { + return height; + } + + /** + * Returns the width of the paper in 1/72nds of an inch. + * + * @return The width of the paper in 1/72nds of an inch. + */ + public double getWidth() + { + return width; + } + + /** + * This method returns the X coordinate of the upper left hand corner of the + * imageable area of the paper. + * + * @return The X coordinate of the upper left hand corner of the imageable + * area of the paper. + */ + public double getImageableX() + { + return imageableX; + } + + /** + * This method returns the Y coordinate of the upper left hand corner of the + * imageable area of the paper. + * + * @return The Y coordinate of the upper left hand corner of the imageable + * area of the paper. + */ + public double getImageableY() + { + return imageableY; + } + + /** + * Returns the width of the imageable area of the paper. + * + * @return The width of the imageable area of the paper. + */ + public double getImageableWidth() + { + return imageableWidth; + } + + /** + * Returns the height of the imageable area of the paper. + * + * @return The height of the imageable area of the paper. + */ + public double getImageableHeight() + { + return imageableHeight; + } + + /** + * This method sets the size of the paper to the specified width and height, + * which are specified in 1/72nds of an inch. + * + * @param width The width of the paper in 1/72nds of an inch. + * @param height The height of the paper in 1/72nds of an inch. + */ + public void setSize(double width, double height) + { + this.width = width; + this.height = height; + } + + /** + * This method sets the imageable area of the paper by specifying the + * coordinates of the upper left hand corner of that area, and its length + * and height. All values are in 1/72nds of an inch. + * + * @param imageableX The X coordinate of the upper left hand corner of the + * imageable area, in 1/72nds of an inch. + * @param imageableY The Y coordinate of the upper left hand corner of the + * imageable area, in 1/72nds of an inch. + * @param imageableWidth The width of the imageable area of the paper, in + * 1/72nds of an inch. + * @param imageableHeight The heigth of the imageable area of the paper, in + * 1/72nds of an inch. + */ + public void setImageableArea(double imageableX, double imageableY, + double imageableWidth, double imageableHeight) + { + this.imageableX = imageableX; + this.imageableY = imageableY; + this.imageableWidth = imageableWidth; + this.imageableHeight = imageableHeight; + } + + /** + * This method creates a copy of this object. + * + * @return A copy of this object. + */ + public Object clone() + { + try + { + return (super.clone()); + } + catch (CloneNotSupportedException e) + { + return (null); + } + } -/*************************************************************************/ - -/** - * Returns the width of the paper in 1/72nds of an inch. - * - * @return The width of the paper in 1/72nds of an inch. - */ -public double -getWidth() -{ - return(width); } - -/*************************************************************************/ - -/** - * This method returns the X coordinate of the upper left hand corner - * of the imageable area of the paper. - * - * @return The X coordinate of the upper left hand corner of the imageable - * area of the paper. - */ -public double -getImageableX() -{ - return(imageableX); -} - -/*************************************************************************/ - -/** - * This method returns the Y coordinate of the upper left hand corner - * of the imageable area of the paper. - * - * @return The Y coordinate of the upper left hand corner of the imageable - * area of the paper. - */ -public double -getImageableY() -{ - return(imageableY); -} - -/*************************************************************************/ - -/** - * Returns the width of the imageable area of the paper. - * - * @return The width of the imageable area of the paper. - */ -public double -getImageableWidth() -{ - return(imageableWidth); -} - -/*************************************************************************/ - -/** - * Returns the height of the imageable area of the paper. - * - * @return The height of the imageable area of the paper. - */ -public double -getImageableHeight() -{ - return(imageableHeight); -} - -/*************************************************************************/ - -/** - * This method sets the size of the paper to the specified width and - * height, which are specified in 1/72nds of an inch. - * - * @param width The width of the paper in 1/72nds of an inch. - * @param height The height of the paper in 1/72nds of an inch. - */ -public void -setSize(double width, double height) -{ - this.width = width; - this.height = height; -} - -/*************************************************************************/ - -/** - * This method sets the imageable area of the paper by specifying the - * coordinates of the upper left hand corner of that area, and its - * length and height. All values are in 1/72nds of an inch. - * - * @param imageableX The X coordinate of the upper left hand corner of - * the imageable area, in 1/72nds of an inch. - * @param imageableY The Y coordinate of the upper left hand corner of - * the imageable area, in 1/72nds of an inch. - * @param imageableWidth The width of the imageable area of the paper, - * in 1/72nds of an inch. - * @param imageableHeight The heigth of the imageable area of the paper, - * in 1/72nds of an inch. - */ -public void -setImageableArea(double imageableX, double imageableY, - double imageableWidth, double imageableHeight) -{ - this.imageableX = imageableX; - this.imageableY = imageableY; - this.imageableWidth = imageableWidth; - this.imageableHeight = imageableHeight; -} - -/*************************************************************************/ - -/** - * This method creates a copy of this object. - * - * @return A copy of this object. - */ -public Object -clone() -{ - try - { - return(super.clone()); - } - catch(CloneNotSupportedException e) - { - return(null); - } -} - -} // class Paper - diff --git a/libjava/classpath/java/awt/print/PrinterGraphics.java b/libjava/classpath/java/awt/print/PrinterGraphics.java index 5ca64190424..62fde8406dd 100644 --- a/libjava/classpath/java/awt/print/PrinterGraphics.java +++ b/libjava/classpath/java/awt/print/PrinterGraphics.java @@ -1,5 +1,5 @@ /* PrinterGraphics.java -- Hook to return print job controller. - Copyright (C) 1999 Free Software Foundation, Inc. + Copyright (C) 1999, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,23 +39,20 @@ exception statement from your version. */ package java.awt.print; /** - * This interface is implemented by the <code>Graphics</code> instance - * that is used for rendering pages. It provides a hook to return the - * object that is controlling the print job. - * - * @author Aaron M. Renn (arenn@urbanophile.com) - */ + * This interface is implemented by the <code>Graphics</code> instance that is + * used for rendering pages. It provides a hook to return the object that is + * controlling the print job. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ public interface PrinterGraphics { - -/** - * This method returns the instance of <code>PrinterJob</code> that is - * controlling this print job. - * - * @return The <code>PrinterJob</code> that is controlling this print job. - */ -PrinterJob -getPrinterJob(); - -} // interface PrinterGraphics - + /** + * This method returns the instance of <code>PrinterJob</code> that is + * controlling this print job. + * + * @return The <code>PrinterJob</code> that is controlling this print job. + */ + PrinterJob getPrinterJob(); + +} diff --git a/libjava/classpath/java/awt/print/PrinterJob.java b/libjava/classpath/java/awt/print/PrinterJob.java index e1aeabc3e62..7f67a6b048b 100644 --- a/libjava/classpath/java/awt/print/PrinterJob.java +++ b/libjava/classpath/java/awt/print/PrinterJob.java @@ -1,5 +1,5 @@ /* PrinterJob.java -- This job is the printer control class - Copyright (C) 1999, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -61,7 +61,7 @@ public abstract class PrinterJob public static PrinterJob getPrinterJob() { // FIXME: Need to fix this to load a default implementation instance. - return null; + return new NoPrinterJob(); } /** |