Java Code Examples for java.awt.Component#getPeer()

The following examples show how to use java.awt.Component#getPeer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XComponentPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void addTree(Collection order, Set set, Container cont) {
    for (int i = 0; i < cont.getComponentCount(); i++) {
        Component comp = cont.getComponent(i);
        ComponentPeer peer = comp.getPeer();
        if (peer instanceof XComponentPeer) {
            Long window = Long.valueOf(((XComponentPeer)peer).getWindow());
            if (!set.contains(window)) {
                set.add(window);
                order.add(window);
            }
        } else if (comp instanceof Container) {
            // It is lightweight container, it might contain heavyweight components attached to this
            // peer
            addTree(order, set, (Container)comp);
        }
    }
}
 
Example 2
Source File: KeyboardFocusManagerPeerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static boolean deliverFocus(Component lightweightChild,
                                   Component target,
                                   boolean temporary,
                                   boolean focusedWindowChangeAllowed,
                                   long time,
                                   CausedFocusEvent.Cause cause,
                                   Component currentFocusOwner) // provided by the descendant peers
{
    if (lightweightChild == null) {
        lightweightChild = target;
    }

    Component currentOwner = currentFocusOwner;
    if (currentOwner != null && currentOwner.getPeer() == null) {
        currentOwner = null;
    }
    if (currentOwner != null) {
        FocusEvent fl = new CausedFocusEvent(currentOwner, FocusEvent.FOCUS_LOST,
                                             false, lightweightChild, cause);

        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
            focusLog.finer("Posting focus event: " + fl);
        }
        SunToolkit.postEvent(SunToolkit.targetToAppContext(currentOwner), fl);
    }

    FocusEvent fg = new CausedFocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED,
                                         false, currentOwner, cause);

    if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
        focusLog.finer("Posting focus event: " + fg);
    }
    SunToolkit.postEvent(SunToolkit.targetToAppContext(lightweightChild), fg);
    return true;
}
 
Example 3
Source File: XRepaintArea.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calls <code>Component.paint(Graphics)</code> with given Graphics.
 */
protected void paintComponent(Component comp, Graphics g) {
    if (comp != null) {
        final XComponentPeer peer = (XComponentPeer) comp.getPeer();
        if (peer != null) {
            peer.paintPeer(g);
        }
        super.paintComponent(comp, g);
    }
}
 
Example 4
Source File: D3DScreenUpdateManager.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if the component has heavyweight children.
 *
 * @param comp component to check for hw children
 * @return true if Component has heavyweight children
 */
