edu.rice.cs.drjava.ui.predictive
Class PredictiveInputFrame<T extends Comparable<? super T>>

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by edu.rice.cs.util.swing.SwingFrame
                          extended by edu.rice.cs.drjava.ui.predictive.PredictiveInputFrame<T>
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class PredictiveInputFrame<T extends Comparable<? super T>>
extends SwingFrame

Frame with predictive string input based on a list of strings.

See Also:
Serialized Form

Nested Class Summary
static interface PredictiveInputFrame.CloseAction<X extends Comparable<? super X>>
          Interface for an action to be performed when the user closes the frame, either by using "OK" or "Cancel".
static class PredictiveInputFrame.FrameState
          Class to save the frame state, i.e.
static interface PredictiveInputFrame.InfoSupplier<X>
          Interface that is used to generate additional information about an item.
private  class PredictiveInputFrame.PredictiveInputListener
          Listener for several events.
 
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
 
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
private  ArrayList<PredictiveInputFrame.CloseAction<T>> _actions
          Action to be performed when the user closes the frame using "OK".
private  String _buttonPressed
          Code for the last button that was pressed.
private  JButton[] _buttons
          Action buttons.
private  int _cancelIndex
          The index in the _actions list that cancels the dialog.
private  PredictiveInputModel.MatchingStrategy<T> _currentStrategy
          Currently used strategy.
private  boolean _force
          True if the user is forced to select one of the items.
private  PredictiveInputFrame.InfoSupplier<? super T> _info
          Info supplier.
private  JLabel _infoLabel
          Text area for additional information.
private  PredictiveInputFrame.FrameState _lastState
          Last frame state.
private  PredictiveInputFrame.PredictiveInputListener _listener
          Listener for several events.
private  JList _matchList
          List with matches.
protected  JComponent[] _optionalComponents
          Optional components for the _optionsPanel.
protected  JPanel _optionsPanel
          Panel for additional options.
private  SwingFrame _owner
          Owner frame.
private  PredictiveInputModel<T> _pim
          Predictive input model
private  JLabel _sharedExtLabel
          Label with shared extension.
private  List<PredictiveInputModel.MatchingStrategy<T>> _strategies
          Array of strategies.
private  JComboBox _strategyBox
          Combo box.
private  JLabel _tabCompletesLabel
          Label with "Tab completes:" string.
private  JTextField _textField
          Text field for string input.
protected  Runnable1<WindowEvent> CANCEL
          Runnable that calls _cancel.
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, 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 javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PredictiveInputFrame(SwingFrame owner, String title, boolean force, boolean ignoreCase, PredictiveInputFrame.InfoSupplier<? super T> info, List<PredictiveInputModel.MatchingStrategy<T>> strategies, List<PredictiveInputFrame.CloseAction<T>> actions, int cancelIndex, Collection<T> items)
          Create a new predictive string input frame.
PredictiveInputFrame(SwingFrame owner, String title, boolean force, boolean ignoreCase, PredictiveInputFrame.InfoSupplier<? super T> info, List<PredictiveInputModel.MatchingStrategy<T>> strategies, List<PredictiveInputFrame.CloseAction<T>> actions, int cancelIndex, T... items)
          Create a new predictive string input frame.
 
Method Summary
private  void _setupOptionsPanel(JComponent[] components)
          Creates the panel with the optional components.
private  void addListener()
          Add the listener.
private  void buttonPressed(PredictiveInputFrame.CloseAction<T> a)
          Handle button pressed.
private  void cancel()
          Cancel the dialog.
 String getButtonPressed()
          Return the name for the last button that was pressed.
 PredictiveInputFrame.FrameState getFrameState()
          Returns the last state of the frame, i.e.
 T getItem()
          Return the item that was selected or null the user entered a mask not in the list and force == false.
 List<T> getItems()
          Return a copy of the list of items in the model.
 String getMask()
          Return the raw, unforced text in the text field.
 String getText()
          Return the string that was entered in the text field.
private  void init(boolean info)
          Initialize the frame.
protected  JComponent[] makeOptions()
          Creates the optional components.
private  void removeListener()
          Remove the listener.
 void resetFocus()
          Focus back in the text field.
 void selectStrategy()
          Select the strategy for matching.
 void setCurrentItem(T item)
          Set the currently selected item.
 void setFrameState(PredictiveInputFrame.FrameState ds)
          Sets state of the frame, i.e.
 void setFrameState(String s)
          Sets state of the frame, i.e.
 void setItems(boolean ignoreCase, Collection<T> items)
          Set the items.
 void setItems(boolean ignoreCase, T... items)
          Set the items.
 void setMask(String mask)
          Set the mask in the text field.
 void setModel(boolean ignoreCase, PredictiveInputModel<T> pim)
          Set the predictive input model.
 void setOwnerEnabled(boolean b)
          Enable or disable owner.
 void setVisible(boolean vis)
          Toggle visibility of this frame.
private  void updateExtensionLabel()
          Update the extension label based on the model.
private  void updateInfo()
          Update the information.
private  void updateList()
          Update the match list based on the model.
private  void updateTextField()
          Update the text field based on the model.
 
Methods inherited from class edu.rice.cs.util.swing.SwingFrame
duringInit, initDone
 
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, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, 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, transferFocusBackward, 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, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, 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, isMaximumSizeSet, isMinimumSizeSet, isOpaque, 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, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, 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
 

Field Detail

_pim

private volatile PredictiveInputModel<T extends Comparable<? super T>> _pim
Predictive input model


_buttonPressed

private volatile String _buttonPressed
Code for the last button that was pressed.


_buttons

private final JButton[] _buttons
Action buttons.


_textField

private final JTextField _textField
Text field for string input.


_optionsPanel

protected JPanel _optionsPanel
Panel for additional options.


_optionalComponents

protected JComponent[] _optionalComponents
Optional components for the _optionsPanel.


_tabCompletesLabel

private final JLabel _tabCompletesLabel
Label with "Tab completes:" string.


_matchList

private final JList _matchList
List with matches.


_force

private final boolean _force
True if the user is forced to select one of the items.


_sharedExtLabel

private final JLabel _sharedExtLabel
Label with shared extension.


_listener

private final PredictiveInputFrame.PredictiveInputListener _listener
Listener for several events.


_info

private final PredictiveInputFrame.InfoSupplier<? super T extends Comparable<? super T>> _info
Info supplier.


_infoLabel

private final JLabel _infoLabel
Text area for additional information.


_owner

private final SwingFrame _owner
Owner frame.


_actions

private final ArrayList<PredictiveInputFrame.CloseAction<T extends Comparable<? super T>>> _actions
Action to be performed when the user closes the frame using "OK".


_cancelIndex

private final int _cancelIndex
The index in the _actions list that cancels the dialog.


_strategies

private final List<PredictiveInputModel.MatchingStrategy<T extends Comparable<? super T>>> _strategies
Array of strategies.


_strategyBox

private final JComboBox _strategyBox
Combo box.


_lastState

private volatile PredictiveInputFrame.FrameState _lastState
Last frame state. It can be stored and restored.


_currentStrategy

private volatile PredictiveInputModel.MatchingStrategy<T extends Comparable<? super T>> _currentStrategy
Currently used strategy.


CANCEL

protected final Runnable1<WindowEvent> CANCEL
Runnable that calls _cancel.

Constructor Detail

PredictiveInputFrame

public PredictiveInputFrame(SwingFrame owner,
                            String title,
                            boolean force,
                            boolean ignoreCase,
                            PredictiveInputFrame.InfoSupplier<? super T> info,
                            List<PredictiveInputModel.MatchingStrategy<T>> strategies,
                            List<PredictiveInputFrame.CloseAction<T>> actions,
                            int cancelIndex,
                            Collection<T> items)
Create a new predictive string input frame.

Parameters:
owner - owner frame
force - true if the user is forced to select one of the items
ignoreCase - true if case should be ignored
info - information supplier to use for additional information display
strategies - array of matching strategies
actions - actions to be performed when the user closes the frame, e.g. "OK" and "Cancel"; "Cancel" has to be last
items - list of items

