Skip to content
Snippets Groups Projects
Cell.java 1.63 KiB
Newer Older
  • Learn to ignore specific revisions
  • Guyslain's avatar
    Guyslain committed
    import datastruct.Lens;
    
    import java.util.ArrayList;
    import java.util.List;
    
     * A class representing a cell that holds a value and allows adding listeners to track value changes.
     *
     * @param <T> The type of value stored in the cell.
    
    Guyslain's avatar
    Guyslain committed
    public class Cell<T> implements Lens<T> {
    
    Guyslain's avatar
    Guyslain committed
    
        //TODO: ajouter la ou les propriétés nécessaires
    
        // la liste des objets écoutant les modifications du contenu de la cellule
    
    Guyslain's avatar
    Guyslain committed
        private final List<OnChangeListener<T>> listeners = new ArrayList<>();
    
    Guyslain's avatar
    Guyslain committed
        /** Initialize a new cell with a given value.
    
    Guyslain's avatar
    Guyslain committed
         * @param initialContent the value initially stored by the cell.
    
    Guyslain's avatar
    Guyslain committed
        public Cell(T initialContent) {
    
    Guyslain's avatar
    Guyslain committed
            //TODO: à compléter
    
        /** Add a {@link OnChangeListener} to react to any change of value in the cell.
         *
         * @param listener the {@link OnChangeListener} to activate when the value in the cell is
         *                 changed.
         */
    
    Guyslain's avatar
    Guyslain committed
        public void addOnChangeListener(OnChangeListener<T> listener) {
            this.listeners.add(listener);
    
         * Sets the content of this {@link Cell}. This will also call all the listeners that were
         * registered by the method {@code addOnChangeListener}.
    
    Guyslain's avatar
    Guyslain committed
         * @param value the new content of this {@link Cell}
    
    Guyslain's avatar
    Guyslain committed
        public void set(T value) {
    
    Guyslain's avatar
    Guyslain committed
            //TODO: modifier le contenu de la cellule, puis appeler les méthodes valueChanged des
            // listeners
    
    Guyslain's avatar
    Guyslain committed
         * Returns the current content of this {@link Cell}.
    
    Guyslain's avatar
    Guyslain committed
         * @return the current content of this {@link Cell}
    
    Guyslain's avatar
    Guyslain committed
        public T get(){
    
    Guyslain's avatar
    Guyslain committed
            //TODO: à compléter
            return null;