ShichimiFX 1.0.1 released

I have added extracted some more classes from my application projects (e.g. from MQTT.fx) and added them as new features to ShichimiFX (and released 1.0.1).

Get the code from my ShichimiFX Bitbucket Repo

Maven

<dependency>
  <groupId>de.jensd</groupId>
  <artifactId>shichimifx</artifactId>
  <version>1.0.1</version>
</dependency>

AnimationDude
Provides support for Fade-in/Fade-out-Transition of controls:
AnimationDude.addInOutFadeTransition(Duration duration, Node node)
AnimationDude.addInOutFadeTransition(Duration duration, Node nodeToFade, Node trigger)

Make a ListCell (this) a trigger to to fade in a button bar on mouse hover:
AnimationDude.addInOutFadeTransition(Duration.millis(200), buttonsBox, this);

public class AnimationDude {
    
    public final static void  addInOutFadeTransition(Duration duration, Node node) {
        addInOutFadeTransition(duration, node, node);
    }

    public final static void  addInOutFadeTransition(Duration duration, Node nodeToFade, Node trigger) {
        nodeToFade.setOpacity(0.0);
        final FadeTransition fadeOutTransition = new FadeTransition(duration, nodeToFade);
        fadeOutTransition.setFromValue(1.0);
        fadeOutTransition.setToValue(0.0);
        final FadeTransition fadeInTransition = new FadeTransition(duration, nodeToFade);
        fadeInTransition.setFromValue(0.0);
        fadeInTransition.setToValue(1.0);
        trigger.setOnMouseEntered(e->{
                    fadeOutTransition.stop();
                    fadeInTransition.play();
        });
        trigger.setOnMouseExited(e->{
                    fadeInTransition.stop();
                    fadeOutTransition.play();
        });
    }
}

ConsoleDude
Provides support for switching System.out/Sytem.err (ConsoleStream)or bypassing a logging output (ConsoleStreamHandler) a JavaFX text components.

Usage

Use “stdOutMessageArea” for System.out and System.err output:
hook StdOut + StdErr: ConsoleDude.hookStdOutTo(stdOutMessageArea);
restore StdOut + StdErr: ConsoleDude.restoreStdOut();

Also you can observe the status, e. g.:
hookButton.disableProperty().bind(ConsoleDude.stdOutHookedProperty());
releaseButton.disableProperty().bind(ConsoleDude.stdOutHookedProperty().not());

Use “logMessageArea” for logging output:
LOGGER.addHandler(ConsoleDude.createConsoleStreamHandler(logMessageArea));

public class ConsoleStream extends OutputStream {

    private final TextInputControl output;

    public ConsoleStream(TextInputControl ta) {
        this.output = ta;
    }

    @Override
    public void write(int i) throws IOException {
        Platform.runLater(() -> {
            output.appendText(String.valueOf((char) i));
        });
    }
}
public class ConsoleStreamHandler extends StreamHandler{

    public ConsoleStreamHandler(OutputStream out, Formatter formatter) {
        super(out, formatter);
    }

    @Override
    public synchronized void publish(LogRecord record) {
        super.publish(record);
        flush();
    }
}
public class ConsoleDude {

    public final static PrintStream STD_OUT = System.out;
    public final static PrintStream STD_ERR = System.err;
    private static BooleanProperty stdOutHooked = new SimpleBooleanProperty();

    public static void hookStdOutTo(TextInputControl outputArea) {
        PrintStream ps = new PrintStream(new ConsoleStream(outputArea), true);
        System.setOut(ps);
        System.setErr(ps);
        stdOutHookedProperty().set(true);
    }

    public static void restoreStdOut() {
        System.setOut(STD_OUT);
        System.setErr(STD_ERR);
        stdOutHookedProperty().set(false);
    }

    public static BooleanProperty stdOutHookedProperty() {
        if (stdOutHooked == null) {
            stdOutHooked = new SimpleBooleanProperty();
        }
        return stdOutHooked;
    }

    public boolean isHooked() {
        return stdOutHookedProperty().get();
    }

    public static ConsoleStreamHandler createConsoleStreamHandler(TextInputControl outputArea) {
        return createConsoleStreamHandler(outputArea,new SimpleFormatter());
    }

    public static ConsoleStreamHandler createConsoleStreamHandler(TextInputControl outputArea, Formatter formatter) {
        return new ConsoleStreamHandler(new ConsoleStream(outputArea), formatter);
    }

}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.