private static boolean hasHWChildren(Component comp) {
    if (comp instanceof Container) {
        for (Component c : ((Container)comp).getComponents()) {
            if (c.getPeer() instanceof WComponentPeer || hasHWChildren(c)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 5
Source File: XComponentPeer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/****** DropTargetPeer implementation ********************/

    public void addDropTarget(DropTarget dt) {
        Component comp = target;
        while(!(comp == null || comp instanceof Window)) {
            comp = comp.getParent();
        }

        if (comp instanceof Window) {
            XWindowPeer wpeer = (XWindowPeer)(comp.getPeer());
            if (wpeer != null) {
                wpeer.addDropTarget();
            }
        }
    }
 
Example 6
Source File: XComponentPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void removeDropTarget(DropTarget dt) {
    Component comp = target;
    while(!(comp == null || comp instanceof Window)) {
        comp = comp.getParent();
    }

    if (comp instanceof Window) {
        XWindowPeer wpeer = (XWindowPeer)(comp.getPeer());
        if (wpeer != null) {
            wpeer.removeDropTarget();
        }
    }
}
 
Example 7
Source File: KeyboardFocusManagerPeerImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static boolean shouldFocusOnClick(Component component) {
    boolean acceptFocusOnClick = false;

    // A component is generally allowed to accept focus on click
    // if its peer is focusable. There're some exceptions though.


    // CANVAS & SCROLLBAR accept focus on click
    if (component instanceof Canvas ||
        component instanceof Scrollbar)
    {
        acceptFocusOnClick = true;

    // PANEL, empty only, accepts focus on click
    } else if (component instanceof Panel) {
        acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);


    // Other components
    } else {
        ComponentPeer peer = (component != null ? component.getPeer() : null);
        acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
    }
    return acceptFocusOnClick &&
           AWTAccessor.getComponentAccessor().canBeFocusOwner(component);
}
 
Example 8
Source File: D3DScreenUpdateManager.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if the component has heavyweight children.
 *
 * @param comp component to check for hw children
 * @return true if Component has heavyweight children
 */
private static boolean hasHWChildren(Component comp) {
    if (comp instanceof Container) {
        for (Component c : ((Container)comp).getComponents()) {
            if (c.getPeer() instanceof WComponentPeer || hasHWChildren(c)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 9
Source File: XRepaintArea.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calls <code>Component.paint(Graphics)</code> with given Graphics.
 */
protected void paintComponent(Component comp, Graphics g) {
    if (comp != null) {
        final XComponentPeer peer = (XComponentPeer) comp.getPeer();
        if (peer != null) {
            peer.paintPeer(g);
        }
        super.paintComponent(comp, g);
    }
}
 
Example 10
Source File: XComponentPeer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/****** DropTargetPeer implementation ********************/

    public void addDropTarget(DropTarget dt) {
        Component comp = target;
        while(!(comp == null || comp instanceof Window)) {
            comp = comp.getParent();
        }

        if (comp instanceof Window) {
            XWindowPeer wpeer = (XWindowPeer)(comp.getPeer());
            if (wpeer != null) {
                wpeer.addDropTarget();
            }
        }
    }
 
Example 11
Source File: XComponentPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void removeDropTarget(DropTarget dt) {
    Component comp = target;
    while(!(comp == null || comp instanceof Window)) {
        comp = comp.getParent();
    }

    if (comp instanceof Window) {
        XWindowPeer wpeer = (XWindowPeer)(comp.getPeer());
        if (wpeer != null) {
            wpeer.removeDropTarget();
        }
    }
}
 
Example 12
Source File: XComponentPeer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void removeDropTarget(DropTarget dt) {
    Component comp = target;
    while(!(comp == null || comp instanceof Window)) {
        comp = comp.getParent();
    }

    if (comp instanceof Window) {
        XWindowPeer wpeer = (XWindowPeer)(comp.getPeer());
        if (wpeer != null) {
            wpeer.removeDropTarget();
        }
    }
}
 
Example 13
Source File: XRepaintArea.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calls <code>Component.paint(Graphics)</code> with given Graphics.
 */
protected void paintComponent(Component comp, Graphics g) {
    if (comp != null) {
        final XComponentPeer peer = (XComponentPeer) comp.getPeer();
        if (peer != null) {
            peer.paintPeer(g);
        }
        super.paintComponent(comp, g);
    }
}
 
Example 14
Source File: D3DScreenUpdateManager.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if the component has heavyweight children.
 *
 * @param comp component to check for hw children
 * @return true if Component has heavyweight children
 */
private static boolean hasHWChildren(Component comp) {
    if (comp instanceof Container) {
        for (Component c : ((Container)comp).getComponents()) {
            if (c.getPeer() instanceof WComponentPeer || hasHWChildren(c)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 15
Source File: KeyboardFocusManagerPeerImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static boolean shouldFocusOnClick(Component component) {
    boolean acceptFocusOnClick = false;

    // A component is generally allowed to accept focus on click
    // if its peer is focusable. There're some exceptions though.


    // CANVAS & SCROLLBAR accept focus on click
    if (component instanceof Canvas ||
        component instanceof Scrollbar)
    {
        acceptFocusOnClick = true;

    // PANEL, empty only, accepts focus on click
    } else if (component instanceof Panel) {
        acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);


    // Other components
    } else {
        ComponentPeer peer = (component != null ? component.getPeer() : null);
        acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
    }
    return acceptFocusOnClick &&
           AWTAccessor.getComponentAccessor().canBeFocusOwner(component);
}
 
Example 16
Source File: D3DVolatileSurfaceManager.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a pbuffer-based SurfaceData object (or init the backbuffer
 * of an existing window if this is a double buffered GraphicsConfig).
 */
protected SurfaceData initAcceleratedSurface() {
    SurfaceData sData;
    Component comp = vImg.getComponent();
    WComponentPeer peer =
        (comp != null) ? (WComponentPeer)comp.getPeer() : null;

    try {
        boolean forceback = false;
        if (context instanceof Boolean) {
            forceback = ((Boolean)context).booleanValue();
        }

        if (forceback) {
            // peer must be non-null in this case
            sData = D3DSurfaceData.createData(peer, vImg);
        } else {
            D3DGraphicsConfig gc =
                (D3DGraphicsConfig)vImg.getGraphicsConfig();
            ColorModel cm = gc.getColorModel(vImg.getTransparency());
            int type = vImg.getForcedAccelSurfaceType();
            // if acceleration type is forced (type != UNDEFINED) then
            // use the forced type, otherwise use RT_TEXTURE
            if (type == UNDEFINED) {
                type = RT_TEXTURE;
            }
            sData = D3DSurfaceData.createData(gc,
                                              vImg.getWidth(),
                                              vImg.getHeight(),
                                              cm, vImg,
                                              type);
        }
    } catch (NullPointerException ex) {
        sData = null;
    } catch (OutOfMemoryError er) {
        sData = null;
    } catch (InvalidPipeException ipe) {
        sData = null;
    }

    return sData;
}
 
Example 17
Source File: D3DVolatileSurfaceManager.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a pbuffer-based SurfaceData object (or init the backbuffer
 * of an existing window if this is a double buffered GraphicsConfig).
 */
protected SurfaceData initAcceleratedSurface() {
    SurfaceData sData;
    Component comp = vImg.getComponent();
    WComponentPeer peer =
        (comp != null) ? (WComponentPeer)comp.getPeer() : null;

    try {
        boolean forceback = false;
        if (context instanceof Boolean) {
            forceback = ((Boolean)context).booleanValue();
        }

        if (forceback) {
            // peer must be non-null in this case
            sData = D3DSurfaceData.createData(peer, vImg);
        } else {
            D3DGraphicsConfig gc =
                (D3DGraphicsConfig)vImg.getGraphicsConfig();
            ColorModel cm = gc.getColorModel(vImg.getTransparency());
            int type = vImg.getForcedAccelSurfaceType();
            // if acceleration type is forced (type != UNDEFINED) then
            // use the forced type, otherwise use RT_TEXTURE
            if (type == UNDEFINED) {
                type = RT_TEXTURE;
            }
            sData = D3DSurfaceData.createData(gc,
                                              vImg.getWidth(),
                                              vImg.getHeight(),
                                              cm, vImg,
                                              type);
        }
    } catch (NullPointerException ex) {
        sData = null;
    } catch (OutOfMemoryError er) {
        sData = null;
    } catch (InvalidPipeException ipe) {
        sData = null;
    }

    return sData;
}
 
Example 18
Source File: GLXVolatileSurfaceManager.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a pbuffer-based SurfaceData object (or init the backbuffer
 * of an existing window if this is a double buffered GraphicsConfig)
 */
protected SurfaceData initAcceleratedSurface() {
    SurfaceData sData;
    Component comp = vImg.getComponent();
    X11ComponentPeer peer =
        (comp != null) ? (X11ComponentPeer)comp.getPeer() : null;

    try {
        boolean createVSynced = false;
        boolean forceback = false;
        if (context instanceof Boolean) {
            forceback = ((Boolean)context).booleanValue();
            if (forceback && peer instanceof BackBufferCapsProvider) {
                BackBufferCapsProvider provider =
                    (BackBufferCapsProvider)peer;
                BufferCapabilities caps = provider.getBackBufferCaps();
                if (caps instanceof ExtendedBufferCapabilities) {
                    ExtendedBufferCapabilities ebc =
                        (ExtendedBufferCapabilities)caps;
                    if (ebc.getVSync() == VSYNC_ON &&
                        ebc.getFlipContents() == COPIED)
                    {
                        createVSynced = true;
                        forceback = false;
                    }
                }
            }
        }

        if (forceback) {
            // peer must be non-null in this case
            sData = GLXSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
        } else {
            GLXGraphicsConfig gc =
                (GLXGraphicsConfig)vImg.getGraphicsConfig();
            ColorModel cm = gc.getColorModel(vImg.getTransparency());
            int type = vImg.getForcedAccelSurfaceType();
            // if acceleration type is forced (type != UNDEFINED) then
            // use the forced type, otherwise choose one based on caps
            if (type == OGLSurfaceData.UNDEFINED) {
                type = gc.isCapPresent(CAPS_EXT_FBOBJECT) ?
                    OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER;
            }
            if (createVSynced) {
                sData = GLXSurfaceData.createData(peer, vImg, type);
            } else {
                sData = GLXSurfaceData.createData(gc,
                                                  vImg.getWidth(),
                                                  vImg.getHeight(),
                                                  cm, vImg, type);
            }
        }
    } catch (NullPointerException ex) {
        sData = null;
    } catch (OutOfMemoryError er) {
        sData = null;
    }

    return sData;
}
 
Example 19
Source File: CGLVolatileSurfaceManager.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
     * Create a pbuffer-based SurfaceData object (or init the backbuffer
     * of an existing window if this is a double buffered GraphicsConfig)
     */
    protected SurfaceData initAcceleratedSurface() {
        SurfaceData sData = null;
        Component comp = vImg.getComponent();
        final ComponentPeer peer = (comp != null) ? comp.getPeer() : null;

        try {
            boolean createVSynced = false;
            boolean forceback = false;
            if (context instanceof Boolean) {
                forceback = ((Boolean)context).booleanValue();
                if (forceback && peer instanceof BackBufferCapsProvider) {
                    BackBufferCapsProvider provider =
                        (BackBufferCapsProvider)peer;
                    BufferCapabilities caps = provider.getBackBufferCaps();
                    if (caps instanceof ExtendedBufferCapabilities) {
                        ExtendedBufferCapabilities ebc =
                            (ExtendedBufferCapabilities)caps;
                        if (ebc.getVSync() == VSYNC_ON &&
                            ebc.getFlipContents() == COPIED)
                        {
                            createVSynced = true;
                            forceback = false;
                        }
                    }
                }
            }

            if (forceback) {
                // peer must be non-null in this case
                // TODO: modify parameter to delegate
                //                sData = CGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
            } else {
                CGLGraphicsConfig gc =
                    (CGLGraphicsConfig)vImg.getGraphicsConfig();
                ColorModel cm = gc.getColorModel(vImg.getTransparency());
                int type = vImg.getForcedAccelSurfaceType();
                // if acceleration type is forced (type != UNDEFINED) then
                // use the forced type, otherwise choose one based on caps
                if (type == OGLSurfaceData.UNDEFINED) {
                    type = gc.isCapPresent(CAPS_EXT_FBOBJECT) ?
                        OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER;
                }
                if (createVSynced) {
                    // TODO: modify parameter to delegate
//                  sData = CGLSurfaceData.createData(peer, vImg, type);
                } else {
                    sData = CGLSurfaceData.createData(gc,
                                                      vImg.getWidth(),
                                                      vImg.getHeight(),
                                                      cm, vImg, type);
                }
            }
        } catch (NullPointerException ex) {
            sData = null;
        } catch (OutOfMemoryError er) {
            sData = null;
        }

        return sData;
    }
 
Example 20
Source File: CGLVolatileSurfaceManager.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
     * Create a pbuffer-based SurfaceData object (or init the backbuffer
     * of an existing window if this is a double buffered GraphicsConfig)
     */
    protected SurfaceData initAcceleratedSurface() {
        SurfaceData sData = null;
        Component comp = vImg.getComponent();
        final ComponentPeer peer = (comp != null) ? comp.getPeer() : null;

        try {
            boolean createVSynced = false;
            boolean forceback = false;
            if (context instanceof Boolean) {
                forceback = ((Boolean)context).booleanValue();
                if (forceback && peer instanceof BackBufferCapsProvider) {
                    BackBufferCapsProvider provider =
                        (BackBufferCapsProvider)peer;
                    BufferCapabilities caps = provider.getBackBufferCaps();
                    if (caps instanceof ExtendedBufferCapabilities) {
                        ExtendedBufferCapabilities ebc =
                            (ExtendedBufferCapabilities)caps;
                        if (ebc.getVSync() == VSYNC_ON &&
                            ebc.getFlipContents() == COPIED)
                        {
                            createVSynced = true;
                            forceback = false;
                        }
                    }
                }
            }

            if (forceback) {
                // peer must be non-null in this case
                // TODO: modify parameter to delegate
                //                sData = CGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
            } else {
                CGLGraphicsConfig gc =
                    (CGLGraphicsConfig)vImg.getGraphicsConfig();
                ColorModel cm = gc.getColorModel(vImg.getTransparency());
                int type = vImg.getForcedAccelSurfaceType();
                // if acceleration type is forced (type != UNDEFINED) then
                // use the forced type, otherwise choose one based on caps
                if (type == OGLSurfaceData.UNDEFINED) {
                    type = gc.isCapPresent(CAPS_EXT_FBOBJECT) ?
                        OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER;
                }
                if (createVSynced) {
                    // TODO: modify parameter to delegate
//                  sData = CGLSurfaceData.createData(peer, vImg, type);
                } else {
                    sData = CGLSurfaceData.createData(gc,
                                                      vImg.getWidth(),
                                                      vImg.getHeight(),
                                                      cm, vImg, type);
                }
            }
        } catch (NullPointerException ex) {
            sData = null;
        } catch (OutOfMemoryError er) {
            sData = null;
        }

        return sData;
    }