From f6dfb1131950a50731fd6921dc53cfb37ba8a9ea Mon Sep 17 00:00:00 2001
From: tobias <tobias.ullerich@icloud.com>
Date: Fri, 23 Sep 2016 21:15:47 +0200
Subject: [PATCH] Bug fixes & tood

- Drag and Drop Bug, when same pad id and different page id
- add menu for page mode
- Code Cleanup
---
 .../tobias/playpad/assets/lang/_de.properties |   1 +
 .../playpad/assets/lang/ui_de.properties      |   5 +-
 .../assets/view/main/desktop/header.fxml      |  11 +-
 PlayWall/src/de/tobias/playpad/Strings.java   |  10 +-
 .../src/de/tobias/playpad/components/Keys.xml |  14 ++-
 .../DesktopMenuToolbarViewController.java     |  22 +++-
 .../desktop/DesktopPageEditButtonView.java    |   1 -
 .../desktop/pad/DesktopPadDragListener.java   | 116 ++++++++++--------
 .../layout/desktop/pad/DesktopPadView.java    |   2 +-
 .../playpad/layout/touch/TouchPadView.java    |   2 +-
 .../tobias/playpad/pad/drag/MoveDragMode.java |  10 +-
 .../playpad/pad/drag/ReplaceDragMode.java     |   8 +-
 .../pad/listener/PadContentListener.java      |   2 +-
 .../tobias/playpad/pad/drag/PadDragMode.java  |  13 +-
 .../de/tobias/playpad/pad/view/IPadView.java  |   2 +-
 .../de/tobias/playpad/project/Project.java    |  17 +--
 .../de/tobias/playpad/project/page/Page.java  |  12 +-
 .../awakeplugin/impl/AwakePluginImpl.java     |   6 +-
 18 files changed, 160 insertions(+), 94 deletions(-)

diff --git a/PlayWall/assets/de/tobias/playpad/assets/lang/_de.properties b/PlayWall/assets/de/tobias/playpad/assets/lang/_de.properties
index 7cda7194..40f14b9c 100644
--- a/PlayWall/assets/de/tobias/playpad/assets/lang/_de.properties
+++ b/PlayWall/assets/de/tobias/playpad/assets/lang/_de.properties
@@ -147,6 +147,7 @@ Error.Project.Rename=Das Projekt konnte nicht umbenannt werden. ({})
 Error.Project.Delete=Das Projekt konnte nicht gel�scht werden. ({})
 Error.Project.Export=Das Projekt {} konnte nicht exportiert werden. ({})
 Error.Project.MediaPath=Der neue Ordner darf kein Unterodner des alten Medienordners sein.
+Error.Project.PageCount=Sie k�nnen keine weiteren Seiten hinzuf�gen. \nSie haben Limit erreicht.
 
 # Error - Pad - Enum
 Error.Pad.FILE_NOT_FOUND=Die Datei {} konnte nicht gefunden werden.
diff --git a/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties b/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties
index f3b3b638..31a6d530 100644
--- a/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties
+++ b/PlayWall/assets/de/tobias/playpad/assets/lang/ui_de.properties
@@ -19,7 +19,8 @@ main.menuitem.onTop=Fenster im Vordergrund
 main.menu.editmode=Modus
 main.menuitem.play=Wiedergabe
 main.menuitem.drag=Drag and Drop
-main.menuitem.color=F�rben
+main.menuitem.page=Seiten bearbeiten
+main.menuitem.color=Farben bearbeiten
 #Ende TODO
 main.menuitem.errors=Fehlerbericht anzeigen...
 main.menuitem.plugins=Erweiterungen...
@@ -45,7 +46,7 @@ settings.gen.label.liveMode.settings=Einstellungen 
 settings.gen.label.liveMode.media=Mediadateien �ndern:
 settings.gen.label.liveMode.dragPads=Kacheln verschieben:
 settings.gen.label.liveMode.pageChange=Seite wechseln:
-settings.gen.radio.liveMode.enable=Deaktivieren
+settings.gen.radio.liveMode.enable=Verbieten
 settings.gen.radio.liveMode.disable=Erlauben
 settings.gen.label.liveModeInfo=Der Live Modus verhindet ungewollte Aktionen w�hrend der Wiedergabe einer Kachel.
 settings.gen.warning.button.reset=Hinweismeldungen zur�cksetzen
