This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: two java.awt classes


I'm checking this in on the trunk (and not the branch).

This patch implements java.awt.Dialog and most (but not all) of
java.awt.List.

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

	* java/awt/List.java: Wrote.
	* java/awt/Dialog.java: Wrote.

Tom

Index: java/awt/Dialog.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Dialog.java,v
retrieving revision 1.1
diff -u -r1.1 Dialog.java
--- Dialog.java	2000/08/03 12:09:38	1.1
+++ Dialog.java	2001/04/21 02:45:28
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000  Free Software Foundation
+/* Copyright (C) 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -8,13 +8,155 @@
 
 package java.awt;
 
-/* A very incomplete placeholder. */
+import java.awt.peer.DialogPeer;
 
+/**
+ * @author Tom Tromey <tromey@redhat.com>
+ * @date April 17, 2001
+ */
+
 public class Dialog extends Window
 {
+  public Dialog (Dialog owner)
+  {
+    this (owner, "", false);
+  }
+
+  public Dialog (Dialog owner, String title)
+  {
+    this (owner, title, false);
+  }
+
+  public Dialog (Dialog owner, String title, boolean modal)
+  {
+    super (owner);
+    this.modal = modal;
+    this.title = title;
+    setLayout (new BorderLayout ());
+  }
+
   public Dialog (Frame owner)
   {
-    super(owner);
-    // FIXME
+    this (owner, "", false);
   }
+
+  public Dialog (Frame owner, boolean modal)
+  {
+    this (owner, "", modal);
+  }
+
+  public Dialog (Frame owner, String title)
+  {
+    this (owner, title, false);
+  }
+
+  public Dialog (Frame owner, String title, boolean modal)
+  {
+    super (owner);
+    this.modal = modal;
+    this.title = title;
+    setLayout (new BorderLayout ());
+  }
+
+  /** Create the peer if it does not already exist.  */
+  public void addNotify ()
+  {
+    if (peer == null)
+      peer = getToolkit ().createDialog (this);
+  }
+
+  public boolean isModal ()
+  {
+    return modal;
+  }
+
+  public void setModal (boolean modal)
+  {
+    this.modal = modal;
+  }
+
+  public String getTitle ()
+  {
+    return title;
+  }
+
+  public void setTitle (String title)
+  {
+    this.title = title;
+    if (peer != null)
+      {
+	DialogPeer d = (DialogPeer) peer;
+	d.setTitle (title);
+      }
+  }
+
+  public void show ()
+  {
+    boolean vis = isVisible ();
+    super.show ();
+    if (modal && vis)
+      {
+	// Don't return until something happens.  We lock on the peer
+	// instead of `this' so that we don't interfere with whatever
+	// locks the caller might want to use.
+	synchronized (peer)
+	  {
+	    try
+	      {
+		peer.wait ();
+	      }
+	    catch (InterruptedException _)
+	      {
+	      }
+	  }
+      }
+  }
+
+  public void hide ()
+  {
+    super.hide ();
+    synchronized (peer)
+      {
+	peer.notify ();
+      }
+  }
+
+  public void dispose ()
+  {
+    super.dispose ();
+    synchronized (peer)
+      {
+	peer.notify ();
+      }
+  }
+
+  public boolean isResizable ()
+  {
+    return resizable;
+  }
+
+  public void setResizable (boolean resizable)
+  {
+    this.resizable = resizable;
+    if (peer != null)
+      {
+	DialogPeer d = (DialogPeer) peer;
+	d.setResizable (resizable);
+      }
+  }
+
+  protected String paramString ()
+  {
+    return ("Dialog["
+	    + title + ","
+	    + modal + ","
+	    + resizable + "]");
+  }
+
+  // True if dialog is modal.
+  private boolean modal;
+  // True if dialog is resizable by the user.
+  private boolean resizable = false;
+  // Dialog title.
+  private String title;
 }
Index: java/awt/List.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/List.java,v
retrieving revision 1.1
diff -u -r1.1 List.java
--- List.java	2000/08/03 12:09:38	1.1
+++ List.java	2001/04/21 02:45:28
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000  Free Software Foundation
+/* Copyright (C) 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -8,8 +8,430 @@
 
 package java.awt;
 
-/* A very incomplete placeholder. */
+import java.awt.peer.ListPeer;
+import java.awt.event.*;
+import java.util.Vector;
 
-public class List extends Component
+/**
+ * @author Tom Tromey <tromey@redhat.com>
+ * @date April 17, 2001
+ * Status: incomplete
+ */
+
+public class List extends Component implements ItemSelectable
 {
+  /** Creates a new scrolling list with four rows.
+   * Initially, multiple selections are not allowed.
+   */
+  public List ()
+  {
+    this (4, false);
+  }
+
+  /** Create a new scrolling list with the indicated number of rows.
+   * Initially, multiple selections are not allowed.
+   * @param rows Number of rows
+   */
+  public List (int rows)
+  {
+    this (rows, false);
+  }
+
+  /** Create a new scrolling list with the indicated number of rows.
+   * @param rows Number of rows
+   * @param multiple True if multiple selections allowed
+   */
+  public List (int rows, boolean multiple)
+  {
+    this.rows = rows;
+    this.multipleMode = multiple;
+  }
+
+  /** Create the peer if it does not already exist.  */
+  public void addNotify ()
+  {
+    if (peer != null)
+      peer = getToolkit ().createList (this);
+  }
+
+  public int getItemCount ()
+  {
+    return items.size ();
+  }
+
+  /** @deprecated Use getItemCount() instead.  */
+  public int countItems ()
+  {
+    return getItemCount ();
+  }
+
+  public String getItem (int index)
+  {
+    return (String) items.elementAt (index);
+  }
+
+  public String[] getItems ()
+  {
+    String[] els = new String[items.size ()];
+    items.copyInto (els);
+    return els;
+  }
+
+  public void add (String item)
+  {
+    add (item, items.size ());
+  }
+
+  /** @deprecated Use add() instead.  */
+  public void addItem (String item)
+  {
+    add (item);
+  }
+
+  public void add (String item, int index)
+  {
+    items.insertElementAt (item, index);
+    if (peer != null)
+      {
+	ListPeer l = (ListPeer) peer;
+	l.add (item, index);
+      }
+  }
+
+  /** @deprecated Use add() instead.  */
+  public void addItem (String item, int index)
+  {
+    add (item, index);
+  }
+
+  public void replaceItem (String item, int index)
+  {
+    items.setElementAt (item, index);
+    // FIXME: notify peer
+  }
+
+  public void removeAll ()
+  {
+    items.clear ();
+    if (peer != null)
+      {
+	ListPeer l = (ListPeer) peer;
+	l.removeAll ();
+      }
+  }
+
+  /** @deprecated Use removeAll() instead.  */
+  public void clear ()
+  {
+    removeAll ();
+  }
+
+  public void remove (String item)
+  {
+    remove (items.indexOf (item));
+  }
+
+  public void remove (int index)
+  {
+    items.removeElementAt (index);
+    if (peer != null)
+      {
+	ListPeer l = (ListPeer) peer;
+	l.delItems (index, index);
+      }
+  }
+
+  /** @deprecated Use remove() instead.  */
+  public void delItem (int index)
+  {
+    remove (index);
+  }
+
+  public int getSelectedIndex ()
+  {
+    if (peer != null)
+      {
+	ListPeer l = (ListPeer) peer;
+	selected = l.getSelectedIndexes ();
+      }
+
+    if (selected == null || selected.length > 1)
+      return -1;
+    return selected[0];
+  }
+
+  public int[] getSelectedIndexes ()
+  {
+    if (peer != null)
+      {
+	ListPeer l = (ListPeer) peer;
+	selected = l.getSelectedIndexes ();
+      }
+    return selected;
+  }
+
+  public String getSelectedItem ()
+  {
+    int i = getSelectedIndex ();
+    return i == -1 ? null : (String) items.elementAt (i);
+  }
+
+  public String[] getSelectedItems ()
+  {
+    int[] is = getSelectedIndexes ();
+    if (is == null)
+      return null;
+    String[] r = new String[is.length];
+    for (int i = 0; i < is.length; ++i)
+      r[i] = (String) items.elementAt (is[i]);
+    return r;
+  }
+
+  public Object[] getSelectedObjects ()
+  {
+    return getSelectedItems ();
+  }
+
+  public void select (int index)
+  {
+    if (peer != null)
+      {
+	ListPeer l = (ListPeer) peer;
+	l.select (index);
+      }
+    else if (selected == null)
+      {
+	selected = new int[1];
+	selected[0] = index;
+      }
+    else
+      {
+	int i;
+	for (i = 0; i < selected.length; ++i)
+	  {
+	    if (selected[i] == index)
+	      return;
+	    if (selected[i] > index)
+	      break;
+	  }
+
+	int[] ns = new int[selected.length + 1];
+	System.arraycopy (selected, 0, ns, 0, i);
+	ns[i] = index;
+	System.arraycopy (selected, i, ns, i + 1, selected.length - i);
+
+	selected = ns;
+      }
+  }
+
+  public void deselect (int index)
+  {
+    if (peer != null)
+      {
+	ListPeer l = (ListPeer) peer;
+	l.deselect (index);
+      }
+    else if (selected != null)
+      {
+	int i;
+	for (i = 0; i < selected.length; ++i)
+	  {
+	    if (selected[i] == index)
+	      break;
+	  }
+	if (i < selected.length)
+	  {
+	    int[] ns = new int[selected.length - 1];
+	    System.arraycopy (selected, 0, ns, 0, i);
+	    System.arraycopy (selected, i + 1, ns, i, selected.length - i);
+	    selected = ns;
+	  }
+      }
+  }
+
+  public boolean isIndexSelected (int index)
+  {
+    int[] is = getSelectedIndexes ();
+    for (int i = 0; i < is.length; ++i)
+      {
+	if (is[i] == index)
+	  return true;
+      }
+    return false;
+  }
+
+  /** @deprecated Use isIndexSelected().  */
+  public boolean isSelected (int index)
+  {
+    return isIndexSelected (index);
+  }
+
+  public int getRows ()
+  {
+    return rows;
+  }
+
+  public boolean isMultipleMode ()
+  {
+    return multipleMode;
+  }
+
+  /** @deprecated Use isMultipleMode().  */
+  public boolean allowsMultipleSelections ()
+  {
+    return isMultipleMode ();
+  }
+
+  public void setMultipleMode (boolean multiple)
+  {
+    this.multipleMode = multiple;
+    if (peer != null)
+      {
+	ListPeer l = (ListPeer) peer;
+	l.setMultipleMode (multiple);
+      }
+  }
+
+  /** @deprecated Use setMultipleMode().  */
+  public void setMultipleSelections (boolean multiple)
+  {
+    setMultipleMode (multiple);
+  }
+
+  public int getVisibleIndex ()
+  {
+    return visibleIndex;
+  }
+
+  public void makeVisible (int index)
+  {
+    visibleIndex = index;
+    if (peer != null)
+      {
+	ListPeer l = (ListPeer) peer;
+	l.makeVisible (index);
+      }
+  }
+
+  public Dimension getPreferredSize (int rows)
+  {
+    return null;		// FIXME
+  }
+
+  /** @deprecated Use getPreferredSize(int).  */
+  public Dimension preferredSize (int rows)
+  {
+    return getPreferredSize (rows);
+  }
+
+  public Dimension getPreferredSize ()
+  {
+    return null;		// FIXME
+  }
+
+  /** @deprecated Use getPreferredSize().  */
+  public Dimension preferredSize ()
+  {
+    return getPreferredSize ();
+  }
+
+  public Dimension getMinimumSize (int rows)
+  {
+    return null;		// FIXME
+  }
+
+  /** @deprecated Use getMinimumSize(int).  */
+  public Dimension minimumSize (int rows)
+  {
+    return getMinimumSize (rows);
+  }
+  
+  public Dimension getMinimumSize ()
+  {
+    return null;		// FIXME
+  }
+
+  /** @deprecated Use getMinimumSize().  */
+  public Dimension minimumSize ()
+  {
+    return getMinimumSize ();
+  }
+
+  public void addItemListener (ItemListener listen)
+  {
+    item_listeners = AWTEventMulticaster.add (item_listeners, listen);
+  }
+
+  public void removeItemListener (ItemListener listen)
+  {
+    item_listeners = AWTEventMulticaster.remove (item_listeners, listen);
+  }
+
+  public void addActionListener (ActionListener listen)
+  {
+    action_listeners = AWTEventMulticaster.add (action_listeners, listen);
+  }
+
+  public void removeActionListener (ActionListener listen)
+  {
+    action_listeners = AWTEventMulticaster.remove (action_listeners, listen);
+  }
+
+  protected void processEvent (AWTEvent e)
+  {
+    if (e instanceof ItemEvent)
+      processItemEvent ((ItemEvent) e);
+    else if (e instanceof ActionEvent)
+      processActionEvent ((ActionEvent) e);
+    else
+      super.processEvent (e);
+  }
+
+  protected void processItemEvent (ItemEvent e)
+  {
+    if (item_listeners != null)
+      item_listeners.itemStateChanged (e);
+  }
+
+  protected void processActionEvent (ActionEvent e)
+  {
+    if (action_listeners != null)
+      action_listeners.actionPerformed (e);
+  }
+
+  protected String paramString ()
+  {
+    return ("List[multiple=" + multipleMode
+	    + ",rows=" + rows
+	    + "]");
+  }
+
+  /** @deprecated */
+  public void delItems (int start, int end)
+  {
+    for (int i = end; i >= start; --i)
+      items.removeElementAt (i);
+    if (peer != null)
+      {
+	ListPeer l = (ListPeer) peer;
+	l.delItems (start, end);
+      }
+  }
+
+  // Vector of items in the list.
+  private Vector items;
+  // True if multiple selection mode enabled.
+  private boolean multipleMode;
+  // Number of rows.
+  private int rows;
+  // Array of indices of selected items.  When there is no peer, we
+  // maintain this in place.  When there is a peer, the peer maintains
+  // the list and we ask for it whenever needed.
+  private int[] selected;
+  // Value used by makeVisible().
+  private int visibleIndex;
+
+  // Listeners.
+  private ActionListener action_listeners;
+  private ItemListener item_listeners;
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]