org.kde.koala
Class KCompletionBase

java.lang.Object
  extended by org.kde.koala.KCompletionBase
All Implemented Interfaces:
KCompletionBaseInterface, org.kde.qt.QtSupport

public class KCompletionBase
extends java.lang.Object
implements org.kde.qt.QtSupport, KCompletionBaseInterface

An abstract base class for adding a completion feature into widgets. This is a convenience class that provides the basic functions needed to add text completion support into widgets. All that is required is an implementation for the pure function setCompletedText. Refer to KLineEdit or KComboBox to see how easily such support can be added using this as a base class.

Author:
Dawit Alemayehu

Field Summary
static int NextCompletionMatch
           
static int PrevCompletionMatch
           
static int SubstringCompletion
           
static int TextCompletion
          Constants that represent the items whose short-cut key-binding is programmable.
 
Constructor Summary
protected KCompletionBase(java.lang.Class dummy)
           
 
Method Summary
 int completionMode()
          Returns the current completion mode.
 KCompletion completionObject()
           
 KCompletion completionObject(boolean hsig)
          Returns a pointer to the current completion object.
 KCompletion compObj()
          Returns a pointer to the completion object.
 boolean emitSignals()
          Returns true if the object emits the signals.
 KShortcut getKeyBinding(int item)
          Returns the key-binding used for the specified item.
 boolean handleSignals()
          Returns true if the object handles the signals.
 boolean isCompletionObjectAutoDeleted()
          Returns true if the completion object is deleted upon this widget's destruction.
 void setAutoDeleteCompletionObject(boolean autoDelete)
          Sets the completion object when this widget's destructor is called.
 void setCompletedItems(java.lang.String[] items)
          A pure function that must be implemented by all inheriting classes.
 void setCompletedText(java.lang.String text)
          A pure function that must be implemented by all inheriting classes.
 void setCompletionMode(int mode)
          Sets the type of completion to be used.
 void setCompletionObject(KCompletion compObj)
           
 void setCompletionObject(KCompletion compObj, boolean hsig)
          Sets up the completion object to be used.
 void setEnableSignals(boolean enable)
          Sets the widget's ability to emit text completion and rotation signals.
 void setHandleSignals(boolean handle)
          Enables this object to handle completion and rotation events internally.
 boolean setKeyBinding(int item, KShortcut key)
          Sets the key-binding to be used for manual text completion, text rotation in a history list as well as a completion list.
 void useGlobalKeyBindings()
          Sets this object to use global values for key-bindings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TextCompletion

public static final int TextCompletion
Constants that represent the items whose short-cut key-binding is programmable. The default key-bindings for these items are defined in KStdAccel.

See Also:
Constant Field Values

PrevCompletionMatch

public static final int PrevCompletionMatch
See Also:
Constant Field Values

NextCompletionMatch

public static final int NextCompletionMatch
See Also:
Constant Field Values

SubstringCompletion

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

KCompletionBase

protected KCompletionBase(java.lang.Class dummy)
Method Detail

completionObject

public KCompletion completionObject(boolean hsig)
Returns a pointer to the current completion object. If the completion object does not exist, it is automatically created and by default handles all the completion signals internally unless hsig is set to false. It is also automatically destroyed when the destructor is called. You can change this default behavior using the setAutoDeleteCompletionObject(boolean) and setHandleSignals(boolean) member functions. See also compObj().

Specified by:
completionObject in interface KCompletionBaseInterface
Parameters:
hsig - if true, handles completion signals internally.
Returns:
a pointer the completion object.

completionObject

public KCompletion completionObject()
Specified by:
completionObject in interface KCompletionBaseInterface

setCompletionObject

public void setCompletionObject(KCompletion compObj,
                                boolean hsig)
Sets up the completion object to be used. This method assigns the completion object and sets it up to automatically handle the completion and rotation signals internally. You should use this function if you want to share one completion object among your widgets or need to use a customized completion object. The object assigned through this method is not deleted when this object's destructor is invoked unless you explicitly call setAutoDeleteCompletionObject(boolean) after calling this method. Be sure to set the boolean argument to false, if you want to handle the completion signals yourself.

Specified by:
setCompletionObject in interface KCompletionBaseInterface
Parameters:
compObj - a KCompletion() or a derived child object.
hsig - if true, handles completion signals internally.

setCompletionObject

public void setCompletionObject(KCompletion compObj)
Specified by:
setCompletionObject in interface KCompletionBaseInterface

setHandleSignals

public void setHandleSignals(boolean handle)
Enables this object to handle completion and rotation events internally. This function simply assigns a booleanean value that indicates whether it should handle rotation and completion events or not. Note that this does not stop the object from emitting signals when these events occur.

Specified by:
setHandleSignals in interface KCompletionBaseInterface
Parameters:
handle - if true, handle completion & rotation internally.

isCompletionObjectAutoDeleted

public boolean isCompletionObjectAutoDeleted()
Returns true if the completion object is deleted upon this widget's destruction. See setCompletionObject() and enableCompletion() for details.

Specified by:
isCompletionObjectAutoDeleted in interface KCompletionBaseInterface
Returns:
true if the completion object will be deleted automatically

setAutoDeleteCompletionObject

public void setAutoDeleteCompletionObject(boolean autoDelete)
Sets the completion object when this widget's destructor is called. If the argument is set to true, the completion object is deleted when this widget's destructor is called.

