sun.awt.AWTAccessor.ComponentAccessor Java Examples

The following examples show how to use sun.awt.AWTAccessor.ComponentAccessor. 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: XWindowPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void recursivelySetIcon(java.util.List<IconInfo> icons) {
    dumpIcons(winAttr.icons);
    setIconHints(icons);
    Window target = (Window)this.target;
    Window[] children = target.getOwnedWindows();
    int cnt = children.length;
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    for (int i = 0; i < cnt; i++) {
        final ComponentPeer childPeer = acc.getPeer(children[i]);
        if (childPeer != null && childPeer instanceof XWindowPeer) {
            if (((XWindowPeer)childPeer).winAttr.iconsInherited) {
                ((XWindowPeer)childPeer).winAttr.icons = icons;
                ((XWindowPeer)childPeer).recursivelySetIcon(icons);
            }
        }
    }
}
 
Example #2
Source File: WInputMethod.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private WComponentPeer getNearestNativePeer(Component comp)
{
    if (comp==null)     return null;
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    ComponentPeer peer = acc.getPeer(comp);
    if (peer==null)     return null;

    while (peer instanceof java.awt.peer.LightweightPeer) {
        comp = comp.getParent();
        if (comp==null) return null;
        peer = acc.getPeer(comp);
        if (peer==null) return null;
    }

    if (peer instanceof WComponentPeer)
        return (WComponentPeer)peer;
    else
        return null;

}
 
Example #3
Source File: D3DGraphicsDevice.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void addFSWindowListener(Window w) {
    // if the window is not a toplevel (has an owner) we have to use the
    // real toplevel to enter the full-screen mode with (4933099).
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    if (!(w instanceof Frame) && !(w instanceof Dialog) &&
        (realFSWindow = getToplevelOwner(w)) != null)
    {
        ownerOrigBounds = realFSWindow.getBounds();
        WWindowPeer fp = acc.getPeer(realFSWindow);
        ownerWasVisible = realFSWindow.isVisible();
        Rectangle r = w.getBounds();
        // we use operations on peer instead of component because calling
        // them on component will take the tree lock
        fp.reshape(r.x, r.y, r.width, r.height);
        fp.setVisible(true);
    } else {
        realFSWindow = w;
    }

    fsWindowWasAlwaysOnTop = realFSWindow.isAlwaysOnTop();
    ((WWindowPeer) acc.getPeer(realFSWindow)).setAlwaysOnTop(true);

    fsWindowListener = new D3DFSWindowAdapter();
    realFSWindow.addWindowListener(fsWindowListener);
}
 
Example #4
Source File: XPanelPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void setForegroundForHierarchy(Container cont, Color c) {
    synchronized(target.getTreeLock()) {
        final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
        int n = cont.getComponentCount();
        for(int i=0; i < n; i++) {
            Component comp = cont.getComponent(i);
            Color color = comp.getForeground();
            if (color == null || color.equals(c)) {
                ComponentPeer cpeer = acc.getPeer(comp);
                if (cpeer != null) {
                    cpeer.setForeground(c);
                }
                if (cpeer instanceof LightweightPeer
                    && comp instanceof Container)
                {
                    setForegroundForHierarchy((Container) comp, c);
                }
            }
        }
    }
}
 
Example #5
Source File: XPanelPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void setBackground(Color c) {
    Component comp;
    int i;

    Container cont = (Container) target;
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    synchronized(target.getTreeLock()) {
        int n = cont.getComponentCount();
        for(i=0; i < n; i++) {
            comp = cont.getComponent(i);
            ComponentPeer peer = acc.getPeer(comp);
            if (peer != null) {
                Color color = comp.getBackground();
                if (color == null || color.equals(c)) {
                    peer.setBackground(c);
                }
            }
        }
    }
    super.setBackground(c);
}
 
Example #6
Source File: XWindowPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void repositionSecurityWarning() {
    // NOTE: On KWin if the window/border snapping option is enabled,
    // the Java window may be swinging while it's being moved.
    // This doesn't make the application unusable though looks quite ugly.
    // Probobly we need to find some hint to assign to our Security
    // Warning window in order to exclude it from the snapping option.
    // We are not currently aware of existance of such a property.
    if (warningWindow != null) {
        // We can't use the coordinates stored in the XBaseWindow since
        // they are zeros for decorated frames.
        ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
        int x = compAccessor.getX(target);
        int y = compAccessor.getY(target);
        int width = compAccessor.getWidth(target);
        int height = compAccessor.getHeight(target);
        warningWindow.reposition(x, y, width, height);
    }
}
 
Example #7
Source File: XWindow.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void handleExposeEvent(XEvent xev) {
    super.handleExposeEvent(xev);
    XExposeEvent xe = xev.get_xexpose();
    if (isEventDisabled(xev)) {
        return;
    }

    int x = scaleDown(xe.get_x());
    int y = scaleDown(xe.get_y());
    int w = scaleDown(xe.get_width());
    int h = scaleDown(xe.get_height());

    Component target = getEventSource();
    ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();

    if (!compAccessor.getIgnoreRepaint(target)
        && compAccessor.getWidth(target) != 0
        && compAccessor.getHeight(target) != 0)
    {
        postPaintEvent(target, x, y, w, h);
    }
}
 
Example #8
Source File: XWindow.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static XWindow getParentXWindowObject(Component target) {
    if (target == null) return null;
    Component temp = target.getParent();
    if (temp == null) return null;
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    ComponentPeer peer = acc.getPeer(temp);
    if (peer == null) return null;
    while ((peer != null) && !(peer instanceof XWindow))
    {
        temp = temp.getParent();
        peer = acc.getPeer(temp);
    }
    if (peer != null && peer instanceof XWindow)
        return (XWindow) peer;
    else return null;
}
 
Example #9
Source File: TestXEmbedServer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void addClient() {
    client = new Canvas() {
            public void paint(Graphics g) {
                super.paint(g);
            }
        };
    client.setBackground(new Color(30, 220, 40));
    clientCont.add(client);
    clientCont.validate();
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    WindowIDProvider pid = (WindowIDProvider)acc.getPeer(client);
    log.fine("Added XEmbed server(Canvas) with X window ID " + pid.getWindow());
    Rectangle toFocusBounds = toFocus.getBounds();
    toFocusBounds.setLocation(toFocus.getLocationOnScreen());
    f.validate();

    // KDE doesn't accept clicks on title as activation - click below title
    Rectangle fbounds = f.getBounds();
    fbounds.y += f.getInsets().top;
    fbounds.height -= f.getInsets().top;

    Process proc = startClient(new Rectangle[] {fbounds, dummy.getBounds(), toFocusBounds,
                                                new Rectangle(b_modal.getLocationOnScreen(), b_modal.getSize()),
                                                new Rectangle(10, 130, 20, 20)}, pid.getWindow());
    new ClientWatcher(client, proc, clientCont).start();
}
 
Example #10
Source File: KeyboardFocusManagerPeerImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    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 ? acc.getPeer(component) : null);
        acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
    }
    return acceptFocusOnClick && acc.canBeFocusOwner(component);
}
 
Example #11
Source File: DropTarget.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Notify the DropTarget that it has been associated with a Component
 *
 **********************************************************************
 * This method is usually called from java.awt.Component.addNotify() of
 * the Component associated with this DropTarget to notify the DropTarget
 * that a ComponentPeer has been associated with that Component.
 *
 * Calling this method, other than to notify this DropTarget of the
 * association of the ComponentPeer with the Component may result in
 * a malfunction of the DnD system.
 **********************************************************************
 */
public void addNotify() {
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    ComponentPeer peer = acc.getPeer(component);
    if (peer == null || peer == componentPeer) {
        return;
    }

    componentPeer = peer;


    for (Component c = component;
         c != null && peer instanceof LightweightPeer; c = c.getParent()) {
        peer = acc.getPeer(c);
    }

    if (peer instanceof DropTargetPeer) {
        nativePeer = (DropTargetPeer) peer;
        ((DropTargetPeer)peer).addDropTarget(this);
    } else {
        nativePeer = null;
    }
}
 
Example #12
Source File: KeyboardFocusManagerPeerImpl.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
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
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    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 ? acc.getPeer(component) : null);
        acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
    }
    return acceptFocusOnClick && acc.canBeFocusOwner(component);
}
 
Example #13
Source File: DropTarget.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Notify the DropTarget that it has been associated with a Component
 *
 **********************************************************************
 * This method is usually called from java.awt.Component.addNotify() of
 * the Component associated with this DropTarget to notify the DropTarget
 * that a ComponentPeer has been associated with that Component.
 *
 * Calling this method, other than to notify this DropTarget of the
 * association of the ComponentPeer with the Component may result in
 * a malfunction of the DnD system.
 **********************************************************************
 */
