Example usage for javax.swing JCheckBox isEnabled

List of usage examples for javax.swing JCheckBox isEnabled

Introduction

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

Prototype

public boolean isEnabled() 

Source Link

Document

Determines whether this component is enabled.

Usage

From source file:Main.java

public static void main(String[] args) {
    JCheckBox checkBox = new JCheckBox("Enabled", true);

    checkBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (checkBox.isEnabled())
                checkBox.setEnabled(false);
            else//from w w  w. ja  v  a 2s  .c  o m
                checkBox.setEnabled(true);
        }
    });
    JOptionPane.showMessageDialog(null, checkBox);
}

From source file:com.github.alexfalappa.nbspringboot.projects.initializr.BootDependenciesPanel.java

public List<String> getSelectedDependencies() {
    List<String> ret = new ArrayList<>();
    for (List<JCheckBox> chList : chkBoxesMap.values()) {
        for (JCheckBox cb : chList) {
            if (cb.isEnabled() && cb.isSelected()) {
                ret.add(cb.getName());//w  w  w  . j av  a 2  s.c om
            }
        }
    }
    return ret;
}

From source file:com.github.alexfalappa.nbspringboot.projects.initializr.BootDependenciesPanel.java

public String getSelectedDependenciesString() {
    StringBuilder sb = new StringBuilder();
    for (List<JCheckBox> chList : chkBoxesMap.values()) {
        for (JCheckBox cb : chList) {
            if (cb.isEnabled() && cb.isSelected()) {
                sb.append(cb.getName()).append(',');
            }//from   w ww.  j a v  a2 s .c  om
        }
    }
    // remove last comma (if present)
    if (sb.length() > 0) {
        sb.setLength(sb.length() - 1);
    }
    return sb.toString();
}

From source file:edu.ku.brc.specify.datamodel.busrules.BaseTreeBusRules.java

@SuppressWarnings("unchecked")
@Override/*from   w w w  .ja va  2  s  .  c  o m*/
public void afterFillForm(final Object dataObj) {
    // This is a little weak and cheesey, but it gets the job done.
    // Because both the Tree and Definition want/need to share Business Rules.
    String viewName = formViewObj.getView().getName();
    if (StringUtils.contains(viewName, "TreeDef")) {
        if (formViewObj.getAltView().getMode() != CreationMode.EDIT) {
            // when we're not in edit mode, we don't need to setup any listeners since the user can't change anything
            //log.debug("form is not in edit mode: no special listeners will be attached");
            return;
        }

        if (!StringUtils.contains(viewName, "TreeDefItem")) {
            return;
        }

        final I nodeInForm = (I) formViewObj.getDataObj();
        //disable FullName -related fields if TreeDefItem is used by nodes in the tree
        //NOTE: Can remove the edit restriction. Tree rebuilds now update fullname fields. Need to add tree rebuild after fullname def edits.
        if (nodeInForm != null && nodeInForm.getTreeDef() != null) {
            //               boolean canNOTEditFullNameFlds = nodeInForm.hasTreeEntries();
            //               if (canNOTEditFullNameFlds)
            //               {
            //                  ValTextField ftCtrl = (ValTextField )formViewObj.getControlByName("textAfter");
            //                  if (ftCtrl != null)
            //                  {
            //                     ftCtrl.setEnabled(false);
            //                  }
            //                  ftCtrl = (ValTextField )formViewObj.getControlByName("textBefore");
            //                  if (ftCtrl != null)
            //                  {
            //                     ftCtrl.setEnabled(false);
            //                  }
            //                  ftCtrl = (ValTextField )formViewObj.getControlByName("fullNameSeparator");
            //                  if (ftCtrl != null)
            //                  {
            //                     ftCtrl.setEnabled(false);
            //                  }
            //                  ValCheckBox ftBox = (ValCheckBox )formViewObj.getControlByName("isInFullName");
            //                  if (ftBox != null)
            //                  {
            //                     ftBox.setEnabled(false);
            //                  }
            //               }

            if (!viewName.endsWith("TreeDefItem")) {
                return;
            }

            //disabling editing of name and rank for standard levels.
            List<TreeDefItemStandardEntry> stds = nodeInForm.getTreeDef().getStandardLevels();
            TreeDefItemStandardEntry stdLevel = null;
            for (TreeDefItemStandardEntry std : stds) {
                //if (std.getTitle().equals(nodeInForm.getName()) && std.getRank() == nodeInForm.getRankId())
                if (std.getRank() == nodeInForm.getRankId()) {
                    stdLevel = std;
                    break;
                }
            }
            if (stdLevel != null) {
                ValTextField nameCtrl = (ValTextField) formViewObj.getControlByName("name");
                Component rankCtrl = formViewObj.getControlByName("rankId");
                if (nameCtrl != null) {
                    nameCtrl.setEnabled(false);
                }
                if (rankCtrl != null) {
                    rankCtrl.setEnabled(false);
                }
                if (nodeInForm.getTreeDef().isRequiredLevel(stdLevel.getRank())) {
                    Component enforcedCtrl = formViewObj.getControlByName("isEnforced");
                    if (enforcedCtrl != null) {
                        enforcedCtrl.setEnabled(false);
                    }
                }
            }
        }
        return;
    }

    final T nodeInForm = (T) formViewObj.getDataObj();

    if (formViewObj.getAltView().getMode() != CreationMode.EDIT) {
        if (nodeInForm != null) {
            //XXX this MAY be necessary due to a bug with TextFieldFromPickListTable??
            // TextFieldFromPickListTable.setValue() does nothing because of a null adapter member.
            Component comp = formViewObj.getControlByName("definitionItem");
            if (comp instanceof JTextField) {
                ((JTextField) comp).setText(nodeInForm.getDefinitionItem().getName());
            }
        }
    } else {
        processedRules = false;
        GetSetValueIFace parentField = (GetSetValueIFace) formViewObj.getControlByName("parent");
        Component comp = formViewObj.getControlByName("definitionItem");
        if (comp instanceof ValComboBox) {
            final ValComboBox rankComboBox = (ValComboBox) comp;

            if (parentField instanceof ValComboBoxFromQuery) {
                final ValComboBoxFromQuery parentCBX = (ValComboBoxFromQuery) parentField;
                if (parentCBX != null && rankComboBox != null && nodeInForm != null) {
                    parentCBX.registerQueryBuilder(new TreeableSearchQueryBuilder(nodeInForm, rankComboBox,
                            TreeableSearchQueryBuilder.PARENT));
                }
            }

            if (nodeInForm != null && nodeInForm.getDefinitionItem() != null) {
                // log.debug("node in form already has a set rank: forcing a call to
                // adjustRankComboBoxModel()");
                UIValidator.setIgnoreAllValidation(this, true);
                adjustRankComboBoxModel(parentField, rankComboBox, nodeInForm);
                UIValidator.setIgnoreAllValidation(this, false);
            }

            // TODO: the form system MUST require the accepted parent widget to be present if
            // the
            // isAccepted checkbox is present
            final JCheckBox acceptedCheckBox = (JCheckBox) formViewObj.getControlByName("isAccepted");
            final ValComboBoxFromQuery acceptedParentWidget = (ValComboBoxFromQuery) formViewObj
                    .getControlByName("acceptedParent");
            if (canAccessSynonymy(nodeInForm)) {
                if (acceptedCheckBox != null && acceptedParentWidget != null) {
                    if (acceptedCheckBox.isSelected() && nodeInForm != null
                            && nodeInForm.getDefinition() != null) {
                        // disable if necessary
                        boolean canSynonymize = nodeInForm.getDefinition().getSynonymizedLevel() <= nodeInForm
                                .getRankId() && nodeInForm.getDescendantCount() == 0;
                        acceptedCheckBox.setEnabled(canSynonymize);
                    }
                    acceptedParentWidget
                            .setEnabled(!acceptedCheckBox.isSelected() && acceptedCheckBox.isEnabled());
                    if (acceptedCheckBox.isSelected()) {
                        acceptedParentWidget.setValue(null, null);
                    }

                    if (nodeInForm != null && acceptedParentWidget != null && rankComboBox != null) {
                        acceptedParentWidget.registerQueryBuilder(new TreeableSearchQueryBuilder(nodeInForm,
                                rankComboBox, TreeableSearchQueryBuilder.ACCEPTED_PARENT));
                    }
                }
            } else {
                if (acceptedCheckBox != null) {
                    acceptedCheckBox.setEnabled(false);
                }
                if (acceptedParentWidget != null) {
                    acceptedParentWidget.setEnabled(false);
                }
            }

            if (parentField instanceof ValComboBoxFromQuery) {
                parentChanged(formViewObj, (ValComboBoxFromQuery) parentField, rankComboBox, acceptedCheckBox,
                        acceptedParentWidget);
            }
        }
    }
}

