From 9bd18e59260557104a70936fcf2fc8fa8b0d2f3f Mon Sep 17 00:00:00 2001 From: Riegel Date: Thu, 16 Jan 2025 10:21:14 +0100 Subject: [PATCH] Feat: Add saveBtn to ZipEntryManager --- .../citydoctor2/gui/ZipEntryManager.java | 32 ++++- .../citydoctor2/gui/ZipEntryManager.fxml | 128 ++++++++++-------- 2 files changed, 104 insertions(+), 56 deletions(-) diff --git a/CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/ZipEntryManager.java b/CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/ZipEntryManager.java index 471b7ec6..b670159d 100644 --- a/CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/ZipEntryManager.java +++ b/CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/ZipEntryManager.java @@ -2,6 +2,7 @@ package de.hft.stuttgart.citydoctor2.gui; import de.hft.stuttgart.citydoctor2.gui.tree.ZipEntryListCell; import de.hft.stuttgart.citydoctor2.gui.tree.ZipEntryNode; +import de.hft.stuttgart.citydoctor2.utils.ArchivePacker; import de.hft.stuttgart.citydoctor2.utils.Localization; import de.hft.stuttgart.citydoctor2.zip.CityGmlZipArchive; import de.hft.stuttgart.citydoctor2.zip.CityGmlZipEntry; @@ -22,14 +23,17 @@ import javafx.scene.image.ImageView; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; import javafx.scene.layout.VBox; +import javafx.stage.FileChooser; import javafx.stage.Modality; import javafx.stage.Stage; import javafx.stage.Window; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.util.function.Predicate; public class ZipEntryManager { @@ -96,6 +100,11 @@ public class ZipEntryManager { @FXML private ImageView showReportImageView; + @FXML + private Button saveBtn; + @FXML + private ImageView saveImageView; + @FXML private ListView entryList; @FXML @@ -165,6 +174,10 @@ public class ZipEntryManager { Image img = new Image(inStream); showReportImageView.setImage(img); } + try (InputStream inStream = MainWindow.class.getResourceAsStream("icons/save.png")) { + Image img = new Image(inStream); + saveImageView.setImage(img); + } } catch (IOException ignored) { //ignore exceptions } @@ -273,6 +286,19 @@ public class ZipEntryManager { }); showReportBtn.setDisable(true); + saveBtn.setOnAction(e -> { + FileChooser fileChooser = new FileChooser(); + fileChooser.setTitle("Export Zip file"); + FileChooser.ExtensionFilter zipFilter = new FileChooser.ExtensionFilter("Zip File", "*.zip"); + fileChooser.getExtensionFilters().add(zipFilter); + File f = fileChooser.showSaveDialog(stage.getOwner()); + if (f != null) { + ArchivePacker.packArchive(f.getAbsolutePath(), archive); + } + + }); + saveBtn.setDisable(true); + cancelBtn.setOnAction(e -> stage.close()); } @@ -311,9 +337,9 @@ public class ZipEntryManager { entryList.getSelectionModel().clearSelection(); entryList.getSelectionModel().select(selectionIndex); showMetadata(entryList.getSelectionModel().getSelectedItem().getEntry()); - decompressAllBtn.setDisable( - entryList.getItems().stream().allMatch(zipEntryNode -> - (zipEntryNode.getEntry().isDecompressed()) || zipEntryNode.getEntry().getErrorType() != null)); + Predicate allEntriesDecompressed = node -> (node.getEntry().isDecompressed() || node.getEntry().getErrorType() != null); + decompressAllBtn.setDisable(entryList.getItems().stream().allMatch(allEntriesDecompressed)); + saveBtn.setDisable(entryList.getItems().stream().allMatch(Predicate.not(allEntriesDecompressed))); } private void showMetadata(CityGmlZipEntry entry) { diff --git a/CityDoctorParent/Extensions/CityDoctorGUI/src/main/resources/de/hft/stuttgart/citydoctor2/gui/ZipEntryManager.fxml b/CityDoctorParent/Extensions/CityDoctorGUI/src/main/resources/de/hft/stuttgart/citydoctor2/gui/ZipEntryManager.fxml index 773b318d..2fa2f2d0 100644 --- a/CityDoctorParent/Extensions/CityDoctorGUI/src/main/resources/de/hft/stuttgart/citydoctor2/gui/ZipEntryManager.fxml +++ b/CityDoctorParent/Extensions/CityDoctorGUI/src/main/resources/de/hft/stuttgart/citydoctor2/gui/ZipEntryManager.fxml @@ -17,60 +17,82 @@ - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + -- GitLab