if (selection[i] instanceof Figure) {
Object userObject = ((Figure) selection[i]).getUserObject();
if (graphModel.isEdge(userObject)
|| graphModel.isNode(userObject)) {
NamedObj actual = (NamedObj) graphModel
.getSemanticObject(userObject);
if (actual != null) {
namedObjSet.add(actual);
} else {
// Special case, may need to handle by not going to
// MoML and which may not be undoable.
// FIXME: This is no way to handle it...
System.out
.println("Object with no semantic object , class: "
+ userObject.getClass().getName());
}
}
}
}
// Generate the MoML to carry out move.
// Note that the location has already been set by the mouseMoved()
// call, but we need to do this so that the undo is generated and
// so that the change propagates.
// The toplevel is the container being edited.
final NamedObj toplevel = (NamedObj) graphModel.getRoot();
StringBuffer moml = new StringBuffer();
StringBuffer undoMoml = new StringBuffer();
moml.append("<group>\n");
undoMoml.append("<group>\n");
Iterator elements = namedObjSet.iterator();
while (elements.hasNext()) {
NamedObj element = (NamedObj) elements.next();
List locationList = element.attributeList(Locatable.class);
if (locationList.isEmpty()) {
// Nothing to do as there was no previous location
// attribute (applies to "unseen" relations)
continue;
}
// Set the new location attribute.
Locatable locatable = (Locatable) locationList.get(0);
// Give default values in case the previous locations value
// has not yet been set
double[] newLocation = new double[] { 0, 0 };
if (locatable.getLocation() != null) {
newLocation = locatable.getLocation();
}
// NOTE: we use the transform worked out for the drag to
// set the original MoML location
double[] oldLocation = new double[2];
oldLocation[0] = newLocation[0] + transform[0];
oldLocation[1] = newLocation[1] + transform[1];
// Create the MoML, wrapping the new location attribute
// in an element refering to the container
String containingElementName = element.getElementName();
String elementToMove = "<" + containingElementName + " name=\""
+ element.getName() + "\" >\n";
moml.append(elementToMove);
undoMoml.append(elementToMove);
// NOTE: use the moml info element name here in case the
// location is a vertex