diff --git a/app/gui-javafx/src/main/java/org/applecommander/javafx/FileContentWindow.java b/app/gui-javafx/src/main/java/org/applecommander/javafx/FileContentWindow.java new file mode 100644 index 00000000..1c1c7ca2 --- /dev/null +++ b/app/gui-javafx/src/main/java/org/applecommander/javafx/FileContentWindow.java @@ -0,0 +1,98 @@ +/* + * AppleCommander - An Apple ][ image utility. + * Copyright (C) 2026 by Robert Greene and others + * robgreene at users.sourceforge.net + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.applecommander.javafx; + +import com.webcodepro.applecommander.util.AppleUtil; +import javafx.scene.Node; +import javafx.scene.Scene; +import javafx.scene.control.ScrollPane; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.StackPane; +import javafx.scene.text.Font; +import javafx.scene.text.Text; +import javafx.scene.text.TextFlow; +import javafx.stage.Stage; +import org.applecommander.converter.ConverterRepository; +import org.applecommander.converter.TextConverter; +import org.applecommander.filestore.ContentType; +import org.applecommander.filestore.FileEntry; + +public class FileContentWindow { + private final BorderPane window; + private final StackPane content; + private final TextFlow textView; + private final FileEntry fileEntry; + + private Stage stage; + + public FileContentWindow(FileEntry fileEntry) { + this.window = new BorderPane(); + this.textView = new TextFlow(); + this.content = new StackPane(textView); + this.fileEntry = fileEntry; + + ScrollPane scrollPane = new ScrollPane(content); + scrollPane.setFitToHeight(true); + scrollPane.setFitToWidth(true); + this.window.setCenter(scrollPane); + } + + public void show() { + Scene scene = new Scene(window, 800, 500); + stage = new Stage(); + stage.setScene(scene); + stage.toFront(); + stage.requestFocus(); + this.initView(); + stage.show(); + } + + public void close() { + stage.close(); + } + + private void initView() { + ContentType contentType = fileEntry.getContentType(); + if (contentType.subtype == ContentType.Subtype.TEXT) { + TextConverter textConverter = ConverterRepository.getTextConverter(contentType).orElseThrow(); + showPlainText(textConverter.read(fileEntry)); + } + else { + // HEX VIEW FIXME + showPlainText(AppleUtil.getHexDump(fileEntry.getDataFork().asBytes())); + } + } + + private void showPlainText(String value) { + Text text = new Text(value); + text.setFont(Font.font("monospaced")); + textView.getChildren().clear(); + textView.getChildren().add(text); + showThisButHideOthers(textView); + } + + private void showThisButHideOthers(Node nodeToShow) { + content.getChildren().forEach(node -> { + boolean showing = node == nodeToShow; + node.setVisible(showing); + node.setManaged(showing); + }); + } +} diff --git a/app/gui-javafx/src/main/java/org/applecommander/javafx/FileStoreWindow.java b/app/gui-javafx/src/main/java/org/applecommander/javafx/FileStoreWindow.java index c092b749..66cb3c42 100644 --- a/app/gui-javafx/src/main/java/org/applecommander/javafx/FileStoreWindow.java +++ b/app/gui-javafx/src/main/java/org/applecommander/javafx/FileStoreWindow.java @@ -60,6 +60,7 @@ import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -95,6 +96,7 @@ public class FileStoreWindow { private final BooleanProperty supportsDiskUsage = new SimpleBooleanProperty(); private final IntegerProperty changeCount = new SimpleIntegerProperty(); private final BooleanProperty canSave = new SimpleBooleanProperty(); + private final List childWindows = new ArrayList<>(); public FileStoreSelectionModel fileStoreSelection() { return fileStoreSelection; @@ -133,6 +135,9 @@ public class FileStoreWindow { new Image(imageUrl("AppleCommanderIcon-48x48.png")), new Image(imageUrl("AppleCommanderIcon-64x64.png")) ); + stage.setOnCloseRequest(event -> { + controller.closeAllChildWindows(); + }); // Bind keyboard shortcuts in controller try { @@ -253,6 +258,14 @@ public class FileStoreWindow { viewMode.set(ViewMode.LANDING); } + public void addChildWindow(FileContentWindow contentWindow) { + Objects.requireNonNull(contentWindow); + childWindows.add(contentWindow); + } + public void closeAllChildWindows() { + childWindows.forEach(FileContentWindow::close); + } + public Stage getPrimaryStage() { return primaryStage; } @@ -343,6 +356,9 @@ public class FileStoreWindow { } } + // Clean up anything being looked at + closeAllChildWindows(); + try { fileStoreSelection.changeFileStores(fileStores); if (fileStoreSelection.isEmpty()) { diff --git a/app/gui-javafx/src/main/java/org/applecommander/javafx/FileView.java b/app/gui-javafx/src/main/java/org/applecommander/javafx/FileView.java index 53d0569f..520cd10f 100644 --- a/app/gui-javafx/src/main/java/org/applecommander/javafx/FileView.java +++ b/app/gui-javafx/src/main/java/org/applecommander/javafx/FileView.java @@ -470,7 +470,11 @@ public class FileView extends BorderPane { var inspected = FileStores.inspect(source); FileStoreWindow.openNewWindow(inspected.fileStores); } - case UNKNOWN -> { /* Do Nothing */ } + default -> { + FileContentWindow contentWindow = new FileContentWindow(selectedRow); + this.fileStoreWindow.addChildWindow(contentWindow); + contentWindow.show(); + } } }