diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TreeTableColumnConfig.java b/src/main/java/com/sparrowwallet/sparrow/control/TreeTableColumnConfig.java new file mode 100644 index 00000000..22cb65eb --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/control/TreeTableColumnConfig.java @@ -0,0 +1,46 @@ +package com.sparrowwallet.sparrow.control; + +import javafx.scene.control.TreeTableColumn; + +public class TreeTableColumnConfig { + private final int index; + private final Integer width; + private final TreeTableColumn.SortType sortType; + + public TreeTableColumnConfig(int index, Integer width, TreeTableColumn.SortType sortType) { + this.index = index; + this.width = width; + this.sortType = sortType; + } + + public TreeTableColumnConfig(int index, String width, String sortType) { + this.index = index; + this.width = width.isEmpty() ? null : Integer.valueOf(width, 10); + this.sortType = sortType.isEmpty() ? null : TreeTableColumn.SortType.valueOf(sortType); + } + + public int getIndex() { + return index; + } + + public Integer getWidth() { + return width; + } + + public TreeTableColumn.SortType getSortType() { + return sortType; + } + + public String toString() { + return index + "-" + (width == null ? "" : width) + "-" + (sortType == null ? "" : sortType); + } + + public static TreeTableColumnConfig fromString(String columnConfig) { + String[] parts = columnConfig.split("-", 3); + if(parts.length == 3) { + return new TreeTableColumnConfig(Integer.parseInt(parts[0]), parts[1], parts[2]); + } + + return new TreeTableColumnConfig(Integer.parseInt(parts[0]), (Integer)null, null); + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TreeTableConfig.java b/src/main/java/com/sparrowwallet/sparrow/control/TreeTableConfig.java new file mode 100644 index 00000000..0028ef2a --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/control/TreeTableConfig.java @@ -0,0 +1,42 @@ +package com.sparrowwallet.sparrow.control; + +import com.sparrowwallet.sparrow.wallet.Entry; +import javafx.scene.control.TreeTableColumn; + +import java.util.ArrayList; +import java.util.List; +import java.util.StringJoiner; + +public class TreeTableConfig { + private final List columnConfigs; + + public TreeTableConfig(CoinTreeTable treeTable) { + columnConfigs = new ArrayList<>(); + TreeTableColumn sortColumn = treeTable.getSortOrder().isEmpty() ? null : treeTable.getSortOrder().get(0); + for(int i = 0; i < treeTable.getColumns().size(); i++) { + TreeTableColumn column = treeTable.getColumns().get(i); + //TODO: Support column widths + columnConfigs.add(new TreeTableColumnConfig(i, null, sortColumn == column ? column.getSortType() : null)); + } + } + + public TreeTableConfig(List columnConfigs) { + this.columnConfigs = columnConfigs; + } + + public String toString() { + StringJoiner joiner = new StringJoiner("|"); + columnConfigs.stream().forEach(col -> joiner.add(col.toString())); + return joiner.toString(); + } + + public static TreeTableConfig fromString(String tableConfig) { + List columnConfigs = new ArrayList<>(); + String[] parts = tableConfig.split("\\|"); + for(String part : parts) { + columnConfigs.add(TreeTableColumnConfig.fromString(part)); + } + + return new TreeTableConfig(columnConfigs); + } +}