Java Code Examples for javax.swing.text.NavigationFilter#moveDot()

The following examples show how to use javax.swing.text.NavigationFilter#moveDot() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: netbeans   File: CaretMoveContext.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Move dot of the given caret so caret selection gets created or changed.
 *
 * @param caret non-null caret.
 * @param dotPos new dot position.
 * @return false if passed caret is obsolete or invalid (e.g. a member of another {@link EditorCaret})
 *  or true otherwise.
 */
public boolean moveDot(@NonNull CaretInfo caret, @NonNull Position dotPos, @NonNull Position.Bias dotBias) {
    NavigationFilter naviFilter = transaction.getCaret().getNavigationFilterNoDefault(transaction.getOrigin());
    if (naviFilter != null) {
        FilterBypassImpl fbi = new FilterBypassImpl(transaction, caret, transaction.getDocument());
        naviFilter.moveDot(fbi, dotPos.getOffset(), Position.Bias.Forward);
        return fbi.getResult();
    } else {
        return transaction.moveDot(caret.getCaretItem(), dotPos, dotBias);
    }
}
 
Example 2
Source Project: netbeans   File: EditorCaret.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void moveDot(NavigationFilter.FilterBypass fb, int dot, Position.Bias bias) {
    NavigationFilter chain = component.getNavigationFilter();
    if (chain != null) {
        chain.moveDot(fb, dot, bias);
    } else {
        super.moveDot(fb, dot, bias);
    }
}
 
Example 3
Source Project: netbeans   File: EditorCaret.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets navigation filter for a certain operation type, defined by {@link MoveCaretsOrigin}.
 * <p>
 * The registered filter will receive <b>only those caret movements</b>, which correspond to the
 * passed {@link MoveCaretsOrigin}. To receive all caret movements, register for {@link MoveCaretsOrigin#DEFAULT} 
 * or use {@link JTextComponent#setNavigationFilter}.
 * </p><p>
 * All the key part(s) of MoveCaretOrigin of a caret operation and `origin' parameter in this function must
 * match in order for the filter to be invoked.
 * </p><p>
 * The NavigationFilter implementation <b>may downcast</b> the passed {@link NavigationFilter.FilterBypass FilterBypass}
 * parameter to {@link NavigationFilterBypass} to get full infomration about the movement. 
 * </p>
 * @param component the component which will use the filter
 * @param origin the origin
 * @param naviFilter the installed filter
 * @see JTextComponent#setNavigationFilter
 * @see NavigationFilterBypass
 * @since 2.10
 */
public static void setNavigationFilter(JTextComponent component, MoveCaretsOrigin origin, @NullAllowed NavigationFilter naviFilter) {
    if (origin == null) {
        origin = MoveCaretsOrigin.DEFAULT;
    }
    final NavigationFilter prev = getNavigationFilter(component, origin);
    if (naviFilter != null) {
        // Note:
        // if the caller passes in a non-cascading filter, we would loose the filter chain information.
        // the alien filter is wrapped by CascadingNavigationFilter delegator, so the previous filter
        // link is preserved.
        if (!(naviFilter instanceof CascadingNavigationFilter)) {
            final NavigationFilter del = naviFilter;
            naviFilter = new CascadingNavigationFilter() {
                @Override
                public void setDot(NavigationFilter.FilterBypass fb, int dot, Position.Bias bias) {
                    del.setDot(fb, dot, bias);
                }

                @Override
                public void moveDot(NavigationFilter.FilterBypass fb, int dot, Position.Bias bias) {
                    del.moveDot(fb, dot, bias);
                }

                @Override
                public int getNextVisualPositionFrom(JTextComponent text, int pos, Position.Bias bias, int direction, Position.Bias[] biasRet) throws BadLocationException {
                    return del.getNextVisualPositionFrom(text, pos, bias, direction, biasRet);
                }
            };
        }
        ((CascadingNavigationFilter)naviFilter).setOwnerAndPrevious(component, origin, prev);
    }
    if (MoveCaretsOrigin.DEFAULT == origin) {
        component.setNavigationFilter(naviFilter);
    } else {
        doPutNavigationFilter(component, origin.getActionType(), prev);
    }
}