aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libjava/ChangeLog35
-rw-r--r--libjava/java/awt/Button.java94
-rw-r--r--libjava/java/awt/Component.java1
-rw-r--r--libjava/java/awt/Container.java51
-rw-r--r--libjava/java/awt/Label.java16
-rw-r--r--libjava/java/awt/Scrollbar.java82
-rw-r--r--libjava/java/awt/Toolkit.java5
7 files changed, 238 insertions, 46 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 29e2d8e..4425fdb 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,38 @@
+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>
* java/io/ObjectOutputStream.java (writeObject): Per spec, call
diff --git a/libjava/java/awt/Button.java b/libjava/java/awt/Button.java
new file mode 100644
index 0000000..a582b96
--- /dev/null
+++ b/libjava/java/awt/Button.java
@@ -0,0 +1,94 @@
+/* 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;
+}
diff --git a/libjava/java/awt/Component.java b/libjava/java/awt/Component.java
index d578826..5c59ed6 100644
--- a/libjava/java/awt/Component.java
+++ b/libjava/java/awt/Component.java
@@ -112,6 +112,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
}
/** @deprecated */
+ // However, Classpath's Gtk peers rely on it.
public java.awt.peer.ComponentPeer getPeer()
{
return peer;
diff --git a/libjava/java/awt/Container.java b/libjava/java/awt/Container.java
index 8484024..81a367b 100644
--- a/libjava/java/awt/Container.java
+++ b/libjava/java/awt/Container.java
@@ -12,6 +12,8 @@ import java.awt.event.*;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.EventListener;
+import java.awt.peer.ComponentPeer;
+import java.awt.peer.ContainerPeer;
/* A very incomplete placeholder. */
@@ -70,10 +72,9 @@ public abstract class Container extends Component
return getInsets();
}
- public Component add(Component comp)
+ public Component add (Component comp)
{
- // FIXME
- return null;
+ return add (comp, -1);
}
public Component add(String name, Component comp)
@@ -84,8 +85,27 @@ public abstract class Container extends Component
public Component add(Component comp, int index)
{
- // FIXME
- return null;
+ // 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)
+ {
+ 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)
@@ -103,19 +123,27 @@ public abstract class Container extends Component
// 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()
{
- // FIXME
+ while (ncomponents >= 0)
+ component[--ncomponents] = null;
}
public LayoutManager getLayout()
@@ -317,7 +345,8 @@ public abstract class Container extends Component
{
for (int i = ncomponents; --i >= 0; )
component[i].addNotify();
- }
+ peer = (ComponentPeer) getToolkit ().createContainer (this);
+ }
public void removeNotify()
{
diff --git a/libjava/java/awt/Label.java b/libjava/java/awt/Label.java
index 230e568..93d2053 100644
--- a/libjava/java/awt/Label.java
+++ b/libjava/java/awt/Label.java
@@ -7,14 +7,14 @@ Libjava License. Please consult the file "LIBJAVA_LICENSE" for
details. */
package java.awt;
+import java.awt.peer.ComponentPeer;
+import java.awt.peer.LabelPeer;
/**
* @author Tom Tromey <tromey@cygnus.com>
* @date April 12, 2000
*/
-/* Status: addNotify() not written. */
-
public class Label extends Component
{
public static final int CENTER = 1;
@@ -41,7 +41,7 @@ public class Label extends Component
public void addNotify ()
{
- // FIXME
+ peer = (ComponentPeer) getToolkit ().createLabel (this);
}
public int getAlignment ()
@@ -64,11 +64,21 @@ public class Label extends Component
if (alignment != CENTER && alignment != LEFT && alignment != RIGHT)
throw new IllegalArgumentException ();
this.alignment = alignment;
+ if (peer != null)
+ {
+ LabelPeer lp = (LabelPeer) peer;
+ lp.setAlignment (alignment);
+ }
}
public void setText (String text)
{
this.text = text;
+ if (peer != null)
+ {
+ LabelPeer lp = (LabelPeer) peer;
+ lp.setText (text);
+ }
}
private String text;
diff --git a/libjava/java/awt/Scrollbar.java b/libjava/java/awt/Scrollbar.java
index 6f79175..5406c0c 100644
--- a/libjava/java/awt/Scrollbar.java
+++ b/libjava/java/awt/Scrollbar.java
@@ -8,8 +8,8 @@ details. */
package java.awt;
import java.awt.event.*;
-import java.util.Vector;
-import java.util.Enumeration;
+import java.awt.peer.ScrollbarPeer;
+import java.awt.peer.ComponentPeer;
/**
* @author Tom Tromey <tromey@cygnus.com>
@@ -47,14 +47,13 @@ public class Scrollbar extends Component implements Adjustable
this.minimum = minimum;
this.maximum = maximum;
this.unit = 1;
- this.listeners = new Vector ();
this.block = 0; // FIXME
}
public void addNotify ()
{
- // FIXME
+ peer = (ComponentPeer) getToolkit ().createScrollbar (this);
}
public int getOrientation ()
@@ -76,11 +75,7 @@ public class Scrollbar extends Component implements Adjustable
public void setValue (int value)
{
- if (value < minimum)
- value = minimum;
- else if (value > maximum)
- value = maximum;
- this.value = value;
+ setValues (value, visible, minimum, maximum);
}
public int getMinimum ()
@@ -90,8 +85,7 @@ public class Scrollbar extends Component implements Adjustable
public void setMinimum (int minimum)
{
- // FIXME: what if it is > max?
- this.minimum = minimum;
+ setValues (value, visible, minimum, maximum);
}
public int getMaximum ()
@@ -101,8 +95,7 @@ public class Scrollbar extends Component implements Adjustable
public void setMaximum (int maximum)
{
- // FIXME: what if it is < min?
- this.maximum = maximum;
+ setValues (value, visible, minimum, maximum);
}
public int getVisibleAmount ()
@@ -117,17 +110,23 @@ public class Scrollbar extends Component implements Adjustable
public void setVisibleAmount (int visible)
{
- this.visible = visible;
+ setValues (value, visible, minimum, maximum);
}
public void setUnitIncrement (int v)
{
unit = v;
+ if (peer != null)
+ {
+ ScrollbarPeer sp = (ScrollbarPeer) peer;
+ sp.setLineIncrement (v);
+ }
}
+ /** @deprecated */
public void setLineIncrement (int v)
{
- unit = v;
+ setUnitIncrement (v);
}
public int getUnitIncrement ()
@@ -143,11 +142,16 @@ public class Scrollbar extends Component implements Adjustable
public void setBlockIncrement (int v)
{
block = v;
+ if (peer != null)
+ {
+ ScrollbarPeer sp = (ScrollbarPeer) peer;
+ sp.setPageIncrement (v);
+ }
}
public void setPageIncrement (int v)
{
- block = v;
+ setBlockIncrement (v);
}
public int getBlockIncrement ()
@@ -163,22 +167,33 @@ public class Scrollbar extends Component implements Adjustable
public synchronized void setValues (int value, int visible,
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)
{
- if (l != null)
- {
- listeners.addElement (l);
- enableEvents (0); // FIXME
- }
+ listeners = AWTEventMulticaster.add (listeners, l);
}
public void removeAdjustmentListener (AdjustmentListener l)
{
- if (l != null)
- listeners.remove (l);
+ listeners = AWTEventMulticaster.add (listeners, l);
}
protected void processEvent (AWTEvent e)
@@ -191,20 +206,23 @@ public class Scrollbar extends Component implements Adjustable
protected void processAdjustmentEvent (AdjustmentEvent e)
{
- Enumeration en = listeners.elements ();
- while (en.hasMoreElements ())
- {
- AdjustmentListener l = (AdjustmentListener) en.nextElement ();
- l.adjustmentValueChanged (e);
- }
+ if (listeners != null)
+ listeners.adjustmentValueChanged (e);
}
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 value;
private int visible;
diff --git a/libjava/java/awt/Toolkit.java b/libjava/java/awt/Toolkit.java
index f7ec764..2aea96d 100644
--- a/libjava/java/awt/Toolkit.java
+++ b/libjava/java/awt/Toolkit.java
@@ -27,6 +27,11 @@ public abstract class Toolkit
protected abstract FramePeer createFrame(Frame target);
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()
{
return systemEventQueue;