From e0f032ad26f51ccda1e1d0968fd24194d7a77176 Mon Sep 17 00:00:00 2001 From: tobias <tobias.ullerich@icloud.com> Date: Sun, 10 Jul 2016 20:46:42 +0200 Subject: [PATCH] Add comments & code clean & refectoring --- .../dialog/DuplicateProjectDialog.java | 2 +- .../dialog/NewProjectDialog.java | 2 +- .../dialog/ProjectManagerDialog.java | 2 +- PlayWallCore/.gitignore | 3 +- .../de/tobias/playpad/project/Importable.java | 26 ++++++ .../playpad/project/ProfileChooseable.java | 12 +++ .../de/tobias/playpad/project/Project.java | 80 ++++++++++++++++--- .../playpad/project/ProjectReference.java | 7 ++ 8 files changed, 119 insertions(+), 15 deletions(-) diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/DuplicateProjectDialog.java b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/DuplicateProjectDialog.java index d4bbfd86..2b3b7505 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/DuplicateProjectDialog.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/DuplicateProjectDialog.java @@ -40,7 +40,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.projectNameEx)) { + if (ProjectReference.getProjects().contains(c) || !c.matches(Project.PROJECT_NAME_PATTERN)) { button.setDisable(true); } else { button.setDisable(false); diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/NewProjectDialog.java b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/NewProjectDialog.java index 973a5a43..3a887b22 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/NewProjectDialog.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/NewProjectDialog.java @@ -57,7 +57,7 @@ public class NewProjectDialog extends ViewController { if (c.isEmpty()) { finishButton.setDisable(true); } else { - if (ProjectReference.getProjects().contains(c) || !c.matches(Project.projectNameEx)) { + if (ProjectReference.getProjects().contains(c) || !c.matches(Project.PROJECT_NAME_PATTERN)) { finishButton.setDisable(true); return; } diff --git a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/ProjectManagerDialog.java b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/ProjectManagerDialog.java index da665cd0..6de43dc9 100644 --- a/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/ProjectManagerDialog.java +++ b/PlayWall/src/de/tobias/playpad/viewcontroller/dialog/ProjectManagerDialog.java @@ -201,7 +201,7 @@ public class ProjectManagerDialog extends ViewController implements Notification try { String newProjectName = (String) nameTextField.getText(); - if (ProjectReference.getProjects().contains(newProjectName) || !nameTextField.getText().matches(Project.projectNameEx)) { + if (ProjectReference.getProjects().contains(newProjectName) || !nameTextField.getText().matches(Project.PROJECT_NAME_PATTERN)) { showErrorMessage(Localization.getString(Strings.Error_Standard_NameInUse, nameTextField.getText())); return; } diff --git a/PlayWallCore/.gitignore b/PlayWallCore/.gitignore index 94faa173..960394d9 100644 --- a/PlayWallCore/.gitignore +++ b/PlayWallCore/.gitignore @@ -1,2 +1,3 @@ /bin/ -/test/ \ No newline at end of file +/test/ +/doc/ diff --git a/PlayWallCore/src/de/tobias/playpad/project/Importable.java b/PlayWallCore/src/de/tobias/playpad/project/Importable.java index 0193b48f..1b3e860e 100644 --- a/PlayWallCore/src/de/tobias/playpad/project/Importable.java +++ b/PlayWallCore/src/de/tobias/playpad/project/Importable.java @@ -2,11 +2,37 @@ package de.tobias.playpad.project; import java.nio.file.Path; +/** + * Delegate Methode vom Model zum Import eines Projektes (mit Profile und Medien optionmal) + * + * @author tobias + * + * @since 5.0.0 + */ public interface Importable { + /** + * Wenn ein Profil bereits vorhanden ist, wird hier nach einem neuen Namen gefragt. + * + * @param name + * Alter name + * @return Neuer Name oder null (dann wird nichts importiert) + */ public String replaceProfile(String name); + /** + * Wenn ein Projekt bereits vorhanden ist, wird hier nach einem neuen Namen gefragt. + * + * @param name + * Alter name + * @return Neuer Name oder null (dann wird nichts importiert) + */ public String replaceProject(String name); + /** + * Frage nach dem Ordner für die Mediendateien. + * + * @return Ordner zum Import. + */ public Path mediaFolder(); } \ No newline at end of file diff --git a/PlayWallCore/src/de/tobias/playpad/project/ProfileChooseable.java b/PlayWallCore/src/de/tobias/playpad/project/ProfileChooseable.java index 36d4062c..11b53720 100644 --- a/PlayWallCore/src/de/tobias/playpad/project/ProfileChooseable.java +++ b/PlayWallCore/src/de/tobias/playpad/project/ProfileChooseable.java @@ -2,7 +2,19 @@ package de.tobias.playpad.project; import de.tobias.playpad.settings.Profile; +/** + * Dieses Interface stellt Methoden für die Wahl des Profiles für ein Projekt bereit. + * + * @author tobias + * + * @since 5.0.0 + */ public interface ProfileChooseable { + /** + * Wird von der API beim Projekt laden aufgerunfen, wenn das referenzierte Projekt nicht gefunden wurde. + * + * @return Neues Profile + */ public Profile getUnkownProfile(); } \ No newline at end of file diff --git a/PlayWallCore/src/de/tobias/playpad/project/Project.java b/PlayWallCore/src/de/tobias/playpad/project/Project.java index d0d6e24a..299a0bdd 100644 --- a/PlayWallCore/src/de/tobias/playpad/project/Project.java +++ b/PlayWallCore/src/de/tobias/playpad/project/Project.java @@ -19,52 +19,110 @@ import de.tobias.playpad.pad.PadException; import de.tobias.playpad.pad.PadStatus; import de.tobias.playpad.settings.Profile; import de.tobias.playpad.settings.ProfileNotFoundException; -import de.tobias.utils.application.ApplicationUtils; -import de.tobias.utils.application.container.PathType; import javafx.application.Platform; import javafx.collections.FXCollections; import javafx.collections.ObservableList; +/** + * Hold all information about the pads and it's settings. + * + * @author tobias + * + */ public class Project { - public static final String projectNameEx = "\\w{1}[\\w\\s-_]{0,}"; + /** + * Pattern für den Namen des Projekts + */ + public static final String PROJECT_NAME_PATTERN = "\\w{1}[\\w\\s-_]{0,}"; + /** + * Dateiendung für eine projekt Datei + */ public static final String FILE_EXTENSION = ".xml"; + /** + * Die projektreferenz gibt auskunft über den Namen und die UUID des Projektes + */ private ProjectReference ref; + /** + * Liste mit allen Pads. + */ private HashMap<Integer, Pad> pads; + /** + * Liste mit den aktuellen Laufzeitfehlern. + */ private ObservableList<PadException> exceptions; + /** + * Erstellt ein neues leeres Projekt mit einer Referenz. + * + * @param ref + * Referenz mit Namen des Projekts. + */ public Project(ProjectReference ref) { this.ref = ref; this.pads = new HashMap<>(); this.exceptions = FXCollections.observableArrayList(); } + /** + * Gibt die Projekt Referenz zurück. Dazu zählen Name und UUID sowie das zugehörige Profile. + * + * @return Referenz. + */ public ProjectReference getRef() { return ref; } + // TODO Update in 5.1.0 + /** + * Gibt ein Pad an einem Index zurück. Sollte kein pad vorhanden sein (weil null, so wird vorher ein neues erzeugt.) + * + * @param index + * Index + * @return Pad am Index i + */ public Pad getPad(int index) { - if (pads.containsKey(index)) { - return pads.get(index); - } else { - pads.put(index, new Pad(this, index)); // Create Pad if not exists - return pads.get(index); + if (!pads.containsKey(index)) { + addPadForIndex(index); } + return pads.get(index); + } + + /** + * Erstellt ein neues leeres Pad (mit Referenz zu diesem Projekt) am Index i. + * + * @param index + * Index i + */ + private void addPadForIndex(int index) { + pads.put(index, new Pad(this, index)); } + /** + * Ersetz ein Pad an einem Index i. + * + * @param index + * Index i + * @param pad + * Neues Pad für den Index i + */ public void setPad(int index, Pad pad) { pad.setIndex(index); pads.put(index, pad); } + /* + * Speichern und Laden + */ + private static final String ROOT_ELEMENT = "Project"; - static final String PAD_ELEMENT = "Pad"; + protected static final String PAD_ELEMENT = "Pad"; public static Project load(ProjectReference ref, boolean loadMedia, ProfileChooseable profileChooseable) throws DocumentException, IOException, ProfileNotFoundException, ProjectNotFoundException { + Path projectPath = ref.getProjectPath(); - Path projectPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, ref.getFileName()); if (Files.exists(projectPath)) { SAXReader reader = new SAXReader(); Document document = reader.read(Files.newInputStream(projectPath)); @@ -103,7 +161,7 @@ public class Project { } public void save() throws IOException { - Path projectPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, ref.getFileName()); + Path projectPath = ref.getProjectPath(); Document document = DocumentHelper.createDocument(); Element rootElement = document.addElement(ROOT_ELEMENT); diff --git a/PlayWallCore/src/de/tobias/playpad/project/ProjectReference.java b/PlayWallCore/src/de/tobias/playpad/project/ProjectReference.java index aabe2871..1ca57c65 100644 --- a/PlayWallCore/src/de/tobias/playpad/project/ProjectReference.java +++ b/PlayWallCore/src/de/tobias/playpad/project/ProjectReference.java @@ -19,6 +19,7 @@ import org.dom4j.io.XMLWriter; import de.tobias.playpad.Displayable; 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 javafx.beans.property.SimpleStringProperty; @@ -237,6 +238,12 @@ public class ProjectReference implements Displayable { return uuid + Project.FILE_EXTENSION; } + public Path getProjectPath() { + App application = ApplicationUtils.getApplication(); + Path projectPath = application.getPath(PathType.DOCUMENTS, getFileName()); + return projectPath; + } + public static ProjectReference getProject(UUID project) { for (ProjectReference ref : projects) { if (ref.uuid.equals(project)) { -- GitLab