public void addNotify() {
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    ComponentPeer peer = acc.getPeer(component);
    if (peer == null || peer == componentPeer) {
        return;
    }

    componentPeer = peer;


    for (Component c = component;
         c != null && peer instanceof LightweightPeer; c = c.getParent()) {
        peer = acc.getPeer(c);
    }

    if (peer instanceof DropTargetPeer) {
        nativePeer = (DropTargetPeer) peer;
        ((DropTargetPeer)peer).addDropTarget(this);
    } else {
        nativePeer = null;
    }
}
 
Example #14
Source File: XFileDialogPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public boolean dispatchKeyEvent(KeyEvent keyEvent) {
    int id = keyEvent.getID();
    int keyCode = keyEvent.getKeyCode();

    if (id == KeyEvent.KEY_PRESSED && keyCode == KeyEvent.VK_ESCAPE) {
        synchronized (target.getTreeLock()) {
            Component comp = (Component) keyEvent.getSource();
            while (comp != null) {
                // Fix for 6240084 Disposing a file dialog when the drop-down is active does not dispose the dropdown menu, on Xtoolkit
                // See also 6259493
                ComponentAccessor acc = AWTAccessor.getComponentAccessor();
                if (comp == pathChoice) {
                    XChoicePeer choicePeer = acc.getPeer(pathChoice);
                    if (choicePeer.isUnfurled()){
                        return false;
                    }
                }
                Object peer = acc.getPeer(comp);
                if (peer == this) {
                    handleCancel();
                    return true;
                }
                comp = comp.getParent();
            }
        }
    }

    return false;
}
 
Example #15
Source File: WPrinterJob.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public PrintRequestAttributeSet
    showDocumentProperties(Window owner,
                           PrintService service,
                           PrintRequestAttributeSet aset)
{
    try {
        setNativePrintServiceIfNeeded(service.getName());
    } catch (PrinterException e) {
    }
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    long hWnd = acc.<WComponentPeer>getPeer(owner).getHWnd();
    DevModeValues info = new DevModeValues();
    getDevModeValues(aset, info);
    boolean ok =
        showDocProperties(hWnd, aset,
                          info.dmFields,
                          info.copies,
                          info.collate,
                          info.color,
                          info.duplex,
                          info.orient,
                          info.paper,
                          info.bin,
                          info.xres_quality,
                          info.yres);

    if (ok) {
        return aset;
    } else {
        return null;
    }
}
 
Example #16
Source File: D3DScreenUpdateManager.java    From openjdk-jdk9 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) {
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    if (comp instanceof Container) {
        for (Component c : ((Container)comp).getComponents()) {
            if (acc.getPeer(c) instanceof WComponentPeer || hasHWChildren(c)) {
                return true;
            }
        }
    }
    return false;
}
 
Example #17
Source File: CPlatformWindow.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void orderAboveSiblingsImpl(Window[] windows) {
    ArrayList<Window> childWindows = new ArrayList<Window>();

    final ComponentAccessor componentAccessor = AWTAccessor.getComponentAccessor();
    final WindowAccessor windowAccessor = AWTAccessor.getWindowAccessor();

    // Go through the list of windows and perform ordering.
    for (Window w : windows) {
        boolean iconified = false;
        final Object p = componentAccessor.getPeer(w);
        if (p instanceof LWWindowPeer) {
            CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
            iconified = isIconified();
            if (pw != null && pw.isVisible() && !iconified) {
                // If the window is one of ancestors of 'main window' or is going to become main by itself,
                // the window should be ordered above its siblings; otherwise the window is just ordered
                // above its nearest parent.
                if (pw.isOneOfOwnersOrSelf(this)) {
                    CWrapper.NSWindow.orderFront(pw.getNSWindowPtr());
                } else {
                    CWrapper.NSWindow.orderWindow(pw.getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove,
                            pw.owner.getNSWindowPtr());
                }
                pw.applyWindowLevel(w);
            }
        }
        // Retrieve the child windows for each window from the list except iconified ones
        // and store them for future use.
        // Note: we collect data about child windows even for invisible owners, since they may have
        // visible children.
        if (!iconified) {
            childWindows.addAll(Arrays.asList(windowAccessor.getOwnedWindows(w)));
        }
    }
    // If some windows, which have just been ordered, have any child windows, let's start new iteration
    // and order these child windows.
    if (!childWindows.isEmpty()) {
        orderAboveSiblingsImpl(childWindows.toArray(new Window[0]));
    }
}
 
