下面列出了java.awt.Container#isShowing ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void layoutContainer(Container parent) {
JComponent jc = (JComponent) parent;
install(jc);
Timer timer = (Timer) jc.getClientProperty(PROPERTY_TIMER);
Boolean layoutImmediately = (Boolean) jc
.getClientProperty(PROPERTY_LAYOUT_IMMEDIATELY);
if (layoutImmediately == null)
layoutImmediately = false;
if (layoutImmediately) {
layoutContainerImmediately(jc);
if (parent.isShowing())
jc.putClientProperty(PROPERTY_LAYOUT_IMMEDIATELY, false);
} else {
if (!timer.isRunning())
timer.start();
}
}
/**
* Returns a set of all the components that
* can have the keyboard focus.
* <P>My first implementation involved of this concept
* simply involved asking JCompnonents if they were
* focusable, but in the <code>FilledButtonTest</code> this
* resulted in shifting focus to the ContentPane. Although
* it is technically focusable: if I used the tab key
* I did <i>not</i> get this result. So I studied
* the inner workings for Component.transferFocus()
* and ended up with a method that involved
* calls to <code>getFocusCycleRootAncestor()</code>,
* and <code>getFocusTraversalPolicy()</code>.
* <P>(Also credit goes to Werner for originally tipping me off
* towards looking at FocusTraversalPolicies.)
*
* @param currentFocusOwner the current focus owner.
* @return all the JComponents that can receive the focus.
*/
public static Set<Component> getFocusableComponents(Component currentFocusOwner) {
Set<Component> set = new HashSet<>();
set.add(currentFocusOwner);
Container rootAncestor = currentFocusOwner.getFocusCycleRootAncestor();
Component comp = currentFocusOwner;
while (rootAncestor != null &&
!(rootAncestor.isShowing() &&
rootAncestor.isFocusable() &&
rootAncestor.isEnabled())) {
comp = rootAncestor;
rootAncestor = comp.getFocusCycleRootAncestor();
}
if (rootAncestor != null) {
FocusTraversalPolicy policy =
rootAncestor.getFocusTraversalPolicy();
Component toFocus = policy.getComponentAfter(rootAncestor, comp);
while (toFocus != null && !set.contains(toFocus)) {
set.add(toFocus);
toFocus = policy.getComponentAfter(rootAncestor, toFocus);
}
toFocus = policy.getComponentBefore(rootAncestor, comp);
while (toFocus != null && !set.contains(toFocus)) {
set.add(toFocus);
toFocus = policy.getComponentBefore(rootAncestor, toFocus);
}
}
return set;
}
private void enumerateAndSortCycle(Container focusCycleRoot, List<Component> cycle) {
if (focusCycleRoot.isShowing()) {
enumerateCycle(focusCycleRoot, cycle);
if (!legacySortingFTPEnabled ||
!legacySort(cycle, comparator))
{
Collections.sort(cycle, comparator);
}
}
}
private void enumerateAndSortCycle(Container focusCycleRoot, List<Component> cycle) {
if (focusCycleRoot.isShowing()) {
enumerateCycle(focusCycleRoot, cycle);
if (!legacySortingFTPEnabled ||
!legacySort(cycle, comparator))
{
Collections.sort(cycle, comparator);
}
}
}
private void enumerateAndSortCycle(Container focusCycleRoot, List<Component> cycle) {
if (focusCycleRoot.isShowing()) {
enumerateCycle(focusCycleRoot, cycle);
if (!legacySortingFTPEnabled ||
!legacySort(cycle, comparator))
{
Collections.sort(cycle, comparator);
}
}
}
private void enumerateAndSortCycle(Container focusCycleRoot, List<Component> cycle) {
if (focusCycleRoot.isShowing()) {
enumerateCycle(focusCycleRoot, cycle);
if (!legacySortingFTPEnabled ||
!legacySort(cycle, comparator))
{
Collections.sort(cycle, comparator);
}
}
}
private void enumerateAndSortCycle(Container focusCycleRoot, List<Component> cycle) {
if (focusCycleRoot.isShowing()) {
enumerateCycle(focusCycleRoot, cycle);
if (!legacySortingFTPEnabled ||
!legacySort(cycle, comparator))
{
Collections.sort(cycle, comparator);
}
}
}
private void findPrintable(Container container, List<JComponent> printable) {
if (container.isShowing() && isPrintable(container)) {
printable.add((JComponent) container);
}
Component[] children = container.getComponents();
for (Component child : children) {
if (child instanceof Container) {
findPrintable((Container) child, printable);
}
}
}
private void enumerateAndSortCycle(Container focusCycleRoot, List<Component> cycle) {
if (focusCycleRoot.isShowing()) {
enumerateCycle(focusCycleRoot, cycle);
if (!legacySortingFTPEnabled ||
!legacySort(cycle, comparator))
{
Collections.sort(cycle, comparator);
}
}
}
private void enumerateAndSortCycle(Container focusCycleRoot, List<Component> cycle) {
if (focusCycleRoot.isShowing()) {
enumerateCycle(focusCycleRoot, cycle);
if (legacySortingFTPEnabled) {
legacySort(cycle, comparator);
} else {
cycle.sort(comparator);
}
}
}
private void enumerateAndSortCycle(Container focusCycleRoot, List<Component> cycle) {
if (focusCycleRoot.isShowing()) {
enumerateCycle(focusCycleRoot, cycle);
if (legacySortingFTPEnabled) {
legacySort(cycle, comparator);
} else {
cycle.sort(comparator);
}
}
}
private void enumerateAndSortCycle(Container focusCycleRoot, List<Component> cycle) {
if (focusCycleRoot.isShowing()) {
enumerateCycle(focusCycleRoot, cycle);
if (!legacySortingFTPEnabled ||
!legacySort(cycle, comparator))
{
Collections.sort(cycle, comparator);
}
}
}
private void enumerateAndSortCycle(Container focusCycleRoot, List<Component> cycle) {
if (focusCycleRoot.isShowing()) {
enumerateCycle(focusCycleRoot, cycle);
if (!legacySortingFTPEnabled ||
!legacySort(cycle, comparator))
{
Collections.sort(cycle, comparator);
}
}
}
private void enumerateAndSortCycle(Container focusCycleRoot, List<Component> cycle) {
if (focusCycleRoot.isShowing()) {
enumerateCycle(focusCycleRoot, cycle);
if (!legacySortingFTPEnabled ||
!legacySort(cycle, comparator))
{
Collections.sort(cycle, comparator);
}
}
}
/**
* Returns a set of all the components that can have the keyboard focus.
* <P>
* My first implementation involved of this concept simply involved asking
* JCompnonents if they were focusable, but in the
* <code>FilledButtonTest</code> this resulted in shifting focus to the
* ContentPane. Although it is technically focusable: if I used the tab key
* I did <i>not</i> get this result. So I studied the inner workings for
* Component.transferFocus() and ended up with a method that involved calls
* to <code>getFocusCycleRootAncestor()</code>, and
* <code>getFocusTraversalPolicy()</code>.
* <P>
* (Also credit goes to Werner for originally tipping me off towards looking
* at FocusTraversalPolicies.)
*
* @param currentFocusOwner
* the current focus owner.
* @return all the JComponents that can receive the focus.
*/
public static Set<Component> getFocusableComponents(
Component currentFocusOwner) {
HashSet<Component> set = new HashSet<Component>();
set.add(currentFocusOwner);
Container rootAncestor = currentFocusOwner.getFocusCycleRootAncestor();
Component comp = currentFocusOwner;
while (rootAncestor != null
&& !(rootAncestor.isShowing() && rootAncestor.isFocusable() && rootAncestor
.isEnabled())) {
comp = rootAncestor;
rootAncestor = comp.getFocusCycleRootAncestor();
}
if (rootAncestor != null) {
FocusTraversalPolicy policy = rootAncestor
.getFocusTraversalPolicy();
Component toFocus = policy.getComponentAfter(rootAncestor, comp);
while (toFocus != null && set.contains(toFocus) == false) {
set.add(toFocus);
toFocus = policy.getComponentAfter(rootAncestor, toFocus);
}
toFocus = policy.getComponentBefore(rootAncestor, comp);
while (toFocus != null && set.contains(toFocus) == false) {
set.add(toFocus);
toFocus = policy.getComponentBefore(rootAncestor, toFocus);
}
}
return set;
}
/** Returns a set of all the components that
* can have the keyboard focus.
* <P>My first implementation involved of this concept
* simply involved asking JCompnonents if they were
* focusable, but in the <code>FilledButtonTest</code> this
* resulted in shifting focus to the ContentPane. Although
* it is technically focusable: if I used the tab key
* I did <i>not</i> get this result. So I studied
* the inner workings for Component.transferFocus()
* and ended up with a method that involved
* calls to <code>getFocusCycleRootAncestor()</code>,
* and <code>getFocusTraversalPolicy()</code>.
* <P>(Also credit goes to Werner for originally tipping me off
* towards looking at FocusTraversalPolicies.)
* @param currentFocusOwner the current focus owner.
* @return all the JComponents that can receive the focus.
*/
public static Set<Component> getFocusableComponents(Component currentFocusOwner) {
HashSet<Component> set = new HashSet<Component>();
set.add(currentFocusOwner);
Container rootAncestor = currentFocusOwner.getFocusCycleRootAncestor();
Component comp = currentFocusOwner;
while (rootAncestor != null &&
!(rootAncestor.isShowing() &&
rootAncestor.isFocusable() &&
rootAncestor.isEnabled()))
{
comp = rootAncestor;
rootAncestor = comp.getFocusCycleRootAncestor();
}
if (rootAncestor != null) {
FocusTraversalPolicy policy =
rootAncestor.getFocusTraversalPolicy();
Component toFocus = policy.getComponentAfter(rootAncestor, comp);
while(toFocus!=null && set.contains(toFocus)==false) {
set.add(toFocus);
toFocus = policy.getComponentAfter(rootAncestor, toFocus);
}
toFocus = policy.getComponentBefore(rootAncestor, comp);
while(toFocus!=null && set.contains(toFocus)==false) {
set.add(toFocus);
toFocus = policy.getComponentBefore(rootAncestor, toFocus);
}
}
return set;
}
private void enumerateAndSortCycle(Container focusCycleRoot, List<Component> cycle) {
if (focusCycleRoot.isShowing()) {
enumerateCycle(focusCycleRoot, cycle);
if (!legacySortingFTPEnabled ||
!legacySort(cycle, comparator))
{
Collections.sort(cycle, comparator);
}
}
}
private void enumerateAndSortCycle(Container focusCycleRoot, List<Component> cycle) {
if (focusCycleRoot.isShowing()) {
enumerateCycle(focusCycleRoot, cycle);
if (!legacySortingFTPEnabled ||
!legacySort(cycle, comparator))
{
Collections.sort(cycle, comparator);
}
}
}
private void enumerateAndSortCycle(Container focusCycleRoot, List<Component> cycle) {
if (focusCycleRoot.isShowing()) {
enumerateCycle(focusCycleRoot, cycle);
Collections.sort(cycle, comparator);
}
}
private void enumerateAndSortCycle(Container focusCycleRoot, List<Component> cycle) {
if (focusCycleRoot.isShowing()) {
enumerateCycle(focusCycleRoot, cycle);
Collections.sort(cycle, comparator);
}
}