Skip to content

Commit

Permalink
Export option for title and keywords added
Browse files Browse the repository at this point in the history
  • Loading branch information
cleme authored and cleme committed Jan 1, 2022
1 parent bff0714 commit d9d11d7
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 26 deletions.
125 changes: 102 additions & 23 deletions PhotoSlide/src/main/java/org/photoslide/ExportDialogController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,35 @@

import java.io.File;
import java.net.URL;
import java.util.Collection;
import java.util.ResourceBundle;
import javafx.beans.binding.Bindings;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.FlowPane;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
import javafx.util.Duration;
import org.photoslide.browsermetadata.Tag;

/**
*
* @author selfemp
*/
public class ExportDialogController implements Initializable {


private Collection<String> keywordList;
@FXML
private ComboBox<String> fileSequenceCombo;
@FXML
Expand All @@ -38,7 +46,7 @@ public class ExportDialogController implements Initializable {
private ComboBox<String> fileFormatCombo;
@FXML
private Label exampleLabel;

private Stage root;
@FXML
private CheckBox exportSelectedBox;
Expand All @@ -47,7 +55,7 @@ public class ExportDialogController implements Initializable {
@FXML
private Slider qualitySlider;
@FXML
private Tooltip qSliderToolTip;
private Tooltip qSliderToolTip;
@FXML
private CheckBox exportAllMetaData;
@FXML
Expand All @@ -56,7 +64,19 @@ public class ExportDialogController implements Initializable {
private CheckBox overwriteFilesBox;
@FXML
private Label errorLabelDirectory;

@FXML
private FlowPane keywordText;
@FXML
private TextField addKeywordTextField;
@FXML
private CheckBox replaceKeywordChoiceBox;
@FXML
private CheckBox replaceTitleBox;
@FXML
private TextField titleTextBox;
@FXML
private Button plusButton;

@Override
public void initialize(URL url, ResourceBundle rb) {
fileFormatCombo.getItems().add("JPG");
Expand All @@ -68,16 +88,16 @@ public void initialize(URL url, ResourceBundle rb) {
case "JPG":
qualitySlider.setDisable(false);
qualitySlider.setMin(40);
qualitySlider.setMax(100);
qualitySlider.setValue(94);
qualitySlider.setMax(100);
qualitySlider.setValue(93);
qualitySlider.setMajorTickUnit(1);
qualitySlider.setMinorTickCount(0);
qualitySlider.setBlockIncrement(1);
break;
case "PNG":
qualitySlider.setDisable(false);
qualitySlider.setMin(1);
qualitySlider.setMax(9);
qualitySlider.setMax(9);
qualitySlider.setValue(6);
qualitySlider.setMajorTickUnit(1);
qualitySlider.setMinorTickCount(0);
Expand All @@ -90,8 +110,8 @@ public void initialize(URL url, ResourceBundle rb) {
});
exampleLabel.textProperty().bind(filenamePrefixText.textProperty().concat("_1." + fileFormatCombo.getSelectionModel().getSelectedItem()));
qualitySlider.valueChangingProperty().addListener((o) -> {
});

});
qSliderToolTip.textProperty().bind(qualitySlider.valueProperty().asString());
qSliderToolTip.textProperty().bind(Bindings.format("%.0f", qualitySlider.valueProperty()));
qSliderToolTip.setShowDelay(Duration.ZERO);
Expand Down Expand Up @@ -124,32 +144,49 @@ public void initialize(URL url, ResourceBundle rb) {
exportBasicMetadataBox.setSelected(false);
}
});
replaceTitleBox.setOnAction((t) -> {
if (replaceTitleBox.isSelected()) {
titleTextBox.setDisable(false);
} else {
titleTextBox.setDisable(true);
}
});
replaceKeywordChoiceBox.setOnAction((t) -> {
if (replaceKeywordChoiceBox.isSelected()) {
keywordText.setDisable(false);
addKeywordTextField.setDisable(false);
} else {
keywordText.setDisable(true);
addKeywordTextField.setDisable(true);
}
});
keywordList = FXCollections.observableArrayList();
}

@FXML
private void outputSelectionButtonAction(ActionEvent event) {
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setInitialDirectory(new File(outputDirText.getText()));
File selectedDirectory = directoryChooser.showDialog((Stage) fileSequenceCombo.getScene().getWindow());
outputDirText.setText(selectedDirectory.getAbsolutePath());
}

public String getFileFormat() {
return fileFormatCombo.getSelectionModel().getSelectedItem();
}

public String getFilename() {
return filenamePrefixText.getText() + "_";
}

public String getOutputDir() {
return outputDirText.getText();
}

public void setInitOutDir(String dir) {
outputDirText.setText(dir);
}

public void setTitel(String titel) {
if (titel != null) {
filenamePrefixText.setText(titel);
Expand All @@ -158,19 +195,19 @@ public void setTitel(String titel) {
fileSequenceCombo.getSelectionModel().select("Custom filname");
}
}

public CheckBox getExportSelectedBox() {
return exportSelectedBox;
}

public CheckBox getExportDeletedFileBox() {
return exportDeletedFileBox;
}
}

public CheckBox getExportAllMetaData() {
return exportAllMetaData;
}

