Auf Thema antworten

Hallo yfons 123,


vielen Dank für deine Rückmeldung. Ich verstehe aber nicht wirklich was du meinst.


Ich habe mal versucht mein Problem auf ein Minimum an lauffähigem Code zu reduzieren. Der am Ende gepostete Code funktioniert so, mich stört aber das bei meiner Lösung im ViewController 2 public Methoden benötigt werden.


Nochmal zur Anforderung, die View-Technology soll vollkommen variabel sein. Daher auch die Abstraktion via Interface. Also egal ob JavaFX mit oder ohne Animation, AWT oder Swing (dann natürlich mit angepasster Main Klasse und ohne Übergabe der stage Instanz im MainController). Sprich der Main Controller sollte keinerlei Abhängigkeiten zu den JavaFX Packages haben, da ggf. JavaFX auf der Zielplattform gar nicht installiert ist. Wie gesagt, das durchreichen der stage Instanz bitte nicht beachten, das dient nur der Vereinfachung des Codebeispiels.


Demnach nochmal die Frage auf den Punkt gebracht: Gibt es irgendeine Möglichkeit das die showConfirmationDialogue() Methode in der View einen boolschen Rückgabewert bekommt, der erst zurückgegeben wird wenn die FadeOut Transition des btnDialogue abgeschlossen ist? So das ich die btnActionClicked() und btnActionClickedConfirmation(boolean confirm) Methoden im ViewController zusammenfassen kann in der Form


boolean confirm = view.showConfirmationDialogue();

if (confirmed) view.showMessage();


Oder hat jemand eine ganz andere Idee oder Vorschlag zur Umsetzung das das alles vereinfacht ? Bin für jeden Tip / Rat dankbar :)


Vielen Dank !


[CODE=java]package com.example.demo;


import javafx.application.Application;

import javafx.stage.Stage;

import java.io.IOException;


public class Main extends Application {

    @Override

    public void start(Stage stage) throws IOException {

        ViewController vc = new ViewController(stage);

    }


    public static void main(String[] args) {

        launch();

    }

}[/CODE]


[CODE]package com.example.demo;


public interface View {

    public void show();

    public void showConfirmationDialogue();

    public void showMessage();

}[/CODE]


[CODE]package com.example.demo;


import javafx.stage.Stage;


public class ViewController {


    private View view;


    public ViewController (Stage stage){

        view = new AnimatedView(stage, this);

        view.show();

    }


    public void btnActionClicked(){

        view.showConfirmationDialogue();

    }


    public void btnActionClickedConfirmation(boolean confirmed){

        if (confirmed) view.showMessage();

    }

}[/CODE]


[CODE]package com.example.demo;


import javafx.animation.FadeTransition;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.control.Label;

import javafx.scene.layout.Pane;

import javafx.scene.layout.VBox;

import javafx.stage.Stage;

import javafx.util.Duration;


public class AnimatedView implements View{


    private Stage stage;

    private ViewController viewController;

    private Button btnAction, btnDialogue;

    private Label lblMessage;


    public AnimatedView(Stage stage, ViewController viewController){

        this.stage = stage;

        this.viewController = viewController;

        createView();

        addEvents();

    }


    private void createView(){

        Pane pane = new Pane();

        VBox box = new VBox();

        btnAction = new Button("Action");

        //Clicking this Button simulates a Dialog Confirmation

        btnDialogue = new Button("DialogueConfirmation");

        btnDialogue.setOpacity(0);

        lblMessage = new Label("If you read this message all animations should have been finished !");

        lblMessage.setVisible(false);

        box.getChildren().addAll(btnAction, btnDialogue, lblMessage);

        pane.getChildren().add(box);

        Scene scene = new Scene(pane);

        stage.setScene(scene);

    }


    private void addEvents(){

        btnAction.setOnMouseClicked(e->{

            viewController.btnActionClicked();

        });

    }


    @Override

    public void show() {

        stage.show();

    }


    @Override

    public void showConfirmationDialogue() {

        FadeTransition fadeIn = getFadeInTransition();

        fadeIn.setNode(btnDialogue);

        fadeIn.setOnFinished(in->{

            btnDialogue.setOnMouseClicked(e->{

                btnDialogue.setDisable(true);

                FadeTransition fadeOut = getFadeOutTransition();

                fadeOut.setNode(btnDialogue);

                fadeOut.setOnFinished(out->{

                    viewController.btnActionClickedConfirmation(true);

                });

                fadeOut.play();

            });

        });

        fadeIn.play();

    }


    @Override

    public void showMessage() {

        lblMessage.setVisible(true);

    }


    private FadeTransition getFadeInTransition(){

        FadeTransition transition = new FadeTransition();

        transition.setDuration(Duration.millis(3000));

        transition.setFromValue(0);

        transition.setToValue(1);

        return transition;

    }


    private FadeTransition getFadeOutTransition(){

        FadeTransition transition = new FadeTransition();

        transition.setDuration(Duration.millis(3000));

        transition.setFromValue(1);

        transition.setToValue(0);

        return transition;

    }

}[/CODE]



Oben