From 1c5395ed55913960a3d2a3f2c3f9e9f2f4518277 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sat, 9 Nov 2024 22:04:10 -0500 Subject: [PATCH 01/16] add an advanced search for boards to the lobby --- .../i18n/megamek/client/messages.properties | 1 + .../AdvancedSearchMapDialog.java | 240 ++++++++++++++++++ .../ui/advancedSearchMap/BoardTableModel.java | 194 ++++++++++++++ .../client/ui/swing/lobby/ChatLounge.java | 33 +++ 4 files changed, 468 insertions(+) create mode 100644 megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java create mode 100644 megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java diff --git a/megamek/i18n/megamek/client/messages.properties b/megamek/i18n/megamek/client/messages.properties index 4c96ba383f0..3d1f23e90a0 100644 --- a/megamek/i18n/megamek/client/messages.properties +++ b/megamek/i18n/megamek/client/messages.properties @@ -155,6 +155,7 @@ BT.Quirks=Quirks AdvancedSearchDialog.title=Advanced Search +AdvancedSearchMapDialog.title=Advanced Search AimedShotDialog.dontAim=Don't aim diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java new file mode 100644 index 00000000000..25c013d111c --- /dev/null +++ b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java @@ -0,0 +1,240 @@ +/* + * Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. + * + * This file is part of MegaMek. + * + * MegaMek 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 3 of the License, or + * (at your option) any later version. + * + * MegaMek 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 MegaMek. If not, see . + */ +package megamek.client.ui.advancedSearchMap; + +import megamek.client.ui.Messages; +import megamek.client.ui.baseComponents.AbstractButtonDialog; +import megamek.client.ui.swing.ButtonEsc; +import megamek.client.ui.swing.CloseAction; +import megamek.client.ui.swing.dialog.DialogButton; +import megamek.common.Board; +import megamek.common.Configuration; +import megamek.common.util.fileUtils.MegaMekFile; +import megamek.utilities.BoardClassifier; +import megamek.utilities.BoardsTagger; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import javax.swing.border.MatteBorder; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableRowSorter; +import java.awt.*; +import java.util.Arrays; +import java.util.List; +import java.util.regex.PatternSyntaxException; + +/** + * This is the dialog for advanced map filtering + */ +public class AdvancedSearchMapDialog extends AbstractButtonDialog { + + BoardClassifier bc; + JTable boardTable; + JList listBoardTags; + JList listBoardPaths; + JLabel boardImage; + JLabel boardInfo; + TableRowSorter boardSorter; + + private BoardTableModel boardModel; + public AdvancedSearchMapDialog(JFrame parent) { + super(parent, true, "AdvancedSearchMapDialog", "AdvancedSearchMapDialog.title"); + + initialize(); + } + + + @Override + protected JPanel createButtonPanel() { + JButton cancelButton = new ButtonEsc(new CloseAction(this)); + JButton okButton = new DialogButton(Messages.getString("Ok.text")); + okButton.addActionListener(this::okButtonActionPerformed); + getRootPane().setDefaultButton(okButton); + + JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 20, 0)); + buttonPanel.add(okButton); + buttonPanel.add(cancelButton); + + JPanel outerPanel = new JPanel(new GridLayout(1,1)); + outerPanel.setBorder(BorderFactory.createCompoundBorder( + new MatteBorder(1, 0, 0, 0, UIManager.getColor("Separator.foreground")), + new EmptyBorder(10, 0, 10, 0))); + outerPanel.add(buttonPanel); + + return outerPanel; + } + + @Override + protected Container createCenterPane() { + bc = BoardClassifier.getInstance(); + + JPanel advancedSearchPane = new JPanel(); + + advancedSearchPane.setLayout(new BoxLayout(advancedSearchPane, BoxLayout.PAGE_AXIS)); + + advancedSearchPane.add(createInfo()); + + JPanel mainPanel = new JPanel(new FlowLayout()); + mainPanel.add(createFilter()); + mainPanel.add(createList()); + + advancedSearchPane.add(mainPanel); + + return advancedSearchPane; + + } + + private JPanel createInfo() { + JPanel infoPanel = new JPanel(new FlowLayout()); + boardImage = new JLabel(); + infoPanel.add(boardImage); + boardInfo = new JLabel(); + infoPanel.add(boardInfo); + return infoPanel; + } + + 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(); + DefaultListModel tagsModel = new DefaultListModel<>(); + tagsModel.addAll(tags); + listBoardTags = new JList<>(tagsModel); + listBoardTags.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + listBoardTags.addSelectionInterval(0, tags.size()); + listBoardTags.addListSelectionListener (new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + filterTables(); + } + }); + JPanel boardTagsPanel = new JPanel(new BorderLayout()); + boardTagsPanel.add(new JLabel("Board Tags"), BorderLayout.NORTH); + boardTagsPanel.add(new JScrollPane(listBoardTags), BorderLayout.CENTER); + filterPanel.add(boardTagsPanel); + + List paths = bc.getBoardPaths().values().stream().toList(); + paths = paths.stream().map(p -> p.substring(0, p.lastIndexOf("\\") + 1 )).distinct().sorted().toList(); + DefaultListModel pathsModel = new DefaultListModel<>(); + pathsModel.addAll(paths); + listBoardPaths = new JList<>(pathsModel); + listBoardPaths.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + listBoardPaths.setSelectedIndex(0); + listBoardPaths.addListSelectionListener (new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + filterTables(); + } + }); + JPanel boardPathsPanel = new JPanel(new BorderLayout()); + boardPathsPanel.add(new JLabel("Board Paths"), BorderLayout.NORTH); + boardPathsPanel.add(new JScrollPane(listBoardPaths), BorderLayout.CENTER); + filterPanel.add(boardPathsPanel); + + return filterPanel; + } + + private JPanel createList() { + JPanel listPanel = new JPanel(new FlowLayout()); + boardModel = new BoardTableModel(); + boardModel.setData(bc.getBoardPaths().values().stream().toList()); + boardTable = new JTable(); + boardTable.setName("RAT"); + ListSelectionModel boardSelModel = boardTable.getSelectionModel(); + boardSelModel.addListSelectionListener (new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + int index = boardTable.getSelectedRow() ; + if (index >= 0) { + index = boardTable.convertRowIndexToModel(index); + boardImage.setIcon(boardModel.getIconAt(index, 200)); + boardInfo.setText(boardModel.getInfoAt(index)); + } + } + }); + boardTable.setModel(boardModel); + boardSorter = new TableRowSorter<>(boardModel); + boardTable.setRowSorter(boardSorter); + boardTable.setIntercellSpacing(new Dimension(5, 0)); + boardTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + for (int i = 0; i < boardModel.getColumnCount(); i++) { + boardTable.getColumnModel().getColumn(i).setPreferredWidth(boardModel.getPreferredWidth(i)); + } + DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer(); + rightRenderer.setHorizontalAlignment(JLabel.RIGHT); + + listPanel.add(new JScrollPane(boardTable)); + + boardTable.setRowSelectionInterval(0,0); + + return listPanel; + } + + void filterTables() { + RowFilter boardFilter; + try { + boardFilter = new RowFilter<>() { + @Override + public boolean include(Entry entry) { + BoardTableModel eqModel = entry.getModel(); + + String path = eqModel.getPathAt(entry.getIdentifier()); + boolean pathMatch = matchPath(path); + + List tags = eqModel.getTagAt(entry.getIdentifier()); + boolean tagMatch = matchTag(tags); + + return pathMatch && tagMatch; + } + }; + } catch (PatternSyntaxException ignored) { + return; + } + + boardSorter.setRowFilter(boardFilter); + } + + boolean matchPath(String path) { + List include = listBoardPaths.getSelectedValuesList(); + + String value = path.substring(0, path.lastIndexOf("\\") + 1 ); + + return !include.isEmpty() && include.stream().anyMatch(value::contains); + } + + boolean matchTag(List tags) { + List include = listBoardTags.getSelectedValuesList(); + + return !include.isEmpty() && include.stream().anyMatch(tags::contains); + } + + public String getPath() { + int index = boardTable.getSelectedRow() ; + if (index >= 0) { + index = boardTable.convertRowIndexToModel(index); + String path = boardModel.getPathAt(index); + return path; + } + + return null; + } +} diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java new file mode 100644 index 00000000000..554aac5bb98 --- /dev/null +++ b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. + * + * This file is part of MegaMek. + * + * MegaMek 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 3 of the License, or + * (at your option) any later version. + * + * MegaMek 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 MegaMek. If not, see . + */ +package megamek.client.ui.advancedSearchMap; + +import megamek.client.ui.swing.minimap.Minimap; +import megamek.client.ui.swing.util.UIUtil; +import megamek.common.*; +import megamek.common.util.ImageUtil; +import megamek.common.util.fileUtils.MegaMekFile; + +import javax.swing.*; +import javax.swing.table.AbstractTableModel; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * A table model for the advanced search weapon tab's equipment list + */ +class BoardTableModel extends AbstractTableModel { + private static final int COL_NAME = 0; + private static final int COL_SIZE = 1; + private static final int N_COL = 2; + + private List data; + private List tags; + private List size; + + public BoardTableModel() { + data = new ArrayList<>(); + } + + @Override + public int getRowCount() { + return data.size(); + } + + public void clearData() { + data = new ArrayList<>(); + tags = new ArrayList<>(); + size = new ArrayList<>(); + fireTableDataChanged(); + } + + @Override + public int getColumnCount() { + return N_COL; + } + + public int getPreferredWidth(int col) { + return switch (col) { + case COL_NAME -> 200; + case COL_SIZE -> 20; + default -> 10; + }; + } + + public void setData(List paths) { + data = paths; + 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()); + } + + fireTableDataChanged(); + } + + @Override + public String getColumnName(int column) { + switch (column) { + case COL_NAME: + return "Name"; + case COL_SIZE: + return "Size"; + default: + return "??"; + } + } + + @Override + public Class getColumnClass(int c) { + return getValueAt(0, c).getClass(); + } + + @Override + public boolean isCellEditable(int row, int col) { + return false; + } + + @Override + public Object getValueAt(int row, int col) { + String path = getPathAt(row); + + if (path== null) { + return "?"; + } + + String value = ""; + + if (col == COL_NAME) { + value = path.substring(path.lastIndexOf("\\") + 1, path.length()); + value = value.substring(0, value.lastIndexOf(".board")); + } else if (col == COL_SIZE) { + value = getSizeAt(row); + } + + return value; + } + + public String getPathAt(int row) { + if (data.size() <= row) { + return null; + } + + return data.get(row); + } + + public String getSizeAt(int row) { + if (size.size() <= row) { + return null; + } + + return size.get(row); + } + + public List getAllPaths() { + return data; + } + + public ImageIcon getIconAt(int row, int height) { + String path = getPathAt(row); + Board board = new Board(16, 17); + board.load(new MegaMekFile(Configuration.boardsDir(), path).getFile()); + + BufferedImage image = Minimap.getMinimapImageMaxZoom(board); + + int scaledHeight = Math.min(image.getHeight(), height); + int scaledWidth = Math.max(1, image.getWidth() * scaledHeight / image.getHeight()); + + image = ImageUtil.getScaledImage(image, scaledWidth, scaledHeight); + ImageIcon icon = new ImageIcon(image); + return icon; + } + + public String getInfoAt(int row) { + String path = getPathAt(row); + Board board = new Board(16, 17); + board.load(new MegaMekFile(Configuration.boardsDir(), path).getFile()); + + String info; + String col = UIUtil.tag("td", "", path); + info = UIUtil.tag("tr", "", col); + col = UIUtil.tag("td", "", board.getWidth() + "x" + board.getHeight()); + info += UIUtil.tag("tr", "", col); + col = UIUtil.tag("td", "", board.getTags().toString()); + info += UIUtil.tag("tr", "", col); + info = UIUtil.tag("table", "", info); + String attr = String.format("WIDTH=%s", UIUtil.scaleForGUI(500)); + info = UIUtil.tag("div", attr, info); + info = UIUtil.tag("body", "", info); + info = UIUtil.tag("html", "", info); + + return info; + } + + public List getTagAt(int row) { + String tag = tags.get(row); + tag = tag.substring(1, tag.length() -1); + return Arrays.stream(tag.split(", ")).toList(); + } +} diff --git a/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java b/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java index 2066ee4cd5b..2f98c2b0fe9 100644 --- a/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java +++ b/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java @@ -80,6 +80,7 @@ import megamek.client.generator.RandomCallsignGenerator; import megamek.client.generator.RandomNameGenerator; import megamek.client.ui.Messages; +import megamek.client.ui.advancedSearchMap.AdvancedSearchMapDialog; import megamek.client.ui.dialogs.BotConfigDialog; import megamek.client.ui.dialogs.CamoChooserDialog; import megamek.client.ui.enums.DialogResult; @@ -213,6 +214,7 @@ public class ChatLounge extends AbstractPhaseDisplay implements private JLabel lblBoardSize = new JLabel(Messages.getString("ChatLounge.labBoardSize")); private JButton butHelp = new JButton(" " + Messages.getString("ChatLounge.butHelp") + " "); + private JButton butAdvancedSearchMap = new JButton("Advanced Search"); private JButton butConditions = new JButton(Messages.getString("ChatLounge.butConditions")); private JButton butRandomMap = new JButton(Messages.getString("BoardSelectionDialog.GeneratedMapSettings")); @@ -384,6 +386,7 @@ private void setupListeners() { butDetach.addActionListener(lobbyListener); butCancelSearch.addActionListener(lobbyListener); butHelp.addActionListener(lobbyListener); + butAdvancedSearchMap.addActionListener(lobbyListener); butListView.addActionListener(lobbyListener); butForceView.addActionListener(lobbyListener); butCollapse.addActionListener(lobbyListener); @@ -679,6 +682,7 @@ private void setupMapPanel() { JPanel panHelp = new JPanel(new GridLayout(1, 1)); panHelp.add(butHelp); + panHelp.add(butAdvancedSearchMap); FixedYPanel panTopRowsHelp = new FixedYPanel(new FlowLayout(FlowLayout.CENTER, 30, 5)); panTopRowsHelp.add(panTopRows); @@ -1896,6 +1900,35 @@ public void actionPerformed(ActionEvent ev) { dialog.setPreferredSize(sz); dialog.setVisible(true); + } else if (ev.getSource() == butAdvancedSearchMap) { + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + AdvancedSearchMapDialog asmd = new AdvancedSearchMapDialog(clientgui.getFrame()); + setCursor(Cursor.getDefaultCursor()); + + if (asmd.showDialog().isConfirmed()) { + String path = asmd.getPath(); + if (path != null) { + Board board = new Board(16, 17); + board.load(new MegaMekFile(Configuration.boardsDir(), path).getFile()); + String boardName = path.replace(".board", ""); + boardName = boardName.replace("\\", "/"); + mapSettings.getBoardsSelectedVector().clear(); + mapSettings.setMapSize(1, 1); + mapSettings.setBoardSize(board.getWidth(), board.getHeight()); + clientgui.getClient().sendMapDimensions(mapSettings); + mapSettings.getBoardsSelectedVector().set(0, boardName); + refreshMapUI(); + clientgui.getClient().sendMapSettings(mapSettings); + + if (boardPreviewW.isVisible()) { + previewGameBoard(); + } + + String msg = clientgui.getClient().getLocalPlayer() + " changed map to: " + boardName; + clientgui.getClient().sendServerChat(Player.PLAYER_NONE, msg); + } + } + } else if (ev.getSource() == butListView) { scrMekTable.setViewportView(mekTable); butCollapse.setEnabled(false); From e6727067bc7423777ee83af8ef6c1daa77ce191d Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sat, 9 Nov 2024 23:40:22 -0500 Subject: [PATCH 02/16] remove size from name in list --- .../AdvancedSearchMapDialog.java | 93 +++++++++---------- .../ui/advancedSearchMap/BoardTableModel.java | 7 ++ 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java index 25c013d111c..a6252e2ce54 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java @@ -18,20 +18,11 @@ */ package megamek.client.ui.advancedSearchMap; -import megamek.client.ui.Messages; import megamek.client.ui.baseComponents.AbstractButtonDialog; -import megamek.client.ui.swing.ButtonEsc; -import megamek.client.ui.swing.CloseAction; -import megamek.client.ui.swing.dialog.DialogButton; -import megamek.common.Board; -import megamek.common.Configuration; -import megamek.common.util.fileUtils.MegaMekFile; import megamek.utilities.BoardClassifier; import megamek.utilities.BoardsTagger; import javax.swing.*; -import javax.swing.border.EmptyBorder; -import javax.swing.border.MatteBorder; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.table.DefaultTableCellRenderer; @@ -45,61 +36,51 @@ * This is the dialog for advanced map filtering */ public class AdvancedSearchMapDialog extends AbstractButtonDialog { - - BoardClassifier bc; - JTable boardTable; - JList listBoardTags; - JList listBoardPaths; - JLabel boardImage; - JLabel boardInfo; - TableRowSorter boardSorter; - + private BoardClassifier bc; + private JTable boardTable; + private JList listBoardTags; + private JList listBoardPaths; + private JLabel boardImage; + private JLabel boardInfo; + private TableRowSorter boardSorter; private BoardTableModel boardModel; + private JLabel boardCountLabel; + public AdvancedSearchMapDialog(JFrame parent) { super(parent, true, "AdvancedSearchMapDialog", "AdvancedSearchMapDialog.title"); - initialize(); - } - + setPreferredSize(new Dimension(1200, 1600)); - @Override - protected JPanel createButtonPanel() { - JButton cancelButton = new ButtonEsc(new CloseAction(this)); - JButton okButton = new DialogButton(Messages.getString("Ok.text")); - okButton.addActionListener(this::okButtonActionPerformed); - getRootPane().setDefaultButton(okButton); - - JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 20, 0)); - buttonPanel.add(okButton); - buttonPanel.add(cancelButton); - - JPanel outerPanel = new JPanel(new GridLayout(1,1)); - outerPanel.setBorder(BorderFactory.createCompoundBorder( - new MatteBorder(1, 0, 0, 0, UIManager.getColor("Separator.foreground")), - new EmptyBorder(10, 0, 10, 0))); - outerPanel.add(buttonPanel); - - return outerPanel; + initialize(); } @Override protected Container createCenterPane() { bc = BoardClassifier.getInstance(); - JPanel advancedSearchPane = new JPanel(); + JPanel advancedSearchPane = new JPanel(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.gridwidth = 1; + c.gridheight = 1; + c.weightx = 0; + c.weighty = 0; + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.NORTHWEST; + c.insets = new Insets(2, 2, 2, 2); - advancedSearchPane.setLayout(new BoxLayout(advancedSearchPane, BoxLayout.PAGE_AXIS)); + c.gridx = 0; + c.gridy = 0; - advancedSearchPane.add(createInfo()); + advancedSearchPane.add(createInfo(), c); JPanel mainPanel = new JPanel(new FlowLayout()); mainPanel.add(createFilter()); mainPanel.add(createList()); - advancedSearchPane.add(mainPanel); + c.gridy++; + advancedSearchPane.add(mainPanel, c); return advancedSearchPane; - } private JPanel createInfo() { @@ -154,11 +135,12 @@ public void valueChanged(ListSelectionEvent e) { } private JPanel createList() { - JPanel listPanel = new JPanel(new FlowLayout()); + JPanel listPanel = new JPanel(); + listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.PAGE_AXIS)); boardModel = new BoardTableModel(); boardModel.setData(bc.getBoardPaths().values().stream().toList()); boardTable = new JTable(); - boardTable.setName("RAT"); + boardTable.setName("Board"); ListSelectionModel boardSelModel = boardTable.getSelectionModel(); boardSelModel.addListSelectionListener (new ListSelectionListener() { @Override @@ -184,12 +166,19 @@ public void valueChanged(ListSelectionEvent e) { listPanel.add(new JScrollPane(boardTable)); + JPanel countPanel = new JPanel(new FlowLayout()); + JLabel countLabel = new JLabel("Count: "); + countPanel.add(countLabel); + boardCountLabel = new JLabel(boardTable.getRowCount() + ""); + countPanel.add(boardCountLabel); + listPanel.add(countPanel); + boardTable.setRowSelectionInterval(0,0); return listPanel; } - void filterTables() { + private void filterTables() { RowFilter boardFilter; try { boardFilter = new RowFilter<>() { @@ -211,9 +200,15 @@ public boolean include(Entry entry } boardSorter.setRowFilter(boardFilter); + boardCountLabel.setText(boardTable.getRowCount() + ""); + + if (boardTable.getRowCount() > 0) { + boardTable.setRowSelectionInterval(0, 0); + boardTable.scrollRectToVisible(boardTable.getCellRect(0, 0, true)); + } } - boolean matchPath(String path) { + private boolean matchPath(String path) { List include = listBoardPaths.getSelectedValuesList(); String value = path.substring(0, path.lastIndexOf("\\") + 1 ); @@ -221,7 +216,7 @@ boolean matchPath(String path) { return !include.isEmpty() && include.stream().anyMatch(value::contains); } - boolean matchTag(List tags) { + private boolean matchTag(List tags) { List include = listBoardTags.getSelectedValuesList(); return !include.isEmpty() && include.stream().anyMatch(tags::contains); diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java index 554aac5bb98..d80a49ff36d 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java @@ -113,6 +113,7 @@ public boolean isCellEditable(int row, int col) { @Override public Object getValueAt(int row, int col) { String path = getPathAt(row); + String size = getSizeAt(row); if (path== null) { return "?"; @@ -123,6 +124,12 @@ public Object getValueAt(int row, int col) { if (col == COL_NAME) { value = path.substring(path.lastIndexOf("\\") + 1, path.length()); value = value.substring(0, value.lastIndexOf(".board")); + value = value.replace(size, "").trim(); + if ((!value.isEmpty()) + && (value.charAt(0) == '-')) { + value = value.substring(1, value.length()).trim(); + } + } else if (col == COL_SIZE) { value = getSizeAt(row); } From c298db5fe5dac5965b6007f832b246a3dd8f3d25 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sun, 10 Nov 2024 00:27:27 -0500 Subject: [PATCH 03/16] disable when using space map --- .../megamek/client/ui/advancedSearchMap/BoardTableModel.java | 3 +-- megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java index d80a49ff36d..6fae1a88064 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java @@ -125,11 +125,10 @@ public Object getValueAt(int row, int col) { value = path.substring(path.lastIndexOf("\\") + 1, path.length()); value = value.substring(0, value.lastIndexOf(".board")); value = value.replace(size, "").trim(); - if ((!value.isEmpty()) + if ((!value.isEmpty()) && (value.charAt(0) == '-')) { value = value.substring(1, value.length()).trim(); } - } else if (col == COL_SIZE) { value = getSizeAt(row); } diff --git a/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java b/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java index 2f98c2b0fe9..187c66fa8fd 100644 --- a/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java +++ b/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java @@ -975,6 +975,7 @@ private void refreshMapUI() { butLoadMapSetup.setEnabled(!inSpace); butMapShrinkW.setEnabled(mapSettings.getMapWidth() > 1); butMapShrinkH.setEnabled(mapSettings.getMapHeight() > 1); + butAdvancedSearchMap.setEnabled(!inSpace); butGroundMap.removeActionListener(lobbyListener); butLowAtmoMap.removeActionListener(lobbyListener); From caf47fb4488044017ee42c1d3bf064fec98713b3 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sun, 10 Nov 2024 08:05:13 -0500 Subject: [PATCH 04/16] disable when map page size is not 1x1 --- .../ui/advancedSearchMap/AdvancedSearchMapDialog.java | 1 + .../client/ui/advancedSearchMap/BoardTableModel.java | 6 +----- megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java index a6252e2ce54..91bf98cb760 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java @@ -155,6 +155,7 @@ public void valueChanged(ListSelectionEvent e) { }); boardTable.setModel(boardModel); boardSorter = new TableRowSorter<>(boardModel); + boardSorter.setSortKeys(List.of(new RowSorter.SortKey(0, SortOrder.ASCENDING))); boardTable.setRowSorter(boardSorter); boardTable.setIntercellSpacing(new Dimension(5, 0)); boardTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java index 6fae1a88064..05b27cdb2ee 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java @@ -125,12 +125,8 @@ public Object getValueAt(int row, int col) { value = path.substring(path.lastIndexOf("\\") + 1, path.length()); value = value.substring(0, value.lastIndexOf(".board")); value = value.replace(size, "").trim(); - if ((!value.isEmpty()) - && (value.charAt(0) == '-')) { - value = value.substring(1, value.length()).trim(); - } } else if (col == COL_SIZE) { - value = getSizeAt(row); + value = size; } return value; diff --git a/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java b/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java index 187c66fa8fd..c88fb580ad1 100644 --- a/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java +++ b/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java @@ -975,7 +975,7 @@ private void refreshMapUI() { butLoadMapSetup.setEnabled(!inSpace); butMapShrinkW.setEnabled(mapSettings.getMapWidth() > 1); butMapShrinkH.setEnabled(mapSettings.getMapHeight() > 1); - butAdvancedSearchMap.setEnabled(!inSpace); + butAdvancedSearchMap.setEnabled(!inSpace && (mapSettings.getMapWidth() == 1) && (mapSettings.getMapHeight() == 1)); butGroundMap.removeActionListener(lobbyListener); butLowAtmoMap.removeActionListener(lobbyListener); From 20d529631758d330c92bbb15bb02b15562612d55 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sun, 10 Nov 2024 08:42:37 -0500 Subject: [PATCH 05/16] cache tags and size to speed up reload --- .../AdvancedSearchMapDialog.java | 4 ++-- .../ui/advancedSearchMap/BoardTableModel.java | 15 +++++++-------- .../src/megamek/utilities/BoardClassifier.java | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 10 deletions(-) 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()); } } } From 71c8c6587ecb401b6727b5227bacb01cf3d6fbfb Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sun, 10 Nov 2024 08:56:51 -0500 Subject: [PATCH 06/16] code cleanup --- .../AdvancedSearchMapDialog.java | 15 +++++++++++--- .../ui/advancedSearchMap/BoardTableModel.java | 2 +- .../megamek/utilities/BoardClassifier.java | 20 +++++++++---------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java index a160e3cabce..a699160b7e4 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java @@ -96,6 +96,13 @@ private JPanel createFilter() { JPanel filterPanel = new JPanel(); filterPanel.setLayout(new BoxLayout(filterPanel, BoxLayout.PAGE_AXIS)); + filterPanel.add(createFilterTags()); + filterPanel.add(createFilterPaths()); + + return filterPanel; + } + + private JPanel createFilterTags() { List tags = Arrays.stream(BoardsTagger.Tags.values()).map(BoardsTagger.Tags::getName).distinct().sorted().toList(); DefaultListModel tagsModel = new DefaultListModel<>(); tagsModel.addAll(tags); @@ -111,8 +118,11 @@ public void valueChanged(ListSelectionEvent e) { JPanel boardTagsPanel = new JPanel(new BorderLayout()); boardTagsPanel.add(new JLabel("Board Tags"), BorderLayout.NORTH); boardTagsPanel.add(new JScrollPane(listBoardTags), BorderLayout.CENTER); - filterPanel.add(boardTagsPanel); + return boardTagsPanel; + } + + private JPanel createFilterPaths() { List paths = bc.getBoardPaths().values().stream().toList(); paths = paths.stream().map(p -> p.substring(0, p.lastIndexOf("\\") + 1 )).distinct().sorted().toList(); DefaultListModel pathsModel = new DefaultListModel<>(); @@ -129,9 +139,8 @@ public void valueChanged(ListSelectionEvent e) { JPanel boardPathsPanel = new JPanel(new BorderLayout()); boardPathsPanel.add(new JLabel("Board Paths"), BorderLayout.NORTH); boardPathsPanel.add(new JScrollPane(listBoardPaths), BorderLayout.CENTER); - filterPanel.add(boardPathsPanel); - return filterPanel; + return boardPathsPanel; } private JPanel createList() { diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java index 245aeaf9148..8c347440055 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java @@ -33,7 +33,7 @@ import java.util.List; /** - * A table model for the advanced search weapon tab's equipment list + * A table model for the advanced map search */ class BoardTableModel extends AbstractTableModel { private static final int COL_NAME = 0; diff --git a/megamek/src/megamek/utilities/BoardClassifier.java b/megamek/src/megamek/utilities/BoardClassifier.java index 5dbc97bb06a..3e609e7cb83 100644 --- a/megamek/src/megamek/utilities/BoardClassifier.java +++ b/megamek/src/megamek/utilities/BoardClassifier.java @@ -152,18 +152,18 @@ private void scanForBoardsInDir(final File boardDir, final String basePath) { getBoardsByHeight().get(dimension.height()).add(filePath.getPath()); getBoardsByWidth().get(dimension.width()).add(filePath.getPath()); - } - for (String tagString : Board.getTags(filePath)) { - Tags tag = Tags.parse(tagString); - getBoardsByTag().putIfAbsent(tag, new ArrayList<>()); - getBoardsByTag().get(tag).add(filePath.getPath()); - } + for (String tagString : Board.getTags(filePath)) { + Tags tag = Tags.parse(tagString); + getBoardsByTag().putIfAbsent(tag, new ArrayList<>()); + getBoardsByTag().get(tag).add(filePath.getPath()); + } - 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()); + 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()); + } } } } From 9eedda58f39aa813e3223ae2097f75b112d03df6 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sun, 10 Nov 2024 09:43:12 -0500 Subject: [PATCH 07/16] add toggle between any and all on tag filter --- .../AdvancedSearchMapDialog.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java index a699160b7e4..2cc75d77303 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java @@ -28,6 +28,7 @@ import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableRowSorter; import java.awt.*; +import java.awt.event.ActionEvent; import java.util.Arrays; import java.util.List; import java.util.regex.PatternSyntaxException; @@ -39,6 +40,7 @@ public class AdvancedSearchMapDialog extends AbstractButtonDialog { private BoardClassifier bc; private JTable boardTable; private JList listBoardTags; + private final JCheckBox boardTagsAllCheckBox = new JCheckBox("All"); private JList listBoardPaths; private JLabel boardImage; private JLabel boardInfo; @@ -116,7 +118,19 @@ public void valueChanged(ListSelectionEvent e) { } }); JPanel boardTagsPanel = new JPanel(new BorderLayout()); - boardTagsPanel.add(new JLabel("Board Tags"), BorderLayout.NORTH); + Box titlePanel = new Box(BoxLayout.LINE_AXIS); + titlePanel.setAlignmentX(Component.LEFT_ALIGNMENT); + titlePanel.add(new JLabel("Board Tags")); + titlePanel.add(Box.createRigidArea( new Dimension(5, 0))); + boardTagsAllCheckBox.setSelected(false); + boardTagsAllCheckBox.addActionListener(new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + filterTables(); + } + }); + titlePanel.add(boardTagsAllCheckBox); + boardTagsPanel.add(titlePanel, BorderLayout.NORTH); boardTagsPanel.add(new JScrollPane(listBoardTags), BorderLayout.CENTER); return boardTagsPanel; @@ -229,7 +243,11 @@ private boolean matchPath(String path) { private boolean matchTag(List tags) { List include = listBoardTags.getSelectedValuesList(); - return !include.isEmpty() && include.stream().anyMatch(tags::contains); + if (boardTagsAllCheckBox.isSelected()) { + return !include.isEmpty() && include.stream().allMatch(tags::contains); + } else { + return !include.isEmpty() && include.stream().anyMatch(tags::contains); + } } public String getPath() { From d71ea43bf2dd69c6468a4b28ab47e29f8682c4f0 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sun, 10 Nov 2024 12:05:02 -0500 Subject: [PATCH 08/16] code cleanup --- megamek/src/megamek/utilities/BoardClassifier.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/megamek/src/megamek/utilities/BoardClassifier.java b/megamek/src/megamek/utilities/BoardClassifier.java index 3e609e7cb83..3294afe6814 100644 --- a/megamek/src/megamek/utilities/BoardClassifier.java +++ b/megamek/src/megamek/utilities/BoardClassifier.java @@ -19,11 +19,7 @@ package megamek.utilities; import java.io.File; -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import megamek.common.Board; @@ -153,14 +149,16 @@ private void scanForBoardsInDir(final File boardDir, final String basePath) { getBoardsByHeight().get(dimension.height()).add(filePath.getPath()); getBoardsByWidth().get(dimension.width()).add(filePath.getPath()); - for (String tagString : Board.getTags(filePath)) { + Set boardTags = Board.getTags(filePath); + + for (String tagString : boardTags) { Tags tag = Tags.parse(tagString); getBoardsByTag().putIfAbsent(tag, new ArrayList<>()); getBoardsByTag().get(tag).add(filePath.getPath()); } getBoardPaths().put(filePath.getPath(), partialBoardPath); - getBoardTags().put(filePath.getPath(), Board.getTags(filePath).toString()); + getBoardTags().put(filePath.getPath(), boardTags.toString()); getBoardWidth().put(filePath.getPath(), dimension.width()); getBoardHeigth().put(filePath.getPath(), dimension.height()); } From 8e2385df6f83199aaac0dd2a585f629aeeb9060a Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sun, 10 Nov 2024 14:31:54 -0500 Subject: [PATCH 09/16] add width, height, and name filters --- .../AdvancedSearchMapDialog.java | 153 ++++++++++++++++-- .../ui/advancedSearchMap/BoardTableModel.java | 25 +++ .../ui/advancedsearch/MekSearchFilter.java | 97 +++++------ .../src/megamek/common/util/StringUtil.java | 18 ++- .../megamek/utilities/BoardClassifier.java | 6 +- 5 files changed, 224 insertions(+), 75 deletions(-) diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java index 2cc75d77303..fcf2bc1ecef 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java @@ -19,10 +19,13 @@ package megamek.client.ui.advancedSearchMap; import megamek.client.ui.baseComponents.AbstractButtonDialog; +import megamek.common.util.StringUtil; import megamek.utilities.BoardClassifier; import megamek.utilities.BoardsTagger; import javax.swing.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.table.DefaultTableCellRenderer; @@ -47,6 +50,11 @@ public class AdvancedSearchMapDialog extends AbstractButtonDialog { private TableRowSorter boardSorter; private BoardTableModel boardModel; private JLabel boardCountLabel; + private JTextField widthStartTextField = new JTextField(4); + private JTextField widthEndTextField = new JTextField(4); + private JTextField heightStartTextField = new JTextField(4); + private JTextField heightEndTextField = new JTextField(4); + private JTextField nameTextField = new JTextField(4); public AdvancedSearchMapDialog(JFrame parent) { super(parent, true, "AdvancedSearchMapDialog", "AdvancedSearchMapDialog.title"); @@ -98,25 +106,99 @@ private JPanel createFilter() { JPanel filterPanel = new JPanel(); filterPanel.setLayout(new BoxLayout(filterPanel, BoxLayout.PAGE_AXIS)); + filterPanel.add(createFilterRange(widthStartTextField, widthEndTextField, "Width:")); + filterPanel.add(createFilterRange(heightStartTextField, heightEndTextField, "Height:")); + filterPanel.add(createFilterText(nameTextField, "Name:")); filterPanel.add(createFilterTags()); filterPanel.add(createFilterPaths()); return filterPanel; } - private JPanel createFilterTags() { - 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); - listBoardTags.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); - listBoardTags.addSelectionInterval(0, tags.size()); - listBoardTags.addListSelectionListener (new ListSelectionListener() { + private JPanel createFilterText(JTextField textField, String caption) { + JPanel textPanel = new JPanel(new BorderLayout()); + Box textBox = new Box(BoxLayout.LINE_AXIS); + textBox.setAlignmentX(Component.LEFT_ALIGNMENT); + + textBox.add(new JLabel(caption)); + textBox.add(Box.createRigidArea( new Dimension(5, 0))); + textField.getDocument().addDocumentListener(new DocumentListener() { @Override - public void valueChanged(ListSelectionEvent e) { + public void insertUpdate(DocumentEvent e) { + filterTables(); + } + + @Override + public void removeUpdate(DocumentEvent e) { + filterTables(); + } + + @Override + public void changedUpdate(DocumentEvent e) { + filterTables(); + } + }); + textBox.add(textField); + + textPanel.add(textBox); + + return textPanel; + } + + private JPanel createFilterRange(JTextField startTextField, JTextField endTextField, String caption) { + JPanel textPanel = new JPanel(new BorderLayout()); + + Box textBox = new Box(BoxLayout.LINE_AXIS); + textBox.setAlignmentX(Component.LEFT_ALIGNMENT); + + textBox.add(new JLabel(caption)); + textBox.add(Box.createRigidArea( new Dimension(5, 0))); + startTextField.getDocument().addDocumentListener(new DocumentListener() { + @Override + public void insertUpdate(DocumentEvent e) { + filterTables(); + } + + @Override + public void removeUpdate(DocumentEvent e) { + filterTables(); + } + + @Override + public void changedUpdate(DocumentEvent e) { + filterTables(); + } + }); + textBox.add(startTextField); + + textBox.add(new JLabel(" - ")); + endTextField.getDocument().addDocumentListener(new DocumentListener() { + @Override + public void insertUpdate(DocumentEvent e) { + filterTables(); + } + + @Override + public void removeUpdate(DocumentEvent e) { + filterTables(); + } + + @Override + public void changedUpdate(DocumentEvent e) { filterTables(); } }); + textBox.add(endTextField); + + textPanel.add(textBox, BorderLayout.NORTH); + return textPanel; + } + + private JPanel createFilterTags() { + List tags = Arrays.stream(BoardsTagger.Tags.values()).map(BoardsTagger.Tags::getName).distinct().sorted().toList(); + DefaultListModel tagsModel = new DefaultListModel<>(); + tagsModel.addAll(tags); + JPanel boardTagsPanel = new JPanel(new BorderLayout()); Box titlePanel = new Box(BoxLayout.LINE_AXIS); titlePanel.setAlignmentX(Component.LEFT_ALIGNMENT); @@ -130,7 +212,18 @@ public void actionPerformed(ActionEvent e) { } }); titlePanel.add(boardTagsAllCheckBox); + + listBoardTags = new JList<>(tagsModel); + listBoardTags.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + listBoardTags.addSelectionInterval(0, tags.size()); + listBoardTags.addListSelectionListener (new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + filterTables(); + } + }); boardTagsPanel.add(titlePanel, BorderLayout.NORTH); + boardTagsPanel.add(new JScrollPane(listBoardTags), BorderLayout.CENTER); return boardTagsPanel; @@ -158,11 +251,29 @@ public void valueChanged(ListSelectionEvent e) { } private JPanel createList() { - JPanel listPanel = new JPanel(); - listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.PAGE_AXIS)); + JPanel listPanel = new JPanel(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.gridwidth = 1; + c.gridheight = 1; + c.weightx = 0; + c.weighty = 0; + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.NORTHWEST; + c.insets = new Insets(2, 2, 2, 2); + + c.gridx = 0; + c.gridy = 0; + boardModel = new BoardTableModel(); boardModel.setData(bc); - boardTable = new JTable(); + boardTable = new JTable() { + @Override + public Dimension getPreferredScrollableViewportSize() { + Dimension standardSize = super.getPreferredScrollableViewportSize(); + return new Dimension(standardSize.width, getRowHeight() * 20); + } + }; + boardTable.setName("Board"); ListSelectionModel boardSelModel = boardTable.getSelectionModel(); boardSelModel.addListSelectionListener (new ListSelectionListener() { @@ -185,19 +296,21 @@ public void valueChanged(ListSelectionEvent e) { for (int i = 0; i < boardModel.getColumnCount(); i++) { boardTable.getColumnModel().getColumn(i).setPreferredWidth(boardModel.getPreferredWidth(i)); } + boardTable.setRowSelectionInterval(0,0); DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer(); rightRenderer.setHorizontalAlignment(JLabel.RIGHT); + boardTable.setFillsViewportHeight(true); + listPanel.add(new JScrollPane(boardTable), c); - listPanel.add(new JScrollPane(boardTable)); + c.gridy++; + c.fill = GridBagConstraints.HORIZONTAL; JPanel countPanel = new JPanel(new FlowLayout()); JLabel countLabel = new JLabel("Count: "); countPanel.add(countLabel); boardCountLabel = new JLabel(boardTable.getRowCount() + ""); countPanel.add(boardCountLabel); - listPanel.add(countPanel); - - boardTable.setRowSelectionInterval(0,0); + listPanel.add(countPanel, c); return listPanel; } @@ -216,7 +329,13 @@ public boolean include(Entry entry List tags = eqModel.getTagAt(entry.getIdentifier()); boolean tagMatch = matchTag(tags); - return pathMatch && tagMatch; + boolean widthMatch = StringUtil.isBetween(eqModel.getWidthAt(entry.getIdentifier()), widthStartTextField.getText(), widthEndTextField.getText()); + + boolean heightMatch = StringUtil.isBetween(eqModel.getHeightAt(entry.getIdentifier()), heightStartTextField.getText(), heightEndTextField.getText()); + + boolean nameMatch = eqModel.getPathAt(entry.getIdentifier()).toUpperCase().contains(nameTextField.getText().toUpperCase()); + + return pathMatch && tagMatch && widthMatch && heightMatch && nameMatch; } }; } catch (PatternSyntaxException ignored) { diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java index 8c347440055..c6ff31ce7aa 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java @@ -43,6 +43,9 @@ class BoardTableModel extends AbstractTableModel { private List data; private List tags; private List size; + private List width; + private List height; + public BoardTableModel() { data = new ArrayList<>(); @@ -57,6 +60,8 @@ public void clearData() { data = new ArrayList<>(); tags = new ArrayList<>(); size = new ArrayList<>(); + width = new ArrayList<>(); + height = new ArrayList<>(); fireTableDataChanged(); } @@ -77,11 +82,15 @@ public void setData(BoardClassifier bc) { data = bc.getBoardPaths().values().stream().toList();; tags = new ArrayList<>(); size = new ArrayList<>(); + width = new ArrayList<>(); + height = new ArrayList<>(); 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)); + width.add(bc.getBoardWidth().get(key)); + height.add(bc.getBoardHeigth().get(key)); } fireTableDataChanged(); @@ -147,6 +156,22 @@ public String getSizeAt(int row) { return size.get(row); } + public Integer getWidthAt(int row) { + if (width.size() <= row) { + return null; + } + + return width.get(row); + } + + public Integer getHeightAt(int row) { + if (height.size() <= row) { + return null; + } + + return height.get(row); + } + public List getAllPaths() { return data; } diff --git a/megamek/src/megamek/client/ui/advancedsearch/MekSearchFilter.java b/megamek/src/megamek/client/ui/advancedsearch/MekSearchFilter.java index 490fcd74c9c..631dfddc3b8 100644 --- a/megamek/src/megamek/client/ui/advancedsearch/MekSearchFilter.java +++ b/megamek/src/megamek/client/ui/advancedsearch/MekSearchFilter.java @@ -342,17 +342,6 @@ public String getEquipmentExpression() { return equipmentCriteria.toString(); } - private static boolean isBetween(double value, String sStart, String sEnd) { - if (sStart.isEmpty() && sEnd.isEmpty()) { - return true; - } - - int iStart = StringUtil.toInt(sStart, Integer.MIN_VALUE); - int iEnd = StringUtil.toInt(sEnd, Integer.MAX_VALUE); - - return (!(value < iStart)) && (!(value > iEnd)); - } - private static boolean isMatch(int i, boolean b) { if (i == 1) { return b; @@ -493,179 +482,179 @@ public static boolean isMatch(MekSummary mek, MekSearchFilter f) { } // Check walk criteria - if (!isBetween(mek.getWalkMp(), f.sStartWalk, f.sEndWalk)) { + if (!StringUtil.isBetween(mek.getWalkMp(), f.sStartWalk, f.sEndWalk)) { return false; } // Check jump criteria - if (!isBetween(mek.getJumpMp(), f.sStartJump, f.sEndJump)) { + if (!StringUtil.isBetween(mek.getJumpMp(), f.sStartJump, f.sEndJump)) { return false; } // Check year criteria - if (!isBetween(mek.getYear(), f.sStartYear, f.sEndYear)) { + if (!StringUtil.isBetween(mek.getYear(), f.sStartYear, f.sEndYear)) { return false; } // Check Tonnage criteria - if (!isBetween((int) mek.getTons(), f.sStartTons, f.sEndTons)) { + if (!StringUtil.isBetween((int) mek.getTons(), f.sStartTons, f.sEndTons)) { return false; } // Check BV criteria - if (!isBetween(mek.getBV(), f.sStartBV, f.sEndBV)) { + if (!StringUtil.isBetween(mek.getBV(), f.sStartBV, f.sEndBV)) { return false; } - if (!isBetween(mek.getTankTurrets(), f.sStartTankTurrets, f.sEndTankTurrets)) { + if (!StringUtil.isBetween(mek.getTankTurrets(), f.sStartTankTurrets, f.sEndTankTurrets)) { return false; } - if (!isBetween(mek.getLowerArms(), f.sStartLowerArms, f.sEndLowerArms)) { + if (!StringUtil.isBetween(mek.getLowerArms(), f.sStartLowerArms, f.sEndLowerArms)) { return false; } - if (!isBetween(mek.getHands(), f.sStartHands, f.sEndHands)) { + if (!StringUtil.isBetween(mek.getHands(), f.sStartHands, f.sEndHands)) { return false; } - if (!isBetween(mek.getTroopCarryingSpace(), f.sStartTroopSpace, f.sEndTroopSpace)) { + if (!StringUtil.isBetween(mek.getTroopCarryingSpace(), f.sStartTroopSpace, f.sEndTroopSpace)) { return false; } - if (!isBetween(mek.getASFBays(), f.sStartASFBays, f.sEndASFBays)) { + if (!StringUtil.isBetween(mek.getASFBays(), f.sStartASFBays, f.sEndASFBays)) { return false; } - if (!isBetween(mek.getASFDoors(), f.sStartASFDoors, f.sEndASFDoors)) { + if (!StringUtil.isBetween(mek.getASFDoors(), f.sStartASFDoors, f.sEndASFDoors)) { return false; } - if (!isBetween(mek.getASFUnits(), f.sStartASFUnits, f.sEndASFUnits)) { + if (!StringUtil.isBetween(mek.getASFUnits(), f.sStartASFUnits, f.sEndASFUnits)) { return false; } - if (!isBetween(mek.getSmallCraftBays(), f.sStartSmallCraftBays, f.sEndSmallCraftBays)) { + if (!StringUtil.isBetween(mek.getSmallCraftBays(), f.sStartSmallCraftBays, f.sEndSmallCraftBays)) { return false; } - if (!isBetween(mek.getSmallCraftDoors(), f.sStartSmallCraftDoors, f.sEndSmallCraftDoors)) { + if (!StringUtil.isBetween(mek.getSmallCraftDoors(), f.sStartSmallCraftDoors, f.sEndSmallCraftDoors)) { return false; } - if (!isBetween(mek.getSmallCraftUnits(), f.sStartSmallCraftUnits, f.sEndSmallCraftUnits)) { + if (!StringUtil.isBetween(mek.getSmallCraftUnits(), f.sStartSmallCraftUnits, f.sEndSmallCraftUnits)) { return false; } - if (!isBetween(mek.getMekBays(), f.sStartMekBays, f.sEndMekBays)) { + if (!StringUtil.isBetween(mek.getMekBays(), f.sStartMekBays, f.sEndMekBays)) { return false; } - if (!isBetween(mek.getMekDoors(), f.sStartMekDoors, f.sEndMekDoors)) { + if (!StringUtil.isBetween(mek.getMekDoors(), f.sStartMekDoors, f.sEndMekDoors)) { return false; } - if (!isBetween(mek.getMekUnits(), f.sStartMekUnits, f.sEndMekUnits)) { + if (!StringUtil.isBetween(mek.getMekUnits(), f.sStartMekUnits, f.sEndMekUnits)) { return false; } - if (!isBetween(mek.getHeavyVehicleBays(), f.sStartHeavyVehicleBays, f.sEndHeavyVehicleBays)) { + if (!StringUtil.isBetween(mek.getHeavyVehicleBays(), f.sStartHeavyVehicleBays, f.sEndHeavyVehicleBays)) { return false; } - if (!isBetween(mek.getHeavyVehicleDoors(), f.sStartHeavyVehicleDoors, f.sEndHeavyVehicleDoors)) { + if (!StringUtil.isBetween(mek.getHeavyVehicleDoors(), f.sStartHeavyVehicleDoors, f.sEndHeavyVehicleDoors)) { return false; } - if (!isBetween(mek.getHeavyVehicleUnits(), f.sStartHeavyVehicleUnits, f.sEndHeavyVehicleUnits)) { + if (!StringUtil.isBetween(mek.getHeavyVehicleUnits(), f.sStartHeavyVehicleUnits, f.sEndHeavyVehicleUnits)) { return false; } - if (!isBetween(mek.getLightVehicleBays(), f.sStartLightVehicleBays, f.sEndLightVehicleBays)) { + if (!StringUtil.isBetween(mek.getLightVehicleBays(), f.sStartLightVehicleBays, f.sEndLightVehicleBays)) { return false; } - if (!isBetween(mek.getLightVehicleDoors(), f.sStartLightVehicleDoors, f.sEndLightVehicleDoors)) { + if (!StringUtil.isBetween(mek.getLightVehicleDoors(), f.sStartLightVehicleDoors, f.sEndLightVehicleDoors)) { return false; } - if (!isBetween(mek.getLightVehicleUnits(), f.sStartLightVehicleUnits, f.sEndLightVehicleUnits)) { + if (!StringUtil.isBetween(mek.getLightVehicleUnits(), f.sStartLightVehicleUnits, f.sEndLightVehicleUnits)) { return false; } - if (!isBetween(mek.getProtoMekBays(), f.sStartProtomekBays, f.sEndProtomekBays)) { + if (!StringUtil.isBetween(mek.getProtoMekBays(), f.sStartProtomekBays, f.sEndProtomekBays)) { return false; } - if (!isBetween(mek.getProtoMekDoors(), f.sStartProtomekDoors, f.sEndProtomekDoors)) { + if (!StringUtil.isBetween(mek.getProtoMekDoors(), f.sStartProtomekDoors, f.sEndProtomekDoors)) { return false; } - if (!isBetween(mek.getProtoMekUnits(), f.sStartProtomekUnits, f.sEndProtomekUnits)) { + if (!StringUtil.isBetween(mek.getProtoMekUnits(), f.sStartProtomekUnits, f.sEndProtomekUnits)) { return false; } - if (!isBetween(mek.getBattleArmorBays(), f.sStartBattleArmorBays, f.sEndBattleArmorBays)) { + if (!StringUtil.isBetween(mek.getBattleArmorBays(), f.sStartBattleArmorBays, f.sEndBattleArmorBays)) { return false; } - if (!isBetween(mek.getBattleArmorDoors(), f.sStartBattleArmorDoors, f.sEndBattleArmorDoors)) { + if (!StringUtil.isBetween(mek.getBattleArmorDoors(), f.sStartBattleArmorDoors, f.sEndBattleArmorDoors)) { return false; } - if (!isBetween(mek.getBattleArmorUnits(), f.sStartBattleArmorUnits, f.sEndBattleArmorUnits)) { + if (!StringUtil.isBetween(mek.getBattleArmorUnits(), f.sStartBattleArmorUnits, f.sEndBattleArmorUnits)) { return false; } - if (!isBetween(mek.getInfantryBays(), f.sStartInfantryBays, f.sEndInfantryBays)) { + if (!StringUtil.isBetween(mek.getInfantryBays(), f.sStartInfantryBays, f.sEndInfantryBays)) { return false; } - if (!isBetween(mek.getInfantryDoors(), f.sStartInfantryDoors, f.sEndInfantryDoors)) { + if (!StringUtil.isBetween(mek.getInfantryDoors(), f.sStartInfantryDoors, f.sEndInfantryDoors)) { return false; } - if (!isBetween(mek.getInfantryUnits(), f.sStartInfantryUnits, f.sEndInfantryUnits)) { + if (!StringUtil.isBetween(mek.getInfantryUnits(), f.sStartInfantryUnits, f.sEndInfantryUnits)) { return false; } - if (!isBetween(mek.getSuperHeavyVehicleBays(), f.sStartSuperHeavyVehicleBays, f.sEndSuperHeavyVehicleBays)) { + if (!StringUtil.isBetween(mek.getSuperHeavyVehicleBays(), f.sStartSuperHeavyVehicleBays, f.sEndSuperHeavyVehicleBays)) { return false; } - if (!isBetween(mek.getSuperHeavyVehicleDoors(), f.sStartSuperHeavyVehicleDoors, f.sEndSuperHeavyVehicleDoors)) { + if (!StringUtil.isBetween(mek.getSuperHeavyVehicleDoors(), f.sStartSuperHeavyVehicleDoors, f.sEndSuperHeavyVehicleDoors)) { return false; } - if (!isBetween(mek.getSuperHeavyVehicleUnits(), f.sStartSuperHeavyVehicleUnits, f.sEndSuperHeavyVehicleUnits)) { + if (!StringUtil.isBetween(mek.getSuperHeavyVehicleUnits(), f.sStartSuperHeavyVehicleUnits, f.sEndSuperHeavyVehicleUnits)) { return false; } - if (!isBetween(mek.getDropshuttleBays(), f.sStartDropshuttleBays, f.sEndDropshuttleBays)) { + if (!StringUtil.isBetween(mek.getDropshuttleBays(), f.sStartDropshuttleBays, f.sEndDropshuttleBays)) { return false; } - if (!isBetween(mek.getDropshuttleDoors(), f.sStartDropshuttleDoors, f.sEndDropshuttleDoors)) { + if (!StringUtil.isBetween(mek.getDropshuttleDoors(), f.sStartDropshuttleDoors, f.sEndDropshuttleDoors)) { return false; } - if (!isBetween(mek.getDropshuttelUnits(), f.sStartDropshuttleUnits, f.sEndDropshuttleUnits)) { + if (!StringUtil.isBetween(mek.getDropshuttelUnits(), f.sStartDropshuttleUnits, f.sEndDropshuttleUnits)) { return false; } - if (!isBetween(mek.getDockingCollars(), f.sStartDockingCollars, f.sEndDockingCollars)) { + if (!StringUtil.isBetween(mek.getDockingCollars(), f.sStartDockingCollars, f.sEndDockingCollars)) { return false; } - if (!isBetween(mek.getBattleArmorHandles(), f.sStartBattleArmorHandles, f.sEndBattleArmorHandles)) { + if (!StringUtil.isBetween(mek.getBattleArmorHandles(), f.sStartBattleArmorHandles, f.sEndBattleArmorHandles)) { return false; } - if (!isBetween(mek.getCargoBayUnits(), f.sStartCargoBayUnits, f.sEndCargoBayUnits)) { + if (!StringUtil.isBetween(mek.getCargoBayUnits(), f.sStartCargoBayUnits, f.sEndCargoBayUnits)) { return false; } - if (!isBetween(mek.getNavalRepairFacilities(), f.sStartNavalRepairFacilities, f.sEndNavalRepairFacilities)) { + if (!StringUtil.isBetween(mek.getNavalRepairFacilities(), f.sStartNavalRepairFacilities, f.sEndNavalRepairFacilities)) { return false; } diff --git a/megamek/src/megamek/common/util/StringUtil.java b/megamek/src/megamek/common/util/StringUtil.java index aacd01bf59c..4db08e960a5 100644 --- a/megamek/src/megamek/common/util/StringUtil.java +++ b/megamek/src/megamek/common/util/StringUtil.java @@ -57,7 +57,7 @@ public static String makeLength(int s, int n) { /** * A utility for padding out a string with spaces. - * + * * @param s the string to pad * @param n the desired length of the resultant string * @param bRightJustify true if the string should be right justified @@ -82,7 +82,7 @@ public static String makeLength(String s, int n, boolean bRightJustify) { * the end. The format of the stamp is dictated by the client option * "StampFormat", which must use the same formatting as Java's * DateTimeFormatter class. - * + * * @param filename the String containing the filename (with extension) * @return the filename with date/time stamp added */ @@ -183,4 +183,18 @@ public static float toFloat(String s, float i) { return i; } } + + /** + * Returns if value is between the start and end + */ + public static boolean isBetween(double value, String sStart, String sEnd) { + if (sStart.isEmpty() && sEnd.isEmpty()) { + return true; + } + + int iStart = StringUtil.toInt(sStart, Integer.MIN_VALUE); + int iEnd = StringUtil.toInt(sEnd, Integer.MAX_VALUE); + + return (!(value < iStart)) && (!(value > iEnd)); + } } diff --git a/megamek/src/megamek/utilities/BoardClassifier.java b/megamek/src/megamek/utilities/BoardClassifier.java index 3294afe6814..9ee76dac0d3 100644 --- a/megamek/src/megamek/utilities/BoardClassifier.java +++ b/megamek/src/megamek/utilities/BoardClassifier.java @@ -153,8 +153,10 @@ private void scanForBoardsInDir(final File boardDir, final String basePath) { for (String tagString : boardTags) { Tags tag = Tags.parse(tagString); - getBoardsByTag().putIfAbsent(tag, new ArrayList<>()); - getBoardsByTag().get(tag).add(filePath.getPath()); + if (tag != null) { + getBoardsByTag().putIfAbsent(tag, new ArrayList<>()); + getBoardsByTag().get(tag).add(filePath.getPath()); + } } getBoardPaths().put(filePath.getPath(), partialBoardPath); From e65f6f4898543d6812ad91fedcb4d7d17336edde Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sun, 10 Nov 2024 15:34:57 -0500 Subject: [PATCH 10/16] code cleanup --- .../AdvancedSearchMapDialog.java | 146 +++++++++--------- 1 file changed, 70 insertions(+), 76 deletions(-) diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java index fcf2bc1ecef..143c92cbcd7 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java @@ -41,15 +41,21 @@ */ public class AdvancedSearchMapDialog extends AbstractButtonDialog { private BoardClassifier bc; - private JTable boardTable; - private JList listBoardTags; + private JTable boardTable = new JTable() { + @Override + public Dimension getPreferredScrollableViewportSize() { + Dimension standardSize = super.getPreferredScrollableViewportSize(); + return new Dimension(standardSize.width, getRowHeight() * 20); + } + }; + private JList listBoardTags = new JList<>(); private final JCheckBox boardTagsAllCheckBox = new JCheckBox("All"); - private JList listBoardPaths; + private JList listBoardPaths = new JList<>(); private JLabel boardImage; private JLabel boardInfo; - private TableRowSorter boardSorter; - private BoardTableModel boardModel; - private JLabel boardCountLabel; + private TableRowSorter boardSorter = new TableRowSorter<>(); + private BoardTableModel boardModel = new BoardTableModel(); + private JLabel boardCountLabel = new JLabel(""); private JTextField widthStartTextField = new JTextField(4); private JTextField widthEndTextField = new JTextField(4); private JTextField heightStartTextField = new JTextField(4); @@ -77,7 +83,6 @@ protected Container createCenterPane() { c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new Insets(2, 2, 2, 2); - c.gridx = 0; c.gridy = 0; @@ -85,12 +90,13 @@ protected Container createCenterPane() { JPanel mainPanel = new JPanel(new FlowLayout()); mainPanel.add(createFilter()); - mainPanel.add(createList()); + mainPanel.add(createListTable()); c.gridy++; + advancedSearchPane.add(mainPanel, c); - return advancedSearchPane; + return new JScrollPane(advancedSearchPane); } private JPanel createInfo() { @@ -109,8 +115,15 @@ private JPanel createFilter() { filterPanel.add(createFilterRange(widthStartTextField, widthEndTextField, "Width:")); filterPanel.add(createFilterRange(heightStartTextField, heightEndTextField, "Height:")); filterPanel.add(createFilterText(nameTextField, "Name:")); - filterPanel.add(createFilterTags()); - filterPanel.add(createFilterPaths()); + + JPanel tagsTitlePanel = createTitleWithCheckBox(boardTagsAllCheckBox, "Board Tags"); + List tags = Arrays.stream(BoardsTagger.Tags.values()).map(BoardsTagger.Tags::getName).distinct().sorted().toList(); + filterPanel.add(createFilterList(listBoardTags, tags, tagsTitlePanel, true)); + + JPanel pathsTitlePanel = createTitle("Board Tags"); + List paths = bc.getBoardPaths().values().stream().toList(); + paths = paths.stream().map(p -> p.substring(0, p.lastIndexOf("\\") + 1 )).distinct().sorted().toList(); + filterPanel.add(createFilterList(listBoardPaths, paths, pathsTitlePanel, false)); return filterPanel; } @@ -194,86 +207,66 @@ public void changedUpdate(DocumentEvent e) { return textPanel; } - private JPanel createFilterTags() { - List tags = Arrays.stream(BoardsTagger.Tags.values()).map(BoardsTagger.Tags::getName).distinct().sorted().toList(); - DefaultListModel tagsModel = new DefaultListModel<>(); - tagsModel.addAll(tags); - - JPanel boardTagsPanel = new JPanel(new BorderLayout()); - Box titlePanel = new Box(BoxLayout.LINE_AXIS); - titlePanel.setAlignmentX(Component.LEFT_ALIGNMENT); - titlePanel.add(new JLabel("Board Tags")); - titlePanel.add(Box.createRigidArea( new Dimension(5, 0))); - boardTagsAllCheckBox.setSelected(false); - boardTagsAllCheckBox.addActionListener(new AbstractAction() { + private JPanel createTitleWithCheckBox(JCheckBox checkBox, String caption) { + JPanel titlePanel = new JPanel(new BorderLayout()); + + Box titleBox = new Box(BoxLayout.LINE_AXIS); + titleBox.setAlignmentX(Component.LEFT_ALIGNMENT); + titleBox.add(new JLabel(caption)); + titleBox.add(Box.createRigidArea( new Dimension(5, 0))); + checkBox.setSelected(false); + checkBox.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { filterTables(); } }); - titlePanel.add(boardTagsAllCheckBox); + titleBox.add(checkBox); + titlePanel.add(titleBox, BorderLayout.NORTH); - listBoardTags = new JList<>(tagsModel); - listBoardTags.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); - listBoardTags.addSelectionInterval(0, tags.size()); - listBoardTags.addListSelectionListener (new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - filterTables(); - } - }); - boardTagsPanel.add(titlePanel, BorderLayout.NORTH); + return titlePanel; + } + + private JPanel createTitle(String caption) { + JPanel titlePanel = new JPanel(new BorderLayout()); - boardTagsPanel.add(new JScrollPane(listBoardTags), BorderLayout.CENTER); + Box titleBox = new Box(BoxLayout.LINE_AXIS); + titleBox.setAlignmentX(Component.LEFT_ALIGNMENT); + titleBox.add(new JLabel(caption)); + titlePanel.add(titleBox, BorderLayout.NORTH); - return boardTagsPanel; + return titlePanel; } - private JPanel createFilterPaths() { - List paths = bc.getBoardPaths().values().stream().toList(); - paths = paths.stream().map(p -> p.substring(0, p.lastIndexOf("\\") + 1 )).distinct().sorted().toList(); - DefaultListModel pathsModel = new DefaultListModel<>(); - pathsModel.addAll(paths); - listBoardPaths = new JList<>(pathsModel); - listBoardPaths.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); - listBoardPaths.setSelectedIndex(0); - listBoardPaths.addListSelectionListener (new ListSelectionListener() { + private JPanel createFilterList(JList list, List data, JPanel title, boolean selectAll) { + DefaultListModel model = new DefaultListModel<>(); + model.addAll(data); + list.setModel(model); + list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + list.setSelectedIndex(0); + list.addListSelectionListener (new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { filterTables(); } }); + + if (selectAll) { + list.addSelectionInterval(0, data.size()); + } + JPanel boardPathsPanel = new JPanel(new BorderLayout()); - boardPathsPanel.add(new JLabel("Board Paths"), BorderLayout.NORTH); - boardPathsPanel.add(new JScrollPane(listBoardPaths), BorderLayout.CENTER); + boardPathsPanel.add(title, BorderLayout.NORTH); + boardPathsPanel.add(new JScrollPane(list), BorderLayout.CENTER); return boardPathsPanel; } - private JPanel createList() { - JPanel listPanel = new JPanel(new GridBagLayout()); - GridBagConstraints c = new GridBagConstraints(); - c.gridwidth = 1; - c.gridheight = 1; - c.weightx = 0; - c.weighty = 0; - c.fill = GridBagConstraints.BOTH; - c.anchor = GridBagConstraints.NORTHWEST; - c.insets = new Insets(2, 2, 2, 2); + private JPanel createListTable() { + JPanel listPanel = new JPanel(); + listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.PAGE_AXIS)); - c.gridx = 0; - c.gridy = 0; - - boardModel = new BoardTableModel(); boardModel.setData(bc); - boardTable = new JTable() { - @Override - public Dimension getPreferredScrollableViewportSize() { - Dimension standardSize = super.getPreferredScrollableViewportSize(); - return new Dimension(standardSize.width, getRowHeight() * 20); - } - }; - boardTable.setName("Board"); ListSelectionModel boardSelModel = boardTable.getSelectionModel(); boardSelModel.addListSelectionListener (new ListSelectionListener() { @@ -288,7 +281,7 @@ public void valueChanged(ListSelectionEvent e) { } }); boardTable.setModel(boardModel); - boardSorter = new TableRowSorter<>(boardModel); + boardSorter.setModel(boardModel); boardSorter.setSortKeys(List.of(new RowSorter.SortKey(0, SortOrder.ASCENDING))); boardTable.setRowSorter(boardSorter); boardTable.setIntercellSpacing(new Dimension(5, 0)); @@ -300,17 +293,15 @@ public void valueChanged(ListSelectionEvent e) { DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer(); rightRenderer.setHorizontalAlignment(JLabel.RIGHT); boardTable.setFillsViewportHeight(true); - listPanel.add(new JScrollPane(boardTable), c); - - c.gridy++; - c.fill = GridBagConstraints.HORIZONTAL; + listPanel.add(new JScrollPane(boardTable)); JPanel countPanel = new JPanel(new FlowLayout()); JLabel countLabel = new JLabel("Count: "); countPanel.add(countLabel); - boardCountLabel = new JLabel(boardTable.getRowCount() + ""); + + boardCountLabel.setText(boardModel.getRowCount() + ""); countPanel.add(boardCountLabel); - listPanel.add(countPanel, c); + listPanel.add(countPanel); return listPanel; } @@ -369,6 +360,9 @@ private boolean matchTag(List tags) { } } + /** + * Returns if path for the selected map when the dialog is confirmed + */ public String getPath() { int index = boardTable.getSelectedRow() ; if (index >= 0) { From 474def9efa90e5d6bcbf08235496c57705a86d68 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sun, 10 Nov 2024 17:02:56 -0500 Subject: [PATCH 11/16] code cleanup --- .../client/ui/advancedSearchMap/AdvancedSearchMapDialog.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java index 143c92cbcd7..d7ef8ea3650 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java @@ -19,6 +19,7 @@ package megamek.client.ui.advancedSearchMap; import megamek.client.ui.baseComponents.AbstractButtonDialog; +import megamek.client.ui.swing.util.UIUtil; import megamek.common.util.StringUtil; import megamek.utilities.BoardClassifier; import megamek.utilities.BoardsTagger; @@ -120,7 +121,7 @@ private JPanel createFilter() { List tags = Arrays.stream(BoardsTagger.Tags.values()).map(BoardsTagger.Tags::getName).distinct().sorted().toList(); filterPanel.add(createFilterList(listBoardTags, tags, tagsTitlePanel, true)); - JPanel pathsTitlePanel = createTitle("Board Tags"); + JPanel pathsTitlePanel = createTitle("Board Paths"); List paths = bc.getBoardPaths().values().stream().toList(); paths = paths.stream().map(p -> p.substring(0, p.lastIndexOf("\\") + 1 )).distinct().sorted().toList(); filterPanel.add(createFilterList(listBoardPaths, paths, pathsTitlePanel, false)); @@ -275,7 +276,7 @@ public void valueChanged(ListSelectionEvent e) { int index = boardTable.getSelectedRow() ; if (index >= 0) { index = boardTable.convertRowIndexToModel(index); - boardImage.setIcon(boardModel.getIconAt(index, 200)); + boardImage.setIcon(boardModel.getIconAt(index, UIUtil.scaleForGUI(200))); boardInfo.setText(boardModel.getInfoAt(index)); } } From cf84c9683e07094300849494b1d9279be77f9b96 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sun, 10 Nov 2024 21:47:58 -0500 Subject: [PATCH 12/16] 0 pad size to improve sort, add tooltips for range textfields --- .../client/ui/advancedSearchMap/AdvancedSearchMapDialog.java | 3 +++ .../megamek/client/ui/advancedSearchMap/BoardTableModel.java | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java index d7ef8ea3650..9a8d0c209f3 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java @@ -167,6 +167,7 @@ private JPanel createFilterRange(JTextField startTextField, JTextField endTextFi textBox.add(new JLabel(caption)); textBox.add(Box.createRigidArea( new Dimension(5, 0))); + startTextField.setToolTipText("start range, blank acts as wildcard"); startTextField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { @@ -186,6 +187,8 @@ public void changedUpdate(DocumentEvent e) { textBox.add(startTextField); textBox.add(new JLabel(" - ")); + + endTextField.setToolTipText("end range, blank acts as wildcard"); endTextField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java index c6ff31ce7aa..848c096e70b 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java @@ -122,6 +122,8 @@ public boolean isCellEditable(int row, int col) { public Object getValueAt(int row, int col) { String path = getPathAt(row); String size = getSizeAt(row); + Integer width = getWidthAt(row); + Integer height = getHeightAt(row); if (path== null) { return "?"; @@ -134,7 +136,7 @@ public Object getValueAt(int row, int col) { value = value.substring(0, value.lastIndexOf(".board")); value = value.replace(size, "").trim(); } else if (col == COL_SIZE) { - value = size; + value = String.format("%03dx%03d", width, height); } return value; From b4aba7e3fbf61b9f5d8f483c6b5d3967cd784a31 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Sun, 10 Nov 2024 21:58:17 -0500 Subject: [PATCH 13/16] code cleanup --- .../ui/advancedSearchMap/BoardTableModel.java | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java index 848c096e70b..60e2a872349 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java @@ -42,7 +42,6 @@ class BoardTableModel extends AbstractTableModel { private List data; private List tags; - private List size; private List width; private List height; @@ -59,7 +58,6 @@ public int getRowCount() { public void clearData() { data = new ArrayList<>(); tags = new ArrayList<>(); - size = new ArrayList<>(); width = new ArrayList<>(); height = new ArrayList<>(); fireTableDataChanged(); @@ -81,14 +79,12 @@ public int getPreferredWidth(int col) { public void setData(BoardClassifier bc) { data = bc.getBoardPaths().values().stream().toList();; tags = new ArrayList<>(); - size = new ArrayList<>(); width = new ArrayList<>(); height = new ArrayList<>(); 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)); width.add(bc.getBoardWidth().get(key)); height.add(bc.getBoardHeigth().get(key)); } @@ -121,20 +117,18 @@ public boolean isCellEditable(int row, int col) { @Override public Object getValueAt(int row, int col) { String path = getPathAt(row); - String size = getSizeAt(row); Integer width = getWidthAt(row); Integer height = getHeightAt(row); if (path== null) { return "?"; } - String value = ""; if (col == COL_NAME) { value = path.substring(path.lastIndexOf("\\") + 1, path.length()); value = value.substring(0, value.lastIndexOf(".board")); - value = value.replace(size, "").trim(); + value = value.replace(width + "x" + height, "").trim(); } else if (col == COL_SIZE) { value = String.format("%03dx%03d", width, height); } @@ -150,14 +144,6 @@ public String getPathAt(int row) { return data.get(row); } - public String getSizeAt(int row) { - if (size.size() <= row) { - return null; - } - - return size.get(row); - } - public Integer getWidthAt(int row) { if (width.size() <= row) { return null; From 306ac8eae151b5a693b198ecc05117c3f50f2276 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Mon, 11 Nov 2024 19:39:33 -0500 Subject: [PATCH 14/16] add text to messages --- .../i18n/megamek/client/messages.properties | 14 ++++++++++- .../AdvancedSearchMapDialog.java | 19 +++++++------- .../ui/advancedSearchMap/BoardTableModel.java | 25 ++++++++++--------- .../client/ui/swing/lobby/ChatLounge.java | 2 +- 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/megamek/i18n/megamek/client/messages.properties b/megamek/i18n/megamek/client/messages.properties index 3d1f23e90a0..d2d3f3754b3 100644 --- a/megamek/i18n/megamek/client/messages.properties +++ b/megamek/i18n/megamek/client/messages.properties @@ -155,7 +155,6 @@ BT.Quirks=Quirks AdvancedSearchDialog.title=Advanced Search -AdvancedSearchMapDialog.title=Advanced Search AimedShotDialog.dontAim=Don't aim @@ -169,6 +168,19 @@ AdvancedOptions.KeyRepeatRate.name=Key Repeat Rate AdvancedOptions.KeyRepeatRate.tooltip= Sets how frequently a key is repeated, if a keybind has the isRepeatable flag set. AdvancedOptions.ShowFPS.name=Show drawtime +AdvancedSearchMapDialog.boardTableCount=Count: +AdvancedSearchMapDialog.boardTableModel.name=Name +AdvancedSearchMapDialog.boardTableModel.size=Size +AdvancedSearchMapDialog.boardTagsAllCheckBox=All +AdvancedSearchMapDialog.filterBoardPaths=Board Paths +AdvancedSearchMapDialog.filterBoardTags=Board Tags +AdvancedSearchMapDialog.filterName=Name: +AdvancedSearchMapDialog.filterRangeEnd.tooltip=end range, blank acts as wildcard +AdvancedSearchMapDialog.filterRangeHeight=Height: +AdvancedSearchMapDialog.filterRangeStart.tooltip=start range, blank acts as wildcard +AdvancedSearchMapDialog.filterRangeWidth=Width: +AdvancedSearchMapDialog.title=Advanced Search + #Board Editor BoardEditor.BridgeBuildingElevError=Bridge/Building Elevation is an offset from the surface of a hex and hence must be a positive value! BoardEditor.OpenFileError=Could not open file {0}. diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java index 9a8d0c209f3..52bcf0c318e 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/AdvancedSearchMapDialog.java @@ -18,6 +18,7 @@ */ package megamek.client.ui.advancedSearchMap; +import megamek.client.ui.Messages; import megamek.client.ui.baseComponents.AbstractButtonDialog; import megamek.client.ui.swing.util.UIUtil; import megamek.common.util.StringUtil; @@ -50,7 +51,7 @@ public Dimension getPreferredScrollableViewportSize() { } }; private JList listBoardTags = new JList<>(); - private final JCheckBox boardTagsAllCheckBox = new JCheckBox("All"); + private final JCheckBox boardTagsAllCheckBox = new JCheckBox(Messages.getString("AdvancedSearchMapDialog.boardTagsAllCheckBox")); private JList listBoardPaths = new JList<>(); private JLabel boardImage; private JLabel boardInfo; @@ -113,15 +114,15 @@ private JPanel createFilter() { JPanel filterPanel = new JPanel(); filterPanel.setLayout(new BoxLayout(filterPanel, BoxLayout.PAGE_AXIS)); - filterPanel.add(createFilterRange(widthStartTextField, widthEndTextField, "Width:")); - filterPanel.add(createFilterRange(heightStartTextField, heightEndTextField, "Height:")); - filterPanel.add(createFilterText(nameTextField, "Name:")); + filterPanel.add(createFilterRange(widthStartTextField, widthEndTextField, Messages.getString("AdvancedSearchMapDialog.filterRangeWidth"))); + filterPanel.add(createFilterRange(heightStartTextField, heightEndTextField, Messages.getString("AdvancedSearchMapDialog.filterRangeHeight"))); + filterPanel.add(createFilterText(nameTextField, Messages.getString("AdvancedSearchMapDialog.filterName"))); - JPanel tagsTitlePanel = createTitleWithCheckBox(boardTagsAllCheckBox, "Board Tags"); + JPanel tagsTitlePanel = createTitleWithCheckBox(boardTagsAllCheckBox, Messages.getString("AdvancedSearchMapDialog.filterBoardTags")); List tags = Arrays.stream(BoardsTagger.Tags.values()).map(BoardsTagger.Tags::getName).distinct().sorted().toList(); filterPanel.add(createFilterList(listBoardTags, tags, tagsTitlePanel, true)); - JPanel pathsTitlePanel = createTitle("Board Paths"); + JPanel pathsTitlePanel = createTitle(Messages.getString("AdvancedSearchMapDialog.filterBoardPaths")); List paths = bc.getBoardPaths().values().stream().toList(); paths = paths.stream().map(p -> p.substring(0, p.lastIndexOf("\\") + 1 )).distinct().sorted().toList(); filterPanel.add(createFilterList(listBoardPaths, paths, pathsTitlePanel, false)); @@ -167,7 +168,7 @@ private JPanel createFilterRange(JTextField startTextField, JTextField endTextFi textBox.add(new JLabel(caption)); textBox.add(Box.createRigidArea( new Dimension(5, 0))); - startTextField.setToolTipText("start range, blank acts as wildcard"); + startTextField.setToolTipText(Messages.getString("AdvancedSearchMapDialog.filterRangeStart.tooltip")); startTextField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { @@ -188,7 +189,7 @@ public void changedUpdate(DocumentEvent e) { textBox.add(new JLabel(" - ")); - endTextField.setToolTipText("end range, blank acts as wildcard"); + endTextField.setToolTipText(Messages.getString("AdvancedSearchMapDialog.filterRangeEnd.tooltip")); endTextField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { @@ -300,7 +301,7 @@ public void valueChanged(ListSelectionEvent e) { listPanel.add(new JScrollPane(boardTable)); JPanel countPanel = new JPanel(new FlowLayout()); - JLabel countLabel = new JLabel("Count: "); + JLabel countLabel = new JLabel(Messages.getString("AdvancedSearchMapDialog.boardTableCount")); countPanel.add(countLabel); boardCountLabel.setText(boardModel.getRowCount() + ""); diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java index 60e2a872349..f163e02e456 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java @@ -18,6 +18,7 @@ */ package megamek.client.ui.advancedSearchMap; +import megamek.client.ui.Messages; import megamek.client.ui.swing.minimap.Minimap; import megamek.client.ui.swing.util.UIUtil; import megamek.common.*; @@ -96,9 +97,9 @@ public void setData(BoardClassifier bc) { public String getColumnName(int column) { switch (column) { case COL_NAME: - return "Name"; + return Messages.getString("AdvancedSearchMapDialog.boardTableModel.name"); case COL_SIZE: - return "Size"; + return Messages.getString("AdvancedSearchMapDialog.boardTableModel.size"); default: return "??"; } @@ -185,17 +186,17 @@ public String getInfoAt(int row) { board.load(new MegaMekFile(Configuration.boardsDir(), path).getFile()); String info; - String col = UIUtil.tag("td", "", path); - info = UIUtil.tag("tr", "", col); - col = UIUtil.tag("td", "", board.getWidth() + "x" + board.getHeight()); - info += UIUtil.tag("tr", "", col); - col = UIUtil.tag("td", "", board.getTags().toString()); - info += UIUtil.tag("tr", "", col); - info = UIUtil.tag("table", "", info); + String col = UIUtil.tag("TD", "", path); + info = UIUtil.tag("TR", "", col); + col = UIUtil.tag("TD", "", board.getWidth() + "x" + board.getHeight()); + info += UIUtil.tag("TR", "", col); + col = UIUtil.tag("TD", "", board.getTags().toString()); + info += UIUtil.tag("TR", "", col); + info = UIUtil.tag("TABLE", "", info); String attr = String.format("WIDTH=%s", UIUtil.scaleForGUI(500)); - info = UIUtil.tag("div", attr, info); - info = UIUtil.tag("body", "", info); - info = UIUtil.tag("html", "", info); + info = UIUtil.tag("DIV", attr, info); + info = UIUtil.tag("BODY", "", info); + info = UIUtil.tag("HTML", "", info); return info; } diff --git a/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java b/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java index 1865ae4442c..dbc9e0b12f8 100644 --- a/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java +++ b/megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java @@ -214,7 +214,7 @@ public class ChatLounge extends AbstractPhaseDisplay implements private JLabel lblBoardSize = new JLabel(Messages.getString("ChatLounge.labBoardSize")); private JButton butHelp = new JButton(" " + Messages.getString("ChatLounge.butHelp") + " "); - private JButton butAdvancedSearchMap = new JButton("Advanced Search"); + private JButton butAdvancedSearchMap = new JButton(Messages.getString("AdvancedSearchMapDialog.title")); private JButton butConditions = new JButton(Messages.getString("ChatLounge.butConditions")); private JButton butRandomMap = new JButton(Messages.getString("BoardSelectionDialog.GeneratedMapSettings")); From 49d0538a847ccdcae8f305538ca020df57014205 Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Mon, 11 Nov 2024 20:00:29 -0500 Subject: [PATCH 15/16] code cleanup --- .../ui/advancedSearchMap/BoardTableModel.java | 61 ++++++++----------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java index f163e02e456..49e1cf7f86d 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java @@ -46,7 +46,6 @@ class BoardTableModel extends AbstractTableModel { private List width; private List height; - public BoardTableModel() { data = new ArrayList<>(); } @@ -56,43 +55,11 @@ public int getRowCount() { return data.size(); } - public void clearData() { - data = new ArrayList<>(); - tags = new ArrayList<>(); - width = new ArrayList<>(); - height = new ArrayList<>(); - fireTableDataChanged(); - } - @Override public int getColumnCount() { return N_COL; } - public int getPreferredWidth(int col) { - return switch (col) { - case COL_NAME -> 200; - case COL_SIZE -> 20; - default -> 10; - }; - } - - public void setData(BoardClassifier bc) { - data = bc.getBoardPaths().values().stream().toList();; - tags = new ArrayList<>(); - width = new ArrayList<>(); - height = new ArrayList<>(); - - for (String path : data) { - String key = Configuration.boardsDir() + path; - tags.add(bc.getBoardTags().get(key)); - width.add(bc.getBoardWidth().get(key)); - height.add(bc.getBoardHeigth().get(key)); - } - - fireTableDataChanged(); - } - @Override public String getColumnName(int column) { switch (column) { @@ -137,6 +104,30 @@ public Object getValueAt(int row, int col) { return value; } + public int getPreferredWidth(int col) { + return switch (col) { + case COL_NAME -> 200; + case COL_SIZE -> 20; + default -> 10; + }; + } + + public void setData(BoardClassifier bc) { + data = bc.getBoardPaths().values().stream().toList();; + tags = new ArrayList<>(); + width = new ArrayList<>(); + height = new ArrayList<>(); + + for (String path : data) { + String key = Configuration.boardsDir() + path; + tags.add(bc.getBoardTags().get(key)); + width.add(bc.getBoardWidth().get(key)); + height.add(bc.getBoardHeigth().get(key)); + } + + fireTableDataChanged(); + } + public String getPathAt(int row) { if (data.size() <= row) { return null; @@ -161,10 +152,6 @@ public Integer getHeightAt(int row) { return height.get(row); } - public List getAllPaths() { - return data; - } - public ImageIcon getIconAt(int row, int height) { String path = getPathAt(row); Board board = new Board(16, 17); From 9cdff42548eb165d26c2e84a30ef91c8e9591d8d Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Fri, 15 Nov 2024 18:51:20 -0500 Subject: [PATCH 16/16] code cleanup --- .../ui/advancedSearchMap/BoardTableModel.java | 69 +++++++++++-------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java index 49e1cf7f86d..fb74f8ef95b 100644 --- a/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java +++ b/megamek/src/megamek/client/ui/advancedSearchMap/BoardTableModel.java @@ -152,45 +152,58 @@ public Integer getHeightAt(int row) { return height.get(row); } + public List getTagAt(int row) { + if (tags.size() <= row) { + return null; + } + + String tag = tags.get(row); + tag = tag.substring(1, tag.length() -1); + return Arrays.stream(tag.split(", ")).toList(); + } + public ImageIcon getIconAt(int row, int height) { + ImageIcon icon = null; String path = getPathAt(row); - Board board = new Board(16, 17); - board.load(new MegaMekFile(Configuration.boardsDir(), path).getFile()); - BufferedImage image = Minimap.getMinimapImageMaxZoom(board); + if (path != null) { + Board board = new Board(16, 17); + board.load(new MegaMekFile(Configuration.boardsDir(), path).getFile()); + + BufferedImage image = Minimap.getMinimapImageMaxZoom(board); - int scaledHeight = Math.min(image.getHeight(), height); - int scaledWidth = Math.max(1, image.getWidth() * scaledHeight / image.getHeight()); + int scaledHeight = Math.min(image.getHeight(), height); + int scaledWidth = Math.max(1, image.getWidth() * scaledHeight / image.getHeight()); + + image = ImageUtil.getScaledImage(image, scaledWidth, scaledHeight); + icon = new ImageIcon(image); + } - image = ImageUtil.getScaledImage(image, scaledWidth, scaledHeight); - ImageIcon icon = new ImageIcon(image); return icon; } public String getInfoAt(int row) { + String info = ""; String path = getPathAt(row); - Board board = new Board(16, 17); - board.load(new MegaMekFile(Configuration.boardsDir(), path).getFile()); - - String info; - String col = UIUtil.tag("TD", "", path); - info = UIUtil.tag("TR", "", col); - col = UIUtil.tag("TD", "", board.getWidth() + "x" + board.getHeight()); - info += UIUtil.tag("TR", "", col); - col = UIUtil.tag("TD", "", board.getTags().toString()); - info += UIUtil.tag("TR", "", col); - info = UIUtil.tag("TABLE", "", info); - String attr = String.format("WIDTH=%s", UIUtil.scaleForGUI(500)); - info = UIUtil.tag("DIV", attr, info); - info = UIUtil.tag("BODY", "", info); - info = UIUtil.tag("HTML", "", info); - return info; - } + if (path != null) { + Board board = new Board(16, 17); + board.load(new MegaMekFile(Configuration.boardsDir(), path).getFile()); + + + String col = UIUtil.tag("TD", "", path); + info = UIUtil.tag("TR", "", col); + col = UIUtil.tag("TD", "", board.getWidth() + "x" + board.getHeight()); + info += UIUtil.tag("TR", "", col); + col = UIUtil.tag("TD", "", board.getTags().toString()); + info += UIUtil.tag("TR", "", col); + info = UIUtil.tag("TABLE", "", info); + String attr = String.format("WIDTH=%s", UIUtil.scaleForGUI(500)); + info = UIUtil.tag("DIV", attr, info); + info = UIUtil.tag("BODY", "", info); + info = UIUtil.tag("HTML", "", info); + } - public List getTagAt(int row) { - String tag = tags.get(row); - tag = tag.substring(1, tag.length() -1); - return Arrays.stream(tag.split(", ")).toList(); + return info; } }