本文整理汇总了Java中javax.swing.text.NavigationFilter类的典型用法代码示例。如果您正苦于以下问题:Java NavigationFilter类的具体用法?Java NavigationFilter怎么用?Java NavigationFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NavigationFilter类属于javax.swing.text包,在下文中一共展示了NavigationFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doPutNavigationFilter
import javax.swing.text.NavigationFilter; //导入依赖的package包/类
/**
* Records the navigation filter. Note that the filter is stored in the JTextComponent rather than
* in this Caret. If the Component's UI changes or the caret is recreated for some reason, the
* navigation filters remain registered.
*
* @param type type of nav filter
* @param n the filter instance
*/
private static void doPutNavigationFilter(JTextComponent component, String type, NavigationFilter n) {
if (component == null) {
throw new IllegalStateException("Not attached to a Component");
}
Map<String, NavigationFilter> m = (Map<String, NavigationFilter>)component.getClientProperty(NAVIGATION_FILTER_PROPERTY);
if (m == null) {
if (n == null) {
return;
}
m = new HashMap<>();
component.putClientProperty(NAVIGATION_FILTER_PROPERTY, m);
}
if (n == null) {
m.remove(type);
} else {
m.put(type, n);
}
}
示例2: unregister
import javax.swing.text.NavigationFilter; //导入依赖的package包/类
/**
* Removes this NavigationFilter from the chain; preceding filter will
* be connected to the following one, so the chain will not be broken.
*/
public final void unregister() {
if (regKey == null) {
// not registered
return;
}
NavigationFilter f = EditorCaret.getNavigationFilter(owner, regKey);
CascadingNavigationFilter next = null;
while (f instanceof CascadingNavigationFilter && f != this) {
next = (CascadingNavigationFilter)f;
f = next.getNextFilter();
}
if (f != this) {
return;
}
if (next == null) {
EditorCaret.setNavigationFilter(owner, regKey, previous);
} else {
next.previous = previous;
}
// reset state
this.owner = null;
this.previous = null;
}
示例3: testInstallUninstall_Filters
import javax.swing.text.NavigationFilter; //导入依赖的package包/类
public void testInstallUninstall_Filters() {
NavigationFilter navFilter = new NavigationFilter();
formatter.setNavigationFilter(navFilter);
DocumentFilter docFilter = new DocumentFilter();
formatter.setDocumentFilter(docFilter);
AbstractDocument doc = (AbstractDocument) tf.getDocument();
assertNull(tf.getNavigationFilter());
assertNull(doc.getDocumentFilter());
formatter.install(tf);
assertEquals(navFilter, tf.getNavigationFilter());
assertEquals(docFilter, doc.getDocumentFilter());
formatter.uninstall();
assertNull(tf.getNavigationFilter());
assertNull(doc.getDocumentFilter());
formatter.install(tf);
assertEquals(navFilter, tf.getNavigationFilter());
assertEquals(docFilter, doc.getDocumentFilter());
formatter.install(null);
assertNull(tf.getNavigationFilter());
assertNull(doc.getDocumentFilter());
}
示例4: setDot
import javax.swing.text.NavigationFilter; //导入依赖的package包/类
/**
* Change dot of the given caret.
*
* @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 setDot(@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.setDot(fbi, dotPos.getOffset(), Position.Bias.Forward);
return fbi.getResult();
} else {
return setDotAndMark(caret, dotPos, dotBias, dotPos, dotBias);
}
}
示例5: moveDot
import javax.swing.text.NavigationFilter; //导入依赖的package包/类
/**
* 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);
}
}
示例6: getNavigationFilter
import javax.swing.text.NavigationFilter; //导入依赖的package包/类
/**
* Returns the navigation filter for a certain operation.
* {@link NavigationFilter} can be
* registered to receive only limited set of operations. This method returns the filter
* for the specified operation. Use {@link MoveCaretsOrigin#DEFAULT} to get text
* component's navigation filter (equivalent to {@link JTextComponent#getNavigationFilter()
* JTextComponent.getNavigationFilter()}. That filter receives all caret movements.
* @param component the component whose filter should be returned
* @param origin the operation description
* @return the current navigation filter.
* @since 2.10
*/
public static @CheckForNull NavigationFilter getNavigationFilter(@NonNull JTextComponent component, @NonNull MoveCaretsOrigin origin) {
Parameters.notNull("origin", origin);
if (origin == MoveCaretsOrigin.DEFAULT) {
return component.getNavigationFilter();
} else if (origin == MoveCaretsOrigin.DISABLE_FILTERS) {
return null;
}
NavigationFilter navi = doGetNavigationFilter(component, origin.getActionType());
// Note: a special delegator is returned, since the component's navigation filter queue
// can be manipulated after call to getNavigationFilter. So if we would have returned the global filter instance directly,
// the calling client may unknowingly bypass certain (global) filters registered after call to this method.
// In other words, there are two possible insertion points into the navigation filter chanin
return navi != null ? navi : getChainNavigationFilter(component);
}
示例7: getNavigationFilterNoDefault
import javax.swing.text.NavigationFilter; //导入依赖的package包/类
/**
* Variant of {@link #getNavigationFilter}, which does not default to chaining navigation
* filter
* @param origin operation specifier
* @return navigation filter or {@code null}
*/
@CheckForNull NavigationFilter getNavigationFilterNoDefault(@NonNull MoveCaretsOrigin origin) {
if (origin == MoveCaretsOrigin.DEFAULT) {
return component.getNavigationFilter();
} else if (origin == MoveCaretsOrigin.DISABLE_FILTERS) {
return null;
}
NavigationFilter navi2 = doGetNavigationFilter(component, origin.getActionType());
return navi2 != null ? navi2 : component.getNavigationFilter();
}
示例8: moveDot
import javax.swing.text.NavigationFilter; //导入依赖的package包/类
@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);
}
}
示例9: setDot
import javax.swing.text.NavigationFilter; //导入依赖的package包/类
@Override
public void setDot(NavigationFilter.FilterBypass fb, int dot, Position.Bias bias) {
NavigationFilter chain = component.getNavigationFilter();
if (chain != null) {
chain.setDot(fb, dot, bias);
} else {
super.setDot(fb, dot, bias);
}
}
示例10: setNavigationFilter
import javax.swing.text.NavigationFilter; //导入依赖的package包/类
/**
* 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);
}
}
示例11: getChainNavigationFilter
import javax.swing.text.NavigationFilter; //导入依赖的package包/类
private static NavigationFilter getChainNavigationFilter(JTextComponent component) {
NavigationFilter chain = (NavigationFilter)component.getClientProperty(CHAIN_FILTER_PROPERTY);
if (chain == null) {
component.putClientProperty(CHAIN_FILTER_PROPERTY, chain = new ChainNavigationFilter(component));
}
return chain;
}
示例12: doGetNavigationFilter
import javax.swing.text.NavigationFilter; //导入依赖的package包/类
private static NavigationFilter doGetNavigationFilter(JTextComponent component, String n) {
if (component == null) {
throw new IllegalStateException("Not attached to a Component");
}
Map<String, NavigationFilter> m = (Map<String, NavigationFilter>)component.getClientProperty(NAVIGATION_FILTER_PROPERTY);
return m == null ? null : m.get(n);
}
示例13: setOwnerAndPrevious
import javax.swing.text.NavigationFilter; //导入依赖的package包/类
public void setOwnerAndPrevious(JTextComponent component, MoveCaretsOrigin orig, NavigationFilter prev) {
if (this.owner != null) {
throw new IllegalStateException("Can be registered only once");
}
this.owner = component;
this.previous = prev;
this.regKey = orig;
}
示例14: setDot
import javax.swing.text.NavigationFilter; //导入依赖的package包/类
@Override
public void setDot(NavigationFilter.FilterBypass bypass,
int dot,
Position.Bias bias) {
if (dot > classNameLength) {
bypass.setDot(classNameLength, bias);
} else {
super.setDot(bypass, dot, bias);
}
}
示例15: moveDot
import javax.swing.text.NavigationFilter; //导入依赖的package包/类
@Override
public void moveDot(NavigationFilter.FilterBypass bypass,
int dot,
Position.Bias bias) {
if (dot > classNameLength) {
bypass.moveDot(classNameLength, bias);
} else {
super.moveDot(bypass, dot, bias);
}
}