From source file:edu.ku.brc.specify.datamodel.busrules.BaseTreeBusRules.java

@SuppressWarnings("unchecked")
protected void rankChanged(final FormViewObj form, final ValComboBoxFromQuery parentComboBox,
        final ValComboBox rankComboBox, final JCheckBox acceptedCheckBox,
        final ValComboBoxFromQuery acceptedParentWidget) {
    if (form.getAltView().getMode() != CreationMode.EDIT) {
        return;/*  w  w w .  j av a  2s .c o  m*/
    }

    //log.debug("form was validated: calling adjustRankComboBoxModel()");

    Object objInForm = form.getDataObj();
    //log.debug("form data object = " + objInForm);
    if (objInForm == null) {
        return;
    }

    final T formNode = (T) objInForm;
    T parent = null;
    if (parentComboBox.getValue() instanceof String) {
        // the data is still in the VIEW mode for some reason
        log.debug("Form is in mode (" + form.getAltView().getMode() + ") but the parent data is a String");
        parentComboBox.getValue();
        parent = formNode.getParent();
    } else {
        parent = (T) parentComboBox.getValue();
    }

    final T theParent = parent;
    I rankObj = (I) rankComboBox.getValue();
    final int rank = rankObj == null ? -2 : rankObj.getRankId();
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            boolean canSynonymize = false;
            if (canAccessSynonymy(formNode, rank)) {
                canSynonymize = formNode.getDefinition() != null
                        && formNode.getDefinition().getSynonymizedLevel() <= rank
                        && formNode.getDescendantCount() == 0;

            }
            if (acceptedCheckBox != null && acceptedParentWidget != null) {
                acceptedCheckBox.setEnabled(canSynonymize && theParent != null);
                if (acceptedCheckBox.isSelected() && acceptedCheckBox.isEnabled()) {
                    acceptedParentWidget.setValue(null, null);
                    acceptedParentWidget.setChanged(true); // This should be done automatically
                    acceptedParentWidget.setEnabled(false);
                }
            }
            form.getValidator().validateForm();
        }
    });
}