Example #18
Source File: CPlatformWindow.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override  // PlatformWindow
public void toFront() {
    LWCToolkit lwcToolkit = (LWCToolkit) Toolkit.getDefaultToolkit();
    Window w = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    if( w != null && acc.getPeer(w) != null
            && ((LWWindowPeer)acc.getPeer(w)).getPeerType() == LWWindowPeer.PeerType.EMBEDDED_FRAME
            && !lwcToolkit.isApplicationActive()) {
        lwcToolkit.activateApplicationIgnoringOtherApps();
    }
    updateFocusabilityForAutoRequestFocus(false);
    execute(CPlatformWindow::nativePushNSWindowToFront);
    updateFocusabilityForAutoRequestFocus(true);
}
 
Example #19
Source File: CPlatformWindow.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public CPlatformWindow convertJComponentToTarget(final JRootPane p) {
    Component root = SwingUtilities.getRoot(p);
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    if (root == null || acc.getPeer(root) == null) return null;
    return (CPlatformWindow)((LWWindowPeer)acc.getPeer(root)).getPlatformWindow();
}
 
Example #20
Source File: LWWindowPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private boolean isOneOfOwnersOf(LWWindowPeer peer) {
    Window owner = (peer != null ? peer.getTarget().getOwner() : null);
    while (owner != null) {
        final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
        if (acc.getPeer(owner) == this) {
            return true;
        }
        owner = owner.getOwner();
    }
    return false;
}
 
Example #21
Source File: LWWindowPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void repositionSecurityWarning() {
    if (warningWindow != null) {
        ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
        Window target = getTarget();
        int x = compAccessor.getX(target);
        int y = compAccessor.getY(target);
        int width = compAccessor.getWidth(target);
        int height = compAccessor.getHeight(target);
        warningWindow.reposition(x, y, width, height);
    }
}
 
Example #22
Source File: BasicSplitPaneUI.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Should be messaged before the dragging session starts, resets
 * lastDragLocation and dividerSize.
 */
protected void startDragging() {
    Component       leftC = splitPane.getLeftComponent();
    Component       rightC = splitPane.getRightComponent();
    ComponentPeer   cPeer;

    beginDragDividerLocation = getDividerLocation(splitPane);
    draggingHW = false;
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    if(leftC != null && (cPeer = acc.getPeer(leftC)) != null &&
       !(cPeer instanceof LightweightPeer)) {
        draggingHW = true;
    } else if(rightC != null && (cPeer = acc.getPeer(rightC)) != null
              && !(cPeer instanceof LightweightPeer)) {
        draggingHW = true;
    }
    if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
        setLastDragLocation(divider.getBounds().x);
        dividerSize = divider.getSize().width;
        if(!isContinuousLayout() && draggingHW) {
            nonContinuousLayoutDivider.setBounds
                    (getLastDragLocation(), 0, dividerSize,
                     splitPane.getHeight());
                  addHeavyweightDivider();
        }
    } else {
        setLastDragLocation(divider.getBounds().y);
        dividerSize = divider.getSize().height;
        if(!isContinuousLayout() && draggingHW) {
            nonContinuousLayoutDivider.setBounds
                    (0, getLastDragLocation(), splitPane.getWidth(),
                     dividerSize);
                  addHeavyweightDivider();
        }
    }
}
 
Example #23
Source File: AppletFlipBuffer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void test(final Applet applet) {
    ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    for (int i = 1; i < 10; ++i) {
        for (final BufferCapabilities caps : bcs) {
            try {
                acc.createBufferStrategy(applet, i, caps);
            } catch (final AWTException ignored) {
                // this kind of buffer strategy is not supported
            }
        }
    }
}
 
Example #24
Source File: BasicSplitPaneUI.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Should be messaged before the dragging session starts, resets
 * lastDragLocation and dividerSize.
 */
protected void startDragging() {
    Component       leftC = splitPane.getLeftComponent();
    Component       rightC = splitPane.getRightComponent();
    ComponentPeer   cPeer;

    beginDragDividerLocation = getDividerLocation(splitPane);
    draggingHW = false;
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    if(leftC != null && (cPeer = acc.getPeer(leftC)) != null &&
       !(cPeer instanceof LightweightPeer)) {
        draggingHW = true;
    } else if(rightC != null && (cPeer = acc.getPeer(rightC)) != null
              && !(cPeer instanceof LightweightPeer)) {
        draggingHW = true;
    }
    if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
        setLastDragLocation(divider.getBounds().x);
        dividerSize = divider.getSize().width;
        if(!isContinuousLayout() && draggingHW) {
            nonContinuousLayoutDivider.setBounds
                    (getLastDragLocation(), 0, dividerSize,
                     splitPane.getHeight());
                  addHeavyweightDivider();
        }
    } else {
        setLastDragLocation(divider.getBounds().y);
        dividerSize = divider.getSize().height;
        if(!isContinuousLayout() && draggingHW) {
            nonContinuousLayoutDivider.setBounds
                    (0, getLastDragLocation(), splitPane.getWidth(),
                     dividerSize);
                  addHeavyweightDivider();
        }
    }
}
 
