org.fxmisc.flowless.CellWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of richtextfx Show documentation
Show all versions of richtextfx Show documentation
FX-Text-Area for formatted text and other special effects.
package org.fxmisc.flowless;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
import javafx.scene.Node;
/**
* Factory class for wrapping a {@link Cell} and running additional code before/after specific methods
*/
abstract class CellWrapper>
implements Cell {
public static >
CellWrapper beforeDispose(C cell, Runnable action) {
return new CellWrapper(cell) {
@Override
public void dispose() {
action.run();
super.dispose();
}
};
}
public static >
CellWrapper afterDispose(C cell, Runnable action) {
return new CellWrapper(cell) {
@Override
public void dispose() {
super.dispose();
action.run();
}
};
}
public static >
CellWrapper beforeReset(C cell, Runnable action) {
return new CellWrapper(cell) {
@Override
public void reset() {
action.run();
super.reset();
}
};
}
public static >
CellWrapper afterReset(C cell, Runnable action) {
return new CellWrapper(cell) {
@Override
public void reset() {
super.reset();
action.run();
}
};
}
public static >
CellWrapper beforeUpdateItem(C cell, Consumer super T> action) {
return new CellWrapper(cell) {
@Override
public void updateItem(T item) {
action.accept(item);
super.updateItem(item);
}
};
}
public static >
CellWrapper afterUpdateItem(C cell, Consumer super T> action) {
return new CellWrapper(cell) {
@Override
public void updateItem(T item) {
super.updateItem(item);
action.accept(item);
}
};
}
public static >
CellWrapper beforeUpdateIndex(C cell, IntConsumer action) {
return new CellWrapper(cell) {
@Override
public void updateIndex(int index) {
action.accept(index);
super.updateIndex(index);
}
};
}
public static >
CellWrapper afterUpdateIndex(C cell, IntConsumer action) {
return new CellWrapper(cell) {
@Override
public void updateIndex(int index) {
super.updateIndex(index);
action.accept(index);
}
};
}
private final C delegate;
public CellWrapper(C delegate) {
this.delegate = delegate;
}
public C getDelegate() {
return delegate;
}
@Override
public N getNode() {
return delegate.getNode();
}
@Override
public boolean isReusable() {
return delegate.isReusable();
}
@Override
public void updateItem(T item) {
delegate.updateItem(item);
}
@Override
public void updateIndex(int index) {
delegate.updateIndex(index);
}
@Override
public void reset() {
delegate.reset();
}
@Override
public void dispose() {
delegate.dispose();
}
@Override
public String toString() {
return delegate.toString();
}
}