Skip to content

Commit 8711d65

Browse files
committed
implemented actions to copy/paste nodes in model editor.
1 parent ac0ef5e commit 8711d65

15 files changed

Lines changed: 161 additions & 24 deletions

src/main/java/com/ss/editor/Messages.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,12 @@ public class Messages {
240240
public static final String MODEL_NODE_TREE_ACTION_ANIMATION_PLAY_SETTINGS;
241241
public static final String MODEL_NODE_TREE_ACTION_ANIMATION_STOP;
242242
public static final String MODEL_NODE_TREE_ACTION_ANIMATION_PAUSE;
243-
public static final String MODEL_NODE_TREE_ACTION_ANIMATION_MANUAL_EXTRAXT_SUB_ANIMATION;
243+
public static final String MODEL_NODE_TREE_ACTION_ANIMATION_MANUAL_EXTRACT_SUB_ANIMATION;
244244
public static final String MODEL_NODE_TREE_ACTION_CREATE_AUDIO_NODE;
245245
public static final String MODEL_NODE_TREE_ACTION_AUDIO_PLAY;
246246
public static final String MODEL_NODE_TREE_ACTION_AUDIO_STOP;
247+
public static final String MODEL_NODE_TREE_ACTION_COPY;
248+
public static final String MODEL_NODE_TREE_ACTION_PASTE;
247249
public static final String MODEL_NODE_TREE_ACTION_CREATE_TONEG0D_PARTICLE_EMITTER;
248250
public static final String MODEL_NODE_TREE_ACTION_CREATE_SOFT_TONEG0D_PARTICLE_EMITTER;
249251
public static final String MODEL_NODE_TREE_ACTION_CREATE_DEFAULT_PARTICLE_EMITTER;
@@ -918,10 +920,12 @@ public class Messages {
918920
MODEL_NODE_TREE_ACTION_ANIMATION_PLAY_SETTINGS = bundle.getString("ModelNodeTreeActionAnimationPlaySettings");
919921
MODEL_NODE_TREE_ACTION_ANIMATION_STOP = bundle.getString("ModelNodeTreeActionAnimationStop");
920922
MODEL_NODE_TREE_ACTION_ANIMATION_PAUSE = bundle.getString("ModelNodeTreeActionAnimationPause");
921-
MODEL_NODE_TREE_ACTION_ANIMATION_MANUAL_EXTRAXT_SUB_ANIMATION = bundle.getString("ModelNodeTreeActionAnimationManualExtractSubAnimation");
923+
MODEL_NODE_TREE_ACTION_ANIMATION_MANUAL_EXTRACT_SUB_ANIMATION = bundle.getString("ModelNodeTreeActionAnimationManualExtractSubAnimation");
922924
MODEL_NODE_TREE_ACTION_CREATE_AUDIO_NODE = bundle.getString("ModelNodeTreeActionCreateAudioNode");
923925
MODEL_NODE_TREE_ACTION_AUDIO_PLAY = bundle.getString("ModelNodeTreeActionAudioPlay");
924926
MODEL_NODE_TREE_ACTION_AUDIO_STOP = bundle.getString("ModelNodeTreeActionAudioStop");
927+
MODEL_NODE_TREE_ACTION_COPY = bundle.getString("ModelNodeTreeActionCopy");
928+
MODEL_NODE_TREE_ACTION_PASTE = bundle.getString("ModelNodeTreeActionPaste");
925929
MODEL_NODE_TREE_ACTION_CREATE_TONEG0D_PARTICLE_EMITTER = bundle.getString("ModelNodeTreeActionCreateToneg0dParticleEmitter");
926930
MODEL_NODE_TREE_ACTION_CREATE_SOFT_TONEG0D_PARTICLE_EMITTER = bundle.getString("ModelNodeTreeActionCreateSoftToneg0dParticleEmitter");
927931
MODEL_NODE_TREE_ACTION_CREATE_DEFAULT_PARTICLE_EMITTER = bundle.getString("ModelNodeTreeActionCreateDefaultParticleEmitter");

src/main/java/com/ss/editor/ui/control/layer/node/SceneLayerTreeNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public boolean hasChildren(@NotNull final NodeTree<?> nodeTree) {
8888

8989
@Override
9090
@FXThread
91-
public boolean canAccept(@NotNull final TreeNode<?> child, final boolean isCopy) {
92-
final Object element = child.getElement();
91+
public boolean canAccept(@NotNull final TreeNode<?> treeNode, final boolean isCopy) {
92+
final Object element = treeNode.getElement();
9393
return element instanceof Spatial && SceneLayer.getLayer((Spatial) element) != getElement();
9494
}
9595

src/main/java/com/ss/editor/ui/control/model/node/spatial/GeometryTreeNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ public void add(@NotNull final TreeNode<?> child) {
7878
}
7979

8080
@Override
81-
public boolean canAccept(@NotNull final TreeNode<?> child, final boolean isCopy) {
82-
final Object element = child.getElement();
83-
return (element instanceof Material && isCopy) || super.canAccept(child, isCopy);
81+
public boolean canAccept(@NotNull final TreeNode<?> treeNode, final boolean isCopy) {
82+
final Object element = treeNode.getElement();
83+
return (element instanceof Material && isCopy) || super.canAccept(treeNode, isCopy);
8484
}
8585

8686
@Override

src/main/java/com/ss/editor/ui/control/model/node/spatial/NodeTreeNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,16 @@ public boolean hasChildren(@NotNull final NodeTree<?> nodeTree) {
146146
}
147147

148148
@Override
149-
public boolean canAccept(@NotNull final TreeNode<?> child, final boolean isCopy) {
150-
if (child == this) return false;
149+
public boolean canAccept(@NotNull final TreeNode<?> treeNode, final boolean isCopy) {
150+
if (treeNode == this) return false;
151151

152-
final Object element = child.getElement();
152+
final Object element = treeNode.getElement();
153153

154154
if (element instanceof Spatial) {
155155
return GeomUtils.canAttach(getElement(), (Spatial) element, isCopy);
156156
}
157157

158-
return super.canAccept(child, isCopy);
158+
return super.canAccept(treeNode, isCopy);
159159
}
160160

161161
@Override

src/main/java/com/ss/editor/ui/control/model/node/spatial/SpatialTreeNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ public boolean canCopy() {
101101

102102
@Override
103103
@FXThread
104-
public boolean canAccept(@NotNull final TreeNode<?> child, final boolean isCopy) {
105-
final Object element = child.getElement();
106-
return element instanceof AbstractControl || super.canAccept(child, isCopy);
104+
public boolean canAccept(@NotNull final TreeNode<?> treeNode, final boolean isCopy) {
105+
final Object element = treeNode.getElement();
106+
return element instanceof AbstractControl || super.canAccept(treeNode, isCopy);
107107
}
108108

109109
@Override

src/main/java/com/ss/editor/ui/control/model/node/spatial/scene/SceneNodeTreeNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public boolean canMove() {
5555
}
5656

5757
@Override
58-
public boolean canAccept(@NotNull final TreeNode<?> child, final boolean isCopy) {
58+
public boolean canAccept(@NotNull final TreeNode<?> treeNode, final boolean isCopy) {
5959
return false;
6060
}
6161

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.ss.editor.ui.control.model.tree.action;
2+
3+
import static com.ss.editor.ui.control.tree.NodeTreeCell.DATA_FORMAT;
4+
import com.ss.editor.Messages;
5+
import com.ss.editor.annotation.FXThread;
6+
import com.ss.editor.model.undo.editor.ModelChangeConsumer;
7+
import com.ss.editor.ui.Icons;
8+
import com.ss.editor.ui.control.tree.NodeTree;
9+
import com.ss.editor.ui.control.tree.action.AbstractNodeAction;
10+
import com.ss.editor.ui.control.tree.node.TreeNode;
11+
import javafx.scene.image.Image;
12+
import javafx.scene.input.Clipboard;
13+
import javafx.scene.input.ClipboardContent;
14+
import org.jetbrains.annotations.NotNull;
15+
import org.jetbrains.annotations.Nullable;
16+
17+
/**
18+
* The action to copy a node in model.
19+
*
20+
* @author JavaSaBr
21+
*/
22+
public class CopyNodeAction extends AbstractNodeAction<ModelChangeConsumer> {
23+
24+
public CopyNodeAction(@NotNull final NodeTree<?> nodeTree, @NotNull final TreeNode<?> node) {
25+
super(nodeTree, node);
26+
}
27+
28+
@Override
29+
@FXThread
30+
protected @NotNull String getName() {
31+
return Messages.MODEL_NODE_TREE_ACTION_COPY;
32+
}
33+
34+
@Override
35+
@FXThread
36+
protected @Nullable Image getIcon() {
37+
return Icons.COPY_16;
38+
}
39+
40+
@Override
41+
@FXThread
42+
protected void process() {
43+
super.process();
44+
45+
final TreeNode<?> node = getNode();
46+
47+
final ClipboardContent content = new ClipboardContent();
48+
content.put(DATA_FORMAT, node.getObjectId());
49+
50+
final Clipboard clipboard = Clipboard.getSystemClipboard();
51+
clipboard.setContent(content);
52+
}
53+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.ss.editor.ui.control.model.tree.action;
2+
3+
import static com.ss.rlib.util.ObjectUtils.notNull;
4+
import com.ss.editor.Messages;
5+
import com.ss.editor.annotation.FXThread;
6+
import com.ss.editor.model.undo.editor.ModelChangeConsumer;
7+
import com.ss.editor.ui.Icons;
8+
import com.ss.editor.ui.control.tree.NodeTree;
9+
import com.ss.editor.ui.control.tree.action.AbstractNodeAction;
10+
import com.ss.editor.ui.control.tree.node.TreeNode;
11+
import javafx.scene.image.Image;
12+
import org.jetbrains.annotations.NotNull;
13+
import org.jetbrains.annotations.Nullable;
14+
15+
/**
16+
* The action to paste a node in model.
17+
*
18+
* @author JavaSaBr
19+
*/
20+
public class PasteNodeAction extends AbstractNodeAction<ModelChangeConsumer> {
21+
22+
/**
23+
* The copied node.
24+
*/
25+
@NotNull
26+
private final TreeNode<?> copiedNode;
27+
28+
public PasteNodeAction(@NotNull final NodeTree<?> nodeTree, @NotNull final TreeNode<?> node,
29+
@NotNull final TreeNode<?> copiedNode) {
30+
super(nodeTree, node);
31+
this.copiedNode = copiedNode;
32+
}
33+
34+
@Override
35+
@FXThread
36+
protected @NotNull String getName() {
37+
return Messages.MODEL_NODE_TREE_ACTION_PASTE;
38+
}
39+
40+
@Override
41+
@FXThread
42+
protected @Nullable Image getIcon() {
43+
return Icons.PASTE_16;
44+
}
45+
46+
@Override
47+
@FXThread
48+
protected void process() {
49+
super.process();
50+
51+
final ModelChangeConsumer changeConsumer = notNull(getNodeTree().getChangeConsumer());
52+
53+
final TreeNode<?> node = getNode();
54+
node.accept(changeConsumer, copiedNode.getElement(), true);
55+
}
56+
}

src/main/java/com/ss/editor/ui/control/model/tree/action/animation/ManualExtractSubAnimationAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public ManualExtractSubAnimationAction(@NotNull final NodeTree<?> nodeTree, @Not
2727
@Override
2828
@FXThread
2929
protected @NotNull String getName() {
30-
return Messages.MODEL_NODE_TREE_ACTION_ANIMATION_MANUAL_EXTRAXT_SUB_ANIMATION;
30+
return Messages.MODEL_NODE_TREE_ACTION_ANIMATION_MANUAL_EXTRACT_SUB_ANIMATION;
3131
}
3232

3333
@Override

src/main/java/com/ss/editor/ui/control/tree/NodeTreeCell.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
*/
4040
public class NodeTreeCell<C extends ChangeConsumer, M extends NodeTree<C>> extends TextFieldTreeCell<TreeNode<?>> {
4141

42+
@NotNull
43+
public static final DataFormat DATA_FORMAT = new DataFormat(NodeTreeCell.class.getName());
44+
4245
@NotNull
4346
private static final PseudoClass DROP_AVAILABLE_PSEUDO_CLASS = PseudoClass.getPseudoClass("drop-available");
4447

@@ -51,9 +54,6 @@ public class NodeTreeCell<C extends ChangeConsumer, M extends NodeTree<C>> exten
5154
@NotNull
5255
private static final ExecutorManager EXECUTOR_MANAGER = ExecutorManager.getInstance();
5356

54-
@NotNull
55-
private static final DataFormat DATA_FORMAT = new DataFormat(NodeTreeCell.class.getName());
56-
5757
@NotNull
5858
private final StringConverter<TreeNode<?>> stringConverter = new StringConverter<TreeNode<?>>() {
5959

0 commit comments

Comments
 (0)