Java Code Examples for sun.awt.SunToolkit#isInstanceOf()

The following examples show how to use sun.awt.SunToolkit#isInstanceOf() . 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: JLayeredPane.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void validateOptimizedDrawing() {
    boolean layeredComponentFound = false;
    synchronized(getTreeLock()) {
        Integer layer;

        for (Component c : getComponents()) {
            layer = null;

            if(SunToolkit.isInstanceOf(c, "javax.swing.JInternalFrame") ||
                   (c instanceof JComponent &&
                    (layer = (Integer)((JComponent)c).
                                 getClientProperty(LAYER_PROPERTY)) != null))
            {
                if(layer != null && layer.equals(FRAME_CONTENT_LAYER))
                    continue;
                layeredComponentFound = true;
                break;
            }
        }
    }

    if(layeredComponentFound)
        optimizedDrawingPossible = false;
    else
        optimizedDrawingPossible = true;
}
 
Example 2
Source File: JLayeredPane.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void validateOptimizedDrawing() {
    boolean layeredComponentFound = false;
    synchronized(getTreeLock()) {
        Integer layer;

        for (Component c : getComponents()) {
            layer = null;

            if(SunToolkit.isInstanceOf(c, "javax.swing.JInternalFrame") ||
                   (c instanceof JComponent &&
                    (layer = (Integer)((JComponent)c).
                                 getClientProperty(LAYER_PROPERTY)) != null))
            {
                if(layer != null && layer.equals(FRAME_CONTENT_LAYER))
                    continue;
                layeredComponentFound = true;
                break;
            }
        }
    }

    if(layeredComponentFound)
        optimizedDrawingPossible = false;
    else
        optimizedDrawingPossible = true;
}
 
Example 3
Source File: Window.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void setLayersOpaque(Component component, boolean isOpaque) {
    // Shouldn't use instanceof to avoid loading Swing classes
    //    if it's a pure AWT application.
    if (SunToolkit.isInstanceOf(component, "javax.swing.RootPaneContainer")) {
        javax.swing.RootPaneContainer rpc = (javax.swing.RootPaneContainer)component;
        javax.swing.JRootPane root = rpc.getRootPane();
        javax.swing.JLayeredPane lp = root.getLayeredPane();
        Container c = root.getContentPane();
        javax.swing.JComponent content =
            (c instanceof javax.swing.JComponent) ? (javax.swing.JComponent)c : null;
        lp.setOpaque(isOpaque);
        root.setOpaque(isOpaque);
        if (content != null) {
            content.setOpaque(isOpaque);

            // Iterate down one level to see whether we have a JApplet
            // (which is also a RootPaneContainer) which requires processing
            int numChildren = content.getComponentCount();
            if (numChildren > 0) {
                Component child = content.getComponent(0);
                // It's OK to use instanceof here because we've
                // already loaded the RootPaneContainer class by now
                if (child instanceof javax.swing.RootPaneContainer) {
                    setLayersOpaque(child, isOpaque);
                }
            }
        }
    }
}
 
Example 4
Source File: Window.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void setLayersOpaque(Component component, boolean isOpaque) {
    // Shouldn't use instanceof to avoid loading Swing classes
    //    if it's a pure AWT application.
    if (SunToolkit.isInstanceOf(component, "javax.swing.RootPaneContainer")) {
        javax.swing.RootPaneContainer rpc = (javax.swing.RootPaneContainer)component;
        javax.swing.JRootPane root = rpc.getRootPane();
        javax.swing.JLayeredPane lp = root.getLayeredPane();
        Container c = root.getContentPane();
        javax.swing.JComponent content =
            (c instanceof javax.swing.JComponent) ? (javax.swing.JComponent)c : null;
        lp.setOpaque(isOpaque);
        root.setOpaque(isOpaque);
        if (content != null) {
            content.setOpaque(isOpaque);

            // Iterate down one level to see whether we have a JApplet
            // (which is also a RootPaneContainer) which requires processing
            int numChildren = content.getComponentCount();
            if (numChildren > 0) {
                Component child = content.getComponent(0);
                // It's OK to use instanceof here because we've
                // already loaded the RootPaneContainer class by now
                if (child instanceof javax.swing.RootPaneContainer) {
                    setLayersOpaque(child, isOpaque);
                }
            }
        }
    }
}
 
