LWComponentPeer.java revision 5232
4767N/A * Copyright (c) 2011, 2012, 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 // 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 5166N/A * Paint area to coalesce all the paint events and store the target dirty 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 * 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. 5166N/A * Initializes this peer. The call to initialize() is not placed to 5166N/A * LWComponentPeer ctor to let the subclass ctor to finish completely first. 5166N/A * Instead, it's the LWToolkit object who is responsible for initialization. 5166N/A * Note that we call setVisible() at the end of initialization. 5166N/A * Fetching general properties from the target. Should be overridden in 5166N/A * subclasses to initialize specific peers properties. 5166N/A * Synchronize all operations with the Swing delegates under AWT tree lock, 5166N/A * using a new separate lock to synchronize access to delegates may lead 5166N/A * deadlocks. Think of it as a 'virtual EDT'. 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 5137N/A * Returns the cursor of the peer, which is cursor of the target by default, 5137N/A * but peer can override this behavior. 5137N/A * @param p Point relative to the peer. 5137N/A * @return Cursor of the peer or null if default cursor should be used. 4632N/A // delegate will repaint the target 4691N/A // delegate will repaint the target 4632N/A // delegate will repaint the target 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 4886N/A // A fix for 7145768. Ensure the parent window is currently natively focused. 4886N/A // The more evident place to perform this check is in KFM.shouldNativelyFocusHeavyweight, 4886N/A // however that is the shared code and this particular problem's reproducibility has 4886N/A // platform specifics. So, it was decided to narrow down the fix to lwawt (OSX) in 4886N/A // current release. TODO: consider fixing it in the shared code. 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 4830N/A // We need to register the DropTarget in the 4830N/A // peer of the window ancestor of the component 4830N/A // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only 4830N/A // if it's the first (or last) one for the component. Otherwise this call is a no-op. 4830N/A // Having a non-null drop target would be an error but let's check just in case: 4830N/A // Create a new drop target: 4830N/A // We need to unregister the DropTarget in the 4830N/A // peer of the window ancestor of the component 4830N/A // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only 4830N/A // if it's the first (or last) one for the component. Otherwise this call is a no-op. 4830N/A // Having a null drop target would be an error but let's check just in case: 4830N/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 4717N/A // Anyway request focus to the toplevel. 4632N/A // Note that the peer receives all the FocusEvents from 4632N/A // its lightweight children as well 4767N/A * All peers should clear background before paint. 4639N/A * @return false on components that DO NOT require a clearRect() before 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 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.