Commit 4e07a9ea by Tom Tromey Committed by Tom Tromey

Container.java (remove(int)): Wrote.

	* java/awt/Container.java (remove(int)): Wrote.
	(remove(Component)): Wrote.
	(add(Component)): Wrote.
	(add(Component,int)): Wrote.
	(removeAll): Wrote.
	(addNotify): Set our own peer.
	* java/awt/Scrollbar.java (listeners): Changed type.
	(Scrollbar): Don't initialize listeners.
	(addNotify): Wrote.
	(setValue): Call setValues.
	(setMinimum): Likewise.
	(setMaxPriority): Likewise.
	(setVisibleAmount): Likewise.
	(setValues): Wrote.
	(setUnitIncrement): Forward to peer.
	(setLineIncrement): Call setUnitIncrement.
	(setPageIncrement): Call setBlockIncrement.
	(setBlockIncrement): Forward to peer.
	(addAdjustmentListener): Rewrote.
	(removeAdjustmentListener): Rewrote.
	(processAdjustmentEvent): Rewrote.
	(paramString): Wrote.
	* Makefile.in: Rebuilt.
	* Makefile.am (awt_java_source_files): Added Button.java.
	* java/awt/Button.java: New file.
	* java/awt/Toolkit.java (createLabel): Declare.
	(createButton): Likewise.
	(createScrollbar): Likewise.
	(createContainer): Likewise.
	* java/awt/Label.java (addNotify): Wrote.
	(setAlignment): Call setAlignment in the peer.
	(setText): Call setText in the peer.

