-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
259 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
193 changes: 193 additions & 0 deletions
193
com.io7m.laurel.gui/src/main/java/com/io7m/laurel/gui/internal/LImageView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
/* | ||
* Copyright © 2024 Mark Raynsford <[email protected]> https://www.io7m.com | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | ||
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
|
||
package com.io7m.laurel.gui.internal; | ||
|
||
import com.io7m.laurel.gui.internal.model.LMImage; | ||
import com.io7m.repetoir.core.RPServiceDirectoryType; | ||
import javafx.fxml.FXML; | ||
import javafx.fxml.FXMLLoader; | ||
import javafx.scene.Scene; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.control.ProgressBar; | ||
import javafx.scene.image.Image; | ||
import javafx.scene.image.ImageView; | ||
import javafx.scene.layout.Pane; | ||
import javafx.scene.shape.Rectangle; | ||
import javafx.stage.Stage; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.net.URL; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.ResourceBundle; | ||
|
||
/** | ||
* The About screen. | ||
*/ | ||
|
||
public final class LImageView implements LScreenViewType | ||
{ | ||
private final Stage stage; | ||
private final LControllerType controller; | ||
|
||
private @FXML Rectangle border; | ||
private @FXML ImageView imageView; | ||
private @FXML Button dismiss; | ||
private @FXML ProgressBar imageProgress; | ||
|
||
/** | ||
* The image view screen. | ||
* | ||
* @param services The services | ||
* @param inStage The stage | ||
*/ | ||
|
||
public LImageView( | ||
final RPServiceDirectoryType services, | ||
final Stage inStage) | ||
{ | ||
this.controller = | ||
services.requireService(LControllerType.class); | ||
this.stage = | ||
Objects.requireNonNull(inStage, "inStage"); | ||
} | ||
|
||
@Override | ||
public void initialize( | ||
final URL url, | ||
final ResourceBundle resourceBundle) | ||
{ | ||
this.border.widthProperty() | ||
.bind(this.stage.widthProperty().subtract(24.0)); | ||
this.border.heightProperty() | ||
.bind(this.stage.heightProperty().subtract(32 + 32 + 16 + 8)); | ||
|
||
this.border.widthProperty() | ||
.addListener((observable, oldValue, newValue) -> { | ||
this.imageView.setFitWidth(newValue.doubleValue() - 2.0); | ||
}); | ||
this.border.heightProperty() | ||
.addListener((observable, oldValue, newValue) -> { | ||
this.imageView.setFitHeight(newValue.doubleValue() - 2.0); | ||
}); | ||
|
||
this.controller.imageSelected() | ||
.subscribe((image1, image2) -> { | ||
this.onImageSelected(image2); | ||
}); | ||
} | ||
|
||
private void onImageSelected( | ||
final LMImage image) | ||
{ | ||
if (image == null) { | ||
this.controller.imageSelect(Optional.empty()); | ||
this.imageView.setImage(null); | ||
return; | ||
} | ||
|
||
final var imageFileOpt = | ||
Optional.ofNullable(image.fileName().get()); | ||
|
||
this.imageProgress.setVisible(true); | ||
if (imageFileOpt.isPresent()) { | ||
final var imageValue = | ||
new Image( | ||
imageFileOpt.get().toUri().toString(), | ||
this.imageView.getFitWidth(), | ||
this.imageView.getFitHeight(), | ||
false, | ||
true, | ||
true | ||
); | ||
|
||
this.imageProgress.setVisible(true); | ||
|
||
imageValue.exceptionProperty() | ||
.subscribe(e -> { | ||
this.imageProgress.setVisible(true); | ||
}); | ||
|
||
imageValue.progressProperty() | ||
.addListener((observable, oldValue, newValue) -> { | ||
if (newValue.doubleValue() >= 1.0) { | ||
this.imageProgress.setVisible(false); | ||
} | ||
}); | ||
|
||
this.imageProgress.progressProperty() | ||
.bind(imageValue.progressProperty()); | ||
|
||
this.imageView.setImage(imageValue); | ||
} else { | ||
this.imageView.setImage(null); | ||
this.imageProgress.setVisible(false); | ||
} | ||
} | ||
|
||
@FXML | ||
private void onDismiss() | ||
{ | ||
this.stage.close(); | ||
} | ||
|
||
/** | ||
* The image view screen. | ||
* | ||
* @param services The services | ||
* @param strings The strings | ||
* | ||
* @return The about screen | ||
*/ | ||
|
||
public static LImageView create( | ||
final Stage stage, | ||
final RPServiceDirectoryType services, | ||
final LStrings strings) | ||
{ | ||
try { | ||
final var layout = | ||
LExporterDialogs.class.getResource( | ||
"/com/io7m/laurel/gui/internal/image.fxml"); | ||
|
||
Objects.requireNonNull(layout, "layout"); | ||
|
||
final var loader = | ||
new FXMLLoader(layout, strings.resources()); | ||
|
||
final var image = new LImageView(services, stage); | ||
loader.setControllerFactory(param -> { | ||
return image; | ||
}); | ||
|
||
final Pane pane = loader.load(); | ||
LCSS.setCSS(pane); | ||
|
||
stage.setTitle(strings.format("image")); | ||
stage.setWidth(512); | ||
stage.setMinWidth(256); | ||
stage.setMinHeight(256); | ||
stage.setHeight(512); | ||
stage.setScene(new Scene(pane)); | ||
return image; | ||
} catch (final IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
com.io7m.laurel.gui/src/main/resources/com/io7m/laurel/gui/internal/image.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.geometry.Insets?> | ||
<?import javafx.scene.control.Button?> | ||
<?import javafx.scene.control.ProgressBar?> | ||
<?import javafx.scene.image.ImageView?> | ||
<?import javafx.scene.layout.AnchorPane?> | ||
<?import javafx.scene.layout.HBox?> | ||
<?import javafx.scene.layout.Region?> | ||
<?import javafx.scene.shape.Rectangle?> | ||
|
||
<AnchorPane xmlns="http://javafx.com/javafx/21.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.io7m.laurel.gui.internal.LImageView"> | ||
<children> | ||
<Rectangle fx:id="border" arcHeight="5.0" arcWidth="5.0" fill="#1f93ff00" height="512.0" stroke="WHITE" strokeType="INSIDE" width="512.0" AnchorPane.bottomAnchor="47.0" AnchorPane.leftAnchor="7.0" AnchorPane.rightAnchor="7.0" AnchorPane.topAnchor="7.0" /> | ||
<ImageView fx:id="imageView" fitHeight="512.0" fitWidth="512.0" layoutX="8.0" layoutY="8.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="48.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="8.0" AnchorPane.topAnchor="8.0" /> | ||
<ProgressBar fx:id="imageProgress" prefHeight="16.0" prefWidth="128.0" progress="0.0" AnchorPane.bottomAnchor="64.0" AnchorPane.leftAnchor="128.0" AnchorPane.rightAnchor="128.0" /> | ||
<HBox alignment="CENTER" layoutX="8.0" layoutY="528.0" maxHeight="-Infinity" minHeight="-Infinity" prefHeight="32.0" AnchorPane.bottomAnchor="8.0" AnchorPane.leftAnchor="8.0" AnchorPane.rightAnchor="8.0"> | ||
<children> | ||
<Region HBox.hgrow="ALWAYS" /> | ||
<Button fx:id="dismiss" defaultButton="true" mnemonicParsing="false" onAction="#onDismiss" prefHeight="32.0" prefWidth="128.0" text="%error.dismiss" HBox.hgrow="NEVER"> | ||
<HBox.margin> | ||
<Insets /> | ||
</HBox.margin> | ||
</Button> | ||
</children> | ||
</HBox> | ||
</children> | ||
</AnchorPane> |