RomFs support: UI enhancements

master
Dmitry Isaenko 2020-04-26 17:13:00 +03:00
parent bad2924c02
commit 8efe9a118c
4 changed files with 83 additions and 29 deletions

View File

@ -18,28 +18,35 @@
*/ */
package konogonka.Controllers.RFS; package konogonka.Controllers.RFS;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.cell.CheckBoxTableCell; import javafx.scene.control.cell.CheckBoxTableCell;
import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseButton; import javafx.scene.input.MouseButton;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import konogonka.Controllers.IRowModel; import konogonka.Controllers.IRowModel;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.ResourceBundle;
public class RFSFolderTableViewController implements Initializable { public class RFSFolderTableViewController implements Initializable {
@FXML @FXML
private TableView<RFSEntry> table; private TableView<RFSEntry> table;
private ObservableList<RFSEntry> rowsObsLst; private ObservableList<RFSEntry> rowsObsLst;
@FXML
private HBox navigationHBox;
@Override @Override
public void initialize(URL url, ResourceBundle resourceBundle) { public void initialize(URL url, ResourceBundle resourceBundle) {
@ -61,23 +68,23 @@ public class RFSFolderTableViewController implements Initializable {
keyEvent.consume(); keyEvent.consume();
}); });
TableColumn<RFSEntry, Integer> numberColumn = new TableColumn<>(resourceBundle.getString("tableNumberLbl")); TableColumn<RFSEntry, Node> imageColumn = new TableColumn<>();
TableColumn<RFSEntry, String> fileNameColumn = new TableColumn<>(resourceBundle.getString("tableFileNameLbl")); TableColumn<RFSEntry, String> fileNameColumn = new TableColumn<>(resourceBundle.getString("tableFileNameLbl"));
TableColumn<RFSEntry, Long> fileOffsetColumn = new TableColumn<>(resourceBundle.getString("tableOffsetLbl")); TableColumn<RFSEntry, Long> fileOffsetColumn = new TableColumn<>(resourceBundle.getString("tableOffsetLbl"));
TableColumn<RFSEntry, Long> fileSizeColumn = new TableColumn<>(resourceBundle.getString("tableSizeLbl")); TableColumn<RFSEntry, Long> fileSizeColumn = new TableColumn<>(resourceBundle.getString("tableSizeLbl"));
TableColumn<RFSEntry, Boolean> checkBoxColumn = new TableColumn<>(resourceBundle.getString("tableUploadLbl")); TableColumn<RFSEntry, Boolean> checkBoxColumn = new TableColumn<>(resourceBundle.getString("tableUploadLbl"));
numberColumn.setEditable(false); imageColumn.setEditable(false);
fileNameColumn.setEditable(false); fileNameColumn.setEditable(false);
fileOffsetColumn.setEditable(false); fileOffsetColumn.setEditable(false);
fileSizeColumn.setEditable(false); fileSizeColumn.setEditable(false);
checkBoxColumn.setEditable(true); checkBoxColumn.setEditable(true);
// See https://bugs.openjdk.java.net/browse/JDK-8157687 // See https://bugs.openjdk.java.net/browse/JDK-8157687
numberColumn.setMinWidth(30.0); imageColumn.setMinWidth(30.0);
numberColumn.setPrefWidth(30.0); imageColumn.setPrefWidth(30.0);
numberColumn.setMaxWidth(30.0); imageColumn.setMaxWidth(30.0);
numberColumn.setResizable(false); imageColumn.setResizable(false);
fileNameColumn.setMinWidth(25.0); fileNameColumn.setMinWidth(25.0);
@ -96,12 +103,32 @@ public class RFSFolderTableViewController implements Initializable {
checkBoxColumn.setMaxWidth(120.0); checkBoxColumn.setMaxWidth(120.0);
checkBoxColumn.setResizable(false); checkBoxColumn.setResizable(false);
numberColumn.setCellValueFactory(new PropertyValueFactory<>("number")); imageColumn.setCellValueFactory(paramFeatures -> {
RFSEntry model = paramFeatures.getValue();
return new ObservableValue<Node>() {
@Override
public Node getValue() {
final Region folderImage = new Region();
if (model.isDirectory())
folderImage.getStyleClass().add("regionFolder");
else
folderImage.getStyleClass().add("regionFile");
return folderImage;
}
@Override
public void addListener(ChangeListener<? super Node> changeListener) {}
@Override
public void removeListener(ChangeListener<? super Node> changeListener) {}
@Override
public void addListener(InvalidationListener invalidationListener) {}
@Override
public void removeListener(InvalidationListener invalidationListener) {}
};
});
fileNameColumn.setCellValueFactory(new PropertyValueFactory<>("fileName")); fileNameColumn.setCellValueFactory(new PropertyValueFactory<>("fileName"));
fileSizeColumn.setCellValueFactory(new PropertyValueFactory<>("fileSize")); fileSizeColumn.setCellValueFactory(new PropertyValueFactory<>("fileSize"));
fileOffsetColumn.setCellValueFactory(new PropertyValueFactory<>("fileOffset")); fileOffsetColumn.setCellValueFactory(new PropertyValueFactory<>("fileOffset"));
// ><
checkBoxColumn.setCellValueFactory(paramFeatures -> { checkBoxColumn.setCellValueFactory(paramFeatures -> {
RFSEntry model = paramFeatures.getValue(); RFSEntry model = paramFeatures.getValue();
@ -147,7 +174,7 @@ public class RFSFolderTableViewController implements Initializable {
} }
); );
table.setItems(rowsObsLst); table.setItems(rowsObsLst);
table.getColumns().add(numberColumn); table.getColumns().add(imageColumn);
table.getColumns().add(fileNameColumn); table.getColumns().add(fileNameColumn);
table.getColumns().add(fileOffsetColumn); table.getColumns().add(fileOffsetColumn);
table.getColumns().add(fileSizeColumn); table.getColumns().add(fileSizeColumn);
@ -157,7 +184,7 @@ public class RFSFolderTableViewController implements Initializable {
* Add files when user selected them on left-hand tree * Add files when user selected them on left-hand tree
* */ * */
public void setContent(TreeItem<RFSEntry> containerTreeItem){ public void setContent(TreeItem<RFSEntry> containerTreeItem){
rowsObsLst.clear(); reset();
if (containerTreeItem == null) { if (containerTreeItem == null) {
table.refresh(); table.refresh();
@ -167,6 +194,36 @@ public class RFSFolderTableViewController implements Initializable {
for (TreeItem<RFSEntry> childTreeItem : containerTreeItem.getChildren()) for (TreeItem<RFSEntry> childTreeItem : containerTreeItem.getChildren())
rowsObsLst.add(childTreeItem.getValue()); rowsObsLst.add(childTreeItem.getValue());
setNavigationContent(containerTreeItem);
table.refresh(); table.refresh();
} }
private void setNavigationContent(TreeItem<RFSEntry> childTreeItem){
TreeItem<RFSEntry> parentTreeItem;
LinkedList<Button> content = new LinkedList<>();
content.add(new Button(childTreeItem.getValue().getFileName()));
while ((parentTreeItem = childTreeItem.getParent()) != null) {
content.add(createNavigationButton(parentTreeItem));
childTreeItem = parentTreeItem;
}
Collections.reverse(content);
for (Button button : content)
navigationHBox.getChildren().add(button);
}
private Button createNavigationButton(TreeItem<RFSEntry> treeItem){
Button button = new Button(treeItem.getValue().getFileName());
button.setOnAction(event -> setContent(treeItem));
return button;
}
public void reset(){
rowsObsLst.clear();
navigationHBox.getChildren().clear();
}
} }

View File

@ -20,9 +20,7 @@ package konogonka.Controllers.RFS;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.Region; import javafx.scene.layout.Region;
import javafx.util.Callback;
import konogonka.Controllers.ITabController; import konogonka.Controllers.ITabController;
import konogonka.Tools.ISuperProvider; import konogonka.Tools.ISuperProvider;
import konogonka.Tools.RomFs.FileSystemEntry; import konogonka.Tools.RomFs.FileSystemEntry;
@ -76,10 +74,6 @@ public class RomFsController implements ITabController {
}); });
} }
private final class RFSTreeCell extends TreeCell<RFSEntry>{
}
@Override @Override
public void analyze(File file) { public void analyze(File file) {
this.analyze(file, 0); this.analyze(file, 0);
@ -180,6 +174,7 @@ public class RomFsController implements ITabController {
headerFileDataOffsetHexLbl.setText(""); headerFileDataOffsetHexLbl.setText("");
filesTreeView.setRoot(null); filesTreeView.setRoot(null);
RFSTableViewController.reset();
} }
private Region getFolderImage(){ private Region getFolderImage(){

View File

@ -19,17 +19,12 @@
package konogonka.Tools.RomFs; package konogonka.Tools.RomFs;
import konogonka.LoperConverter;
import konogonka.Tools.ISuperProvider; import konogonka.Tools.ISuperProvider;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.PipedInputStream; import java.io.PipedInputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import static konogonka.RainbowDump.formatDecHexString; import static konogonka.RainbowDump.formatDecHexString;

View File

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.TableView?> <?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<!-- <!--
~ Copyright 2019-2020 Dmitry Isaenko ~ Copyright 2019-2020 Dmitry Isaenko
@ -22,8 +24,13 @@
~ along with Konogonka. If not, see <https://www.gnu.org/licenses/>. ~ along with Konogonka. If not, see <https://www.gnu.org/licenses/>.
--> -->
<AnchorPane xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="konogonka.Controllers.RFS.RFSFolderTableViewController"> <VBox spacing="5.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="konogonka.Controllers.RFS.RFSFolderTableViewController">
<children> <children>
<TableView fx:id="table" editable="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" /> <HBox fx:id="navigationHBox" prefHeight="40.0" spacing="5.0" VBox.vgrow="NEVER">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</HBox>
<TableView fx:id="table" editable="true" VBox.vgrow="ALWAYS" />
</children> </children>
</AnchorPane> </VBox>