Example 5
Source File: Window.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void setLayersOpaque(Component component, boolean isOpaque) {
    // Shouldn't use instanceof to avoid loading Swing classes
    //    if it's a pure AWT application.
    if (SunToolkit.isInstanceOf(component, "javax.swing.RootPaneContainer")) {
        javax.swing.RootPaneContainer rpc = (javax.swing.RootPaneContainer)component;
        javax.swing.JRootPane root = rpc.getRootPane();
        javax.swing.JLayeredPane lp = root.getLayeredPane();
        Container c = root.getContentPane();
        javax.swing.JComponent content =
            (c instanceof javax.swing.JComponent) ? (javax.swing.JComponent)c : null;
        lp.setOpaque(isOpaque);
        root.setOpaque(isOpaque);
        if (content != null) {
            content.setOpaque(isOpaque);

            // Iterate down one level to see whether we have a JApplet
            // (which is also a RootPaneContainer) which requires processing
            int numChildren = content.getComponentCount();
            if (numChildren > 0) {
                Component child = content.getComponent(0);
                // It's OK to use instanceof here because we've
                // already loaded the RootPaneContainer class by now
                if (child instanceof javax.swing.RootPaneContainer) {
                    setLayersOpaque(child, isOpaque);
                }
            }
        }
    }
}
 
Example 6
Source File: Window.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void setLayersOpaque(Component component, boolean isOpaque) {
    // Shouldn't use instanceof to avoid loading Swing classes
    //    if it's a pure AWT application.
    if (SunToolkit.isInstanceOf(component, "javax.swing.RootPaneContainer")) {
        javax.swing.RootPaneContainer rpc = (javax.swing.RootPaneContainer)component;
        javax.swing.JRootPane root = rpc.getRootPane();
        javax.swing.JLayeredPane lp = root.getLayeredPane();
        Container c = root.getContentPane();
        javax.swing.JComponent content =
            (c instanceof javax.swing.JComponent) ? (javax.swing.JComponent)c : null;
        lp.setOpaque(isOpaque);
        root.setOpaque(isOpaque);
        if (content != null) {
            content.setOpaque(isOpaque);

            // Iterate down one level to see whether we have a JApplet
            // (which is also a RootPaneContainer) which requires processing
            int numChildren = content.getComponentCount();
            if (numChildren > 0) {
                Component child = content.getComponent(0);
                // It's OK to use instanceof here because we've
                // already loaded the RootPaneContainer class by now
                if (child instanceof javax.swing.RootPaneContainer) {
                    setLayersOpaque(child, isOpaque);
                }
            }
        }
    }
}
 
Example 7
Source File: TransferHandler.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void setComponentDropLocation(TransferSupport support,
                                      boolean forDrop) {

    DropLocation dropLocation = (support == null)
                                ? null
                                : support.getDropLocation();

    if (SunToolkit.isInstanceOf(component, "javax.swing.text.JTextComponent")) {
        state = SwingAccessor.getJTextComponentAccessor().
                    setDropLocation((JTextComponent)component, dropLocation, state, forDrop);
    } else if (component instanceof JComponent) {
        state = ((JComponent)component).setDropLocation(dropLocation, state, forDrop);
    }
}
 
Example 8
Source File: TransferHandler.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private void setComponentDropLocation(TransferSupport support,
                                      boolean forDrop) {

    DropLocation dropLocation = (support == null)
                                ? null
                                : support.getDropLocation();

    if (SunToolkit.isInstanceOf(component, "javax.swing.text.JTextComponent")) {
        state = SwingAccessor.getJTextComponentAccessor().
                    setDropLocation((JTextComponent)component, dropLocation, state, forDrop);
    } else if (component instanceof JComponent) {
        state = ((JComponent)component).setDropLocation(dropLocation, state, forDrop);
    }
}
 
Example 9
Source File: TransferHandler.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private void setComponentDropLocation(TransferSupport support,
                                      boolean forDrop) {

    DropLocation dropLocation = (support == null)
                                ? null
                                : support.getDropLocation();

    if (SunToolkit.isInstanceOf(component, "javax.swing.text.JTextComponent")) {
        state = SwingAccessor.getJTextComponentAccessor().
                    setDropLocation((JTextComponent)component, dropLocation, state, forDrop);
    } else if (component instanceof JComponent) {
        state = ((JComponent)component).setDropLocation(dropLocation, state, forDrop);
    }
}
 
