aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/awt
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/awt')
-rw-r--r--libjava/java/awt/BorderLayout.java7
-rw-r--r--libjava/java/awt/Button.java3
-rw-r--r--libjava/java/awt/Component.java20
-rw-r--r--libjava/java/awt/Container.java221
-rw-r--r--libjava/java/awt/Frame.java14
-rw-r--r--libjava/java/awt/Label.java3
-rw-r--r--libjava/java/awt/Scrollbar.java3
-rw-r--r--libjava/java/awt/Toolkit.java1
-rw-r--r--libjava/java/awt/Window.java130
9 files changed, 313 insertions, 89 deletions
diff --git a/libjava/java/awt/BorderLayout.java b/libjava/java/awt/BorderLayout.java
index 16700f3..6f4cb5c 100644
--- a/libjava/java/awt/BorderLayout.java
+++ b/libjava/java/awt/BorderLayout.java
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999 Free Software Foundation
+/* Copyright (C) 1999, 2000 Free Software Foundation
This file is part of libjava.
@@ -15,6 +15,11 @@ public class BorderLayout implements LayoutManager2
int hgap;
int vgap;
+ public BorderLayout ()
+ {
+ this (0, 0);
+ }
+
public BorderLayout (int hgap, int vgap)
{
this.hgap = hgap;
diff --git a/libjava/java/awt/Button.java b/libjava/java/awt/Button.java
index a582b96..5038817 100644
--- a/libjava/java/awt/Button.java
+++ b/libjava/java/awt/Button.java
@@ -36,7 +36,8 @@ public class Button extends Component
public void addNotify ()
{
- peer = (ComponentPeer) getToolkit ().createButton (this);
+ if (peer == null)
+ peer = (ComponentPeer) getToolkit ().createButton (this);
}
public String getActionCommand ()
diff --git a/libjava/java/awt/Component.java b/libjava/java/awt/Component.java
index 5c59ed6..340b185 100644
--- a/libjava/java/awt/Component.java
+++ b/libjava/java/awt/Component.java
@@ -137,23 +137,25 @@ public abstract class Component implements ImageObserver, MenuContainer,
// FIXME
return null;
}
-
+
public final Object getTreeLock()
{
// FIXME
return null;
}
-
+
public Toolkit getToolkit()
{
- // FIXME
- return null;
+ if (peer != null)
+ return peer.getToolkit ();
+ if (parent != null)
+ return parent.getToolkit ();
+ return Toolkit.getDefaultToolkit ();
}
-
+
public boolean isValid()
{
- // FIXME
- return false;
+ return valid;
}
/** @since 1.2 */
@@ -518,7 +520,9 @@ public abstract class Component implements ImageObserver, MenuContainer,
public void invalidate()
{
- // FIXME
+ valid = false;
+ if (parent != null)
+ parent.invalidate ();
}
public Graphics getGraphics()
diff --git a/libjava/java/awt/Container.java b/libjava/java/awt/Container.java
index 81a367b..7ebdc9c 100644
--- a/libjava/java/awt/Container.java
+++ b/libjava/java/awt/Container.java
@@ -29,7 +29,10 @@ public abstract class Container extends Component
/* Anything else is non-serializable, and should be declared "transient". */
transient ContainerListener containerListener;
-
+
+ // Insets.
+ private transient Insets myInsets;
+
public Container()
{
}
@@ -62,10 +65,9 @@ public abstract class Container extends Component
public Insets getInsets()
{
- // FIXME
- return null;
+ return myInsets;
}
-
+
/** @deprecated Use getInsets() instead. */
public Insets insets()
{
@@ -74,17 +76,50 @@ public abstract class Container extends Component
public Component add (Component comp)
{
- return add (comp, -1);
+ addImpl (comp, null, -1);
+ return comp;
}
-
- public Component add(String name, Component comp)
+
+ public Component add (String name, Component comp)
{
- // FIXME
- return null;
+ addImpl (comp, name, -1);
+ return comp;
+ }
+
+ public Component add (Component comp, int index)
+ {
+ addImpl (comp, null, index);
+ return comp;
+ }
+
+ public void add (Component comp, Object constraints)
+ {
+ addImpl (comp, constraints, -1);
+ }
+
+ public void add (Component comp, Object constraints, int index)
+ {
+ addImpl (comp, constraints, index);
}
- public Component add(Component comp, int index)
+ protected void addImpl (Component comp, Object constraints, int index)
{
+ if (index > ncomponents
+ || comp instanceof Window
+ || (comp instanceof Container
+ && ((Container) comp).isAncestorOf (this)))
+ throw new IllegalArgumentException ();
+
+ // Reparent component, and make sure component is instantiated if
+ // we are.
+ if (comp.parent != this)
+ comp.parent.remove (comp);
+ comp.parent = this;
+ if (peer != null)
+ comp.addNotify ();
+
+ invalidate ();
+
// This isn't the most efficient implementation. We could do less
// copying when growing the array. It probably doesn't matter.
if (ncomponents >= component.length)
@@ -94,7 +129,6 @@ public abstract class Container extends Component
System.arraycopy (component, 0, c, 0, ncomponents);
component = c;
}
-
if (index == -1)
component[ncomponents++] = comp;
else
@@ -105,45 +139,69 @@ public abstract class Container extends Component
++ncomponents;
}
- return comp;
- }
-
- public void add(Component comp, Object constraints)
- {
- // FIXME
- }
+ // Notify the layout manager.
+ if (layoutMgr != null)
+ {
+ if (constraints != null && layoutMgr instanceof LayoutManager2)
+ {
+ LayoutManager2 lm2 = (LayoutManager2) layoutMgr;
+ lm2.addLayoutComponent (comp, constraints);
+ }
+ else
+ layoutMgr.addLayoutComponent ((String) constraints, comp);
+ }
- public void add(Component comp, Object constraints, int index)
- {
- // FIXME
- }
+ ContainerEvent ce = new ContainerEvent (this,
+ ContainerEvent.COMPONENT_ADDED,
+ comp);
- protected void addImpl(Component comp, Object constraints, int index)
- {
- // FIXME
+ // FIXME: is this right?
+ dispatchEvent (ce);
+ if (containerListener != null)
+ containerListener.componentAdded (ce);
}
public void remove (int index)
{
+ Component r = component[index];
+
+ r.removeNotify ();
+
System.arraycopy (component, index + 1, component, index,
ncomponents - index - 1);
component[--ncomponents] = null;
+
+ invalidate ();
+
+ if (layoutMgr != null)
+ layoutMgr.removeLayoutComponent (r);
+
+ ContainerEvent ce = new ContainerEvent (this,
+ ContainerEvent.COMPONENT_REMOVED,
+ r);
+
+ // FIXME: is this right?
+ dispatchEvent (ce);
+ if (containerListener != null)
+ containerListener.componentAdded (ce);
}
public void remove (Component comp)
{
for (int i = 0; i < ncomponents; ++i)
- if (component[i] == comp)
- {
- remove (i);
- break;
- }
+ {
+ if (component[i] == comp)
+ {
+ remove (i);
+ break;
+ }
+ }
}
public void removeAll()
{
- while (ncomponents >= 0)
- component[--ncomponents] = null;
+ while (ncomponents > 0)
+ remove (0);
}
public LayoutManager getLayout()
@@ -159,7 +217,8 @@ public abstract class Container extends Component
public void doLayout()
{
- // FIXME
+ if (layoutMgr != null)
+ layoutMgr.layoutContainer (this);
}
/** @deprecated Use doLayout() instead. */
@@ -170,17 +229,22 @@ public abstract class Container extends Component
public void invalidate()
{
- // FIXME
+ super.invalidate ();
}
public void validate()
{
- // FIXME
+ if (! isValid ())
+ {
+ doLayout ();
+ validateTree ();
+ }
}
protected void validateTree()
{
- // FIXME
+ for (int i = 0; i < ncomponents; ++i)
+ component[i].validate ();
}
public void setFont(Font f)
@@ -190,8 +254,10 @@ public abstract class Container extends Component
public Dimension getPreferredSize()
{
- // FIXME
- return null;
+ if (layoutMgr != null)
+ return layoutMgr.preferredLayoutSize (this);
+ else
+ return super.getPreferredSize ();
}
/** @deprecated Use getPreferredSize() instead */
@@ -202,8 +268,10 @@ public abstract class Container extends Component
public Dimension getMinimumSize()
{
- // FIXME
- return null;
+ if (layoutMgr != null)
+ return layoutMgr.minimumLayoutSize (this);
+ else
+ return super.getMinimumSize ();
}
/** @deprecated Use getMinimumSize() instead */
@@ -214,20 +282,35 @@ public abstract class Container extends Component
public Dimension getMaximumSize()
{
- // FIXME
- return null;
+ if (layoutMgr != null && layoutMgr instanceof LayoutManager2)
+ {
+ LayoutManager2 lm2 = (LayoutManager2) layoutMgr;
+ return lm2.maximumLayoutSize (this);
+ }
+ else
+ return super.getMaximumSize ();
}
-
+
public float getAlignmentX()
{
- // FIXME
- return 0;
+ if (layoutMgr instanceof LayoutManager2)
+ {
+ LayoutManager2 lm2 = (LayoutManager2) layoutMgr;
+ return lm2.getLayoutAlignmentX (this);
+ }
+ else
+ return CENTER_ALIGNMENT;
}
public float getAlignmentY()
{
- // FIXME
- return 0;
+ if (layoutMgr instanceof LayoutManager2)
+ {
+ LayoutManager2 lm2 = (LayoutManager2) layoutMgr;
+ return lm2.getLayoutAlignmentY (this);
+ }
+ else
+ return CENTER_ALIGNMENT;
}
public void paint(Graphics g)
@@ -252,7 +335,8 @@ public abstract class Container extends Component
public void printComponents(Graphics g)
{
- // FIXME
+ for (int i = 0; i < ncomponents; ++i)
+ component[i].printAll (g);
}
void dispatchEventImpl(AWTEvent e)
@@ -267,14 +351,12 @@ public abstract class Container extends Component
public void addContainerListener(ContainerListener l)
{
- containerListener = (ContainerListener)
- AWTEventMulticaster.add(containerListener, l);
+ containerListener = AWTEventMulticaster.add (containerListener, l);
}
public void removeContainerListener(ContainerListener l)
{
- containerListener = (ContainerListener)
- AWTEventMulticaster.remove(containerListener, l);
+ containerListener = AWTEventMulticaster.remove(containerListener, l);
}
/** @since 1.3 */
@@ -294,7 +376,7 @@ public abstract class Container extends Component
protected void processContainerEvent(ContainerEvent e)
{
- if (componentListener == null)
+ if (containerListener == null)
return;
switch (e.id)
{
@@ -313,9 +395,17 @@ public abstract class Container extends Component
{
}
- public Component getComponentAt(int x, int y)
+ public Component getComponentAt (int x, int y)
{
- // FIXME
+ if (! contains (x, y))
+ return null;
+ for (int i = 0; i < ncomponents; ++i)
+ {
+ int x2 = x - component[i].x;
+ int y2 = y - component[i].y;
+ if (component[i].contains (x2, y2))
+ return component[i];
+ }
return null;
}
@@ -345,12 +435,13 @@ public abstract class Container extends Component
{
for (int i = ncomponents; --i >= 0; )
component[i].addNotify();
- peer = (ComponentPeer) getToolkit ().createContainer (this);
}
public void removeNotify()
{
- // FIXME
+ for (int i = 0; i < ncomponents; ++i)
+ component[i].removeNotify ();
+ // FIXME: remove our peer.
}
public boolean isAncestorOf (Component comp)
@@ -370,13 +461,21 @@ public abstract class Container extends Component
return "FIXME";
}
- public void list(PrintStream out, int indent)
+ public void list (PrintStream out, int indent)
{
- // FIXME
+ for (int i = 0; i < indent; ++i)
+ out.print (' ');
+ out.println (toString ());
+ for (int i = 0; i < ncomponents; ++i)
+ component[i].list (out, indent + 2);
}
-
+
public void list(PrintWriter out, int indent)
{
- // FIXME
+ for (int i = 0; i < indent; ++i)
+ out.print (' ');
+ out.println (toString ());
+ for (int i = 0; i < ncomponents; ++i)
+ component[i].list (out, indent + 2);
}
}
diff --git a/libjava/java/awt/Frame.java b/libjava/java/awt/Frame.java
index 0d0acf9..fb9f7fd 100644
--- a/libjava/java/awt/Frame.java
+++ b/libjava/java/awt/Frame.java
@@ -17,11 +17,13 @@ public class Frame extends Window implements MenuContainer
String title;
public Frame ()
- { /* FIXME */ }
+ {
+ super (null);
+ }
public Frame (String title)
{
- this();
+ super (null);
setTitle(title);
}
@@ -43,13 +45,7 @@ public class Frame extends Window implements MenuContainer
public synchronized void addNotify ()
{
if (peer == null)
- {
- FramePeer fpeer = Toolkit.getDefaultToolkit().createFrame(this);
- // Compiler bug requires cast ??; FIXME?
- peer = (java.awt.peer.ComponentPeer) fpeer;
- if (width + height > 0)
- peer.setBounds(x, y, width, height);
- }
+ peer = getToolkit ().createFrame (this);
super.addNotify();
}
diff --git a/libjava/java/awt/Label.java b/libjava/java/awt/Label.java
index 93d2053..840456d 100644
--- a/libjava/java/awt/Label.java
+++ b/libjava/java/awt/Label.java
@@ -41,7 +41,8 @@ public class Label extends Component
public void addNotify ()
{
- peer = (ComponentPeer) getToolkit ().createLabel (this);
+ if (peer == null)
+ peer = (ComponentPeer) getToolkit ().createLabel (this);
}
public int getAlignment ()
diff --git a/libjava/java/awt/Scrollbar.java b/libjava/java/awt/Scrollbar.java
index 5406c0c..afe3aba 100644
--- a/libjava/java/awt/Scrollbar.java
+++ b/libjava/java/awt/Scrollbar.java
@@ -53,7 +53,8 @@ public class Scrollbar extends Component implements Adjustable
public void addNotify ()
{
- peer = (ComponentPeer) getToolkit ().createScrollbar (this);
+ if (peer == null)
+ peer = (ComponentPeer) getToolkit ().createScrollbar (this);
}
public int getOrientation ()
diff --git a/libjava/java/awt/Toolkit.java b/libjava/java/awt/Toolkit.java
index 2aea96d..e1788df 100644
--- a/libjava/java/awt/Toolkit.java
+++ b/libjava/java/awt/Toolkit.java
@@ -31,6 +31,7 @@ public abstract class Toolkit
protected abstract ContainerPeer createContainer (Container target);
protected abstract LabelPeer createLabel (Label target);
protected abstract ScrollbarPeer createScrollbar (Scrollbar target);
+ protected abstract WindowPeer createWindow (Window target);
public final EventQueue getSystemEventQueue()
{
diff --git a/libjava/java/awt/Window.java b/libjava/java/awt/Window.java
index 4112861..463b67b 100644
--- a/libjava/java/awt/Window.java
+++ b/libjava/java/awt/Window.java
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999 Free Software Foundation
+/* Copyright (C) 1999, 2000 Free Software Foundation
This file is part of libjava.
@@ -7,23 +7,139 @@ Libjava License. Please consult the file "LIBJAVA_LICENSE" for
details. */
package java.awt;
+import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
+import java.awt.peer.WindowPeer;
+import java.awt.peer.ComponentPeer;
+import java.util.Locale;
/* A very incomplete placeholder. */
public class Window extends Container
{
- public void dispose ()
- { /* FIXME */ }
+ public Window (Frame parent)
+ {
+ this.parent = parent;
+ // FIXME: compiler bug
+ // this.layoutMgr = new BorderLayout ();
+ }
+
+ public void addNotify ()
+ {
+ if (peer == null)
+ peer = (ComponentPeer) getToolkit ().createWindow (this);
+ super.addNotify ();
+ }
public synchronized void addWindowListener (WindowListener listener)
- { /* FIXME */ }
+ {
+ windowListener = AWTEventMulticaster.add (windowListener, listener);
+ }
+
+ public void dispose ()
+ {
+ }
+
+ public Component getFocusOwner ()
+ {
+ return null; // FIXME
+ }
+ public Locale getLocale ()
+ {
+ return locale == null ? Locale.getDefault () : locale;
+ }
+
+ public String getWarningString ()
+ {
+ return warningString;
+ }
+
+ public void pack ()
+ {
+ addNotify ();
+ // FIXME
+ }
+
+ public boolean postEvent (Event evt)
+ {
+ return false; // FIXME
+ }
+
+ protected void processEvent (AWTEvent evt)
+ {
+ if (evt instanceof WindowEvent)
+ processWindowEvent ((WindowEvent) evt);
+ else
+ super.processEvent (evt);
+ }
+
+ protected void processWindowEvent (WindowEvent evt)
+ {
+ if (windowListener != null)
+ {
+ switch (evt.getID ())
+ {
+ case WindowEvent.WINDOW_ACTIVATED:
+ windowListener.windowActivated (evt);
+ break;
+ case WindowEvent.WINDOW_CLOSED:
+ windowListener.windowClosed (evt);
+ break;
+ case WindowEvent.WINDOW_CLOSING:
+ windowListener.windowClosing (evt);
+ break;
+ case WindowEvent.WINDOW_DEACTIVATED:
+ windowListener.windowDeactivated (evt);
+ break;
+ case WindowEvent.WINDOW_DEICONIFIED:
+ windowListener.windowDeiconified (evt);
+ break;
+ case WindowEvent.WINDOW_ICONIFIED:
+ windowListener.windowIconified (evt);
+ break;
+ case WindowEvent.WINDOW_OPENED:
+ windowListener.windowOpened (evt);
+ break;
+ }
+ }
+ }
+
+ public synchronized void removeWindowListener (WindowListener listener)
+ {
+ windowListener = AWTEventMulticaster.remove (windowListener, listener);
+ }
public void show ()
{
- addNotify();
- // validate FIXME
- // validate setVisible FIXME
+ addNotify ();
+ validate ();
+ setVisible (true);
+ // FIXME: is there more to it?
+ }
+
+ public void toBack ()
+ {
+ if (peer != null)
+ {
+ WindowPeer wp = (WindowPeer) peer;
+ wp.toBack ();
+ }
}
+
+ public void toFront ()
+ {
+ if (peer != null)
+ {
+ WindowPeer wp = (WindowPeer) peer;
+ wp.toFront ();
+ }
+ }
+
+ // Serialized fields, from Sun's serialization spec.
+ // private FocusManager focusMgr; // FIXME: what is this?
+ private int state;
+ private String warningString;
+
+ private transient WindowListener windowListener;
}