Specified by:
setAutoDeleteCompletionObject in interface KCompletionBaseInterface
Parameters:
autoDelete - if true, delete completion object on destruction.

setEnableSignals

public void setEnableSignals(boolean enable)
Sets the widget's ability to emit text completion and rotation signals. Invoking this function with enable set to false will cause the completion & rotation signals not to be emitted. However, unlike setting the completion object to NULL using setCompletionObject, disabling the emition of the signals through this method does not affect the current completion object. There is no need to invoke this function by default. When a completion object is created through completionObject or setCompletionObject, these signals are set to emit automatically. Also note that disabling this signals will not necessarily interfere with the objects ability to handle these events internally. See setHandleSignals.

Specified by:
setEnableSignals in interface KCompletionBaseInterface
Parameters:
enable - if false, disables the emition of completion & rotation signals.

handleSignals

public boolean handleSignals()
Returns true if the object handles the signals.

Specified by:
handleSignals in interface KCompletionBaseInterface
Returns:
true if this signals are handled internally.

emitSignals

public boolean emitSignals()
Returns true if the object emits the signals.

Specified by:
emitSignals in interface KCompletionBaseInterface
Returns:
true if signals are emitted

setCompletionMode

public void setCompletionMode(int mode)
Sets the type of completion to be used. The completion modes supported are those defined in KGlobalSettings(). See below.

Specified by:
setCompletionMode in interface KCompletionBaseInterface
Parameters:
mode - Completion type:
  • CompletionNone: Disables completion feature.
  • CompletionAuto: Attempts to find a match & fills-in the remaining text.
  • CompletionMan: Acts the same as the above except the action has to be manually triggered through pre-defined completion key.
  • CompletionShell: Mimics the completion feature found in typical nix shell environments.
  • CompletionPopup: Shows all available completions at once, in a listbox popping up.
  • @short Sets the type of completion to be used.

    completionMode

    public int completionMode()
    Returns the current completion mode. The return values are of type KGlobalSettings.Completion. See setCompletionMode() for details.

    Specified by:
    completionMode in interface KCompletionBaseInterface
    Returns:
    the completion mode.

    setKeyBinding

    public boolean setKeyBinding(int item,
                                 KShortcut key)
    Sets the key-binding to be used for manual text completion, text rotation in a history list as well as a completion list. When the keys set by this function are pressed, a signal defined by the inheriting widget will be activated. If the default value or 0 is specified by the second parameter, then the key-binding as defined in the global setting should be used. This method returns false value for key is negative or the supplied key-binding conflicts with the ones set for one of the other features. NOTE: To use a modifier key (Shift, Ctrl, Alt) as part of the key-binding simply simply sum up the values of the modifier and the actual key. For example, to use CTRL+E as a key binding for one of the items, you would simply supply "Qt.CtrlButton + Qt.Key_E" as the second argument to this function.

    Specified by:
    setKeyBinding in interface KCompletionBaseInterface
    Parameters:
    item - the feature whose key-binding needs to be set:
  • TextCompletion the manual completion key-binding.
  • PrevCompletionMatch the previous match key for multiple completion.
  • NextCompletionMatch the next match key for for multiple completion.
  • SubstringCompletion the key for substring completion
  • key - key-binding used to rotate down in a list.
    Returns:
    true if key-binding can successfully be set.
    See Also:
    getKeyBinding(int)

    getKeyBinding

    public KShortcut getKeyBinding(int item)
    Returns the key-binding used for the specified item. This methods returns the key-binding used to activate the feature feature given by item. If the binding contains modifier key(s), the SUM of the modifier key and the actual key code are returned.

    Specified by:
    getKeyBinding in interface KCompletionBaseInterface
    Parameters:
    item - the item to check
    Returns:
    the key-binding used for the feature given by item.
    See Also:
    setKeyBinding(int, org.kde.koala.KShortcut)

    useGlobalKeyBindings

    public void useGlobalKeyBindings()
    Sets this object to use global values for key-bindings. This method changes the values of the key bindings for rotation and completion features to the default values provided in KGlobalSettings. NOTE: By default inheriting widgets should uses the global key-bindings so that there will be no need to call this method.

    Specified by:
    useGlobalKeyBindings in interface KCompletionBaseInterface

    setCompletedText

    public void setCompletedText(java.lang.String text)
    A pure function that must be implemented by all inheriting classes. This function is intended to allow external completion implementations to set completed text appropriately. It is mostly relevant when the completion mode is set to CompletionAuto and CompletionManual modes. See KCompletionBase.setCompletedText. Does nothing in CompletionPopup mode, as all available matches will be shown in the popup.

    Specified by:
    setCompletedText in interface KCompletionBaseInterface
    Parameters:
    text - the completed text to be set in the widget.

    setCompletedItems

    public void setCompletedItems(java.lang.String[] items)
    A pure function that must be implemented by all inheriting classes.

    Specified by:
    setCompletedItems in interface KCompletionBaseInterface
    Parameters:
    items - the list of completed items

    compObj

    public KCompletion compObj()
    Returns a pointer to the completion object. This method is only different from completionObject() in that it does not create a new KCompletion object even if the internal pointer is NULL. Use this method to get the pointer to a completion object when inheriting so that you won't inadvertently create it!!

    Specified by:
    compObj in interface KCompletionBaseInterface
    Returns:
    the completion object or NULL if one does not exist.