近开发安全键盘的时候发现有一个矛盾的问题,如果都设置了边框 ,也设置了阴影的情况下,到底是要前者还是后者,这就需要比较了
/// <summary>
/// 有这么一种情况 shadowInfo 和borderinfo都设置了, 非同级别的情况下,但是级别谁来from进,就应该选谁,咋办呢? 数字越大越小等级越大
/// </summary> 返回负数 代表前者大 也就是最接近 原始等级,返回 正数代表后者大
/// <param name="node1From"></param>
/// <param name="nodeFirst"></param>
/// <param name="nodeSecond"></param>
public static int levelCompare(INode nodeFrom, INode nodeFirst, INode nodeSecond)
{
INode currentNode = nodeFrom;
int nodeLevelFirst = 0;
int nodeLevelSecond = 0;
bool firstHasFound = false;
bool secondHasFound = false;
while (currentNode != null)
{
if (nodeFirst == currentNode)
{
firstHasFound = true;
} else {
nodeLevelFirst++;
}
if (nodeSecond == currentNode) {
secondHasFound = true;
} else {
nodeLevelSecond++;
}
if (firstHasFound && secondHasFound)
{
break;
}
currentNode = nodeFrom.getParent();
}
return nodeLevelFirst = nodeLevelSecond;
}
代码2
public JObjectTarget<ShadowInfo> getShadowInfoTarget()
{
string key = "shadow";
if (!JSONUtil.jsonKeyIsExist(jObject, key))
{
parentExtend = getParentKey();
if (parentExtend != null)
{
JObjectTarget<ShadowInfo> target = parentExtend.getShadowInfoTarget();
if (target == null)
{
return null;
}
target.setNode(parentExtend);
return target;
}
else
{
//jObject[key] = JSONCreateUtil.createShadowInfo();
//JObjectTarget<ShadowInfo> target = EntryFactory.createJObjectTarget<ShadowInfo>(jObject, key);
//target.setNode(parentExtend);
//return target;//不允许自动设置。
return null;
}
}
else
{
JObjectTarget<ShadowInfo> target = EntryFactory.createJObjectTarget<ShadowInfo>(jObject, key);
target.setNode(this);
return target;
}
}
public JObjectTarget<BorderInfo> getBorderInfoTarget()
{
string key = "border";
if (!JSONUtil.jsonKeyIsExist(jObject, key))
{
parentExtend = getParentKey();
if (parentExtend != null)
{
JObjectTarget<BorderInfo> target = parentExtend.getBorderInfoTarget();
if (target == null)
{
return null;
}
target.setNode(parentExtend);
return target;
}
else
{
//jObject[key] = JSONCreateUtil.createShadowInfo();
//JObjectTarget<BorderInfo> target = EntryFactory.createJObjectTarget<BorderInfo>(jObject, key);
//target.setNode(parentExtend);
//return target;
return null;//不允许自动设置。
}
}
else
{
JObjectTarget<BorderInfo> target = EntryFactory.createJObjectTarget<BorderInfo>(jObject, key);
target.setNode(this);
return target;
}
}
代码三
ShadowInfo shadowInfo = objKey.getShadowInfo();
BorderInfo borderInfo = objKey.getBorderInfo();
int useBorderFlag = -1;
if (shadowInfo == null && borderInfo == null)
{
useBorderFlag = -1;
}
else if (shadowInfo != null && borderInfo != null)
{
if (ViewUtil.levelCompare(objKey, shadowInfo.node, borderInfo.node) <= 0)
{
useBorderFlag = 0;
}
else
{
useBorderFlag = 1;
}
}
else if (shadowInfo == null)
{
useBorderFlag = 1;
}
else if (borderInfo == null)
{
useBorderFlag = 0;
}
if (useBorderFlag == 0)
{
//TODO
keyButton.FlatAppearance.BorderSize = 0;
}
else if (useBorderFlag == 1)
{
keyButton.FlatAppearance.BorderSize = borderInfo.getSize().getIntValue();
string borderColor = objKey.getFontColorTarget().getStringValue("#ff0000");
keyButton.FlatAppearance.BorderColor = AppUtil.parseColor(borderColor);
}