public CheckBox getExportBasicMetadataBox() {
return exportBasicMetadataBox;
}
Expand All @@ -182,7 +219,49 @@ public CheckBox getOverwriteFilesBox() {
public Label getErrorLabelDirectory() {
return errorLabelDirectory;
}




@FXML
private void addKeywordAction(KeyEvent event) {
if (event.getCode() == KeyCode.ENTER) {
keywordText.getChildren().add(new Tag(addKeywordTextField.getText()));
addKeywordTextField.clear();
event.consume();
}
}

public Collection<String> getKeywordList() {
return keywordList;
}

public String getKeywordsAsString() {
StringBuilder sb = new StringBuilder();
if (!keywordText.getChildren().isEmpty()) {
keywordText.getChildren().forEach((tagitem) -> {
sb.append(((Tag) tagitem).getText()).append(";");
});
String substring = sb.toString().substring(0, sb.toString().length() - 1);
return substring;
} else {
return "";
}
}

public String getTitle() {
return titleTextBox.getText();
}

public CheckBox getReplaceTitleBox() {
return replaceTitleBox;
}

public CheckBox getReplaceKeywordChoiceBox() {
return replaceKeywordChoiceBox;
}

@FXML
private void plusButtonAction(ActionEvent event) {
keywordText.getChildren().add(new Tag(addKeywordTextField.getText()));
addKeywordTextField.clear();
}

}
16 changes: 14 additions & 2 deletions PhotoSlide/src/main/java/org/photoslide/MainViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ protected Boolean call() throws Exception {
break;
}
String outFileStr;
System.out.println("Option: "+diag.getController().getFilename());
System.out.println("Option: " + diag.getController().getFilename());
if (diag.getController().getFilename().equalsIgnoreCase("<Original>_")) {
outFileStr = outputDir + File.separator + mediaItem.getName() + (i + 1) + "." + imageType.getExtension();
} else {
Expand Down Expand Up @@ -433,7 +433,7 @@ protected Boolean call() throws Exception {
break;
case JPG:
JPGOptions jpegOptions = new JPGOptions();
jpegOptions.setQuality(96);
jpegOptions.setQuality(93);
jpegOptions.setColorSpace(JPGOptions.COLOR_SPACE_RGB);
jpegOptions.setWriteICCProfile(true);
builder.imageOptions(jpegOptions);
Expand All @@ -451,10 +451,22 @@ protected Boolean call() throws Exception {
fo.close();
if (diag.getController().getExportAllMetaData().isSelected()) {
metadataPaneController.readBasicMetadata(this, mediaItem);
if (diag.getController().getReplaceTitleBox().isSelected()) {
mediaItem.setTitle(diag.getController().getTitle());
}
if (diag.getController().getReplaceKeywordChoiceBox().isSelected()) {
mediaItem.setKeywords(diag.getController().getKeywordsAsString());
}
metadataPaneController.exportCompleteMetdata(mediaItem, outFileStr, imageType.getExtension());
}
if (diag.getController().getExportBasicMetadataBox().isSelected()) {
metadataPaneController.readBasicMetadata(this, mediaItem);
if (diag.getController().getReplaceTitleBox().isSelected()) {
mediaItem.setTitle(diag.getController().getTitle());
}
if (diag.getController().getReplaceKeywordChoiceBox().isSelected()) {
mediaItem.setKeywords(diag.getController().getKeywordsAsString());
}
metadataPaneController.exportBasicMetadata(mediaItem, outFileStr);
}
} catch (FileNotFoundException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.photoslide.datamodel;

import javafx.animation.PauseTransition;
import javafx.application.Platform;
import javafx.beans.binding.DoubleBinding;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.geometry.Insets;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import org.kordamp.ikonli.javafx.FontIcon?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="306.0" prefWidth="511.0" stylesheets="@../css/Dialogs.css" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.photoslide.ExportDialogController">
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="538.0" prefWidth="511.0" stylesheets="@../css/Dialogs.css" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.photoslide.ExportDialogController">
<children>
<Label layoutX="84.0" layoutY="71.0" text="Filesequence" />
<ComboBox fx:id="fileSequenceCombo" layoutX="164.0" layoutY="66.0" prefHeight="27.0" prefWidth="161.0" />
Expand Down Expand Up @@ -54,5 +59,35 @@
</tooltip>
</Slider>
<Label fx:id="errorLabelDirectory" layoutX="367.0" layoutY="143.0" text="Label" textFill="#ff0101" visible="false" />
<VBox layoutX="81.0" layoutY="356.0" prefHeight="123.0" prefWidth="350.0" spacing="2.0">
<children>
<CheckBox fx:id="replaceKeywordChoiceBox" mnemonicParsing="false" text="Replace keywords during export" />
<ScrollPane fitToWidth="true" minViewportHeight="90.0" minViewportWidth="100.0" prefViewportWidth="230.0">
<content>
<FlowPane fx:id="keywordText" disable="true" hgap="5.0" prefHeight="100.0" prefWidth="230.0" style="-fx-background-color: rgb(80, 80, 80);" vgap="5.0">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</FlowPane>
</content>
</ScrollPane>
<HBox spacing="5.0">
<children>
<TextField fx:id="addKeywordTextField" disable="true" onKeyPressed="#addKeywordAction" prefHeight="27.0" prefWidth="205.0" promptText="Add Keywords..." HBox.hgrow="ALWAYS" />
<Button fx:id="plusButton" mnemonicParsing="false" onAction="#plusButtonAction">
<graphic>
<FontIcon iconLiteral="ti-plus" />
</graphic>
</Button>
</children>
</HBox>
</children>
</VBox>
<HBox alignment="CENTER_LEFT" layoutX="81.0" layoutY="319.0" prefHeight="25.0" prefWidth="350.0" spacing="10.0">
<children>
<CheckBox fx:id="replaceTitleBox" mnemonicParsing="false" text="Replace Title during export" />
<TextField fx:id="titleTextBox" disable="true" HBox.hgrow="ALWAYS" />
</children>
</HBox>
</children>
</AnchorPane>

0 comments on commit d9d11d7

Please sign in to comment.