diff options
Diffstat (limited to 'libjava/java/awt/Window.java')
-rw-r--r-- | libjava/java/awt/Window.java | 90 |
1 files changed, 78 insertions, 12 deletions
diff --git a/libjava/java/awt/Window.java b/libjava/java/awt/Window.java index d084bb4..786e51a 100644 --- a/libjava/java/awt/Window.java +++ b/libjava/java/awt/Window.java @@ -56,6 +56,9 @@ import java.util.Vector; import javax.accessibility.Accessible; import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleRole; +import javax.accessibility.AccessibleState; +import javax.accessibility.AccessibleStateSet; /** * This class represents a top-level window with no decorations. @@ -84,11 +87,26 @@ public class Window extends Container implements Accessible private transient WindowFocusListener windowFocusListener; private transient WindowStateListener windowStateListener; private transient GraphicsConfiguration graphicsConfiguration; - private transient AccessibleContext accessibleContext; private transient boolean shown; private transient Component windowFocusOwner; + + protected class AccessibleAWTWindow extends AccessibleAWTContainer + { + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.WINDOW; + } + + public AccessibleStateSet getAccessibleStateSet() + { + AccessibleStateSet states = super.getAccessibleStateSet(); + if (isActive()) + states.add(AccessibleState.ACTIVE); + return states; + } + } /** * This (package access) constructor is used by subclasses that want @@ -200,12 +218,11 @@ public class Window extends Container implements Accessible && gc.getDevice().getType() != GraphicsDevice.TYPE_RASTER_SCREEN) throw new IllegalArgumentException ("gc must be from a screen device"); - // FIXME: until we implement this, it just causes AWT to crash. -// if (gc == null) -// graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment() -// .getDefaultScreenDevice() -// .getDefaultConfiguration(); -// else + if (gc == null) + graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment() + .getDefaultScreenDevice() + .getDefaultConfiguration(); + else graphicsConfiguration = gc; } @@ -672,8 +689,34 @@ public class Window extends Container implements Accessible } } } + + /** + * Identifies if this window is active. The active window is a Frame or + * Dialog that has focus or owns the active window. + * + * @return true if active, else false. + * @since 1.4 + */ + public boolean isActive() + { + KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); + return manager.getActiveWindow() == this; + } /** + * Identifies if this window is focused. A window is focused if it is the + * focus owner or it contains the focus owner. + * + * @return true if focused, else false. + * @since 1.4 + */ + public boolean isFocused() + { + KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); + return manager.getFocusedWindow() == this; + } + + /** * Returns the child window that has focus if this window is active. * This method returns <code>null</code> if this window is not active * or no children have focus. @@ -731,6 +774,22 @@ public class Window extends Container implements Accessible return super.isShowing(); } + public void setLocationRelativeTo (Component c) + { + if (c == null || !c.isShowing ()) + { + int x = 0; + int y = 0; + + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment (); + Point center = ge.getCenterPoint (); + x = center.x - (width / 2); + y = center.y - (height / 2); + setLocation (x, y); + } + // FIXME: handle case where component is non-null. + } + /** * @since 1.2 * @@ -754,11 +813,18 @@ public class Window extends Container implements Accessible applyResourceBundle(rb); } + /** + * Gets the AccessibleContext associated with this <code>Window</code>. + * The context is created, if necessary. + * + * @return the associated context + */ public AccessibleContext getAccessibleContext() { - // FIXME - //return null; - throw new Error ("Not implemented"); + /* Create the context if this is the first request */ + if (accessibleContext == null) + accessibleContext = new AccessibleAWTWindow(); + return accessibleContext; } /** @@ -866,13 +932,13 @@ public class Window extends Container implements Accessible this.y = y; width = w; height = h; - if (resized) + if (resized && isShowing ()) { ComponentEvent ce = new ComponentEvent(this, ComponentEvent.COMPONENT_RESIZED); getToolkit().getSystemEventQueue().postEvent(ce); } - if (moved) + if (moved && isShowing ()) { ComponentEvent ce = new ComponentEvent(this, ComponentEvent.COMPONENT_MOVED); |