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

The following examples show how to use java.awt.Component#isEnabled() . 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: MetalBorders.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    AbstractButton button = (AbstractButton)c;
    ButtonModel model = button.getModel();
    if (MetalLookAndFeel.usingOcean()) {
        if(model.isArmed() || !button.isEnabled()) {
            super.paintBorder(c, g, x, y, w, h);
        }
        else {
         g.setColor(MetalLookAndFeel.getControlDarkShadow());
         g.drawRect(0, 0, w - 1, h - 1);
    }
    return;
}
    if (! c.isEnabled() ) {
        MetalUtils.drawDisabledBorder( g, x, y, w-1, h-1 );
    } else {
        if ( model.isPressed() && model.isArmed() ) {
           MetalUtils.drawPressed3DBorder( g, x, y, w, h );
        } else if ( model.isSelected() ) {
            MetalUtils.drawDark3DBorder( g, x, y, w, h );
        } else {
            MetalUtils.drawFlush3DBorder( g, x, y, w, h );
        }
    }
}
 
Example 2
Source File: BasicLabelUI.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void doPress(JLabel label) {
    Component labelFor = label.getLabelFor();
    if (labelFor != null && labelFor.isEnabled()) {
        InputMap inputMap = SwingUtilities.getUIInputMap(label, JComponent.WHEN_FOCUSED);
        if (inputMap == null) {
            inputMap = new InputMapUIResource();
            SwingUtilities.replaceUIInputMap(label, JComponent.WHEN_FOCUSED, inputMap);
        }
        int dka = label.getDisplayedMnemonic();
        putOnRelease(inputMap, dka, BasicLookAndFeel
                .getFocusAcceleratorKeyMask());
        // Need this when the sticky keys are enabled
        putOnRelease(inputMap, dka, 0);
        // Need this if ALT is released before the accelerator
        putOnRelease(inputMap, KeyEvent.VK_ALT, 0);
        label.requestFocus();
    }
}
 
Example 3
Source File: LegacyGlueFocusTraversalPolicy.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 4
Source File: LegacyGlueFocusTraversalPolicy.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 5
Source File: MetalBorders.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y,
                        int w, int h) {

  if (!(c instanceof JTextComponent)) {
        // special case for non-text components (bug ID 4144840)
        if (c.isEnabled()) {
            MetalUtils.drawFlush3DBorder(g, x, y, w, h);
        } else {
            MetalUtils.drawDisabledBorder(g, x, y, w, h);
        }
        return;
    }

    if (c.isEnabled() && ((JTextComponent)c).isEditable()) {
        MetalUtils.drawFlush3DBorder(g, x, y, w, h);
    } else {
        MetalUtils.drawDisabledBorder(g, x, y, w, h);
    }

}
 
Example 6
Source File: BasicLabelUI.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void doRelease(JLabel label) {
    Component labelFor = label.getLabelFor();
    if (labelFor != null && labelFor.isEnabled()) {
        InputMap inputMap = SwingUtilities.getUIInputMap(label, JComponent.WHEN_FOCUSED);
        if (inputMap != null) {
            // inputMap should never be null.
            int dka = label.getDisplayedMnemonic();
            inputMap.remove(KeyStroke.getKeyStroke(dka, BasicLookAndFeel.getFocusAcceleratorKeyMask(), true));
            inputMap.remove(KeyStroke.getKeyStroke(dka, 0, true));
            inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ALT, 0, true));
        }
        if (labelFor instanceof Container &&
                ((Container) labelFor).isFocusCycleRoot()) {
            labelFor.requestFocus();
        } else {
            SwingUtilities2.compositeRequestFocus(labelFor);
        }
    }
}
 
Example 7
Source File: BasicLabelUI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void doPress(JLabel label) {
    Component labelFor = label.getLabelFor();
    if (labelFor != null && labelFor.isEnabled()) {
        InputMap inputMap = SwingUtilities.getUIInputMap(label, JComponent.WHEN_FOCUSED);
        if (inputMap == null) {
            inputMap = new InputMapUIResource();
            SwingUtilities.replaceUIInputMap(label, JComponent.WHEN_FOCUSED, inputMap);
        }
        int dka = label.getDisplayedMnemonic();
        putOnRelease(inputMap, dka, BasicLookAndFeel
                .getFocusAcceleratorKeyMask());
        // Need this when the sticky keys are enabled
        putOnRelease(inputMap, dka, 0);
        // Need this if ALT is released before the accelerator
        putOnRelease(inputMap, KeyEvent.VK_ALT, 0);
        label.requestFocus();
    }
}
 
