LWComponentPeer.java revision 4639
4632N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4632N/A * This code is free software; you can redistribute it and/or modify it 4632N/A * under the terms of the GNU General Public License version 2 only, as 4632N/A * published by the Free Software Foundation. Oracle designates this 4632N/A * particular file as subject to the "Classpath" exception as provided 4632N/A * by Oracle in the LICENSE file that accompanied this code. 4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT 4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4632N/A * version 2 for more details (a copy is included in the LICENSE file that 4632N/A * You should have received a copy of the GNU General Public License version 4632N/A * 2 along with this work; if not, write to the Free Software Foundation, 4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4632N/A * or visit www.oracle.com if you need additional information or have any 4632N/A // State lock is to be used for modifications to this 4632N/A // peer's fields (e.g. bounds, background, font, etc.) 4632N/A // It should be the last lock in the lock chain 4632N/A // The lock to operate with the peers hierarchy. AWT tree 4632N/A // lock is not used as there are many peers related ops 4632N/A // to be done on the toolkit thread, and we don't want to 4632N/A // depend on a public lock on this thread 4632N/A * A custom tree-lock used for the hierarchy of the delegate Swing 4632N/A * The lock synchronizes access to the delegate 4632N/A * internal state. Think of it as a 'virtual EDT'. 4632N/A// private final Object delegateTreeLock = 4632N/A// new StringBuilder("LWComponentPeer.delegateTreeLock"); 4632N/A // Container peer. It may not be the peer of the target's direct 4632N/A // parent, for example, in the case of hw/lw mixing. However, 4632N/A // let's skip this scenario for the time being. We also assume 4632N/A // the container peer is not null, which might also be false if 4632N/A // addNotify() is called for a component outside of the hierarchy. 4632N/A // The exception is LWWindowPeers: their parents are always null 4632N/A // Handy reference to the top-level window peer. Window peer is 4632N/A // borrowed from the containerPeer in constructor, and should also 4632N/A // be updated when the component is reparented to another container 4632N/A // Bounds are relative to parent peer 4632N/A // Component state. Should be accessed under the state lock 4632N/A // Paint area to coalesce all the paint events and store 4632N/A // private volatile boolean paintPending; 4632N/A // Container peer is always null for LWWindowPeers, so 4632N/A // windowPeer is always null for them as well. On the other 4632N/A // hand, LWWindowPeer shouldn't use windowPeer at all 4632N/A // don't bother about z-order here as updateZOrder() 4632N/A // will be called from addNotify() later anyway 4632N/A // the delegate must be created after the target is set 4632N/A // todo swing: later on we will probably have one global RM 4632N/A // Repainting in Swing is asynchronous, so it is emulated here by using invokeLater() 4632N/A // to extract the painting call from the event's processing routine 4632N/A //TODO: so why exactly do we have to emulate this in lwawt? We use a back-buffer anyway, 4632N/A //why not paint the components synchronously into the buffer? 4632N/A * This method must be called under Toolkit.getDefaultToolkit() lock 4632N/A * and followed by setToolkitAWTEventListener() 4632N/A * This method is called under getDelegateLock(). 4632N/A * Overridden in subclasses. 4632N/A * Initializes this peer by fetching all the properties from the target. 4632N/A * The call to initialize() is not placed to LWComponentPeer ctor to 4632N/A * let the subclass ctor to finish completely first. Instead, it's the 4632N/A * LWToolkit object who is responsible for initialization. 4639N/A // we must explicitly set the font here 4639N/A // see Component.getFont_NoClientCode() for details 4632N/A // Synchronize all operations with the Swing delegates under 4632N/A // AWT tree lock, using a new separate lock to synchronize 4632N/A // access to delegates may lead deadlocks 4632N/A // Returns the window peer or null if this is a window peer 4632N/A // Returns the window peer or 'this' if this is a window peer 4639N/A // Overridden in LWWindowPeer to skip containerPeer initialization 4632N/A // ---- PEER METHODS ---- // 4632N/A * GraphicsConfiguration is borrowed from the parent peer. The 4632N/A * return value must not be null. 4632N/A * Overridden in LWWindowPeer. 4632N/A // Don't check windowPeer for null as it can only happen 4632N/A // for windows, but this method is overridden in 4632N/A // LWWindowPeer and doesn't call super() 4632N/A * Overridden in LWWindowPeer to replace its surface 4632N/A// throw new RuntimeException("Has not been implemented yet."); 4632N/A * Peer Graphics is borrowed from the parent peer, while 4632N/A * foreground and background colors and font are specific to 4639N/A // translate and set rectangle constrain. 4639N/A //sg2d.constrain(getVisibleRegion()); 4639N/A //TODO Move this method to SG2D? 4639N/A //validateCompClip() forced call. 4632N/A // Is it a correct implementation? 4632N/A "Window or Canvas components.");
4632N/A * To be overridden in LWWindowPeer and LWCanvasPeer. 4632N/A // Return null or throw AWTException? 4632N/A // Skip silently or throw AWTException? 4639N/A * This method could be called on the toolkit thread. 4639N/A // TODO: the following means that the delegateContainer NEVER gets validated. That's WRONG! 4632N/A // Return a copy to prevent subsequent modifications 4639N/A // Return a copy to prevent subsequent modifications 4632N/A // delegate will repaint the target 4632N/A // delegate will repaint the target 4632N/A // delegate will repaint the target 4632N/A // we must explicitly set the font here 4632N/A // see Component.getFont_NoClientCode() for details 4632N/A // Borrow the metrics from the top-level window 4632N/A// return getWindowPeer().getFontMetrics(f); 4632N/A // Obtain the metrics from the offscreen window where this peer is 4632N/A // TODO: check for "use platform metrics" settings 4632N/A // Don't check containerPeer for null as it can only happen 4632N/A // for windows, but this method is overridden in 4632N/A // LWWindowPeer and doesn't call super() 4632N/A * Should be overridden in subclasses which use complex Swing components. 4639N/A * Should be overridden in subclasses to forward the request 4632N/A * to the Swing helper component, if required. 4632N/A // It looks like a default implementation for all toolkits 4632N/A * Should be overridden in subclasses to forward the request 4632N/A * to the Swing helper component. 4632N/A // Is it a correct default value? 4632N/A // Overridden in focusable subclasses like buttons 4632N/A // If parent window can be made focused and has been made focused (synchronously) 4632N/A // then we can proceed with children, otherwise we retreat 4632N/A // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only 4632N/A // if it's the first (or last) one for the component. Otherwise this call is a no-op. 4632N/A // Having a non-null drop target would be an error but let's check just in case: 4632N/A // Create a new drop target: 4632N/A // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only 4632N/A // if it's the first (or last) one for the component. Otherwise this call is a no-op. 4632N/A // Having a null drop target would be an error but let's check just in case: 4632N/A // Dispose of the drop target: 4632N/A // ---- PEER NOTIFICATIONS ---- // 4632N/A * Called when this peer's location has been changed either as a result 4632N/A * of target.setLocation() or as a result of user actions (window is 4632N/A * To be overridden in LWWindowPeer to update its GraphicsConfig. 4632N/A * This method could be called on the toolkit thread. 4632N/A * Called when this peer's size has been changed either as a result of 4632N/A * target.setSize() or as a result of user actions (window is resized). 4632N/A * To be overridden in LWWindowPeer to update its SurfaceData and 4632N/A * This method could be called on the toolkit thread. 4632N/A // Repaint unobscured part of the parent 4632N/A * Post an event to the proper Java EDT. 4632N/A // TODO: call getIgnoreRepaint() directly with the right ACC 4632N/A * Gives a chance for the peer to handle the event after it's been 4632N/A // Got a native paint event 4632N/A // fall through to the next statement 4632N/A 3,
// TODO: wheel scroll amount 4632N/A // Note that the peer receives all the FocusEvents from 4632N/A // its lightweight children as well 4639N/A * Peers with null delegates should clear background before paint. 4639N/A * @return false on components that DO NOT require a clearRect() before 4639N/A // By default, just fill the entire bounds with a bg color 4639N/A // TODO: sun.awt.noerasebackground 4632N/A * Handler for PAINT and UPDATE PaintEvents. 4632N/A // Skip all painting while layouting and all UPDATEs 4632N/A // while waiting for native paint 4632N/A// if (!isLayouting && !paintPending) { 4632N/A // ---- UTILITY METHODS ---- // 4632N/A * Finds a top-most visible component for the given point. The location is 4632N/A * specified relative to the peer's parent. 4632N/A * Translated the given point in Window coordinates to the point in 4632N/A * coordinates local to this component. The given window peer must be 4632N/A * the window where this component is in. 4632N/A // Return a copy to prevent subsequent modifications 4632N/A // Return a copy to prevent subsequent modifications 4632N/A * Determines whether this peer is showing on screen. This means that the 4632N/A * peer must be visible, and it must be in a container that is visible and 4639N/A * Paints the peer. Overridden in subclasses to delegate the actual painting 4632N/A // JComponent.print() is guaranteed to not affect the double buffer 4632N/A // Just a helper method, thus final 4632N/A * Flushes the given rectangle from the back buffer to the screen. 4632N/A // g is a screen Graphics from the delegate 4639N/A * Used by ContainerPeer to skip all the paint events during layout. 4639N/A * @param isLayouting layouting state. 4639N/A * Returns layouting state. Used by ComponentPeer to skip all the paint 4639N/A * @return true during layout, false otherwise.