net.sf.sdedit.ui.components
Class AutoCompletion

java.lang.Object
  extended by java.awt.event.KeyAdapter
      extended by net.sf.sdedit.ui.components.AutoCompletion
All Implemented Interfaces:
KeyListener, EventListener

public class AutoCompletion
extends KeyAdapter

An AutoCompletion object can be added to a JTextPane as a key listener. When the tab key is pressed, and there is a character to the left to the cursor and whitespace to its right, the associated AutoCompletion.SuggestionProvider's (see AutoCompletion(JTextPane, SuggestionProvider, char...)) method AutoCompletion.SuggestionProvider.getSuggestions(String) is called with the string to the left of the cursor (separated by whitespace or one of the given delimiters) as a parameter. The strings that are returned by this method all have the parameter string as a prefix. If there is at least one string, the prefix is replaced by it. If there are even more, successive strokes of the tab key will cycle through all strings.

Author:
Markus Strauch

Nested Class Summary
static interface AutoCompletion.SuggestionProvider
          An interface for objects that provide suggestions how a prefix could be completed to a known string.
 
Constructor Summary
AutoCompletion(JTextPane textPane, AutoCompletion.SuggestionProvider provider, char... delimiters)
          Creates a new AutoCompletion.
 
Method Summary
 void keyPressed(KeyEvent e)
          Implements the behaviour as described in the class comment: AutoCompletion.
 
Methods inherited from class java.awt.event.KeyAdapter
keyReleased, keyTyped
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AutoCompletion

public AutoCompletion(JTextPane textPane,
                      AutoCompletion.SuggestionProvider provider,
                      char... delimiters)
Creates a new AutoCompletion.

Parameters:
textPane - the JTextPane in which text should be substituted NOTE: its getText() method must return a string with a single '\n' as end-of-line character
provider - for providing suggestions of what could be substituted
delimiters - characters that are to be interpreted as the left limit (not inclusive) of a prefix that might be substituted
Method Detail

keyPressed

public void keyPressed(KeyEvent e)
Implements the behaviour as described in the class comment: AutoCompletion.

Specified by:
keyPressed in interface KeyListener
Overrides:
keyPressed in class KeyAdapter
Parameters:
e -


Copyright © 2011. All Rights Reserved.