Search in sources :

Example 6 with ComponentPeer

use of java.awt.peer.ComponentPeer in project jdk8u_jdk by JetBrains.

the class DefaultKeyboardFocusManager method preDispatchKeyEvent.

private boolean preDispatchKeyEvent(KeyEvent ke) {
    if (((AWTEvent) ke).isPosted) {
        Component focusOwner = getFocusOwner();
        ke.setSource(((focusOwner != null) ? focusOwner : getFocusedWindow()));
    }
    if (ke.getSource() == null) {
        return true;
    }
    // Explicitly set the key event timestamp here (not in Component.dispatchEventImpl):
    // - A key event is anyway passed to this method which starts its actual dispatching.
    // - If a key event is put to the type ahead queue, its time stamp should not be registered
    //   until its dispatching actually starts (by this method).
    EventQueue.setCurrentEventAndMostRecentTime(ke);
    /**
         * Fix for 4495473.
         * This fix allows to correctly dispatch events when native
         * event proxying mechanism is active.
         * If it is active we should redispatch key events after
         * we detected its correct target.
         */
    if (KeyboardFocusManager.isProxyActive(ke)) {
        Component source = (Component) ke.getSource();
        Container target = source.getNativeContainer();
        if (target != null) {
            ComponentPeer peer = target.getPeer();
            if (peer != null) {
                peer.handleEvent(ke);
                /**
                     * Fix for 4478780 - consume event after it was dispatched by peer.
                     */
                ke.consume();
            }
        }
        return true;
    }
    java.util.List<KeyEventDispatcher> dispatchers = getKeyEventDispatchers();
    if (dispatchers != null) {
        for (java.util.Iterator<KeyEventDispatcher> iter = dispatchers.iterator(); iter.hasNext(); ) {
            if (iter.next().dispatchKeyEvent(ke)) {
                return true;
            }
        }
    }
    return dispatchKeyEvent(ke);
}
Also used : ComponentPeer(java.awt.peer.ComponentPeer)

Example 7 with ComponentPeer

use of java.awt.peer.ComponentPeer in project jdk8u_jdk by JetBrains.

the class Component method getGraphics_NoClientCode.

final Graphics getGraphics_NoClientCode() {
    ComponentPeer peer = this.peer;
    if (peer instanceof LightweightPeer) {
        // This is for a lightweight component, need to
        // translate coordinate spaces and clip relative
        // to the parent.
        Container parent = this.parent;
        if (parent == null)
            return null;
        Graphics g = parent.getGraphics_NoClientCode();
        if (g == null)
            return null;
        if (g instanceof ConstrainableGraphics) {
            ((ConstrainableGraphics) g).constrain(x, y, width, height);
        } else {
            g.translate(x, y);
            g.setClip(0, 0, width, height);
        }
        g.setFont(getFont_NoClientCode());
        return g;
    } else {
        return (peer != null) ? peer.getGraphics() : null;
    }
}
Also used : LightweightPeer(java.awt.peer.LightweightPeer) ConstrainableGraphics(sun.awt.ConstrainableGraphics) ConstrainableGraphics(sun.awt.ConstrainableGraphics) ComponentPeer(java.awt.peer.ComponentPeer)

Example 8 with ComponentPeer

use of java.awt.peer.ComponentPeer in project jdk8u_jdk by JetBrains.

the class Component method show.

/**
     * @deprecated As of JDK version 1.1,
     * replaced by <code>setVisible(boolean)</code>.
     */
@Deprecated
public void show() {
    if (!visible) {
        synchronized (getTreeLock()) {
            visible = true;
            mixOnShowing();
            ComponentPeer peer = this.peer;
            if (peer != null) {
                peer.setVisible(true);
                createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, this, parent, HierarchyEvent.SHOWING_CHANGED, Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
                if (peer instanceof LightweightPeer) {
                    repaint();
                }
                updateCursorImmediately();
            }
            if (componentListener != null || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 || Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) {
                ComponentEvent e = new ComponentEvent(this, ComponentEvent.COMPONENT_SHOWN);
                Toolkit.getEventQueue().postEvent(e);
            }
        }
        Container parent = this.parent;
        if (parent != null) {
            parent.invalidate();
        }
    }
}
Also used : LightweightPeer(java.awt.peer.LightweightPeer) ComponentPeer(java.awt.peer.ComponentPeer)

