diff --git a/PlayWall/src/de/tobias/playpad/PlayPadMain.java b/PlayWall/src/de/tobias/playpad/PlayPadMain.java index 92aeeaf123cbe7ddaccbe5cc41e0aea0ccc77d12..a44ad94ced90de062c4f950c1bfe1438cedeba66 100644 --- a/PlayWall/src/de/tobias/playpad/PlayPadMain.java +++ b/PlayWall/src/de/tobias/playpad/PlayPadMain.java @@ -9,10 +9,10 @@ import java.util.Optional; import java.util.ResourceBundle; import java.util.UUID; +import de.tobias.playpad.profile.ref.ProfileReferences; import de.tobias.playpad.project.Project; -import de.tobias.playpad.project.ref.ProjectReference; +import de.tobias.playpad.project.ref.ProjectReferences; import de.tobias.playpad.settings.GlobalSettings; -import de.tobias.playpad.settings.ProfileReference; import de.tobias.playpad.update.PlayPadUpdater; import de.tobias.playpad.update.Updates; import de.tobias.playpad.viewcontroller.LaunchDialog; @@ -131,8 +131,8 @@ public class PlayPadMain extends Application implements LocalizationDelegate { /* * Load Data */ - ProfileReference.loadProfiles(); - ProjectReference.loadProjects(); + ProfileReferences.loadProfiles(); + ProjectReferences.loadProjects(); // Changelog nach Update anzeigen ViewController.create(ChangelogDialog.class); @@ -141,7 +141,7 @@ public class PlayPadMain extends Application implements LocalizationDelegate { if (getParameters().getRaw().size() > 0) { if (getParameters().getNamed().containsKey("project")) { UUID uuid = UUID.fromString(getParameters().getNamed().get("project")); - impl.openProject(Project.load(ProjectReference.getProject(uuid), true, null)); + impl.openProject(Project.load(ProjectReferences.getProject(uuid), true, null)); return; } } @@ -186,8 +186,8 @@ public class PlayPadMain extends Application implements LocalizationDelegate { @Override public void stop() throws Exception { try { - ProfileReference.saveProfiles(); - ProjectReference.saveProjects(); + ProfileReferences.saveProfiles(); + ProjectReferences.saveProjects(); impl.getGlobalSettings().save(); } catch (Exception e) { e.printStackTrace(); // Speichern Fehler diff --git a/PlayWall/src/de/tobias/playpad/VersionUpdater.java b/PlayWall/src/de/tobias/playpad/VersionUpdater.java index 34345c4bd77a1a12ffe8ece42a296354f0f6af08..9e821f39112798518bd3ec31955658e82ab2e1ee 100644 --- a/PlayWall/src/de/tobias/playpad/VersionUpdater.java +++ b/PlayWall/src/de/tobias/playpad/VersionUpdater.java @@ -1,75 +1,13 @@ package de.tobias.playpad; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.UUID; - -import org.dom4j.Document; -import org.dom4j.DocumentException; -import org.dom4j.Element; -import org.dom4j.io.OutputFormat; -import org.dom4j.io.SAXReader; -import org.dom4j.io.XMLWriter; - -import de.tobias.playpad.project.ProjectSettings; import de.tobias.utils.application.App; -import de.tobias.utils.application.container.PathType; import de.tobias.utils.application.update.UpdateService; public class VersionUpdater implements UpdateService { @Override public void update(App app, long oldVersion, long newVersion) { - try { - if (newVersion >= 33 && oldVersion < 33) - update33(app); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private void update33(App app) throws DocumentException, IOException { - SAXReader reader = new SAXReader(); - - Document projectsDocument = reader.read(Files.newInputStream(app.getPath(PathType.CONFIGURATION, "Projects.xml"))); - for (Object obj : projectsDocument.getRootElement().elements("Project")) { - if (obj instanceof Element) { - Element element = (Element) obj; - - UUID profile = UUID.fromString(element.attributeValue("profile")); - UUID project = UUID.fromString(element.attributeValue("uuid")); - - updateProject(profile, project, app); - } - } - } - - private void updateProject(UUID profile, UUID project, App app) throws DocumentException, IOException { - Path profileSettings = app.getPath(PathType.CONFIGURATION, profile.toString(), "ProfileSettings.xml"); - SAXReader reader = new SAXReader(); - - Document document = reader.read(Files.newInputStream(profileSettings)); - Element rootElement = document.getRootElement(); - - int pages = Integer.valueOf(rootElement.element("PageCount").getStringValue()); - int rows = Integer.valueOf(rootElement.element("Rows").getStringValue()); - int columns = Integer.valueOf(rootElement.element("Columns").getStringValue()); - - Path projectSettings = app.getPath(PathType.DOCUMENTS, project.toString() + ".xml"); - Document projectDocument = reader.read(Files.newInputStream(projectSettings)); - Element rootProjectElement = projectDocument.getRootElement(); - Element settingsElement = rootProjectElement.addElement("Settings"); - - ProjectSettings projectSettings2 = new ProjectSettings(); - projectSettings2.setColumns(columns); - projectSettings2.setRows(rows); - - projectSettings2.save(settingsElement); - XMLWriter writer = new XMLWriter(Files.newOutputStream(projectSettings), OutputFormat.createPrettyPrint()); - writer.write(projectDocument); - writer.close(); } } diff --git a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java index e19862184dafb6901f492595b64b12815ae7553e..453d49f820e3171e35b4c2bedb2172ae25a8a5d6 100644 --- a/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java +++ b/PlayWall/src/de/tobias/playpad/layout/desktop/DesktopMenuToolbarViewController.java @@ -25,6 +25,7 @@ import de.tobias.playpad.project.Project; import de.tobias.playpad.project.ProjectNotFoundException; import de.tobias.playpad.project.page.Page; import de.tobias.playpad.project.ref.ProjectReference; +import de.tobias.playpad.project.ref.ProjectReferences; import de.tobias.playpad.registry.Registry; import de.tobias.playpad.settings.GlobalSettings; import de.tobias.playpad.settings.Profile; @@ -735,7 +736,7 @@ public class DesktopMenuToolbarViewController extends BasicMenuToolbarViewContro String project = openProject.getProjectReference().getName(); - ProjectReference.getProjectsSorted().stream().filter(item -> !item.getName().equals(project)).limit(LAST_DOCUMENT_LIMIT).forEach(item -> + ProjectReferences.getProjectsSorted().stream().filter(item -> !item.getName().equals(project)).limit(LAST_DOCUMENT_LIMIT).forEach(item -> { MenuItem menuItem = new MenuItem(item.toString()); menuItem.setUserData(item); diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/LaunchDialog.java b/PlayWall/src/de/tobias/playpad/viewcontroller/LaunchDialog.java index f379a2fadb24bf50117a3ecfac2a53a8edd0ceee..e3dc06be70db2a04b67f12b8175634873c40b736 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/LaunchDialog.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/LaunchDialog.java @@ -15,6 +15,7 @@ import de.tobias.playpad.project.Project; import de.tobias.playpad.project.ProjectImporter; import de.tobias.playpad.project.ProjectNotFoundException; import de.tobias.playpad.project.ref.ProjectReference; +import de.tobias.playpad.project.ref.ProjectReferences; import de.tobias.playpad.settings.Profile; import de.tobias.playpad.settings.ProfileNotFoundException; import de.tobias.playpad.viewcontroller.cell.ProjectCell; @@ -58,7 +59,7 @@ public class LaunchDialog extends ViewController implements ProfileChooseable { public LaunchDialog(Stage stage) { super("launchDialog", "de/tobias/playpad/assets/dialog/", stage, null, PlayPadMain.getUiResourceBundle()); - projectListView.getItems().addAll(ProjectReference.getProjectsSorted()); + projectListView.getItems().addAll(ProjectReferences.getProjectsSorted()); } @Override @@ -168,7 +169,7 @@ public class LaunchDialog extends ViewController implements ProfileChooseable { alert.showAndWait().filter(item -> item == ButtonType.OK).ifPresent(item -> { try { - ProjectReference.removeDocument(ref); + ProjectReferences.removeDocument(ref); projectListView.getItems().remove(ref); // VIEW } catch (DocumentException | IOException e) { showErrorMessage(getString(Strings.Error_Project_Delete, e.getLocalizedMessage())); diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/cell/ProjectCell.java b/PlayWall/src/de/tobias/playpad/viewcontroller/cell/ProjectCell.java index 6d132b21054e346355bf8dc1a1c6fa30f1bd882e..68b8729394997b82289d4534d706dfaf50990f20 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/cell/ProjectCell.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/cell/ProjectCell.java @@ -4,8 +4,8 @@ import java.nio.file.Files; import java.nio.file.Path; import de.tobias.playpad.Displayable; +import de.tobias.playpad.profile.ref.ProfileReference; import de.tobias.playpad.project.ref.ProjectReference; -import de.tobias.playpad.settings.ProfileReference; import de.tobias.utils.ui.icon.FontAwesomeType; import de.tobias.utils.ui.icon.FontIcon; import javafx.geometry.Pos; diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/DuplicateProfileDialog.java b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/DuplicateProfileDialog.java index 8556d72177365c43b1a3e563c2e2f976ffd8e2ee..da7c833673ea20a8b697a1aeb8d74eb26577a823 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/DuplicateProfileDialog.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/DuplicateProfileDialog.java @@ -4,8 +4,9 @@ import java.util.Optional; import de.tobias.playpad.PlayPadMain; import de.tobias.playpad.Strings; +import de.tobias.playpad.profile.ref.ProfileReference; +import de.tobias.playpad.profile.ref.ProfileReferences; import de.tobias.playpad.settings.Profile; -import de.tobias.playpad.settings.ProfileReference; import de.tobias.utils.ui.ViewController; import de.tobias.utils.util.Localization; import javafx.scene.control.Button; @@ -27,7 +28,7 @@ public class DuplicateProfileDialog extends TextInputDialog { Button button = (Button) getDialogPane().lookupButton(ButtonType.OK); getEditor().textProperty().addListener((a, b, c) -> { - if (ProfileReference.getProfiles().contains(c) || !c.matches(Profile.profileNameEx)) { + if (ProfileReferences.getProfiles().contains(c) || !c.matches(Profile.profileNameEx)) { button.setDisable(true); } else { button.setDisable(false); @@ -38,13 +39,13 @@ public class DuplicateProfileDialog extends TextInputDialog { showAndWait().filter(name -> !name.isEmpty()).ifPresent(name -> { try { - if (ProfileReference.getProfiles().contains(name)) { + if (ProfileReferences.getProfiles().contains(name)) { controller.showErrorMessage(Localization.getString(Strings.Error_Standard_NameInUse, name)); return; } newRef = new ProfileReference(name); - ProfileReference.duplicate(cloneableProfile, newRef); + ProfileReferences.duplicate(cloneableProfile, newRef); } catch (Exception e) { e.printStackTrace(); diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/DuplicateProjectDialog.java b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/DuplicateProjectDialog.java index b31808a79568be8d99f6214cff746a0799f45ff1..8b14194ea86e8cf78064ea06accefeb29ca3cbb4 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/DuplicateProjectDialog.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/DuplicateProjectDialog.java @@ -4,9 +4,10 @@ import java.util.Optional; import de.tobias.playpad.PlayPadMain; import de.tobias.playpad.Strings; +import de.tobias.playpad.profile.ref.ProfileReferences; import de.tobias.playpad.project.Project; import de.tobias.playpad.project.ref.ProjectReference; -import de.tobias.playpad.settings.ProfileReference; +import de.tobias.playpad.project.ref.ProjectReferences; import de.tobias.utils.ui.ViewController; import de.tobias.utils.util.Localization; import javafx.scene.control.Button; @@ -40,7 +41,7 @@ public class DuplicateProjectDialog extends TextInputDialog { Button button = (Button) getDialogPane().lookupButton(ButtonType.OK); getEditor().textProperty().addListener((a, b, c) -> { - if (ProjectReference.getProjects().contains(c) || !c.matches(Project.PROJECT_NAME_PATTERN)) { + if (ProjectReferences.getProjects().contains(c) || !c.matches(Project.PROJECT_NAME_PATTERN)) { button.setDisable(true); } else { button.setDisable(false); @@ -51,12 +52,12 @@ public class DuplicateProjectDialog extends TextInputDialog { showAndWait().filter(name -> !name.isEmpty()).ifPresent(name -> { try { - if (ProfileReference.getProfiles().contains(name)) { + if (ProfileReferences.getProfiles().contains(name)) { controller.showErrorMessage(Localization.getString(Strings.Error_Standard_NameInUse, name)); return; } - ref = ProjectReference.duplicate(cloneableProject, name); + ref = ProjectReferences.duplicate(cloneableProject, name); } catch (Exception e) { e.printStackTrace(); controller.showErrorMessage(Localization.getString(Strings.Error_Project_Save, name, e.getMessage())); diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/NewProfileDialog.java b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/NewProfileDialog.java index 294c7f99b43d034d9eeba22752ee2f7200d82654..292a169445017fc7fbc24a19886f6f6e157b7438 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/NewProfileDialog.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/NewProfileDialog.java @@ -1,12 +1,15 @@ package de.tobias.playpad.viewcontroller.dialog; +import java.util.List; + import javax.sound.midi.MidiDevice.Info; import de.tobias.playpad.PlayPadMain; import de.tobias.playpad.Strings; import de.tobias.playpad.midi.Midi; +import de.tobias.playpad.profile.ref.ProfileReference; +import de.tobias.playpad.profile.ref.ProfileReferences; import de.tobias.playpad.settings.Profile; -import de.tobias.playpad.settings.ProfileReference; import de.tobias.utils.ui.ViewController; import de.tobias.utils.util.Localization; import de.tobias.utils.util.Worker; @@ -86,7 +89,7 @@ public class NewProfileDialog extends ViewController { if (c.isEmpty()) { finishButton.setDisable(true); } else { - if (ProfileReference.getProfiles().contains(c) || !c.matches(Profile.profileNameEx)) { + if (ProfileReferences.getProfiles().contains(c) || !c.matches(Profile.profileNameEx)) { finishButton.setDisable(true); return; } @@ -125,12 +128,14 @@ public class NewProfileDialog extends ViewController { private void finishButtonHandler(ActionEvent event) { String name = nameTextField.getText(); try { - if (ProfileReference.getProfiles().contains(name) || !name.matches(Profile.profileNameEx)) { + List<ProfileReference> profiles = ProfileReferences.getProfiles(); + + if (profiles.contains(name) || !name.matches(Profile.profileNameEx)) { showErrorMessage(Localization.getString(Strings.Error_Standard_NameInUse, name)); return; } - profile = ProfileReference.newProfile(name); + profile = ProfileReferences.newProfile(name); profile.getProfileSettings().setMidiActive(activeCheckBox.isSelected()); profile.getProfileSettings().setMidiDeviceName(midiDeviceComboBox.getSelectionModel().getSelectedItem()); diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/NewProjectDialog.java b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/NewProjectDialog.java index 58d17b37c38775d5aa2a998ffee99501b209a1d5..9f12a82e215d1517f76db27b96f322a5452ca17d 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/NewProjectDialog.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/NewProjectDialog.java @@ -9,11 +9,13 @@ import org.dom4j.DocumentException; import de.tobias.playpad.PlayPadMain; import de.tobias.playpad.Strings; +import de.tobias.playpad.profile.ref.ProfileReference; +import de.tobias.playpad.profile.ref.ProfileReferences; import de.tobias.playpad.project.Project; import de.tobias.playpad.project.ref.ProjectReference; +import de.tobias.playpad.project.ref.ProjectReferences; import de.tobias.playpad.settings.Profile; import de.tobias.playpad.settings.ProfileNotFoundException; -import de.tobias.playpad.settings.ProfileReference; import de.tobias.utils.ui.ViewController; import de.tobias.utils.util.Localization; import javafx.event.ActionEvent; @@ -57,7 +59,7 @@ public class NewProjectDialog extends ViewController { getStage().initOwner(owner); getStage().initModality(Modality.WINDOW_MODAL); - profileComboBox.getItems().addAll(ProfileReference.getProfiles()); + profileComboBox.getItems().addAll(ProfileReferences.getProfiles()); profileComboBox.getSelectionModel().selectFirst(); } @@ -68,7 +70,7 @@ public class NewProjectDialog extends ViewController { if (c.isEmpty()) { finishButton.setDisable(true); } else { - if (ProjectReference.getProjects().contains(c) || !c.matches(Project.PROJECT_NAME_PATTERN)) { + if (ProjectReferences.getProjects().contains(c) || !c.matches(Project.PROJECT_NAME_PATTERN)) { finishButton.setDisable(true); return; } @@ -138,7 +140,7 @@ public class NewProjectDialog extends ViewController { project.getSettings().setMediaPath(newMediaPath); project.save(); - ProjectReference.addProject(projectReference); + ProjectReferences.addProject(projectReference); getStage().close(); } catch (IOException | DocumentException | ProfileNotFoundException e) { diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/ProfileChooseDialog.java b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/ProfileChooseDialog.java index 16362ff2cae9c234455fbbab6f86d343eafeafaa..d516fcd3d631672ef212daaf66f3f202c1a9ab31 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/ProfileChooseDialog.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/ProfileChooseDialog.java @@ -6,9 +6,10 @@ import org.dom4j.DocumentException; import de.tobias.playpad.PlayPadMain; import de.tobias.playpad.Strings; +import de.tobias.playpad.profile.ref.ProfileReference; +import de.tobias.playpad.profile.ref.ProfileReferences; import de.tobias.playpad.settings.Profile; import de.tobias.playpad.settings.ProfileNotFoundException; -import de.tobias.playpad.settings.ProfileReference; import de.tobias.utils.ui.ViewController; import de.tobias.utils.util.Localization; import javafx.event.ActionEvent; @@ -35,7 +36,7 @@ public class ProfileChooseDialog extends ViewController { getStage().initOwner(owner); getStage().initModality(Modality.WINDOW_MODAL); - profileComboBox.getItems().addAll(ProfileReference.getProfiles()); + profileComboBox.getItems().addAll(ProfileReferences.getProfiles()); profileComboBox.getSelectionModel().selectFirst(); } diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/ProfileViewController.java b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/ProfileViewController.java index e915ad9846a31a0ad8e58964a95e655f066ef29c..293390b3c2021cc76ae1b1e6e8c609fd43d80431 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/ProfileViewController.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/ProfileViewController.java @@ -7,10 +7,11 @@ import org.dom4j.DocumentException; import de.tobias.playpad.PlayPadMain; import de.tobias.playpad.PseudoClasses; import de.tobias.playpad.Strings; +import de.tobias.playpad.profile.ref.ProfileReference; +import de.tobias.playpad.profile.ref.ProfileReferences; import de.tobias.playpad.project.Project; import de.tobias.playpad.settings.Profile; import de.tobias.playpad.settings.ProfileNotFoundException; -import de.tobias.playpad.settings.ProfileReference; import de.tobias.playpad.viewcontroller.cell.DisplayableCell; import de.tobias.utils.ui.ViewController; import de.tobias.utils.util.Localization; @@ -50,7 +51,7 @@ public class ProfileViewController extends ViewController implements ChangeListe getStage().initOwner(owner); getStage().initModality(Modality.WINDOW_MODAL); - if (ProfileReference.getProfiles().size() == 1 + if (ProfileReferences.getProfiles().size() == 1 || profileList.getSelectionModel().getSelectedItem().equals(Profile.currentProfile().getRef())) { deleteButton.setDisable(true); } @@ -58,14 +59,14 @@ public class ProfileViewController extends ViewController implements ChangeListe @Override public void init() { - profileList.getItems().setAll(ProfileReference.getProfiles()); + profileList.getItems().setAll(ProfileReferences.getProfiles()); profileList.setCellFactory(list -> new DisplayableCell<>()); nameTextField.textProperty().addListener((a, b, c) -> { if (c != null) { try { - if ((ProfileReference.getProfiles().contains(c) && !profileList.getSelectionModel().getSelectedItem().equals(c)) + if ((ProfileReferences.getProfiles().contains(c) && !profileList.getSelectionModel().getSelectedItem().equals(c)) && !c.equals(profileList.getSelectionModel().getSelectedItem().getName())) { nameTextField.pseudoClassStateChanged(PseudoClasses.ERROR_CLASS, true); } else { @@ -150,7 +151,7 @@ public class ProfileViewController extends ViewController implements ChangeListe alert.showAndWait().filter(button -> button == ButtonType.OK).ifPresent(button -> { try { - ProfileReference.removeProfile(ref); + ProfileReferences.removeProfile(ref); profileList.getItems().remove(ref); } catch (Exception e) { e.printStackTrace(); @@ -164,7 +165,7 @@ public class ProfileViewController extends ViewController implements ChangeListe ProfileReference ref = profileList.getSelectionModel().getSelectedItem(); try { String newProfileName = nameTextField.getText(); - if (ProfileReference.getProfiles().contains(newProfileName) || !newProfileName.matches(Profile.profileNameEx)) { + if (ProfileReferences.getProfiles().contains(newProfileName) || !newProfileName.matches(Profile.profileNameEx)) { showErrorMessage(Localization.getString(Strings.Error_Standard_NameInUse, newProfileName)); return; } @@ -190,7 +191,7 @@ public class ProfileViewController extends ViewController implements ChangeListe chooseButton.setDisable(newValue == null); duplicateButton.setDisable(newValue == null); - if (ProfileReference.getProfiles().size() == 1 || profileList.getSelectionModel().getSelectedItem() == null + if (ProfileReferences.getProfiles().size() == 1 || profileList.getSelectionModel().getSelectedItem() == null || profileList.getSelectionModel().getSelectedItem().equals(Profile.currentProfile().getRef())) { deleteButton.setDisable(true); } else { diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/ProjectManagerDialog.java b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/ProjectManagerDialog.java index 33ca625564325d62e577135fb78a53b5b5b54bd7..13f99b0344427a5198b28c70e7e62749c71723fd 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/ProjectManagerDialog.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/ProjectManagerDialog.java @@ -9,11 +9,12 @@ import org.dom4j.DocumentException; import de.tobias.playpad.PlayPadMain; import de.tobias.playpad.Strings; +import de.tobias.playpad.profile.ref.ProfileReference; import de.tobias.playpad.project.Project; import de.tobias.playpad.project.ProjectImporter; import de.tobias.playpad.project.ref.ProjectReference; +import de.tobias.playpad.project.ref.ProjectReferences; import de.tobias.playpad.settings.Profile; -import de.tobias.playpad.settings.ProfileReference; import de.tobias.playpad.viewcontroller.cell.ProjectCell; import de.tobias.utils.ui.NotificationHandler; import de.tobias.utils.ui.ViewController; @@ -69,7 +70,7 @@ public class ProjectManagerDialog extends ViewController implements Notification super("openDialog", "de/tobias/playpad/assets/dialog/project/", null, PlayPadMain.getUiResourceBundle()); this.currentProject = currentProject; - projectList.getItems().setAll(ProjectReference.getProjectsSorted()); + projectList.getItems().setAll(ProjectReferences.getProjectsSorted()); getStage().initOwner(owner); getStage().initModality(Modality.WINDOW_MODAL); @@ -176,7 +177,7 @@ public class ProjectManagerDialog extends ViewController implements Notification alert.showAndWait().filter(item -> item == ButtonType.OK).ifPresent(item -> { try { - ProjectReference.removeDocument(ref); + ProjectReferences.removeDocument(ref); projectList.getItems().remove(ref); // VIEW } catch (Exception e) { showErrorMessage(Localization.getString(Strings.Error_Project_Delete, e.getLocalizedMessage())); @@ -202,13 +203,13 @@ public class ProjectManagerDialog extends ViewController implements Notification try { String newProjectName = nameTextField.getText(); - if (ProjectReference.getProjects().contains(newProjectName) || !nameTextField.getText().matches(Project.PROJECT_NAME_PATTERN)) { + if (ProjectReferences.getProjects().contains(newProjectName) || !nameTextField.getText().matches(Project.PROJECT_NAME_PATTERN)) { showErrorMessage(Localization.getString(Strings.Error_Standard_NameInUse, nameTextField.getText())); return; } projectReference.setName(newProjectName); - projectList.getItems().setAll(ProjectReference.getProjectsSorted()); + projectList.getItems().setAll(ProjectReferences.getProjectsSorted()); selectProject(projectReference); } catch (Exception e) { diff --git a/PlayWallCore/src/de/tobias/playpad/profile/ref/ProfileReference.java b/PlayWallCore/src/de/tobias/playpad/profile/ref/ProfileReference.java new file mode 100644 index 0000000000000000000000000000000000000000..8b3cecea7892323d0716d7f3cdd939a0d4d1d70f --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/profile/ref/ProfileReference.java @@ -0,0 +1,144 @@ +package de.tobias.playpad.profile.ref; + +import java.nio.file.Path; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +import de.tobias.playpad.Displayable; +import de.tobias.playpad.plugin.Module; +import de.tobias.playpad.settings.Profile; +import de.tobias.utils.application.ApplicationUtils; +import de.tobias.utils.application.container.PathType; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +/** + * Container für Profile Referenzen + * + * @author tobias + * + * @see Profile + * @since 5.0.0 + */ +public class ProfileReference implements Displayable { + + private final UUID uuid; + private String name; + private Set<Module> requestedModules; + + /** + * Erstellt eine neue Referenz mit einer Random UUID. + * + * @param name + * Name + */ + public ProfileReference(String name) { + this.name = name; + this.uuid = UUID.randomUUID(); + requestedModules = new HashSet<>(); + updateDisplayProperty(); + } + + /** + * Erstellt eine neue Referenz mit Namen und UUID. + * + * @param uuid + * UUID + * @param name + * Name + */ + public ProfileReference(UUID uuid, String name) { + this.uuid = uuid; + this.name = name; + requestedModules = new HashSet<>(); + updateDisplayProperty(); + } + + /** + * Erstellt eine neue Referenz mit Namen und UUID. + * + * @param uuid + * UUID + * @param name + * Name + */ + public ProfileReference(UUID uuid, String name, Set<Module> requestedModules) { + this(uuid, name); + this.requestedModules = requestedModules; + } + + /** + * Gibt den Namen zurück + * + * @return Name + */ + public String getName() { + return name; + } + + /** + * Gibt die UUID zurück + * + * @return uudi + */ + public UUID getUuid() { + return uuid; + } + + /** + * Setzt einen neuen Namen. + * + * @param name + * Neuer Name + */ + public void setName(String name) { + this.name = name; + updateDisplayProperty(); + } + + public Set<Module> getRequestedModules() { + return requestedModules; + } + + public void addRequestedModule(Module module) { + requestedModules.add(module); + } + + /** + * Gibt einen Pfad für einen Dateinamen in diesem Profile zurück. + * + * @param name + * Name der Datei + * @return Path für die Datei + */ + public Path getCustomFilePath(String name) { + return ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, getFileName(), name); + } + + /** + * Gibt den internen (File-) Namen des Profiles zurück. + * + * @return Ordnernamen + */ + public String getFileName() { + return uuid.toString(); + } + + @Override + public String toString() { + return name; + } + + // Displayable + private StringProperty displayProperty = new SimpleStringProperty(toString()); + + @Override + public StringProperty displayProperty() { + return displayProperty; + } + + private void updateDisplayProperty() { + displayProperty.set(toString()); + } +} diff --git a/PlayWallCore/src/de/tobias/playpad/settings/ProfileReferenceList.java b/PlayWallCore/src/de/tobias/playpad/profile/ref/ProfileReferenceList.java similarity index 95% rename from PlayWallCore/src/de/tobias/playpad/settings/ProfileReferenceList.java rename to PlayWallCore/src/de/tobias/playpad/profile/ref/ProfileReferenceList.java index 6fa172307dbcc11ea478ca8f6c0e0b96a034e130..dd53a96f93a4b924433cba69145a0599aa5034d2 100644 --- a/PlayWallCore/src/de/tobias/playpad/settings/ProfileReferenceList.java +++ b/PlayWallCore/src/de/tobias/playpad/profile/ref/ProfileReferenceList.java @@ -1,4 +1,4 @@ -package de.tobias.playpad.settings; +package de.tobias.playpad.profile.ref; import de.tobias.utils.list.UniqList; diff --git a/PlayWallCore/src/de/tobias/playpad/settings/ProfileReferenceSerializer.java b/PlayWallCore/src/de/tobias/playpad/profile/ref/ProfileReferenceSerializer.java similarity index 97% rename from PlayWallCore/src/de/tobias/playpad/settings/ProfileReferenceSerializer.java rename to PlayWallCore/src/de/tobias/playpad/profile/ref/ProfileReferenceSerializer.java index b1c1fa689c7425647727a5fa7dc1a9c5fb1bb18d..879a33bd42523c0bed923f3a0573b19f7057a1ac 100644 --- a/PlayWallCore/src/de/tobias/playpad/settings/ProfileReferenceSerializer.java +++ b/PlayWallCore/src/de/tobias/playpad/profile/ref/ProfileReferenceSerializer.java @@ -1,4 +1,4 @@ -package de.tobias.playpad.settings; +package de.tobias.playpad.profile.ref; import java.util.HashSet; import java.util.Set; diff --git a/PlayWallCore/src/de/tobias/playpad/settings/ProfileReference.java b/PlayWallCore/src/de/tobias/playpad/profile/ref/ProfileReferences.java similarity index 61% rename from PlayWallCore/src/de/tobias/playpad/settings/ProfileReference.java rename to PlayWallCore/src/de/tobias/playpad/profile/ref/ProfileReferences.java index 511f6ca92ea4191ecde3b168f6d0bd23ab78211d..741e9cacc47c12a4819739ab72f460f9edeac907 100644 --- a/PlayWallCore/src/de/tobias/playpad/settings/ProfileReference.java +++ b/PlayWallCore/src/de/tobias/playpad/profile/ref/ProfileReferences.java @@ -1,13 +1,11 @@ -package de.tobias.playpad.settings; +package de.tobias.playpad.profile.ref; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.UUID; import org.dom4j.Document; @@ -15,117 +13,21 @@ import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; -import de.tobias.playpad.Displayable; -import de.tobias.playpad.plugin.Module; +import de.tobias.playpad.settings.Profile; import de.tobias.utils.application.ApplicationUtils; import de.tobias.utils.application.container.PathType; import de.tobias.utils.util.FileUtils; import de.tobias.utils.util.FileUtils.FileActionAdapter; import de.tobias.utils.xml.XMLHandler; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; -/** - * Container für Profile Referenzen - * - * @author tobias - * - * @see Profile - * @since 5.0.0 - */ -public class ProfileReference implements Displayable { +public final class ProfileReferences { - private static final String DEFAULT_PROFILE_NAME = "Default"; - - private final UUID uuid; - private String name; - private Set<Module> requestedModules; - - /** - * Erstellt eine neue Referenz mit einer Random UUID. - * - * @param name - * Name - */ - public ProfileReference(String name) { - this.name = name; - this.uuid = UUID.randomUUID(); - requestedModules = new HashSet<>(); - updateDisplayProperty(); - } - - /** - * Erstellt eine neue Referenz mit Namen und UUID. - * - * @param uuid - * UUID - * @param name - * Name - */ - public ProfileReference(UUID uuid, String name) { - this.uuid = uuid; - this.name = name; - requestedModules = new HashSet<>(); - updateDisplayProperty(); - } - - /** - * Erstellt eine neue Referenz mit Namen und UUID. - * - * @param uuid - * UUID - * @param name - * Name - */ - public ProfileReference(UUID uuid, String name, Set<Module> requestedModules) { - this(uuid, name); - this.requestedModules = requestedModules; - } - - /** - * Gibt den Namen zurück - * - * @return Name - */ - public String getName() { - return name; - } - - /** - * Gibt die UUID zurück - * - * @return uudi - */ - public UUID getUuid() { - return uuid; - } - - /** - * Setzt einen neuen Namen. - * - * @param name - * Neuer Name - */ - public void setName(String name) { - this.name = name; - updateDisplayProperty(); - } - - - public Set<Module> getRequestedModules() { - return requestedModules; - } - - public void addRequestedModule(Module module) { - requestedModules.add(module); - } - - // Verwaltungsmethoden für Profile Referenzen // TODO Extract in Extra Class + private ProfileReferences() {} /** * Liste mit allen Referenzen */ - private static List<ProfileReference> profiles = new ProfileReferenceList(); + static List<ProfileReference> profiles = new ProfileReferenceList(); /** * Sucht eine Referenz zu einer UUID raus. @@ -136,7 +38,7 @@ public class ProfileReference implements Displayable { */ public static ProfileReference getReference(UUID profile) { for (ProfileReference ref : profiles) { - if (ref.uuid.equals(profile)) { + if (ref.getUuid().equals(profile)) { return ref; } } @@ -165,7 +67,7 @@ public class ProfileReference implements Displayable { */ public static Profile newProfile(String name) throws UnsupportedEncodingException, IOException { ProfileReference ref = new ProfileReference(UUID.randomUUID(), name); - ProfileReference.addProfile(ref); + ProfileReferences.addProfile(ref); Profile profile = new Profile(ref); profile.save(); @@ -253,6 +155,7 @@ public class ProfileReference implements Displayable { } // Load and Save + private static final String DEFAULT_PROFILE_NAME = "Default"; private static final String FILE_NAME = "Profiles.xml"; private static final String ROOT_ELEMENT = "Settings"; @@ -267,20 +170,20 @@ public class ProfileReference implements Displayable { * XML Fehler */ public static void loadProfiles() throws IOException, DocumentException { - profiles.clear(); + ProfileReferences.profiles.clear(); Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, FILE_NAME); if (Files.exists(path)) { // Load data from xml XMLHandler<ProfileReference> handler = new XMLHandler<>(path); - profiles = handler.loadElements(PROFILE_ELEMENT, new ProfileReferenceSerializer()); - System.out.println(profiles); + ProfileReferences.profiles = handler.loadElements(PROFILE_ELEMENT, new ProfileReferenceSerializer()); + System.out.println("Find Profile: " + ProfileReferences.profiles); } // Add Default Element if list is empty - if (profiles.isEmpty()) { - Profile profile = newProfile(DEFAULT_PROFILE_NAME); + if (ProfileReferences.profiles.isEmpty()) { + Profile profile = ProfileReferences.newProfile(DEFAULT_PROFILE_NAME); profile.save(); } } @@ -299,7 +202,7 @@ public class ProfileReference implements Displayable { // Save data to xml XMLHandler<ProfileReference> handler = new XMLHandler<>(root); - handler.saveElements(PROFILE_ELEMENT, profiles, new ProfileReferenceSerializer()); + handler.saveElements(PROFILE_ELEMENT, ProfileReferences.profiles, new ProfileReferenceSerializer()); Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, FILE_NAME); if (Files.notExists(path)) { @@ -309,40 +212,4 @@ public class ProfileReference implements Displayable { XMLHandler.save(path, document); } - /** - * Gibt einen Pfad für einen Dateinamen in diesem Profile zurück. - * - * @param name - * Name der Datei - * @return Path für die Datei - */ - public Path getCustomFilePath(String name) { - return ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, getFileName(), name); - } - - /** - * Gibt den internen (File-) Namen des Profiles zurück. - * - * @return Ordnernamen - */ - public String getFileName() { - return uuid.toString(); - } - - @Override - public String toString() { - return name; - } - - // Displayable - private StringProperty displayProperty = new SimpleStringProperty(toString()); - - @Override - public StringProperty displayProperty() { - return displayProperty; - } - - private void updateDisplayProperty() { - displayProperty.set(toString()); - } } diff --git a/PlayWallCore/src/de/tobias/playpad/project/ProjectExporter.java b/PlayWallCore/src/de/tobias/playpad/project/ProjectExporter.java index 74b5417b3604a080fe9ea6d8d7b6b12849c28951..8157c6eced8f924a8ed37b952fe53ee06e644e07 100644 --- a/PlayWallCore/src/de/tobias/playpad/project/ProjectExporter.java +++ b/PlayWallCore/src/de/tobias/playpad/project/ProjectExporter.java @@ -16,8 +16,8 @@ import org.dom4j.io.XMLWriter; import de.tobias.playpad.pad.Pad; import de.tobias.playpad.pad.PadSerializer; +import de.tobias.playpad.profile.ref.ProfileReference; import de.tobias.playpad.project.ref.ProjectReference; -import de.tobias.playpad.settings.ProfileReference; import de.tobias.utils.application.App; import de.tobias.utils.application.ApplicationUtils; import de.tobias.utils.application.container.PathType; diff --git a/PlayWallCore/src/de/tobias/playpad/project/ProjectImporter.java b/PlayWallCore/src/de/tobias/playpad/project/ProjectImporter.java index 45eb65debe4a180059690fe9c1442788b2957963..735671ecd611101132d67291ee4c8e203d362109 100644 --- a/PlayWallCore/src/de/tobias/playpad/project/ProjectImporter.java +++ b/PlayWallCore/src/de/tobias/playpad/project/ProjectImporter.java @@ -16,9 +16,11 @@ import org.dom4j.io.XMLWriter; import de.tobias.playpad.pad.Pad; import de.tobias.playpad.pad.PadSerializer; +import de.tobias.playpad.profile.ref.ProfileReference; +import de.tobias.playpad.profile.ref.ProfileReferences; import de.tobias.playpad.project.ref.ProjectReference; +import de.tobias.playpad.project.ref.ProjectReferences; import de.tobias.playpad.settings.Profile; -import de.tobias.playpad.settings.ProfileReference; import de.tobias.utils.application.App; import de.tobias.utils.application.ApplicationUtils; import de.tobias.utils.application.container.PathType; @@ -70,7 +72,7 @@ public class ProjectImporter { UUID localProfileUUID = null; if (includeProfile) { // Dieser Dialog wird aufgerufen, wenn das Profile bereits existiert, wenn nicht wird es direkt importiert - if (ProfileReference.getProfiles().contains(profileName)) { + if (ProfileReferences.getProfiles().contains(profileName)) { profileName = importable.replaceProfile(profileName); } @@ -98,7 +100,7 @@ public class ProjectImporter { }); ProfileReference profileRef = new ProfileReference(localProfileUUID, profileName); - ProfileReference.addProfile(profileRef); + ProfileReferences.addProfile(profileRef); } else { Profile profile = chooseable.getUnkownProfile(); if (profile != null) { @@ -121,13 +123,13 @@ public class ProjectImporter { zip.getFile(projectFile, localFile); - if (ProjectReference.getProjects().contains(projectName)) { + if (ProjectReferences.getProjects().contains(projectName)) { projectName = importable.replaceProject(projectName); } ProjectReference projectRef = new ProjectReference(localProjectUUID, projectName, - ProfileReference.getReference(localProfileUUID)); - ProjectReference.addProject(projectRef); + ProfileReferences.getReference(localProfileUUID)); + ProjectReferences.addProject(projectRef); // Import Media if (includeMedia) { diff --git a/PlayWallCore/src/de/tobias/playpad/project/ref/ProjectReference.java b/PlayWallCore/src/de/tobias/playpad/project/ref/ProjectReference.java index c83804a93569a3d65b62ca3a9cdef2188e3fc165..b993267893bec2724d27a4701adcfaa9652eb276 100644 --- a/PlayWallCore/src/de/tobias/playpad/project/ref/ProjectReference.java +++ b/PlayWallCore/src/de/tobias/playpad/project/ref/ProjectReference.java @@ -1,39 +1,24 @@ package de.tobias.playpad.project.ref; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.UUID; -import org.dom4j.Document; -import org.dom4j.DocumentException; -import org.dom4j.DocumentHelper; -import org.dom4j.Element; - import de.tobias.playpad.Displayable; import de.tobias.playpad.PlayPadPlugin; import de.tobias.playpad.plugin.Module; +import de.tobias.playpad.profile.ref.ProfileReference; import de.tobias.playpad.project.Project; -import de.tobias.playpad.settings.ProfileReference; import de.tobias.utils.application.App; import de.tobias.utils.application.ApplicationUtils; import de.tobias.utils.application.container.PathType; -import de.tobias.utils.xml.XMLHandler; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; public class ProjectReference implements Displayable { - private static List<ProjectReference> projects = new ProjectReferenceList(); - private static boolean loadedProjectOverview = false; - /** * Name + XML */ @@ -144,93 +129,6 @@ public class ProjectReference implements Displayable { return name; } - public static void addProject(ProjectReference item) throws UnsupportedEncodingException, IOException { - if (!projects.contains(item)) { - projects.add(item); - } - saveProjects(); - } - - public static void removeDocument(ProjectReference projectReference) throws DocumentException, IOException { - Path path = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, projectReference.getUuid() + Project.FILE_EXTENSION); - - Files.deleteIfExists(path); // DIRVE - projects.remove(projectReference); // MODEL - saveProjects(); - } - - public static ProjectReference duplicate(ProjectReference currentProject, String name) throws IOException { - ProjectReference newProjectReference = new ProjectReference(UUID.randomUUID(), name, currentProject.getProfileReference()); - addProject(newProjectReference); - - duplicateFiles(currentProject, newProjectReference); - - saveProjects(); - return newProjectReference; - } - - private static void duplicateFiles(ProjectReference currentProject, ProjectReference newProjectReference) throws IOException { - Path oldPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, currentProject.getName()); - Path newPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, newProjectReference.getName()); - Files.copy(oldPath, newPath, StandardCopyOption.COPY_ATTRIBUTES); - } - - public static List<ProjectReference> getProjects() { - if (!loadedProjectOverview) - try { - loadProjects(); - } catch (DocumentException | IOException e) { - e.printStackTrace(); - } - return projects; - } - - // Load and Save - private static final String FILE_NAME = "Projects.xml"; - private static final String PROJECT_ELEMENT = "Project"; - private static final String ROOT_ELEMENT = "Settings"; - - public static void loadProjects() throws DocumentException, IOException { - Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, FILE_NAME); - if (Files.exists(path)) { - XMLHandler<ProjectReference> loader = new XMLHandler<>(path); - projects = loader.loadElements(PROJECT_ELEMENT, new ProjectReferenceSerializer()); - } - loadedProjectOverview = true; - } - - public static void saveProjects() throws UnsupportedEncodingException, IOException { - Document document = DocumentHelper.createDocument(); - Element root = document.addElement(ROOT_ELEMENT); - - XMLHandler<ProjectReference> handler = new XMLHandler<>(root); - handler.saveElements(PROJECT_ELEMENT, projects, new ProjectReferenceSerializer()); - - Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, FILE_NAME); - if (Files.notExists(path)) { - Files.createDirectories(path.getParent()); - Files.createFile(path); - } - XMLHandler.save(path, document); - } - - public static List<ProjectReference> getProjectsSorted() { - if (!loadedProjectOverview) - try { - loadProjects(); - } catch (DocumentException | IOException e) { - e.printStackTrace(); - } - - List<ProjectReference> items = new ArrayList<>(); - projects.forEach(item -> items.add(item)); - items.sort((ProjectReference o1, ProjectReference o2) -> - { - return Long.compare(o2.lastMofied, o1.lastMofied); - }); - return items; - } - public String getFileName() { return uuid + Project.FILE_EXTENSION; } @@ -241,15 +139,6 @@ public class ProjectReference implements Displayable { return projectPath; } - public static ProjectReference getProject(UUID project) { - for (ProjectReference ref : projects) { - if (ref.uuid.equals(project)) { - return ref; - } - } - return null; - } - private StringProperty displayProperty = new SimpleStringProperty(toString()); @Override diff --git a/PlayWallCore/src/de/tobias/playpad/project/ref/ProjectReferenceSerializer.java b/PlayWallCore/src/de/tobias/playpad/project/ref/ProjectReferenceSerializer.java index 4c92383e76f577f22ea9f7921f83cabc08954940..448e369358aef6bf48c9791c129f900a64852f18 100644 --- a/PlayWallCore/src/de/tobias/playpad/project/ref/ProjectReferenceSerializer.java +++ b/PlayWallCore/src/de/tobias/playpad/project/ref/ProjectReferenceSerializer.java @@ -11,7 +11,8 @@ import org.dom4j.Element; import de.tobias.playpad.plugin.Module; import de.tobias.playpad.plugin.ModuleSerializer; -import de.tobias.playpad.settings.ProfileReference; +import de.tobias.playpad.profile.ref.ProfileReference; +import de.tobias.playpad.profile.ref.ProfileReferences; import de.tobias.utils.application.ApplicationUtils; import de.tobias.utils.application.container.PathType; import de.tobias.utils.xml.XMLDeserializer; @@ -34,7 +35,7 @@ public class ProjectReferenceSerializer implements XMLDeserializer<ProjectRefere XMLHandler<Module> handler = new XMLHandler<>(element); Set<Module> modules = new HashSet<>(handler.loadElements(MODULE_ELEMENT, new ModuleSerializer())); - ProfileReference profileRef = ProfileReference.getReference(profile); + ProfileReference profileRef = ProfileReferences.getReference(profile); ProjectReference ref = new ProjectReference(uuid, name, profileRef, modules); Path projectPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, ref.getFileName()); diff --git a/PlayWallCore/src/de/tobias/playpad/project/ref/ProjectReferences.java b/PlayWallCore/src/de/tobias/playpad/project/ref/ProjectReferences.java new file mode 100644 index 0000000000000000000000000000000000000000..67fc41d20bc0a588b5a47fbb5616ddbfa54525a1 --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/project/ref/ProjectReferences.java @@ -0,0 +1,121 @@ +package de.tobias.playpad.project.ref; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; + +import de.tobias.playpad.project.Project; +import de.tobias.utils.application.ApplicationUtils; +import de.tobias.utils.application.container.PathType; +import de.tobias.utils.xml.XMLHandler; + +public final class ProjectReferences { + + private ProjectReferences() {} + + private static List<ProjectReference> projects = new ProjectReferenceList(); + private static boolean loadedProjectOverview = false; + + public static ProjectReference getProject(UUID project) { + for (ProjectReference ref : projects) { + if (ref.getUuid().equals(project)) { + return ref; + } + } + return null; + } + + public static void addProject(ProjectReference item) throws UnsupportedEncodingException, IOException { + if (!projects.contains(item)) { + projects.add(item); + } + saveProjects(); + } + + public static void removeDocument(ProjectReference projectReference) throws DocumentException, IOException { + Path path = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, projectReference.getUuid() + Project.FILE_EXTENSION); + + Files.deleteIfExists(path); // DIRVE + projects.remove(projectReference); // MODEL + saveProjects(); + } + + public static ProjectReference duplicate(ProjectReference currentProject, String name) throws IOException { + ProjectReference newProjectReference = new ProjectReference(UUID.randomUUID(), name, currentProject.getProfileReference()); + addProject(newProjectReference); + + duplicateFiles(currentProject, newProjectReference); + + saveProjects(); + return newProjectReference; + } + + private static void duplicateFiles(ProjectReference currentProject, ProjectReference newProjectReference) throws IOException { + Path oldPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, currentProject.getName()); + Path newPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, newProjectReference.getName()); + Files.copy(oldPath, newPath, StandardCopyOption.COPY_ATTRIBUTES); + } + + public static List<ProjectReference> getProjects() { + if (!loadedProjectOverview) + try { + loadProjects(); + } catch (DocumentException | IOException e) { + e.printStackTrace(); + } + return projects; + } + + // Load and Save + private static final String FILE_NAME = "Projects.xml"; + private static final String PROJECT_ELEMENT = "Project"; + private static final String ROOT_ELEMENT = "Settings"; + + public static void loadProjects() throws DocumentException, IOException { + Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, FILE_NAME); + if (Files.exists(path)) { + XMLHandler<ProjectReference> loader = new XMLHandler<>(path); + projects = loader.loadElements(PROJECT_ELEMENT, new ProjectReferenceSerializer()); + } + loadedProjectOverview = true; + } + + public static void saveProjects() throws UnsupportedEncodingException, IOException { + Document document = DocumentHelper.createDocument(); + Element root = document.addElement(ROOT_ELEMENT); + + XMLHandler<ProjectReference> handler = new XMLHandler<>(root); + handler.saveElements(PROJECT_ELEMENT, projects, new ProjectReferenceSerializer()); + + Path path = ApplicationUtils.getApplication().getPath(PathType.CONFIGURATION, FILE_NAME); + if (Files.notExists(path)) { + Files.createDirectories(path.getParent()); + Files.createFile(path); + } + XMLHandler.save(path, document); + } + + public static List<ProjectReference> getProjectsSorted() { + if (!loadedProjectOverview) + try { + loadProjects(); + } catch (DocumentException | IOException e) { + e.printStackTrace(); + } + + List<ProjectReference> items = new ArrayList<>(); + projects.forEach(item -> items.add(item)); + items.sort((o1, o2) -> Long.compare(o2.getLastMofied(), o1.getLastMofied())); + return items; + } +} diff --git a/PlayWallCore/src/de/tobias/playpad/settings/Fade.java b/PlayWallCore/src/de/tobias/playpad/settings/Fade.java index 48c9d864b835df013f86031d27131dfbf4a77cb4..0a30c6032cd1fbd883998fedf3b833fc64b96202 100644 --- a/PlayWallCore/src/de/tobias/playpad/settings/Fade.java +++ b/PlayWallCore/src/de/tobias/playpad/settings/Fade.java @@ -2,8 +2,20 @@ package de.tobias.playpad.settings; import org.dom4j.Element; +import de.tobias.playpad.pad.PadSettings; import javafx.util.Duration; +/** + * Einstellungen zum Fading, zusammengefasst in dieser Klasse. + * + * @author tobias + * + * @since 6.0.0 + * + * @see ProfileSettings#getFade() + * @see PadSettings#getFade() + * + */ public class Fade { private Duration fadeIn; @@ -14,19 +26,48 @@ public class Fade { private boolean fadeOutPause; private boolean fadeOutStop; + /** + * Erstellt ein neues Fading mit den Default Werten. (Fade Dauer: 0 sec) + */ public Fade() { - fadeIn = Duration.ZERO; - fadeOut = Duration.ZERO; - - fadeInStart = false; - fadeInPause = true; - fadeOutPause = true; - fadeOutStop = true; + this(Duration.ZERO, Duration.ZERO); } + /** + * Erstellt einen neues Fading mit Custom Zeiten und Default Einstellungen für Play, Pause, Stop. + * + * @param fadeIn + * Fade In Dauer + * @param fadeOut + * Fade Out Dauer + */ public Fade(Duration fadeIn, Duration fadeOut) { + this(fadeIn, fadeOut, false, true, true, true); + } + + /** + * Erstellt ein Fading mit Custom Werten. + * + * @param fadeIn + * Fade In Dauer + * @param fadeOut + * Fade Out Dauer + * @param fadeInStart + * Fade beim Start + * @param fadeInPause + * Fade nach Pause + * @param fadeOutPause + * Fade vor Pause + * @param fadeOutStop + * Fade vor Stop + */ + public Fade(Duration fadeIn, Duration fadeOut, boolean fadeInStart, boolean fadeInPause, boolean fadeOutPause, boolean fadeOutStop) { this.fadeIn = fadeIn; this.fadeOut = fadeOut; + this.fadeInStart = fadeInStart; + this.fadeInPause = fadeInPause; + this.fadeOutPause = fadeOutPause; + this.fadeOutStop = fadeOutStop; } public Duration getFadeIn() { @@ -77,6 +118,10 @@ public class Fade { this.fadeOutStop = fadeOutStop; } + /* + * Serialize + */ + private static final String FADE_OUT = "FadeOut"; private static final String FADE_IN = "FadeIn"; @@ -114,7 +159,9 @@ public class Fade { fade.setFadeOutStop(Boolean.valueOf(fadeOutElement.attributeValue(ON_STOP_ATTR))); fade.setFadeOut(Duration.valueOf(fadeOutElement.getStringValue().replace(" ", ""))); return fade; - } catch (Exception e) {} + } catch (Exception e) { + e.printStackTrace(); + } return null; } } diff --git a/PlayWallCore/src/de/tobias/playpad/settings/Profile.java b/PlayWallCore/src/de/tobias/playpad/settings/Profile.java index 35ea90703f7cd314457bbdbc018348d3175b52c5..cd8b78e90bf865042eca8da35b54b1f833f0a3d1 100644 --- a/PlayWallCore/src/de/tobias/playpad/settings/Profile.java +++ b/PlayWallCore/src/de/tobias/playpad/settings/Profile.java @@ -14,6 +14,8 @@ import de.tobias.playpad.PlayPadPlugin; import de.tobias.playpad.action.MappingList; import de.tobias.playpad.design.DesignConnect; import de.tobias.playpad.design.GlobalDesign; +import de.tobias.playpad.profile.ref.ProfileReference; +import de.tobias.playpad.profile.ref.ProfileReferences; import de.tobias.playpad.registry.DefaultRegistry; import de.tobias.playpad.registry.NoSuchComponentException; import de.tobias.utils.application.App; @@ -38,7 +40,13 @@ public class Profile { private MappingList mappings; private HashMap<String, GlobalDesign> layouts; - Profile(ProfileReference ref) { + /** + * Use {@link ProfileReferences#addProfile(ProfileReference)} instead + * + * @param ref + * Ref + */ + public Profile(ProfileReference ref) { this.ref = ref; this.profileSettings = new ProfileSettings(); this.mappings = new MappingList(this); @@ -140,7 +148,7 @@ public class Profile { public void save() throws UnsupportedEncodingException, IOException { ref.getRequestedModules().clear(); - + PlayPadPlugin.getImplementation().getSettingsListener().forEach(l -> { try { diff --git a/PlayWallCore/src/de/tobias/playpad/settings/ProfileNotFoundException.java b/PlayWallCore/src/de/tobias/playpad/settings/ProfileNotFoundException.java index ddf59e72d88f646e644a6139b03fca3c4c569073..ab1cb36b5a12c8c1d3a15bbd1666472a742b9b25 100644 --- a/PlayWallCore/src/de/tobias/playpad/settings/ProfileNotFoundException.java +++ b/PlayWallCore/src/de/tobias/playpad/settings/ProfileNotFoundException.java @@ -1,5 +1,7 @@ package de.tobias.playpad.settings; +import de.tobias.playpad.profile.ref.ProfileReference; + public class ProfileNotFoundException extends Exception { private static final long serialVersionUID = 1L; diff --git a/PlayWallCore/src/de/tobias/playpad/settings/Warning.java b/PlayWallCore/src/de/tobias/playpad/settings/Warning.java deleted file mode 100644 index edb1944b0f630b1b7b6535eb4d235844714e5f39..0000000000000000000000000000000000000000 --- a/PlayWallCore/src/de/tobias/playpad/settings/Warning.java +++ /dev/null @@ -1,51 +0,0 @@ -package de.tobias.playpad.settings; - -import org.dom4j.Element; - -import de.tobias.utils.settings.SettingsSerializable; -import de.tobias.utils.settings.Storable; -import javafx.util.Duration; - -@Deprecated -public class Warning implements SettingsSerializable { - - private static final long serialVersionUID = 1L; - - @Storable private Duration time; - - public Warning() { - time = Duration.seconds(5); - } - - public Warning(Duration time) { - this.time = time; - } - - public Duration getTime() { - return time; - } - - public void setTime(Duration time) { - this.time = time; - } - - private static final String TIME_ELEMENT = "Time"; - - public static Warning load(Element feedbackElement) { - try { - if (feedbackElement.element(TIME_ELEMENT) != null) { - Duration dutation = Duration.valueOf(feedbackElement.element(TIME_ELEMENT).getStringValue().replace(" ", "")); - Warning warning = new Warning(dutation); - return warning; - } - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - public Element save(Element feedbackElement) { - feedbackElement.addElement(TIME_ELEMENT).addText(time.toString()); - return feedbackElement; - } -} diff --git a/PlayWallCore/src/de/tobias/playpad/settings/keys/Key.java b/PlayWallCore/src/de/tobias/playpad/settings/keys/Key.java index 7ae9e3c5bf7f7a64ef8970e00bf2fe5efc5f8bee..a281973d495050875b66a05f0039aeb797000a0d 100644 --- a/PlayWallCore/src/de/tobias/playpad/settings/keys/Key.java +++ b/PlayWallCore/src/de/tobias/playpad/settings/keys/Key.java @@ -5,6 +5,13 @@ import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.scene.input.KeyCombination; +/** + * Eine Tastenkombination für das Mapping zum Menü. + * + * @author tobias + * + * @since 5.1.0 + */ public class Key implements Displayable { private String id; @@ -15,10 +22,32 @@ public class Key implements Displayable { private boolean meta; private boolean shift; + /** + * Erstellt eine leere Tastenkombination. + * + * @param id + * ID für die Speicherung + */ public Key(String id) { this.id = id; } + /** + * Erstellt eine Vollständige Tastenkombination mit ID und Datenwerten. + * + * @param id + * ID f+r doe Speicherung + * @param key + * Taste + * @param ctrl + * ctrl + * @param alt + * alt + * @param meta + * meta (Mac: CMD) + * @param shift + * shift + */ public Key(String id, String key, boolean ctrl, boolean alt, boolean meta, boolean shift) { this.id = id; @@ -83,26 +112,30 @@ public class Key implements Displayable { return id; } + /** + * Gibt die Tastenkombination als String für das Menü in JavaFX zurück. + * + * @return + */ public String getKeyCode() { StringBuilder builder = new StringBuilder(); if (ctrl) builder.append("ctrl+"); - if (alt) builder.append("alt+"); - if (meta) builder.append("meta+"); - if (shift) builder.append("shift+"); - builder.append(key); return builder.toString(); } + /** + * Gibt die Tastenkombination von JavaFX geparsed zurück. Diese wird dann für das Menü und die Darstellung verwendet. + */ @Override public String toString() { if (!getKeyCode().isEmpty()) @@ -115,7 +148,7 @@ public class Key implements Displayable { return ""; } - private StringProperty displayProperty = new SimpleStringProperty(); + private transient StringProperty displayProperty = new SimpleStringProperty(); @Override public StringProperty displayProperty() { diff --git a/PlayWallCore/src/de/tobias/playpad/settings/keys/KeyCollection.java b/PlayWallCore/src/de/tobias/playpad/settings/keys/KeyCollection.java index 4c209a3b8b0dedb397a6371e8ea1e08f48412ea5..f68eb96920886c940d6ea24ffd8aa4f17d8e822a 100644 --- a/PlayWallCore/src/de/tobias/playpad/settings/keys/KeyCollection.java +++ b/PlayWallCore/src/de/tobias/playpad/settings/keys/KeyCollection.java @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.ResourceBundle; +import java.util.stream.Collectors; import org.dom4j.Document; import org.dom4j.DocumentException; @@ -24,32 +25,54 @@ import de.tobias.utils.xml.XMLHandler; public class KeyCollection { // Schlüssel: ID, Value: Key - private HashMap<String, Key> keys; - private HashMap<String, String> names; + private HashMap<String, KeyCollectionEntry> keys; + /** + * Erstellt ein neues, leeres Mapping. + */ public KeyCollection() { keys = new HashMap<>(); - names = new HashMap<>(); } - public void register(Key key) { - if (!keys.containsKey(key.getId())) { - if (!keysConflict(key)) { - keys.put(key.getId(), key); + /** + * Fügt eine Taste zum Mapping hinzu. + * + * @param entry + * Taste + * @throws KeyConflictException + * Registrierung fehlgeschlagen, weil Key bereits vorhanden. + */ + public void register(KeyCollectionEntry entry) throws KeyConflictException { + if (!keys.containsKey(entry.getKey().getId())) { + if (!keysConflict(entry.getKey())) { + keys.put(entry.getKey().getId(), entry); + } else { + throw new KeyConflictException(entry.getKey()); } } } + /** + * Name des Keys. + * + * @param id + * ID der Kombination + * @return Localized Name + */ public String getName(String id) { - return names.get(id); + return keys.get(id).getName(); } public Key getKey(String id) { - return keys.get(id); + return keys.get(id).getKey(); + } + + private void updateKey(Key key) { + keys.get(key.getId()).setKey(key); } public Collection<Key> getKeys() { - return keys.values(); + return keys.values().stream().map(KeyCollectionEntry::getKey).collect(Collectors.toList()); } /** @@ -66,32 +89,50 @@ public class KeyCollection { key.setKey(""); } + /** + * Prüft ob es einen Konflikt zu anderen Key Combinations gibt. + * + * @param key + * Test Objekt + * @return <code>true</code> Konflikt. + */ public boolean keysConflict(Key key) { - for (Key k : keys.values()) { - if (k.getKeyCode().equals(key.getKeyCode())) { + for (KeyCollectionEntry k : keys.values()) { + if (k.getKey().getKeyCode().equals(key.getKeyCode())) { return true; } } return false; } - + + /** + * Sucht nach den konkreten Konflikten. + * + * @param key + * Test Objekt + * @return Liste der Konflikte. + */ public List<Key> getConflicts(Key key) { List<Key> conflicts = new ArrayList<>(); - for (Key k : keys.values()) { - if (k.getKeyCode().equals(key.getKeyCode())) { - conflicts.add(k); + for (KeyCollectionEntry k : keys.values()) { + if (k.getKey().getKeyCode().equals(key.getKeyCode())) { + conflicts.add(k.getKey()); } } return conflicts; } + /* + * Speicher & Laden + */ + private static final String KEY_ELEMENT = "Key"; public void load(Element element) { XMLHandler<Key> handler = new XMLHandler<>(element); List<Key> keys = handler.loadElements(KEY_ELEMENT, new KeySerializer()); for (Key key : keys) { - register(key); + updateKey(key); } } @@ -103,6 +144,14 @@ public class KeyCollection { private static final String WINDOWS_KEYS = "Windows"; private static final String MAC_KEYS = "Mac"; + /** + * Lädt die Default Liste an vorhanden Keys. + * + * @param classPath + * Pfad zu der XML Datei mit den Keys. + * @param bundle + * ResourceBundle für die Namen der Kombinationen. + */ public void loadDefaultFromFile(String classPath, ResourceBundle bundle) { SAXReader reader = new SAXReader(); try { @@ -124,9 +173,14 @@ public class KeyCollection { String name = loadName(keyElement, bundle); Key key = keySerializer.loadElement(keyElement); - - names.put(key.getId(), name); - register(key); + KeyCollectionEntry entry = new KeyCollectionEntry(name, key); + + try { + register(entry); + } catch (KeyConflictException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } } } @@ -135,6 +189,15 @@ public class KeyCollection { } } + /** + * Lädt den Namen des Keys auf dem Bundle anhand der XML Eintrages. + * + * @param element + * XML Eintrag + * @param bundle + * ResourceBundle + * @return Name oder null + */ private String loadName(Element element, ResourceBundle bundle) { String name = element.attributeValue("name"); if (name != null) { @@ -143,6 +206,12 @@ public class KeyCollection { return null; } + /** + * Change an Interal Key with this new settings + * + * @param newKey + * virtal copy. + */ public void editKey(Key newKey) { Key savedKey = getKey(newKey.getId()); diff --git a/PlayWallCore/src/de/tobias/playpad/settings/keys/KeyCollectionEntry.java b/PlayWallCore/src/de/tobias/playpad/settings/keys/KeyCollectionEntry.java new file mode 100644 index 0000000000000000000000000000000000000000..9d90cf8f5e8f0aa606ea34748fc998bf0269fb8f --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/settings/keys/KeyCollectionEntry.java @@ -0,0 +1,32 @@ +package de.tobias.playpad.settings.keys; + +/** + * Datenstruktur für die KeyCollection, zum speichern der Einträge. + * + * @author tobias + * + * @since 6.0.0 + */ +class KeyCollectionEntry { + + private final String name; + private Key key; + + public KeyCollectionEntry(String name, Key key) { + this.name = name; + this.key = key; + } + + public String getName() { + return name; + } + + public Key getKey() { + return key; + } + + public void setKey(Key key) { + this.key = key; + } + +} diff --git a/PlayWallCore/src/de/tobias/playpad/settings/keys/KeyConflictException.java b/PlayWallCore/src/de/tobias/playpad/settings/keys/KeyConflictException.java new file mode 100644 index 0000000000000000000000000000000000000000..6590027a19c382cd001bae0d3800d28d8da2a111 --- /dev/null +++ b/PlayWallCore/src/de/tobias/playpad/settings/keys/KeyConflictException.java @@ -0,0 +1,17 @@ +package de.tobias.playpad.settings.keys; + +/** + * Exception wenn Key nicht hinzugefügt werden kann, aufgrund eines Konflikts. + * + * @author tobias + * + * @since 6.0.0 + */ +public class KeyConflictException extends Exception { + + private static final long serialVersionUID = 1L; + + public KeyConflictException(Key key) { + super("Key: " + key.toString() + " cannot be used, caused by an conflict"); + } +} diff --git a/PlayWallPlugins/equalizerplugin/de/tobias/playpad/equalizerplugin/main/impl/EqualizerPluginImpl.java b/PlayWallPlugins/equalizerplugin/de/tobias/playpad/equalizerplugin/main/impl/EqualizerPluginImpl.java index f12a8dcb0700673574f8917f4b6651770b7734a2..e45b66e579f232a0f788d4b11fb0403642f60a95 100644 --- a/PlayWallPlugins/equalizerplugin/de/tobias/playpad/equalizerplugin/main/impl/EqualizerPluginImpl.java +++ b/PlayWallPlugins/equalizerplugin/de/tobias/playpad/equalizerplugin/main/impl/EqualizerPluginImpl.java @@ -22,7 +22,6 @@ import de.tobias.utils.application.container.PathType; import de.tobias.utils.util.Localization; import javafx.event.ActionEvent; import javafx.event.EventHandler; -import javafx.fxml.FXML; import javafx.scene.control.MenuItem; import javafx.scene.media.AudioEqualizer; import javafx.scene.media.EqualizerBand;