Example 10
Source File: Window.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void setLayersOpaque(Component component, boolean isOpaque) {
    // Shouldn't use instanceof to avoid loading Swing classes
    //    if it's a pure AWT application.
    if (SunToolkit.isInstanceOf(component, "javax.swing.RootPaneContainer")) {
        javax.swing.RootPaneContainer rpc = (javax.swing.RootPaneContainer)component;
        javax.swing.JRootPane root = rpc.getRootPane();
        javax.swing.JLayeredPane lp = root.getLayeredPane();
        Container c = root.getContentPane();
        javax.swing.JComponent content =
            (c instanceof javax.swing.JComponent) ? (javax.swing.JComponent)c : null;
        lp.setOpaque(isOpaque);
        root.setOpaque(isOpaque);
        if (content != null) {
            content.setOpaque(isOpaque);

            // Iterate down one level to see whether we have a JApplet
            // (which is also a RootPaneContainer) which requires processing
            int numChildren = content.getComponentCount();
            if (numChildren > 0) {
                Component child = content.getComponent(0);
                // It's OK to use instanceof here because we've
                // already loaded the RootPaneContainer class by now
                if (child instanceof javax.swing.RootPaneContainer) {
                    setLayersOpaque(child, isOpaque);
                }
            }
        }
    }
}
 
Example 11
Source File: TransferHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void setComponentDropLocation(TransferSupport support,
                                      boolean forDrop) {

    DropLocation dropLocation = (support == null)
                                ? null
                                : support.getDropLocation();

    if (SunToolkit.isInstanceOf(component, "javax.swing.text.JTextComponent")) {
        state = SwingAccessor.getJTextComponentAccessor().
                    setDropLocation((JTextComponent)component, dropLocation, state, forDrop);
    } else if (component instanceof JComponent) {
        state = ((JComponent)component).setDropLocation(dropLocation, state, forDrop);
    }
}
 
Example 12
Source File: Window.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void setLayersOpaque(Component component, boolean isOpaque) {
    // Shouldn't use instanceof to avoid loading Swing classes
    //    if it's a pure AWT application.
    if (SunToolkit.isInstanceOf(component, "javax.swing.RootPaneContainer")) {
        javax.swing.RootPaneContainer rpc = (javax.swing.RootPaneContainer)component;
        javax.swing.JRootPane root = rpc.getRootPane();
        javax.swing.JLayeredPane lp = root.getLayeredPane();
        Container c = root.getContentPane();
        javax.swing.JComponent content =
            (c instanceof javax.swing.JComponent) ? (javax.swing.JComponent)c : null;
        lp.setOpaque(isOpaque);
        root.setOpaque(isOpaque);
        if (content != null) {
            content.setOpaque(isOpaque);

            // Iterate down one level to see whether we have a JApplet
            // (which is also a RootPaneContainer) which requires processing
            int numChildren = content.getComponentCount();
            if (numChildren > 0) {
                Component child = content.getComponent(0);
                // It's OK to use instanceof here because we've
                // already loaded the RootPaneContainer class by now
                if (child instanceof javax.swing.RootPaneContainer) {
                    setLayersOpaque(child, isOpaque);
                }
            }
        }
    }
}
 
Example 13
Source File: BufferStrategyPaintManager.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private Container fetchRoot(JComponent c) {
    boolean encounteredHW = false;
    rootJ = c;
    Container root = c;
    xOffset = yOffset = 0;
    while (root != null &&
           (!(root instanceof Window) &&
            !SunToolkit.isInstanceOf(root, "java.applet.Applet"))) {
        xOffset += root.getX();
        yOffset += root.getY();
        root = root.getParent();
        if (root != null) {
            if (root instanceof JComponent) {
                rootJ = (JComponent)root;
            }
            else if (!root.isLightweight()) {
                if (!encounteredHW) {
                    encounteredHW = true;
                }
                else {
                    // We've encountered two hws now and may have
                    // a containment hierarchy with lightweights containing
                    // heavyweights containing other lightweights.
                    // Heavyweights poke holes in lightweight
                    // rendering so that if we call show on the BS
                    // (which is associated with the Window) you will
                    // not see the contents over any child
                    // heavyweights.  If we didn't do this when we
                    // went to show the descendants of the nested hw
                    // you would see nothing, so, we bail out here.
                    return null;
                }
            }
        }
    }
    if ((root instanceof RootPaneContainer) &&
        (rootJ instanceof JRootPane)) {
        // We're in a Swing heavyeight (JFrame/JWindow...), use double
        // buffering if double buffering enabled on the JRootPane and
        // the JRootPane wants true double buffering.
        if (rootJ.isDoubleBuffered() &&
                ((JRootPane)rootJ).getUseTrueDoubleBuffering()) {
            // Whether or not a component is double buffered is a
            // bit tricky with Swing. This gives a good approximation
            // of the various ways to turn on double buffering for
            // components.
            return root;
        }
    }
    // Don't do true double buffering.
    return null;
}
 
