Search in sources :

Example 1 with ICriterium

use of com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.ICriterium 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 ICriterium

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

the class JCriteriumTreeModel method nodeStructureChanged.

@Override
public void nodeStructureChanged(final TreeNode node) {
    final Set<ICriterium> criteriumSet = new HashSet<ICriterium>();
    final Enumeration<TreePath> expandedPaths = m_jtree.getExpandedDescendants(new TreePath(getRoot()));
    if (expandedPaths != null) {
        while (expandedPaths.hasMoreElements()) {
            final TreePath path = expandedPaths.nextElement();
            final JCriteriumTreeNode expandedNode = (JCriteriumTreeNode) path.getLastPathComponent();
            criteriumSet.add(expandedNode.getCriterium());
        }
    }
    super.nodeStructureChanged(node);
    final Enumeration<?> nodes = ((JCriteriumTreeNode) getRoot()).breadthFirstEnumeration();
    while (nodes.hasMoreElements()) {
        final JCriteriumTreeNode nextNode = (JCriteriumTreeNode) nodes.nextElement();
        if (criteriumSet.contains(nextNode.getCriterium())) {
            m_jtree.expandPath(new TreePath(nextNode.getPath()));
        }
    }
}
Also used : ICriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.ICriterium) TreePath(javax.swing.tree.TreePath) HashSet(java.util.HashSet)

Example 3 with ICriterium

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

the class JCriteriumTreeModel method sortChildren.

/**
   * Sorts visible tree nodes.
   * 
   * @param parentNode Parent nodes whose children are sorted.
   */
private void sortChildren(final JCriteriumTreeNode parentNode) {
    final List<JCriteriumTreeNode> operators = new ArrayList<JCriteriumTreeNode>();
    final List<JCriteriumTreeNode> conditions = new ArrayList<JCriteriumTreeNode>();
    final List<JCriteriumTreeNode> minus = new ArrayList<JCriteriumTreeNode>();
    final Enumeration<?> children = parentNode.children();
    while (children.hasMoreElements()) {
        final JCriteriumTreeNode child = (JCriteriumTreeNode) children.nextElement();
        final ICriterium type = child.getCriterium();
        if (type instanceof CConditionCriterium) {
            conditions.add(child);
        } else {
            operators.add(child);
        }
    }
    parentNode.removeAllChildren();
    for (final JCriteriumTreeNode child : operators) {
        parentNode.add(child);
        child.setParent(parentNode);
    }
    for (final JCriteriumTreeNode child : conditions) {
        parentNode.add(child);
        child.setParent(parentNode);
    }
    for (final JCriteriumTreeNode child : minus) {
        parentNode.add(child);
        child.setParent(parentNode);
    }
}
Also used : ICriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.ICriterium) ArrayList(java.util.ArrayList) CConditionCriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.CConditionCriterium)

Example 4 with ICriterium

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

the class CCriteriumFunctions method appendCriterium.

/**
   * Appends a criterium to the criterium tree. The criterium is selected through the given combo
   * box.
   *
   * @param jtree Visible criteria tree.
   * @param ctree Backs the visible criteria tree.
   * @param conditionBox Provides the criterium to add.
   */
public static void appendCriterium(final JCriteriumTree jtree, final CCriteriumTree ctree, final CConditionBox conditionBox) {
    final TreePath path = jtree.getSelectionPath();
    if (path != null) {
        final JCriteriumTreeNode criteriumTreeNode = (JCriteriumTreeNode) path.getLastPathComponent();
        final CCriteriumTreeNode parent = CCriteriumFunctions.findNode(ctree.getRoot(), criteriumTreeNode.getCriterium());
        final CCriteriumWrapper selectedItem = (CCriteriumWrapper) conditionBox.getSelectedItem();
        if (selectedItem != null) {
            final ICriterium criterium = selectedItem.getObject().createCriterium();
            if (criterium != null) {
                appendCriterium(ctree, parent, criterium);
            }
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) ICriterium(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.ICriterium) JCriteriumTreeNode(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionTree.JCriteriumTreeNode) CCriteriumWrapper(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.CCriteriumWrapper) CCriteriumTreeNode(com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTreeNode)

Example 5 with ICriterium

use of com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.ICriterium 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)5 CConditionCriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.CConditionCriterium)2 CNotCriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Not.CNotCriterium)2 TreePath (javax.swing.tree.TreePath)2 CAndCriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.And.CAndCriterium)1 CCriteriumWrapper (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.CCriteriumWrapper)1 COrCriterium (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Or.COrCriterium)1 CCriteriumTreeNode (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionModel.CCriteriumTreeNode)1 JCriteriumTreeNode (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.ExpressionTree.JCriteriumTreeNode)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1