[gui][PATCH] JOptionPane and some other things.

Kim Ho kho@redhat.com
Mon May 3 18:51:00 GMT 2004


Hi,

This patch implements JOptionPane (minus JInternalFrame parts) and fixes
up some parts of JDialog. I also stubbed Box so that I could get parts
of JOptionPane working.

Cheers,

Kim

2004-05-03  Kim Ho  <kho@redhat.com>

	* gnu/java/awt/peer/gtk/GtkDialogPeer.java:
	(getGraphics): Like GtkFramePeer, the Graphics
	object needs to be translate to account for
	window decorations.
	(postMouseEvent): New method. Account for
	translation.
	(postExposeEvent): ditto.
	* javax/swing/Box.java: Stubbed.
	* javax/swing/JDialog.java: Ran through jalopy
	to fix indentation.
	(JDialog): Call SwingUtilities' getOwnerFrame
	for null owners.
	(setLayout): Check isRootPaneCheckingEnabled
	* javax/swing/JOptionPane.java: Re-implemented.
	* javax/swing/SwingUtilities.java:
	(getOwnerFrame): Static method to grab a default
	owner frame for Dialogs that don't specify owners.
	* javax/swing/event/SwingPropertyChangeSupport.java:
	(firePropertyChange): Fix early exit condition.
	* javax/swing/plaf/basic/BasicLabelUI.java:
	(paint): Avoid painting text if it is null 
	or empty.
	* javax/swing/plaf/basic/BasicOptionPaneUI.java:
	Implement.
	
-------------- next part --------------
? plaf
? javax/swing/plaf/basic/icons
Index: gnu/java/awt/peer/gtk/GtkDialogPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkDialogPeer.java,v
retrieving revision 1.9
diff -u -r1.9 GtkDialogPeer.java
--- gnu/java/awt/peer/gtk/GtkDialogPeer.java	13 Jan 2004 20:54:46 -0000	1.9
+++ gnu/java/awt/peer/gtk/GtkDialogPeer.java	3 May 2004 18:44:10 -0000
@@ -41,7 +41,10 @@
 import java.awt.AWTEvent;
 import java.awt.Component;
 import java.awt.Dialog;
+import java.awt.Graphics;
 import java.awt.peer.DialogPeer;
+import java.awt.Rectangle;
+import java.awt.event.PaintEvent;
 
 public class GtkDialogPeer extends GtkWindowPeer
   implements DialogPeer
@@ -50,6 +53,33 @@
   {
     super (dialog);
   }