Example 14
Source File: LayoutFocusTraversalPolicy.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Determines whether the specified <code>Component</code>
 * is an acceptable choice as the new focus owner.
 * This method performs the following sequence of operations:
 * <ol>
 * <li>Checks whether <code>aComponent</code> is visible, displayable,
 *     enabled, and focusable.  If any of these properties is
 *     <code>false</code>, this method returns <code>false</code>.
 * <li>If <code>aComponent</code> is an instance of <code>JTable</code>,
 *     returns <code>true</code>.
 * <li>If <code>aComponent</code> is an instance of <code>JComboBox</code>,
 *     then returns the value of
 *     <code>aComponent.getUI().isFocusTraversable(aComponent)</code>.
 * <li>If <code>aComponent</code> is a <code>JComponent</code>
 *     with a <code>JComponent.WHEN_FOCUSED</code>
 *     <code>InputMap</code> that is neither <code>null</code>
 *     nor empty, returns <code>true</code>.
 * <li>Returns the value of
 *     <code>DefaultFocusTraversalPolicy.accept(aComponent)</code>.
 * </ol>
 *
 * @param aComponent the <code>Component</code> whose fitness
 *                   as a focus owner is to be tested
 * @see java.awt.Component#isVisible
 * @see java.awt.Component#isDisplayable
 * @see java.awt.Component#isEnabled
 * @see java.awt.Component#isFocusable
 * @see javax.swing.plaf.ComboBoxUI#isFocusTraversable
 * @see javax.swing.JComponent#getInputMap
 * @see java.awt.DefaultFocusTraversalPolicy#accept
 * @return <code>true</code> if <code>aComponent</code> is a valid choice
 *         for a focus owner;
 *         otherwise <code>false</code>
 */
 protected boolean accept(Component aComponent) {
    if (!super.accept(aComponent)) {
        return false;
    } else if (SunToolkit.isInstanceOf(aComponent, "javax.swing.JTable")) {
        // JTable only has ancestor focus bindings, we thus force it
        // to be focusable by returning true here.
        return true;
    } else if (SunToolkit.isInstanceOf(aComponent, "javax.swing.JComboBox")) {
        JComboBox<?> box = (JComboBox)aComponent;
        return box.getUI().isFocusTraversable(box);
    } else if (aComponent instanceof JComponent) {
        if (SunToolkit.isInstanceOf(aComponent,
                                             "javax.swing.JToggleButton")) {
            ButtonModel model = ((JToggleButton)aComponent).getModel();
            if (model != null) {
                ButtonGroup group = model.getGroup();
                if (group != null) {
                    Enumeration<AbstractButton> elements =
                                                    group.getElements();
                    int idx = 0;
                    while (elements.hasMoreElements()) {
                        AbstractButton member = elements.nextElement();
                        if (member instanceof JToggleButton &&
                             member.isVisible() && member.isDisplayable() &&
                             member.isEnabled() && member.isFocusable()) {
                            if (member == aComponent) {
                                return idx == 0;
                            }
                            idx++;
                        }
                    }
                }
            }
        }

        JComponent jComponent = (JComponent)aComponent;
        InputMap inputMap = jComponent.getInputMap(JComponent.WHEN_FOCUSED,
                                                   false);
        while (inputMap != null && inputMap.size() == 0) {
            inputMap = inputMap.getParent();
        }
        if (inputMap != null) {
            return true;
        }
        // Delegate to the fitnessTestPolicy, this will test for the
        // case where the developer has overriden isFocusTraversable to
        // return true.
    }
    return fitnessTestPolicy.accept(aComponent);
}
 