diff --git a/PlayWall/assets/de/tobias/playpad/assets/view/main/desktop/header.fxml b/PlayWall/assets/de/tobias/playpad/assets/view/main/desktop/header.fxml
index 05ebf66e..7cb4ef9a 100644
--- a/PlayWall/assets/de/tobias/playpad/assets/view/main/desktop/header.fxml
+++ b/PlayWall/assets/de/tobias/playpad/assets/view/main/desktop/header.fxml
@@ -43,19 +43,24 @@
                      <items>
                         <MenuItem fx:id="playMenu" mnemonicParsing="false" onAction="#playMenuHandler" text="%main.menuitem.play">
                            <accelerator>
-                              <KeyCodeCombination alt="UP" code="L" control="UP" meta="UP" shift="UP" shortcut="DOWN" />
+                              <KeyCodeCombination alt="UP" code="H" control="UP" meta="UP" shift="UP" shortcut="DOWN" />
                            </accelerator>
                         </MenuItem>
                         <MenuItem fx:id="dragMenu" mnemonicParsing="false" onAction="#dragMenuHandler" text="%main.menuitem.drag">
                            <accelerator>
-                              <KeyCodeCombination alt="UP" code="M" control="UP" meta="UP" shift="UP" shortcut="DOWN" />
+                              <KeyCodeCombination alt="UP" code="J" control="UP" meta="UP" shift="UP" shortcut="DOWN" />
                            </accelerator>
                         </MenuItem>
-                        <MenuItem fx:id="colorMenu" mnemonicParsing="false" onAction="#colorMenuHandler" text="%main.menuitem.color">
+                        <MenuItem fx:id="pageMenu" mnemonicParsing="false" text="%main.menuitem.page">
                            <accelerator>
                               <KeyCodeCombination alt="UP" code="K" control="UP" meta="UP" shift="UP" shortcut="DOWN" />
                            </accelerator>
                         </MenuItem>
+                        <MenuItem fx:id="colorMenu" mnemonicParsing="false" onAction="#colorMenuHandler" text="%main.menuitem.color">
+                           <accelerator>
+                              <KeyCodeCombination alt="UP" code="L" control="UP" meta="UP" shift="UP" shortcut="DOWN" />
+                           </accelerator>
+                        </MenuItem>
                      </items>
                   </Menu>
                   <SeparatorMenuItem mnemonicParsing="false" />
