/** * */ package de.fhswf.in.inf.se.notepadMinusMinus.model; import java.math.BigDecimal; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlValue; import javafx.beans.Observable; import javafx.beans.property.IntegerProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.property.Property; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.util.Callback; /** * A grade with module information. * * @author Stefan Suhren * @version 1.0 */ @XmlRootElement(name = "grade") public class Grade { private static ObservableList gradeValues; private IntegerProperty semester = new SimpleIntegerProperty(1); private StringProperty modulename = new SimpleStringProperty( "Neues Modul"); private IntegerProperty ects = new SimpleIntegerProperty(0); private ObjectProperty grade = new SimpleObjectProperty<>( new BigDecimal("0.0")); private IntegerProperty attempt = new SimpleIntegerProperty(1); /** * Generates an extractor that fires when a property of a list value * changes. * * @return The extractor. */ public static Callback extractor() { return (Grade grade) -> new Observable[] { grade.semesterProperty(), grade.modulenameProperty(), grade.ectsProperty(), grade.gradeProperty(), grade.attemptProperty() }; } /** * Get the semester {@link Property}. * * @return The semester {@link Property}. */ public final IntegerProperty semesterProperty() { return this.semester; } /** * Get the semester. * * @return The semester. */ @XmlAttribute(name = "semester") public final int getSemester() { return this.semesterProperty().get(); } /** * Set the semester. * * @param semester * The new semester. */ public final void setSemester(final int semester) { this.semesterProperty().set(semester); } /** * Get the modulename {@link Property}. * * @return The modulename {@link Property}. */ public final StringProperty modulenameProperty() { return this.modulename; } /** * Get the modulename. * * @return The modulename. */ @XmlAttribute(name = "modulename", required = true) public final String getModulename() { return this.modulenameProperty().get(); } /** * Set the modulename. * * @param modulename * The new modulename. */ public final void setModulename(final String modulename) { this.modulenameProperty().set(modulename); } /** * Get the ects {@link Property}. * * @return The ects {@link Property}. */ public final IntegerProperty ectsProperty() { return this.ects; } /** * Get the ects. * * @return The ects. */ @XmlAttribute(name = "ects") public final int getEcts() { return this.ectsProperty().get(); } /** * Set the ects. * * @param ects * The new ects. */ public final void setEcts(final int ects) { this.ectsProperty().set(ects); } /** * Get the grade {@link Property}. * * @return The grade {@link Property}. */ public final ObjectProperty gradeProperty() { return this.grade; } /** * Get the grade. * * @return The grade. */ @XmlValue public final BigDecimal getGrade() { return this.gradeProperty().get(); } /** * Set the grade. * * @param grade * The new grade. */ public final void setGrade(final BigDecimal grade) { this.gradeProperty().set(grade); } /** * Get the attempt {@link Property}. * * @return The attempt {@link Property}. */ public final IntegerProperty attemptProperty() { return this.attempt; } /** * Get the attempt. * * @return The attempt. */ @XmlAttribute(name = "attempt") public final int getAttempt() { return this.attemptProperty().get(); } /** * Set the attempt. * * @param attempt * The new attempt. */ public final void setAttempt(final int attempt) { this.attemptProperty().set(attempt); } /** * Returns an unmodifiable {@link ObservableList} that contains all valid * grades. * * @return The unmodifiable {@link ObservableList}. */ public static final ObservableList gradeValuesProperty() { if (gradeValues == null) { gradeValues = FXCollections.observableArrayList(); gradeValues.add(new BigDecimal("0.0")); gradeValues.add(new BigDecimal("1.0")); gradeValues.add(new BigDecimal("1.3")); gradeValues.add(new BigDecimal("1.7")); gradeValues.add(new BigDecimal("2.0")); gradeValues.add(new BigDecimal("2.3")); gradeValues.add(new BigDecimal("2.7")); gradeValues.add(new BigDecimal("3.0")); gradeValues.add(new BigDecimal("3.3")); gradeValues.add(new BigDecimal("3.7")); gradeValues.add(new BigDecimal("4.0")); } return FXCollections.unmodifiableObservableList(gradeValues); } }