Patch: Jumbo AWT patch

Tom Tromey tromey@redhat.com
Mon Dec 25 16:25:00 GMT 2000


I spent the day hacking AWT.  I'm checking this in.
Don't expect much from me until next year.  I'm taking time off.

2000-12-25  Tom Tromey  <tromey@redhat.com>

	* java/awt/MenuContainer.java: Fixed typo.

	* Makefile.in: Rebuilt.
	* Makefile.am (awt_java_source_files): Added SystemColor.java.
	* java/awt/SystemColor.java: New file.

	* java/awt/Color.java (rgba): Now package-private.

	* java/awt/event/InputEvent.java (isAltGraphDown): New method.

	* java/awt/event/ContainerEvent.java (getContainer): Renamed from
	getComponent.

	* java/awt/MenuItem.java (addNotify): New method.
	(MenuItem(String,MenuShortcut)): New constructor.
	(setLabel): Notify peer of change.
	(setEnabled): Likewise.

	* java/awt/GridLayout.java (toString): New method.

	* java/awt/FlowLayout.java (LEADING, TRAILING): New constants.
	(FlowLayout): Check for LEADING and TRAILING.
	(setAlignment): Likewise.
	(layoutContainer): Handle component orientation.

	* java/awt/Component.java (orientatin): New field.
	(setComponentOrientation): Wrote.
	(getComponentOrientation): Wrote.

	* java/awt/Event.java (Event): Implements Serializable.
	(consumed): New field for serialization.
	* java/awt/Dimension.java (Dimension): Implements Serializable.
	* java/awt/Cursor.java (Cursor): Implements Serializable.
	* java/awt/Container.java (Container): No longer abstract.

	* java/awt/Choice.java: Wrote.
	* java/awt/Checkbox.java: Wrote.
	* java/awt/ItemSelectable.java: Documented.
	* java/awt/CheckboxGroup.java: Wrote.

	* java/awt/CardLayout.java (layoutContainer): Directly use fields
	in other classes.
	(getSize): Likewise.

Tom

Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/egcs/libjava/Makefile.am,v
retrieving revision 1.120
diff -u -r1.120 Makefile.am
--- Makefile.am	2000/12/21 02:00:15	1.120
+++ Makefile.am	2000/12/26 00:20:06
@@ -624,6 +624,7 @@
 java/awt/ScrollPane.java \
 java/awt/Scrollbar.java	\
 java/awt/Shape.java \
+java/awt/SystemColor.java \
 java/awt/TextArea.java \
 java/awt/TextComponent.java \
 java/awt/TextField.java	\
Index: java/awt/CardLayout.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/CardLayout.java,v
retrieving revision 1.1
diff -u -r1.1 CardLayout.java
--- CardLayout.java	2000/12/03 06:34:54	1.1
+++ CardLayout.java	2000/12/26 00:20:06
@@ -19,7 +19,7 @@
  * time.  This class includes methods for changing which card is
  * shown.
  *
- * @verson 0.0
+ * @version 0.0
  * @author Tom Tromey <tromey@redhat.com>
  * @date December 2, 2000
  */
@@ -127,24 +127,22 @@
    */
   public void layoutContainer (Container parent)
   {
-    // FIXME: can we just use the width and height fields of parent?
-    // Or will that break with subclassing?
-    Dimension d = parent.getSize ();
+    int width = parent.width;
+    int height = parent.height;
 
     Insets ins = parent.getInsets ();
 
-    int num = parent.getComponentCount ();
-    // This is more efficient than calling getComponents().
+    int num = parent.ncomponents;
     Component[] comps = parent.component;
-    
+
     for (int i = 0; i < num; ++i)
       {
 	if (comps[i].isVisible ())
 	  {
 	    // Only resize the one we care about.
 	    comps[i].setBounds (hgap + ins.left, vgap + ins.top,
-				d.width - 2 * hgap - ins.left - ins.right,
-				d.height - 2 * vgap - ins.top - ins.bottom);
+				width - 2 * hgap - ins.left - ins.right,
+				height - 2 * vgap - ins.top - ins.bottom);
 	    break;
 	  }
       }
