Example usage for javax.swing JComponent isEnabled

List of usage examples for javax.swing JComponent isEnabled

Introduction

In this page you can find the example usage for javax.swing JComponent isEnabled.

Prototype

public boolean isEnabled() 

Source Link

Document

Determines whether this component is enabled.

Usage

From source file:Main.java

/**
 * Ignore mouse events if the component is null, not enabled, the event
 * is not associated with the left mouse button, or the event has been
 * consumed./*from   w ww  .ja v  a 2s  .  c om*/
 */
public static boolean shouldIgnore(MouseEvent me, JComponent c) {
    return c == null || !c.isEnabled() || !SwingUtilities.isLeftMouseButton(me) || me.isConsumed();
}

From source file:ButtonScroll.java

protected void enableComponent(JComponent c, boolean b) {
    if (c.isEnabled() != b)
        c.setEnabled(b);
}

From source file:com.stefanbrenner.droplet.utils.UiUtilsTest.java

@Test
public void testSetEnabledRecursive() {
    JPanel testPanel = new JPanel();

    JButton btnTest = new JButton();
    testPanel.add(btnTest);//from   w  w  w.ja  v a  2s .c om
    JTextField txtTest = new JTextField();
    testPanel.add(txtTest);

    JPanel testPanel2 = new JPanel();
    JCheckBox chTest = new JCheckBox();
    testPanel2.add(chTest);

    testPanel.add(testPanel2);

    List<JComponent> allComps = Arrays
            .asList(new JComponent[] { testPanel, btnTest, txtTest, testPanel2, chTest });

    // disable all components
    UiUtils.setEnabledRecursive(testPanel, false);
    for (JComponent comp : allComps) {
        assertEquals(false, comp.isEnabled());
    }
    // re-enable all components
    UiUtils.setEnabledRecursive(testPanel, true);
    for (JComponent comp : allComps) {
        assertEquals(true, comp.isEnabled());
    }

    // disable all except txtTest
    UiUtils.setEnabledRecursive(testPanel, false, txtTest);
    for (JComponent comp : allComps) {
        if (ObjectUtils.notEqual(comp, txtTest)) {
            assertEquals(false, comp.isEnabled());
        } else {
            assertEquals(true, comp.isEnabled());
        }
    }
    // re-enable all components
    UiUtils.setEnabledRecursive(testPanel, true);
    for (JComponent comp : allComps) {
        assertEquals(true, comp.isEnabled());
    }

    // disable all except chTest in testPanel2
    UiUtils.setEnabledRecursive(testPanel, false, chTest);
    for (JComponent comp : allComps) {
        if (ObjectUtils.notEqual(comp, chTest)) {
            assertEquals(false, comp.isEnabled());
        } else {
            assertEquals(true, comp.isEnabled());
        }
    }
    // re-enable all components
    UiUtils.setEnabledRecursive(testPanel, true);
    for (JComponent comp : allComps) {
        assertEquals(true, comp.isEnabled());
    }

    // disable all except txtTest in testPanel and chTest in testPanel2
    JComponent[] except = new JComponent[] { txtTest, chTest };
    UiUtils.setEnabledRecursive(testPanel, false, except);
    for (JComponent comp : allComps) {
        if (!Arrays.asList(except).contains(comp)) {
            assertEquals(false, comp.isEnabled());
        } else {
            assertEquals(true, comp.isEnabled());
        }
    }
    // re-enable all components
    UiUtils.setEnabledRecursive(testPanel, true);
    for (JComponent comp : allComps) {
        assertEquals(true, comp.isEnabled());
    }

}

From source file:com.stefanbrenner.droplet.utils.UiUtilsTest.java

