All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fxmisc.undo.UndoManagerFactory Maven / Gradle / Ivy

There is a newer version: 2.1.1
Show newest version
package org.fxmisc.undo;

import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Consumer;

import org.fxmisc.undo.impl.ChangeQueue;
import org.fxmisc.undo.impl.FixedSizeChangeQueue;
import org.fxmisc.undo.impl.UndoManagerImpl;
import org.fxmisc.undo.impl.UnlimitedChangeQueue;
import org.fxmisc.undo.impl.ZeroSizeChangeQueue;
import org.reactfx.EventStream;

public interface UndoManagerFactory {

     UndoManager create(
            EventStream changeStream,
            Consumer apply,
            Consumer undo);

     UndoManager create(
            EventStream changeStream,
            Consumer apply,
            Consumer undo,
            BiFunction> merge);

    public static  UndoManager unlimitedHistoryUndoManager(
            EventStream changeStream,
            Consumer apply,
            Consumer undo) {
        ChangeQueue queue = new UnlimitedChangeQueue();
        BiFunction> merge = (c1, c2) -> Optional.empty();
        return new UndoManagerImpl<>(queue, apply, undo, merge, changeStream);
    }

    public static  UndoManager unlimitedHistoryUndoManager(
            EventStream changeStream,
            Consumer apply,
            Consumer undo,
            BiFunction> merge) {
        ChangeQueue queue = new UnlimitedChangeQueue();
        return new UndoManagerImpl<>(queue, apply, undo, merge, changeStream);
    }

    public static UndoManagerFactory unlimitedHistoryFactory() {
        return new UndoManagerFactory() {
            @Override
            public  UndoManager create(
                    EventStream changeStream,
                    Consumer apply,
                    Consumer undo) {
                return unlimitedHistoryUndoManager(changeStream, apply, undo);
            }

            @Override
            public  UndoManager create(
                    EventStream changeStream,
                    Consumer apply,
                    Consumer undo,
                    BiFunction> merge) {
                return unlimitedHistoryUndoManager(changeStream, apply, undo, merge);
            }
        };
    }

    public static  UndoManager fixedSizeHistoryUndoManager(
            EventStream changeStream,
            Consumer apply,
            Consumer undo,
            int capacity) {
        ChangeQueue queue = new FixedSizeChangeQueue(capacity);
        BiFunction> merge = (c1, c2) -> Optional.empty();
        return new UndoManagerImpl<>(queue, apply, undo, merge, changeStream);
    }

    public static  UndoManager fixedSizeHistoryUndoManager(
            EventStream changeStream,
            Consumer apply,
            Consumer undo,
            BiFunction> merge,
            int capacity) {
        ChangeQueue queue = new FixedSizeChangeQueue(capacity);
        return new UndoManagerImpl<>(queue, apply, undo, merge, changeStream);
    }

    public static UndoManagerFactory fixedSizeHistoryFactory(int capacity) {
        return new UndoManagerFactory() {
            @Override
            public  UndoManager create(
                    EventStream changeStream,
                    Consumer apply,
                    Consumer undo) {
                return fixedSizeHistoryUndoManager(changeStream, apply, undo, capacity);
            }

            @Override
            public  UndoManager create(
                    EventStream changeStream,
                    Consumer apply,
                    Consumer undo,
                    BiFunction> merge) {
                return fixedSizeHistoryUndoManager(changeStream, apply, undo, merge, capacity);
            }
        };
    }

    public static  UndoManager zeroHistoryUndoManager(EventStream changeStream) {
        ChangeQueue queue = new ZeroSizeChangeQueue<>();
        return new UndoManagerImpl<>(queue, c -> {}, c -> {}, (c1, c2) -> Optional.empty(), changeStream);
    }

    public static UndoManagerFactory zeroHistoryFactory() {
        return new UndoManagerFactory() {
            @Override
            public  UndoManager create(
                    EventStream changeStream,
                    Consumer apply,
                    Consumer undo) {
                return zeroHistoryUndoManager(changeStream);
            }

            @Override
            public  UndoManager create(
                    EventStream changeStream,
                    Consumer apply,
                    Consumer undo,
                    BiFunction> merge) {
                return zeroHistoryUndoManager(changeStream);
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy