Skip to content
Snippets Groups Projects
Cell.java 1.47 KiB
Newer Older
  • Learn to ignore specific revisions
  • package model;
    
    import javafx.beans.property.Property;
    import javafx.beans.property.SimpleObjectProperty;
    
    Guyslain's avatar
    Guyslain committed
    import javafx.scene.paint.Color;
    
    
    /**
     * {@link Cell} instances represent the cells of <i>The Game of Life</i>.
     */
    
    
    Guyslain's avatar
    Guyslain committed
    public class Cell<S extends State<S>> {
        private final Property<S> stateProperty;
    
        public Cell(S initialState) {
            this.stateProperty = new SimpleObjectProperty<>(initialState);
        }
    
    Guyslain's avatar
    Guyslain committed
         * Determines the color associated with the state in which
         * this {@link Cell} is.
    
    Guyslain's avatar
    Guyslain committed
         * @return the {@link Color} associated with the state in
         * which this {@link Cell} is
    
    Guyslain's avatar
    Guyslain committed
        public Color getColor() {
            return this.getState().getColor();
    
        }
    
        /**
         * Sets the state of this {@link Cell}.
         *
    
    Guyslain's avatar
    Guyslain committed
         * @param state the new state of this {@link Cell}
    
    Guyslain's avatar
    Guyslain committed
        public void setState(S state) {
            getStateProperty().setValue(state);
    
        }
    
        /**
         * Returns the current state of this {@link Cell}.
         *
         * @return the current state of this {@link Cell}
         */
    
    
    Guyslain's avatar
    Guyslain committed
        public S getState(){
    
            return getStateProperty().getValue();
        }
    
        /**
    
    Guyslain's avatar
    Guyslain committed
         * Change the state of this {@link Cell} to the next possible state.
    
         */
    
        public void toggleState() {
    
    Guyslain's avatar
    Guyslain committed
            setState(getState().next());
    
        }
    
        /**
         * Returns this {@link Cell}'s state property.
         *
         * @return this {@link Cell}'s state property.
         */
    
    Guyslain's avatar
    Guyslain committed
        public Property<S> getStateProperty() {
    
            return stateProperty;
        }
    
    }