Patch: AWT jumbo patch

Tom Tromey tromey@redhat.com
Sat Apr 21 20:05:00 GMT 2001


This is a jumbo AWT patch.  It fixes a bunch of ABI bugs, a few
semantic bugs, and adds java.awt.geom.Line2D and java.awt.FileDialog.

I'm checking this in on the trunk.

2001-04-21  Tom Tromey  <tromey@redhat.com>

	* Makefile.in: Rebuilt.
	* Makefile.am (awt_java_source_files): Added Line2D.java.
	* java/awt/geom/Line2D.java: Wrote.

	* java/awt/Menu.java (addNotify): Wrote.

	* java/awt/PopupMenu.java (addNotify): Implemented.
	(show): Likewise.

	* java/awt/Scrollbar.java (addNotify): Call super.addNotify.
	* java/awt/List.java (addNotify): Call super.addNotify.
	* java/awt/Label.java (addNotify): Call super.addNotify.
	* java/awt/FileDialog.java (addNotify): Call super.addNotify.
	* java/awt/Dialog.java (addNotify): Call super.addNotify.
	* java/awt/Choice.java (addNotify): Call super.addNotify.
	* java/awt/CheckboxMenuItem.java (addNotify): Call super.addNotify.
	* java/awt/Checkbox.java (addNotify): Call super.addNotify.

	* java/awt/List.java (replaceItem): Notify peer.

	* java/awt/geom/Rectangle2D.java
	(Float.setRect(float,float,float,float)): New method.

	* java/awt/event/ContainerEvent.java (getContainer): Now returns
	Container.

	* java/awt/RenderingHints.java (Key): Class now public.

	* java/awt/Rectangle.java (Rectangle): Now implements
	Serializable.
	(getPathIterator): Removed.

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

	* java/awt/FileDialog.java: Wrote.

	* java/awt/EventQueue.java (isDispatchThread): Now public.
	(invokeLater): Likewise.

	* java/awt/Component.java (setCursor): Update peer.
	(getFontMetrics): Use peer.

	* java/awt/ComponentOrientation.java (ComponentOrientation): Class
	now final.

Tom

Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.138
diff -u -r1.138 Makefile.am
--- Makefile.am	2001/04/12 09:32:50	1.138
+++ Makefile.am	2001/04/22 02:58:06
@@ -694,6 +694,7 @@
 java/awt/geom/Dimension2D.java \
 java/awt/geom/Ellipse2D.java \
 java/awt/geom/IllegalPathStateException.java \
+java/awt/geom/Line2D.java \
 java/awt/geom/NoninvertibleTransformException.java \
 java/awt/geom/PathIterator.java	\
 java/awt/geom/Point2D.java \
Index: java/awt/Checkbox.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Checkbox.java,v
retrieving revision 1.2
diff -u -r1.2 Checkbox.java
--- Checkbox.java	2000/12/26 00:25:12	1.2
+++ Checkbox.java	2001/04/22 02:58:06
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000  Free Software Foundation
+/* Copyright (C) 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -63,6 +63,7 @@
   {
     if (peer == null)
       peer = getToolkit ().createCheckbox (this);
+    super.addNotify ();
   }
 
   /** Returns the current CheckboxGroup associated with this
Index: java/awt/CheckboxMenuItem.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/CheckboxMenuItem.java,v
retrieving revision 1.2
diff -u -r1.2 CheckboxMenuItem.java
--- CheckboxMenuItem.java	2000/12/26 07:18:16	1.2
+++ CheckboxMenuItem.java	2001/04/22 02:58:06
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000  Free Software Foundation
+/* Copyright (C) 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -55,6 +55,7 @@
 	// what else to do.
 	peer = Toolkit.getDefaultToolkit ().createCheckboxMenuItem (this);
       }
+    super.addNotify ();
   }
 
   /** Returns this checkbox's label if this checkbox is selected.  */
