aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/awt/Window.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/awt/Window.java')
-rw-r--r--libjava/java/awt/Window.java114
1 files changed, 100 insertions, 14 deletions
diff --git a/libjava/java/awt/Window.java b/libjava/java/awt/Window.java
index d084bb4350b..0a39d20b1ff 100644
--- a/libjava/java/awt/Window.java
+++ b/libjava/java/awt/Window.java
@@ -56,12 +56,15 @@ 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.
*
- * @author Aaron M. Renn <arenn@urbanophile.com>
- * @author Warren Levy <warrenl@cygnus.com>
+ * @author Aaron M. Renn (arenn@urbanophile.com)
+ * @author Warren Levy (warrenl@cygnus.com)
*/
public class Window extends Container implements Accessible
{
@@ -84,11 +87,31 @@ 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;
+
+ /*
+ * The number used to generate the name returned by getName.
+ */
+ private static transient long next_window_number;
+
+ 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 +223,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 +694,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 +779,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 +818,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,17 +937,32 @@ 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);
getToolkit().getSystemEventQueue().postEvent(ce);
}
}
+
+ /**
+ * Generate a unique name for this window.
+ *
+ * @return A unique name for this window.
+ */
+ String generateName()
+ {
+ return "win" + getUniqueLong();
+ }
+
+ private static synchronized long getUniqueLong()
+ {
+ return next_window_number++;
+ }
}