diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java index 91bf98cb760..a160e3cabce 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java @@ -96,7 +96,7 @@ private JPanel createFilter() { JPanel filterPanel = new JPanel(); filterPanel.setLayout(new BoxLayout(filterPanel, BoxLayout.PAGE_AXIS)); - List tags = Arrays.stream(BoardsTagger.Tags.values()).map(BoardsTagger.Tags::getName).distinct().toList(); + List tags = Arrays.stream(BoardsTagger.Tags.values()).map(BoardsTagger.Tags::getName).distinct().sorted().toList(); DefaultListModel tagsModel = new DefaultListModel<>(); tagsModel.addAll(tags); listBoardTags = new JList<>(tagsModel); @@ -138,7 +138,7 @@ private JPanel createList() { JPanel listPanel = new JPanel(); listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.PAGE_AXIS)); boardModel = new BoardTableModel(); - boardModel.setData(bc.getBoardPaths().values().stream().toList()); + boardModel.setData(bc); boardTable = new JTable(); boardTable.setName("Board"); ListSelectionModel boardSelModel = boardTable.getSelectionModel(); diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java index 05b27cdb2ee..245aeaf9148 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java @@ -23,6 +23,7 @@ import megamek.common.*; import megamek.common.util.ImageUtil; import megamek.common.util.fileUtils.MegaMekFile; +import megamek.utilities.BoardClassifier; import javax.swing.*; import javax.swing.table.AbstractTableModel; @@ -72,17 +73,15 @@ public int getPreferredWidth(int col) { }; } - public void setData(List paths) { - data = paths; + public void setData(BoardClassifier bc) { + data = bc.getBoardPaths().values().stream().toList();; tags = new ArrayList<>(); size = new ArrayList<>(); - for (String path : paths) { - Board board = new Board(16, 17); - board.load(new MegaMekFile(Configuration.boardsDir(), path).getFile()); - - tags.add(board.getTags().toString()); - size.add(board.getWidth() + "x" + board.getHeight()); + for (String path : data) { + String key = Configuration.boardsDir() + path; + tags.add(bc.getBoardTags().get(key)); + size.add(bc.getBoardWidth().get(key) + "x" + bc.getBoardHeigth().get(key)); } fireTableDataChanged(); diff --git a/megamek/src/megamek/utilities/BoardClassifier.java b/megamek/src/megamek/utilities/BoardClassifier.java index 1cdfadb0b54..5dbc97bb06a 100644 --- a/megamek/src/megamek/utilities/BoardClassifier.java +++ b/megamek/src/megamek/utilities/BoardClassifier.java @@ -50,6 +50,9 @@ public class BoardClassifier { // function that maps full board paths to partial board paths private Map boardPaths = new HashMap<>(); + private Map boardTags = new HashMap<>(); + private Map boardWidth = new HashMap<>(); + private Map boardHeight = new HashMap<>(); public Map> getBoardsByTag() { return boardsByTag; @@ -79,6 +82,18 @@ public Map getBoardPaths() { return boardPaths; } + public Map getBoardTags() { + return boardTags; + } + + public Map getBoardWidth() { + return boardWidth; + } + + public Map getBoardHeigth() { + return boardHeight; + } + public void setBoardPaths(Map boardPaths) { this.boardPaths = boardPaths; } @@ -146,6 +161,9 @@ private void scanForBoardsInDir(final File boardDir, final String basePath) { } getBoardPaths().put(filePath.getPath(), partialBoardPath); + getBoardTags().put(filePath.getPath(), Board.getTags(filePath).toString()); + getBoardWidth().put(filePath.getPath(), dimension.width()); + getBoardHeigth().put(filePath.getPath(), dimension.height()); } } }