@Test
public void testSetEnabled() {
    JPanel testPanel = new JPanel();

    JButton btnTest = new JButton();
    testPanel.add(btnTest);/*from  w  ww. j  a va2  s  .c om*/
    JTextField txtTest = new JTextField();
    testPanel.add(txtTest);

    JPanel testPanel2 = new JPanel();
    JCheckBox chTest = new JCheckBox();
    testPanel2.add(chTest);

    testPanel.add(testPanel2);

    List<JComponent> allComps = Arrays
            .asList(new JComponent[] { testPanel, btnTest, txtTest, testPanel2, chTest });
    List<JComponent> childComps = Arrays.asList(new JComponent[] { testPanel, btnTest, txtTest, testPanel2 });

    // disable all components
    UiUtils.setEnabled(testPanel, false);
    for (JComponent comp : allComps) {
        if (childComps.contains(comp)) {
            assertEquals(false, comp.isEnabled());
        } else {
            assertEquals(true, comp.isEnabled());
        }
    }
    // re-enable all components
    UiUtils.setEnabled(testPanel, true);
    for (JComponent comp : allComps) {
        assertEquals(true, comp.isEnabled());
    }

    // disable all except txtTest
    UiUtils.setEnabled(testPanel, false, txtTest);
    for (JComponent comp : allComps) {
        if (childComps.contains(comp) && ObjectUtils.notEqual(comp, txtTest)) {
            assertEquals(false, comp.isEnabled());
        } else {
            assertEquals(true, comp.isEnabled());
        }
    }
    // re-enable all components
    UiUtils.setEnabled(testPanel, true);
    for (JComponent comp : allComps) {
        assertEquals(true, comp.isEnabled());
    }

    // disable all except chTest in testPanel2
    UiUtils.setEnabled(testPanel, false, chTest);
    for (JComponent comp : allComps) {
        if (childComps.contains(comp) && ObjectUtils.notEqual(comp, chTest)) {
            assertEquals(false, comp.isEnabled());
        } else {
            assertEquals(true, comp.isEnabled());
        }
    }
    // re-enable all components
    UiUtils.setEnabled(testPanel, true);
    for (JComponent comp : allComps) {
        assertEquals(true, comp.isEnabled());
    }

    // disable all except txtTest in testPanel and chTest in testPanel2
    JComponent[] except = new JComponent[] { txtTest, chTest };
    UiUtils.setEnabled(testPanel, false, except);
    for (JComponent comp : allComps) {
        if (childComps.contains(comp) && !Arrays.asList(except).contains(comp)) {
            assertEquals(false, comp.isEnabled());
        } else {
            assertEquals(true, comp.isEnabled());
        }
    }
    // re-enable all components
    UiUtils.setEnabled(testPanel, true);
    for (JComponent comp : allComps) {
        assertEquals(true, comp.isEnabled());
    }

}

From source file:com.aw.swing.mvp.binding.BindingComponent.java

public boolean isFocusable() {
    if (!isUiReadOnly()) {
        JComponent jComponent = getJComponent();
        return (jComponent.isVisible() && jComponent.isEnabled() && !(jComponent instanceof JLabel));
    }/*  w  ww .  j a  v  a2  s. c  om*/
    return false;
}

From source file:com.atlassian.theplugin.idea.bamboo.tree.BuildTreeNode.java

@Override
public JComponent getRenderer(final JComponent c, final boolean selected, final boolean expanded,
        final boolean hasFocus) {
    renderer.reformatPanel(selected, c.isEnabled());
    return renderer;
}

From source file:net.aepik.alasca.gui.ldap.SchemaObjectEditorFrame.java

/**
 * Build frame./*from  ww w .ja  v  a 2 s .  c  om*/
 */