PredictiveInputFrame

public PredictiveInputFrame(SwingFrame owner,
                            String title,
                            boolean force,
                            boolean ignoreCase,
                            PredictiveInputFrame.InfoSupplier<? super T> info,
                            List<PredictiveInputModel.MatchingStrategy<T>> strategies,
                            List<PredictiveInputFrame.CloseAction<T>> actions,
                            int cancelIndex,
                            T... items)
Create a new predictive string input frame.

Parameters:
owner - owner frame
force - true if the user is forced to select one of the items
info - information supplier to use for additional information display
strategies - array of matching strategies
actions - actions to be performed when the user closes the frame, e.g. "OK" and "Cancel"; "Cancel" has to be last
items - varargs/array of items
Method Detail

getFrameState

public PredictiveInputFrame.FrameState getFrameState()
Returns the last state of the frame, i.e. the location and dimension.

Returns:
frame state

setFrameState

public void setFrameState(PredictiveInputFrame.FrameState ds)
Sets state of the frame, i.e. the location and dimension of the frame for the next use.

Parameters:
ds - State to update to, or null to reset

setFrameState

public void setFrameState(String s)
Sets state of the frame, i.e. the location and dimension of the frame for the next use.

Parameters:
s - State to update to, or null to reset

getItems

public List<T> getItems()
Return a copy of the list of items in the model.

Returns:
list of items

setModel

public void setModel(boolean ignoreCase,
                     PredictiveInputModel<T> pim)
Set the predictive input model.

Parameters:
ignoreCase - true if case should be ignored
pim - predictive input model

setItems

public void setItems(boolean ignoreCase,
                     Collection<T> items)
Set the items.

Parameters:
ignoreCase - true if case should be ignored
items - list of items

setCurrentItem

public void setCurrentItem(T item)
Set the currently selected item.

Parameters:
item - item to select

setItems

public void setItems(boolean ignoreCase,
                     T... items)
Set the items.

Parameters:
ignoreCase - true if case should be ignored
items - varargs/array of items

getButtonPressed

public String getButtonPressed()
Return the name for the last button that was pressed.

Returns:
button name

getMask

public String getMask()
Return the raw, unforced text in the text field.

Returns:
text in text field

setMask

public void setMask(String mask)
Set the mask in the text field.

Parameters:
mask - for text field

getText

public String getText()
Return the string that was entered in the text field. If the user is forced to select an item, then the text of the item will be returned.

Returns:
text in text field

getItem

public T getItem()
Return the item that was selected or null the user entered a mask not in the list and force == false.

Returns:
item that was selected or null

init

private void init(boolean info)
Initialize the frame.

Parameters:
info - true if additional information is desired

makeOptions

protected JComponent[] makeOptions()
Creates the optional components. Should be overridden.


_setupOptionsPanel

private void _setupOptionsPanel(JComponent[] components)
Creates the panel with the optional components.


setOwnerEnabled

public void setOwnerEnabled(boolean b)
Enable or disable owner. Can be overridden to toggle the hourglass, etc.

Parameters:
b - whether the owner should be enabled (true) or disabled

setVisible

public void setVisible(boolean vis)
Toggle visibility of this frame. Warning, it behaves like a modal dialog.

Overrides:
setVisible in class Window

addListener

private void addListener()
Add the listener.


removeListener

private void removeListener()
Remove the listener.


updateTextField

private void updateTextField()
Update the text field based on the model.


resetFocus

public void resetFocus()
Focus back in the text field.


updateExtensionLabel

private void updateExtensionLabel()
Update the extension label based on the model.


updateList

private void updateList()
Update the match list based on the model.


updateInfo

private void updateInfo()
Update the information.


cancel

private void cancel()
Cancel the dialog.


buttonPressed

private void buttonPressed(PredictiveInputFrame.CloseAction<T> a)
Handle button pressed.


selectStrategy

public void selectStrategy()
Select the strategy for matching.