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
This commit is contained in:
Tom Tromey 2000-07-31 02:03:51 +00:00 committed by Tom Tromey
parent 911a71a729
commit e0a339f785
10 changed files with 375 additions and 91 deletions

View File

@ -1,3 +1,63 @@
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.

View File

@ -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;

View File

@ -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 ()

View File

@ -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()

View File

@ -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);
}
public Component add(String name, Component comp)
{
// FIXME
return null;
addImpl (comp, null, -1);
return comp;
}
public Component add(Component comp, int index)
public Component add (String name, Component comp)
{
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);
}
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;
}
// 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)
{
// FIXME
}
ContainerEvent ce = new ContainerEvent (this,
ContainerEvent.COMPONENT_ADDED,
comp);
public void add(Component comp, Object constraints, int index)
{
// FIXME
}
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);
}
}

View File

@ -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();
}

View File

@ -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 ()

View File

@ -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 ()

View File

@ -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()
{

View File

@ -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;
}