ucb.gui
Class TopLevel

java.lang.Object
  extended by ucb.gui.TopLevel
All Implemented Interfaces:
ActionListener, EventListener

public class TopLevel
extends Object
implements ActionListener

A top-level window with optional menu bar. A TopLevel primarily exists to contain Widgets. The general technique is to extend TopLevel. Most of the methods here are protected: the intent is that any calls to them are from within your extension class, thus allowing the latter to retain control over its size, menu, etc.


Constructor Summary
protected TopLevel(String title, boolean exitOnClose)
          A new TopLevel with the given TITLE (which window managers typically display on the border).
 
Method Summary
 void actionPerformed(ActionEvent e)
           
protected  void add(Widget widget, LayoutSpec layout)
          Add a new Widget, placed according to LAYOUT.
protected  void addButton(String label, Object receiver, String funcName, LayoutSpec layout)
          Add a new button displaying LABEL, laid out according to LAYOUT, which when clicked calls the method named FUNCNAME of RECEIVER with LABEL as its single String argument.
protected  void addButton(String label, String funcName, LayoutSpec layout)
          Add a new button displaying LABEL, placed according to LAYOUT, which when clicked calls my method named FUNCNAME with LABEL as its single String argument.
protected  void addLabel(String text, LayoutSpec layout)
          Add a new, anonymous label that displays the text TEXT, placed according to LAYOUT.
protected  void addLabel(String text, String id, LayoutSpec layout)
          Add a label that initially displays the text TEXT, placed according to LAYOUT, and identified by the tag ID.
protected  void addMenuButton(String label, Object receiver, String funcName)
          Add a new simple menu button labeled LABEL to my menus, which when clicked, invokes a method named FUNCNAME on RECEIVER, sending LABEL as data.
protected  void addMenuButton(String label, String funcName)
          Add a new simple menu button labeled LABEL to my menus, which when clicked invokes a function named FUNCNAME on me, sending LABEL as data.
protected  void addMenuRadioButton(String label, String groupName, boolean selected, Object receiver, String funcName)
          Add a radio button labeled LABEL to my menus, belonging to the group of buttons called GROUPNAME.
protected  void addMenuRadioButton(String label, String groupName, boolean selected, String funcName)
          Add a radio button labeled LABEL to my menus, belonging to the group of buttons called GROUPNAME.
protected  void addSeparator(String label)
          Add a separator to the end of the menu labeled LABEL (which must exist) in my menu bar.
 void display(boolean visible)
          If VISIBLE, display this TopLevel.
 int getHeight()
          My current height in pixels.
 String getTextInput(String message, String title, String type, String init)
          Display a dialog box with message MESSAGE and title TITLE that prompts the user for textual input, with INIT providing the initial value of the text.
 int getWidth()
          My current width in pixels.
protected  boolean isSelected(String label)
          True iff the button named LABEL is currently selected.
protected  void select(String label, boolean val)
          Set isSelected (LABEL) to VAL, if LABEL is a valid button.
protected  void setEnabled(boolean enable, String... labels)
          Set the enabled status of the buttons labeled LABELS[0], ...
protected  void setLabel(String id, String text)
          Set the text of the existing label with tag ID to TEXT.
protected  void setMaximumSize(int width, int height)
          Set my maximum size to WIDTHxHEIGHT pixels.
protected  void setMinimumSize(int width, int height)
          Set my minimum size to WIDTHxHEIGHT pixels.
protected  void setPreferredSize(int width, int height)
          Set my preferred size to WIDTHxHEIGHT pixels.
 void showMessage(String text, String title, String type)
          Display the dismissable message TEXT of type TYPE in a separate dialog window with title TITLE.
 int showOptions(String message, String title, String type, String deflt, String... labels)
          Display a choice of optional responses, labeled LABELS0,...,LABELSn in a separate dialog box with title TITLE and message MESSAGE.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TopLevel

protected TopLevel(String title,
                   boolean exitOnClose)
A new TopLevel with the given TITLE (which window managers typically display on the border). If EXITONCLOSE, then closing this window exits the application.

Method Detail

display

public void display(boolean visible)
If VISIBLE, display this TopLevel. Otherwise, make it invisible.


setPreferredSize

protected void setPreferredSize(int width,
                                int height)
Set my preferred size to WIDTHxHEIGHT pixels.


setMinimumSize

protected void setMinimumSize(int width,
                              int height)
Set my minimum size to WIDTHxHEIGHT pixels.


setMaximumSize

protected void setMaximumSize(int width,
                              int height)
Set my maximum size to WIDTHxHEIGHT pixels.


getWidth

public int getWidth()
My current width in pixels.


getHeight

public int getHeight()
My current height in pixels.


addMenuButton

protected void addMenuButton(String label,
                             Object receiver,
                             String funcName)
Add a new simple menu button labeled LABEL to my menus, which when clicked, invokes a method named FUNCNAME on RECEIVER, sending LABEL as data. LABEL has the form MENUNAME->SUBMENU1->...SUBMENUn->NAME, where n >= 0, (for example, "File->Open" or "File->New->Project"). This label denotes "the item labeled NAME in the submenu named SUBMENUn in the ... in the menu-bar entry MENUNAME. FUNCNAME is the simple name of a method of the object RECEIVER whose signature is void FUNCNAME (String label). The new button appears at the end of its menu. Likewise, any previously non-existing menus get created at the end of the menu bar or their containing menu.


addMenuButton

protected void addMenuButton(String label,
                             String funcName)
Add a new simple menu button labeled LABEL to my menus, which when clicked invokes a function named FUNCNAME on me, sending LABEL as data.


addMenuRadioButton

protected void addMenuRadioButton(String label,
                                  String groupName,
                                  boolean selected,
                                  Object receiver,
                                  String funcName)
Add a radio button labeled LABEL to my menus, belonging to the group of buttons called GROUPNAME. Initially, the button is selected iff SELECTED. Only one radio button in a group is selected at a time (see @{item #isSelected}); when the user clicks one, it becomes selected and any other button in the group is deselected. If FUNCNAME is non-null, the method of that name is invoked on RECEIVER, sending LABEL as its argument.


addMenuRadioButton

protected void addMenuRadioButton(String label,
                                  String groupName,
                                  boolean selected,
                                  String funcName)
Add a radio button labeled LABEL to my menus, belonging to the group of buttons called GROUPNAME. Initially, the button is selected iff SELECTED. Only one radio button in a group is selected at a time (see @{item #isSelected}); when the user clicks one, it becomes selected and any other button in the group is deselected. If FUNCNAME is non-null, the method of that name is invoked on RECEIVER, sending LABEL as its argument.


addSeparator

protected void addSeparator(String label)
Add a separator to the end of the menu labeled LABEL (which must exist) in my menu bar. LABEL has the form MENUNAME->SUBMENU1->...->SUBMENUn.


isSelected

protected boolean isSelected(String label)
True iff the button named LABEL is currently selected.


select

protected void select(String label,
                      boolean val)
Set isSelected (LABEL) to VAL, if LABEL is a valid button.


setEnabled

protected void setEnabled(boolean enable,
                          String... labels)
Set the enabled status of the buttons labeled LABELS[0], ... to ENABLE. An ENABLE value of false causes the buttons to become unresponsive, typically displaying as being grayed out.


addButton

protected void addButton(String label,
                         Object receiver,
                         String funcName,
                         LayoutSpec layout)
Add a new button displaying LABEL, laid out according to LAYOUT, which when clicked calls the method named FUNCNAME of RECEIVER with LABEL as its single String argument.


addButton

protected void addButton(String label,
                         String funcName,
                         LayoutSpec layout)
Add a new button displaying LABEL, placed according to LAYOUT, which when clicked calls my method named FUNCNAME with LABEL as its single String argument.


add

protected void add(Widget widget,
                   LayoutSpec layout)
Add a new Widget, placed according to LAYOUT.


addLabel

protected void addLabel(String text,
                        String id,
                        LayoutSpec layout)
Add a label that initially displays the text TEXT, placed according to LAYOUT, and identified by the tag ID. If a label with the same ID already exists, its text is altered to TEXT.


setLabel

protected void setLabel(String id,
                        String text)
Set the text of the existing label with tag ID to TEXT.


addLabel

protected void addLabel(String text,
                        LayoutSpec layout)
Add a new, anonymous label that displays the text TEXT, placed according to LAYOUT.


showMessage

public void showMessage(String text,
                        String title,
                        String type)
Display the dismissable message TEXT of type TYPE in a separate dialog window with title TITLE. TYPE may be any of the strings "information", "warning", "error", or "plain", which modify the look of the message.


showOptions

public int showOptions(String message,
                       String title,
                       String type,
                       String deflt,
                       String... labels)
Display a choice of optional responses, labeled LABELS0,...,LABELSn in a separate dialog box with title TITLE and message MESSAGE. Returns the selected option (0 -- n), or -1 if the user closes the dialog window. DEFLT is the default label (may be null). TYPE may be "question", "information", "warning", "error", or "plain".


getTextInput

public String getTextInput(String message,
                           String title,
                           String type,
                           String init)
Display a dialog box with message MESSAGE and title TITLE that prompts the user for textual input, with INIT providing the initial value of the text. TYPE may be "question", "information", "warning", "error", or "plain". The user's input text is returned, or null if the user closes the dialog window.


actionPerformed

public void actionPerformed(ActionEvent e)
Specified by:
actionPerformed in interface ActionListener