private void build() {
    setTitle("Proprits de l'objet " + objetSchema.getId());
    setSize(700, 400);
    setResizable(false);
    setLocationRelativeTo(mainFrame);

    if (mainFrame != null)
        setIconImage(mainFrame.getIconImage());

    // - Panel bouton du bas -

    JPanel boutonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    boutonsPanel.add(boutonOk);
    boutonsPanel.add(boutonAnnuler);

    // - Description -

    JTextArea textAreaValues = new JTextArea("Vous pouvez apporter des modifications sur les paramtres"
            + " de cet objet d'identifiant " + objetSchema.getId() + ". Les"
            + " modifications apportes  des paramtres non-cochs ne" + " seront pas prises en compte.");
    textAreaValues.setEditable(false);
    textAreaValues.setLineWrap(true);
    textAreaValues.setWrapStyleWord(true);
    textAreaValues.setFont((new JLabel()).getFont());
    textAreaValues.setBorder(BorderFactory.createEmptyBorder(7, 8, 7, 8));
    textAreaValues.setBackground((new JLabel()).getBackground());

    // - La table des valeurs -
    // Correction : Tri alphabtique des valeurs

    Enumeration<String> k = values.keys();
    String[] keys = new String[values.size()];

    for (int i = 0; i < keys.length; i++)
        keys[i] = k.nextElement();
    Arrays.sort(keys);

    JPanel colonne1 = new JPanel(new GridLayout(keys.length, 1));
    JPanel colonne2 = new JPanel(new GridLayout(keys.length, 1));

    // Enumeration<JComponent> l = labels.elements();
    // Enumeration<JComponent> v = values.elements();
    // Enumeration<String> k = values.keys();
    // JPanel colonne1 = new JPanel( new GridLayout( values.size(), 1 ) );
    // JPanel colonne2 = new JPanel( new GridLayout( values.size(), 1 ) );

    for (int i = 0; keys != null && i < keys.length; i++) {

        // while( l.hasMoreElements() && v.hasMoreElements() && k.hasMoreElements() ) {

        String key = keys[i];
        JComponent label = labels.get(key);
        JComponent value = values.get(key);
        JCheckBox checkbox = valuesPresent.get(key);

        // String key = k.nextElement();
        // JComponent label = l.nextElement();
        // JComponent value = v.nextElement();
        // JCheckBox checkbox = valuesPresent.get( key );

        if (!value.isEnabled() && value instanceof JTextField) {

            //value.setEnabled( true );

            JButton b = new JButton("...");
            b.setBorder(BorderFactory.createCompoundBorder(
                    BorderFactory.createMatteBorder(0, 5, 0, 0, Color.white), b.getBorder()));
            b.addActionListener(new SchemaValueEditorLauncher(b, (JTextField) value, objetSchema, key));

            JPanel tmp = new JPanel(new BorderLayout());
            tmp.add(value, BorderLayout.CENTER);
            tmp.add(b, BorderLayout.EAST);
            tmp.setOpaque(false);
            value = tmp;
        }

        JPanel panelTmp1 = new JPanel(new BorderLayout());
        panelTmp1.add(checkbox, BorderLayout.WEST);
        panelTmp1.add(label, BorderLayout.CENTER);
        panelTmp1.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 3));
        colonne1.add(panelTmp1);

        JPanel panelTmp2 = new JPanel(new BorderLayout());
        panelTmp2.add(value, BorderLayout.CENTER);
        panelTmp2.setBorder(BorderFactory.createEmptyBorder(2, 3, 2, 3));
        colonne2.add(panelTmp2);

        checkbox.setOpaque(false);
        label.setOpaque(false);
        value.setOpaque(false);
        panelTmp1.setOpaque(false);
        panelTmp2.setOpaque(false);
    }

    JPanel tablePanel = new JPanel(new BorderLayout());
    tablePanel.add(colonne1, BorderLayout.WEST);
    tablePanel.add(colonne2, BorderLayout.EAST);
    tablePanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    colonne1.setOpaque(false);
    colonne2.setOpaque(false);
    tablePanel.setOpaque(false);

    JPanel tablePanelContainer = new JPanel(new BorderLayout());
    tablePanelContainer.add(tablePanel, BorderLayout.NORTH);
    tablePanelContainer.setBackground(Color.white);

    JList tmpForBorderList = new JList();
    JScrollPane tmpForBorderScroller = new JScrollPane(tmpForBorderList);

    JScrollPane tableScroller = new JScrollPane(tablePanelContainer);
    //tableScroller.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
    tableScroller.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 6, 1, 6),
            BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(" Listes des paramtres "),
                    BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5),
                            tmpForBorderScroller.getBorder()))));

    // - Organisation gnrale -

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(textAreaValues, BorderLayout.NORTH);
    mainPanel.add(tableScroller, BorderLayout.CENTER);

    JPanel mainPanelContainer = new JPanel(new BorderLayout());
    mainPanelContainer.add(mainPanel, BorderLayout.CENTER);
    mainPanelContainer.add(boutonsPanel, BorderLayout.SOUTH);
    mainPanelContainer.setBorder(BorderFactory.createEmptyBorder(2, 1, 1, 1));

    getContentPane().add(mainPanelContainer);

    // - Listeners -

    addWindowListener(this);
    boutonOk.addActionListener(this);
    boutonAnnuler.addActionListener(this);
}

From source file:org.nuclos.client.ui.collect.CollectController.java

/**
 * @param clctcomp - collectablecomponent of the details panel
 * this method should only be used to check whether it is allowed to adopt a value from the
 * search panel to the details panel//from ww  w . j  a v  a 2 s  .  c  o  m
 */
protected boolean isSetAllowedForClctComponent(CollectableComponent clctcomp) {
    boolean bEnabled = true;
    JComponent jcomp = clctcomp.getJComponent();

    if (jcomp instanceof LabeledTextField) {
        if (!((LabeledTextField) jcomp).getTextField().isEditable()) {
            bEnabled = false;
        }
    } else if (jcomp instanceof LabeledComboBox) {
        if (!((LabeledComboBox) jcomp).getJComboBox().isEnabled()) {
            bEnabled = false;
        }
    } else if (jcomp instanceof LabeledListOfValues) {
        if (!((ListOfValues) ((LabeledListOfValues) jcomp).getControlComponent()).getJTextField().isEnabled()) {
            bEnabled = false;
        }
    } else if (jcomp instanceof LabeledTextArea) {
        if (!((LabeledTextArea) jcomp).getJTextArea().isEditable()) {
            bEnabled = false;
        }
    } else if (jcomp instanceof LabeledDateChooser) {
        if (!((LabeledDateChooser) jcomp).getJTextComponent().isEditable()) {
            bEnabled = false;
        }
    } else if (clctcomp instanceof CollectableCheckBox) {
        if (!((CollectableCheckBox) clctcomp).getJCheckBox().isEnabled()) {
            bEnabled = false;
        }
    }
    // fallback - maybe the list above has to be adjusted
    if (!jcomp.isEnabled()) {
        bEnabled = false;
    }

    return bEnabled;
}