net.jakubholy.jedit.autocomplete
Class CompletionPopup

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by javax.swing.JWindow
                  extended by org.gjt.sp.jedit.gui.CompletionPopup
                      extended by net.jakubholy.jedit.autocomplete.CompletionPopup
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer, ITextAutoCompletionPopup

public class CompletionPopup
extends org.gjt.sp.jedit.gui.CompletionPopup
implements ITextAutoCompletionPopup

A pop-up window to display a list of available completions.

When visible it intercepts all keys and either passes them on or handles them if they've a special meaning for it (such as dispose or insert the selected completion). What keys have what meaning is determined by a PreferencesManager. It could be extended to react also to other events such as focus lost.

The window is absolutely unaware of the AutoComplete that's using it and that contains most of the logic to show/dispose the pop-up/update the list of completions.

NOTE: Re-implemented based on the completion pop-up being part of the jEdit API. The implementation is inspired by CompleteWord.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.gjt.sp.jedit.gui.CompletionPopup
org.gjt.sp.jedit.gui.CompletionPopup.Candidates
 
Nested classes/interfaces inherited from class javax.swing.JWindow
javax.swing.JWindow.AccessibleJWindow
 
Nested classes/interfaces inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  int DOWN
          A constant used by moveSelection - down arrow pressed.
protected  int UP
          A constant used by moveSelection - up arrow pressed.
 
Fields inherited from class javax.swing.JWindow
accessibleContext, rootPane, rootPaneCheckingEnabled
 
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
CompletionPopup(org.gjt.sp.jedit.View view, java.awt.Point location)
          Create a new (so far invisible) pop-up with its listeners at the given location.
 
Method Summary
 void keyPressed(java.awt.event.KeyEvent evt)
          Keys handling while the popup is visible.
 void keyTyped(java.awt.event.KeyEvent evt)
          Handle key typed while intercepting any user input when popup visible.
protected  void moveSelection(java.awt.event.KeyEvent evt, int direction)
          Move selection in the popup completition list up or down.
 void setWord(java.lang.String word)
          Set the prefix being completed.
 boolean showCompletions(net.jakubholy.jedit.autocomplete.Completion[] completions)
          Display/update a popup with the given completions.
 
Methods inherited from class org.gjt.sp.jedit.gui.CompletionPopup
dispose, doSelectedCompletion, getCandidates, getSelectedIndex, reset, setSelectedIndex
 
Methods inherited from class javax.swing.JWindow
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getGraphics, getLayeredPane, getRootPane, getTransferHandler, isRootPaneCheckingEnabled, paramString, remove, repaint, setContentPane, setGlassPane, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update, windowInit
 
Methods inherited from class java.awt.Window
addNotify, addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, 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, processWindowEvent, processWindowFocusEvent, processWindowStateEvent, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, 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, 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, remove, 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 net.jakubholy.jedit.autocomplete.ITextAutoCompletionPopup
dispose
 

Field Detail

DOWN

protected final int DOWN
A constant used by moveSelection - down arrow pressed.

See Also:
Constant Field Values

UP

protected final int UP
A constant used by moveSelection - up arrow pressed.

See Also:
Constant Field Values
Constructor Detail

CompletionPopup

public CompletionPopup(org.gjt.sp.jedit.View view,
                       java.awt.Point location)
Create a new (so far invisible) pop-up with its listeners at the given location.

Method Detail

showCompletions

public boolean showCompletions(net.jakubholy.jedit.autocomplete.Completion[] completions)
Description copied from interface: ITextAutoCompletionPopup
Display/update a popup with the given completions.

Specified by:
showCompletions in interface ITextAutoCompletionPopup
Parameters:
completions - The completions to set; if empty => dispose.
Returns:
Returns true if the operation succeeded (== valid completions).

setWord

public void setWord(java.lang.String word)
Description copied from interface: ITextAutoCompletionPopup
Set the prefix being completed. We need it for positioning the pop-up and for inserting only the missing part of a completion (e.g. only 'phant' for prefix 'ele' and completion 'elephant').

Specified by:
setWord in interface ITextAutoCompletionPopup

keyPressed

public void keyPressed(java.awt.event.KeyEvent evt)
Keys handling while the popup is visible. Displayable key are forwarded to the underlying textArea, control keys (Esc, F2 ...) are handeled w.r.t. PreferencesManager and unhandled keys dispose the popup window. ? This method is only invoked for special keys, not for those that can be typed such as a letter ?

Overrides:
keyPressed in class org.gjt.sp.jedit.gui.CompletionPopup

moveSelection

protected void moveSelection(java.awt.event.KeyEvent evt,
                             int direction)
Move selection in the popup completition list up or down.


keyTyped

public void keyTyped(java.awt.event.KeyEvent evt)
Handle key typed while intercepting any user input when popup visible. Mostly we do nothing because that will fire a buffer changed event that will invoke AutoComplete.update that will handle the event and do something with the pop-up window. Only if it's a digit we insert the completion with the given number if there's such on the list.

Overrides:
keyTyped in class org.gjt.sp.jedit.gui.CompletionPopup
See Also:
AutoComplete.update(java.util.Observable, Object), WordTypedListener