Example 15
Source File: BufferStrategyPaintManager.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private Container fetchRoot(JComponent c) {
    boolean encounteredHW = false;
    rootJ = c;
    Container root = c;
    xOffset = yOffset = 0;
    while (root != null &&
           (!(root instanceof Window) &&
            !SunToolkit.isInstanceOf(root, "java.applet.Applet"))) {
        xOffset += root.getX();
        yOffset += root.getY();
        root = root.getParent();
        if (root != null) {
            if (root instanceof JComponent) {
                rootJ = (JComponent)root;
            }
            else if (!root.isLightweight()) {
                if (!encounteredHW) {
                    encounteredHW = true;
                }
                else {
                    // We've encountered two hws now and may have
                    // a containment hierarchy with lightweights containing
                    // heavyweights containing other lightweights.
                    // Heavyweights poke holes in lightweight
                    // rendering so that if we call show on the BS
                    // (which is associated with the Window) you will
                    // not see the contents over any child
                    // heavyweights.  If we didn't do this when we
                    // went to show the descendants of the nested hw
                    // you would see nothing, so, we bail out here.
                    return null;
                }
            }
        }
    }
    if ((root instanceof RootPaneContainer) &&
        (rootJ instanceof JRootPane)) {
        // We're in a Swing heavyeight (JFrame/JWindow...), use double
        // buffering if double buffering enabled on the JRootPane and
        // the JRootPane wants true double buffering.
        if (rootJ.isDoubleBuffered() &&
                ((JRootPane)rootJ).getUseTrueDoubleBuffering()) {
            // Whether or not a component is double buffered is a
            // bit tricky with Swing. This gives a good approximation
            // of the various ways to turn on double buffering for
            // components.
            return root;
        }
    }
    // Don't do true double buffering.
    return null;
}
 
Example 16
Source File: LayoutFocusTraversalPolicy.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Determines whether the specified <code>Component</code>
 * is an acceptable choice as the new focus owner.
 * This method performs the following sequence of operations:
 * <ol>
 * <li>Checks whether <code>aComponent</code> is visible, displayable,
 *     enabled, and focusable.  If any of these properties is
 *     <code>false</code>, this method returns <code>false</code>.
 * <li>If <code>aComponent</code> is an instance of <code>JTable</code>,
 *     returns <code>true</code>.
 * <li>If <code>aComponent</code> is an instance of <code>JComboBox</code>,
 *     then returns the value of
 *     <code>aComponent.getUI().isFocusTraversable(aComponent)</code>.
 * <li>If <code>aComponent</code> is a <code>JComponent</code>
 *     with a <code>JComponent.WHEN_FOCUSED</code>
 *     <code>InputMap</code> that is neither <code>null</code>
 *     nor empty, returns <code>true</code>.
 * <li>Returns the value of
 *     <code>DefaultFocusTraversalPolicy.accept(aComponent)</code>.
 * </ol>
 *
 * @param aComponent the <code>Component</code> whose fitness
 *                   as a focus owner is to be tested
 * @see java.awt.Component#isVisible
 * @see java.awt.Component#isDisplayable
 * @see java.awt.Component#isEnabled
 * @see java.awt.Component#isFocusable
 * @see javax.swing.plaf.ComboBoxUI#isFocusTraversable
 * @see javax.swing.JComponent#getInputMap
 * @see java.awt.DefaultFocusTraversalPolicy#accept
 * @return <code>true</code> if <code>aComponent</code> is a valid choice
 *         for a focus owner;
 *         otherwise <code>false</code>
 */
 protected boolean accept(Component aComponent) {
    if (!super.accept(aComponent)) {
        return false;
    } else if (SunToolkit.isInstanceOf(aComponent, "javax.swing.JTable")) {
        // JTable only has ancestor focus bindings, we thus force it
        // to be focusable by returning true here.
        return true;
    } else if (SunToolkit.isInstanceOf(aComponent, "javax.swing.JComboBox")) {
        JComboBox box = (JComboBox)aComponent;
        return box.getUI().isFocusTraversable(box);
    } else if (aComponent instanceof JComponent) {
        JComponent jComponent = (JComponent)aComponent;
        InputMap inputMap = jComponent.getInputMap(JComponent.WHEN_FOCUSED,
                                                   false);
        while (inputMap != null && inputMap.size() == 0) {
            inputMap = inputMap.getParent();
        }
        if (inputMap != null) {
            return true;
        }
        // Delegate to the fitnessTestPolicy, this will test for the
        // case where the developer has overriden isFocusTraversable to
        // return true.
    }
    return fitnessTestPolicy.accept(aComponent);
}
 
