src/macosx/classes/sun/lwawt/LWComponentPeer.java

Print this page

        

*** 79,101 **** // The lock to operate with the peers hierarchy. AWT tree // lock is not used as there are many peers related ops // to be done on the toolkit thread, and we don't want to // depend on a public lock on this thread ! private final static Object peerTreeLock = new StringBuilder("LWComponentPeer.peerTreeLock"); ! /** ! * A custom tree-lock used for the hierarchy of the delegate Swing ! * components. ! * The lock synchronizes access to the delegate ! * internal state. Think of it as a 'virtual EDT'. ! */ ! // private final Object delegateTreeLock = ! // new StringBuilder("LWComponentPeer.delegateTreeLock"); ! ! private T target; // Container peer. It may not be the peer of the target's direct // parent, for example, in the case of hw/lw mixing. However, // let's skip this scenario for the time being. We also assume // the container peer is not null, which might also be false if --- 79,92 ---- // The lock to operate with the peers hierarchy. AWT tree // lock is not used as there are many peers related ops // to be done on the toolkit thread, and we don't want to // depend on a public lock on this thread ! private static final Object peerTreeLock = new StringBuilder("LWComponentPeer.peerTreeLock"); ! private final T target; // Container peer. It may not be the peer of the target's direct // parent, for example, in the case of hw/lw mixing. However, // let's skip this scenario for the time being. We also assume // the container peer is not null, which might also be false if
*** 106,132 **** // Handy reference to the top-level window peer. Window peer is // borrowed from the containerPeer in constructor, and should also // be updated when the component is reparented to another container private LWWindowPeer windowPeer; ! private AtomicBoolean disposed = new AtomicBoolean(false); // Bounds are relative to parent peer ! private Rectangle bounds = new Rectangle(); private Region region; // Component state. Should be accessed under the state lock private boolean visible = false; private boolean enabled = true; private Color background; private Color foreground; private Font font; ! // Paint area to coalesce all the paint events and store ! // the target dirty area ! private RepaintArea targetPaintArea; // private volatile boolean paintPending; private volatile boolean isLayouting; private D delegate = null; --- 97,125 ---- // Handy reference to the top-level window peer. Window peer is // borrowed from the containerPeer in constructor, and should also // be updated when the component is reparented to another container private LWWindowPeer windowPeer; ! private final AtomicBoolean disposed = new AtomicBoolean(false); // Bounds are relative to parent peer ! private final Rectangle bounds = new Rectangle(); private Region region; // Component state. Should be accessed under the state lock private boolean visible = false; private boolean enabled = true; private Color background; private Color foreground; private Font font; ! /** ! * Paint area to coalesce all the paint events and store the target dirty ! * area. ! */ ! private final RepaintArea targetPaintArea; // private volatile boolean paintPending; private volatile boolean isLayouting; private D delegate = null;
*** 135,145 **** private final Object dropTargetLock = new Object(); private int fNumDropTargets = 0; private CDropTarget fDropTarget = null; ! private PlatformComponent platformComponent; private final class DelegateContainer extends Container { { enableEvents(0xFFFFFFFF); } --- 128,138 ---- private final Object dropTargetLock = new Object(); private int fNumDropTargets = 0; private CDropTarget fDropTarget = null; ! private final PlatformComponent platformComponent; private final class DelegateContainer extends Container { { enableEvents(0xFFFFFFFF); }
*** 173,182 **** --- 166,176 ---- return getLocation().y; } } public LWComponentPeer(T target, PlatformComponent platformComponent) { + targetPaintArea = new LWRepaintArea(); this.target = target; this.platformComponent = platformComponent; initializeContainerPeer(); // Container peer is always null for LWWindowPeers, so
*** 199,212 **** --- 193,209 ---- setToolkitAWTEventListener(null); synchronized (getDelegateLock()) { delegate = createDelegate(); if (delegate != null) { + delegate.setVisible(false); delegateContainer = new DelegateContainer(); delegateContainer.add(delegate); delegateContainer.addNotify(); delegate.addNotify(); + resetColorsAndFont(delegate); + delegate.setOpaque(true); } else { return; } }
*** 276,306 **** protected Component getDelegateFocusOwner() { return getDelegate(); } ! /* ! * Initializes this peer by fetching all the properties from the target. ! * The call to initialize() is not placed to LWComponentPeer ctor to ! * let the subclass ctor to finish completely first. Instead, it's the ! * LWToolkit object who is responsible for initialization. */ ! public void initialize() { platformComponent.initialize(target, this, getPlatformWindow()); ! targetPaintArea = new LWRepaintArea(); ! if (getDelegate() != null) { ! synchronized (getDelegateLock()) { ! resetColorsAndFont(delegate); ! getDelegate().setOpaque(true); ! } } setBackground(target.getBackground()); setForeground(target.getForeground()); setFont(target.getFont()); setBounds(target.getBounds()); setEnabled(target.isEnabled()); - setVisible(target.isVisible()); } private static void resetColorsAndFont(final Container c) { c.setBackground(null); c.setForeground(null); --- 273,304 ---- protected Component getDelegateFocusOwner() { return getDelegate(); } ! /** ! * Initializes this peer. The call to initialize() is not placed to ! * LWComponentPeer ctor to let the subclass ctor to finish completely first. ! * Instead, it's the LWToolkit object who is responsible for initialization. ! * Note that we call setVisible() at the end of initialization. */ ! public final void initialize() { platformComponent.initialize(target, this, getPlatformWindow()); ! initializeImpl(); ! setVisible(target.isVisible()); } + + /** + * Fetching general properties from the target. Should be overridden in + * subclasses to initialize specific peers properties. + */ + void initializeImpl() { setBackground(target.getBackground()); setForeground(target.getForeground()); setFont(target.getFont()); setBounds(target.getBounds()); setEnabled(target.isEnabled()); } private static void resetColorsAndFont(final Container c) { c.setBackground(null); c.setForeground(null);
*** 312,330 **** final Object getStateLock() { return stateLock; } ! // Synchronize all operations with the Swing delegates under ! // AWT tree lock, using a new separate lock to synchronize ! // access to delegates may lead deadlocks final Object getDelegateLock() { - //return delegateTreeLock; return getTarget().getTreeLock(); } ! protected final static Object getPeerTreeLock() { return peerTreeLock; } final T getTarget() { return target; --- 310,331 ---- final Object getStateLock() { return stateLock; } ! /** ! * Synchronize all operations with the Swing delegates under AWT tree lock, ! * using a new separate lock to synchronize access to delegates may lead ! * deadlocks. Think of it as a 'virtual EDT'. ! * ! * @return DelegateLock ! */ final Object getDelegateLock() { return getTarget().getTreeLock(); } ! protected static final Object getPeerTreeLock() { return peerTreeLock; } final T getTarget() { return target;
*** 756,773 **** return enabled; } } @Override ! public void setVisible(boolean v) { synchronized (getStateLock()) { if (visible == v) { return; } visible = v; } final D delegate = getDelegate(); if (delegate != null) { synchronized (getDelegateLock()) { delegate.setVisible(v); --- 757,777 ---- return enabled; } } @Override ! public void setVisible(final boolean v) { synchronized (getStateLock()) { if (visible == v) { return; } visible = v; } + setVisibleImpl(v); + } + protected void setVisibleImpl(final boolean v) { final D delegate = getDelegate(); if (delegate != null) { synchronized (getDelegateLock()) { delegate.setVisible(v);
*** 1353,1363 **** * peer must be visible, and it must be in a container that is visible and * showing. * * @see #isVisible() */ ! protected boolean isShowing() { synchronized (getPeerTreeLock()) { if (isVisible()) { final LWContainerPeer container = getContainerPeer(); return (container == null) || container.isShowing(); } --- 1357,1367 ---- * peer must be visible, and it must be in a container that is visible and * showing. * * @see #isVisible() */ ! protected final boolean isShowing() { synchronized (getPeerTreeLock()) { if (isVisible()) { final LWContainerPeer container = getContainerPeer(); return (container == null) || container.isShowing(); }