Example 9 with ComponentPeer

use of java.awt.peer.ComponentPeer in project jdk8u_jdk by JetBrains.

the class Component method disable.

/**
     * @deprecated As of JDK version 1.1,
     * replaced by <code>setEnabled(boolean)</code>.
     */
@Deprecated
public void disable() {
    if (enabled) {
        KeyboardFocusManager.clearMostRecentFocusOwner(this);
        synchronized (getTreeLock()) {
            enabled = false;
            // A disabled lw container is allowed to contain a focus owner.
            if ((isFocusOwner() || (containsFocus() && !isLightweight())) && KeyboardFocusManager.isAutoFocusTransferEnabled()) {
                // Don't clear the global focus owner. If transferFocus
                // fails, we want the focus to stay on the disabled
                // Component so that keyboard traversal, et. al. still
                // makes sense to the user.
                transferFocus(false);
            }
            ComponentPeer peer = this.peer;
            if (peer != null) {
                peer.setEnabled(false);
                if (visible && !getRecursivelyVisibleBounds().isEmpty()) {
                    updateCursorImmediately();
                }
            }
        }
        if (accessibleContext != null) {
            accessibleContext.firePropertyChange(AccessibleContext.ACCESSIBLE_STATE_PROPERTY, null, AccessibleState.ENABLED);
        }
    }
}
Also used : ComponentPeer(java.awt.peer.ComponentPeer)

Example 10 with ComponentPeer

use of java.awt.peer.ComponentPeer in project jdk8u_jdk by JetBrains.

the class Component method setFont.

/**
     * Sets the font of this component.
     * <p>
     * This method changes layout-related information, and therefore,
     * invalidates the component hierarchy.
     *
     * @param f the font to become this component's font;
     *          if this parameter is <code>null</code> then this
     *          component will inherit the font of its parent
     * @see #getFont
     * @see #invalidate
     * @since JDK1.0
     * @beaninfo
     *       bound: true
     */
public void setFont(Font f) {
    Font oldFont, newFont;
    synchronized (getTreeLock()) {
        oldFont = font;
        newFont = font = f;
        ComponentPeer peer = this.peer;
        if (peer != null) {
            f = getFont();
            if (f != null) {
                peer.setFont(f);
                peerFont = f;
            }
        }
    }
    // This is a bound property, so report the change to
    // any registered listeners.  (Cheap if there are none.)
    firePropertyChange("font", oldFont, newFont);
    // call invalidate() if they are equal.
    if (f != oldFont && (oldFont == null || !oldFont.equals(f))) {
        invalidateIfValid();
    }
}
Also used : ComponentPeer(java.awt.peer.ComponentPeer)

Aggregations

ComponentPeer (java.awt.peer.ComponentPeer)41 LightweightPeer (java.awt.peer.LightweightPeer)10 Component (java.awt.Component)5 Container (java.awt.Container)3 InputContext (java.awt.im.InputContext)2 ConstrainableGraphics (sun.awt.ConstrainableGraphics)2 Pointer (com.sun.jna.Pointer)1 BufferCapabilities (java.awt.BufferCapabilities)1 HeadlessException (java.awt.HeadlessException)1 AffineTransform (java.awt.geom.AffineTransform)1 ColorModel (java.awt.image.ColorModel)1 FramePeer (java.awt.peer.FramePeer)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 TooManyListenersException (java.util.TooManyListenersException)1 AppContext (sun.awt.AppContext)1 CausedFocusEvent (sun.awt.CausedFocusEvent)1 SunToolkit (sun.awt.SunToolkit)1 WindowClosingListener (sun.awt.WindowClosingListener)1 SunDropTargetEvent (sun.awt.dnd.SunDropTargetEvent)1