From-SVN: r35354
parent 3a8c5c77
2000-07-30 Tom Tromey <tromey@cygnus.com>
* java/awt/Container.java (remove(int)): Wrote.
(remove(Component)): Wrote.
(add(Component)): Wrote.
(add(Component,int)): Wrote.
(removeAll): Wrote.
(addNotify): Set our own peer.
* java/awt/Scrollbar.java (listeners): Changed type.
(Scrollbar): Don't initialize listeners.
(addNotify): Wrote.
(setValue): Call setValues.
(setMinimum): Likewise.
(setMaxPriority): Likewise.
(setVisibleAmount): Likewise.
(setValues): Wrote.
(setUnitIncrement): Forward to peer.
(setLineIncrement): Call setUnitIncrement.
(setPageIncrement): Call setBlockIncrement.
(setBlockIncrement): Forward to peer.
(addAdjustmentListener): Rewrote.
(removeAdjustmentListener): Rewrote.
(processAdjustmentEvent): Rewrote.
(paramString): Wrote.
* Makefile.in: Rebuilt.
* Makefile.am (awt_java_source_files): Added Button.java.
* java/awt/Button.java: New file.
* java/awt/Toolkit.java (createLabel): Declare.
(createButton): Likewise.
(createScrollbar): Likewise.
(createContainer): Likewise.
* java/awt/Label.java (addNotify): Wrote.
(setAlignment): Call setAlignment in the peer.
(setText): Call setText in the peer.
2000-07-28 Warren Levy <warrenl@cygnus.com> 2000-07-28 Warren Levy <warrenl@cygnus.com>
* java/io/ObjectOutputStream.java (writeObject): Per spec, call * java/io/ObjectOutputStream.java (writeObject): Per spec, call
......
/* Copyright (C) 2000 Free Software Foundation
This file is part of libjava.
This software is copyrighted work licensed under the terms of the
Libjava License. Please consult the file "LIBJAVA_LICENSE" for
details. */
package java.awt;
import java.awt.peer.ButtonPeer;
import java.awt.peer.ComponentPeer;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/**
* @author Tom Tromey <tromey@cygnus.com>
* @date July 30, 2000
*/
public class Button extends Component
{
public Button ()
{
this (null);
}
public Button (String label)
{
this.label = label;
}
public void addActionListener (ActionListener l)
{
listeners = AWTEventMulticaster.add (listeners, l);
}
public void addNotify ()
{
peer = (ComponentPeer) getToolkit ().createButton (this);
}
public String getActionCommand ()
{
return command;
}
public String getLabel ()
{
return label;
}
protected String paramString ()
{
return "Button[" + label + "]";
}
protected void processActionEvent (ActionEvent e)
{
if (listeners != null)
listeners.actionPerformed (e);
}
protected void processEvent (AWTEvent e)
{
if (e instanceof ActionEvent)
processActionEvent ((ActionEvent) e);
else
super.processEvent (e);
}
public void removeActionListener (ActionListener l)
{
listeners = AWTEventMulticaster.remove (listeners, l);
}
public void setActionCommand (String command)
{
this.command = (command == null) ? label : command;
}
public void setLabel (String label)
{
this.label = label;
if (peer != null)
{
ButtonPeer bp = (ButtonPeer) peer;
bp.setLabel (label);
}
}
private String label;
private String command;
private ActionListener listeners;
}
...@@ -112,6 +112,7 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -112,6 +112,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
} }
/** @deprecated */ /** @deprecated */
// However, Classpath's Gtk peers rely on it.
public java.awt.peer.ComponentPeer getPeer() public java.awt.peer.ComponentPeer getPeer()
{ {
return peer; return peer;
......
...@@ -12,6 +12,8 @@ import java.awt.event.*; ...@@ -12,6 +12,8 @@ import java.awt.event.*;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.EventListener; import java.util.EventListener;
import java.awt.peer.ComponentPeer;
import java.awt.peer.ContainerPeer;
/* A very incomplete placeholder. */ /* A very incomplete placeholder. */
...@@ -70,10 +72,9 @@ public abstract class Container extends Component ...@@ -70,10 +72,9 @@ public abstract class Container extends Component
return getInsets(); return getInsets();
} }
public Component add(Component comp) public Component add (Component comp)
{ {
// FIXME return add (comp, -1);
return null;
} }
public Component add(String name, Component comp) public Component add(String name, Component comp)
...@@ -84,8 +85,27 @@ public abstract class Container extends Component ...@@ -84,8 +85,27 @@ public abstract class Container extends Component
public Component add(Component comp, int index) public Component add(Component comp, int index)
{ {
// FIXME // This isn't the most efficient implementation. We could do less
return null; // copying when growing the array. It probably doesn't matter.
if (ncomponents >= component.length)
{
int nl = component.length * 2;
Component[] c = new Component[nl];
System.arraycopy (component, 0, c, 0, ncomponents);
component = c;
}
if (index == -1)
component[ncomponents++] = comp;
else
{
System.arraycopy (component, index, component, index + 1,
ncomponents - index);
component[index] = comp;
++ncomponents;
}
return comp;
} }
public void add(Component comp, Object constraints) public void add(Component comp, Object constraints)
...@@ -103,19 +123,27 @@ public abstract class Container extends Component ...@@ -103,19 +123,27 @@ public abstract class Container extends Component
// FIXME // FIXME
} }
public void remove(int index) public void remove (int index)
{ {
// FIXME System.arraycopy (component, index + 1, component, index,
ncomponents - index - 1);
component[--ncomponents] = null;
} }
public void remove(Component comp) public void remove (Component comp)
{ {
// FIXME for (int i = 0; i < ncomponents; ++i)
if (component[i] == comp)
{
remove (i);
break;
}
} }
public void removeAll() public void removeAll()
{ {
// FIXME while (ncomponents >= 0)
component[--ncomponents] = null;
} }
public LayoutManager getLayout() public LayoutManager getLayout()
...@@ -317,7 +345,8 @@ public abstract class Container extends Component ...@@ -317,7 +345,8 @@ 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()
{ {
......
...@@ -7,14 +7,14 @@ Libjava License. Please consult the file "LIBJAVA_LICENSE" for ...@@ -7,14 +7,14 @@ Libjava License. Please consult the file "LIBJAVA_LICENSE" for
details. */ details. */
package java.awt; package java.awt;
import java.awt.peer.ComponentPeer;
import java.awt.peer.LabelPeer;
/** /**
* @author Tom Tromey <tromey@cygnus.com> * @author Tom Tromey <tromey@cygnus.com>
* @date April 12, 2000 * @date April 12, 2000
*/ */
/* Status: addNotify() not written. */
public class Label extends Component public class Label extends Component
{ {
public static final int CENTER = 1; public static final int CENTER = 1;
...@@ -41,7 +41,7 @@ public class Label extends Component ...@@ -41,7 +41,7 @@ public class Label extends Component
public void addNotify () public void addNotify ()
{ {
// FIXME peer = (ComponentPeer) getToolkit ().createLabel (this);
} }
public int getAlignment () public int getAlignment ()
...@@ -64,11 +64,21 @@ public class Label extends Component ...@@ -64,11 +64,21 @@ public class Label extends Component
if (alignment != CENTER && alignment != LEFT && alignment != RIGHT) if (alignment != CENTER && alignment != LEFT && alignment != RIGHT)
throw new IllegalArgumentException (); throw new IllegalArgumentException ();
this.alignment = alignment; this.alignment = alignment;
if (peer != null)
{
LabelPeer lp = (LabelPeer) peer;
lp.setAlignment (alignment);
}
} }
public void setText (String text) public void setText (String text)
{ {
this.text = text; this.text = text;
if (peer != null)
{
LabelPeer lp = (LabelPeer) peer;
lp.setText (text);
}
} }
private String text; private String text;
......
...@@ -8,8 +8,8 @@ details. */ ...@@ -8,8 +8,8 @@ details. */
package java.awt; package java.awt;
import java.awt.event.*; import java.awt.event.*;
import java.util.Vector; import java.awt.peer.ScrollbarPeer;
import java.util.Enumeration; import java.awt.peer.ComponentPeer;
/** /**
* @author Tom Tromey <tromey@cygnus.com> * @author Tom Tromey <tromey@cygnus.com>
...@@ -47,14 +47,13 @@ public class Scrollbar extends Component implements Adjustable ...@@ -47,14 +47,13 @@ public class Scrollbar extends Component implements Adjustable
this.minimum = minimum; this.minimum = minimum;
this.maximum = maximum; this.maximum = maximum;
this.unit = 1; this.unit = 1;
this.listeners = new Vector ();
this.block = 0; // FIXME this.block = 0; // FIXME
} }
public void addNotify () public void addNotify ()
{ {
// FIXME peer = (ComponentPeer) getToolkit ().createScrollbar (this);
} }
public int getOrientation () public int getOrientation ()
...@@ -76,11 +75,7 @@ public class Scrollbar extends Component implements Adjustable ...@@ -76,11 +75,7 @@ public class Scrollbar extends Component implements Adjustable
public void setValue (int value) public void setValue (int value)
{ {
if (value < minimum) setValues (value, visible, minimum, maximum);
value = minimum;
else if (value > maximum)
value = maximum;
this.value = value;
} }
public int getMinimum () public int getMinimum ()
...@@ -90,8 +85,7 @@ public class Scrollbar extends Component implements Adjustable ...@@ -90,8 +85,7 @@ public class Scrollbar extends Component implements Adjustable
public void setMinimum (int minimum) public void setMinimum (int minimum)
{ {
// FIXME: what if it is > max? setValues (value, visible, minimum, maximum);
this.minimum = minimum;
} }
public int getMaximum () public int getMaximum ()
...@@ -101,8 +95,7 @@ public class Scrollbar extends Component implements Adjustable ...@@ -101,8 +95,7 @@ public class Scrollbar extends Component implements Adjustable
public void setMaximum (int maximum) public void setMaximum (int maximum)
{ {
// FIXME: what if it is < min? setValues (value, visible, minimum, maximum);
this.maximum = maximum;
} }
public int getVisibleAmount () public int getVisibleAmount ()
...@@ -117,17 +110,23 @@ public class Scrollbar extends Component implements Adjustable ...@@ -117,17 +110,23 @@ public class Scrollbar extends Component implements Adjustable
public void setVisibleAmount (int visible) public void setVisibleAmount (int visible)
{ {
this.visible = visible; setValues (value, visible, minimum, maximum);
} }
public void setUnitIncrement (int v) public void setUnitIncrement (int v)
{ {
unit = v; unit = v;
if (peer != null)
{
ScrollbarPeer sp = (ScrollbarPeer) peer;
sp.setLineIncrement (v);
}
} }
/** @deprecated */
public void setLineIncrement (int v) public void setLineIncrement (int v)
{ {
unit = v; setUnitIncrement (v);
} }
public int getUnitIncrement () public int getUnitIncrement ()
...@@ -143,11 +142,16 @@ public class Scrollbar extends Component implements Adjustable ...@@ -143,11 +142,16 @@ public class Scrollbar extends Component implements Adjustable
public void setBlockIncrement (int v) public void setBlockIncrement (int v)
{ {
block = v; block = v;
if (peer != null)
{
ScrollbarPeer sp = (ScrollbarPeer) peer;
sp.setPageIncrement (v);
}
} }
public void setPageIncrement (int v) public void setPageIncrement (int v)
{ {
block = v; setBlockIncrement (v);
} }
public int getBlockIncrement () public int getBlockIncrement ()
...@@ -163,22 +167,33 @@ public class Scrollbar extends Component implements Adjustable ...@@ -163,22 +167,33 @@ public class Scrollbar extends Component implements Adjustable
public synchronized void setValues (int value, int visible, public synchronized void setValues (int value, int visible,
int minimum, int maximum) int minimum, int maximum)
{ {
// fixme; if (maximum < minimum)
maximum = minimum;
if (value < minimum)
value = minimum;
if (value > maximum)
value = maximum;
this.value = value;
this.visible = visible;
this.minimum = minimum;
this.maximum = maximum;
if (peer != null)
{
ScrollbarPeer sp = (ScrollbarPeer) peer;
sp.setValues (value, visible, minimum, maximum);
}
} }
public void addAdjustmentListener (AdjustmentListener l) public void addAdjustmentListener (AdjustmentListener l)
{ {
if (l != null) listeners = AWTEventMulticaster.add (listeners, l);
{
listeners.addElement (l);
enableEvents (0); // FIXME
}
} }
public void removeAdjustmentListener (AdjustmentListener l) public void removeAdjustmentListener (AdjustmentListener l)
{ {
if (l != null) listeners = AWTEventMulticaster.add (listeners, l);
listeners.remove (l);
} }
protected void processEvent (AWTEvent e) protected void processEvent (AWTEvent e)
...@@ -191,20 +206,23 @@ public class Scrollbar extends Component implements Adjustable ...@@ -191,20 +206,23 @@ public class Scrollbar extends Component implements Adjustable
protected void processAdjustmentEvent (AdjustmentEvent e) protected void processAdjustmentEvent (AdjustmentEvent e)
{ {
Enumeration en = listeners.elements (); if (listeners != null)
while (en.hasMoreElements ()) listeners.adjustmentValueChanged (e);
{
AdjustmentListener l = (AdjustmentListener) en.nextElement ();
l.adjustmentValueChanged (e);
}
} }
protected String paramString () protected String paramString ()
{ {
return null; // FIXME return ("Scrollbar["
+ ((orientation == VERTICAL) ? "VERTICAL" : "HORIZONTAL") + ","
+ value + ","
+ visible + ","
+ minimum + ","
+ maximum + ","
+ unit + ","
+ block + "]");
} }
private Vector listeners; private AdjustmentListener listeners;
private int orientation; private int orientation;
private int value; private int value;
private int visible; private int visible;
......
...@@ -27,6 +27,11 @@ public abstract class Toolkit ...@@ -27,6 +27,11 @@ public abstract class Toolkit
protected abstract FramePeer createFrame(Frame target); protected abstract FramePeer createFrame(Frame target);
public abstract Image getImage(URL url); public abstract Image getImage(URL url);
protected abstract ButtonPeer createButton (Button target);
protected abstract ContainerPeer createContainer (Container target);
protected abstract LabelPeer createLabel (Label target);
protected abstract ScrollbarPeer createScrollbar (Scrollbar target);
public final EventQueue getSystemEventQueue() public final EventQueue getSystemEventQueue()
{ {
return systemEventQueue; return systemEventQueue;
......
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