Example 8
Source File: MetalBorders.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y,
                        int w, int h) {

  if (!(c instanceof JTextComponent)) {
        // special case for non-text components (bug ID 4144840)
        if (c.isEnabled()) {
            MetalUtils.drawFlush3DBorder(g, x, y, w, h);
        } else {
            MetalUtils.drawDisabledBorder(g, x, y, w, h);
        }
        return;
    }

    if (c.isEnabled() && ((JTextComponent)c).isEditable()) {
        MetalUtils.drawFlush3DBorder(g, x, y, w, h);
    } else {
        MetalUtils.drawDisabledBorder(g, x, y, w, h);
    }

}
 
Example 9
Source File: BasicLabelUI.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void doPress(JLabel label) {
    Component labelFor = label.getLabelFor();
    if (labelFor != null && labelFor.isEnabled()) {
        InputMap inputMap = SwingUtilities.getUIInputMap(label, JComponent.WHEN_FOCUSED);
        if (inputMap == null) {
            inputMap = new InputMapUIResource();
            SwingUtilities.replaceUIInputMap(label, JComponent.WHEN_FOCUSED, inputMap);
        }
        int dka = label.getDisplayedMnemonic();
        inputMap.put(KeyStroke.getKeyStroke(dka, BasicLookAndFeel.getFocusAcceleratorKeyMask(), true), RELEASE);
        // Need this when the sticky keys are enabled
        inputMap.put(KeyStroke.getKeyStroke(dka, 0, true), RELEASE);
        // Need this if ALT is released before the accelerator
        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ALT, 0, true), RELEASE);
        label.requestFocus();
    }
}
 
Example 10
Source File: MetalBorders.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y,
                        int w, int h) {

  if (!(c instanceof JTextComponent)) {
        // special case for non-text components (bug ID 4144840)
        if (c.isEnabled()) {
            MetalUtils.drawFlush3DBorder(g, x, y, w, h);
        } else {
            MetalUtils.drawDisabledBorder(g, x, y, w, h);
        }
        return;
    }

    if (c.isEnabled() && ((JTextComponent)c).isEditable()) {
        MetalUtils.drawFlush3DBorder(g, x, y, w, h);
    } else {
        MetalUtils.drawDisabledBorder(g, x, y, w, h);
    }

}
 
Example 11
Source File: BasicLabelUI.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private void doPress(JLabel label) {
    Component labelFor = label.getLabelFor();
    if (labelFor != null && labelFor.isEnabled()) {
        InputMap inputMap = SwingUtilities.getUIInputMap(label, JComponent.WHEN_FOCUSED);
        if (inputMap == null) {
            inputMap = new InputMapUIResource();
            SwingUtilities.replaceUIInputMap(label, JComponent.WHEN_FOCUSED, inputMap);
        }
        int dka = label.getDisplayedMnemonic();
        putOnRelease(inputMap, dka, BasicLookAndFeel
                .getFocusAcceleratorKeyMask());
        // Need this when the sticky keys are enabled
        putOnRelease(inputMap, dka, 0);
        // Need this if ALT is released before the accelerator
        putOnRelease(inputMap, KeyEvent.VK_ALT, 0);
        label.requestFocus();
    }
}
 
Example 12
Source File: CopyAction.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
  public void actionPerformed(ActionEvent evt) {
    Component cFocusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();

    if (cFocusOwner instanceof JComponent) {
      if (cFocusOwner.isEnabled()) {
        // Cut all selected UserObjects from the tree
        if (cFocusOwner instanceof EditableComponent) {
          ((EditableComponent) cFocusOwner).copySelectedItems();
        }
      }
    }

    // "Old" version with JHotDraw clipboard
//    JComponent cTarget = target;
//
//    if (cTarget == null && (cFocusOwner instanceof JComponent)) {
//      cTarget = (JComponent) cFocusOwner;
//    }
//    // Note: copying is allowed for disabled components
//    if (cTarget != null && cTarget.getTransferHandler() != null) {
//      cTarget.getTransferHandler().exportToClipboard(cTarget, ClipboardUtil.getClipboard(), TransferHandler.COPY);
//    }
  }
 
