Skip to content

Commit

Permalink
remove size from name in list
Browse files Browse the repository at this point in the history
  • Loading branch information
kuronekochomusuke committed Nov 10, 2024
1 parent 1c5395e commit e672706
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,61 +36,51 @@
* This is the dialog for advanced map filtering
*/
public class AdvancedSearchMapDialog extends AbstractButtonDialog {

BoardClassifier bc;
JTable boardTable;
JList<String> listBoardTags;
JList<String> listBoardPaths;
JLabel boardImage;
JLabel boardInfo;
TableRowSorter<BoardTableModel> boardSorter;

private BoardClassifier bc;
private JTable boardTable;
private JList<String> listBoardTags;
private JList<String> listBoardPaths;
private JLabel boardImage;
private JLabel boardInfo;
private TableRowSorter<BoardTableModel> 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() {
Expand Down Expand Up @@ -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
Expand All @@ -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<BoardTableModel, Integer> boardFilter;
try {
boardFilter = new RowFilter<>() {
Expand All @@ -211,17 +200,23 @@ public boolean include(Entry<? extends BoardTableModel, ? extends Integer> 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<String> include = listBoardPaths.getSelectedValuesList();

String value = path.substring(0, path.lastIndexOf("\\") + 1 );

return !include.isEmpty() && include.stream().anyMatch(value::contains);
}

boolean matchTag(List<String> tags) {
private boolean matchTag(List<String> tags) {
List<String> include = listBoardTags.getSelectedValuesList();

return !include.isEmpty() && include.stream().anyMatch(tags::contains);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "?";
Expand All @@ -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);
}
Expand Down

0 comments on commit e672706

Please sign in to comment.