JmodelStationDefinition sd = mediator.getStationDefinition();
JGraph graph = mediator.getGraph();
Object cells[] = graph.getDescendants(graph.getSelectionCells());
// Temp variables
Object key; // Station key
JmtEdge edgetmp;
JmtCell celltmp;
Point2D location; // position of a station
// Saves into data structure selected stations (including position) and links
for (Object cell : cells) {
if (cell instanceof JmtCell) {
celltmp = (JmtCell) cell;
key = ((CellComponent) celltmp.getUserObject()).getKey();
stations.put(key, sd.serializeStation(key));
location = mediator.getCellCoordinates(celltmp);
stationpositions.put(key, location);
// Initialize 'zero' as the upper-leftmost point of selected stations
// Will be used as a bias while pasting
if (zero == null) {
zero = location;
}
if (zero.getX() > location.getX()) {
zero = new Point2D.Double(location.getX(), zero.getY());
}
if (zero.getY() > location.getY()) {
zero = new Point2D.Double(zero.getX(), location.getY());
}
} else if (cell instanceof JmtEdge) {
edgetmp = (JmtEdge) cell;
links.add(new Connection(edgetmp.getSourceKey(), edgetmp.getTargetKey()));
}
}
}