Search in sources :

Example 1 with CNotCriterium

use of com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Not.CNotCriterium in project binnavi by google.

the class CTreeNodeRenderer method getTreeCellRendererComponent.

@Override
public Component getTreeCellRendererComponent(final JTree tree, final Object value, final boolean sel, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    if (value instanceof JCriteriumTreeNode) {
        final JCriteriumTreeNode node = (JCriteriumTreeNode) value;
        final int count = node.getChildCount();
        final ICriterium type = node.getCriterium();
        if (!(type instanceof CConditionCriterium)) {
            if (count == 1 && (type instanceof CNotCriterium || node.getLevel() == 0) || count > 1 && !(type instanceof CNotCriterium)) {
                setForeground(VALID_NODE_FONT_COLOR);
            } else {
                setForeground(INVALID_NODE_FONT_COLOR);
            }
        }
    }
    return this;
}
Also used : ICriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.ICriterium) CNotCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Not.CNotCriterium) CConditionCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.CConditionCriterium)

Example 2 with CNotCriterium

use of com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Not.CNotCriterium in project binnavi by google.

the class CExpressionTreeValidator method isValid.

/**
   * Checks whether a given tree contains a valid boolean formula.
   *
   * @param tree The tree to check.
   *
   * @return True, if the tree is valid. False, otherwise.
   */
public static boolean isValid(final JCriteriumTree tree) {
    final JCriteriumTreeNode root = (JCriteriumTreeNode) tree.getModel().getRoot();
    if (root.getChildCount() != 1) {
        return false;
    }
    final Enumeration<?> enumeration = root.breadthFirstEnumeration();
    while (enumeration.hasMoreElements()) {
        final JCriteriumTreeNode node = (JCriteriumTreeNode) enumeration.nextElement();
        final ICriterium type = node.getCriterium();
        final int count = node.getChildCount();
        if ((type instanceof CAndCriterium || type instanceof COrCriterium) && count < 2) {
            return false;
        } else if (type instanceof CNotCriterium && count != 1) {
            return false;
        }
    }
    return true;
}
Also used : ICriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.ICriterium) CAndCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.And.CAndCriterium) CNotCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Not.CNotCriterium) COrCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Or.COrCriterium)

Aggregations

ICriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.ICriterium)2 CNotCriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Not.CNotCriterium)2 CAndCriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.And.CAndCriterium)1 CConditionCriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.CConditionCriterium)1 COrCriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Or.COrCriterium)1