Index: java/awt/Choice.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Choice.java,v
retrieving revision 1.2
diff -u -r1.2 Choice.java
--- Choice.java	2000/12/26 00:25:12	1.2
+++ Choice.java	2001/04/22 02:58:06
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000  Free Software Foundation
+/* Copyright (C) 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -66,6 +66,7 @@
   {
     if (peer == null)
       peer = getToolkit ().createChoice (this);
+    super.addNotify ();
   }
 
   /** Returns number of items.
Index: java/awt/Component.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Component.java,v
retrieving revision 1.16
diff -u -r1.16 Component.java
--- Component.java	2001/01/03 00:07:13	1.16
+++ Component.java	2001/04/22 02:58:10
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999, 2000  Free Software Foundation
+/* Copyright (C) 1999, 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -649,14 +649,18 @@
   
   public FontMetrics getFontMetrics(Font font)
   {
-    return getToolkit().getFontMetrics(font);
+    if (peer == null)
+      return getToolkit().getFontMetrics(font);
+    return peer.getFontMetrics (font);
   }
-  
+
   public void setCursor(Cursor cursor)
   {
     this.cursor = cursor;
+    if (peer != null)
+      peer.setCursor (cursor);
   }
-  
+
   public Cursor getCursor()
   {
     return this.cursor;
@@ -705,7 +709,7 @@
 	  parent.repaint(tm, x+getX(), y+getY(), width, height);
 	return;
       }
-    
+
     if (peer != null)
       peer.repaint(tm, x, y, width, height);
   }
Index: java/awt/ComponentOrientation.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/ComponentOrientation.java,v
retrieving revision 1.2
diff -u -r1.2 ComponentOrientation.java
--- ComponentOrientation.java	2000/08/09 13:01:43	1.2
+++ ComponentOrientation.java	2001/04/22 02:58:10
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000  Free Software Foundation
+/* Copyright (C) 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -13,7 +13,7 @@
 import java.util.Locale;
 import java.util.ResourceBundle;
 
-public class ComponentOrientation implements java.io.Serializable
+public final class ComponentOrientation implements java.io.Serializable
 {
   // Here is a wild guess.
   private static int HORIZONTAL_ID    = 1 << 0,
@@ -29,7 +29,7 @@
   // FIXME: This field is from the serialization spec, but what are the 
   // correct values?
   int orientation;
-  
+
   ComponentOrientation(int orientation)
   {
     this.orientation = orientation;
@@ -54,7 +54,7 @@
   public static ComponentOrientation getOrientation(ResourceBundle bdl)
   {
     ComponentOrientation r;
-    
+
     try
     {
       Object obj = bdl.getObject("Orientation");
Index: java/awt/Dialog.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Dialog.java,v
retrieving revision 1.2
diff -u -r1.2 Dialog.java
--- Dialog.java	2001/04/21 02:48:35	1.2
+++ Dialog.java	2001/04/22 02:58:10
@@ -63,6 +63,7 @@
   {
     if (peer == null)
       peer = getToolkit ().createDialog (this);
+    super.addNotify ();
   }
 
   public boolean isModal ()
Index: java/awt/EventQueue.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/EventQueue.java,v
retrieving revision 1.3
diff -u -r1.3 EventQueue.java
--- EventQueue.java	2000/08/16 18:03:47	1.3
+++ EventQueue.java	2001/04/22 02:58:10
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000  Free Software Foundation
+/* Copyright (C) 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -166,7 +166,7 @@
   }
   
   /** @since JDK1.2 */
-  static void invokeLater(Runnable runnable)
+  public static void invokeLater(Runnable runnable)
   {
     EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); 
 
@@ -176,7 +176,7 @@
     eq.postEvent(ie);
   }
   
-  static boolean isDispatchThread()
+  public static boolean isDispatchThread()
   {
     EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); 
     return (Thread.currentThread() == eq.dispatchThread);
Index: java/awt/FileDialog.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/FileDialog.java,v
retrieving revision 1.1
diff -u -r1.1 FileDialog.java
--- FileDialog.java	2000/08/03 12:09:38	1.1
+++ FileDialog.java	2001/04/22 02:58:10
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000  Free Software Foundation
+/* Copyright (C) 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -8,13 +8,112 @@
 
 package java.awt;
 
-/* A very incomplete placeholder. */
+import java.awt.peer.FileDialogPeer;
+import java.io.FilenameFilter;
 
