下面列出了java.awt.event.HierarchyBoundsListener#javax.swing.event.AncestorListener 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Maps {@code JComponent.addAncestorListener(AncestorListener)}
* through queue
*/
public void addAncestorListener(final AncestorListener ancestorListener) {
runMapping(new MapVoidAction("addAncestorListener") {
@Override
public void map() {
((JComponent) getSource()).addAncestorListener(ancestorListener);
}
});
}
/**
* Maps {@code JComponent.removeAncestorListener(AncestorListener)}
* through queue
*/
public void removeAncestorListener(final AncestorListener ancestorListener) {
runMapping(new MapVoidAction("removeAncestorListener") {
@Override
public void map() {
((JComponent) getSource()).removeAncestorListener(ancestorListener);
}
});
}
public ExpandableSupport(@Nonnull Source source, Function<? super String, String> onShow, Function<? super String, String> onHide) {
this.source = source;
this.onShow = onShow != null ? onShow : Function.ID;
this.onHide = onHide != null ? onHide : Function.ID;
source.putClientProperty(Expandable.class, this);
source.addAncestorListener(create(AncestorListener.class, this, "collapse"));
source.addComponentListener(create(ComponentListener.class, this, "collapse"));
}
/** Overridden to do nothing for performance reasons */
public @Override void addAncestorListener(AncestorListener l) {
if (swingRendering || !cellRenderer) {
super.addAncestorListener(l);
}
}
public AncestorListener getAncestorListener() {
return ancestorListener;
}
/**
* Installs a {@link WindowFocusListener} on the given {@link JComponent}'s
* parent {@link Window}. If the {@code JComponent} doesn't yet have a
* parent, then the listener will be installed when the component is added
* to a container.
*
* @param component the component who's parent frame to listen to focus
* changes on.
* @param focusListener the {@code WindowFocusListener} to notify when focus
* changes.
*/
public static void installWeakWindowFocusListener(JComponent component, WindowFocusListener focusListener) {
WindowListener weakFocusListener = createWeakWindowFocusListener(focusListener);
AncestorListener ancestorListener = createAncestorListener(component, weakFocusListener);
component.addAncestorListener(ancestorListener);
}
/**
* Installs a listener on the given {@link JComponent}'s parent
* {@link Window} that repaints the given component when the parent window's
* focused state changes. If the given component does not have a parent at
* the time this method is called, then an ancestor listener will be
* installed that installs a window listener when the components parent
* changes.
*
* @param component the {@code JComponent} to add the repaint focus listener
* to.
*/
public static void installJComponentRepainterOnWindowFocusChanged(JComponent component) {
// TODO check to see if the component already has an ancestor.
WindowListener windowListener = createWeakWindowFocusListener(createRepaintWindowListener(component));
AncestorListener ancestorListener = createAncestorListener(component, windowListener);
component.addAncestorListener(ancestorListener);
}