Example 17
Source File: LayoutFocusTraversalPolicy.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Determines whether the specified <code>Component</code>
 * is an acceptable choice as the new focus owner.
 * This method performs the following sequence of operations:
 * <ol>
 * <li>Checks whether <code>aComponent</code> is visible, displayable,
 *     enabled, and focusable.  If any of these properties is
 *     <code>false</code>, this method returns <code>false</code>.
 * <li>If <code>aComponent</code> is an instance of <code>JTable</code>,
 *     returns <code>true</code>.
 * <li>If <code>aComponent</code> is an instance of <code>JComboBox</code>,
 *     then returns the value of
 *     <code>aComponent.getUI().isFocusTraversable(aComponent)</code>.
 * <li>If <code>aComponent</code> is a <code>JComponent</code>
 *     with a <code>JComponent.WHEN_FOCUSED</code>
 *     <code>InputMap</code> that is neither <code>null</code>
 *     nor empty, returns <code>true</code>.
 * <li>Returns the value of
 *     <code>DefaultFocusTraversalPolicy.accept(aComponent)</code>.
 * </ol>
 *
 * @param aComponent the <code>Component</code> whose fitness
 *                   as a focus owner is to be tested
 * @see java.awt.Component#isVisible
 * @see java.awt.Component#isDisplayable
 * @see java.awt.Component#isEnabled
 * @see java.awt.Component#isFocusable
 * @see javax.swing.plaf.ComboBoxUI#isFocusTraversable
 * @see javax.swing.JComponent#getInputMap
 * @see java.awt.DefaultFocusTraversalPolicy#accept
 * @return <code>true</code> if <code>aComponent</code> is a valid choice
 *         for a focus owner;
 *         otherwise <code>false</code>
 */
 protected boolean accept(Component aComponent) {
    if (!super.accept(aComponent)) {
        return false;
    } else if (SunToolkit.isInstanceOf(aComponent, "javax.swing.JTable")) {
        // JTable only has ancestor focus bindings, we thus force it
        // to be focusable by returning true here.
        return true;
    } else if (SunToolkit.isInstanceOf(aComponent, "javax.swing.JComboBox")) {
        JComboBox box = (JComboBox)aComponent;
        return box.getUI().isFocusTraversable(box);
    } else if (aComponent instanceof JComponent) {
        JComponent jComponent = (JComponent)aComponent;
        InputMap inputMap = jComponent.getInputMap(JComponent.WHEN_FOCUSED,
                                                   false);
        while (inputMap != null && inputMap.size() == 0) {
            inputMap = inputMap.getParent();
        }
        if (inputMap != null) {
            return true;
        }
        // Delegate to the fitnessTestPolicy, this will test for the
        // case where the developer has overriden isFocusTraversable to
        // return true.
    }
    return fitnessTestPolicy.accept(aComponent);
}
 
Example 18
Source File: LookAndFeel.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Convenience method for installing a property with the specified name
 * and value on a component if that property has not already been set
 * by the developer.  This method is intended to be used by
 * ui delegate instances that need to specify a default value for a
 * property of primitive type (boolean, int, ..), but do not wish
 * to override a value set by the client.  Since primitive property
 * values cannot be wrapped with the {@code UIResource} marker, this method
 * uses private state to determine whether the property has been set
 * by the client.
 *
 * @throws IllegalArgumentException if the specified property is not
 *         one which can be set using this method
 * @throws ClassCastException if the property value has not been set
 *         by the developer and the type does not match the property's type
 * @throws NullPointerException if {@code c} is {@code null}, or the
 *         named property has not been set by the developer and
 *         {@code propertyValue} is {@code null}
 * @param c target component to set the property on
 * @param propertyName name of the property to set
 * @param propertyValue value of the property
 * @since 1.5
 */
public static void installProperty(JComponent c,
                                   String propertyName, Object propertyValue) {
    // this is a special case because the JPasswordField's ancestor hierarchy
    // includes a class outside of javax.swing, thus we cannot call setUIProperty
    // directly.
    if (SunToolkit.isInstanceOf(c, "javax.swing.JPasswordField")) {
        if (!((JPasswordField)c).customSetUIProperty(propertyName, propertyValue)) {
            c.setUIProperty(propertyName, propertyValue);
        }
    } else {
        c.setUIProperty(propertyName, propertyValue);
    }
}
 
