public final class MoveCaretsOrigin extends Object
The core implementation supports operation type (token) as a key and original intended movement direction as a hint for possible filtering. Future API versions may define more details.
This class is used in two modes:
setDot(pos, origin)
,
moveDot(pos, origin)
,
moveCarets(handler, origin)
),
as a information on the originating operation (getActionType()
) and possibly additional
hints that describes the intended caret move (getDirection()
).
registering a NavigationFilter
as a filtering template.
The intended usage in caret moving code (actions) is as follows:
// Action perform method
editorCaret.moveCarets(new CaretMoveHandler() {
@Override
public void moveCarets(CaretMoveContext context) {
...
}
}, new MoveCaretsOrigin(
// The action is a raw movement command
MoveCaretsOrigin.DIRECT_NAVIGATION,
// The approximate direction of the movement; can be 0.
SwingConstants.NORTH)
);
If a NavigationFilter
only wants to intercept certain type of moevements, it can register as follows:
EditorCaret eCaret = .... ; // obtain EditorCaret
eCaret.setNavigationFilter(
new NavigationFilter() {
// navigation filter implementation, not important for the example
},
new MoveCaretsOrigin(MoveCaretsOrigin.DIRECT_NAVIGATION)
);
If the NavigationFilter implementation wants to obtain the extended information for the caret movement, it can downcast the received FilterBypass:
public void setDot(FilterBypass fb, int dot, Position.Bias bias) {
if (fb instanceof NavigationFilterBypass) {
NavigationFilterBypass nfb = (NavigationFilterBypass)fb;
// get the Origin object created by the caret-moving operation, can query the details
MoveCaretsOrigin origin = nfb.getOrigin();
// get the individual caret in multi-caret scenario
CaretInfo info = nfb.getCaretInfo();
// get the whole EditorCaret
EditorCaret eCaret = nfb.getEditorCaret();
}
}
NavigationFilterBypass
Modifier and Type | Field and Description |
---|---|
static MoveCaretsOrigin |
DEFAULT
Undefined action type.
|
static String |
DIRECT_NAVIGATION
Actions, which are defined as moving or setting the caret.
|
static MoveCaretsOrigin |
DISABLE_FILTERS
Actions which must avoid caret filters.
|
Constructor and Description |
---|
MoveCaretsOrigin(String actionType)
Describes the origin by just the action type.
|
MoveCaretsOrigin(String actionType,
int direction)
Specifies the origin by action type, and the overall moving direction
|
Modifier and Type | Method and Description |
---|---|
String |
getActionType()
Returns the type of the action which originated the caret movement.
|
int |
getDirection()
Specifies the desired movement direction.
|
String |
toString() |
public static final String DIRECT_NAVIGATION
public static final MoveCaretsOrigin DEFAULT
public static final MoveCaretsOrigin DISABLE_FILTERS
public MoveCaretsOrigin(String actionType)
actionType
- action type@NonNull public String getActionType()
public int getDirection()
SwingConstants
compass constants to specify the direction. 0 means the direction
is unspecified.