@@ -302,14 +300,11 @@
   // Compute the size according to WHAT.
   private Dimension getSize (Container parent, int what)
   {
-    int w = 0, h = 0, num = parent.getComponentCount ();
-    // This is more efficient than calling getComponents().
+    int w = 0, h = 0, num = parent.ncomponents;
     Component[] comps = parent.component;
 
     for (int i = 0; i < num; ++i)
       {
-	// FIXME: can we just directly read the fields in Component?
-	// Or will that not work with subclassing?
 	Dimension d;
 
 	if (what == MIN)
Index: java/awt/Checkbox.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/Checkbox.java,v
retrieving revision 1.1
diff -u -r1.1 Checkbox.java
--- Checkbox.java	2000/08/03 12:09:38	1.1
+++ Checkbox.java	2000/12/26 00:20:06
@@ -7,9 +7,179 @@
 details.  */
 
 package java.awt;
+import java.awt.event.*;
+import java.awt.peer.CheckboxPeer;
 
-/* A very incomplete placeholder. */
-
-public class Checkbox extends Component
+/** This class implements a component which has an on/off state.  Two
+ * or more Checkboxes can be grouped by a CheckboxGroup.
+ * @author Tom Tromey <tromey@redhat.com>
+ * @date December 25, 2000
+ */
+public class Checkbox extends Component implements ItemSelectable
 {
+  /** Create a new checkbox.
+   * @param label The checkbox label.  A null value is the same as "";
+   *              this is the default.
+   * @param state The initial check state; defaults to false.
+   * @param group The CheckboxGroup.  Defaults to null.
+   */
+  public Checkbox ()
+  {
+    this (null, null, false);
+  }
+
+  public Checkbox (String label)
+  {
+    this (label, null, false);
+  }
+
+  public Checkbox (String label, boolean state)
+  {
+    this (label, null, state);
+  }
+
+  public Checkbox (String label, boolean state, CheckboxGroup group)
+  {
+    this (label, group, state);
+  }
+
+  public Checkbox (String label, CheckboxGroup group, boolean state)
+  {
+    this.label = label;
+    this.group = group;
+    this.state = state;
+  }
+
+  /** Add a listener for item events.
+   * @param listener The listener to add.
+   */
+  public synchronized void addItemListener (ItemListener listener)
+  {
+    listeners = AWTEventMulticaster.add (listeners, listener);
+  }
+
+  /** This creates the component's peer.  */
+  public void addNotify ()
+  {
+    if (peer == null)
+      peer = getToolkit ().createCheckbox (this);
+  }
+
+  /** Returns the current CheckboxGroup associated with this
+   * Checkbox.  */
+  public CheckboxGroup getCheckboxGroup ()
+  {
+    return group;
+  }
+
+  /** Returns the current label; might be null.  */
+  public String getLabel ()
+  {
+    return label;
+  }
+
+  /** Returns this checkbox's label if this checkbox is selected.  */
+  public Object[] getSelectedObjects ()
+  {
+    Object[] r;
+    if (state)
+      {
+	r = new Object[1];
+	r[0] = label;
+      }
+    else
+      r = new Object[0];
+    return r;
+  }
+
+  /** Returns the current state of this checkbox.  */
+  public boolean getState ()
+  {
+    return state;
+  }
+
+  /** Generates a String representation of this Checkbox's state.  */
+  protected String paramString ()
+  {
+    return ("Checkbox["
+	    + "state=" + state + ","
+	    + "label=" + label + ","
+	    + "group=" + group + "]");
+  }
+
+  /** Process an event for this Checkbox.
+   * @param event The event the process.
+   */
+  protected void processEvent (AWTEvent event) 
+  {
+    if (event instanceof ItemEvent)
+      processItemEvent ((ItemEvent) event);
+    else
+      super.processEvent (event);
+  }
+
+  /** Process an item event for this Checkbox.
+   * @param event The ItemEvent to process
+   */
+  protected void processItemEvent (ItemEvent event)
+  {
+    if (listeners != null)
+      listeners.itemStateChanged (event);
+  }
+
+  /** Remove an item listener.
+   * @param listener Item listener to remove.
+   */
+  public synchronized void removeItemListener (ItemListener listener)
+  {
+    listeners = AWTEventMulticaster.remove (listeners, listener);
+  }
+
+  /** Set this checkbox's group.
+   * @param group The new group.  null means remove the Checkbox from
+   *              its group.
+   */
+  public void setCheckboxGroup (CheckboxGroup group)
+  {
+    this.group = group;
+    if (peer != null)
+      {
+	CheckboxPeer cp = (CheckboxPeer) peer;
+	cp.setCheckboxGroup (group);
+      }
+  }
+
+  /** Set the checkbox's label.
+   * @param label The new label
+   */
+  public synchronized void setLabel (String label)
+  {
+    this.label = label;
+    if (peer != null)
+      {
+	CheckboxPeer cp = (CheckboxPeer) peer;
+	// FIXME: unclear what to do here; we err on the side of
+	// caution.
+	cp.setLabel (label == null ? "" : label);
+      }
+  }
+
+  /** Set the checkbox's state.
+   * @param state The new state.
+   */
+  public void setState (boolean state)
+  {
+    this.state = state;
+    if (peer != null)
+      {
+	CheckboxPeer cp = (CheckboxPeer) peer;
+	cp.setState (state);
+      }
+  }
+
+  private ItemListener listeners;
+
+  String label;
+  CheckboxGroup group;
+  boolean state;
 }
Index: java/awt/CheckboxGroup.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/CheckboxGroup.java,v
retrieving revision 1.1
diff -u -r1.1 CheckboxGroup.java
--- CheckboxGroup.java	2000/07/12 03:32:06	1.1
+++ CheckboxGroup.java	2000/12/26 00:20:06
@@ -8,11 +8,59 @@
 
 package java.awt;
 
-/* Status: Empty placeholder. */
+import java.io.Serializable;
 
-public class CheckboxGroup
+/** This class is used to groups checkbox components.
+ * @author Tom Tromey <tromey@redhat.com>
+ * @date December 25, 2000
+ */
+public class CheckboxGroup implements Serializable
 {
-  // Fields from the serialization spec. Decalare others "transient".
-  boolean state;
-  int checkboxMenuItemSerializedDataVersion;
+  // Current set checkbox.
+  Checkbox selectedCheckbox;
+
+  /** Create a new instance of CheckboxGroup.  */
+  public CheckboxGroup ()
+  {
+  }
+
+  /** Returns the currently selected checkbox in the group.
+   * @deprecated
+   */
+  public Checkbox getCurrent ()
+  {
+    return getSelectedCheckbox ();
+  }
+
+  /** Returns the currently selected checkbox in the group.  */
+  public Checkbox getSelectedCheckbox ()
+  {
+    return selectedCheckbox;
+  }
+
+  /** Set the selected checkbox.
+   * @deprecated
+   */
+  public synchronized void setCurrent (Checkbox checkbox)
+  {
+    setSelectedCheckbox (checkbox);
+  }
+
+  /** Set the selected checkbox.  */
+  public synchronized void setSelectedCheckbox (Checkbox checkbox)
+  {
+    if (checkbox != null && checkbox.group != this)
+      return;
+
+    selectedCheckbox.setState (false);
+    selectedCheckbox = checkbox;
+    if (checkbox != null)
+      checkbox.setState (true);
+  }
+
+  /** Return String representation of this class and current Checkbox.  */
+  public String toString ()
+  {
+    return "[CheckboxGroup: " + selectedCheckbox + "]";
+  }
 }
Index: java/awt/Choice.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/Choice.java,v
retrieving revision 1.1
diff -u -r1.1 Choice.java
--- Choice.java	2000/08/03 12:09:38	1.1
+++ Choice.java	2000/12/26 00:20:07
@@ -7,9 +7,269 @@
 details.  */
 
 package java.awt;
+import java.awt.event.*;
+import java.awt.peer.ChoicePeer;
+import java.util.ArrayList;
 
-/* A very incomplete placeholder. */
-
-public class Choice extends Component
+/** This component lets the user choose an item from a list of
+ * Strings.
+ * @author Tom Tromey <tromey@redhat.com>
+ * @date December 25, 2000
+ */
+public class Choice extends Component implements ItemSelectable
 {
+  /** Create a new Choice object.  */
+  public Choice ()
+  {
+    items = new ArrayList ();
+    selected = -1;
+  }
+
+  /** Add a new item to this Choice object.  If the item is the first
+   * item on the list, then it is selected.
+   * @param item The new item; must be non-null.
+   */
+  public synchronized void add (String item)
+  {
+    if (item == null)
+      throw new IllegalArgumentException ("item must be non-null");
+    items.add (item);
+
+    int i = items.size () - 1;
+    if (peer != null)
+      {
+	ChoicePeer cp = (ChoicePeer) peer;
+	cp.add (item, i);
+      }
+
+    if (i == 0)
+      select (0);
+  }
+
+  /** Add a new item to this Choice object.  This is the same as the
+   * add method.  */
+  public void addItem (String item)
+  {
+    add (item);
+  }
+
+  /** Add a listener for item events.
+   * @param listener The listener to add.
+   */
+  public synchronized void addItemListener (ItemListener listener)
+  {
+    listeners = AWTEventMulticaster.add (listeners, listener);
+  }
+
+  /** This creates the component's peer.  */
+  public void addNotify ()
+  {
+    if (peer == null)
+      peer = getToolkit ().createChoice (this);
+  }
+
+  /** Returns number of items.
+   * @deprecated
+   */
+  public int countItems ()
+  {
+    return getItemCount ();
+  }
+
+  /** Returns an item from this choice.
+   * @param index Index of the item.  Indices start at zero.
+   */
+  public String getItem (int index)
+  {
+    return (String) items.get (index);
+  }
+
+  /** Returns number of items in Choice.  */
+  public int getItemCount ()
+  {
+    return items.size ();
+  }
+
+  /** Returns index of selected item; -1 if no item is selected.  */
+  public int getSelectedIndex ()
+  {
+    return selected;
+  }
+
+  /** Returns currently selected item; null if no item is selected.  */
+  public synchronized String getSelectedItem ()
+  {
+    return selected == -1 ? null : (String) items.get (selected);
+  }
+
+  /** Returns the currently selected item.  */
+  public synchronized Object[] getSelectedObjects ()
+  {
+    // The JCL says this can return null but that breaks the contract
+    // for ItemSelectable.
+    Object[] r;
+    if (selected != -1)
+      {
+	r = new Object[1];
+	r[0] = items.get (selected);
+      }
+    else
+      r = new Object[0];
+    return r;
+  }
+
+  /** Inserts an item into this Choice.  Existing items are shifted
+   * upwards.  If the new item is the only item, then it is selected.
+   * If the currently selected item is shifted, then the first item is
+   * selected.  If the currently selected item is not shifted, then it
+   * remains selected.
+   * @param item The new item
+   * @param index The position at which to insert it.
+   */
+  public synchronized void insert (String item, int index)
+  {
+    if (index > items.size ())
+      index = items.size ();
+    items.add (index, item);
+
+    if (peer != null)
+      {
+	ChoicePeer cp = (ChoicePeer) peer;
+	cp.add (item, index);
+      }
+
+    if (items.size () == 1 || selected >= index)
+      select (0);
+  }
+
+  /** Generates a String representation of this Choice's state.  */
+  protected String paramString ()
+  {
+    return ("Choice["
+	    + "selected=" + selected
+	    + "]");
+  }
+
+  /** Process an event for this Choice
+   * @param event The event the process.
+   */
+  protected void processEvent (AWTEvent event)
+  {
+    if (event instanceof ItemEvent)
+      processItemEvent ((ItemEvent) event);
+    else
+      super.processEvent (event);
+  }
+
+  /** Process an item event for this Choice.
+   * @param event The ItemEvent to process
+   */
+  protected void processItemEvent (ItemEvent event)
+  {
+    if (listeners != null)
+      listeners.itemStateChanged (event);
+  }
+
+  /** Remove an item from this Choice.  If several matches exist, the
+   * first one is removed.  If the removed item is selected, the the
+   * first item is selected.
+   * @param item The item string.
+   */
+  public synchronized void remove (String item)
+  {
+    int size = items.size ();
+    for (int i = 0; i < size; ++i)
+      {
+	if (item.equals (items.get (i)))
+	  {
+	    remove (i);
+	    break;
+	  }
+      }
+    throw new IllegalArgumentException ("item \"" + item + "\" not in Choice");
+  }
+
+  /** Remove an item from this Choice.  If the removed item is
+   * selected, the the first item is selected.
+   * @param index Index of the item to remove
+   */
+  public synchronized void remove (int index)
+  {
+    items.remove (index);
+
+    if (peer != null)
+      {
+	ChoicePeer cp = (ChoicePeer) peer;
+	cp.remove (index);
+      }
+
+    if (index == selected)
+      select (0);
+    else if (selected > index)
+      --selected;
+  }
+
+  /** Remove all items from this choice.  */
+  public synchronized void removeAll ()
+  {
+    int oldsize = items.size ();
+    items.clear ();
+    selected = -1;
+
+    if (peer != null)
+      {
+	ChoicePeer cp = (ChoicePeer) peer;
+	for (int i = 0; i < oldsize; ++i)
+	  {
+	    // Always remove item 0.
+	    cp.remove (0);
+	  }
+      }
+  }
+
+  /** Remove an item listener.
+   * @param listener Item listener to remove.
+   */
+  public synchronized void removeItemListener (ItemListener listener)
+  {
+    listeners = AWTEventMulticaster.remove (listeners, listener);
+  }
+
+  /** Select an item in this Choice.
+   * @param item Name of the item to select.
+   */
+  public synchronized void select (String item)
+  {
+    int size = items.size ();
+    for (int i = 0; i < size; ++i)
+      {
+	if (item.equals (items.get (i)))
+	  {
+	    select (i);
+	    break;
+	  }
+      }
+  }
+
+  /** Select an item in this choice.
+   * @param index Index of item to select.
+   */
+  public synchronized void select (int index)
+  {
+    if (index < 0 || index > items.size ())
+      throw new IllegalArgumentException ("index out of range");
+    selected = index;
+    if (peer != null)
+      {
+	ChoicePeer cp = (ChoicePeer) peer;
+	cp.select (index);
+      }
+  }
+
+  private ItemListener listeners;
+
+  // List of items.
+  ArrayList items;
+  // Index of selected item.
+  int selected;
 }
Index: java/awt/Color.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/Color.java,v
retrieving revision 1.5
diff -u -r1.5 Color.java
--- Color.java	2000/08/16 18:03:47	1.5
+++ Color.java	2000/12/26 00:20:07
@@ -38,7 +38,7 @@
   // The internal sRGB representation.
   // Alpha is bits 24-31, if hasalpha is true.
   // Red is bits 16-23; Green is bits 8-15; Blue is bits 0-7.
-  private int rgba = 0xFFFFFFFF;
+  int rgba = 0xFFFFFFFF;
 
   public Color(int rgb)
   {
Index: java/awt/Component.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/Component.java,v
retrieving revision 1.14
diff -u -r1.14 Component.java
--- Component.java	2000/12/18 22:17:25	1.14
+++ Component.java	2000/12/26 00:20:07
@@ -90,6 +90,8 @@
   transient HierarchyListener hierarchyListener;
   transient HierarchyBoundsListener hierarchyBoundsListener;
 
+  transient ComponentOrientation orientation = ComponentOrientation.UNKNOWN;
+
   protected Component()
   {
   }
@@ -1569,15 +1571,14 @@
   
   public void setComponentOrientation(ComponentOrientation o)
   {
-    // FIXME
+    orientation = o;
   }
-  
+
   public ComponentOrientation getComponentOrientation()
   {
-    // FIXME
-    return null;
+    return orientation;
   }
-  
+
   /*
   public AccessibleContext getAccessibleContext()
   {
Index: java/awt/Container.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/Container.java,v
retrieving revision 1.9
diff -u -r1.9 Container.java
--- Container.java	2000/08/16 18:03:47	1.9
+++ Container.java	2000/12/26 00:20:07
@@ -18,7 +18,7 @@
 
 /* A somewhat incomplete class. */
 
-public abstract class Container extends Component
+public class Container extends Component
 {
   /* Serialized fields from the serialization spec. */
   int ncomponents;
Index: java/awt/Cursor.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/Cursor.java,v
retrieving revision 1.1
diff -u -r1.1 Cursor.java
--- Cursor.java	2000/07/12 03:32:06	1.1
+++ Cursor.java	2000/12/26 00:20:08
@@ -10,7 +10,7 @@
 
 /* A somewhat incomplete placeholder. */
 
-public class Cursor
+public class Cursor implements java.io.Serializable
 {
   public static final int DEFAULT_CURSOR   = 0,
 			  CROSSHAIR_CURSOR = 1,
Index: java/awt/Dimension.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/Dimension.java,v
retrieving revision 1.3
diff -u -r1.3 Dimension.java
--- Dimension.java	2000/03/07 19:55:25	1.3
+++ Dimension.java	2000/12/26 00:20:08
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999  Free Software Foundation
+/* Copyright (C) 1999, 2000  Free Software Foundation
 
    This file is part of libjava.
 
@@ -20,6 +20,7 @@
  */
 
 public class Dimension extends java.awt.geom.Dimension2D
+  implements java.io.Serializable
 {
   public int height;
   public int width;
Index: java/awt/Event.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/Event.java,v
retrieving revision 1.5
diff -u -r1.5 Event.java
--- Event.java	2000/07/12 03:32:06	1.5
+++ Event.java	2000/12/26 00:20:08
@@ -14,7 +14,7 @@
  * Status:  Believed complete and correct.
  */
 
-public class Event
+public class Event implements java.io.Serializable
 {
   public static final int SHIFT_MASK = 1,
 			  CTRL_MASK = 2,
@@ -82,9 +82,10 @@
 			  WINDOW_ICONIFY = 203,
 			  WINDOW_MOVED = 205;
 
-  public Event evt;
   public Object arg;
   public int clickCount;
+  boolean consumed;		// Required by serialization spec.
+  public Event evt;
   public int id;
   public int key; 
   public int modifiers;
Index: java/awt/FlowLayout.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/FlowLayout.java,v
retrieving revision 1.1
diff -u -r1.1 FlowLayout.java
--- FlowLayout.java	2000/12/03 08:28:35	1.1
+++ FlowLayout.java	2000/12/26 00:20:08
@@ -27,6 +27,13 @@
   /** Constant that specifies right alignment.  */
   public static final int RIGHT = 2;
 
+  /** Constant that specifies alignment to leading edge of container's
+   * orientation.  */
+  public static final int LEADING = 3;
+  /** Constant that specifies alignment to trailing edge of container's
+   * orientation.  */
+  public static final int TRAILING = 4;
+
   /** Add a new component to the layout.  This particular implementation
    * does nothing.
    */
@@ -82,7 +89,8 @@
       throw new IllegalArgumentException ("horizontal gap must be nonnegative");
     if (vgap < 0)
       throw new IllegalArgumentException ("vertical gap must be nonnegative");
-    if (align != LEFT && align != RIGHT && align != CENTER)
+    if (align != LEFT && align != RIGHT && align != CENTER
+	&& align != LEADING && align != TRAILING)
       throw new IllegalArgumentException ("invalid align: " + align);
     this.align = align;
     this.hgap = hgap;
@@ -101,6 +109,9 @@
     Dimension d = parent.getSize ();
     Insets ins = parent.getInsets ();
 
+    ComponentOrientation orient = parent.getComponentOrientation ();
+    boolean left_to_right = orient.isLeftToRight ();
+
     int y = ins.top + vgap;
     int i = 0;
     while (i < num)
@@ -128,12 +139,20 @@
 
 	// Set the location of each component for this row.
 	int x;
-	if (align == LEFT)
+
+	int myalign = align;
+	if (align == LEADING)
+	  myalign = left_to_right ? LEFT : RIGHT;
+	else if (align == TRAILING)
+	  myalign = left_to_right ? RIGHT : LEFT;
+
+	if (myalign == LEFT)
 	  x = ins.left + hgap;
-	else if (align == CENTER)
+	else if (myalign == CENTER)
 	  x = (d.width - new_w) / 2;
 	else
 	  x = d.width - new_w;
+
 	for (int k = i; i < j; ++k)
 	  {
 	    // FIXME: this is very inefficient.
@@ -178,7 +197,8 @@
    */
   public void setAlignment (int align)
   {
-    if (align != LEFT && align != RIGHT && align != CENTER)
+    if (align != LEFT && align != RIGHT && align != CENTER
+	&& align != LEADING && align != TRAILING)
       throw new IllegalArgumentException ("invalid align: " + align);
     this.align = align;
   }
Index: java/awt/GridLayout.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/GridLayout.java,v
retrieving revision 1.1
diff -u -r1.1 GridLayout.java
--- GridLayout.java	2000/12/03 07:16:20	1.1
+++ GridLayout.java	2000/12/26 00:20:09
@@ -224,6 +224,15 @@
     this.vgap = vgap;
   }
 
+  /** Return String description of this object.  */
+  public String toString ()
+  {
+    return ("[" + getClass ().getName ()
+	    + ",hgap=" + hgap + ",vgap=" + vgap
+	    + ",rows=" + rows + ",cols=" + cols
+	    + "]");
+  }
+
   // This method is used to compute the various sizes.
   private Dimension getSize (Container parent, boolean is_min)
   {
Index: java/awt/ItemSelectable.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/ItemSelectable.java,v
retrieving revision 1.1
diff -u -r1.1 ItemSelectable.java
--- ItemSelectable.java	2000/04/09 04:13:27	1.1
+++ ItemSelectable.java	2000/12/26 00:20:09
@@ -9,16 +9,28 @@
 package java.awt;
 import java.awt.event.*;
 
-/**
+/** This interface is implemented by components that support the
+ * select of items.  For instance, Checkbox implements this
+ * interface.
  * @author Tom Tromey <tromey@cygnus.com>
  * @date April 8, 2000
  */
-
-/* Status: Believed complete and correct to JDK 1.2.  */
-
 public interface ItemSelectable
 {
+  /** This method adds a listener to receive item events fired by the
+   * component.
+   * @param l The item listener to add.
+   */
   public void addItemListener (ItemListener l);
+
+  /** This method returns the items in this component which are
+   * currently selected.
+   * @returns A non-null array containing the items.
+   */
   public Object[] getSelectedObjects ();
+
+  /** This method removes an item listener.
+   * @param l The item listener to remove.
+   */
   public void removeItemListener (ItemListener l);
 }
Index: java/awt/MenuContainer.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/MenuContainer.java,v
retrieving revision 1.3
diff -u -r1.3 MenuContainer.java
--- MenuContainer.java	2000/03/07 19:55:25	1.3
+++ MenuContainer.java	2000/12/26 00:20:09
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999  Free Software Foundation
+/* Copyright (C) 1999, 2000  Free Software Foundation
 
    This file is part of libjava.
 
@@ -13,12 +13,12 @@
  * Status:  Believed complete and correct.
  */
 
-public  interface MenuContainer
+public interface MenuContainer
 {
   public Font getFont();
 
   /**
-   * @deprected
+   * @deprecated
    */
   public boolean postEvent(Event evt);
 
Index: java/awt/MenuItem.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/MenuItem.java,v
retrieving revision 1.5
diff -u -r1.5 MenuItem.java
--- MenuItem.java	2000/08/03 12:09:38	1.5
+++ MenuItem.java	2000/12/26 00:20:09
@@ -9,9 +9,8 @@
 package java.awt;
 import java.awt.event.*;
 import java.util.EventListener;
+import java.awt.peer.MenuItemPeer;
 
-/* A very incomplete placeholder. */
-
 public class MenuItem extends MenuComponent
 {
   // Fields from the serialization spec. Decalare others "transient".
@@ -34,6 +33,12 @@
     this.label = label;
   }
 
+  public MenuItem (String label, MenuShortcut shortcut)
+  {
+    this.label = label;
+    this.shortcut = shortcut;
+  }
+
   public String getLabel()
   {
     return label;
@@ -42,6 +47,11 @@
   public synchronized void setLabel(String label)
   {
     this.label = label;
+    if (peer != null)
+      {
+	MenuItemPeer mp = (MenuItemPeer) peer;
+	mp.setLabel (label);
+      }
   }
 
   public boolean isEnabled()
@@ -51,7 +61,18 @@
 
   public synchronized void setEnabled(boolean b)
   {
-    this.enabled = b;
+    // The JCL says this method is ignored if the enabled state does
+    // not change.  I take that to mean that the peer is not notified
+    // in this case.
+    if (this.enabled != b)
+      {
+	this.enabled = b;
+	if (peer != null)
+	  {
+	    MenuItemPeer mp = (MenuItemPeer) peer;
+	    mp.setEnabled (b);
+	  }
+      }
   }
 
   /** @deprecated Use setEnabled() instead. */
@@ -118,6 +139,16 @@
   public synchronized void removeActionListener(ActionListener l)
   {
     actionListener = AWTEventMulticaster.remove(actionListener, l);
+  }
+
+  public void addNotify ()
+  {
+    if (peer != null)
+      {
+	// This choice of toolkit seems unsatisfying, but I'm not sure
+	// what else to do.
+	peer = Toolkit.getDefaultToolkit ().createMenuItem (this);
+      }
   }
 
   /** Returns all registered EventListers of the given listenerType. 
Index: java/awt/SystemColor.java
===================================================================
RCS file: SystemColor.java
diff -N SystemColor.java
--- /dev/null	Tue May  5 13:32:27 1998
+++ SystemColor.java	Mon Dec 25 16:20:09 2000
@@ -0,0 +1,158 @@
+/* Copyright (C) 2000  Free Software Foundation
+
+   This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
+details.  */
+
+package java.awt;
+
+/** This class contains most of the colors used by the native
+ * windowing sytem to draw native components.
+ * @author Tom Tromey <tromey@redhat.com>
+ * @date December 25, 2000
+ */
+public final class SystemColor extends Color implements java.io.Serializable
+{
+  /** The background color for the title bar of an active window.  */
+  public static final SystemColor activeCaption
+      = new SystemColor (ACTIVE_CAPTION);
+  /** The border color of an active window.  */
+  public static final SystemColor activeCaptionBorder
+      = new SystemColor (ACTIVE_CAPTION_BORDER);
+  /** The color of text in the title bar of an active window.  */
+  public static final SystemColor activeCaptionText
+      = new SystemColor (ACTIVE_CAPTION_TEXT);
+  /** The background color.  */
+  public static final SystemColor control = new SystemColor (CONTROL);
+  /** The darkest color of an outline.  */
+  public static final SystemColor controlDkShadow
+      = new SystemColor (CONTROL_DK_SHADOW);
+  /** The second brightest color of an outline.  */
+  public static final SystemColor controlHighlight
+      = new SystemColor (CONTROL_HIGHLIGHT);
+  /** The brightest color of an outline.  */
+  public static final SystemColor controlLtHighlight
+      = new SystemColor (CONTROL_LT_HIGHLIGHT);
+  /** The second darkest color of an outline.  */
+  public static final SystemColor controlShadow
+      = new SystemColor (CONTROL_SHADOW);
+  /** The color of text in a label.  */
+  public static final SystemColor controlText = new SystemColor (CONTROL_TEXT);
+  /** The background color of the desktop.  */
+  public static final SystemColor desktop = new SystemColor (DESKTOP);
+  /** The background color for the title bar of an inactive window.  */
+  public static final SystemColor inactiveCaption
+      = new SystemColor (INACTIVE_CAPTION);
+  /** The border color of an inactive window.  */
+  public static final SystemColor inactiveCaptionBorder
+      = new SystemColor (INACTIVE_CAPTION_BORDER);
+  /** The color of text in the title ar of an inactive window.  */
+  public static final SystemColor inactiveCaptionText
+      = new SystemColor (INACTIVE_CAPTION_TEXT);
+  /** The background color of tooltips. */
+  public static final SystemColor info = new SystemColor (INFO);
+  /** The color of text in tooltips.  */
+  public static final SystemColor infoText = new SystemColor (INFO_TEXT);
+  /** The background color of a menu.  */
+  public static final SystemColor menu = new SystemColor (MENU);
+  /** The color of text in a menu.  */
+  public static final SystemColor menuText = new SystemColor (MENU_TEXT);
+  /** The background color of a scrollbar.  */
+  public static final SystemColor scrollbar = new SystemColor (SCROLLBAR);
+  /** The background color of text components.  */
+  public static final SystemColor text = new SystemColor (TEXT);
+  /** The background color of highlighted text.  */
+  public static final SystemColor textHighlight
+      = new SystemColor (TEXT_HIGHLIGHT);
+  /** The color of highlighted text.  */
+  public static final SystemColor textHighlightText
+      = new SystemColor (TEXT_HIGHLIGHT_TEXT);
+  /** The color of inactive text.  */
+  public static final SystemColor textInactiveText
+      = new SystemColor (TEXT_INACTIVE_TEXT);
+  /** The color of text in text components.  */
+  public static final SystemColor textText = new SystemColor (TEXT_TEXT);
+  /** The background color of a window.  */
+  public static final SystemColor window = new SystemColor (WINDOW);
+  /** The border color of a window.  */
+  public static final SystemColor windowBorder
+      = new SystemColor (WINDOW_BORDER);
+  /** The color of text in a window.  */
+  public static final SystemColor windowText = new SystemColor (WINDOW_TEXT);
+
+  public static final int DESKTOP = 0;
+  public static final int ACTIVE_CAPTION = 1;
+  public static final int ACTIVE_CAPTION_TEXT = 2;
+  public static final int ACTIVE_CAPTION_BORDER = 3;
+  public static final int INACTIVE_CAPTION = 4;
+  public static final int INACTIVE_CAPTION_TEXT = 5;
+  public static final int INACTIVE_CAPTION_BORDER = 6;
+  public static final int WINDOW = 7;
+  public static final int WINDOW_BORDER = 8;
+  public static final int WINDOW_TEXT = 9;
+  public static final int MENU = 10;
+  public static final int MENU_TEXT = 11;
+  public static final int TEXT = 12;
+  public static final int TEXT_TEXT = 13;
+  public static final int TEXT_HIGHLIGHT = 14;
+  public static final int TEXT_HIGHLIGHT_TEXT = 15;
+  public static final int TEXT_INACTIVE_TEXT = 16;
+  public static final int CONTROL = 17;
+  public static final int CONTROL_TEXT = 18;
+  public static final int CONTROL_HIGHLIGHT = 19;
+  public static final int CONTROL_LT_HIGHLIGHT = 20;
+  public static final int CONTROL_SHADOW = 21;
+  public static final int CONTROL_DK_SHADOW = 22;
+  public static final int SCROLLBAR = 23;
+  public static final int INFO = 24;
+  public static final int INFO_TEXT = 25;
+
+  public static final int NUM_COLORS = 26;
+
+  private static final int rgbs[] =
+  {
+    0x005c5c,
+    0x000080,
+    0xffffff,
+    0xc0c0c0,
+    0x808080,
+    0xc0c0c0,
+    0xc0c0c0,
+    0xffffff,
+    0x000000,
+    0x000000,
+    0xc0c0c0,
+    0x000000,
+    0xc0c0c0,
+    0x000000,
+    0x000080,
+    0xffffff,
+    0x808080,
+    0xc0c0c0,
+    0x000000,
+    0xffffff,
+    0xe0e0e0,
+    0x808080,
+    0x000000,
+    0xe0e0e0,
+    0xe0e000,
+    0x000000
+  };
+
+  public int getRGB ()
+  {
+    return rgbs[rgba];
+  }
+
+  public String toString ()
+  {
+    return "[" + getClass ().getName () + " " + rgba + "]";
+  }
+
+  private SystemColor (int index)
+  {
+    super (index, true);
+  }
+}
Index: java/awt/event/ContainerEvent.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/event/ContainerEvent.java,v
retrieving revision 1.2
diff -u -r1.2 ContainerEvent.java
--- ContainerEvent.java	2000/07/12 03:32:06	1.2
+++ ContainerEvent.java	2000/12/26 00:20:09
@@ -35,7 +35,7 @@
     return child;
   }
 
-  public Component getComponent ()
+  public Component getContainer ()
   {
     return (Component) source;
   }
Index: java/awt/event/InputEvent.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/awt/event/InputEvent.java,v
retrieving revision 1.4
diff -u -r1.4 InputEvent.java
--- InputEvent.java	2000/04/09 04:13:27	1.4
+++ InputEvent.java	2000/12/26 00:20:09
@@ -47,6 +47,11 @@
     return (modifiers & ALT_MASK) != 0;
   }
 
+  public boolean isAltGraphDown ()
+  {
+    return (modifiers & ALT_GRAPH_MASK) != 0;
+  }
+
   public long getWhen ()
   {
     return when;


More information about the Java-patches mailing list