+/**
+ * @author Tom Tromey <tromey@redhat.com>
+ * @date April 20, 2001
+ */
+
 public class FileDialog extends Dialog
 {
-  public FileDialog (Frame owner)
+  public static int LOAD = 0;
+  public static int SAVE = 1;
+
+  public FileDialog (Frame parent)
+  {
+    this (parent, "", LOAD);
+  }
+
+  public FileDialog (Frame parent, String title)
+  {
+    this (parent, title, LOAD);
+  }
+
+  public FileDialog (Frame parent, String title, int mode)
+  {
+    super (parent, title, true);
+    if (mode != LOAD && mode != SAVE)
+      throw new IllegalArgumentException ("unknown mode: " + mode);
+    this.mode = mode;
+  }
+
+  public void addNotify ()
+  {
+    if (peer == null)
+      peer = getToolkit ().createFileDialog (this);
+    super.addNotify ();
+  }
+
+  public String getDirectory ()
+  {
+    return dir;
+  }
+
+  public String getFile ()
+  {
+    return file;
+  }
+
+  public FilenameFilter getFilenameFilter ()
   {
-    super(owner);
-    // FIXME
+    return filter;
   }
+
+  public int getMode ()
+  {
+    return mode;
+  }
+
+  protected String paramString ()
+  {
+    return ("FileDialog[mode=" + mode
+	    + ",dir=" + dir
+	    + ",file=" + file + "]");
+  }
+
+  public void setDirectory (String dir)
+  {
+    this.dir = dir;
+    if (peer != null)
+      {
+	FileDialogPeer f = (FileDialogPeer) peer;
+	f.setDirectory (dir);
+      }
+  }
+
+  public void setFile (String file)
+  {
+    this.file = file;
+    if (peer != null)
+      {
+	FileDialogPeer f = (FileDialogPeer) peer;
+	f.setFile (file);
+      }
+  }
+
+  public void setFilenameFilter (FilenameFilter filter)
+  {
+    this.filter = filter;
+    if (peer != null)
+      {
+	FileDialogPeer f = (FileDialogPeer) peer;
+	f.setFilenameFilter (filter);
+      }
+  }
+
+  public void setMode (int mode)
+  {
+    if (mode != LOAD && mode != SAVE)
+      throw new IllegalArgumentException ("unknown mode: " + mode);
+    this.mode = mode;
+    // FIXME: update peer?
+  }
+
+  // Names here from serialization spec.
+  private int mode;
+  private String dir;
+  private String file;
+  private FilenameFilter filter;
 }
Index: java/awt/GraphicsConfiguration.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/GraphicsConfiguration.java,v
retrieving revision 1.2
diff -u -r1.2 GraphicsConfiguration.java
--- GraphicsConfiguration.java	2000/08/16 18:03:47	1.2
+++ GraphicsConfiguration.java	2001/04/22 02:58:10
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000  Free Software Foundation
+/* Copyright (C) 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -17,6 +17,12 @@
 
 public abstract class GraphicsConfiguration
 {
+  // Can't instantiate directly.  Having a protected constructor seems
+  // redundant, but that is what the docs specify.
+  protected GraphicsConfiguration ()
+  {
+  }
+
   /*
   public abstract GraphicsDevice getDevice();
   */
