Package ucb.gui2
Class TopLevel
java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Window
java.awt.Frame
javax.swing.JFrame
ucb.gui2.TopLevel
- All Implemented Interfaces:
ActionListener
,ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
,RootPaneContainer
,WindowConstants
A top-level window with optional menu bar. The general technique to use
it is by extension. Many 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.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JFrame
JFrame.AccessibleJFrame
Nested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow, Window.Type
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields inherited from class javax.swing.JFrame
accessibleContext, rootPane, rootPaneCheckingEnabled
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
void
add
(Component component, LayoutSpec layout) protected void
addButton
(String label, Consumer<String> func, LayoutSpec layout) Add a new button displaying LABEL, laid out according to LAYOUT, which when clicked calls FUNC, with the button and LABEL as its arguments.protected void
addCheckBox
(String label, boolean selected, Consumer<String> func, LayoutSpec layout) Add a new check box displaying LABEL, laid out according to LAYOUT, which when clicked calls FUNC, with the button and LABEL as its arguments.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
addLabel
(String text, LayoutSpec layout) Add a new, anonymous label that displays the text TEXT, placed according to LAYOUT.protected void
addMenuButton
(String label, Consumer<String> func) Add a new simple menu button labeled LABEL to my menus, which when clicked, invokes FUNC, sending LABEL as argument.protected void
addMenuCheckBox
(String label, boolean selected, Consumer<String> func) Add a check box labeled LABEL to my menus, which when clicked, flips its state and invokes FUNC, sending LABEL as arguments.protected void
addMenuRadioButton
(String label, String groupName, boolean selected, Consumer<String> func) Add a radio button labeled LABEL to my menus, belonging to the group of buttons called GROUPNAME.protected void
addRadioButton
(String label, String groupName, boolean selected, Consumer<String> func, LayoutSpec layout) Add a radio button labeled LABEL, placed according to LAYOUT, 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.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.String[]
getTextInputs
(String topMessage, String title, String type, int textWidth, String... requests) Display a dialog box that requests and returns input from multiple text fields.protected boolean
isSelected
(String label) Return true iff the button named LABEL is currently selected.protected void
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
Set the text of the existing label with tag ID to TEXT.void
setPreferredFocus
(JComponent widget) When the focus is in my window, request that WIDGET, which should be one of my components, get the focus.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
Display a choice of optional responses, labeled LABELS[0],...,LABELS[n] in a separate dialog box with title TITLE and message MESSAGE.Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecorated
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFront
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
-
Constructor Details
-
TopLevel
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 Details
-
display
public void display(boolean visible) If VISIBLE, display this TopLevel. Otherwise, make it invisible. -
addMenuButton
Add a new simple menu button labeled LABEL to my menus, which when clicked, invokes FUNC, sending LABEL as argument. A null value of FUNC indicates no action. 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. 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. -
addMenuCheckBox
Add a check box labeled LABEL to my menus, which when clicked, flips its state and invokes FUNC, sending LABEL as arguments. LABEL is as for addMenuButton. The box is initially checked iff CHECKED. A null value of FUNC indicates no action (aside from changing selection state). -
addMenuRadioButton
protected void addMenuRadioButton(String label, String groupName, boolean selected, Consumer<String> func) 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 (seeisSelected(java.lang.String)
); when the user clicks one, it becomes selected and any other button in the group is deselected. If FUNC is non-null, it denotes a function that is invoked when the button is pressed, sending LABEL as its argument. -
addSeparator
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
Return true iff the button named LABEL is currently selected. -
select
Set isSelected(LABEL) to VAL, if LABEL is a valid button. -
setEnabled
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. -
add
-
addButton
Add a new button displaying LABEL, laid out according to LAYOUT, which when clicked calls FUNC, with the button and LABEL as its arguments. -
addCheckBox
protected void addCheckBox(String label, boolean selected, Consumer<String> func, LayoutSpec layout) Add a new check box displaying LABEL, laid out according to LAYOUT, which when clicked calls FUNC, with the button and LABEL as its arguments. It is initially selected iff SELECTED. -
addRadioButton
protected void addRadioButton(String label, String groupName, boolean selected, Consumer<String> func, LayoutSpec layout) Add a radio button labeled LABEL, placed according to LAYOUT, 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 (seeisSelected(java.lang.String)
); when the user clicks one, it becomes selected and any other button in the group is deselected. If FUNC is non-null, FUNC is invoked when pressed, sending the LABEL as argument. -
addLabel
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
Set the text of the existing label with tag ID to TEXT. -
addLabel
Add a new, anonymous label that displays the text TEXT, placed according to LAYOUT. -
showMessage
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
Display a choice of optional responses, labeled LABELS[0],...,LABELS[n] 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
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". Return the user's input text, or null if the user closes the dialog window. -
getTextInputs
public String[] getTextInputs(String topMessage, String title, String type, int textWidth, String... requests) Display a dialog box that requests and returns input from multiple text fields. TITLE is the title of the dialog window. TOPMESSAGE is a message placed above the input entries. TYPE may be "question", "information", "warning", "error", or "plain", indicating the style of dialog desired. TEXTWIDTH is the common width of the text input fields. REQUESTS is a non-empty, even-length sequence containing pairs label, init, where label gives the text placed to the right of a text input area, and init is that area's initial contents (may be null). Returns the users responses in the order their specifications appear in REQUESTS, or null if the user cancels the request. -
setPreferredFocus
When the focus is in my window, request that WIDGET, which should be one of my components, get the focus. -
actionPerformed
- Specified by:
actionPerformed
in interfaceActionListener
-