Example 13
Source File: BasicPopupMenuUI.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static MenuElement nextEnabledChild(MenuElement e[],
                                            int fromIndex, int toIndex) {
    for (int i=fromIndex; i<=toIndex; i++) {
        if (e[i] != null) {
            Component comp = e[i].getComponent();
            if ( comp != null
                    && (comp.isEnabled() || UIManager.getBoolean("MenuItem.disabledAreNavigable"))
                    && comp.isVisible()) {
                return e[i];
            }
        }
    }
    return null;
}
 
Example 14
Source File: BasicPopupMenuUI.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private static MenuElement nextEnabledChild(MenuElement e[],
                                            int fromIndex, int toIndex) {
    for (int i=fromIndex; i<=toIndex; i++) {
        if (e[i] != null) {
            Component comp = e[i].getComponent();
            if ( comp != null
                    && (comp.isEnabled() || UIManager.getBoolean("MenuItem.disabledAreNavigable"))
                    && comp.isVisible()) {
                return e[i];
            }
        }
    }
    return null;
}
 
Example 15
Source File: SeaGlassLookAndFeel.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the component state for the specified component. This should only
 * be used for Components that don't have any special state beyond that of
 * ENABLED, DISABLED or FOCUSED. For example, buttons shouldn't call into
 * this method.
 *
 * @param  c the component.
 *
 * @return the simple state of the component.
 */
public static int getComponentState(Component c) {
    if (c.isEnabled()) {

        if (c.isFocusOwner()) {
            return SeaglassUI.ENABLED | SeaglassUI.FOCUSED;
        }

        return SeaglassUI.ENABLED;
    }

    return SeaglassUI.DISABLED;
}
 
Example 16
Source File: BasicPopupMenuUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static MenuElement previousEnabledChild(MenuElement e[],
                                            int fromIndex, int toIndex) {
    for (int i=fromIndex; i>=toIndex; i--) {
        if (e[i] != null) {
            Component comp = e[i].getComponent();
            if ( comp != null
                    && (comp.isEnabled() || UIManager.getBoolean("MenuItem.disabledAreNavigable"))
                    && comp.isVisible()) {
                return e[i];
            }
        }
    }
    return null;
}
 
Example 17
Source File: BasicPopupMenuUI.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private static MenuElement previousEnabledChild(MenuElement e[],
                                            int fromIndex, int toIndex) {
    for (int i=fromIndex; i>=toIndex; i--) {
        if (e[i] != null) {
            Component comp = e[i].getComponent();
            if ( comp != null
                    && (comp.isEnabled() || UIManager.getBoolean("MenuItem.disabledAreNavigable"))
                    && comp.isVisible()) {
                return e[i];
            }
        }
    }
    return null;
}
 
Example 18
Source File: MetalBorders.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y,
                  int w, int h) {
    if (c.isEnabled()) {
        MetalUtils.drawFlush3DBorder(g, x, y, w, h);
    } else {
        MetalUtils.drawDisabledBorder(g, x, y, w, h);
    }
}
 
Example 19
Source File: BasicPopupMenuUI.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static MenuElement previousEnabledChild(MenuElement e[],
                                            int fromIndex, int toIndex) {
    for (int i=fromIndex; i>=toIndex; i--) {
        if (e[i] != null) {
            Component comp = e[i].getComponent();
            if ( comp != null
                    && (comp.isEnabled() || UIManager.getBoolean("MenuItem.disabledAreNavigable"))
                    && comp.isVisible()) {
                return e[i];
            }
        }
    }
    return null;
}
 
Example 20
Source File: ClientFocusTraversalPolicy.java    From chipster with MIT License 5 votes vote down vote up
public Component getComponentAfter(Container focusCycleRoot,
                                   Component aComponent)
{
    int idx = (order.indexOf(aComponent) + 1) % order.size();
    logger.debug("Focus moved to next component: " + order.get(idx));
    Component comp = order.get(idx);
    if(!comp.isEnabled()){
    	comp = getComponentAfter(focusCycleRoot, comp);
    }
    return comp;        
}