Skip to content

Commit

Permalink
Disable save when gif is not ready
Browse files Browse the repository at this point in the history
  • Loading branch information
krissrex committed Nov 11, 2020
1 parent acef468 commit 79d4a23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import com.polarbirds.gifcreator.*;
import com.polarbirds.gifcreator.javafx.Disposable;
import com.polarbirds.gifcreator.javafx.JavaFxController;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
Expand Down Expand Up @@ -34,6 +37,7 @@ public class GifSettingsController implements Initializable, Disposable, JavaFxC
public Slider delaySlider;
@FXML
public TextField delayField;
@FXML public Button btnSave;

private final ImageCombiner ic;
private final FileManager fm;
Expand All @@ -42,6 +46,8 @@ public class GifSettingsController implements Initializable, Disposable, JavaFxC
private ImageCombiner.OnImageCombineCompleteListener onImageCombineCompleteListener;
private Stage stage;

private BooleanProperty gifIsReady = new SimpleBooleanProperty(false);

public GifSettingsController() {
SharedState state = SharedState.getInstance();
this.ic = state.imageCombiner;
Expand All @@ -52,26 +58,27 @@ public GifSettingsController() {
public void initialize(URL location, ResourceBundle resources) {
this.onLoadCompleteListener = () -> {
System.out.println("" + fm.getImages().length + " files loaded.");
loadingLabel.setVisible(true);
gifIsReady.setValue(false);
ic.setImages(fm.getImages());
ic.generate();
};
fm.addListener(this.onLoadCompleteListener);

this.onImageCombineCompleteListener = (success) -> {
loadingLabel.setVisible(false);
if (success) {
System.out.println("Gif generated.");
gifPreview.setImage(ic.getGif());
gifIsReady.setValue(true);
} else {
System.err.println("Gif generation failed.");

}
};
ic.addListener(this.onImageCombineCompleteListener);

delaySliderChanged();
delaySlider.valueProperty().addListener((observable, oldValue, newValue) -> delaySliderChanged());
btnSave.disableProperty().bind(gifIsReady.not());
loadingLabel.visibleProperty().bind(gifIsReady.not());

fm.loadImages();
}
Expand All @@ -90,7 +97,7 @@ public void dispose() {
@FXML
public void sliderReleased(MouseEvent mouseEvent) {
System.out.println("Slider released. Generating gif...");
loadingLabel.setVisible(true);
gifIsReady.setValue(false);
delaySliderChanged();
ic.cancelGeneration();
ic.generate();
Expand Down
2 changes: 1 addition & 1 deletion GifCreator/src/main/resources/res/gif_settings.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</Pane>
<Label layoutX="389.0" layoutY="14.0" text="%LbSetDelay" />
<Slider fx:id="delaySlider" blockIncrement="5.0" layoutX="389.0" layoutY="42.0" majorTickUnit="100.0" max="1000.0" min="1.0" minorTickCount="1" onMouseReleased="#sliderReleased" prefHeight="22.0" prefWidth="239.0" showTickMarks="true" value="60.0" />
<Button layoutX="621.0" layoutY="341.0" mnemonicParsing="false" onAction="#saveGif" text="%BtSave" />
<Button fx:id="btnSave" layoutX="621.0" layoutY="341.0" mnemonicParsing="false" onAction="#saveGif" text="%BtSave" />
<Button layoutX="542.0" layoutY="341.0" mnemonicParsing="false" onAction="#prevMode" text="%BtBack" />
<TextField fx:id="delayField" layoutX="389.0" layoutY="73.0" prefHeight="25.0" prefWidth="153.0" />
<Label layoutX="561.0" layoutY="77.0" text="%LbSeconds" />
Expand Down

0 comments on commit 79d4a23

Please sign in to comment.