Skip to content

Commit

Permalink
Global prefix captions, bug fixes, image deletion.
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed Jan 21, 2024
1 parent 39924be commit 8b7787e
Show file tree
Hide file tree
Showing 28 changed files with 985 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.io7m.laurel.gui.internal;

import javafx.fxml.FXML;
import javafx.scene.Parent;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
Expand All @@ -36,10 +37,13 @@

public final class LCaptionEdit implements LScreenViewType
{
private final String startingCaption;

@FXML private Label error;
@FXML private TextField textArea;
@FXML private Button cancel;
@FXML private Button save;
@FXML private Parent errorContainer;

private final Stage stage;
private Optional<String> result;
Expand All @@ -48,22 +52,28 @@ public final class LCaptionEdit implements LScreenViewType
* The caption editor.
*
* @param inStage The stage
* @param caption The starting caption
*/

public LCaptionEdit(
final Stage inStage)
final Stage inStage,
final String caption)
{
this.stage =
Objects.requireNonNull(inStage, "stage");
this.result =
Optional.empty();
this.startingCaption =
Objects.requireNonNull(caption, "caption");
}

@Override
public void initialize(
final URL url,
final ResourceBundle resourceBundle)
{
this.errorContainer.setVisible(false);
this.textArea.setText(this.startingCaption);
this.error.setText("");
this.save.setDisable(true);
}
Expand Down Expand Up @@ -96,8 +106,10 @@ private void onTextChanged()
if (VALID_CAPTION.matcher(this.textArea.getText()).matches()) {
this.save.setDisable(false);
this.error.setText("");
this.errorContainer.setVisible(false);
} else {
this.error.setText("Caption must match %s".formatted(VALID_CAPTION));
this.errorContainer.setVisible(true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public LCaptionEdit open(
final var loader =
new FXMLLoader(layout, this.strings.resources());

final var editor = new LCaptionEdit(stage);
final var editor = new LCaptionEdit(stage, caption);
loader.setControllerFactory(param -> {
return editor;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import com.io7m.repetoir.core.RPServiceDirectoryType;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
Expand All @@ -36,15 +38,23 @@
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URL;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.stream.Collectors;

import static javafx.stage.Modality.APPLICATION_MODAL;

/**
* The captions view.
*/
Expand All @@ -54,6 +64,7 @@ public final class LCaptionsView implements LScreenViewType
private static final Logger LOG =
LoggerFactory.getLogger(LCaptionsView.class);

private final RPServiceDirectoryType services;
private final LControllerType controller;
private final LStrings strings;
private final LFileChoosers choosers;
Expand All @@ -72,8 +83,6 @@ public final class LCaptionsView implements LScreenViewType
@FXML private Button imageDelete;
@FXML private Button imageCaptionAssign;
@FXML private Button imageCaptionUnassign;
@FXML private Button imageCaptionPriorityUp;
@FXML private Button imageCaptionPriorityDown;
@FXML private Button captionNew;
@FXML private Button captionDelete;
@FXML private TextField captionAvailableSearch;
Expand All @@ -82,22 +91,24 @@ public final class LCaptionsView implements LScreenViewType
/**
* The captions view.
*
* @param services The service directory
* @param inServices The service directory
*/

public LCaptionsView(
final RPServiceDirectoryType services)
final RPServiceDirectoryType inServices)
{
this.services =
Objects.requireNonNull(inServices, "services");
this.controller =
services.requireService(LControllerType.class);
inServices.requireService(LControllerType.class);
this.strings =
services.requireService(LStrings.class);
inServices.requireService(LStrings.class);
this.choosers =
services.requireService(LFileChoosers.class);
inServices.requireService(LFileChoosers.class);
this.editors =
services.requireService(LCaptionEditors.class);
inServices.requireService(LCaptionEditors.class);
this.preferences =
services.requireService(LPreferencesType.class);
inServices.requireService(LPreferencesType.class);
}

@Override
Expand All @@ -114,8 +125,6 @@ public void initialize(
this.imageDelete.setDisable(true);
this.imageCaptionAssign.setDisable(true);
this.imageCaptionUnassign.setDisable(true);
this.imageCaptionPriorityUp.setDisable(true);
this.imageCaptionPriorityDown.setDisable(true);
this.captionNew.setDisable(false);
this.captionDelete.setDisable(true);

Expand Down Expand Up @@ -252,7 +261,6 @@ private void onCaptionUnassignedSelected(
{
this.updateImageCaptionUnassignButton();
this.updateImageCaptionAssignButton();
this.updateImageCaptionPriorityButtons();

if (caption == null) {
this.captionDelete.setDisable(true);
Expand All @@ -267,7 +275,6 @@ private void onCaptionAssignedSelected(
{
this.updateImageCaptionAssignButton();
this.updateImageCaptionUnassignButton();
this.updateImageCaptionPriorityButtons();
}

private void updateImageCaptionUnassignButton()
Expand Down Expand Up @@ -313,7 +320,6 @@ private void onImageSelected(
{
this.updateImageCaptionUnassignButton();
this.updateImageCaptionAssignButton();
this.updateImageCaptionPriorityButtons();

if (image == null) {
this.controller.imageSelect(Optional.empty());
Expand Down Expand Up @@ -369,27 +375,6 @@ private void onImageSelected(
}
}

private void updateImageCaptionPriorityButtons()
{
final var imageSelected =
!this.imagesAll.getSelectionModel()
.getSelectedItems()
.isEmpty();

final var captionSelected =
this.captionsAssignedView.getSelectionModel()
.getSelectedItems()
.size() == 1;

if (imageSelected && captionSelected) {
this.imageCaptionPriorityDown.setDisable(false);
this.imageCaptionPriorityUp.setDisable(false);
} else {
this.imageCaptionPriorityDown.setDisable(true);
this.imageCaptionPriorityUp.setDisable(true);
}
}

private void handleImageSetStateChanged(
final LModelFileStatusType fileStatus)
{
Expand Down Expand Up @@ -431,35 +416,13 @@ private void onImageAdd()
@FXML
private void onImageDelete()
{
final var images =
List.copyOf(
this.imagesAll.getSelectionModel()
.getSelectedItems()
);

}

@FXML
private void onImageCaptionPriorityUp()
{
final var image =
this.imagesAll.getSelectionModel()
.getSelectedItem();
final var caption =
this.captionsAssignedView.getSelectionModel()
.getSelectedItem();

this.controller.imageCaptionPriorityIncrease(image.id(), caption.id());
this.captionsAssignedView.requestFocus();
}

@FXML
private void onImageCaptionPriorityDown()
{
final var image =
this.imagesAll.getSelectionModel()
.getSelectedItem();
final var caption =
this.captionsAssignedView.getSelectionModel()
.getSelectedItem();

this.controller.imageCaptionPriorityDecrease(image.id(), caption.id());
this.captionsAssignedView.requestFocus();
this.controller.imagesDelete(images);
}

@FXML
Expand Down Expand Up @@ -545,4 +508,44 @@ private void onImageSearchChanged()
{
this.controller.imagesSetFilter(this.imageSearch.getText().trim());
}

@FXML
private void onCaptionGlobal()
{
try {
final var stage = new Stage();

final var layout =
LCaptionsView.class.getResource(
"/com/io7m/laurel/gui/internal/globalPrefixCaptions.fxml");

Objects.requireNonNull(layout, "layout");

final var loader =
new FXMLLoader(layout, this.strings.resources());

final var globals = new LGlobalPrefixCaptions(this.services, stage);
loader.setControllerFactory(param -> {
return globals;
});

final Pane pane = loader.load();
LCSS.setCSS(pane);

final var width = 650.0;
final var height = 432.0;
stage.initModality(APPLICATION_MODAL);
stage.setTitle(this.strings.format("globals"));
stage.setWidth(width);
stage.setMaxWidth(width);
stage.setMinWidth(width);
stage.setMinHeight(height);
stage.setHeight(height);
stage.setMaxHeight(height);
stage.setScene(new Scene(pane));
stage.showAndWait();
} catch (final IOException e) {
throw new UncheckedIOException(e);
}
}
}
Loading

0 comments on commit 8b7787e

Please sign in to comment.