int realY = (int) (e.getY() / scale + 0.5);
anchor = new Point(realX, realY);
FeatureFigure parent = null;
Feature parentFeature = null;
Figure pressedFigure = drawingView.getDrawing().findFigureInside(realX, realY);
if (pressedFigure != null && FeatureFigure.class.isInstance(pressedFigure) && pressedFigure.getAttribute("id") != null && featureModel.containsFeature((String) pressedFigure.getAttribute("id"))) {
parent = (FeatureFigure) pressedFigure;
parentFeature = featureModel.getFeature((String) parent.getAttribute("id"));
anchor = parent.getDisplayBox().getLocation();
} else {
parent = new FeatureFigure();
drawingView.add(parent);
parent.setDisplayBox(anchor, anchor);
parentFeature = featureModelEditor.addFeature((String) parent.getAttribute(FeatureFigure.TEXT));
parent.setAttribute("id", parentFeature.getID());
//����id��figure��ӳ���
if (idToFigureMap != null) {
idToFigureMap.add(parentFeature.getID(), parent);
}
featureEditor.setName(parentFeature, "Parent");
}
if (refineType == Refinement.Decompose || refineType == Refinement.Attribute) {
FeatureFigure child[] = new FeatureFigure[childCount];
Feature childFeature[] = new Feature[childCount];
ConnectionFigure relation[] = new ConnectionFigure[childCount];
FeatureRelation fr[] = new FeatureRelation[childCount];
int xDis, yDis;
xDis = 80;
yDis = 85;
anchor.translate(-(childCount - 1) * xDis / 2 - xDis, yDis);
for (int i = 0; i < child.length; i++) {
anchor.translate(xDis, 0);
child[i] = (FeatureFigure) parent.clone();
child[i].setAttribute("id", "null");
drawingView.add(child[i]);
child[i].setDisplayBox(anchor, anchor);
childFeature[i] = featureModelEditor.addFeature((String) child[i].getAttribute(FeatureFigure.TEXT));
child[i].setAttribute("id", childFeature[i].getID());
switch (refineType) {
case Decompose:
relation[i] = new DecomposeConnection();
break;
case Attribute:
relation[i] = new AttributeConnection();
break;
case Specialize:
break;
}
relation[i].startPoint(anchor.x, anchor.y);
relation[i].endPoint(anchor.x, anchor.y);
drawingView.add(relation[i]);
relation[i].connectStart(parent.getConnectors()[TextFigure.SOUTH]);
relation[i].connectEnd(child[i].getConnectors()[TextFigure.NORTH]);
relation[i].updateConnection();
switch (refineType) {
case Decompose:
fr[i] = featureModelEditor.addRelation(FeatureRelation.DECOMPOSE, parentFeature, childFeature[i]);
break;
case Attribute:
fr[i] = featureModelEditor.addRelation(FeatureRelation.ATTRIBUTE, parentFeature, childFeature[i]);
break;
}
relation[i].setAttribute("id", fr[i].getID());
//����id��figure��ӳ���
if (idToFigureMap != null) {
idToFigureMap.add(childFeature[i].getID(), child[i]);
idToFigureMap.add(fr[i].getID(), relation[i]);
}
}
for (int i = 0; i < child.length; i++) {
featureEditor.setName(childFeature[i], "Child " + i);
}
} else if (refineType == Refinement.Specialize) {
PLConnection topRelation = new PLConnection();
CFRelation topCFRelation = null;
VPConstraintFigure vp = new VPConstraintFigure();
VPConstraint vpConstraint = null;
int xDis, yDis;
xDis = 80;
yDis = 60;
anchor.translate(0, yDis);
Rectangle parentBounds = parent.getDisplayBox();
Rectangle bounds = vp.getDisplayBox();
vp.moveBy(anchor.x + parentBounds.width / 2 - (bounds.x + bounds.width) / 2, anchor.y - (bounds.y + bounds.height) / 2);
vpConstraint = constraintModelEditor.addVPConstraint();
vp.setAttribute("id", vpConstraint.getID());
drawingView.add(vp);
topRelation.startPoint(anchor.x, anchor.y);
topRelation.endPoint(anchor.x, anchor.y);
drawingView.add(topRelation);
topRelation.connectStart(vp.getStartConnector());
topRelation.connectEnd(parent.getConnectors()[TextFigure.SOUTH]);
topRelation.setAttribute(PLConnection.DISPLAY_MODE, PLConnection.H_V_MODE);
topRelation.updateConnection();
topCFRelation = constraintModelEditor.addCFRelation(parentFeature, vpConstraint, true, CFRModifier.Affirmation);
topRelation.setAttribute("id", topCFRelation.getID());
//����id��figure��ӳ���
if (idToFigureMap != null) {
idToFigureMap.add(vpConstraint.getID(), vp);
idToFigureMap.add(topCFRelation.getID(), topRelation);
}
PLConnection relation[] = new PLConnection[childCount];
CFRelation childCFRelation[] = new CFRelation[childCount];
FeatureFigure child[] = new FeatureFigure[childCount];
Feature childFeature[] = new Feature[childCount];
yDis = 25;
anchor.translate(-(childCount - 1) * xDis / 2 - xDis, yDis);
for (int i = 0; i < child.length; i++) {