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;
}
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()));
}
}
}
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);
}
}
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);
}
}
}
}
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;
}
Aggregations