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

The following examples show how to use java.awt.Component#isEnabled() . These examples are extracted from open source projects. 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
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 Project: openAGV   File: CopyAction.java    License: 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 3
Source Project: JDKSourceCode1.8   File: BasicLabelUI.java    License: 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 4
Source Project: Bytecoder   File: MetalBorders.java    License: 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 5
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 6
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 7
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
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 9
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 10
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 11
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 12
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 13
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 14
Source Project: JDKSourceCode1.8   File: BasicPopupMenuUI.java    License: 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 15
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 16
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 17
Source Project: seaglass   File: SeaGlassLookAndFeel.java    License: 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 18
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 19
Source Project: Java8CN   File: MetalBorders.java    License: 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 20
Source Project: chipster   File: ClientFocusTraversalPolicy.java    License: 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;        
}