diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/utils/ConfigValues.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/utils/ConfigValues.java new file mode 100644 index 0000000..0af1843 --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/utils/ConfigValues.java @@ -0,0 +1,16 @@ +package edu.ntnu.idi.idatt2003.g40.mappe.utils; + +public enum ConfigValues { + VIEWPORT_WIDTH(600), + VIEWPORT_HEIGHT(600); + + private int value; + + ConfigValues(final int value) { + this.value = value; + } + + public int getValue() { + return value; + } +} diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ViewController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ViewController.java new file mode 100644 index 0000000..5d7a7c0 --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ViewController.java @@ -0,0 +1,77 @@ +package edu.ntnu.idi.idatt2003.g40.mappe.view; + +import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventData; +import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager; +import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventPublisher; + +/** + * Handles logic and event publishing for {@link ViewElement} objects. + * + *

Implements {@link EventPublisher}

+ * + * @param The type of {@link ViewElement} this controller is attached to. We use generics + * because we want to call methods that may be specific for certain view element + * objects, and we want to reduce casting. + * @see ViewElement + * @see EventPublisher + * @see EventManager + * + */ +public abstract class ViewController> + implements EventPublisher { + + /** + * The {@link ViewElement} object this controller is associated with. + * + */ + private final T1 viewElement; + /** + * The {@link EventManager} object to send events to. + * + */ + private final EventManager eventManager; + + /** + * Constructor. + * + * @param viewElement the instance of type T1 this controller is attached to. + * @param eventManager the {@link EventManager} object this controller communicates with. + * + */ + protected ViewController(final T1 viewElement, final EventManager eventManager) { + this.viewElement = viewElement; + this.eventManager = eventManager; + initInteractions(); + } + + /** + * Getter method for the event manager. + * + * @return the {@link EventManager} object. + * + */ + protected EventManager getEventManager() { + return eventManager; + } + + /** + * Getter method for the current view element. + * + * @return the {@link ViewElement} object. + * + */ + public T1 getViewElement() { + return viewElement; + } + + /** + * Abstract method to initialize logic for the view element. + * + */ + protected abstract void initInteractions(); + + @Override + public final void invoke(final EventData data, final EventManager eventManager) { + eventManager.invokeEvent(data); + } +} diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ViewData.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ViewData.java new file mode 100644 index 0000000..06dbdfc --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ViewData.java @@ -0,0 +1,39 @@ +package edu.ntnu.idi.idatt2003.g40.mappe.view; + +/** + * Object containing data about {@link ViewElement} objects. + * + *

Sent in {@link edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventData} + * objects of type SCENE_CHANGE

+ * + *

Handled by the {@link ViewManager} to update and change views

+ * + */ +public class ViewData { + + /** + * Name of the scene. + * + */ + private final String sceneName; + + /** + * Constructor. + * + * @param sceneName the name of the scene. + * + */ + public ViewData(final String sceneName) { + this.sceneName = sceneName; + } + + /** + * Getter method for the scene name. + * + * @return scene name. + * + */ + public String getSceneName() { + return sceneName; + } +} diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ViewElement.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ViewElement.java new file mode 100644 index 0000000..fec4af4 --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ViewElement.java @@ -0,0 +1,155 @@ +package edu.ntnu.idi.idatt2003.g40.mappe.view; + + +import javafx.scene.control.Button; +import javafx.scene.layout.Pane; +import java.util.ArrayList; + +/** + * Base class for view elements, such as the main menu, or list items. + * + *

Extends {@link Pane}

+ * + * @param the type of pane this view element represents. + * + */ +public abstract class ViewElement { + + /** + * List of buttons in this view. + * + */ + private final ArrayList