diff --git a/PlayWall/src/de/tobias/playpad/Strings.java b/PlayWall/src/de/tobias/playpad/Strings.java
index 2db02c1e..0686a4d0 100644
--- a/PlayWall/src/de/tobias/playpad/Strings.java
+++ b/PlayWall/src/de/tobias/playpad/Strings.java
@@ -46,8 +46,7 @@ public class Strings {
 
 	// UI - Window - Main
 	public static final String UI_Window_Main_CloseRequest = "UI.Window.Main.CloseRequest";
-	@Deprecated
-	public static final String UI_Window_Main_SaveRequest = "UI.Window.Main.SaveRequest";
+	@Deprecated public static final String UI_Window_Main_SaveRequest = "UI.Window.Main.SaveRequest";
 	public static final String UI_Window_Main_PageButton = "UI.Window.Main.PageButton";
 
 	// UI - Dialog - Launch
@@ -145,6 +144,7 @@ public class Strings {
 	public static final String Error_Project_Delete = "Error.Project.Delete";
 	public static final String Error_Project_Export = "Error.Project.Export";
 	public static final String Error_Project_MediaPath = "Error.Project.MediaPath";
+	public static final String Error_Project_PageCount = "Error.Project.PageCount";
 
 	// Error - Pad
 	public static final String Error_Pad_BaseName = "Error.Pad.";
@@ -257,15 +257,15 @@ public class Strings {
 	public static final String Search_Button = "Search.Button";
 	public static final String Search_Placeholder = "Search.Placeholder";
 	public static final String Search_Alert_NoMatches = "Search.Alert.NoMatches";
-	
+
 	// UI - Dialog - Page - Delete
 	public static final String UI_Dialog_Page_Delete_Header = "UI.Dialog.Page.Delete.Header";
 	public static final String UI_Dialog_Page_Delete_Content = "UI.Dialog.Page.Delete.Content";
-	
+
 	// UI - Dialog - Page - Name
 	public static final String UI_Dialog_Page_Name_Header = "UI.Dialog.Page.Name.Header";
 	public static final String UI_Dialog_Page_Name_Content = "UI.Dialog.Page.Name.Content";
-	
+
 	// Tooltip
 	public static final String Tooltip_PlayButton = "Tooltip.PlayButton";
 	public static final String Tooltip_DragButton = "Tooltip.DragButton";
diff --git a/PlayWall/src/de/tobias/playpad/components/Keys.xml b/PlayWall/src/de/tobias/playpad/components/Keys.xml
index 589d9d4f..11254b52 100644
--- a/PlayWall/src/de/tobias/playpad/components/Keys.xml
+++ b/PlayWall/src/de/tobias/playpad/components/Keys.xml
@@ -6,9 +6,10 @@
 		<Key id="save_proj" name="main.menuitem.save" key="S" ctrl="true" alt="false" meta="false" shift="false"/>
 		<Key id="print_proj" name="main.menuitem.print" key="P" ctrl="true" alt="false" meta="false" shift="false"/>
 		
-		<Key id="play" name="main.menuitem.play" key="L" ctrl="true" alt="false" meta="false" shift="false"/>
-		<Key id="drag" name="main.menuitem.drag" key="M" ctrl="true" alt="false" meta="false" shift="false"/>
-		<Key id="color" name="main.menuitem.color" key="K" ctrl="true" alt="false" meta="false" shift="false"/>
+		<Key id="play" name="main.menuitem.play" key="H" ctrl="true" alt="false" meta="false" shift="false"/>
+		<Key id="drag" name="main.menuitem.drag" key="J" ctrl="true" alt="false" meta="false" shift="false"/>
+		<Key id="page" name="main.menuitem.page" key="K" ctrl="true" alt="false" meta="false" shift="false"/>
+		<Key id="color" name="main.menuitem.color" key="L" ctrl="true" alt="false" meta="false" shift="false"/>
 
 		<Key id="errors" name="main.menuitem.errors" key="E" ctrl="true" alt="false" meta="false" shift="false"/>
 		
@@ -27,9 +28,10 @@
 		<Key id="save_proj" name="main.menuitem.save" key="S" ctrl="false" alt="false" meta="true" shift="false"/>
 		<Key id="print_proj" name="main.menuitem.print" key="P" ctrl="false" alt="false" meta="true" shift="false"/>
 		
-		<Key id="play" name="main.menuitem.play" key="L" ctrl="false" alt="false" meta="true" shift="false"/>
-		<Key id="drag" name="main.menuitem.drag" key="M" ctrl="false" alt="false" meta="true" shift="false"/>
-		<Key id="color" name="main.menuitem.color" key="K" ctrl="false" alt="false" meta="true" shift="false"/>
+		<Key id="play" name="main.menuitem.play" key="H" ctrl="false" alt="false" meta="true" shift="false"/>
+		<Key id="drag" name="main.menuitem.drag" key="J" ctrl="false" alt="false" meta="true" shift="false"/>
+		<Key id="page" name="main.menuitem.page" key="K" ctrl="false" alt="false" meta="true" shift="false"/>
+		<Key id="color" name="main.menuitem.color" key="L" ctrl="false" alt="false" meta="true" shift="false"/>
 		
 		<Key id="errors" name="main.menuitem.errors" key="E" ctrl="false" alt="false" meta="true" shift="false"/>
 		
diff --git a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java
index c49c28a2..641a812b 100644
--- a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java
+++ b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java
@@ -99,6 +99,7 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro
 
 	@FXML protected MenuItem playMenu;
 	@FXML protected MenuItem dragMenu;
+	@FXML protected MenuItem pageMenu;
 	@FXML protected MenuItem colorMenu;
 
 	@FXML protected MenuItem errorMenu;
@@ -211,9 +212,13 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro
 		addPageButton.setFocusTraversable(false);
 		addPageButton.setOnAction(e ->
 		{
-			openProject.addPage();
-			initPageButtons();
-			highlightPageButton(mainViewController.getPage());
+			if (openProject.addPage()) {
+				// seite konnte hinzugefügt werden
+				initPageButtons();
+				highlightPageButton(mainViewController.getPage());
+			} else {
+				showErrorMessage(Localization.getString(Strings.Error_Project_PageCount), PlayPadMain.stageIcon);
+			}
 		});
 
 		iconHbox.getChildren().add(editButtons);
@@ -242,7 +247,13 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro
 		if (newValue == DesktopEditMode.PLAY) {
 			playButton.setSelected(true);
 		} else if (newValue == DesktopEditMode.DRAG) {
-			// TODO Live Mode Check
+			// Wenn Live Mode on, dann zum alten Wert zurück
+			GlobalSettings settings = PlayPadPlugin.getImplementation().getGlobalSettings();
+			if (settings.isLiveMode() && settings.isLiveModeDrag() && openProject.getActivePlayers() != 0) {
+				connect.setEditMode(oldValue);
+				return;
+			}
+			// Drag and Drop Aktivieren
 			dragButton.setSelected(true);
 			for (IPadView view : mainViewController.getPadViews()) {
 				view.enableDragAndDropDesignMode(true);
@@ -330,6 +341,7 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro
 
 		setKeyBindingForMenu(playMenu, keys.getKey("play"));
 		setKeyBindingForMenu(dragMenu, keys.getKey("drag"));
+		setKeyBindingForMenu(pageMenu, keys.getKey("page"));
 		setKeyBindingForMenu(colorMenu, keys.getKey("color"));
 
 		setKeyBindingForMenu(errorMenu, keys.getKey("errors"));
@@ -349,6 +361,7 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro
 
 		playMenu.setDisable(false);
 		dragMenu.setDisable(false);
+		pageMenu.setDisable(false);
 		colorMenu.setDisable(false);
 
 		errorMenu.setDisable(false);
@@ -409,6 +422,7 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro
 
 		playMenu.setDisable(true);
 		dragMenu.setDisable(true);
+		pageMenu.setDisable(true);
 		colorMenu.setDisable(true);
 
 		errorMenu.setDisable(true);
diff --git a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopPageEditButtonView.java b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopPageEditButtonView.java
index 98839443..12b67b85 100644
--- a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopPageEditButtonView.java
+++ b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopPageEditButtonView.java
@@ -130,7 +130,6 @@ public class DesktopPageEditButtonView extends HBox implements EventHandler<Acti
 			PlayPadMain.stageIcon.ifPresent(stage.getIcons()::add);
 
 			Optional<ButtonType> result = alert.showAndWait();
-			System.out.println(result);
 			result.filter(r -> r == ButtonType.OK).ifPresent(r ->
 			{
 				Project project = page.getProjectReference();
diff --git a/PlayWall/src/de/tobias/playpad/layout/desktop/pad/DesktopPadDragListener.java b/PlayWall/src/de/tobias/playpad/layout/desktop/pad/DesktopPadDragListener.java
index 63a8d826..b057c89d 100644
--- a/PlayWall/src/de/tobias/playpad/layout/desktop/pad/DesktopPadDragListener.java
+++ b/PlayWall/src/de/tobias/playpad/layout/desktop/pad/DesktopPadDragListener.java
@@ -36,8 +36,11 @@ import javafx.scene.paint.Color;
 
 public class DesktopPadDragListener {
 
-	private Pad sourcePad;
-	final private Pane view;
+	private static final String PADINDEX_DATATYPE = "de.tobias.playpad.padindex";
+	private static final DataFormat dataFormat = new DataFormat(PADINDEX_DATATYPE);
+
+	private Pad currentPad;
+	private final Pane padView; // Node der PadView
 
 	private DesktopMainLayoutConnect connect;
 	private static Project project;
@@ -45,19 +48,17 @@ public class DesktopPadDragListener {
 	private PadDragOptionView padHud;
 	private FileDragOptionView fileHud;
 
-	private static DataFormat dataFormat = new DataFormat("de.tobias.playpad.padindex");
-
-	public DesktopPadDragListener(Pad pad, IPadView view, DesktopMainLayoutConnect connect) {
-		this.sourcePad = pad;
+	public DesktopPadDragListener(Pad currentPad, IPadView view, DesktopMainLayoutConnect connect) {
+		this.currentPad = currentPad;
 		this.connect = connect;
 
-		this.view = view.getRootNode();
+		this.padView = view.getRootNode();
 
 		// Drag and Drop
-		this.view.setOnDragOver(event -> dragOver(event));
-		this.view.setOnDragExited(event -> dragExited());
-		this.view.setOnDragDropped(event -> dragDropped(event));
-		this.view.setOnDragDetected(event -> dragDetacted(event));
+		this.padView.setOnDragOver(event -> dragOver(event));
+		this.padView.setOnDragExited(event -> dragExited());
+		this.padView.setOnDragDropped(event -> dragDropped(event));
+		this.padView.setOnDragDetected(event -> dragDetacted(event));
 	}
 
 	private void dragOver(DragEvent event) {
@@ -66,18 +67,13 @@ public class DesktopPadDragListener {
 		}
 
 		if (event.getGestureSource() != this && event.getDragboard().hasFiles()) {
-			if (event.getDragboard().getFiles().get(0).isFile()) {
-
-				GlobalSettings globalSettings = PlayPadPlugin.getImplementation().getGlobalSettings();
-
-				if (sourcePad.getProject() != null) {
-					if (globalSettings.isLiveMode() && globalSettings.isLiveModeFile() && sourcePad.getProject().getActivePlayers() > 0) {
-						return;
-					}
+			File file = event.getDragboard().getFiles().get(0);
+			if (file.isFile()) {
+				// Check Live Mode
+				if (checkLiveMode()) {
+					return;
 				}
 
-				File file = event.getDragboard().getFiles().get(0);
-
 				// Build In Filesupport
 				try {
 					PadContentRegistry registry = PlayPadPlugin.getRegistryCollection().getPadContents();
@@ -85,7 +81,7 @@ public class DesktopPadDragListener {
 
 					if (!connects.isEmpty()) {
 						if (fileHud == null) {
-							fileHud = new FileDragOptionView(view);
+							fileHud = new FileDragOptionView(padView);
 						}
 						fileHud.showDropOptions(connects);
 
@@ -101,13 +97,13 @@ public class DesktopPadDragListener {
 		// Drag and Drop von Pads
 		if (event.getDragboard().hasContent(dataFormat)) {
 			PadIndex index = (PadIndex) event.getDragboard().getContent(dataFormat); // TODO Check cast
-			if (!sourcePad.getPadIndex().equals(index)) {
+			if (!currentPad.getPadIndex().equals(index)) {
 
 				Collection<PadDragMode> connects = PlayPadPlugin.getRegistryCollection().getDragModes().getComponents();
 
 				if (!connects.isEmpty()) {
 					if (padHud == null) {
-						padHud = new PadDragOptionView(view);
+						padHud = new PadDragOptionView(padView);
 					}
 					padHud.showDropOptions(connects);
 
@@ -127,18 +123,21 @@ public class DesktopPadDragListener {
 		}
 	}
 
+	// Drag Content ist los gelassen am Ziel
 	private void dragDropped(DragEvent event) {
 		Dragboard db = event.getDragboard();
 		boolean success = false;
+
+		// File Handling
 		if (db.hasFiles()) {
 			success = true;
 			File file = db.getFiles().get(0);
 
 			PadContentConnect connect = fileHud.getSelectedConnect();
 			if (connect != null) {
-				PadContent content = sourcePad.getContent();
-				if (sourcePad.getContent() == null || !sourcePad.getContent().getType().equals(connect.getType())) {
-					content = connect.newInstance(sourcePad);
+				PadContent content = currentPad.getContent();
+				if (currentPad.getContent() == null || !currentPad.getContent().getType().equals(connect.getType())) {
+					content = connect.newInstance(currentPad);
 				}
 
 				try {
@@ -147,48 +146,54 @@ public class DesktopPadDragListener {
 					// TODO Auto-generated catch block
 					e.printStackTrace();
 				}
-				this.sourcePad.setContent(content);
-				this.sourcePad.setName(FileUtils.getFilenameWithoutExtention(file.toPath().getFileName()));
+				this.currentPad.setContent(content);
+				this.currentPad.setName(FileUtils.getFilenameWithoutExtention(file.toPath().getFileName()));
 
-				if (sourcePad.getController() != null) {
-					IPadView padView = sourcePad.getController().getView();
-					padView.setContentView(sourcePad);
-					padView.addDefaultElement(sourcePad);
+				if (currentPad.getController() != null) {
+					IPadView padView = currentPad.getController().getView();
+					padView.setContentView(currentPad);
+					padView.addDefaultElements(currentPad);
 				}
 			}
 		}
 
+		// Pad DnD
 		if (db.hasContent(dataFormat)) {
-			PadIndex padID = (PadIndex) db.getContent(dataFormat); // TODO Check Cast
+			Object data = db.getContent(dataFormat);
+			if (data instanceof PadIndex) {
+				PadIndex srcIndex = (PadIndex) data;
+				PadIndex newIndex = currentPad.getPadIndex(); // Lister ist auf Ziel Pad, daher ist der Index von currentPad
 
-			PadDragMode mode = padHud.getSelectedPadDragMode();
+				System.out.println(newIndex);
 
-			mode.handle(padID, sourcePad.getPadIndex(), project);
-			padHud.hide();
+				// Drag handle
+				PadDragMode mode = padHud.getSelectedPadDragMode();
+				success = mode.handle(srcIndex, newIndex, project);
+				padHud.hide();
 
-			IMainViewController mainViewController = PlayPadPlugin.getImplementation().getMainViewController();
-			mainViewController.showPage(mainViewController.getPage());
+				// Update der Pad Views nach dem DnD
+				IMainViewController mainViewController = PlayPadPlugin.getImplementation().getMainViewController();
+				mainViewController.showPage(mainViewController.getPage());
 
-			event.setDropCompleted(success);
-			event.consume();
+				// Event Completion
+				event.setDropCompleted(success);
+				event.consume();
+			}
 		}
 	}
 
 	private void dragDetacted(MouseEvent event) {
 		if (connect.getEditMode() == DesktopEditMode.DRAG) {
-			GlobalSettings globalSettings = PlayPadPlugin.getImplementation().getGlobalSettings();
-
-			if (sourcePad.getProject() != null) {
-				if (globalSettings.isLiveMode() && globalSettings.isLiveModeDrag() && sourcePad.getProject().getActivePlayers() > 0) {
-					return;
-				}
+			if (checkLiveMode()) {
+				return;
 			}
 
-			Dragboard dragboard = view.startDragAndDrop(TransferMode.MOVE);
+			Dragboard dragboard = padView.startDragAndDrop(TransferMode.MOVE);
 
+			// Create Snapshot
 			SnapshotParameters parameters = new SnapshotParameters();
 			parameters.setFill(Color.TRANSPARENT);
-			WritableImage snapshot = view.snapshot(parameters, null);
+			WritableImage snapshot = padView.snapshot(parameters, null);
 			for (int x = 0; x < snapshot.getWidth(); x++) {
 				for (int y = 0; y < snapshot.getHeight(); y++) {
 					Color oldColor = snapshot.getPixelReader().getColor(x, y).darker().darker();
@@ -200,13 +205,24 @@ public class DesktopPadDragListener {
 			dragboard.setDragView(snapshot);
 
 			ClipboardContent content = new ClipboardContent();
-			content.put(dataFormat, sourcePad.getPadIndex());
+			content.put(dataFormat, currentPad.getPadIndex());
 			dragboard.setContent(content);
 
 			event.consume();
 		}
 	}
 
+	// Utils
+	private boolean checkLiveMode() {
+		GlobalSettings globalSettings = PlayPadPlugin.getImplementation().getGlobalSettings();
+		if (currentPad.getProject() != null) {
+			if (globalSettings.isLiveMode() && globalSettings.isLiveModeFile() && currentPad.getProject().getActivePlayers() > 0) {
+				return true;
+			}
+		}
+		return false;
+	}
+
 	public static void setProject(Project project) {
 		DesktopPadDragListener.project = project;
 	}
diff --git a/PlayWall/src/de/tobias/playpad/layout/desktop/pad/DesktopPadView.java b/PlayWall/src/de/tobias/playpad/layout/desktop/pad/DesktopPadView.java
index b8fdb172..2864463c 100644
--- a/PlayWall/src/de/tobias/playpad/layout/desktop/pad/DesktopPadView.java
+++ b/PlayWall/src/de/tobias/playpad/layout/desktop/pad/DesktopPadView.java
@@ -273,7 +273,7 @@ public class DesktopPadView implements IPadView {
 	}
 
 	@Override
-	public void addDefaultElement(Pad pad) {
+	public void addDefaultElements(Pad pad) {
 		if (pad != null) {
 			if (pad.getContent() != null) {
 				if (pad.getContent() instanceof Pauseable) {
diff --git a/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadView.java b/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadView.java
index ad69f446..02c20f1a 100644
--- a/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadView.java
+++ b/PlayWall/src/de/tobias/playpad/layout/touch/TouchPadView.java
@@ -220,7 +220,7 @@ public class TouchPadView implements IPadView {
 	}
 
 	@Override
-	public void addDefaultElement(Pad pad) {
+	public void addDefaultElements(Pad pad) {
 		infoBox.getChildren().setAll(indexLabel, loopLabel, triggerLabel, errorLabel, timeLabel);
 
 		// alle Labels in der InfoBox sollen die gleiche Höhe haben, damit die Icons auf gleicher höhe sind
diff --git a/PlayWall/src/de/tobias/playpad/pad/drag/MoveDragMode.java b/PlayWall/src/de/tobias/playpad/pad/drag/MoveDragMode.java
index d79ce380..dfa1923a 100644
--- a/PlayWall/src/de/tobias/playpad/pad/drag/MoveDragMode.java
+++ b/PlayWall/src/de/tobias/playpad/pad/drag/MoveDragMode.java
@@ -41,12 +41,18 @@ public class MoveDragMode extends PadDragMode {
 	}
 
 	@Override
-	public void handle(PadIndex oldIndex, PadIndex newIndex, Project project) {
+	public boolean handle(PadIndex oldIndex, PadIndex newIndex, Project project) {
 		Pad oldPad = project.getPad(oldIndex);
 		Pad newPad = project.getPad(newIndex);
 
-		project.setPad(newIndex, oldPad);
+		// Alte Pads entfernen, damit keine Nebenabhängigkeiten entstehen in den verschiedenen Seiten
+		project.setPad(oldIndex, null);
+		project.setPad(newIndex, null);
+
+		// Neue Pads in die Seiten einfügen
 		project.setPad(oldIndex, newPad);
+		project.setPad(newIndex, oldPad);
+		return true;
 	}
 
 }
diff --git a/PlayWall/src/de/tobias/playpad/pad/drag/ReplaceDragMode.java b/PlayWall/src/de/tobias/playpad/pad/drag/ReplaceDragMode.java
index 107bcf13..e1c67a5d 100644
--- a/PlayWall/src/de/tobias/playpad/pad/drag/ReplaceDragMode.java
+++ b/PlayWall/src/de/tobias/playpad/pad/drag/ReplaceDragMode.java
@@ -41,11 +41,15 @@ public class ReplaceDragMode extends PadDragMode {
 	}
 
 	@Override
-	public void handle(PadIndex oldPad, PadIndex newPad, Project project) {
+	public boolean handle(PadIndex oldPad, PadIndex newPad, Project project) {
 		Pad srcPad = project.getPad(oldPad);
 
+		// Alte Pads entfernen, damit keine Nebenabhängigkeiten entstehen in den verschiedenen Seiten
+		project.setPad(oldPad, null);
+		project.setPad(newPad, null);
+
 		project.setPad(newPad, srcPad);
-		project.setPad(oldPad, new Pad(project, oldPad)); // Leeres Pad an den Index
+		return true;
 	}
 
 }
diff --git a/PlayWall/src/de/tobias/playpad/pad/listener/PadContentListener.java b/PlayWall/src/de/tobias/playpad/pad/listener/PadContentListener.java
index b27598ec..d974f109 100644
--- a/PlayWall/src/de/tobias/playpad/pad/listener/PadContentListener.java
+++ b/PlayWall/src/de/tobias/playpad/pad/listener/PadContentListener.java
@@ -24,7 +24,7 @@ public class PadContentListener implements ChangeListener<PadContent> {
 	public void changed(ObservableValue<? extends PadContent> observable, PadContent oldValue, PadContent newValue) {
 		// wenn Content change, update preview & buttons
 		controller.getView().setContentView(pad);
-		controller.getView().addDefaultElement(pad);
+		controller.getView().addDefaultElements(pad);
 
 		controller.updateButtonDisable();
 		controller.updateTimeLabel();
diff --git a/PlayWallCore/src/de/tobias/playpad/pad/drag/PadDragMode.java b/PlayWallCore/src/de/tobias/playpad/pad/drag/PadDragMode.java
index 3a71578f..f79faf27 100644
--- a/PlayWallCore/src/de/tobias/playpad/pad/drag/PadDragMode.java
+++ b/PlayWallCore/src/de/tobias/playpad/pad/drag/PadDragMode.java
@@ -15,7 +15,18 @@ public abstract class PadDragMode implements Displayable, Comparable<PadDragMode
 
 	public abstract String getType();
 
-	public abstract void handle(PadIndex oldPad, PadIndex newPad, Project project);
+	/**
+	 * Führt die Drag and Drop Aktion aus, ändert das Datenmodell.
+	 * 
+	 * @param oldPad
+	 *            Alter Index
+	 * @param newPad
+	 *            Neuer Index
+	 * @param project
+	 *            Projekt zu den Pads
+	 * @return <code>true</code> Erfolgreiches DnD
+	 */
+	public abstract boolean handle(PadIndex oldPad, PadIndex newPad, Project project);
 
 	@Override
 	public int compareTo(PadDragMode o) {
diff --git a/PlayWallCore/src/de/tobias/playpad/pad/view/IPadView.java b/PlayWallCore/src/de/tobias/playpad/pad/view/IPadView.java
index b9c0cfcb..35ead4cb 100644
--- a/PlayWallCore/src/de/tobias/playpad/pad/view/IPadView.java
+++ b/PlayWallCore/src/de/tobias/playpad/pad/view/IPadView.java
@@ -117,7 +117,7 @@ public interface IPadView {
 	 * @param pad
 	 *            Pad
 	 */
-	public void addDefaultElement(Pad pad);
+	public void addDefaultElements(Pad pad);
 
 	/**
 	 * Fügt die StyleClasses der PadView hinzu. Die Methode wird vom Controller aufgerufen.
diff --git a/PlayWallCore/src/de/tobias/playpad/project/Project.java b/PlayWallCore/src/de/tobias/playpad/project/Project.java
index cdc25bd2..c4de04d5 100644
--- a/PlayWallCore/src/de/tobias/playpad/project/Project.java
+++ b/PlayWallCore/src/de/tobias/playpad/project/Project.java
@@ -46,7 +46,7 @@ public class Project {
 	 * Pattern für den Namen des Projekts
 	 */
 	public static final String PROJECT_NAME_PATTERN = "[\\p{L}0-9]{1}[\\p{L}\\s-_0-9]{0,}";
-	
+
 	/**
 	 * Dateiendung für eine projekt Datei
 	 */
@@ -109,9 +109,12 @@ public class Project {
 	}
 
 	public void setPad(PadIndex index, Pad pad) {
-		if (pad.getPage() != index.getPage()) {
-			Page oldPage = getPage(pad.getPage());
-			oldPage.removePade(index.getId());
+		if (pad != null) {
+
+			if (pad.getPage() != index.getPage()) {
+				Page oldPage = getPage(pad.getPage());
+				oldPage.removePade(index.getId());
+			}
 		}
 		Page page = pages.get(index.getPage());
 		page.setPad(index.getId(), pad);
@@ -124,7 +127,6 @@ public class Project {
 	}
 
 	// Pages
-
 	public Page getPage(int index) {
 		if (index >= pages.size() && index < ProjectSettings.MAX_PAGES) {
 			pages.add(new Page(index, this));
@@ -309,11 +311,12 @@ public class Project {
 		}
 	}
 
-	public void addPage() {
+	public boolean addPage() {
 		if (pages.size() == ProjectSettings.MAX_PAGES) {
-			return;
+			return false;
 		}
 		int index = pages.size();
 		pages.add(new Page(index, this));
+		return true;
 	}
 }
diff --git a/PlayWallCore/src/de/tobias/playpad/project/page/Page.java b/PlayWallCore/src/de/tobias/playpad/project/page/Page.java
index 749cf163..d2c135ba 100644
--- a/PlayWallCore/src/de/tobias/playpad/project/page/Page.java
+++ b/PlayWallCore/src/de/tobias/playpad/project/page/Page.java
@@ -75,9 +75,13 @@ public class Page {
 	}
 
 	public void setPad(int id, Pad pad) {
-		pads.put(id, pad);
-		pad.setPage(this.id);
-		pad.setIndex(id);
+		if (pad == null) {
+			pads.remove(id);
+		} else {
+			pads.put(id, pad);
+			pad.setPage(this.id);
+			pad.setIndex(id);
+		}
 	}
 
 	public Collection<Pad> getPads() {
@@ -87,7 +91,7 @@ public class Page {
 	public void removePade(int id) {
 		pads.remove(id);
 	}
-	
+
 	@Override
 	public String toString() {
 		return "Page [id=" + id + "]";
diff --git a/PlayWallPlugins/awakeplugin/de/tobias/playpad/awakeplugin/impl/AwakePluginImpl.java b/PlayWallPlugins/awakeplugin/de/tobias/playpad/awakeplugin/impl/AwakePluginImpl.java
index 7988b5fc..37564d3d 100644
--- a/PlayWallPlugins/awakeplugin/de/tobias/playpad/awakeplugin/impl/AwakePluginImpl.java
+++ b/PlayWallPlugins/awakeplugin/de/tobias/playpad/awakeplugin/impl/AwakePluginImpl.java
@@ -94,7 +94,7 @@ public class AwakePluginImpl implements AwakePlugin, WindowListener<IMainViewCon
 		if (Files.notExists(folder)) {
 			Files.createFile(folder);
 			URL url = new URL(ApplicationUtils.getApplication().getInfo().getUpdateURL() + "/stable/plugins/libAwake/libAwakeLib.dylib");
-			System.out.println("Downlaod " + url);
+			System.out.println("Download " + url);
 			IOUtils.copy(url.openStream(), folder);
 		}
 		return folder;
@@ -109,14 +109,14 @@ public class AwakePluginImpl implements AwakePlugin, WindowListener<IMainViewCon
 		if (Files.notExists(jnaFile)) {
 			Files.createDirectories(folder);
 			URL url = new URL(ApplicationUtils.getApplication().getInfo().getUpdateURL() + "/stable/plugins/jna/jna.jar");
-			System.out.println("Downlaod " + url);
+			System.out.println("Download " + url);
 			IOUtils.copy(url.openStream(), jnaFile);
 		}
 
 		if (Files.notExists(jnaPlatformFile)) {
 			Files.createDirectories(folder);
 			URL url = new URL(ApplicationUtils.getApplication().getInfo().getUpdateURL() + "/stable/plugins/jna/jna-platform.jar");
-			System.out.println("Downlaod " + url);
+			System.out.println("Download " + url);
 			IOUtils.copy(url.openStream(), jnaPlatformFile);
 		}
 	}
-- 
GitLab