Example #25
Source File: XWindow.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static long getParentWindowID(Component target) {

        Component temp = target.getParent();
        final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
        ComponentPeer peer = acc.getPeer(temp);
        while (!(peer instanceof XWindow))
        {
            temp = temp.getParent();
            peer = acc.getPeer(temp);
        }

        if (peer != null && peer instanceof XWindow)
            return ((XWindow)peer).getContentWindow();
        else return 0;
    }
 
Example #26
Source File: XComponentPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
XWindowPeer getParentTopLevel() {
    ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
    Container parent = (target instanceof Container) ? ((Container)target) : (compAccessor.getParent(target));
    // Search for parent window
    while (parent != null && !(parent instanceof Window)) {
        parent = compAccessor.getParent(parent);
    }
    if (parent != null) {
        return (XWindowPeer)compAccessor.getPeer(parent);
    } else {
        return null;
    }
}
 
Example #27
Source File: XComponentPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see java.awt.peer.ComponentPeer
 */
public void setEnabled(final boolean value) {
    if (enableLog.isLoggable(PlatformLogger.Level.FINE)) {
        enableLog.fine("{0}ing {1}", (value ? "Enabl" : "Disabl"), this);
    }
    boolean status = value;
    // If any of our heavyweight ancestors are disable, we should be too
    // See 6176875 for more information
    final Container cp = SunToolkit.getNativeContainer(target);
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    if (cp != null) {
        status &= acc.<XComponentPeer>getPeer(cp).isEnabled();
    }
    synchronized (getStateLock()) {
        if (enabled == status) {
            return;
        }
        enabled = status;
    }

    if (target instanceof Container) {
        final Component[] list = ((Container) target).getComponents();
        for (final Component child : list) {
            final ComponentPeer p = acc.getPeer(child);
            if (p != null) {
                p.setEnabled(status && child.isEnabled());
            }
        }
    }
    repaint();
}
 
Example #28
Source File: bug7129742.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame("Test");
            TextArea textArea = new TextArea("Non-editable textArea");
            textArea.setEditable(false);
            frame.setLayout(new FlowLayout());
            frame.add(textArea);
            frame.pack();
            frame.setVisible(true);

            try {
                ComponentAccessor acc = AWTAccessor.getComponentAccessor();
                Class XTextAreaPeerClzz = acc.getPeer(textArea).getClass();
                System.out.println(XTextAreaPeerClzz.getName());
                if (!XTextAreaPeerClzz.getName().equals("sun.awt.X11.XTextAreaPeer")) {
                    fastreturn = true;
                    return;
                }

                Field jtextField = XTextAreaPeerClzz.getDeclaredField("jtext");
                jtextField.setAccessible(true);
                JTextArea jtext = (JTextArea)jtextField.get(acc.getPeer(textArea));
                caret = (DefaultCaret) jtext.getCaret();

                textArea.requestFocusInWindow();
            } catch (NoSuchFieldException | SecurityException
                     | IllegalArgumentException | IllegalAccessException e) {
                /* These exceptions mean the implementation of XTextAreaPeer is
                 * changed, this testcase is not valid any more, fix it or remove.
                 */
                frame.dispose();
                throw new RuntimeException("This testcase is not valid any more!");
            }
        }
    });
    robot.waitForIdle();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            try{
                if (fastreturn) {
                    return;
                }
                boolean passed = caret.isActive();
                System.out.println("is caret visible : " + passed);

                if (!passed) {
                    throw new RuntimeException("The test for bug 71297422 failed");
                }
            } finally {
                frame.dispose();
            }
        }
    });
}
 
Example #29
Source File: CPlatformWindow.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void orderAboveSiblingsImpl(Window[] windows) {
    ArrayList<Window> childWindows = new ArrayList<Window>();

    final ComponentAccessor componentAccessor = AWTAccessor.getComponentAccessor();
    final WindowAccessor windowAccessor = AWTAccessor.getWindowAccessor();

    // Go through the list of windows and perform ordering.
    for (Window w : windows) {
        boolean iconified = false;
        final Object p = componentAccessor.getPeer(w);
        if (p instanceof LWWindowPeer) {
            CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
            iconified = isIconified();
            if (pw != null && pw.isVisible() && !iconified) {
                // If the window is one of ancestors of 'main window' or is going to become main by itself,
                // the window should be ordered above its siblings; otherwise the window is just ordered
                // above its nearest parent.
                if (pw.isOneOfOwnersOrSelf(this)) {
                    pw.execute(CWrapper.NSWindow::orderFront);
                } else {
                    pw.owner.execute(ownerPtr -> {
                        pw.execute(ptr -> {
                            CWrapper.NSWindow.orderWindow(ptr, CWrapper.NSWindow.NSWindowAbove, ownerPtr);
                        });
                    });
                }
                pw.applyWindowLevel(w);
            }
        }
        // Retrieve the child windows for each window from the list except iconified ones
        // and store them for future use.
        // Note: we collect data about child windows even for invisible owners, since they may have
        // visible children.
        if (!iconified) {
            childWindows.addAll(Arrays.asList(windowAccessor.getOwnedWindows(w)));
        }
    }
    // If some windows, which have just been ordered, have any child windows, let's start new iteration
    // and order these child windows.
    if (!childWindows.isEmpty()) {
        orderAboveSiblingsImpl(childWindows.toArray(new Window[0]));
    }
}
 
Example #30
Source File: WScrollPanePeer.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run() {
    if (getScrollChild() == null) {
        return;
    }
    ScrollPane sp = (ScrollPane)WScrollPanePeer.this.target;
    ScrollPaneAdjustable adj = null;

    // ScrollPaneAdjustable made public in 1.4, but
    // get[HV]Adjustable can't be declared to return
    // ScrollPaneAdjustable because it would break backward
    // compatibility -- hence the cast

    if (orient == Adjustable.VERTICAL) {
        adj = (ScrollPaneAdjustable)sp.getVAdjustable();
    } else if (orient == Adjustable.HORIZONTAL) {
        adj = (ScrollPaneAdjustable)sp.getHAdjustable();
    } else {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("Assertion failed: unknown orient");
        }
    }

    if (adj == null) {
        return;
    }

    int newpos = adj.getValue();
    switch (type) {
      case AdjustmentEvent.UNIT_DECREMENT:
          newpos -= adj.getUnitIncrement();
          break;
      case AdjustmentEvent.UNIT_INCREMENT:
          newpos += adj.getUnitIncrement();
          break;
      case AdjustmentEvent.BLOCK_DECREMENT:
          newpos -= adj.getBlockIncrement();
          break;
      case AdjustmentEvent.BLOCK_INCREMENT:
          newpos += adj.getBlockIncrement();
          break;
      case AdjustmentEvent.TRACK:
          newpos = this.pos;
          break;
      default:
          if (log.isLoggable(PlatformLogger.Level.FINE)) {
              log.fine("Assertion failed: unknown type");
          }
          return;
    }

    // keep scroll position in acceptable range
    newpos = Math.max(adj.getMinimum(), newpos);
    newpos = Math.min(adj.getMaximum(), newpos);

    // set value, this will synchronously fire an AdjustmentEvent
    adj.setValueIsAdjusting(isAdjusting);

    // Fix for 4075484 - consider type information when creating AdjustmentEvent
    // We can't just call adj.setValue() because it creates AdjustmentEvent with type=TRACK
    // Instead, we call private method setTypedValue of ScrollPaneAdjustable.
    AWTAccessor.getScrollPaneAdjustableAccessor().setTypedValue(adj,
                                                                newpos,
                                                                type);

    // Paint the exposed area right away.  To do this - find
    // the heavyweight ancestor of the scroll child.
    Component hwAncestor = getScrollChild();
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    while (hwAncestor != null
           && !(acc.getPeer(hwAncestor) instanceof WComponentPeer))
    {
        hwAncestor = hwAncestor.getParent();
    }
    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        if (hwAncestor == null) {
            log.fine("Assertion (hwAncestor != null) failed, " +
                     "couldn't find heavyweight ancestor of scroll pane child");
        }
    }
    WComponentPeer hwPeer = acc.getPeer(hwAncestor);
    hwPeer.paintDamagedAreaImmediately();
}