/** * notify this instance that it may no longer render a GUI. */ public synchronized void dontUseGui() { if (okToUseGui) { okToUseGui = false; // lets also tell the Children that can that they may not use their GUI's synchronized(children) { for (Iterator i = children.keySet().iterator(); i.hasNext();) { Visibility v = getChildVisibility(i.next()); if (v != null) v.dontUseGui(); } } } }
/** * Notify this instance that it may now render a GUI */ public synchronized void okToUseGui() { if (!okToUseGui) { okToUseGui = true; // lets also tell the Children that can that they may use their GUI's synchronized(children) { for (Iterator i = children.keySet().iterator(); i.hasNext();) { Visibility v = getChildVisibility(i.next()); if (v != null) v.okToUseGui(); } } } }
/** * notify this instance that it may no longer render a GUI. */ public synchronized void dontUseGui() { if (okToUseGui) { okToUseGui = false; // lets also tell the Children that can that they may not use their GUI's synchronized(children) { for (Iterator<Object> i = children.keySet().iterator(); i.hasNext();) { Visibility v = getChildVisibility(i.next()); if (v != null) v.dontUseGui(); } } } }
/** * Notify this instance that it may now render a GUI */ public synchronized void okToUseGui() { if (!okToUseGui) { okToUseGui = true; // lets also tell the Children that can that they may use their GUI's synchronized(children) { for (Iterator<Object> i = children.keySet().iterator(); i.hasNext();) { Visibility v = getChildVisibility(i.next()); if (v != null) v.okToUseGui(); } } } }
/** * Returns true if this context or its children needs GUI to work properly. * <p> * The implementation checks the peer and all the children that implement * <code>Visibility</code> to see if any of their <code>needsGui()</code> * returns true, and if any of the children extends * <code>java.awt.Component</code>.</p> * * @see java.beans.Visibility#needsGui() */ public boolean needsGui() { if (inNeedsGui) { return false; } inNeedsGui = true; try { if (getBeanContextPeer() != this) { if (getBeanContextPeer().needsGui()) { return true; } } Object childs[] = copyChildren(); for (int i = 0; i < childs.length; i++) { Visibility v = getChildVisibility(childs[i]); if (v != null && v.needsGui()) { return true; } } return false; } finally { inNeedsGui = false; } }
public synchronized boolean needsGui() { // BeanContext needs GUI if at least one its children needs it. // We may check it by trying to cast each child to Visibility // and see it needs GUI. // A child definitely needs GUI if it implements Component for (Iterator it = iterator(); it.hasNext();) { Object next = it.next(); Visibility vis = getChildVisibility(next); if (vis != null) { if (vis.needsGui()) { return true; } } if (next instanceof java.awt.Component) { return true; } } return false; }
/** * <p> * This method is typically called from the environment in order to determine * if the implementor "needs" a GUI. * </p> * <p> * The algorithm used herein tests the BeanContextPeer, and its current children * to determine if they are either Containers, Components, or if they implement * Visibility and return needsGui() == true. * </p> * @return <tt>true</tt> if the implementor needs a GUI */ public synchronized boolean needsGui() { BeanContext bc = getBeanContextPeer(); if (bc != this) { if (bc instanceof Visibility) return ((Visibility)bc).needsGui(); if (bc instanceof Container || bc instanceof Component) return true; } synchronized(children) { for (Iterator i = children.keySet().iterator(); i.hasNext();) { Object c = i.next(); try { return ((Visibility)c).needsGui(); } catch (ClassCastException cce) { // do nothing ... } if (c instanceof Container || c instanceof Component) return true; } } return false; }
/** * Gets the Component (if any) associated with the specified child. * @param child the specified child * @return the Component (if any) associated with the specified child. */ protected static final Visibility getChildVisibility(Object child) { try { return (Visibility)child; } catch (ClassCastException cce) { return null; } }
/** * <p> * This method is typically called from the environment in order to determine * if the implementor "needs" a GUI. * </p> * <p> * The algorithm used herein tests the BeanContextPeer, and its current children * to determine if they are either Containers, Components, or if they implement * Visibility and return needsGui() == true. * </p> * @return {@code true} if the implementor needs a GUI */ public synchronized boolean needsGui() { BeanContext bc = getBeanContextPeer(); if (bc != this) { if (bc instanceof Visibility) return ((Visibility)bc).needsGui(); if (bc instanceof Container || bc instanceof Component) return true; } synchronized(children) { for (Iterator<Object> i = children.keySet().iterator(); i.hasNext();) { Object c = i.next(); try { return ((Visibility)c).needsGui(); } catch (ClassCastException cce) { // do nothing ... } if (c instanceof Container || c instanceof Component) return true; } } return false; }