/* delta for Position */
int deltaX = 20, deltaY = 20;
/* insert elements */
CreationMap sourceMap, tempMap = null, currentArcMap;
HashMap<String, Object> correctedSourceId = new HashMap<String, Object>();
HashMap<String, Object> correctedTargetId = new HashMap<String, Object>();
Point currentPosition;
Point middleOfSelection = null;
AbstractPetriNetElementModel tempElement;
String oldElementId;
Vector<Object> toSelectElements = new Vector<Object>();
Iterator<String> eleIter = pasteElements.keySet().iterator();
boolean originalName = true;
String originalNameStr = null;
while (eleIter.hasNext()) {
sourceMap = pasteElements.get(eleIter.next());
tempMap = (CreationMap) sourceMap.clone();
// position for element
currentPosition = sourceMap.getPosition();
// set new delta values if a mouse position is given
if (points.length > 0 && middleOfSelection == null) {
middleOfSelection = getMiddleOfSelection(pasteElements);
deltaX = (int) points[0].getX() - middleOfSelection.x
- tempMap.getSize().getX1() / 2;
deltaY = (int) points[0].getY() - middleOfSelection.y
- tempMap.getSize().getX2() / 2;
}
// set new position
tempMap.setPosition(currentPosition.x + deltaX, currentPosition.y
+ deltaY);
// position for name
currentPosition = (Point) sourceMap.getNamePosition().clone();
tempMap.setNamePosition(currentPosition.x + deltaX,
currentPosition.y + deltaY);
// position for trigger
if ((currentPosition = sourceMap.getTriggerPosition()) != null) {
tempMap.setTriggerPosition(currentPosition.x + deltaX,
currentPosition.y + deltaY);
}
// copy in another frame than the source frame
if (this != m_clipboard.getM_sourceEditor()) {
// determine middle of selected elements
if (middleOfSelection == null) {
middleOfSelection = getMiddleOfSelection(pasteElements);
}
// position for element
if (points.length > 0) {
currentPosition = new Point(
(int) (((int) points[0].getX() / 2)
- tempMap.getSize().getX1() / 2
+ tempMap.getPosition().getX() - middleOfSelection.x),
(int) (((int) points[0].getY() / 2)
- tempMap.getSize().getX2() / 2
+ tempMap.getPosition().getY() - middleOfSelection.y));
} else {
currentPosition = new Point(
(int) ((getEditorPanel().getWidth() / 2) - tempMap.getSize().getX1()
/ 2 + tempMap.getPosition().getX() - middleOfSelection.x),
(int) ((getEditorPanel().getHeight() / 2)
- tempMap.getSize().getX2() / 2
+ tempMap.getPosition().getY() - middleOfSelection.y));
}
tempMap.setPosition(currentPosition.x, currentPosition.y);
// position for name
if (isRotateSelected()) {
tempMap.setNamePosition(currentPosition.x
+ tempMap.getSize().getX1(), currentPosition.y - 1);
} else {
tempMap.setNamePosition(currentPosition.x - 1,
currentPosition.y + tempMap.getSize().getX2());
}
if (isRotateSelected()) {
tempMap.setTriggerPosition(currentPosition.x - 20,
currentPosition.y + 7);
} else {
tempMap.setTriggerPosition(currentPosition.x + 7,
currentPosition.y - 20);
}
}
// keep the sourceMapID
oldElementId = sourceMap.getId();
originalNameStr = sourceMap.getName();
originalName = isOriginalName(originalNameStr, oldElementId);
tempMap.setEditOnCreation(false);
tempMap.setReadOnly(false);
// set ID to null, to get new ID
tempMap.setId(null);
// get tempGroupModel with new ID
GroupModel tempGroupModel = (GroupModel) (create(tempMap));
// get form the group an AbstractElementModel (extends GraphCell)
tempElement = tempGroupModel.getMainElement();
// check if tempElement TransitionModel (PetriNetModelElement)
if (tempElement instanceof TransitionModel) {
// GroupModel currentTrans = (GroupModel) (create(currentMap));
// new element exactly transitionModel
TransitionModel tempTrans = (TransitionModel) tempElement;
// copy time
if ((sourceMap.getTransitionTime() != -1)
&& (sourceMap.getTransitionTimeUnit() != -1)) {
tempTrans.getToolSpecific().setTime(
sourceMap.getTransitionTime());
tempTrans.getToolSpecific().setTimeUnit(
sourceMap.getTransitionTimeUnit());
}
// copy trigger model
CreationMap map = tempTrans.getCreationMap();
if (sourceMap.getTriggerType() != -1) {
if (map != null) {
map.setTriggerType(sourceMap.getTriggerType());
createTriggerForPaste(map, tempTrans);
Point p = tempTrans.getPosition();
// Why deleteCell?
// deleteCell(tempTrans.getToolSpecific().getTrigger(),
// true);
map.setTriggerPosition(p.x, p.y);
// copy resource model
if ((sourceMap.getResourceOrgUnit() != null)
&& sourceMap.getResourceRole() != null) {
map.setResourceOrgUnit(sourceMap
.getResourceOrgUnit());
map.setResourceRole(sourceMap.getResourceRole());
}
}
} else
map.setType(1);
}
/* change arc source/target */
Iterator<String> arcIter = pasteArcs.keySet().iterator();
while (arcIter.hasNext()) {
currentArcMap = pasteArcs.get(arcIter.next());
if ((this.getEditorPanel().getContainer().getActionMap()
.get(currentArcMap.getArcSourceId()) != null)
|| ((currentArcMap.getArcSourceId()
.equals(oldElementId)) && (!correctedSourceId
.containsKey(currentArcMap.getArcId())))) {
currentArcMap.setArcSourceId(tempElement.getId());
correctedSourceId.put(currentArcMap.getArcId(), null);
}
if ((currentArcMap.getArcTargetId().equals(oldElementId))
&& (!correctedTargetId.containsKey(currentArcMap
.getArcId()))) {
currentArcMap.setArcTargetId(tempElement.getId());
correctedTargetId.put(currentArcMap.getArcId(), null);
}
}
/* */
if (originalName)
tempElement.setNameValue(tempElement.getId());
else
tempElement.setNameValue(originalNameStr);
toSelectElements.add(tempElement.getParent());
}
/* insert arcs */
Iterator<String> arcIter = pasteArcs.keySet().iterator();
ArcModel tempArc;
Point2D point;
CreationMap cmap = CreationMap.createMap();
while (arcIter.hasNext()) {
currentArcMap = pasteArcs.get(arcIter.next());
if ((currentArcMap.getArcSourceId() != null)
&& (currentArcMap.getArcTargetId()) != null) {
cmap.setArcSourceId(currentArcMap.getArcSourceId());
cmap.setArcTargetId(currentArcMap.getArcTargetId());
tempArc = createArc(cmap, true);
// It is possible that an arc could not be created, because either its source
// or target element are missing. Simply ignore the arc in this case
if (tempArc == null)