From 3364b29189caa6b476afe23290600f598346d2f2 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 18 Aug 2022 00:57:33 +0200 Subject: [PATCH] Clean up code --- .../sf/openrocket/gui/main/RocketActions.java | 39 ++++++------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/main/RocketActions.java b/swing/src/net/sf/openrocket/gui/main/RocketActions.java index 7c768b1a1..987cb0d3c 100644 --- a/swing/src/net/sf/openrocket/gui/main/RocketActions.java +++ b/swing/src/net/sf/openrocket/gui/main/RocketActions.java @@ -418,35 +418,22 @@ public class RocketActions { * should be pasted. Returns null if the clipboard is empty or if the * clipboard cannot be pasted to the current selection. * - * @param copyComponent the component to be copy-pasted. - * @param pasteComponent the component where copyComponent should be pasted to. + * @param srcComponent the component to be copy-pasted. + * @param destComponent the component where srcComponent should be pasted to. * @return a Pair with both components defined, or null. */ - private Pair getPastePosition(RocketComponent copyComponent, RocketComponent pasteComponent) { - if (pasteComponent == null) + private Pair getPastePosition(RocketComponent srcComponent, RocketComponent destComponent) { + if (destComponent == null) return null; - if (copyComponent == null) + if (srcComponent == null) return null; - if (pasteComponent.isCompatible(copyComponent)) - return new Pair(pasteComponent, pasteComponent.getChildCount()); + if (destComponent.isCompatible(srcComponent)) + return new Pair(destComponent, destComponent.getChildCount()); - RocketComponent parent = pasteComponent.getParent(); - return getPastePositionFromParent(copyComponent, parent); - } - - /** - * Return the component and position to which the current clipboard - * should be pasted. Returns null if the clipboard is empty or if the - * clipboard cannot be pasted to the current selection. - * - * @param copyComponent the component to be copy-pasted. - * @return a Pair with both components defined, or null. - */ - private Pair getPastePosition(RocketComponent copyComponent) { - RocketComponent selected = selectionModel.getSelectedComponent(); - return getPastePosition(copyComponent, selected); + RocketComponent parent = destComponent.getParent(); + return getPastePositionFromParent(srcComponent, parent); } private Pair getPastePositionFromParent(RocketComponent component, RocketComponent parent) { @@ -468,8 +455,9 @@ public class RocketActions { */ private List> getPastePositions(List clipboard) { List> result = new LinkedList<>(); + RocketComponent selected = selectionModel.getSelectedComponent(); for (RocketComponent component : clipboard) { - Pair position = getPastePosition(component); + Pair position = getPastePosition(component, selected); if (position != null) { result.add(position); } @@ -775,10 +763,7 @@ public class RocketActions { pasted.add(component.copy()); } - List> positions = new LinkedList<>(); - for (RocketComponent component : pasted) { - positions.add(getPastePosition(component)); - } + List> positions = getPastePositions(pasted); if (pasted.size() == 1) { document.addUndoPosition("Paste " + pasted.get(0).getComponentName());