use of com.cburch.draw.util.MatchingSet in project logisim-evolution by reds-heig.
the class AppearanceEditHandler method paste.
@Override
public void paste() {
ClipboardContents clip = Clipboard.get();
Collection<CanvasObject> contents = clip.getElements();
List<CanvasObject> add = new ArrayList<CanvasObject>(contents.size());
for (CanvasObject o : contents) {
add.add(o.clone());
}
if (add.isEmpty())
return;
// find how far we have to translate shapes so that at least one of the
// pasted shapes doesn't match what's already in the model
Collection<CanvasObject> raw = canvas.getModel().getObjectsFromBottom();
MatchingSet<CanvasObject> cur = new MatchingSet<CanvasObject>(raw);
int dx = 0;
while (true) {
// if any shapes in "add" aren't in canvas, we are done
boolean allMatch = true;
for (CanvasObject o : add) {
if (!cur.contains(o)) {
allMatch = false;
break;
}
}
if (!allMatch)
break;
// otherwise translate everything by 10 pixels and repeat test
for (CanvasObject o : add) {
o.translate(10, 10);
}
dx += 10;
}
Location anchorLocation = clip.getAnchorLocation();
if (anchorLocation != null && dx != 0) {
anchorLocation = anchorLocation.translate(dx, dx);
}
canvas.getProject().doAction(new SelectionAction(canvas, Strings.getter("pasteClipboardAction"), null, add, add, anchorLocation, clip.getAnchorFacing()));
}
Aggregations