Skip to content

Commit

Permalink
Update ViewElement.java
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyah committed May 25, 2026
1 parent e2a84b6 commit a0fa328
Showing 1 changed file with 17 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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.utils.Validator;
import java.util.EnumMap;
import java.util.Map;
Expand Down Expand Up @@ -47,31 +46,36 @@ public abstract class ViewElement<T extends Pane, A extends Enum<A>> {
* @param rootPane an instance of type T (defined in the class).
* @param viewName The name of the view as an {@link ViewEnum}.
*
* @throws IllegalArgumentException if parameters are invalid.
*
*/
protected ViewElement(final T rootPane, final ViewEnum viewName, final Class<A> actionEnum) {
protected ViewElement(final T rootPane,
final ViewEnum viewName,
final Class<A> actionEnum)
throws IllegalArgumentException {
this(rootPane, actionEnum);
if (Validator.NOT_EMPTY.isValid(viewName.name())) {
this.viewName = viewName;
} else {
if (!Validator.NOT_EMPTY.isValid(viewName.name())) {
throw new IllegalArgumentException(Validator.NOT_EMPTY.getErrorMessage());
}
this.viewName = viewName;
}

/**
* Constructor without a specific name.
*
* @param rootPane the root of this view.
*
* @throws IllegalArgumentException if parameters are null.
*/
protected ViewElement(final T rootPane, final Class<A> actionEnum) {
if (rootPane != null) {
setRootPane(rootPane);
this.buttonMap = new EnumMap<>(actionEnum);
initLayout();
initStyling();
} else {
protected ViewElement(final T rootPane, final Class<A> actionEnum)
throws IllegalArgumentException {
if (rootPane == null || actionEnum == null) {
throw new IllegalArgumentException("Invalid ViewElement!");
}
setRootPane(rootPane);
this.buttonMap = new EnumMap<>(actionEnum);
initLayout();
initStyling();
}

/**
Expand Down Expand Up @@ -155,21 +159,10 @@ public void setOnAction(final A action, final Runnable logic)
}
}

/**
* Method that defines how view elements set data.
*
* @param <T2> The type of data to set.
* @param data the data to set.
*
*/
public <T2 extends ViewData> void setData(final T2 data) {
setViewName(data.getSceneName());
}

/**
* Method called when updating a view.
* */
public void onUpdate() {

// Empty by default.
}
}

0 comments on commit a0fa328

Please sign in to comment.