Skip to content
Snippets Groups Projects
Commit 30efac59 authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Refactor pad clone method to custom copy method

parent cce05314
Branches
Tags
No related merge requests found
package de.tobias.playpad.pad.drag;
import de.thecodelabs.logger.Logger;
import de.tobias.playpad.pad.Pad;
import de.tobias.playpad.project.Project;
import de.tobias.playpad.project.page.PadIndex;
......@@ -16,15 +15,10 @@ public class DuplicateDragMode extends PadDragMode {
Pad oldPad = project.getPad(oldIndex);
Pad newPad = project.getPad(newIndex);
try {
Pad copyPad = oldPad.clone(oldPad.getPage());
Pad copyPad = oldPad.copy(oldPad.getPage());
project.removePad(newPad.getUuid());
project.setPad(newIndex, copyPad);
return true;
} catch (CloneNotSupportedException e) {
Logger.error(e);
}
return false;
}
}
\ No newline at end of file
......@@ -12,7 +12,7 @@ import javafx.scene.paint.Color;
import java.util.UUID;
public class ModernCartDesign implements FeedbackDesignColorSuggester, Cloneable {
public class ModernCartDesign implements FeedbackDesignColorSuggester {
private UUID uuid;
private ObjectProperty<ModernColor> backgroundColor;
......@@ -111,8 +111,8 @@ public class ModernCartDesign implements FeedbackDesignColorSuggester, Cloneable
return Color.web(backgroundColor.get().getColorHi());
}
public ModernCartDesign clone(Pad pad) throws CloneNotSupportedException {
ModernCartDesign clone = (ModernCartDesign) super.clone();
public ModernCartDesign copy(Pad pad) {
ModernCartDesign clone = new ModernCartDesign(pad);
clone.backgroundColor = new SimpleObjectProperty<>(getBackgroundColor());
clone.playColor = new SimpleObjectProperty<>(getPlayColor());
......
......@@ -40,7 +40,7 @@ import java.util.UUID;
* @author tobias
* @version 6.2.0
*/
public class Pad implements Cloneable {
public class Pad {
private UUID uuid;
private IntegerProperty positionProperty = new SimpleIntegerProperty();
......@@ -608,16 +608,19 @@ public class Pad implements Cloneable {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!(o instanceof Pad)) return false;
Pad pad = (Pad) o;
return Objects.equals(uuid, pad.uuid);
}
@Override
public int hashCode() {
return Objects.hash(uuid);
}
// Clone
public Pad clone(Page page) throws CloneNotSupportedException {
Pad clone = (Pad) super.clone();
public Pad copy(Page page) {
Pad clone = new Pad(project);
clone.uuid = UUID.randomUUID();
clone.positionProperty = new SimpleIntegerProperty(getPosition());
......@@ -629,16 +632,16 @@ public class Pad implements Cloneable {
clone.mediaPaths = FXCollections.observableArrayList();
for (MediaPath path : mediaPaths) {
MediaPath clonedPath = path.clone(clone);
MediaPath clonedPath = path.copy(clone);
clone.mediaPaths.add(clonedPath);
}
clone.contentTypeProperty = new SimpleStringProperty(getContentType());
clone.contentProperty = new SimpleObjectProperty<>();
if (getContent() != null) {
clone.contentProperty = new SimpleObjectProperty<>(getContent().clone());
clone.contentProperty.set(getContent().copy(clone));
clone.getContent().setPad(clone);
} else {
clone.contentProperty = new SimpleObjectProperty<>();
clone.getContent().loadMedia();
}
if (project.getProjectReference().isSync()) {
......@@ -647,7 +650,7 @@ public class Pad implements Cloneable {
clone.addSyncListener();
}
clone.padSettings = padSettings.clone();
clone.padSettings = padSettings.copy(clone);
clone.controller = null;
clone.project = project;
......
......@@ -19,7 +19,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class PadSettings implements Cloneable {
public class PadSettings {
// Pad Reference
private Pad pad;
......@@ -249,9 +249,8 @@ public class PadSettings implements Cloneable {
return false;
}
@Override
public PadSettings clone() throws CloneNotSupportedException {
PadSettings clone = (PadSettings) super.clone();
public PadSettings copy(Pad pad) {
PadSettings clone = new PadSettings(pad);
clone.id = UUID.randomUUID();
clone.volumeProperty = new SimpleDoubleProperty(getVolume());
......@@ -274,7 +273,7 @@ public class PadSettings implements Cloneable {
clone.customDesignProperty = new SimpleBooleanProperty(isCustomDesign());
if (design != null) {
clone.design = design.clone(pad);
clone.design = design.copy(pad);
}
clone.triggers = new EnumMap<>(TriggerPoint.class); // TODO Trigger werden nicht Kopiert
......
package de.tobias.playpad.pad.content;
import de.tobias.playpad.PlayPadPlugin;
import de.tobias.playpad.pad.Pad;
import de.tobias.playpad.pad.mediapath.MediaPath;
......@@ -10,7 +11,7 @@ import de.tobias.playpad.pad.mediapath.MediaPath;
* @version 5.1.0
* @see Pad
*/
public abstract class PadContent implements Cloneable {
public abstract class PadContent {
// reference
private Pad pad;
......@@ -69,12 +70,9 @@ public abstract class PadContent implements Cloneable {
@Override
protected void finalize() throws Throwable {
unloadMedia();
this.pad = null;
}
@Override
public PadContent clone() throws CloneNotSupportedException {
return (PadContent) super.clone();
public PadContent copy(Pad pad) {
return PlayPadPlugin.getRegistries().getPadContents().getFactory(getType()).newInstance(pad);
}
}
\ No newline at end of file
......@@ -17,7 +17,7 @@ import java.util.UUID;
/**
* Created by tobias on 21.02.17.
*/
public class MediaPath implements Cloneable {
public class MediaPath {
private UUID id;
private StringProperty fileName;
......@@ -105,12 +105,8 @@ public class MediaPath implements Cloneable {
return original;
}
public MediaPath clone(Pad pad) throws CloneNotSupportedException {
MediaPath clone = (MediaPath) super.clone();
clone.id = UUID.randomUUID();
clone.fileName = new SimpleStringProperty(fileName.get());
clone.pad = pad;
public MediaPath copy(Pad pad) {
MediaPath clone = new MediaPath(UUID.randomUUID(), fileName.get(), pad);
MediaPool.getInstance().create(clone, this.getPath());
if (pad.getProject().getProjectReference().isSync()) {
......
......@@ -264,7 +264,7 @@ public class Page implements Cloneable {
clone.pads = new HashSet<>();
for (Pad pad : pads) {
Pad padClone = pad.clone(clone);
Pad padClone = pad.copy(clone);
clone.pads.add(padClone);
}
return clone;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment