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