Double Click and Triple click
Double click (double click) and Triple click (Triple click) are accessibility features that make it easy for users to select text (which, of course, does not necessarily have to be selected). This article describes how to customize the double-click behavior in JTF and how to add three-click Support for JTF.
Double Click
In Eclipse's Java editor, when the user double-clicks the editing area with the mouse, you can see that the word that is double-clicked is selected, which is the JTF double click (double click) feature. The actions that are triggered when you double-click are customizable, and you do not have to select a piece of text.
The interface associated with double-clicking is Itextdoubleclickstrategy, it has only one method called doubleclicked, as long as the interface is implemented, in the example, I added the Exprdoubleclickstrategy class:
Listing 1. Exprdoubleclickstrategy implements the Itextdoubleclickstrategy interface
public class ExprDoubleClickStrategy implements ITextDoubleClickStrategy {
public void doubleClicked(ITextViewer viewer) {
// get doc
IDocument doc = viewer.getDocument();
// get token list
TokenList tokenList = TokenManager.getTokenList(doc);
// get double click position
int offset = viewer.getSelectedRange().x;
// get token in that offset
CommonToken token = tokenList.getToken(offset);
// select whole token if token is not null
if(token != null && token.getType() != Token.EOF)
{
// select double clicked token
viewer.setSelectedRange(
token.getStartIndex(), token.getStopIndex() - token.getStartIndex() + 1);
}
}
}
This process is very straightforward, gets the location that is clicked, gets the corresponding symbol through the position, and then selects the entire symbol. We again took advantage of the symbol Tokenlist came to the specified character offset.
As with the second part of the series, with the implementation you have to let JTF know your implementation, we then modify the exprconfiguation, overwriting a Getdoubleclickstrategy method:
Listing 2. Let JTF know your Double Click implementation
public ITextDoubleClickStrategy getDoubleClickStrategy(
ISourceViewer sourceViewer, String contentType)
{
return new ExprDoubleClickStrategy();
}
Simply return to our implementation of the Itextdoubleclickstrategy only, so that JTF know our double-click Behavior, and note that the double-click Behavior is also bound to the text type, but we have only one type, so did not use this information.
The reader can try the example in this article, double-click a variable to see if the variable is all selected.