+  
+  public Graphics getGraphics ()
+  {
+    Graphics g;
+    if (GtkToolkit.useGraphics2D ())
+      g = new GdkGraphics2D (this);
+    else
+      g = new GdkGraphics (this);
+    g.translate (-insets.left, -insets.top);
+    return g;
+  }  
+  
+  protected void postMouseEvent(int id, long when, int mods, int x, int y, 
+				int clickCount, boolean popupTrigger)
+  {
+    super.postMouseEvent (id, when, mods, 
+			  x + insets.left, y + insets.top, 
+			  clickCount, popupTrigger);
+  }
+
+  protected void postExposeEvent (int x, int y, int width, int height)
+  {
+    q.postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT,
+				 new Rectangle (x + insets.left, 
+						y + insets.top, 
+						width, height)));
+  }  
 
   void create ()
   {
Index: javax/swing/Box.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/Box.java,v
retrieving revision 1.3
diff -u -r1.3 Box.java
--- javax/swing/Box.java	5 Feb 2004 18:48:53 -0000	1.3
+++ javax/swing/Box.java	3 May 2004 18:44:13 -0000
@@ -39,6 +39,12 @@
 package javax.swing;
 
 import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRole;
+import java.awt.LayoutManager;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.AWTError;
 
 /**
  * Needs some work I guess....
@@ -49,8 +55,127 @@
 {
   private static final long serialVersionUID = 1525417495883046342L;
   
-  public Box(int a)
+  protected class AccessibleBox extends AccessibleAWTContainer
   {
-    setLayout(new BoxLayout(this, a));	
+    protected AccessibleBox()
+    {
+    }
+    
+    public AccessibleRole getAccessibleRole()
+    {
+      return null;
+    }
   }
+  
+  public static class Filler extends JComponent implements Accessible
+  {
+    protected class AccessibleBoxFiller extends AccessibleAWTComponent
+    {
+      protected AccessibleBoxFiller()
+      {
+      }
+      
+      public AccessibleRole getAccessibleRole()
+      {
+        return null;
+      }
+    }
+    
+    protected AccessibleContext accessibleContext;
+    
+    private transient Dimension min, pref, max;
+    
+    public Filler(Dimension min, Dimension pref, Dimension max)
+    {
+      changeShape(min, pref, max);
+    }
+    
+    public void changeShape(Dimension min, Dimension pref, Dimension max)
+    {
+      this.min = min;
+      this.pref = pref;
+      this.max = max;    
+    }
+    
+    public AccessibleContext getAccessibleContext()
+    {
+      if (accessibleContext == null)
+        accessibleContext = new AccessibleBox();
+      return accessibleContext;
+    }
+    
+    public Dimension getMaximumSize()
+    {
+      return max;
+    }
+    
+    public Dimension getMinimumSize()
+    {
+      return min;
+    }
+    
+    public Dimension getPreferredSize()
+    {
+      return pref;
+    }
+  }
+  
+  public Box(int axis)
+  {
+    setLayout(new BoxLayout(this, axis));	
+  }
+  
+  public static Component createGlue()
+  {
+    return null;
+  }
+  
+  public static Box createHorizontalBox()
+  {
+    return null;
+  }
+  
+  public static Component createHorizontalGlue()
+  {
+    return null;
+  }
+  
+  public static Component createHorizontalStrut(int width)
+  {
+    return null;
+  }
+  
+  public static Component createRigidArea(Dimension d)
+  {
+    return null;
+  }
+  
+  public static Box createVerticalBox()
+  {
+    return null;
+  }
+  
+  public static Component createVerticalGlue()
+  {
+    return null;
+  }
+  
+  public static Component createVerticalStrut(int height)
+  {
+    return null;
+  }
+  
+  public void setLayout(LayoutManager l)
+  {
+    throw new AWTError("Not allowed to set layout managers for boxes.");
+  }
+  
+  public AccessibleContext getAccessibleContext()
+  {
+    if (accessibleContext == null)
+      accessibleContext = new AccessibleBox();
+    return accessibleContext;
+  }
+  
+  
 }
Index: javax/swing/JDialog.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JDialog.java,v
retrieving revision 1.2
diff -u -r1.2 JDialog.java
--- javax/swing/JDialog.java	11 Jun 2003 13:20:39 -0000	1.2
+++ javax/swing/JDialog.java	3 May 2004 18:44:13 -0000
@@ -1,5 +1,5 @@
 /* JDialog.java --
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -35,7 +35,6 @@
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
-
 package javax.swing;
 
 import java.awt.BorderLayout;
@@ -45,227 +44,518 @@
 import java.awt.Dimension;
 import java.awt.Frame;
 import java.awt.Graphics;
+import java.awt.GraphicsConfiguration;
 import java.awt.LayoutManager;
 import java.awt.event.KeyEvent;
 import java.awt.event.WindowEvent;
+import java.awt.IllegalComponentStateException;
 import javax.accessibility.Accessible;
 import javax.accessibility.AccessibleContext;
 
+
 /**
- * Unlike JComponent derivatives, JDialog inherits from
- * java.awt.Dialog. But also lets a look-and-feel component to its work.
+ * Unlike JComponent derivatives, JDialog inherits from java.awt.Dialog. But
+ * also lets a look-and-feel component to its work.
  *
- * @author Ronald Veldema (rveldema@cs.vu.nl)
+ * @author Ronald Veldema (rveldema_AT_cs.vu.nl)
  */
-public class JDialog extends Dialog implements Accessible
+public class JDialog extends Dialog implements Accessible, WindowConstants,
+                                               RootPaneContainer
 {
-    public final static int HIDE_ON_CLOSE        = 0;
-    public final static int DISPOSE_ON_CLOSE     = 1;
-    public final static int DO_NOTHING_ON_CLOSE  = 2;
-
-    protected  AccessibleContext accessibleContext;
-
-    private int close_action = HIDE_ON_CLOSE;    
-
-    /***************************************************
-     *
-     *
-     *  constructors
-     *
-     *
-     *************/
-
-    JDialog(Frame owner)
-    {
-	this(owner, "dialog");
-    }
-    
-    JDialog(Frame owner,
-	    String s)
-    {
-	this(owner, s, true);
-    }
-    
-  JDialog(Frame owner,
-	  String s,
-	  boolean modeld)
-    {
-	super(owner, s, modeld);
-    }
-
-  JDialog(Frame owner,
-	  //  String s,
-	  boolean modeld)
-    {
-	super(owner, "JDialog", modeld);
-    }
-  JDialog(Dialog owner)
-  {
-      this(owner, "dialog");
-  }
-    
-    JDialog(Dialog owner,
-	    String s)
-    {
-	this(owner, s, true);
-    }
-    
-  JDialog(Dialog owner,
-	  String s,
-	  boolean modeld)
-    {
-	super(owner, s, modeld);
-    }
-
-
-    /***************************************************
-     *
-     *
-     *  methods, this part is shared with JDialog, JFrame
-     *
-     *
-     *************/
 
-  
-    private boolean checking;
-    protected  JRootPane         rootPane;
+  /** DOCUMENT ME! */
+  protected AccessibleContext accessibleContext;
 
-    void setLocationRelativeTo(Component c)
-    {
-    }
+  /** The single RootPane in the Dialog. */
+  protected JRootPane rootPane;
 
+  /** Whether checking is enabled on the RootPane */
+  protected boolean rootPaneCheckingEnabled = true;
 
-    protected  void frameInit()
-    {
-      super.setLayout(new BorderLayout(1, 1));
-      getRootPane(); // will do set/create
-    }
+  /** The default action taken when closed. */
+  private int close_action = HIDE_ON_CLOSE;
   
+  /** Whether JDialogs are decorated by the L&F. */
+  private static boolean decorated = false;
+
+  /**
+   * Creates a new non-modal JDialog with no title 
+   * using a shared Frame as the owner.
+   */
+  public JDialog()
+  {
+    this(SwingUtilities.getOwnerFrame(), "", false, null);
+  }
+
+  /**
+   * Creates a new non-modal JDialog with no title
+   * using the given owner.
+   *
+   * @param owner The owner of the JDialog.
+   */
+  public JDialog(Dialog owner)
+  {
+    this(owner, "", false, null);
+  }
+
+  /**
+   * Creates a new JDialog with no title using the
+   * given modal setting and owner.
+   *
+   * @param owner The owner of the JDialog.
+   * @param modal Whether the JDialog is modal.
+   */
+  public JDialog(Dialog owner, boolean modal)
+  {
+    this(owner, "", modal, null);
+  }
+
+  /**
+   * Creates a new non-modal JDialog using the 
+   * given title and owner.
+   *
+   * @param owner The owner of the JDialog.
+   * @param title The title of the JDialog.
+   */
+  public JDialog(Dialog owner, String title)
+  {
+    this(owner, title, false, null);
+  }
+
+  /**
+   * Creates a new JDialog using the given modal 
+   * settings, title, and owner.
+   *
+   * @param owner The owner of the JDialog.
+   * @param title The title of the JDialog.
+   * @param modal Whether the JDialog is modal.
+   */
+  public JDialog(Dialog owner, String title, boolean modal)
+  {
+    this(owner, title, modal, null);
+  }
+
+  /**
+   * Creates a new JDialog using the given modal 
+   * settings, title, owner and graphics configuration.
+   *
+   * @param owner The owner of the JDialog.
+   * @param title The title of the JDialog.
+   * @param modal Whether the JDialog is modal.
+   * @param gc The Graphics Configuration to use.
+   */
+  public JDialog(Dialog owner, String title, boolean modal,
+                 GraphicsConfiguration gc)
+  {
+    super(owner, title, modal, gc);
+    dialogInit();
+  }
+
+  /**
+   * Creates a new non-modal JDialog with no title
+   * using the given owner.
+   *
+   * @param owner The owner of the JDialog.
+   */
+  public JDialog(Frame owner)
+  {
+    this(owner, "", false, null);
+  }
+
+  /**
+   * Creates a new JDialog with no title using the
+   * given modal setting and owner.
+   *
+   * @param owner The owner of the JDialog.
+   * @param modal Whether the JDialog is modal.
+   */
+  public JDialog(Frame owner, boolean modal)
+  {
+    this(owner, "", modal, null);
+  }
+
+  /**
+   * Creates a new non-modal JDialog using the 
+   * given title and owner.
+   *
+   * @param owner The owner of the JDialog.
+   * @param title The title of the JDialog.
+   */
+  public JDialog(Frame owner, String title)
+  {
+    this(owner, title, false, null);
+  }
+
+  /**
+   * Creates a new JDialog using the given modal 
+   * settings, title, and owner.
+   *
+   * @param owner The owner of the JDialog.
+   * @param title The title of the JDialog.
+   * @param modal Whether the JDialog is modal.
+   */
+  public JDialog(Frame owner, String title, boolean modal)
+  {
+    this(owner, title, modal, null);
+  }
+
+  /**
+   * Creates a new JDialog using the given modal 
+   * settings, title, owner and graphics configuration.
+   *
+   * @param owner The owner of the JDialog.
+   * @param title The title of the JDialog.
+   * @param modal Whether the JDialog is modal.
+   * @param gc The Graphics Configuration to use.
+   */
+  public JDialog(Frame owner, String title, boolean modal,
+                 GraphicsConfiguration gc)
+  {
+    super((owner == null) ? SwingUtilities.getOwnerFrame() : owner, 
+          title, modal, gc);
+    dialogInit();
+  }
+
+  /**
+   * This method is called to initialize the 
+   * JDialog. It sets the layout used, the locale, 
+   * and creates the RootPane.
+   */
+  protected void dialogInit()
+  {
+    // FIXME: Do a check on GraphicsEnvironment.isHeadless()
+    setRootPaneCheckingEnabled(false);
+    setLocale(JComponent.getDefaultLocale());       
+    getRootPane(); // will do set/create  
+    setRootPaneCheckingEnabled(true);    
+    invalidate();
+
+  }
+
+  /**
+   * This method returns whether JDialogs will have their
+   * window decorations provided by the Look and Feel.
+   *
+   * @return Whether the window decorations are L&F provided.
+   */
+  public static boolean isDefaultLookAndFeelDecorated()
+  {
+    return decorated;
+  }
+
+  /**
+   * This method sets whether JDialogs will have their
+   * window decorations provided by the Look and Feel.
+   *
+   * @param defaultLookAndFeelDecorated Whether the window
+   * decorations are L&F provided.
+   */
+  public static void setDefaultLookAndFeelDecorated(boolean defaultLookAndFeelDecorated)
+  {
+    decorated = defaultLookAndFeelDecorated;
+  }
+
+  /**
+   * This method returns the preferred size of 
+   * the JDialog.
+   *
+   * @return The preferred size.
+   */
   public Dimension getPreferredSize()
   {
     Dimension d = super.getPreferredSize();
     return d;
   }
 
-    JMenuBar getJMenuBar()
-    {    return getRootPane().getJMenuBar();   }
-    
-    void setJMenuBar(JMenuBar menubar)
-    {    getRootPane().setJMenuBar(menubar); }
-    
+  /**
+   * This method returns the JMenuBar used
+   * in this JDialog.
+   *
+   * @return The JMenuBar in the JDialog.
+   */
+  public JMenuBar getJMenuBar()
+  {
+    return getRootPane().getJMenuBar();
+  }
 
-  public  void setLayout(LayoutManager manager)
-  {    super.setLayout(manager);  }
+  /**
+   * This method sets the JMenuBar used 
+   * in this JDialog.
+   *
+   * @param menubar The JMenuBar to use.
+   */
+  public void setJMenuBar(JMenuBar menubar)
+  {
+    getRootPane().setJMenuBar(menubar);
+  }
 
-    void setLayeredPane(JLayeredPane layeredPane) 
-    {   getRootPane().setLayeredPane(layeredPane);   }
-  
-    JLayeredPane getLayeredPane()
-    {   return getRootPane().getLayeredPane();     }
-  
-    JRootPane getRootPane()
-    {
-	if (rootPane == null)
-	    setRootPane(createRootPane());
-	return rootPane;          
-    }
-
-    void setRootPane(JRootPane root)
-    {
-	if (rootPane != null)
-	    remove(rootPane);
-	    
-	rootPane = root; 
-	add(rootPane, BorderLayout.CENTER);
-    }
+  /**
+   * This method sets the LayoutManager used in the JDialog.
+   * This method will throw an Error if rootPaneChecking is 
+   * enabled.
+   *
+   * @param manager The LayoutManager to use.
+   */
+  public void setLayout(LayoutManager manager)
+  {
+    if (isRootPaneCheckingEnabled())
+      throw new Error("rootPaneChecking is enabled - cannot set layout.");
+    super.setLayout(manager);
+  }
 
-    JRootPane createRootPane()
-    {   return new JRootPane();    }
+  /**
+   * This method sets the JLayeredPane used in the JDialog.
+   * If the given JLayeredPane is null, then this method
+   * will throw an Error.
+   *
+   * @param layeredPane The JLayeredPane to use.
+   */
+  public void setLayeredPane(JLayeredPane layeredPane)
+  {
+    if (layeredPane == null)
+      throw new IllegalComponentStateException("layeredPane cannot be null.");
+    getRootPane().setLayeredPane(layeredPane);
+  }
 
-    Container getContentPane()
-    {    return getRootPane().getContentPane();     }
+  /**
+   * This method returns the JLayeredPane used with this JDialog.
+   *
+   * @return The JLayeredPane used with this JDialog.
+   */
+  public JLayeredPane getLayeredPane()
+  {
+    return getRootPane().getLayeredPane();
+  }
 
-    void setContentPane(Container contentPane)
-    {    getRootPane().setContentPane(contentPane);    }
-  
-    Component getGlassPane()
-    {    return getRootPane().getGlassPane();   }
-  
-    void setGlassPane(Component glassPane)
-    {   getRootPane().setGlassPane(glassPane);   }
+  /**
+   * This method returns the JRootPane used with this JDialog.
+   *
+   * @return The JRootPane used with this JDialog.
+   */
+  public JRootPane getRootPane()
+  {
+    if (rootPane == null)
+      setRootPane(createRootPane());
+    return rootPane;
+  }
 
-    
-    protected  void addImpl(Component comp, Object constraints, int index)
-    {	super.addImpl(comp, constraints, index);    }
+  /**
+   * This method sets the JRootPane used with this JDialog.
+   *
+   * @param root The JRootPane to use.
+   */
+  protected void setRootPane(JRootPane root)
+  {
+    if (rootPane != null)
+      remove(rootPane);
 
+    rootPane = root;
+    rootPane.show();
+    add(rootPane);
+  }
 
-    public void remove(Component comp)
-    {   getContentPane().remove(comp);  }
-  
-    protected  boolean isRootPaneCheckingEnabled()
-    {    return checking;        }
+  /**
+   * This method creates a new JRootPane.
+   *
+   * @return A new JRootPane.
+   */
+  protected JRootPane createRootPane()
+  {
+    return new JRootPane();
+  }
 
+  /**
+   * This method returns the ContentPane
+   * in the JRootPane.
+   *
+   * @return The ContentPane in the JRootPane.
+   */
+  public Container getContentPane()
+  {
+    return getRootPane().getContentPane();
+  }
 
-    protected  void setRootPaneCheckingEnabled(boolean enabled)
-    { checking = enabled;  }
+  /**
+   * This method sets the ContentPane to use with this
+   * JDialog. If the ContentPane given is null, this method
+   * will throw an exception.
+   *
+   * @param contentPane The ContentPane to use with the JDialog.
+   */
+  public void setContentPane(Container contentPane)
+  {
+    if (contentPane == null)
+      throw new IllegalComponentStateException("contentPane cannot be null.");
+    getRootPane().setContentPane(contentPane);
+  }
 
+  /**
+   * This method returns the GlassPane for this JDialog.
+   *
+   * @return The GlassPane for this JDialog.
+   */
+  public Component getGlassPane()
+  {
+    return getRootPane().getGlassPane();
+  }
 
-    public void update(Graphics g)
-    {   paint(g);  }
+  /**
+   * This method sets the GlassPane for this JDialog.
+   *
+   * @param glassPane The GlassPane for this JDialog.
+   */
+  public void setGlassPane(Component glassPane)
+  {
+    getRootPane().setGlassPane(glassPane);
+  }
 
-    protected  void processKeyEvent(KeyEvent e)
-    {	super.processKeyEvent(e);    }
+  /**
+   * This method is called when a component is added to the 
+   * the JDialog. Calling this method with rootPaneCheckingEnabled
+   * will cause an Error to be thrown.
+   *
+   * @param comp The component to add.
+   * @param constraints The constraints.
+   * @param index The position of the component.
+   */
+  protected void addImpl(Component comp, Object constraints, int index)
+  {
+    if (isRootPaneCheckingEnabled())
+      throw new Error("rootPaneChecking is enabled - adding components disallowed.");
+    super.addImpl(comp, constraints, index);
+  }
 
-    /////////////////////////////////////////////////////////////////////////////////
-  
+  /**
+   * This method removes a component from the JDialog.
+   *
+   * @param comp The component to remove.
+   */
+  public void remove(Component comp)
+  {
+    // The path changes if the component == root.
+    if (comp == rootPane)
+      super.remove(rootPane);
+    else 
+      getContentPane().remove(comp);
+  }
 
-    protected  void processWindowEvent(WindowEvent e)
-    {
-	//	System.out.println("PROCESS_WIN_EV-1: " + e);
-	super.processWindowEvent(e); 
-	//	System.out.println("PROCESS_WIN_EV-2: " + e);
-	switch (e.getID())
+  /**
+   * This method returns whether rootPane checking is enabled.
+   *
+   * @return Whether rootPane checking is enabled.
+   */
+  protected boolean isRootPaneCheckingEnabled()
+  {
+    return rootPaneCheckingEnabled;
+  }
+
+  /**
+   * This method sets whether rootPane checking is enabled.
+   *
+   * @param enabled Whether rootPane checking is enabled.
+   */
+  protected void setRootPaneCheckingEnabled(boolean enabled)
+  {
+    rootPaneCheckingEnabled = enabled;
+  }
+
+  /**
+   * This method simply calls paint and returns.
+   *
+   * @param g The Graphics object to paint with.
+   */
+  public void update(Graphics g)
+  {
+    paint(g);
+  }
+  
+  
+  /**
+   * This method handles window events. This allows the JDialog
+   * to honour its default close operation.
+   *
+   * @param e The WindowEvent.
+   */
+  protected void processWindowEvent(WindowEvent e)
+  {
+    //	System.out.println("PROCESS_WIN_EV-1: " + e);
+    super.processWindowEvent(e);
+    //	System.out.println("PROCESS_WIN_EV-2: " + e);
+    switch (e.getID())
+      {
+      case WindowEvent.WINDOW_CLOSING:
+        {
+	  switch (getDefaultCloseOperation())
 	    {
-	    case WindowEvent.WINDOW_CLOSING:
-		{
-		    switch(close_action)
-			{
-			case DISPOSE_ON_CLOSE:
-			    {
-				System.out.println("user requested dispose on close");
-				dispose();
-				break;
-			    }
-			case HIDE_ON_CLOSE:
-			    {
-				setVisible(false);
-				break;
-			    }
-			case DO_NOTHING_ON_CLOSE:
-			    break;
-			}
-		    break;
-		}
-		
-	    case WindowEvent.WINDOW_CLOSED:
-	    case WindowEvent.WINDOW_OPENED:
-	    case WindowEvent.WINDOW_ICONIFIED:
-	    case WindowEvent.WINDOW_DEICONIFIED:
-	    case WindowEvent.WINDOW_ACTIVATED:
-	    case WindowEvent.WINDOW_DEACTIVATED:
+	    case DISPOSE_ON_CLOSE:
+	      {
+		dispose();
+		break;
+	      }
+	    case HIDE_ON_CLOSE:
+	      {
+		setVisible(false);
 		break;
+	      }
+	    case DO_NOTHING_ON_CLOSE:
+	      break;
 	    }
-    }   
- 
+	  break;
+        }
+      case WindowEvent.WINDOW_CLOSED:
+      case WindowEvent.WINDOW_OPENED:
+      case WindowEvent.WINDOW_ICONIFIED:
+      case WindowEvent.WINDOW_DEICONIFIED:
+      case WindowEvent.WINDOW_ACTIVATED:
+      case WindowEvent.WINDOW_DEACTIVATED:
+	break;
+      }
+  }
+
+  /**
+   * This method sets the action to take
+   * when the JDialog is closed.
+   *
+   * @param operation The action to take.
+   */
+  public void setDefaultCloseOperation(int operation)
+  {
+    if (operation == DO_NOTHING_ON_CLOSE ||
+    	operation == HIDE_ON_CLOSE ||
+	operation == DISPOSE_ON_CLOSE)
+      close_action = operation;
+    else
+      throw new IllegalArgumentException("Default close operation must be one of DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE, or DISPOSE_ON_CLOSE");
+  }
 
-    void setDefaultCloseOperation(int operation)
-    {  close_action = operation;   }
+  /**
+   * This method returns the action taken when
+   * the JDialog is closed.
+   *
+   * @return The action to take.
+   */
+  public int getDefaultCloseOperation()
+  {
+    return close_action;
+  }
 
-    protected  String paramString()
-    {   return "JDialog";     }
+  /**
+   * This method returns a String describing the JDialog.
+   *
+   * @return A String describing the JDialog.
+   */
+  protected String paramString()
+  {
+    return "JDialog";
+  }
 
-    public AccessibleContext getAccessibleContext()
-    {
-	return null;
-    }  
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public AccessibleContext getAccessibleContext()
+  {
+    return null;
+  }
 }
Index: javax/swing/JOptionPane.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JOptionPane.java,v
retrieving revision 1.3
diff -u -r1.3 JOptionPane.java
--- javax/swing/JOptionPane.java	12 Feb 2004 00:17:23 -0000	1.3
+++ javax/swing/JOptionPane.java	3 May 2004 18:44:13 -0000
@@ -1,5 +1,5 @@
-/* JOptionPane.java -- 
-   Copyright (C) 2002 Free Software Foundation, Inc.
+/* JOptionPane.java
+   Copyright (C) 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -35,365 +35,1388 @@
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
-
 package javax.swing;
 
-import java.awt.BorderLayout;
 import java.awt.Component;
 import java.awt.Dialog;
 import java.awt.Frame;
 import javax.accessibility.Accessible;
 import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRole;
+import javax.swing.Icon;
 import javax.swing.plaf.OptionPaneUI;
 
-public class JOptionPane extends JComponent 
-{
-    public static final int DEFAULT_OPTION        = 0;
-    public static final int YES_NO_OPTION         = 1;
-    public static final int YES_NO_CANCEL_OPTION  = 2;
-    public static final int OK_CANCEL_OPTION      = 3;
-    public static final int YES_OPTION            = 4;
-    public static final int NO_OPTION             = 5;
-    public static final int CANCEL_OPTION         = 6;
-    public static final int OK_OPTION             = 7;
-    public static final int CLOSED_OPTION         = 8;
-
-    public static final int ERROR_MESSAGE         = 0;
-    public static final int INFORMATION_MESSAGE   = 1;
-    public static final int WARNING_MESSAGE       = 2;
-    public static final int QUESTION_MESSAGE      = 3;
-    public static final int PLAIN_MESSAGE         = 4;
-
-    final static String VALUE_PROPERTY = "value_prop";
-    final static String INPUT_VALUE_PROPERTY = "input_value_prop";
-    
-    final static String UNINITIALIZED_VALUE = "uninit";
-
-    // Ronald: shouldnt by public ?
-    public Object msg;
-    public int mtype;
-    public int otype;
-    public Icon icon;
-    public Object []args;
-    public Object init;
-
-    public JDialog dialog;
 
-    /*****************************************************************************
-     *
-     *
-     *  joptionpanels
-     *
-     *
-     ***********************************/
-
-    JOptionPane()
-    {
-	this("mess");
-    }
-    
-    JOptionPane(Object m)
-    {
-	this(m, PLAIN_MESSAGE);
-    }
-    
-    JOptionPane(Object m,
-		 int mtype)
-    {
-	this(m, mtype, DEFAULT_OPTION);
-    }
-
-    JOptionPane(Object m,
-		int mtype,
-		int otype)
-    {
-	this(m, mtype, otype, null);
-    }
- 
-    JOptionPane(Object m,
-		 int mtype,
-		 int otype,
-		 Icon icon)
-    {
-	this(m, mtype, otype, icon, null);
-    }
-
-    JOptionPane(Object m,
-		 int mtype,
-		 int otype,
-		 Icon icon,
-		 Object []args)
-    {
-	this(m, mtype, otype, icon, args, null);
-    }
-
-    JOptionPane(Object msg,
-		int mtype,
-		int otype,
-		Icon icon,
-		Object []args,
-		Object init)
+/**
+ * This class creates different types of JDialogs and JInternalFrames that can
+ * ask users for input or pass on information. JOptionPane can be used by
+ * calling one of the show static methods or  by creating an instance of
+ * JOptionPane and calling createDialog or createInternalFrame.
+ */
+public class JOptionPane extends JComponent implements Accessible
+{
+  /**
+   * DOCUMENT ME!
+   */
+  protected class AccessibleJOptionPane extends JComponent.AccessibleJComponent
+  {
+    /**
+     * Creates a new AccessibleJOptionPane object.
+     */
+    protected AccessibleJOptionPane()
     {
-	//	this(m, mtype, otype, icon, args, init);
-	this.msg   = msg;
-	this.mtype = mtype;
-	this.otype = otype;
-	this.icon  = icon;
-	this.args  = args;
-	this.init  = init;
-	
-	updateUI();
+      super(JOptionPane.this);
     }
 
-
-    /*****************************************************************************
-     *
+    /**
+     * DOCUMENT ME!
      *
-     *
-     *
-     *
-     ***********************************/
-
-    Object val;
-    public void setValue(Object v)  
-    {   val = v;       }
-    public Object getValue()
-    {	return val;    }
-
-    public String getUIClassID()
-    {	return "OptionPaneUI";    }
-
-
-    public void setUI(OptionPaneUI ui) {
-        super.setUI(ui);
-    }
-    
-    public OptionPaneUI getUI() {
-        return (OptionPaneUI)ui;
-    }
-    
-    public void updateUI() {
-	setUI((OptionPaneUI)UIManager.getUI(this));
-    }
-
-
-    public AccessibleContext getAccessibleContext()
+     * @return DOCUMENT ME!
+     */
+    public AccessibleRole getAccessibleRole()
     {
-	return null;
-    }
-    
-    protected  String paramString()
-    {
-	return "JOptionPane";
-    }
-    
-    public static void showMessageDialog(Component frame,
-				  String msg,
-				  String title,
-				  int bla)
-    {
-	DoShowOptionDialog(frame,
-			  msg,
-			  title,
-			  bla,
-			  0,
-			  null,
-			  null,
-			  null);
-    }
-
-    public static void showMessageDialog(Component frame,
-				 String msg,
-				 String title,
-				 int bla,
-				 Icon icon)
-    {
-	DoShowOptionDialog(frame,
-				 msg,
-				 title,
-				 bla,
-				 0,
-				 icon,
-				 null,
-				 null);
-    }
-
-    public static void showMessageDialog(Component frame,
-				  String msg)
-    {
-	showMessageDialog(frame,
-			  msg,
-			  null);
-    }
-    
-
-    public static void showMessageDialog(Component frame,
-				  String msg,
-				  Icon icon)
-    {	
-	//System.out.println("++++++++++++++++++creating message dialog:"+msg + ", frame="+frame);
-         DoShowOptionDialog(frame, 
-				msg, 
-				"Message",				
-				DEFAULT_OPTION, 
-				PLAIN_MESSAGE,
-				icon,
-				null,
-				null);
-    }
-
-    public static int showConfirmDialog(JFrame frame,
-				 String yes,
-				 String no, 
-				 int bla)
-    {
-	return 0;
-    }
-
-    public static String showInputDialog(JFrame frame,
-			     String msg, 
-			     String title, 
-			     int opt_type, 
-			     int msg_type,
-			     Icon icon, 
-			     Object[] opts, 
-			     Object init)
-    {
-	return (String) DoShowOptionDialog(frame,
-				msg, 
-				title, 
-				opt_type, 
-				msg_type,
-				icon, 
-				opts, 
-				init);
+      return null;
     }
+  }
 
-    public static Object showInputDialog(JFrame frame,
-			     String msg, 
-			     String title, 
-			     int opt_type, 
-			     Icon icon, 
-			     Object[] opts, 
-			     Object init)
-    {
-	return DoShowOptionDialog(frame,
-				msg, 
-				title, 
-				opt_type, 
-				0, //msg_type,
-				icon, 
-				opts, 
-				init);
-    }
-
-
-    // everybody comes here eventually
-    public static int showOptionDialog(Component frame,
-				String msg, 
-				String title, 
-				int opt_type, 
-				int msg_type,
-				Icon icon, 
-				Object[] opts, 
-				Object init)
-    {
-	Integer a = (Integer) DoShowOptionDialog(frame,
-						 msg, 
-						 title, 
-						 opt_type, 
-						 msg_type,
-						 icon, 
-						 opts, 
-						 init);
-	if (a == null)
-	    return -1;
-	return a.intValue();
-    }
-    
-    public static Object DoShowOptionDialog(Component frame,
-				   String msg, 
-				   String title, 
-				   int opt_type, 
-				   int msg_type,
-				   Icon icon, 
-				   Object[] opts, 
-				   Object init)
-    {
-	
-	JOptionPane p = new JOptionPane(msg,
-					msg_type,
-					opt_type,
-					icon,
-					opts,
-					init);
-	System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ " + p.msg);
-
-	
-	JDialog a;
-
-	if (frame == null)
-	    {
-		a = new JDialog((Frame)frame,
-				title,
-				true);
-	    }
-	else if (frame instanceof Dialog)
-	    {
-		a = new JDialog((Dialog) frame,
-				title,
-				true);
-	    }
-	else if (frame instanceof Frame)
-	    {
-		a = new JDialog((Frame) frame,
-				title,
-				true);
-	    }
-	else
-	    {
-		System.out.println("HUUUUHHH, not a frame or dialog !");
-		
-		a = new JDialog((Frame)null,
-				title,
-				true);
-	    }
-
-	p.dialog = a;
-	
-	a.getContentPane().setLayout(new BorderLayout());
-	a.getContentPane().add(p,
-			       BorderLayout.CENTER);
-	// package the deal
-	a.pack();
-	
-	a.setVisible(true);
-	
-	Object s = p.getValue();
-
-	System.out.println("RESULT FROM DIALOG = " + s);
-
-	if (s == null)
-	    return null;
-	
-	return s;
-    }
+  /** The value returned when cancel option is selected. */
+  public static final int CANCEL_OPTION = 2;
 
+  /** The value returned when the dialog is closed without a selection. */
+  public static final int CLOSED_OPTION = -1;
+
+  /** An option used in confirmation dialog methods. */
+  public static final int DEFAULT_OPTION = -1;
+
+  /** The value returned when the no option is selected. */
+  public static final int NO_OPTION = 1;
+
+  /** An option used in confirmation dialog methods. */
+  public static final int OK_CANCEL_OPTION = 2;
+
+  /** The value returned when the ok option is selected. */
+  public static final int OK_OPTION = 0;
+
+  /** An option used in confirmation dialog methods. */
+  public static final int YES_NO_CANCEL_OPTION = 1;
+
+  /** An option used in confirmation dialog methods. */
+  public static final int YES_NO_OPTION = 0;
+
+  /** The value returned when the yes option is selected. */
+  public static final int YES_OPTION = 0;
+
+  /** Identifier for the error message type. */
+  public static final int ERROR_MESSAGE = 0;
+
+  /** Identifier for the information message type. */
+  public static final int INFORMATION_MESSAGE = 1;
+
+  /** Identifier for the plain message type. */
+  public static final int PLAIN_MESSAGE = -1;
+
+  /** Identifier for the question message type. */
+  public static final int QUESTION_MESSAGE = 3;
+
+  /** Identifier for the warning message type. */
+  public static final int WARNING_MESSAGE = 2;
+
+  /**
+   * The identifier for the propertyChangeEvent when the icon property
+   * changes.
+   */
+  public static final String ICON_PROPERTY = "icon";
+
+  /**
+   * The identifier for the propertyChangeEvent when the initialSelectionValue
+   * property changes.
+   */
+  public static final String INITIAL_SELECTION_VALUE_PROPERTY = "initialSelectionValue";
+
+  /**
+   * The identifier for the propertyChangeEvent when the initialValue property
+   * changes.
+   */
+  public static final String INITIAL_VALUE_PROPERTY = "initialValue";
+
+  /**
+   * The identifier for the propertyChangeEvent when the inputValue property
+   * changes.
+   */
+  public static final String INPUT_VALUE_PROPERTY = "inputValue";
+
+  /**
+   * The identifier for the propertyChangeEvent when the message property
+   * changes.
+   */
+  public static final String MESSAGE_PROPERTY = "message";
+
+  /**
+   * The identifier for the propertyChangeEvent when the messageType property
+   * changes.
+   */
+  public static final String MESSAGE_TYPE_PROPERTY = "messageType";
+
+  /**
+   * The identifier for the propertyChangeEvent when the optionType property
+   * changes.
+   */
+  public static final String OPTION_TYPE_PROPERTY = "optionType";
+
+  /**
+   * The identifier for the propertyChangeEvent when the options property
+   * changes.
+   */
+  public static final String OPTIONS_PROPERTY = "options";
+
+  /**
+   * The identifier for the propertyChangeEvent when the selectionValues
+   * property changes.
+   */
+  public static final String SELECTION_VALUES_PROPERTY = "selectionValues";
+
+  /**
+   * The identifier for the propertyChangeEvent when the value property
+   * changes.
+   */
+  public static final String VALUE_PROPERTY = "value";
+
+  /**
+   * The identifier for the propertyChangeEvent when the wantsInput property
+   * changes.
+   */
+  public static final String WANTS_INPUT_PROPERTY = "wantsInput";
+
+  /** The value returned when the inputValue is uninitialized. */
+  public static Object UNINITIALIZED_VALUE = "uninitializedValue";
+
+  /** The icon displayed in the dialog/internal frame. */
+  protected Icon icon;
+
+  /** The initial selected value in the input component. */
+  protected Object initialSelectionValue;
+
+  /** The object that is initially selected for options. */
+  protected Object initialValue;
+
+  /** The value the user inputs. */
+  protected Object inputValue = UNINITIALIZED_VALUE;
+
+  /** The message displayed in the dialog/internal frame. */
+  protected Object message = "JOptionPane message";
+
+  /** The type of message displayed. */
+  protected int messageType = PLAIN_MESSAGE;
+
+  /**
+   * The options (usually buttons) aligned at the bottom for the user to
+   * select.
+   */
+  protected Object[] options;
+
+  /** The type of options to display. */
+  protected int optionType = DEFAULT_OPTION;
+
+  /** The input values the user can select. */
+  protected Object[] selectionValues;
+
+  /** The value returned by selecting an option. */
+  protected Object value = UNINITIALIZED_VALUE;
+
+  /** Whether the Dialog/InternalFrame needs input. */
+  protected boolean wantsInput;
+
+  /** The common frame used when no parent is provided. */
+  private static Frame privFrame = SwingUtilities.getOwnerFrame();
+
+  /**
+   * Creates a new JOptionPane object using a message of "JOptionPane
+   * message", using the PLAIN_MESSAGE type and DEFAULT_OPTION.
+   */
+  public JOptionPane()
+  {
+    this(this.message, PLAIN_MESSAGE, DEFAULT_OPTION, null, null, null);
+  }
+
+  /**
+   * Creates a new JOptionPane object using the given message using the
+   * PLAIN_MESSAGE type and DEFAULT_OPTION.
+   *
+   * @param message The message to display.
+   */
+  public JOptionPane(Object message)
+  {
+    this(message, PLAIN_MESSAGE, DEFAULT_OPTION, null, null, null);
+  }
+
+  /**
+   * Creates a new JOptionPane object using the given message and messageType
+   * and DEFAULT_OPTION.
+   *
+   * @param message The message to display.
+   * @param messageType The type of message.
+   */
+  public JOptionPane(Object message, int messageType)
+  {
+    this(message, messageType, DEFAULT_OPTION, null, null, null);
+  }
+
+  /**
+   * Creates a new JOptionPane object using the given message, messageType and
+   * optionType.
+   *
+   * @param message The message to display.
+   * @param messageType The type of message.
+   * @param optionType The type of options.
+   */
+  public JOptionPane(Object message, int messageType, int optionType)
+  {
+    this(message, messageType, optionType, null, null, null);
+  }
+
+  /**
+   * Creates a new JOptionPane object using the given message, messageType,
+   * optionType and icon.
+   *
+   * @param message The message to display.
+   * @param messageType The type of message.
+   * @param optionType The type of options.
+   * @param icon The icon to display.
+   */
+  public JOptionPane(Object message, int messageType, int optionType, Icon icon)
+  {
+    this(message, messageType, optionType, icon, null, null);
+  }
+
+  /**
+   * Creates a new JOptionPane object using the given message, messageType,
+   * optionType, icon and options.
+   *
+   * @param message The message to display.
+   * @param messageType The type of message.
+   * @param optionType The type of options.
+   * @param icon The icon to display.
+   * @param options The options given.
+   */
+  public JOptionPane(Object message, int messageType, int optionType,
+                     Icon icon, Object[] options)
+  {
+    this(message, messageType, optionType, icon, options, null);
+  }
+
+  /**
+   * Creates a new JOptionPane object using the given message, messageType,
+   * optionType, icon, options and initialValue. The initialValue will be
+   * focused initially.
+   *
+   * @param message The message to display.
+   * @param messageType The type of message.
+   * @param optionType The type of options.
+   * @param icon The icon to display.
+   * @param options The options given.
+   * @param initialValue The component to focus on initially.
+   *
+   * @throws IllegalArgumentException If the messageType or optionType are not
+   *         legal values.
+   */
+  public JOptionPane(Object message, int messageType, int optionType,
+                     Icon icon, Object[] options, Object initialValue)
+  {
+    this.message = message;
+    if (! validMessageType(messageType))
+      throw new IllegalArgumentException("Message Type not legal value.");
+    this.messageType = messageType;
+    if (! validOptionType(optionType))
+      throw new IllegalArgumentException("Option Type not legal value.");
+    this.optionType = optionType;
+    this.icon = icon;
+    this.options = options;
+    this.initialValue = initialValue;
+
+    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+
+    updateUI();
+    invalidate();
+    repaint();
+  }
+
+  /**
+   * This method creates a new JDialog that is either centered around the
+   * parent's frame or centered on the screen (if the parent is null). The
+   * JDialog will not be resizable and will be modal. Once the JDialog is
+   * disposed, the inputValue and value properties will  be set by the
+   * optionPane.
+   *
+   * @param parentComponent The parent of the Dialog.
+   * @param title The title in the bar of the JDialog.
+   *
+   * @return A new JDialog based on the JOptionPane configuration.
+   */
+  public JDialog createDialog(Component parentComponent, String title)
+  {
+    Frame toUse = getFrameForComponent(parentComponent);
+    if (toUse == null)
+      toUse = getRootFrame();
+
+    JDialog dialog = new JDialog(toUse, title);
+    inputValue = UNINITIALIZED_VALUE;
+    value = UNINITIALIZED_VALUE;
+
+    // FIXME: This dialog should be centered on the parent
+    // or at the center of the screen (if the parent is null)
+    // Need getGraphicsConfiguration to return non-null in
+    // order for that to work so we know how large the 
+    // screen is.
+    dialog.getContentPane().add(this);
+    dialog.setModal(true);
+    dialog.setResizable(false);
+
+    return dialog;
+  }
+
+  /**
+   * This method creates a new JInternalFrame that is in the JDesktopPane
+   * which contains the parentComponent given. If no suitable JDesktopPane
+   * can be found from the parentComponent given, a RuntimeException will be
+   * thrown.
+   *
+   * @param parentComponent The parent to find a JDesktopPane from.
+   * @param title The title of the JInternalFrame.
+   *
+   * @return A new JInternalFrame based on the JOptionPane configuration.
+   *
+   * @throws RuntimeException If no suitable JDesktopPane is found.
+   */
+  public JInternalFrame createInternalFrame(Component parentComponent,
+                                            String title)
+                                     throws RuntimeException
+  {
+    // FIXME: implement.
+    return null;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public AccessibleContext getAccessibleContext()
+  {
+    if (accessibleContext == null)
+      accessibleContext = new AccessibleJOptionPane();
+    return accessibleContext;
+  }
+
+  /**
+   * This method returns the JDesktopPane for the given parentComponent or
+   * null if none can be found.
+   *
+   * @param parentComponent The component to look in.
+   *
+   * @return The JDesktopPane for the given component or null if none can be
+   *         found.
+   */
+  public static JDesktopPane getDesktopPaneForComponent(Component parentComponent)
+  {
+    if (parentComponent == null)
+      return null;
+    if (parentComponent instanceof JDesktopPane)
+      return (JDesktopPane) parentComponent;
+    JDesktopPane parent = null;
+    while (parentComponent.getParent() != null)
+      {
+	parentComponent = parentComponent.getParent();
+	if (parentComponent instanceof JDesktopPane)
+	  {
+	    parent = (JDesktopPane) parentComponent;
+	    break;
+	  }
+      }
+    return parent;
+  }
+
+  /**
+   * This method returns the Frame for the given parentComponent or null if
+   * none can be found.
+   *
+   * @param parentComponent The component to look in.
+   *
+   * @return The Frame for the given component or null if none can be found.
+   */
+  public static Frame getFrameForComponent(Component parentComponent)
+  {
+    if (parentComponent == null)
+      return null;
+    if (parentComponent instanceof Frame)
+      return (Frame) parentComponent;
+    Frame parent = null;
+    while (parentComponent.getParent() != null)
+      {
+	parentComponent = parentComponent.getParent();
+	if (parentComponent instanceof Frame)
+	  {
+	    parent = (Frame) parentComponent;
+	    break;
+	  }
+      }
+    return parent;
+  }
+
+  /**
+   * This method returns the icon displayed.
+   *
+   * @return The icon displayed.
+   */
+  public Icon getIcon()
+  {
+    return icon;
+  }
+
+  /**
+   * This method returns the value initially selected from the list of values
+   * the user can input.
+   *
+   * @return The initial selection value.
+   */
+  public Object getInitialSelectionValue()
+  {
+    return initialSelectionValue;
+  }
+
+  /**
+   * This method returns the value that is focused from the list of options.
+   *
+   * @return The initial value from options.
+   */
+  public Object getInitialValue()
+  {
+    return initialValue;
+  }
+
+  /**
+   * This method returns the value that the user input.
+   *
+   * @return The user's input value.
+   */
+  public Object getInputValue()
+  {
+    return inputValue;
+  }
+
+  /**
+   * This method returns the maximum characters per line. By default, this is
+   * Integer.MAX_VALUE.
+   *
+   * @return The maximum characters per line.
+   */
+  public int getMaxCharactersPerLineCount()
+  {
+    return Integer.MAX_VALUE;
+  }
+
+  /**
+   * This method returns the message displayed.
+   *
+   * @return The message displayed.
+   */
+  public Object getMessage()
+  {
+    return message;
+  }
+
+  /**
+   * This method returns the message type.
+   *
+   * @return The message type.
+   */
+  public int getMessageType()
+  {
+    return messageType;
+  }
+
+  /**
+   * This method returns the options.
+   *
+   * @return The options.
+   */
+  public Object[] getOptions()
+  {
+    return options;
+  }
+
+  /**
+   * This method returns the option type.
+   *
+   * @return The option type.
+   */
+  public int getOptionType()
+  {
+    return optionType;
+  }
+
+  /**
+   * This method returns the Frame used by JOptionPane dialog's that have no
+   * parent.
+   *
+   * @return The Frame used by dialogs that have no parent.
+   */
+  public static Frame getRootFrame()
+  {
+    return privFrame;
+  }
+
+  /**
+   * This method returns the selection values.
+   *
+   * @return The selection values.
+   */
+  public Object[] getSelectionValues()
+  {
+    return selectionValues;
+  }
+
+  /**
+   * This method returns the UI used by the JOptionPane.
+   *
+   * @return The UI used by the JOptionPane.
+   */
+  public OptionPaneUI getUI()
+  {
+    return (OptionPaneUI) ui;
+  }
+
+  /**
+   * This method returns an identifier to determine which UI class will act as
+   * the UI.
+   *
+   * @return The UI identifier.
+   */
+  public String getUIClassID()
+  {
+    return "OptionPaneUI";
+  }
+
+  /**
+   * This method returns the value that the user selected out of options.
+   *
+   * @return The value that the user selected out of options.
+   */
+  public Object getValue()
+  {
+    return value;
+  }
+
+  /**
+   * This method returns whether this JOptionPane wants input.
+   *
+   * @return Whether this JOptionPane wants input.
+   */
+  public boolean getWantsInput()
+  {
+    return wantsInput;
+  }
+
+  /**
+   * This method returns a String that describes this JOptionPane.
+   *
+   * @return A String that describes this JOptionPane.
+   */
+  protected String paramString()
+  {
+    return "JOptionPane";
+  }
+
+  /**
+   * This method requests focus for the initial value.
+   */
+  public void selectInitialValue()
+  {
+    if (ui != null)
+      ((OptionPaneUI) ui).selectInitialValue(this);
+  }
+
+  /**
+   * This method changes the icon property.
+   *
+   * @param newIcon The new icon to use.
+   */
+  public void setIcon(Icon newIcon)
+  {
+    if (icon != newIcon)
+      {
+	Icon old = icon;
+	icon = newIcon;
+	firePropertyChange(ICON_PROPERTY, old, icon);
+      }
+  }
+
+  /**
+   * This method changes the initial selection property.
+   *
+   * @param newValue The new initial selection.
+   */
+  public void setInitialSelectionValue(Object newValue)
+  {
+    if (initialSelectionValue != newValue)
+      {
+	Object old = initialSelectionValue;
+	initialSelectionValue = newValue;
+	firePropertyChange(INITIAL_SELECTION_VALUE_PROPERTY, old,
+	                   initialSelectionValue);
+      }
+  }
+
+  /**
+   * This method changes the initial value property.
+   *
+   * @param newValue The new initial value.
+   */
+  public void setInitialValue(Object newValue)
+  {
+    if (initialValue != newValue)
+      {
+	Object old = initialValue;
+	initialValue = newValue;
+	firePropertyChange(INITIAL_VALUE_PROPERTY, old, initialValue);
+      }
+  }
+
+  /**
+   * This method changes the inputValue property.
+   *
+   * @param newValue The new inputValue.
+   */
+  public void setInputValue(Object newValue)
+  {
+    if (inputValue != newValue)
+      {
+	Object old = inputValue;
+	inputValue = newValue;
+	firePropertyChange(INPUT_VALUE_PROPERTY, old, inputValue);
+      }
+  }
+
+  /**
+   * This method changes the message property.
+   *
+   * @param newMessage The new message.
+   */
+  public void setMessage(Object newMessage)
+  {
+    if (message != newMessage)
+      {
+	Object old = message;
+	message = newMessage;
+	firePropertyChange(MESSAGE_PROPERTY, old, message);
+      }
+  }
+
+  /**
+   * This method changes the messageType property.
+   *
+   * @param newType The new messageType.
+   *
+   * @throws IllegalArgumentException If the messageType is not valid.
+   */
+  public void setMessageType(int newType)
+  {
+    if (! validMessageType(newType))
+      throw new IllegalArgumentException("Message Type not legal value.");
+    if (newType != messageType)
+      {
+	int old = messageType;
+	messageType = newType;
+	firePropertyChange(MESSAGE_TYPE_PROPERTY, old, messageType);
+      }
+  }
+
+  /**
+   * This method changes the options property.
+   *
+   * @param newOptions The new options.
+   */
+  public void setOptions(Object[] newOptions)
+  {
+    if (options != newOptions)
+      {
+	Object[] old = options;
+	options = newOptions;
+	firePropertyChange(OPTIONS_PROPERTY, old, options);
+      }
+  }
+
+  /**
+   * This method changes the optionType property.
+   *
+   * @param newType The new optionType.
+   *
+   * @throws IllegalArgumentException If the optionType is not valid.
+   */
+  public void setOptionType(int newType)
+  {
+    if (! validOptionType(newType))
+      throw new IllegalArgumentException("Option Type not legal value.");
+    if (newType != optionType)
+      {
+	int old = optionType;
+	optionType = newType;
+	firePropertyChange(OPTION_TYPE_PROPERTY, old, optionType);
+      }
+  }
+
+  /**
+   * This method changes the Frame used for JOptionPane dialogs that have no
+   * parent.
+   *
+   * @param newRootFrame The Frame to use for dialogs that have no parent.
+   */
+  public static void setRootFrame(Frame newRootFrame)
+  {
+    privFrame = newRootFrame;
+  }
+
+  /**
+   * This method changes the selectionValues property.
+   *
+   * @param newValues The new selectionValues.
+   */
+  public void setSelectionValues(Object[] newValues)
+  {
+    if (newValues != selectionValues)
+      {
+	if (newValues != null)
+	  wantsInput = true;
+	Object[] old = selectionValues;
+	selectionValues = newValues;
+	firePropertyChange(SELECTION_VALUES_PROPERTY, old, selectionValues);
+      }
+  }
+
+  /**
+   * This method sets the UI used with the JOptionPane.
+   *
+   * @param ui The UI used with the JOptionPane.
+   */
+  public void setUI(OptionPaneUI ui)
+  {
+    super.setUI(ui);
+  }
+
+  /**
+   * This method sets the value has been selected out of options.
+   *
+   * @param newValue The value that has been selected out of options.
+   */
+  public void setValue(Object newValue)
+  {
+    if (value != newValue)
+      {
+	Object old = value;
+	value = newValue;
+	firePropertyChange(VALUE_PROPERTY, old, value);
+      }
+  }
+
+  /**
+   * This method changes the wantsInput property.
+   *
+   * @param newValue Whether this JOptionPane requires input.
+   */
+  public void setWantsInput(boolean newValue)
+  {
+    if (wantsInput != newValue)
+      {
+	boolean old = wantsInput;
+	wantsInput = newValue;
+	firePropertyChange(WANTS_INPUT_PROPERTY, old, wantsInput);
+      }
+  }
+
+  /**
+   * This method shows a confirmation dialog with the title "Select an Option"
+   * and displays the given message. The parent frame will be the same as the
+   * parent frame of the given parentComponent. This method returns the
+   * option chosen by the user.
+   *
+   * @param parentComponent The parentComponent to find a frame in.
+   * @param message The message to display.
+   *
+   * @return The option that was selected.
+   */
+  public static int showConfirmDialog(Component parentComponent, Object message)
+  {
+    JOptionPane pane = new JOptionPane(message);
+    JDialog dialog = pane.createDialog(parentComponent, "Select an Option");
+    dialog.pack();
+    dialog.show();
+
+    return ((Integer) pane.getValue()).intValue();
+  }
+
+  /**
+   * This method shows a confirmation dialog with the given message,
+   * optionType and title. The frame that owns the dialog will be the same
+   * frame that holds the given parentComponent. This method returns the
+   * option that was chosen.
+   *
+   * @param parentComponent The component to find a frame in.
+   * @param message The message displayed.
+   * @param title The title of the dialog.
+   * @param optionType The optionType.
+   *
+   * @return The option that was chosen.
+   */
+  public static int showConfirmDialog(Component parentComponent,
+                                      Object message, String title,
+                                      int optionType)
+  {
+    JOptionPane pane = new JOptionPane(message, PLAIN_MESSAGE, optionType);
+    JDialog dialog = pane.createDialog(parentComponent, title);
+    dialog.pack();
+    dialog.show();
+
+    return ((Integer) pane.getValue()).intValue();
+  }
+
+  /**
+   * This method shows a confirmation dialog with the given message, title,
+   * messageType and optionType. The frame owner will be the same frame as
+   * the one that holds the given parentComponent. This method returns the
+   * option selected by the user.
+   *
+   * @param parentComponent The component to find a frame in.
+   * @param message The message displayed.
+   * @param title The title of the dialog.
+   * @param optionType The optionType.
+   * @param messageType The messageType.
+   *
+   * @return The selected option.
+   */
+  public static int showConfirmDialog(Component parentComponent,
+                                      Object message, String title,
+                                      int optionType, int messageType)
+  {
+    JOptionPane pane = new JOptionPane(message, messageType, optionType);
+    JDialog dialog = pane.createDialog(parentComponent, title);
+    dialog.pack();
+    dialog.show();
+
+    return ((Integer) pane.getValue()).intValue();
+  }
+
+  /**
+   * This method shows a confirmation dialog with the given message, title,
+   * optionType, messageType and icon. The frame owner will be the same as
+   * the one that holds the given parentComponent. This method returns the
+   * option selected by the user.
+   *
+   * @param parentComponent The component to find a frame in.
+   * @param message The message displayed.
+   * @param title The title of the dialog.
+   * @param optionType The optionType.
+   * @param messageType The messsageType.
+   * @param icon The icon displayed.
+   *
+   * @return The selected option.
+   */
+  public static int showConfirmDialog(Component parentComponent,
+                                      Object message, String title,
+                                      int optionType, int messageType,
+                                      Icon icon)
+  {
+    JOptionPane pane = new JOptionPane(message, messageType, optionType, icon);
+    JDialog dialog = pane.createDialog(parentComponent, title);
+    dialog.pack();
+    dialog.show();
+
+    return ((Integer) pane.getValue()).intValue();
+  }
+
+  /**
+   * This method will show a QUESTION_MESSAGE input dialog with the given
+   * message. No selectionValues is set so the Look and Feel will usually
+   * give the user a TextField to fill out. The frame owner will be the same
+   * frame that holds the given parentComponent. This method will return the
+   * value entered by the user.
+   *
+   * @param parentComponent The component to find a frame in.
+   * @param message The message displayed.
+   *
+   * @return The value entered by the user.
+   */
+  public static String showInputDialog(Component parentComponent,
+                                       Object message)
+  {
+    JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE);
+    pane.setWantsInput(true);
+    JDialog dialog = pane.createDialog(parentComponent, null);
+    dialog.pack();
+    dialog.show();
+
+    return (String) pane.getInputValue();
+  }
+
+  /**
+   * This method will show a QUESTION_MESSAGE type input dialog with the given
+   * message and initialSelectionValue. Since there is no selectionValues
+   * set, the Look and Feel will usually give a TextField to fill out. The
+   * frame owner will be the same as the one that holds the given
+   * parentComponent. This method will return the value entered by the user.
+   *
+   * @param parentComponent The component to find a frame in.
+   * @param message The message to display.
+   * @param initialSelectionValue The initially selected value.
+   *
+   * @return The value the user input.
+   */
+  public static String showInputDialog(Component parentComponent,
+                                       Object message,
+                                       Object initialSelectionValue)
+  {
+    JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE);
+    pane.setInitialSelectionValue(initialSelectionValue);
+    pane.setWantsInput(true);
+    JDialog dialog = pane.createDialog(parentComponent, null);
+    dialog.pack();
+    dialog.show();
+
+    return (String) pane.getInputValue();
+  }
+
+  /**
+   * This method displays a new input dialog with the given message, title and
+   * messageType. Since no selectionValues value is given, the Look and Feel
+   * will usually give the user a TextField to input data to. This method
+   * returns the value the user inputs.
+   *
+   * @param parentComponent The component to find a frame in.
+   * @param message The message to display.
+   * @param title The title of the dialog.
+   * @param messageType The messageType.
+   *
+   * @return The value the user input.
+   */
+  public static String showInputDialog(Component parentComponent,
+                                       Object message, String title,
+                                       int messageType)
+  {
+    JOptionPane pane = new JOptionPane(message, messageType);
+    pane.setWantsInput(true);
+    JDialog dialog = pane.createDialog(parentComponent, title);
+    dialog.pack();
+    dialog.show();
+
+    return (String) pane.getInputValue();
+  }
+
+  /**
+   * This method shows an input dialog with the given message, title,
+   * messageType, icon, selectionValues, and initialSelectionValue. This
+   * method returns the value that the user selects.
+   *
+   * @param parentComponent The component to find a frame in.
+   * @param message The message displayed.
+   * @param title The title of the dialog.
+   * @param messageType The messageType.
+   * @param icon The icon displayed.
+   * @param selectionValues The list of values to select from.
+   * @param initialSelectionValue The initially selected value.
+   *
+   * @return The user selected value.
+   */
+  public static Object showInputDialog(Component parentComponent,
+                                       Object message, String title,
+                                       int messageType, Icon icon,
+                                       Object[] selectionValues,
+                                       Object initialSelectionValue)
+  {
+    JOptionPane pane = new JOptionPane(message, messageType);
+    pane.setWantsInput(true);
+    pane.setIcon(icon);
+    pane.setSelectionValues(selectionValues);
+    pane.setInitialSelectionValue(initialSelectionValue);
+    JDialog dialog = pane.createDialog(parentComponent, title);
+    dialog.pack();
+    dialog.show();
+
+    return (String) pane.getInputValue();
+  }
+
+  /**
+   * This method shows a QUESTION_MESSAGE type input dialog. Since no
+   * selectionValues is set, the Look and Feel will usually give the user a
+   * TextField to input data to. This method returns the value the user
+   * inputs.
+   *
+   * @param message The message to display.
+   *
+   * @return The user selected value.
+   */
+  public static String showInputDialog(Object message)
+  {
+    JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE);
+    pane.setWantsInput(true);
+    JDialog dialog = pane.createDialog(null, null);
+    dialog.pack();
+    dialog.show();
+
+    return (String) pane.getInputValue();
+  }
+
+  /**
+   * This method shows a QUESTION_MESSAGE type input dialog. Since no
+   * selectionValues is set, the Look and Feel will usually give the user a
+   * TextField to input data to. The input component will be initialized with
+   * the initialSelectionValue. This method returns the value the user
+   * inputs.
+   *
+   * @param message The message to display.
+   * @param initialSelectionValue The initialSelectionValue.
+   *
+   * @return The user selected value.
+   */
+  public static String showInputDialog(Object message,
+                                       Object initialSelectionValue)
+  {
+    JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE);
+    pane.setWantsInput(true);
+    pane.setInitialSelectionValue(initialSelectionValue);
+    JDialog dialog = pane.createDialog(null, null);
+    dialog.pack();
+    dialog.show();
+
+    return (String) pane.getInputValue();
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param parentComponent DOCUMENT ME!
+   * @param message DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public static int showInternalConfirmDialog(Component parentComponent,
+                                              Object message)
+  {
+    // FIXME: implement
+    return 0;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param parentComponent DOCUMENT ME!
+   * @param message DOCUMENT ME!
+   * @param title DOCUMENT ME!
+   * @param optionType DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public static int showInternalConfirmDialog(Component parentComponent,
+                                              Object message, String title,
+                                              int optionType)
+  {
+    // FIXME: implement  
+    return 0;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param parentComponent DOCUMENT ME!
+   * @param message DOCUMENT ME!
+   * @param title DOCUMENT ME!
+   * @param optionType DOCUMENT ME!
+   * @param messageType DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public static int showInternalConfirmDialog(Component parentComponent,
+                                              Object message, String title,
+                                              int optionType, int messageType)
+  {
+    // FIXME: implement  
+    return 0;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param parentComponent DOCUMENT ME!
+   * @param message DOCUMENT ME!
+   * @param title DOCUMENT ME!
+   * @param optionType DOCUMENT ME!
+   * @param messageType DOCUMENT ME!
+   * @param icon DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public static int showInternalConfirmDialog(Component parentComponent,
+                                              Object message, String title,
+                                              int optionType, int messageType,
+                                              Icon icon)
+  {
+    // FIXME: implement  
+    return 0;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param parentComponent DOCUMENT ME!
+   * @param message DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public static String showInternalInputDialog(Component parentComponent,
+                                               Object message)
+  {
+    // FIXME: implement  
+    return null;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param parentComponent DOCUMENT ME!
+   * @param message DOCUMENT ME!
+   * @param title DOCUMENT ME!
+   * @param messageType DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public static String showInternalInputDialog(Component parentComponent,
+                                               Object message, String title,
+                                               int messageType)
+  {
+    // FIXME: implement  
+    return null;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param parentComponent DOCUMENT ME!
+   * @param message DOCUMENT ME!
+   * @param title DOCUMENT ME!
+   * @param messageType DOCUMENT ME!
+   * @param icon DOCUMENT ME!
+   * @param selectionValues DOCUMENT ME!
+   * @param initialSelectionValue DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public static Object showInternalInputDialog(Component parentComponent,
+                                               Object message, String title,
+                                               int messageType, Icon icon,
+                                               Object[] selectionValues,
+                                               Object initialSelectionValue)
+  {
+    // FIXME: implement  
+    return null;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param parentComponent DOCUMENT ME!
+   * @param message DOCUMENT ME!
+   */
+  public static void showInternalMessageDialog(Component parentComponent,
+                                               Object message)
+  {
+    // FIXME: implement  
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param parentComponent DOCUMENT ME!
+   * @param message DOCUMENT ME!
+   * @param title DOCUMENT ME!
+   * @param messageType DOCUMENT ME!
+   */
+  public static void showInternalMessageDialog(Component parentComponent,
+                                               Object message, String title,
+                                               int messageType)
+  {
+    // FIXME: implement
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param parentComponent DOCUMENT ME!
+   * @param message DOCUMENT ME!
+   * @param title DOCUMENT ME!
+   * @param messageType DOCUMENT ME!
+   * @param icon DOCUMENT ME!
+   */
+  public static void showInternalMessageDialog(Component parentComponent,
+                                               Object message, String title,
+                                               int messageType, Icon icon)
+  {
+    // FIXME: implement  
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param parentComponent DOCUMENT ME!
+   * @param message DOCUMENT ME!
+   * @param title DOCUMENT ME!
+   * @param optionType DOCUMENT ME!
+   * @param messageType DOCUMENT ME!
+   * @param icon DOCUMENT ME!
+   * @param options DOCUMENT ME!
+   * @param initialValue DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public static int showInternalOptionDialog(Component parentComponent,
+                                             Object message, String title,
+                                             int optionType, int messageType,
+                                             Icon icon, Object[] options,
+                                             Object initialValue)
+  {
+    // FIXME: implement  
+    return 0;
+  }
+
+  /**
+   * This method shows an INFORMATION_MESSAGE type message dialog.
+   *
+   * @param parentComponent The component to find a frame in.
+   * @param message The message displayed.
+   */
+  public static void showMessageDialog(Component parentComponent,
+                                       Object message)
+  {
+    JOptionPane pane = new JOptionPane(message, INFORMATION_MESSAGE);
+    JDialog dialog = pane.createDialog(parentComponent, null);
+    dialog.pack();
+    dialog.show();
+  }
+
+  /**
+   * This method shows a message dialog with the given message, title and
+   * messageType.
+   *
+   * @param parentComponent The component to find a frame in.
+   * @param message The message displayed.
+   * @param title The title of the dialog.
+   * @param messageType The messageType.
+   */
+  public static void showMessageDialog(Component parentComponent,
+                                       Object message, String title,
+                                       int messageType)
+  {
+    JOptionPane pane = new JOptionPane(message, messageType);
+    JDialog dialog = pane.createDialog(parentComponent, title);
+    dialog.pack();
+    dialog.show();
+  }
+
+  /**
+   * This method shows a message dialog with the given message, title,
+   * messageType and icon.
+   *
+   * @param parentComponent The component to find a frame in.
+   * @param message The message displayed.
+   * @param title The title of the dialog.
+   * @param messageType The messageType.
+   * @param icon The icon displayed.
+   */
+  public static void showMessageDialog(Component parentComponent,
+                                       Object message, String title,
+                                       int messageType, Icon icon)
+  {
+    JOptionPane pane = new JOptionPane(message, messageType);
+    pane.setIcon(icon);
+    JDialog dialog = pane.createDialog(parentComponent, title);
+    dialog.pack();
+    dialog.show();
+  }
+
+  /**
+   * This method shows an option dialog with the given message, title,
+   * optionType, messageType, icon, options and initialValue. This method
+   * returns the option that was selected.
+   *
+   * @param parentComponent The component to find a frame in.
+   * @param message The message displayed.
+   * @param title The title of the dialog.
+   * @param optionType The optionType.
+   * @param messageType The messageType.
+   * @param icon The icon displayed.
+   * @param options The options to choose from.
+   * @param initialValue The initial value.
+   *
+   * @return The selected option.
+   */
+  public static int showOptionDialog(Component parentComponent,
+                                     Object message, String title,
+                                     int optionType, int messageType,
+                                     Icon icon, Object[] options,
+                                     Object initialValue)
+  {
+    JOptionPane pane = new JOptionPane(message, messageType, optionType, icon,
+                                       options, initialValue);
+    JDialog dialog = pane.createDialog(parentComponent, title);
+    dialog.pack();
+    dialog.show();
+
+    return ((Integer) pane.getValue()).intValue();
+  }
+
+  /**
+   * This method resets the UI to the Look and Feel default.
+   */
+  public void updateUI()
+  {
+    setUI((OptionPaneUI) UIManager.getUI(this));
+    invalidate();
+  }
+
+  /**
+   * This method returns true if the key is a valid messageType.
+   *
+   * @param key The key to check.
+   *
+   * @return True if key is valid.
+   */
+  private boolean validMessageType(int key)
+  {
+    switch (key)
+      {
+      case ERROR_MESSAGE:
+      case INFORMATION_MESSAGE:
+      case PLAIN_MESSAGE:
+      case QUESTION_MESSAGE:
+      case WARNING_MESSAGE:
+	return true;
+      }
+    return false;
+  }
+
+  /**
+   * This method returns true if the key is a valid optionType.
+   *
+   * @param key The key to check.
+   *
+   * @return True if key is valid.
+   */
+  private boolean validOptionType(int key)
+  {
+    switch (key)
+      {
+      case DEFAULT_OPTION:
+      case OK_CANCEL_OPTION:
+      case YES_NO_CANCEL_OPTION:
+      case YES_NO_OPTION:
+	return true;
+      }
+    return false;
+  }
 }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Index: javax/swing/SwingUtilities.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/SwingUtilities.java,v
retrieving revision 1.6.2.2
diff -u -r1.6.2.2 SwingUtilities.java
--- javax/swing/SwingUtilities.java	26 Feb 2004 14:24:08 -0000	1.6.2.2
+++ javax/swing/SwingUtilities.java	3 May 2004 18:44:14 -0000
@@ -44,6 +44,7 @@
 import java.awt.EventQueue;
 import java.awt.Font;
 import java.awt.FontMetrics;
+import java.awt.Frame;
 import java.awt.Graphics;
 import java.awt.Insets;
 import java.awt.Point;
@@ -68,6 +69,8 @@
 public class SwingUtilities implements SwingConstants
 {
 
+  private static Frame ownerFrame;
+
   /**
    * Calculates the portion of the base rectangle which is inside the
    * insets.
@@ -832,6 +835,19 @@
                                     Container p, Rectangle r)
   {
     paintComponent(g, c, p, r.x, r.y, r.width, r.height);
+  }
+  
+  /**
+   * This method returns the common Frame owner used in JDialogs
+   * when no owner is provided.
+   *
+   * @return The common Frame 
+   */
+  static Frame getOwnerFrame()
+  {
+    if (ownerFrame == null)
+      ownerFrame = new Frame();
+    return ownerFrame;
   }
   
 
Index: javax/swing/event/SwingPropertyChangeSupport.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/event/SwingPropertyChangeSupport.java,v
retrieving revision 1.3
diff -u -r1.3 SwingPropertyChangeSupport.java
--- javax/swing/event/SwingPropertyChangeSupport.java	10 Jan 2004 21:07:43 -0000	1.3
+++ javax/swing/event/SwingPropertyChangeSupport.java	3 May 2004 18:44:14 -0000
@@ -210,8 +210,9 @@
 		PropertyChangeListener	listener;
 
 		// Check Values if they are equal
-		if (event.getOldValue() == null || event.getNewValue() == null ||
-			event.getOldValue().equals(event.getNewValue()) == true) {
+		if (event.getOldValue() == null && event.getNewValue() == null ||
+		    (event.getOldValue() != null && event.getNewValue() != null &&
+	            event.getOldValue().equals(event.getNewValue()))) {
 			return;
 		} // if
 
Index: javax/swing/plaf/basic/BasicLabelUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicLabelUI.java,v
retrieving revision 1.4.16.2
diff -u -r1.4.16.2 BasicLabelUI.java
--- javax/swing/plaf/basic/BasicLabelUI.java	17 Feb 2004 01:44:46 -0000	1.4.16.2
+++ javax/swing/plaf/basic/BasicLabelUI.java	3 May 2004 18:44:15 -0000
@@ -168,7 +168,7 @@
       vr.width = 0;
     if (vr.height < 0)
       vr.height = 0;
-
+      
     Icon icon = (b.isEnabled()) ? b.getIcon() : b.getDisabledIcon();
 
     String text = layoutCL(b, fm, b.getText(), icon, vr, ir, tr);
@@ -181,10 +181,13 @@
 
     if (icon != null)
       icon.paintIcon(b, g, ir.x, ir.y);
-    if (b.isEnabled())
-      paintEnabledText(b, g, text, tr.x, tr.y + fm.getAscent());
-    else
-      paintDisabledText(b, g, text, tr.x, tr.y + fm.getAscent());
+    if (text != null && ! text.equals(""))
+    {
+      if (b.isEnabled())
+        paintEnabledText(b, g, text, tr.x, tr.y + fm.getAscent());
+      else
+        paintDisabledText(b, g, text, tr.x, tr.y + fm.getAscent());
+    }
     g.setFont(saved_font);
   }
 
Index: javax/swing/plaf/basic/BasicOptionPaneUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicOptionPaneUI.java,v
retrieving revision 1.6
diff -u -r1.6 BasicOptionPaneUI.java
--- javax/swing/plaf/basic/BasicOptionPaneUI.java	10 Jan 2004 21:59:30 -0000	1.6
+++ javax/swing/plaf/basic/BasicOptionPaneUI.java	3 May 2004 18:44:15 -0000
@@ -1,5 +1,5 @@
 /* BasicOptionPaneUI.java
-   Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+   Copyright (C) 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -35,124 +35,1275 @@
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
-
 package javax.swing.plaf.basic;
 
+import java.awt.BorderLayout;
+import java.awt.Color;
 import java.awt.Component;
+import java.awt.Container;
 import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
 import java.awt.LayoutManager;
+import java.awt.Polygon;
+import java.awt.Rectangle;
+import java.awt.Window;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.Icon;
 import javax.swing.JButton;
+import javax.swing.JComboBox;
 import javax.swing.JComponent;
+import javax.swing.JDialog;
 import javax.swing.JLabel;
+import javax.swing.JList;
 import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.SwingUtilities;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
+import javax.swing.border.Border;
 import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.IconUIResource;
 import javax.swing.plaf.OptionPaneUI;
 
+
+/**
+ * This class is the UI delegate for JOptionPane in the Basic Look and Feel.
+ */
 public class BasicOptionPaneUI extends OptionPaneUI
 {
-    JOptionPane pane;
+  /**
+   * This is a helper class that listens to the buttons located at the bottom
+   * of the JOptionPane.
+   */
+  protected class ButtonActionListener implements ActionListener
+  {
+    /** The index of the option this button represents. */
+    protected int buttonIndex;
+
+    /**
+     * Creates a new ButtonActionListener object with the given buttonIndex.
+     *
+     * @param buttonIndex The index of the option this button represents.
+     */
+    public ButtonActionListener(int buttonIndex)
+    {
+      this.buttonIndex = buttonIndex;
+    }
+
+    /**
+     * This method is called when one of the option buttons are pressed.
+     *
+     * @param e The ActionEvent.
+     */
+    public void actionPerformed(ActionEvent e)
+    {
+      Object value = new Integer(JOptionPane.CLOSED_OPTION);
+      Object[] options = optionPane.getOptions();
+      if (options != null)
+	value = options[buttonIndex];
+      else
+        {
+	  String text = ((JButton) e.getSource()).getText();
+	  if (text.equals(OK_STRING))
+	    value = new Integer(JOptionPane.OK_OPTION);
+	  if (text.equals(CANCEL_STRING))
+	    value = new Integer(JOptionPane.CANCEL_OPTION);
+	  if (text.equals(YES_STRING))
+	    value = new Integer(JOptionPane.YES_OPTION);
+	  if (text.equals(NO_STRING))
+	    value = new Integer(JOptionPane.NO_OPTION);
+        }
+      optionPane.setValue(value);
+      resetInputValue();
+
+      Window owner = SwingUtilities.windowForComponent(optionPane);
+
+      if (owner instanceof JDialog)
+	((JDialog) owner).dispose();
+    }
+  }
+
+  /**
+   * This helper layout manager is responsible for the layout of the button
+   * area. The button area is the panel that holds the buttons which
+   * represent the options.
+   */
+  protected class ButtonAreaLayout implements LayoutManager
+  {
+    /** Whether this layout will center the buttons. */
+    protected boolean centersChildren = true;
 
-    BasicOptionPaneUI()
+    /** The space between the buttons. */
+    protected int padding;
+
+    /** Whether the buttons will share the same widths. */
+    protected boolean syncAllWidths;
+
+    /** The width of the widest button. */
+    private transient int widthOfWidestButton;
+
+    /** The height of the tallest button. */
+    private transient int tallestButton;
+
+    /**
+     * Creates a new ButtonAreaLayout object with the given sync widths
+     * property and padding.
+     *
+     * @param syncAllWidths Whether the buttons will share the same widths.
+     * @param padding The padding between the buttons.
+     */
+    public ButtonAreaLayout(boolean syncAllWidths, int padding)
     {
+      this.syncAllWidths = syncAllWidths;
+      this.padding = padding;
     }
 
-    public static ComponentUI createUI(JComponent x) 
+    /**
+     * This method is called when a component is added to the container.
+     *
+     * @param string The constraints string.
+     * @param comp The component added.
+     */
+    public void addLayoutComponent(String string, Component comp)
     {
-        return new BasicOptionPaneUI();
+      // Do nothing.
     }
 
-    public void installUI(JComponent c)
+    /**
+     * This method returns whether the children will be centered.
+     *
+     * @return Whether the children will be centered.
+     */
+    public boolean getCentersChildren()
     {
-	super.installUI(c);
-	pane = (JOptionPane)c;
+      return centersChildren;
+    }
 
-	System.out.println("     -------------: " + pane);
+    /**
+     * This method returns the amount of space between components.
+     *
+     * @return The amount of space between components.
+     */
+    public int getPadding()
+    {
+      return padding;
+    }
 
-	JLabel  message   = null;
-	JButton ok_button = new JButton("Ok");	
+    /**
+     * This method returns whether all components will share widths (set to
+     * largest width).
+     *
+     * @return Whether all components will share widths.
+     */
+    public boolean getSyncAllWidths()
+    {
+      return syncAllWidths;
+    }
 
-	ok_button.addActionListener(new ActionListener()
+    /**
+     * This method lays out the given container.
+     *
+     * @param container The container to lay out.
+     */
+    public void layoutContainer(Container container)
+    {
+      Component[] buttonList = container.getComponents();
+      int x = container.getInsets().left;
+      if (getCentersChildren())
+	x += (int) ((double) (container.getSize().width) / 2
+	- (double) (buttonRowLength(container)) / 2);
+      for (int i = 0; i < buttonList.length; i++)
+        {
+	  Dimension dims = buttonList[i].getPreferredSize();
+	  if (getSizeButtonsToSameWidth())
 	    {
-		public void actionPerformed(ActionEvent a)
-		{
-		    System.out.println("ACTION ---> " + a);
-		    //		    pane.dialog.dispose();
-
-		    if (pane.dialog.isModal())
-			{
-			    System.out.println("modal dialog !!");
-			    pane.dialog.setModal(false);
-			}
-		    pane.dialog.setVisible(false);
-		}
-	    });
-
-	Object[] options = null;
-	if (options != null)
+	      buttonList[i].setBounds(x, 0, widthOfWidestButton, dims.height);
+	      x += widthOfWidestButton + getPadding();
+	    }
+	  else
 	    {
-		for (int i=0; i<options.length; i++)
-		    {
-			Object o = options[i];
-			if (o != null)
-			    {
-				if (o instanceof String)
-				    {
-					String s = (String) o;
-					JLabel m = new JLabel(s);
-					pane.add(m);
-				    }
-				else if (o instanceof Component)
-				    {
-					Component com = (Component) o;
-					pane.add(com);
-				    }
-				else
-				    {
-					System.out.println("UNRECOGNIZED ARG: " + o);
-				    }
-			    }
-		    }
+	      buttonList[i].setBounds(x, 0, dims.width, dims.height);
+	      x += dims.width + getPadding();
 	    }
+        }
+    }
+
+    /**
+     * This method returns the width of the given container taking into
+     * consideration the padding and syncAllWidths.
+     *
+     * @param c The container to calculate width for.
+     *
+     * @return The width of the given container.
+     */
+    private int buttonRowLength(Container c)
+    {
+      Component[] buttonList = c.getComponents();
+
+      int buttonLength = 0;
+      int widest = 0;
+      int tallest = 0;
+
+      for (int i = 0; i < buttonList.length; i++)
+        {
+	  Dimension dims = buttonList[i].getPreferredSize();
+	  buttonLength += dims.width + getPadding();
+	  widest = Math.max(widest, dims.width);
+	  tallest = Math.max(tallest, dims.height);
+        }
+
+      widthOfWidestButton = widest;
+      tallestButton = tallest;
+
+      int width;
+      if (getSyncAllWidths())
+	width = widest * buttonList.length
+	        + getPadding() * (buttonList.length - 1);
+      else
+	width = buttonLength;
 
-	pane.add(message);
-	pane.add(ok_button);
+      Insets insets = c.getInsets();
+      width += insets.left + insets.right;
+
+      return width;
     }
 
-    Dimension getMinimumOptionPaneSize()
+    /**
+     * This method returns the minimum layout size for the given container.
+     *
+     * @param c The container to measure.
+     *
+     * @return The minimum layout size.
+     */
+    public Dimension minimumLayoutSize(Container c)
     {
-	return new Dimension(300,100);
+      return preferredLayoutSize(c);
     }
 
-    public Dimension getPreferredSize(JComponent c)
+    /**
+     * This method returns the preferred size of the given container.
+     *
+     * @param c The container to measure.
+     *
+     * @return The preferred size.
+     */
+    public Dimension preferredLayoutSize(Container c)
     {
-	if (c == null)
-	    return getMinimumOptionPaneSize();
+      int w = buttonRowLength(c);
 
-	if (c != pane)
-	    return null;
+      return new Dimension(w, tallestButton);
+    }
 
-	LayoutManager l  = c.getLayout();
-	if (l == null)
-	    return getMinimumOptionPaneSize();
+    /**
+     * This method removes the given component from the layout manager's
+     * knowledge.
+     *
+     * @param c The component to remove.
+     */
+    public void removeLayoutComponent(Component c)
+    {
+      // Do nothing.
+    }
+
+    /**
+     * This method sets whether the children will be centered.
+     *
+     * @param newValue Whether the children will be centered.
+     */
+    public void setCentersChildren(boolean newValue)
+    {
+      centersChildren = newValue;
+      optionPane.invalidate();
+    }
 
-	Dimension d1 = l.preferredLayoutSize(c);
-	Dimension d2 = getMinimumOptionPaneSize();
-	
-	d1.width = Math.max(d1.width, d2.width);
-	d1.height = Math.max(d1.height, d2.height);
+    /**
+     * This method sets the amount of space between each component.
+     *
+     * @param newPadding The padding between components.
+     */
+    public void setPadding(int newPadding)
+    {
+      padding = newPadding;
+      optionPane.invalidate();
+    }
 
-	return d2;
+    /**
+     * This method sets whether the widths will be synced.
+     *
+     * @param newValue Whether the widths will be synced.
+     */
+    public void setSyncAllWidths(boolean newValue)
+    {
+      syncAllWidths = newValue;
+      optionPane.invalidate();
     }
+  }
 
-  public void selectInitialValue(JOptionPane op)
+  /**
+   * This helper class handles property change events from the JOptionPane.
+   */
+  public class PropertyChangeHandler implements PropertyChangeListener
+  {
+    /**
+     * This method is called when one of the properties of the JOptionPane
+     * changes.
+     *
+     * @param e The PropertyChangeEvent.
+     */
+    public void propertyChange(PropertyChangeEvent e)
+    {
+      if (e.getPropertyName().equals(JOptionPane.ICON_PROPERTY)
+          || e.getPropertyName().equals(JOptionPane.MESSAGE_TYPE_PROPERTY))
+	addIcon(messageAreaContainer);
+      else if (e.getPropertyName().equals(JOptionPane.INITIAL_SELECTION_VALUE_PROPERTY))
+	resetSelectedValue();
+      else if (e.getPropertyName().equals(JOptionPane.INITIAL_VALUE_PROPERTY)
+               || e.getPropertyName().equals(JOptionPane.OPTIONS_PROPERTY)
+               || e.getPropertyName().equals(JOptionPane.OPTION_TYPE_PROPERTY))
+        {
+	  Container newButtons = createButtonArea();
+	  optionPane.remove(buttonContainer);
+	  optionPane.add(newButtons);
+	  buttonContainer = newButtons;
+        }
+
+      else if (e.getPropertyName().equals(JOptionPane.MESSAGE_PROPERTY)
+               || e.getPropertyName().equals(JOptionPane.WANTS_INPUT_PROPERTY)
+               || e.getPropertyName().equals(JOptionPane.SELECTION_VALUES_PROPERTY))
+        {
+	  optionPane.removeAll();
+	  messageAreaContainer = createMessageArea();
+	  optionPane.add(messageAreaContainer);
+	  optionPane.add(buttonContainer);
+        }
+      optionPane.invalidate();
+      optionPane.repaint();
+    }
+  }
+
+  /** Whether the JOptionPane contains custom components. */
+  protected boolean hasCustomComponents = false;
+
+  // The initialFocusComponent seems to always be set to a button (even if 
+  // I try to set initialSelectionValue). This is different from what the 
+  // javadocs state (which should switch this reference to the input component 
+  // if one is present since that is what's going to get focus). 
+
+  /**
+   * The button that will receive focus based on initialValue when no input
+   * component is present. If an input component is present, then the input
+   * component will receive focus instead.
+   */
+  protected Component initialFocusComponent;
+
+  /** The component that receives input when the JOptionPane needs it. */
+  protected JComponent inputComponent;
+
+  /** The minimum height of the JOptionPane. */
+  public static int minimumHeight;
+
+  /** The minimum width of the JOptionPane. */
+  public static int minimumWidth;
+
+  /** The minimum dimensions of the JOptionPane. */
+  protected Dimension minimumSize;
+
+  /** The propertyChangeListener for the JOptionPane. */
+  protected PropertyChangeListener propertyChangeListener;
+
+  /** The JOptionPane this UI delegate is used for. */
+  protected JOptionPane optionPane;
+
+  /** The size of the icons. */
+  private static int iconSize = 36;
+
+  /** The foreground color for the message area. */
+  private transient Color messageForeground;
+
+  /** The border around the message area. */
+  private transient Border messageBorder;
+
+  /** The border around the button area. */
+  private transient Border buttonBorder;
+
+  /** The string used to describe OK buttons. */
+  private static String OK_STRING = "OK";
+
+  /** The string used to describe Yes buttons. */
+  private static String YES_STRING = "Yes";
+
+  /** The string used to describe No buttons. */
+  private static String NO_STRING = "No";
+
+  /** The string used to describe Cancel buttons. */
+  private static String CANCEL_STRING = "Cancel";
+
+  /** The container for the message area. */
+  private transient Container messageAreaContainer;
+
+  /** The container for the buttons. */
+  private transient Container buttonContainer;
+
+  /**
+   * A helper class that implements Icon. This is used temporarily until
+   * ImageIcons are fixed.
+   */
+  private static class messageIcon implements Icon
+  {
+    /**
+     * This method returns the width of the icon.
+     *
+     * @return The width of the icon.
+     */
+    public int getIconWidth()
+    {
+      return iconSize;
+    }
+
+    /**
+     * This method returns the height of the icon.
+     *
+     * @return The height of the icon.
+     */
+    public int getIconHeight()
+    {
+      return iconSize;
+    }
+
+    /**
+     * This method paints the icon as a part of the given component using the
+     * given graphics and the given x and y position.
+     *
+     * @param c The component that owns this icon.
+     * @param g The Graphics object to paint with.
+     * @param x The x coordinate.
+     * @param y The y coordinate.
+     */
+    public void paintIcon(Component c, Graphics g, int x, int y)
+    {
+    }
+  }
+
+  /** The icon displayed for ERROR_MESSAGE. */
+  private static messageIcon errorIcon = new messageIcon()
+    {
+      public void paintIcon(Component c, Graphics g, int x, int y)
+      {
+	Polygon oct = new Polygon(new int[] { 0, 0, 9, 27, 36, 36, 27, 9 },
+	                          new int[] { 9, 27, 36, 36, 27, 9, 0, 0 }, 8);
+	g.translate(x, y);
+
+	Color saved = g.getColor();
+	g.setColor(Color.RED);
+
+	g.fillPolygon(oct);
+
+	g.setColor(Color.BLACK);
+	g.drawRect(13, 16, 10, 4);
+
+	g.setColor(saved);
+	g.translate(-x, -y);
+      }
+    };
+
+  /** The icon displayed for INFORMATION_MESSAGE. */
+  private static messageIcon infoIcon = new messageIcon()
+    {
+      public void paintIcon(Component c, Graphics g, int x, int y)
+      {
+	g.translate(x, y);
+	Color saved = g.getColor();
+
+	// Should be purple.
+	g.setColor(Color.RED);
+
+	g.fillOval(0, 0, iconSize, iconSize);
+
+	g.setColor(Color.BLACK);
+	g.drawOval(16, 6, 4, 4);
+
+	Polygon bottomI = new Polygon(new int[] { 15, 15, 13, 13, 23, 23, 21, 21 },
+	                              new int[] { 12, 28, 28, 30, 30, 28, 28, 12 },
+	                              8);
+	g.drawPolygon(bottomI);
+
+	g.setColor(saved);
+	g.translate(-x, -y);
+      }
+    };
+
+  /** The icon displayed for WARNING_MESSAGE. */
+  private static messageIcon warningIcon = new messageIcon()
+    {
+      public void paintIcon(Component c, Graphics g, int x, int y)
+      {
+	g.translate(x, y);
+	Color saved = g.getColor();
+	g.setColor(Color.YELLOW);
+
+	Polygon triangle = new Polygon(new int[] { 0, 18, 36 },
+	                               new int[] { 36, 0, 36 }, 3);
+	g.fillPolygon(triangle);
+
+	g.setColor(Color.BLACK);
+
+	Polygon excl = new Polygon(new int[] { 15, 16, 20, 21 },
+	                           new int[] { 8, 26, 26, 8 }, 4);
+	g.drawPolygon(excl);
+	g.drawOval(16, 30, 4, 4);
+
+	g.setColor(saved);
+	g.translate(-x, -y);
+      }
+    };
+
+  /** The icon displayed for MESSAGE_ICON. */
+  private static messageIcon questionIcon = new messageIcon()
+    {
+      public void paintIcon(Component c, Graphics g, int x, int y)
+      {
+	g.translate(x, y);
+	Color saved = g.getColor();
+	g.setColor(Color.GREEN);
+
+	g.fillRect(0, 0, iconSize, iconSize);
+
+	g.setColor(Color.BLACK);
+
+	g.drawOval(11, 2, 16, 16);
+	g.drawOval(14, 5, 10, 10);
+
+	g.setColor(Color.GREEN);
+	g.fillRect(0, 10, iconSize, iconSize - 10);
+
+	g.setColor(Color.BLACK);
+
+	g.drawLine(11, 10, 14, 10);
+
+	g.drawLine(24, 10, 17, 22);
+	g.drawLine(27, 10, 20, 22);
+	g.drawLine(17, 22, 20, 22);
+
+	g.drawOval(17, 25, 3, 3);
+
+	g.setColor(saved);
+	g.translate(-x, -y);
+      }
+    };
+
+  // FIXME: Uncomment when the ImageIcons are fixed.
+
+  /*  IconUIResource warningIcon, questionIcon, infoIcon, errorIcon;*/
+
+  /**
+   * Creates a new BasicOptionPaneUI object.
+   */
+  public BasicOptionPaneUI()
+  {
+  }
+
+  /**
+   * This method is messaged to add the buttons to the given container.
+   *
+   * @param container The container to add components to.
+   * @param buttons The buttons to add. (If it is an instance of component,
+   *        the Object is added directly. If it is an instance of Icon, it is
+   *        packed into a label and added. For all other cases, the string
+   *        representation of the Object is retreived and packed into a
+   *        label.)
+   * @param initialIndex The index of the component that is the initialValue.
+   */
+  protected void addButtonComponents(Container container, Object[] buttons,
+                                     int initialIndex)
+  {
+    if (buttons == null)
+      return;
+    for (int i = 0; i < buttons.length; i++)
+      {
+	if (buttons[i] != null)
+	  {
+	    Component toAdd;
+	    if (buttons[i] instanceof Component)
+	      toAdd = (Component) buttons[i];
+	    else
+	      {
+		if (buttons[i] instanceof Icon)
+		  toAdd = new JButton((Icon) buttons[i]);
+		else
+		  toAdd = new JButton(buttons[i].toString());
+		((JButton) toAdd).addActionListener(createButtonActionListener(i));
+		hasCustomComponents = true;
+	      }
+
+	    if (i == initialIndex)
+	      initialFocusComponent = toAdd;
+	    container.add(toAdd);
+	  }
+      }
+    selectInitialValue(optionPane);
+  }
+
+  /**
+   * This method adds the appropriate icon the given container.
+   *
+   * @param top The container to add an icon to.
+   */
+  protected void addIcon(Container top)
+  {
+    JLabel iconLabel = null;
+    Icon icon = getIcon();
+    if (icon != null)
+      {
+	iconLabel = new JLabel(icon);
+	top.add(iconLabel, BorderLayout.WEST);
+      }
+  }
+
+  /**
+   * A helper method that returns an instance of GridBagConstraints to be used
+   * for creating the message area.
+   *
+   * @return An instance of GridBagConstraints.
+   */
+  private static GridBagConstraints createConstraints()
+  {
+    GridBagConstraints constraints = new GridBagConstraints();
+    constraints.gridx = GridBagConstraints.REMAINDER;
+    constraints.gridy = GridBagConstraints.REMAINDER;
+    constraints.gridwidth = 0;
+    constraints.anchor = GridBagConstraints.LINE_START;
+    constraints.fill = GridBagConstraints.NONE;
+    constraints.insets = new Insets(0, 0, 3, 0);
+
+    return constraints;
+  }
+
+  /**
+   * This method creates the proper object (if necessary) to represent msg.
+   * (If msg is an instance of Component, it will add it directly. If it is
+   * an icon, then it will pack it in a label and add it. Otherwise, it gets
+   * treated as a string. If the string is longer than maxll, a box is
+   * created and the burstStringInto is called with the box as the container.
+   * The box is then added to the given container. Otherwise, the string is
+   * packed in a label and placed in the given container.) This method is
+   * also used for adding the inputComponent to the container.
+   *
+   * @param container The container to add to.
+   * @param cons The constraints when adding.
+   * @param msg The message to add.
+   * @param maxll The max line length.
+   * @param internallyCreated Whether the msg is internally created.
+   */
+  protected void addMessageComponents(Container container,
+                                      GridBagConstraints cons, Object msg,
+                                      int maxll, boolean internallyCreated)
+  {
+    if (msg == null)
+      return;
+    hasCustomComponents = internallyCreated;
+    if (msg instanceof Object[])
+      {
+	Object[] arr = (Object[]) msg;
+	for (int i = 0; i < arr.length; i++)
+	  addMessageComponents(container, cons, arr[i], maxll,
+	                       internallyCreated);
+	return;
+      }
+    else if (msg instanceof Component)
+      {
+	container.add((Component) msg, cons);
+	cons.gridy++;
+      }
+    else if (msg instanceof Icon)
+      {
+	container.add(new JLabel((Icon) msg), cons);
+	cons.gridy++;
+      }
+    else
+      {
+	// Undocumented behaviour.
+	// if msg.toString().length greater than maxll
+	// it will create a box and burst the string.
+	// otherwise, it will just create a label and re-call 
+	// this method with the label o.O
+	if (msg.toString().length() > maxll)
+	  {
+	    Box tmp = new Box(BoxLayout.Y_AXIS);
+	    burstStringInto(tmp, msg.toString(), maxll);
+	    addMessageComponents(container, cons, tmp, maxll, true);
+	  }
+	else
+	  addMessageComponents(container, cons, new JLabel(msg.toString()),
+	                       maxll, true);
+      }
+  }
+
+  /**
+   * This method creates instances of d (recursively if necessary based on
+   * maxll) and adds to c.
+   *
+   * @param c The container to add to.
+   * @param d The string to burst.
+   * @param maxll The max line length.
+   */
+  protected void burstStringInto(Container c, String d, int maxll)
   {
-     throw new Error ("Not implemented");
+    // FIXME: Verify that this is the correct behaviour.
+    // One interpretation of the spec is that this method
+    // should recursively call itself to create (and add) 
+    // JLabels to the container if the length of the String d
+    // is greater than maxll.
+    // but in practice, even with a really long string, this is 
+    // all that happens.
+    if (d == null || c == null)
+      return;
+    JLabel label = new JLabel(d);
+    c.add(label);
   }
 
+  /**
+   * This method returns true if the given JOptionPane contains custom
+   * components.
+   *
+   * @param op The JOptionPane to check.
+   *
+   * @return True if the JOptionPane contains custom components.
+   */
   public boolean containsCustomComponents(JOptionPane op)
   {
-     throw new Error ("Not implemented");
+    return hasCustomComponents;
+  }
+
+  /**
+   * This method creates a button action listener for the given button index.
+   *
+   * @param buttonIndex The index of the button in components.
+   *
+   * @return A new ButtonActionListener.
+   */
+  protected ActionListener createButtonActionListener(int buttonIndex)
+  {
+    return new ButtonActionListener(buttonIndex);
+  }
+
+  /**
+   * This method creates the button area.
+   *
+   * @return A new Button Area.
+   */
+  protected Container createButtonArea()
+  {
+    JPanel buttonPanel = new JPanel();
+
+    buttonPanel.setLayout(createLayoutManager());
+    addButtonComponents(buttonPanel, getButtons(), getInitialValueIndex());
+
+    return buttonPanel;
+  }
+
+  /**
+   * This method creates a new LayoutManager for the button area.
+   *
+   * @return A new LayoutManager for the button area.
+   */
+  protected LayoutManager createLayoutManager()
+  {
+    return new ButtonAreaLayout(getSizeButtonsToSameWidth(), 6);
+  }
+
+  /**
+   * This method creates the message area.
+   *
+   * @return A new message area.
+   */
+  protected Container createMessageArea()
+  {
+    JPanel messageArea = new JPanel();
+    messageArea.setLayout(new BorderLayout());
+    addIcon(messageArea);
+
+    JPanel rightSide = new JPanel()
+    {
+    public Dimension getPreferredSize()
+    {
+      int w = Math.max(optionPane.getSize().width,
+                       minimumWidth);
+      Insets i = optionPane.getInsets();
+      Dimension orig = super.getPreferredSize();
+      Dimension value = new Dimension(w - i.left - i.right - iconSize,
+                                      orig.height);
+      return value;
+    }
+    };    
+    rightSide.setLayout(new GridBagLayout());
+    GridBagConstraints con = createConstraints();
+
+    addMessageComponents(rightSide, con, getMessage(),
+                         getMaxCharactersPerLineCount(), false);
+
+    if (optionPane.getWantsInput())
+      {
+	Object[] selection = optionPane.getSelectionValues();
+
+	if (selection == null)
+	  inputComponent = new JTextField();
+	else if (selection.length < 20)
+	  inputComponent = new JComboBox(selection);
+	else
+	  inputComponent = new JList(selection);
+	if (inputComponent != null)
+	  {
+	    addMessageComponents(rightSide, con, inputComponent,
+	                         getMaxCharactersPerLineCount(), true);
+	    resetSelectedValue();
+	    selectInitialValue(optionPane);
+	  }
+      }
+
+    messageArea.add(rightSide, BorderLayout.EAST);
+
+    return messageArea;
+  }
+
+  /**
+   * This method creates a new PropertyChangeListener for listening to the
+   * JOptionPane.
+   *
+   * @return A new PropertyChangeListener.
+   */
+  protected PropertyChangeListener createPropertyChangeListener()
+  {
+    return new PropertyChangeHandler();
+  }
+
+  /**
+   * This method creates a Container that will separate the message and button
+   * areas.
+   *
+   * @return A Container that will separate the message and button areas.
+   */
+  protected Container createSeparator()
+  {
+    return null;
+  }
+
+  /**
+   * This method creates a new BasicOptionPaneUI for the given component.
+   *
+   * @param x The component to create a UI for.
+   *
+   * @return A new BasicOptionPaneUI.
+   */
+  public static ComponentUI createUI(JComponent x)
+  {
+    return new BasicOptionPaneUI();
+  }
+
+  /**
+   * This method returns the buttons for the JOptionPane. If no options are
+   * set, a set of options will be created based upon the optionType.
+   *
+   * @return The buttons that will be added.
+   */
+  protected Object[] getButtons()
+  {
+    if (optionPane.getOptions() != null)
+      return optionPane.getOptions();
+    switch (optionPane.getOptionType())
+      {
+      case JOptionPane.YES_NO_OPTION:
+	return new Object[] { YES_STRING, NO_STRING };
+      case JOptionPane.YES_NO_CANCEL_OPTION:
+	return new Object[] { YES_STRING, NO_STRING, CANCEL_STRING };
+      case JOptionPane.OK_CANCEL_OPTION:
+      case JOptionPane.DEFAULT_OPTION:
+	return new Object[] { OK_STRING, CANCEL_STRING };
+      }
+    return null;
+  }
+
+  /**
+   * This method will return the icon the user has set or the icon that will
+   * be used based on message type.
+   *
+   * @return The icon to use in the JOptionPane.
+   */
+  protected Icon getIcon()
+  {
+    if (optionPane.getIcon() != null)
+      return optionPane.getIcon();
+    else
+      return getIconForType(optionPane.getMessageType());
+  }
+
+  /**
+   * This method returns the icon for the given messageType.
+   *
+   * @param messageType The type of message.
+   *
+   * @return The icon for the given messageType.
+   */
+  protected Icon getIconForType(int messageType)
+  {
+    Icon tmp = null;
+    switch (messageType)
+      {
+      case JOptionPane.ERROR_MESSAGE:
+	tmp = errorIcon;
+	break;
+      case JOptionPane.INFORMATION_MESSAGE:
+	tmp = infoIcon;
+	break;
+      case JOptionPane.WARNING_MESSAGE:
+	tmp = warningIcon;
+	break;
+      case JOptionPane.QUESTION_MESSAGE:
+	tmp = questionIcon;
+	break;
+      }
+    return new IconUIResource(tmp);
+  }
+
+  /**
+   * This method returns the index of the initialValue in the options array.
+   *
+   * @return The index of the initalValue.
+   */
+  protected int getInitialValueIndex()
+  {
+    Object[] buttons = getButtons();
+
+    if (buttons == null)
+      return -1;
+
+    Object select = optionPane.getInitialValue();
+
+    for (int i = 0; i < buttons.length; i++)
+      {
+	if (select == buttons[i])
+	  return i;
+      }
+    return 0;
+  }
+
+  /**
+   * This method returns the maximum number of characters that should be
+   * placed on a line.
+   *
+   * @return The maximum number of characteres that should be placed on a
+   *         line.
+   */
+  protected int getMaxCharactersPerLineCount()
+  {
+    return optionPane.getMaxCharactersPerLineCount();
+  }
+
+  /**
+   * This method returns the maximum size.
+   *
+   * @param c The JComponent to measure.
+   *
+   * @return The maximum size.
+   */
+  public Dimension getMaximumSize(JComponent c)
+  {
+    return getPreferredSize(c);
+  }
+
+  /**
+   * This method returns the message of the JOptionPane.
+   *
+   * @return The message.
+   */
+  protected Object getMessage()
+  {
+    return optionPane.getMessage();
+  }
+
+  /**
+   * This method returns the minimum size of the JOptionPane.
+   *
+   * @return The minimum size.
+   */
+  public Dimension getMinimumOptionPaneSize()
+  {
+    return minimumSize;
+  }
+
+  /**
+   * This method returns the minimum size.
+   *
+   * @param c The JComponent to measure.
+   *
+   * @return The minimum size.
+   */
+  public Dimension getMinimumSize(JComponent c)
+  {
+    return getPreferredSize(c);
+  }
+
+  /**
+   * This method returns the preferred size of the JOptionPane. The preferred
+   * size is the maximum of the size desired by the layout and the minimum
+   * size.
+   *
+   * @param c The JComponent to measure.
+   *
+   * @return The preferred size.
+   */
+  public Dimension getPreferredSize(JComponent c)
+  {
+    Dimension d = optionPane.getLayout().preferredLayoutSize(optionPane);
+    Dimension d2 = getMinimumOptionPaneSize();
+
+    int w = Math.max(d.width, d2.width);
+    int h = Math.max(d.height, d2.height);
+    return new Dimension(w, h);
+  }
+
+  /**
+   * This method returns whether all buttons should have the same width.
+   *
+   * @return Whether all buttons should have the same width.
+   */
+  protected boolean getSizeButtonsToSameWidth()
+  {
+    return true;
+  }
+
+  /**
+   * This method installs components for the JOptionPane.
+   */
+  protected void installComponents()
+  {
+    // reset it.
+    hasCustomComponents = false;
+    Container msg = createMessageArea();
+    if (msg != null)
+      {
+	((JComponent) msg).setBorder(messageBorder);
+	msg.setForeground(messageForeground);
+	messageAreaContainer = msg;
+	optionPane.add(msg);
+      }
+
+    Container sep = createSeparator();
+    if (sep != null)
+      optionPane.add(sep);
+
+    Container button = createButtonArea();
+    if (button != null)
+      {
+	((JComponent) button).setBorder(buttonBorder);
+	buttonContainer = button;
+	optionPane.add(button);
+      }
+
+    optionPane.invalidate();
+  }
+
+  /**
+   * This method installs defaults for the JOptionPane.
+   */
+  protected void installDefaults()
+  {
+    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+
+    optionPane.setFont(defaults.getFont("OptionPane.font"));
+    optionPane.setBackground(defaults.getColor("OptionPane.background"));
+    optionPane.setForeground(defaults.getColor("OptionPane.foreground"));
+    optionPane.setBorder(defaults.getBorder("OptionPane.border"));
+
+    messageBorder = defaults.getBorder("OptionPane.messageAreaBorder");
+    messageForeground = defaults.getColor("OptionPane.messageForeground");
+    buttonBorder = defaults.getBorder("OptionPane.buttonAreaBorder");
+
+    minimumSize = defaults.getDimension("OptionPane.minimumSize");
+    minimumWidth = minimumSize.width;
+    minimumHeight = minimumSize.height;
+
+    // FIXME: Image icons don't seem to work properly right now.
+    // Once they do, replace the synthetic icons with these ones.
+
+    /*
+    warningIcon = (IconUIResource) defaults.getIcon("OptionPane.warningIcon");
+    infoIcon = (IconUIResource) defaults.getIcon("OptionPane.informationIcon");
+    errorIcon = (IconUIResource) defaults.getIcon("OptionPane.errorIcon");
+    questionIcon = (IconUIResource) defaults.getIcon("OptionPane.questionIcon");
+    */
+  }
+
+  /**
+   * This method installs keyboard actions for the JOptionpane.
+   */
+  protected void installKeyboardActions()
+  {
+    // FIXME: implement.
+  }
+
+  /**
+   * This method installs listeners for the JOptionPane.
+   */
+  protected void installListeners()
+  {
+    propertyChangeListener = createPropertyChangeListener();
+
+    optionPane.addPropertyChangeListener(propertyChangeListener);
+  }
+
+  /**
+   * This method installs the UI for the JOptionPane.
+   *
+   * @param c The JComponent to install the UI for.
+   */
+  public void installUI(JComponent c)
+  {
+    if (c instanceof JOptionPane)
+      {
+	optionPane = (JOptionPane) c;
+
+	installDefaults();
+	installComponents();
+	installListeners();
+	installKeyboardActions();
+      }
+  }
+
+  /**
+   * Changes the inputValue property in the JOptionPane based on the current
+   * value of the inputComponent.
+   */
+  protected void resetInputValue()
+  {
+    if (optionPane.getWantsInput() && inputComponent != null)
+      {
+	Object output = null;
+	if (inputComponent instanceof JTextField)
+	  output = ((JTextField) inputComponent).getText();
+	else if (inputComponent instanceof JComboBox)
+	  output = ((JComboBox) inputComponent).getSelectedItem();
+	else if (inputComponent instanceof JList)
+	  output = ((JList) inputComponent).getSelectedValue();
+
+	if (output != null)
+	  optionPane.setInputValue(output);
+      }
+  }
+
+  /**
+   * This method requests focus to the inputComponent (if one is present) and
+   * the initialFocusComponent otherwise.
+   *
+   * @param op The JOptionPane.
+   */
+  public void selectInitialValue(JOptionPane op)
+  {
+    if (inputComponent != null)
+      {
+	inputComponent.requestFocus();
+	return;
+      }
+    if (initialFocusComponent != null)
+      initialFocusComponent.requestFocus();
+  }
+
+  /**
+   * This method resets the value in the inputComponent to the
+   * initialSelectionValue property.
+   */
+  private void resetSelectedValue()
+  {
+    if (inputComponent != null)
+      {
+	Object init = optionPane.getInitialSelectionValue();
+	if (init == null)
+	  return;
+	if (inputComponent instanceof JTextField)
+	  ((JTextField) inputComponent).setText((String) init);
+	else if (inputComponent instanceof JComboBox)
+	  ((JComboBox) inputComponent).setSelectedItem(init);
+	else if (inputComponent instanceof JList)
+	  {
+	    //  ((JList) inputComponent).setSelectedValue(init, true);
+	  }
+      }
+  }
+
+  /**
+   * This method uninstalls all the components in the JOptionPane.
+   */
+  protected void uninstallComponents()
+  {
+    optionPane.removeAll();
+    buttonContainer = null;
+    messageAreaContainer = null;
+  }
+
+  /**
+   * This method uninstalls the defaults for the JOptionPane.
+   */
+  protected void uninstallDefaults()
+  {
+    optionPane.setFont(null);
+    optionPane.setForeground(null);
+    optionPane.setBackground(null);
+
+    minimumSize = null;
+
+    messageBorder = null;
+    buttonBorder = null;
+    messageForeground = null;
+
+    // FIXME: ImageIcons don't seem to work properly
+
+    /*
+    warningIcon = null;
+    errorIcon = null;
+    questionIcon = null;
+    infoIcon = null;
+    */
+  }
+
+  /**
+   * This method uninstalls keyboard actions for the JOptionPane.
+   */
+  protected void uninstallKeyboardActions()
+  {
+    // FIXME: implement.
+  }
+
+  /**
+   * This method uninstalls listeners for the JOptionPane.
+   */
+  protected void uninstallListeners()
+  {
+    optionPane.removePropertyChangeListener(propertyChangeListener);
+    propertyChangeListener = null;
+  }
+
+  /**
+   * This method uninstalls the UI for the given JComponent.
+   *
+   * @param c The JComponent to uninstall for.
+   */
+  public void uninstallUI(JComponent c)
+  {
+    uninstallKeyboardActions();
+    uninstallListeners();
+    uninstallComponents();
+    uninstallDefaults();
+
+    optionPane = null;
   }
 }


More information about the Java-patches mailing list