Example 19
Source File: LookAndFeel.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Convenience method for installing a property with the specified name
 * and value on a component if that property has not already been set
 * by the developer.  This method is intended to be used by
 * ui delegate instances that need to specify a default value for a
 * property of primitive type (boolean, int, ..), but do not wish
 * to override a value set by the client.  Since primitive property
 * values cannot be wrapped with the {@code UIResource} marker, this method
 * uses private state to determine whether the property has been set
 * by the client.
 *
 * @throws IllegalArgumentException if the specified property is not
 *         one which can be set using this method
 * @throws ClassCastException if the property value has not been set
 *         by the developer and the type does not match the property's type
 * @throws NullPointerException if {@code c} is {@code null}, or the
 *         named property has not been set by the developer and
 *         {@code propertyValue} is {@code null}
 * @param c target component to set the property on
 * @param propertyName name of the property to set
 * @param propertyValue value of the property
 * @since 1.5
 */
public static void installProperty(JComponent c,
                                   String propertyName, Object propertyValue) {
    // this is a special case because the JPasswordField's ancestor hierarchy
    // includes a class outside of javax.swing, thus we cannot call setUIProperty
    // directly.
    if (SunToolkit.isInstanceOf(c, "javax.swing.JPasswordField")) {
        if (!((JPasswordField)c).customSetUIProperty(propertyName, propertyValue)) {
            c.setUIProperty(propertyName, propertyValue);
        }
    } else {
        c.setUIProperty(propertyName, propertyValue);
    }
}
 
Example 20
Source File: LayoutFocusTraversalPolicy.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Determines whether the specified <code>Component</code>
 * is an acceptable choice as the new focus owner.
 * This method performs the following sequence of operations:
 * <ol>
 * <li>Checks whether <code>aComponent</code> is visible, displayable,
 *     enabled, and focusable.  If any of these properties is
 *     <code>false</code>, this method returns <code>false</code>.
 * <li>If <code>aComponent</code> is an instance of <code>JTable</code>,
 *     returns <code>true</code>.
 * <li>If <code>aComponent</code> is an instance of <code>JComboBox</code>,
 *     then returns the value of
 *     <code>aComponent.getUI().isFocusTraversable(aComponent)</code>.
 * <li>If <code>aComponent</code> is a <code>JComponent</code>
 *     with a <code>JComponent.WHEN_FOCUSED</code>
 *     <code>InputMap</code> that is neither <code>null</code>
 *     nor empty, returns <code>true</code>.
 * <li>Returns the value of
 *     <code>DefaultFocusTraversalPolicy.accept(aComponent)</code>.
 * </ol>
 *
 * @param aComponent the <code>Component</code> whose fitness
 *                   as a focus owner is to be tested
 * @see java.awt.Component#isVisible
 * @see java.awt.Component#isDisplayable
 * @see java.awt.Component#isEnabled
 * @see java.awt.Component#isFocusable
 * @see javax.swing.plaf.ComboBoxUI#isFocusTraversable
 * @see javax.swing.JComponent#getInputMap
 * @see java.awt.DefaultFocusTraversalPolicy#accept
 * @return <code>true</code> if <code>aComponent</code> is a valid choice
 *         for a focus owner;
 *         otherwise <code>false</code>
 */
 protected boolean accept(Component aComponent) {
    if (!super.accept(aComponent)) {
        return false;
    } else if (SunToolkit.isInstanceOf(aComponent, "javax.swing.JTable")) {
        // JTable only has ancestor focus bindings, we thus force it
        // to be focusable by returning true here.
        return true;
    } else if (SunToolkit.isInstanceOf(aComponent, "javax.swing.JComboBox")) {
        JComboBox box = (JComboBox)aComponent;
        return box.getUI().isFocusTraversable(box);
    } else if (aComponent instanceof JComponent) {
        JComponent jComponent = (JComponent)aComponent;
        InputMap inputMap = jComponent.getInputMap(JComponent.WHEN_FOCUSED,
                                                   false);
        while (inputMap != null && inputMap.size() == 0) {
            inputMap = inputMap.getParent();
        }
        if (inputMap != null) {
            return true;
        }
        // Delegate to the fitnessTestPolicy, this will test for the
        // case where the developer has overriden isFocusTraversable to
        // return true.
    }
    return fitnessTestPolicy.accept(aComponent);
}