Index: java/awt/Label.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Label.java,v
retrieving revision 1.4
diff -u -r1.4 Label.java
--- Label.java	2000/12/18 22:17:25	1.4
+++ Label.java	2001/04/22 02:58:10
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000  Free Software Foundation
+/* Copyright (C) 2000, 2001  Free Software Foundation
 
    This file is part of libjava.
 
@@ -43,6 +43,7 @@
   {
     if (peer == null)
       peer = getToolkit ().createLabel (this);
+    super.addNotify ();
   }
 
   public int getAlignment ()
Index: java/awt/List.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/List.java,v
retrieving revision 1.2
diff -u -r1.2 List.java
--- List.java	2001/04/21 02:48:35	1.2
+++ List.java	2001/04/22 02:58:10
@@ -52,6 +52,7 @@
   {
     if (peer != null)
       peer = getToolkit ().createList (this);
+    super.addNotify ();
   }
 
   public int getItemCount ()
@@ -107,7 +108,12 @@
   public void replaceItem (String item, int index)
   {
     items.setElementAt (item, index);
-    // FIXME: notify peer
+    if (peer != null)
+      {
+	ListPeer l = (ListPeer) peer;
+	l.delItems (index, index);
+	l.add (item, index);
+      }
   }
 
   public void removeAll ()
Index: java/awt/Menu.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Menu.java,v
retrieving revision 1.6
diff -u -r1.6 Menu.java
--- Menu.java	2000/07/12 03:32:06	1.6
+++ Menu.java	2001/04/22 02:58:10
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999, 2000  Free Software Foundation
+/* Copyright (C) 1999, 2000, 2001  Free Software Foundation
 
    This file is part of libjava.
 
@@ -40,7 +40,13 @@
 
   public void addNotify()
   {
-    // FIXME
+    if (peer != null)
+      {
+	// This choice of toolkit seems unsatisfying, but I'm not sure
+	// what else to do.
+	peer = Toolkit.getDefaultToolkit ().createMenu (this);
+      }
+    super.addNotify ();
   }
 
   public void removeNotify()
Index: java/awt/MenuBar.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/MenuBar.java,v
retrieving revision 1.6
diff -u -r1.6 MenuBar.java
--- MenuBar.java	2000/12/26 07:18:16	1.6
+++ MenuBar.java	2001/04/22 02:58:10
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999, 2000  Free Software Foundation
+/* Copyright (C) 1999, 2000, 2001  Free Software Foundation
 
    This file is part of libjava.
 
Index: java/awt/MenuItem.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/MenuItem.java,v
retrieving revision 1.6
diff -u -r1.6 MenuItem.java
--- MenuItem.java	2000/12/26 00:25:12	1.6
+++ MenuItem.java	2001/04/22 02:58:10
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999, 2000  Free Software Foundation
+/* Copyright (C) 1999, 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
Index: java/awt/PopupMenu.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/PopupMenu.java,v
retrieving revision 1.1
diff -u -r1.1 PopupMenu.java
--- PopupMenu.java	2000/07/12 03:32:06	1.1
+++ PopupMenu.java	2001/04/22 02:58:10
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000  Free Software Foundation
+/* Copyright (C) 2000, 2001  Free Software Foundation
 
    This file is part of libjava.
 
@@ -8,6 +8,8 @@
 
 package java.awt;
 
+import java.awt.peer.PopupMenuPeer;
+
 /* Status: Incomplete. */
 
 public class PopupMenu extends Menu
@@ -24,14 +26,31 @@
 
   public void addNotify()
   {
-    // FIXME
+    if (peer != null)
+      {
+	// This choice of toolkit seems unsatisfying, but I'm not sure
+	// what else to do.
+	peer = Toolkit.getDefaultToolkit ().createPopupMenu (this);
+      }
+    super.addNotify ();
   }
 
   public void show(Component origin, int x, int y)
   {
-    // FIXME
+    if (! origin.isShowing ()
+	// FIXME: or ! parent is showing -- but how?
+	)
+      {
+	// This is an invalid call which we choose to ignore.
+	return;
+      }
+	
+    addNotify ();		// FIXME?
+    Event e = new Event (origin, 0, 0, x, y, 0, 0);
+    PopupMenuPeer p = (PopupMenuPeer) peer;
+    p.show (e);
   }
-  
+
   // Accessibility API not yet implemented.
   // public AccessibleContext getAccessibleContext()
 }
Index: java/awt/Rectangle.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Rectangle.java,v
retrieving revision 1.6
diff -u -r1.6 Rectangle.java
--- Rectangle.java	2000/08/16 18:03:47	1.6
+++ Rectangle.java	2001/04/22 02:58:10
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999, 2000  Free Software Foundation
+/* Copyright (C) 1999, 2000, 2001  Free Software Foundation
 
    This file is part of libjava.
 
@@ -7,11 +7,14 @@
 details.  */
 
 package java.awt;
+
 import java.awt.geom.*;
+import java.io.Serializable;
 
 /* Status:  Mostly complete. Some of the Java2D stuff is commented out. */
 
