Commit e0a339f7 by Tom Tromey Committed by Tom Tromey

BorderLayout.java (BorderLayout()): New constructor.

	* java/awt/BorderLayout.java (BorderLayout()): New constructor.

	* java/awt/Frame.java (Frame): Pass `null' to Window constructor.

	* java/awt/Window.java (addNotify): Wrote.
	(addWindowListener): Wrote.
	(getLocale): Wrote.
	(getWarningString): Wrote.
	(processEvent): Wrote.
	(processWindowEvent): Wrote.
	(removeWindowListener): Wrote.
	(show): Call validate(), setVisible().
	(toBack): Wrote.
	(toFront): Wrote.

	* java/awt/Toolkit.java (createWindow): Declare.

	* java/awt/Frame.java (addNotify): Use getToolkit to find
	toolkit.

	* java/awt/Component.java (invalidate): Wrote.
	(isValid): Wrote.
	(getToolkit): Wrote.

	* java/awt/Container.java (addContainerListener): Removed
	unnecessary cast.
	(removeContainerListener): Likewise.
	(addImpl): Wrote.
	(add(Component)): Use it.
	(add(String,Component)): Likewise.
	(add(Component,int)): Likewise.
	(add(Component,Object)): Likewise.
	(add(Component,Object,int)): Likewise.
	(doLayout): Wrote.
	(getAlignmentX): Wrote.
	(getAlignmentY): Wrote.
	(getComponentAt): Wrote.
	(getMaximumSize): Wrote.
	(invalidate): Wrote.
	(list(PrintStream,int)): Wrote.
	(list(PrintWriter,int)): Wrote.
	(getMinimumSize): Wrote.
	(getPreferredSize): Wrote.
	(printComponents): Wrote.
	(processContainerEvent): Look at containerListener, not
	componentListener.
	(remove): Added event processing and peer destruction.
	(removeAll): Use remove.
	(removeNotify): Wrote.
	(validate): Wrote.
	(validateTree): Wrote.

	* java/awt/Scrollbar.java (addNotify): Do nothing if peer exists.
	* java/awt/Label.java (addNotify): Do nothing if peer exists.
	* java/awt/Container.java (addNotify): Don't create Container
	peer.
	* java/awt/Button.java (addNotify): Do nothing if peer exists.

From-SVN: r35361
parent 911a71a7
2000-07-30 Tom Tromey <tromey@cygnus.com> 2000-07-30 Tom Tromey <tromey@cygnus.com>
* java/awt/BorderLayout.java (BorderLayout()): New constructor.
* java/awt/Frame.java (Frame): Pass `null' to Window constructor.
* java/awt/Window.java (addNotify): Wrote.
(addWindowListener): Wrote.
(getLocale): Wrote.
(getWarningString): Wrote.
(processEvent): Wrote.
(processWindowEvent): Wrote.
(removeWindowListener): Wrote.
(show): Call validate(), setVisible().
(toBack): Wrote.
(toFront): Wrote.
* java/awt/Toolkit.java (createWindow): Declare.
* java/awt/Frame.java (addNotify): Use getToolkit to find
toolkit.
* java/awt/Component.java (invalidate): Wrote.
(isValid): Wrote.
(getToolkit): Wrote.
* java/awt/Container.java (addContainerListener): Removed
unnecessary cast.
(removeContainerListener): Likewise.
(addImpl): Wrote.
(add(Component)): Use it.
(add(String,Component)): Likewise.
(add(Component,int)): Likewise.
(add(Component,Object)): Likewise.
(add(Component,Object,int)): Likewise.
(doLayout): Wrote.
(getAlignmentX): Wrote.
(getAlignmentY): Wrote.
(getComponentAt): Wrote.
(getMaximumSize): Wrote.
(invalidate): Wrote.
(list(PrintStream,int)): Wrote.
(list(PrintWriter,int)): Wrote.
(getMinimumSize): Wrote.
(getPreferredSize): Wrote.
(printComponents): Wrote.
(processContainerEvent): Look at containerListener, not
componentListener.
(remove): Added event processing and peer destruction.
(removeAll): Use remove.
(removeNotify): Wrote.
(validate): Wrote.
(validateTree): Wrote.
* java/awt/Scrollbar.java (addNotify): Do nothing if peer exists.
* java/awt/Label.java (addNotify): Do nothing if peer exists.
* java/awt/Container.java (addNotify): Don't create Container
peer.
* java/awt/Button.java (addNotify): Do nothing if peer exists.
2000-07-30 Tom Tromey <tromey@cygnus.com>
* java/awt/Container.java (remove(int)): Wrote. * java/awt/Container.java (remove(int)): Wrote.
(remove(Component)): Wrote. (remove(Component)): Wrote.
(add(Component)): Wrote. (add(Component)): Wrote.
......
/* Copyright (C) 1999 Free Software Foundation /* Copyright (C) 1999, 2000 Free Software Foundation
This file is part of libjava. This file is part of libjava.
...@@ -15,6 +15,11 @@ public class BorderLayout implements LayoutManager2 ...@@ -15,6 +15,11 @@ public class BorderLayout implements LayoutManager2
int hgap; int hgap;
int vgap; int vgap;
public BorderLayout ()
{
this (0, 0);
}
public BorderLayout (int hgap, int vgap) public BorderLayout (int hgap, int vgap)
{ {
this.hgap = hgap; this.hgap = hgap;
......
...@@ -36,7 +36,8 @@ public class Button extends Component ...@@ -36,7 +36,8 @@ public class Button extends Component
public void addNotify () public void addNotify ()
{ {
peer = (ComponentPeer) getToolkit ().createButton (this); if (peer == null)
peer = (ComponentPeer) getToolkit ().createButton (this);
} }
public String getActionCommand () public String getActionCommand ()
......
...@@ -137,23 +137,25 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -137,23 +137,25 @@ public abstract class Component implements ImageObserver, MenuContainer,
// FIXME // FIXME
return null; return null;
} }
public final Object getTreeLock() public final Object getTreeLock()
{ {
// FIXME // FIXME
return null; return null;
} }
public Toolkit getToolkit() public Toolkit getToolkit()
{ {
// FIXME if (peer != null)
return null; return peer.getToolkit ();
if (parent != null)
return parent.getToolkit ();
return Toolkit.getDefaultToolkit ();
} }
public boolean isValid() public boolean isValid()
{ {
// FIXME return valid;
return false;
} }
/** @since 1.2 */ /** @since 1.2 */
...@@ -518,7 +520,9 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -518,7 +520,9 @@ public abstract class Component implements ImageObserver, MenuContainer,
public void invalidate() public void invalidate()
{ {
// FIXME valid = false;
if (parent != null)
parent.invalidate ();
} }
public Graphics getGraphics() public Graphics getGraphics()
......
...@@ -29,7 +29,10 @@ public abstract class Container extends Component ...@@ -29,7 +29,10 @@ public abstract class Container extends Component
/* Anything else is non-serializable, and should be declared "transient". */ /* Anything else is non-serializable, and should be declared "transient". */
transient ContainerListener containerListener; transient ContainerListener containerListener;
// Insets.
private transient Insets myInsets;
public Container() public Container()
{ {
} }
...@@ -62,10 +65,9 @@ public abstract class Container extends Component ...@@ -62,10 +65,9 @@ public abstract class Container extends Component
public Insets getInsets() public Insets getInsets()
{ {
// FIXME return myInsets;
return null;
} }
/** @deprecated Use getInsets() instead. */ /** @deprecated Use getInsets() instead. */
public Insets insets() public Insets insets()
{ {
...@@ -74,17 +76,50 @@ public abstract class Container extends Component ...@@ -74,17 +76,50 @@ public abstract class Container extends Component
public Component add (Component comp) 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 addImpl (comp, name, -1);
return null; 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 // This isn't the most efficient implementation. We could do less
// copying when growing the array. It probably doesn't matter. // copying when growing the array. It probably doesn't matter.
if (ncomponents >= component.length) if (ncomponents >= component.length)
...@@ -94,7 +129,6 @@ public abstract class Container extends Component ...@@ -94,7 +129,6 @@ public abstract class Container extends Component
System.arraycopy (component, 0, c, 0, ncomponents); System.arraycopy (component, 0, c, 0, ncomponents);
component = c; component = c;
} }
if (index == -1) if (index == -1)
component[ncomponents++] = comp; component[ncomponents++] = comp;
else else
...@@ -105,45 +139,69 @@ public abstract class Container extends Component ...@@ -105,45 +139,69 @@ public abstract class Container extends Component
++ncomponents; ++ncomponents;
} }
return comp; // Notify the layout manager.
} if (layoutMgr != null)
{
public void add(Component comp, Object constraints) if (constraints != null && layoutMgr instanceof LayoutManager2)
{ {
// FIXME LayoutManager2 lm2 = (LayoutManager2) layoutMgr;
} lm2.addLayoutComponent (comp, constraints);
}
else
layoutMgr.addLayoutComponent ((String) constraints, comp);
}
public void add(Component comp, Object constraints, int index) ContainerEvent ce = new ContainerEvent (this,
{ ContainerEvent.COMPONENT_ADDED,
// FIXME comp);
}
protected void addImpl(Component comp, Object constraints, int index) // FIXME: is this right?
{ dispatchEvent (ce);
// FIXME if (containerListener != null)
containerListener.componentAdded (ce);
} }
public void remove (int index) public void remove (int index)
{ {
Component r = component[index];
r.removeNotify ();
System.arraycopy (component, index + 1, component, index, System.arraycopy (component, index + 1, component, index,
ncomponents - index - 1); ncomponents - index - 1);
component[--ncomponents] = null; 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) public void remove (Component comp)
{ {
for (int i = 0; i < ncomponents; ++i) for (int i = 0; i < ncomponents; ++i)
if (component[i] == comp) {
{ if (component[i] == comp)
remove (i); {
break; remove (i);
} break;
}
}
} }
public void removeAll() public void removeAll()
{ {
while (ncomponents >= 0) while (ncomponents > 0)
component[--ncomponents] = null; remove (0);
} }
public LayoutManager getLayout() public LayoutManager getLayout()
...@@ -159,7 +217,8 @@ public abstract class Container extends Component ...@@ -159,7 +217,8 @@ public abstract class Container extends Component
public void doLayout() public void doLayout()
{ {
// FIXME if (layoutMgr != null)
layoutMgr.layoutContainer (this);
} }
/** @deprecated Use doLayout() instead. */ /** @deprecated Use doLayout() instead. */
...@@ -170,17 +229,22 @@ public abstract class Container extends Component ...@@ -170,17 +229,22 @@ public abstract class Container extends Component
public void invalidate() public void invalidate()
{ {
// FIXME super.invalidate ();
} }
public void validate() public void validate()
{ {
// FIXME if (! isValid ())
{
doLayout ();
validateTree ();
}
} }
protected void validateTree() protected void validateTree()
{ {
// FIXME for (int i = 0; i < ncomponents; ++i)
component[i].validate ();
} }
public void setFont(Font f) public void setFont(Font f)
...@@ -190,8 +254,10 @@ public abstract class Container extends Component ...@@ -190,8 +254,10 @@ public abstract class Container extends Component
public Dimension getPreferredSize() public Dimension getPreferredSize()
{ {
// FIXME if (layoutMgr != null)
return null; return layoutMgr.preferredLayoutSize (this);
else
return super.getPreferredSize ();
} }
/** @deprecated Use getPreferredSize() instead */ /** @deprecated Use getPreferredSize() instead */
...@@ -202,8 +268,10 @@ public abstract class Container extends Component ...@@ -202,8 +268,10 @@ public abstract class Container extends Component
public Dimension getMinimumSize() public Dimension getMinimumSize()
{ {
// FIXME if (layoutMgr != null)
return null; return layoutMgr.minimumLayoutSize (this);
else
return super.getMinimumSize ();
} }
/** @deprecated Use getMinimumSize() instead */ /** @deprecated Use getMinimumSize() instead */
...@@ -214,20 +282,35 @@ public abstract class Container extends Component ...@@ -214,20 +282,35 @@ public abstract class Container extends Component
public Dimension getMaximumSize() public Dimension getMaximumSize()
{ {
// FIXME if (layoutMgr != null && layoutMgr instanceof LayoutManager2)
return null; {
LayoutManager2 lm2 = (LayoutManager2) layoutMgr;
return lm2.maximumLayoutSize (this);
}
else
return super.getMaximumSize ();
} }
public float getAlignmentX() public float getAlignmentX()
{ {
// FIXME if (layoutMgr instanceof LayoutManager2)
return 0; {
LayoutManager2 lm2 = (LayoutManager2) layoutMgr;
return lm2.getLayoutAlignmentX (this);
}
else
return CENTER_ALIGNMENT;
} }
public float getAlignmentY() public float getAlignmentY()
{ {
// FIXME if (layoutMgr instanceof LayoutManager2)
return 0; {
LayoutManager2 lm2 = (LayoutManager2) layoutMgr;
return lm2.getLayoutAlignmentY (this);
}
else
return CENTER_ALIGNMENT;
} }
public void paint(Graphics g) public void paint(Graphics g)
...@@ -252,7 +335,8 @@ public abstract class Container extends Component ...@@ -252,7 +335,8 @@ public abstract class Container extends Component
public void printComponents(Graphics g) public void printComponents(Graphics g)
{ {
// FIXME for (int i = 0; i < ncomponents; ++i)
component[i].printAll (g);
} }
void dispatchEventImpl(AWTEvent e) void dispatchEventImpl(AWTEvent e)
...@@ -267,14 +351,12 @@ public abstract class Container extends Component ...@@ -267,14 +351,12 @@ public abstract class Container extends Component
public void addContainerListener(ContainerListener l) public void addContainerListener(ContainerListener l)
{ {
containerListener = (ContainerListener) containerListener = AWTEventMulticaster.add (containerListener, l);
AWTEventMulticaster.add(containerListener, l);
} }
public void removeContainerListener(ContainerListener l) public void removeContainerListener(ContainerListener l)
{ {
containerListener = (ContainerListener) containerListener = AWTEventMulticaster.remove(containerListener, l);
AWTEventMulticaster.remove(containerListener, l);
} }
/** @since 1.3 */ /** @since 1.3 */
...@@ -294,7 +376,7 @@ public abstract class Container extends Component ...@@ -294,7 +376,7 @@ public abstract class Container extends Component
protected void processContainerEvent(ContainerEvent e) protected void processContainerEvent(ContainerEvent e)
{ {
if (componentListener == null) if (containerListener == null)
return; return;
switch (e.id) switch (e.id)
{ {
...@@ -313,9 +395,17 @@ public abstract class Container extends Component ...@@ -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; return null;
} }
...@@ -345,12 +435,13 @@ public abstract class Container extends Component ...@@ -345,12 +435,13 @@ public abstract class Container extends Component
{ {
for (int i = ncomponents; --i >= 0; ) for (int i = ncomponents; --i >= 0; )
component[i].addNotify(); component[i].addNotify();
peer = (ComponentPeer) getToolkit ().createContainer (this);
} }
public void removeNotify() public void removeNotify()
{ {
// FIXME for (int i = 0; i < ncomponents; ++i)
component[i].removeNotify ();
// FIXME: remove our peer.
} }
public boolean isAncestorOf (Component comp) public boolean isAncestorOf (Component comp)
...@@ -370,13 +461,21 @@ public abstract class Container extends Component ...@@ -370,13 +461,21 @@ public abstract class Container extends Component
return "FIXME"; 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) 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);
} }
} }
...@@ -17,11 +17,13 @@ public class Frame extends Window implements MenuContainer ...@@ -17,11 +17,13 @@ public class Frame extends Window implements MenuContainer
String title; String title;
public Frame () public Frame ()
{ /* FIXME */ } {
super (null);
}
public Frame (String title) public Frame (String title)
{ {
this(); super (null);
setTitle(title); setTitle(title);
} }
...@@ -43,13 +45,7 @@ public class Frame extends Window implements MenuContainer ...@@ -43,13 +45,7 @@ public class Frame extends Window implements MenuContainer
public synchronized void addNotify () public synchronized void addNotify ()
{ {
if (peer == null) if (peer == null)
{ peer = getToolkit ().createFrame (this);
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);
}
super.addNotify(); super.addNotify();
} }
......
...@@ -41,7 +41,8 @@ public class Label extends Component ...@@ -41,7 +41,8 @@ public class Label extends Component
public void addNotify () public void addNotify ()
{ {
peer = (ComponentPeer) getToolkit ().createLabel (this); if (peer == null)
peer = (ComponentPeer) getToolkit ().createLabel (this);
} }
public int getAlignment () public int getAlignment ()
......
...@@ -53,7 +53,8 @@ public class Scrollbar extends Component implements Adjustable ...@@ -53,7 +53,8 @@ public class Scrollbar extends Component implements Adjustable
public void addNotify () public void addNotify ()
{ {
peer = (ComponentPeer) getToolkit ().createScrollbar (this); if (peer == null)
peer = (ComponentPeer) getToolkit ().createScrollbar (this);
} }
public int getOrientation () public int getOrientation ()
......
...@@ -31,6 +31,7 @@ public abstract class Toolkit ...@@ -31,6 +31,7 @@ public abstract class Toolkit
protected abstract ContainerPeer createContainer (Container target); protected abstract ContainerPeer createContainer (Container target);
protected abstract LabelPeer createLabel (Label target); protected abstract LabelPeer createLabel (Label target);
protected abstract ScrollbarPeer createScrollbar (Scrollbar target); protected abstract ScrollbarPeer createScrollbar (Scrollbar target);
protected abstract WindowPeer createWindow (Window target);
public final EventQueue getSystemEventQueue() public final EventQueue getSystemEventQueue()
{ {
......
/* Copyright (C) 1999 Free Software Foundation /* Copyright (C) 1999, 2000 Free Software Foundation
This file is part of libjava. This file is part of libjava.
...@@ -7,23 +7,139 @@ Libjava License. Please consult the file "LIBJAVA_LICENSE" for ...@@ -7,23 +7,139 @@ Libjava License. Please consult the file "LIBJAVA_LICENSE" for
details. */ details. */
package java.awt; package java.awt;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener; import java.awt.event.WindowListener;
import java.awt.peer.WindowPeer;
import java.awt.peer.ComponentPeer;
import java.util.Locale;
/* A very incomplete placeholder. */ /* A very incomplete placeholder. */
public class Window extends Container public class Window extends Container
{ {
public void dispose () public Window (Frame parent)
{ /* FIXME */ } {
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) 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 () public void show ()
{ {
addNotify(); addNotify ();
// validate FIXME validate ();
// validate setVisible FIXME 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;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment