mdh.hephaestus2.gamelib
Class MetaDialog

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Dialog
                          |
                          +--mdh.hephaestus2.gamelib.MetaDialog
All Implemented Interfaces:
Accessible, ActionListener, EventListener, FocusListener, ImageObserver, KeyListener, MenuContainer, Serializable

public class MetaDialog
extends Dialog
implements ActionListener, KeyListener, FocusListener

A generalized input dialog. This can contain multiple user-specified components, has variable button handling, and can position itself over a specified component (like a pop-up action for a button), at a given coordinate, or centered over the parent frame. When a button is pressed, the button # is remembered and the dialog is hidden, thus returning to the calling code. If an internal component sends its action events to the dialog, and they're parseable integers, the value is used as the 'button'. The buttons at the bottom are already numbered 0..nbuttons.

Author:
Copyright © 2000 by Mark Hughes <kamikaze@kuoi.asui.uidaho.edu>
See Also:
Serialized Form

Field Summary
static int MIN_HEIGHT
           
static int MIN_WIDTH
           
static int POS_CENTER
          Values for position
static int POS_EAST
           
static int POS_NORTH
           
static int POS_NORTHEAST
           
static int POS_NORTHWEST
           
static int POS_RANDOM
           
static int POS_RELATIVE
           
static int POS_SOUTH
           
static int POS_SOUTHEAST
           
static int POS_SOUTHWEST
           
static int POS_WEST
           
 
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
 
Constructor Summary
MetaDialog(Frame frame, String title, boolean modal, LayoutManager layout, int position, String buttons)
           
MetaDialog(Frame frame, String title, boolean modal, LayoutManager layout, int position, String buttons, int defaultButton, int cancelButton)
          Creates a new MetaDialog.
 
Method Summary
 void actionPerformed(ActionEvent ae)
           
 void addComponent(Component comp)
           
 void addNotify()
           
 void addPrompt(String key, String label, Component prompt)
           
 void addPrompt(String key, String label, Component prompt, boolean addListeners)
          Adds a 'prompt' component, with an optional text label to its left.
 void addText(String text)
          Adds a line of text to the component.
 void focusGained(FocusEvent fe)
           
 void focusLost(FocusEvent fe)
           
 int getButton()
           
 Dimension getMaximumSize()
           
 Dimension getMinimumSize()
           
 int getPosition()
           
 Dimension getPreferredSize()
           
 Component getPrompt(String key)
           
 String getText(String key)
           
 void keyPressed(KeyEvent ke)
           
 void keyReleased(KeyEvent ke)
           
 void keyTyped(KeyEvent ke)
           
 void setIcon(Image icon)
           
 void setPosition(int pos)
          Called automatically by setVisible(), but can also be invoked directly to move the viewer around.
 void setRelative(Component comp)
           
 void setRelativePosition(Component comp, int dx, int dy)
           
 void show()
          Centers the dialog over the parent frame
 
Methods inherited from class java.awt.Dialog
dispose, getAccessibleContext, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setResizable, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, 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, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_WIDTH

public static final int MIN_WIDTH
See Also:
Constant Field Values

MIN_HEIGHT

public static final int MIN_HEIGHT
See Also:
Constant Field Values

POS_CENTER

public static final int POS_CENTER
Values for position

See Also:
Constant Field Values

POS_NORTH

public static final int POS_NORTH
See Also:
Constant Field Values

POS_NORTHEAST

public static final int POS_NORTHEAST
See Also:
Constant Field Values

POS_EAST

public static final int POS_EAST
See Also:
Constant Field Values

POS_SOUTHEAST

public static final int POS_SOUTHEAST
See Also:
Constant Field Values

POS_SOUTH

public static final int POS_SOUTH
See Also:
Constant Field Values

POS_SOUTHWEST

public static final int POS_SOUTHWEST
See Also:
Constant Field Values

POS_WEST

public static final int POS_WEST
See Also:
Constant Field Values

POS_NORTHWEST

public static final int POS_NORTHWEST
See Also:
Constant Field Values

POS_RELATIVE

public static final int POS_RELATIVE
See Also:
Constant Field Values

POS_RANDOM

public static final int POS_RANDOM
See Also:
Constant Field Values
Constructor Detail

MetaDialog

public MetaDialog(Frame frame,
                  String title,
                  boolean modal,
                  LayoutManager layout,
                  int position,
                  String buttons,
                  int defaultButton,
                  int cancelButton)
Creates a new MetaDialog.

Parameters:
frame - Parent frame.
title - Title of the dialog.
modal - Is this a modal dialog?
position - Where should the dialog be displayed? One of the POS_* constants. If you setRelative, the position is relative to that component rather than the entire screen.
layout - Layout manager to use for the central area, where your prompt components will go. If you pass 'null' for layout, a one-column, unlimited-row GridLayout will be used.
buttons - Text of the buttons for the bottom of the screen, each divided by a "|" character. If you pass 'null' for buttons, "OK" will be used.
defaultButton - Default button number, 0-indexed
cancelButton - Cancel button number, 0-indexed

MetaDialog

public MetaDialog(Frame frame,
                  String title,
                  boolean modal,
                  LayoutManager layout,
                  int position,
                  String buttons)
Method Detail

actionPerformed

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

addNotify

public void addNotify()
Overrides:
addNotify in class Dialog

addPrompt

public void addPrompt(String key,
                      String label,
                      Component prompt,
                      boolean addListeners)
Adds a 'prompt' component, with an optional text label to its left.

Parameters:
key - key to retrieve the prompt with later.
label - text label to precede the prompt
prompt - any AWT component.

addPrompt

public void addPrompt(String key,
                      String label,
                      Component prompt)

addComponent

public void addComponent(Component comp)

addText

public void addText(String text)
Adds a line of text to the component.


getButton

public int getButton()
Returns:
the 0-based index of the button pressed to dismiss the dialog, or -1 if the dialog has not been dismissed yet or an error occurred.

getPosition

public int getPosition()
Returns:
Current position relative to the parent window, one of the POS_* values above.

getPreferredSize

public Dimension getPreferredSize()
Overrides:
getPreferredSize in class Container

getMaximumSize

public Dimension getMaximumSize()
Overrides:
getMaximumSize in class Container

getMinimumSize

public Dimension getMinimumSize()
Overrides:
getMinimumSize in class Container

getPrompt

public Component getPrompt(String key)
Returns:
the prompt stored earlier under 'key'.

getText

public String getText(String key)
Returns:
the text contained in a TextComponent prompt.

keyPressed

public void keyPressed(KeyEvent ke)
Specified by:
keyPressed in interface KeyListener

keyReleased

public void keyReleased(KeyEvent ke)
Specified by:
keyReleased in interface KeyListener

keyTyped

public void keyTyped(KeyEvent ke)
Specified by:
keyTyped in interface KeyListener

setIcon

public void setIcon(Image icon)

setPosition

public void setPosition(int pos)
Called automatically by setVisible(), but can also be invoked directly to move the viewer around.


setRelative

public void setRelative(Component comp)

setRelativePosition

public void setRelativePosition(Component comp,
                                int dx,
                                int dy)

show

public void show()
Centers the dialog over the parent frame

Overrides:
show in class Dialog

focusGained

public void focusGained(FocusEvent fe)
Specified by:
focusGained in interface FocusListener

focusLost

public void focusLost(FocusEvent fe)
Specified by:
focusLost in interface FocusListener