-public class Rectangle extends Rectangle2D implements Cloneable, Shape
+public class Rectangle extends Rectangle2D
+  implements Cloneable, Shape, Serializable
 {
   public int x;
   public int y;
@@ -149,12 +152,6 @@
   public Point getLocation()
   {
     return new Point(x,y);
-  }
-
-  public PathIterator getPathIterator (AffineTransform t)
-  {
-    // FIXME
-    return null;
   }
 
   public Dimension getSize()
Index: java/awt/RenderingHints.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/RenderingHints.java,v
retrieving revision 1.2
diff -u -r1.2 RenderingHints.java
--- RenderingHints.java	2000/08/29 03:23:56	1.2
+++ RenderingHints.java	2001/04/22 02:58:10
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000  Free Software Foundation
+/* Copyright (C) 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -16,7 +16,7 @@
     Cloneable
 {
 
-  static abstract class Key
+  public abstract static class Key
   {
     private int intKey;
 
Index: java/awt/Scrollbar.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Scrollbar.java,v
retrieving revision 1.5
diff -u -r1.5 Scrollbar.java
--- Scrollbar.java	2000/12/18 22:17:25	1.5
+++ Scrollbar.java	2001/04/22 02:58:10
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000  Free Software Foundation
+/* Copyright (C) 2000, 2001  Free Software Foundation
 
    This file is part of libjava.
 
@@ -55,6 +55,7 @@
   {
     if (peer == null)
       peer = getToolkit ().createScrollbar (this);
+    super.addNotify ();
   }
 
   public int getOrientation ()
Index: java/awt/TextComponent.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/TextComponent.java,v
retrieving revision 1.3
diff -u -r1.3 TextComponent.java
--- TextComponent.java	2000/03/07 19:55:25	1.3
+++ TextComponent.java	2001/04/22 02:58:10
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999  Free Software Foundation
+/* Copyright (C) 1999, 2001  Free Software Foundation
 
    This file is part of libjava.
 
@@ -7,16 +7,25 @@
 details.  */
 
 package java.awt;
+
 import java.awt.event.*;
+import java.awt.peer.TextComponentPeer;
 
 /* A very incomplete placeholder. */
 
 public class TextComponent extends Component
 {
+  protected TextListener textListener;
+
   char[] buffer;
   int length;
   int caretPosition;
 
+  public synchronized void addTextListener (TextListener listener)
+  {
+    textListener = AWTEventMulticaster.add (textListener, listener);
+  }
+
   public synchronized String getText ()
   { return new String(buffer, 0, length); }
 
@@ -28,11 +37,15 @@
     text.getChars(0, length, buffer, 0);
   }
 
-  public synchronized void addTextListener (TextListener listener)
-  { /* FIXME */ }
-
   public int getCaretPosition () { return caretPosition; }
-
-  public void setCaretPosition (int pos) { caretPosition = pos; }
 
+  public void setCaretPosition (int pos)
+  {
+    caretPosition = pos;
+    if (peer != null)
+      {
+	TextComponentPeer t = (TextComponentPeer) peer;
+	t.setCaretPosition (pos);
+      }
+  }
 }
Index: java/awt/event/ContainerEvent.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/event/ContainerEvent.java,v
retrieving revision 1.3
diff -u -r1.3 ContainerEvent.java
--- ContainerEvent.java	2000/12/26 00:25:12	1.3
+++ ContainerEvent.java	2001/04/22 02:58:10
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000  Free Software Foundation
+/* Copyright (C) 2000, 2001  Free Software Foundation
 
    This file is part of libjava.
 
@@ -35,9 +35,9 @@
     return child;
   }
 
-  public Component getContainer ()
+  public Container getContainer ()
   {
-    return (Component) source;
+    return (Container) source;
   }
 
   public String paramString ()
Index: java/awt/geom/Rectangle2D.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/geom/Rectangle2D.java,v
retrieving revision 1.1
diff -u -r1.1 Rectangle2D.java
--- Rectangle2D.java	2000/07/23 00:24:14	1.1
+++ Rectangle2D.java	2001/04/22 02:58:10
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000  Free Software Foundation
+/* Copyright (C) 2000, 2001  Free Software Foundation
 
    This file is part of libjava.
 
@@ -377,6 +377,14 @@
       this.y = (float) y;
       this.width = (float) w;
       this.height = (float) h;
+    }
+
+    public void setRect (float x, float y, float w, float h)
+    {
+      this.x = x;
+      this.y = y;
+      this.width = w;
+      this.height = h;
     }
 
     public void setRect (Rectangle2D r)



More information about the Java-patches mailing list