Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced Search updates #6131

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2174,15 +2174,15 @@ MekSelectorDialog.Search.Armor25=25% of maximum
MekSelectorDialog.Search.Armor50=50% of maximum
MekSelectorDialog.Search.Armor75=75% of maximum
MekSelectorDialog.Search.Armor90=90% of maximum
MekSelectorDialog.Search.WeaponClass=Has Weapon Type:
MekSelectorDialog.Search.Weapons=Has weapons:
MekSelectorDialog.Search.WeaponsAtLeast=At least
MekSelectorDialog.Search.Equipment=Has equipment:
MekSelectorDialog.Search.WeaponClass=Weapon Type
MekSelectorDialog.Search.Weapons=Weapons
MekSelectorDialog.Search.Equipment=Equipment
MekSelectorDialog.Search.Year=Design year:
MekSelectorDialog.Search.TableFilters=Table filters:
MekSelectorDialog.Search.UnitType=Unit Type:
MekSelectorDialog.Search.TechClass=Tech Class:
MekSelectorDialog.Search.TechLevel=Tech Level:
MekSelectorDialog.Search.TableFilter=Filter Text:
MekSelectorDialog.Search.Quirk=Quirk:
MekSelectorDialog.Search.Quirks=Quirks
MekSelectorDialog.Search.WeaponQuirk=Weapon Quirk:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
*/
package megamek.client.ui.swing.unitSelector;
package megamek.client.ui.advancedsearch;

import java.awt.BasicStroke;
import java.awt.Dimension;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 - The MegaMek Team. All Rights Reserved.
* Copyright (c) 2022-2024 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMek.
*
Expand All @@ -16,15 +16,17 @@
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
*/
package megamek.client.ui.swing.dialog;
package megamek.client.ui.advancedsearch;

import megamek.client.ui.Messages;
import megamek.client.ui.baseComponents.AbstractButtonDialog;
import megamek.client.ui.swing.unitSelector.ASAdvancedSearchPanel;
import megamek.client.ui.swing.unitSelector.TWAdvancedSearchPanel;
import megamek.client.ui.swing.util.UIUtil;
import megamek.client.ui.swing.ButtonEsc;
import megamek.client.ui.swing.CloseAction;
import megamek.client.ui.swing.dialog.DialogButton;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.MatteBorder;
import java.awt.*;

/**
Expand Down Expand Up @@ -68,16 +70,23 @@ protected void cancelAction() {

@Override
protected JPanel createButtonPanel() {
JPanel buttonPanel = super.createButtonPanel();
buttonPanel.setLayout(new FlowLayout());
buttonPanel.setBorder(new EmptyBorder(5, 0, 5, 0));
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.setBorder(BorderFactory.createCompoundBorder(
new MatteBorder(1, 0, 0, 0, UIManager.getColor("Separator.foreground")),
new EmptyBorder(10, 0, 10, 0)));
buttonPanel.add(okButton);
buttonPanel.add(cancelButton);
return buttonPanel;
}

@Override
protected Container createCenterPane() {
JScrollPane advScrollpane = new JScrollPane(advancedSearchPane);
return advScrollpane;
return advancedSearchPane;
}

/** Deactivates the search fields in both search tabs so that no units are filtered out. */
Expand Down
28 changes: 28 additions & 0 deletions megamek/src/megamek/client/ui/advancedsearch/AndFilterToken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package megamek.client.ui.advancedsearch;

import megamek.common.MekSearchFilter;

public class AndFilterToken extends OperatorFT {

public AndFilterToken() {
super(MekSearchFilter.BoolOp.AND);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

package megamek.client.ui.advancedsearch;

public class EquipmentFilterToken implements FilterToken {


}
129 changes: 129 additions & 0 deletions megamek/src/megamek/client/ui/advancedsearch/EquipmentTableModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package megamek.client.ui.advancedsearch;

import megamek.common.EquipmentType;
import megamek.common.TechConstants;

import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* A table model for the advanced search weapon tab's equipment list
*/
public class EquipmentTableModel extends AbstractTableModel {

static final int COL_QTY = 0;
static final int COL_NAME = 1;
static final int COL_COST = 2;
static final int COL_IS_CLAN = 3;
static final int COL_LEVEL = 4;
static final int N_COL = 5;
static final int COL_INTERNAL_NAME = 5;

private final TWAdvancedSearchPanel twAdvancedSearchPanel;
private int[] qty;
private List<EquipmentType> equipment = new ArrayList<>();

public EquipmentTableModel(TWAdvancedSearchPanel twAdvancedSearchPanel) {
this.twAdvancedSearchPanel = twAdvancedSearchPanel;
}

@Override
public int getRowCount() {
return equipment.size();
}

@Override
public int getColumnCount() {
return N_COL;
}

public int getPreferredWidth(int col) {
return switch (col) {
case COL_QTY -> 40;
case COL_NAME -> 400;
case COL_IS_CLAN -> 75;
case COL_COST -> 175;
case COL_LEVEL -> 100;
default -> 0;
};
}

@Override
public String getColumnName(int column) {
return switch (column) {
case COL_QTY -> "Qty";
case COL_NAME -> "Name";
case COL_IS_CLAN -> "IS/Clan";
case COL_COST -> "Cost";
case COL_LEVEL -> "Lvl";
default -> "?";
};
}

@Override
public Class<?> getColumnClass(int c) {
return getValueAt(0, c).getClass();
}

@Override
public boolean isCellEditable(int row, int col) {
return col == COL_QTY;
}

public void setData(List<EquipmentType> eq) {
equipment = eq;
qty = new int[eq.size()];
Arrays.fill(qty, 1);
fireTableDataChanged();
}

public EquipmentType getEquipmentTypeAt(int row) {
return equipment.get(row);
}

@Override
public Object getValueAt(int row, int col) {
if (row >= equipment.size()) {
return null;
}
EquipmentType eq = equipment.get(row);
return switch (col) {
case COL_QTY -> qty[row] + "";
case COL_NAME -> eq.getName();
case COL_IS_CLAN -> TechConstants.getTechName(eq.getTechLevel(twAdvancedSearchPanel.gameYear));
case COL_COST -> eq.getRawCost();
case COL_LEVEL -> TechConstants.getSimpleLevelName(
TechConstants.convertFromNormalToSimple(eq.getTechLevel(twAdvancedSearchPanel.gameYear)));
case COL_INTERNAL_NAME -> eq.getInternalName();
default -> "?";
};
}

@Override
public void setValueAt(Object value, int row, int col) {
if (col == COL_QTY) {
qty[row] = Integer.parseInt((String) value);

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException Note

Potential uncaught 'java.lang.NumberFormatException'.
fireTableCellUpdated(row, col);
}
}
}
24 changes: 24 additions & 0 deletions megamek/src/megamek/client/ui/advancedsearch/EquipmentTypeFT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package megamek.client.ui.advancedsearch;

/**
* FilterTokens subclass that represents equipment.
*
* @author Arlith
*/
public class EquipmentTypeFT extends EquipmentFilterToken {

public String internalName;
public String fullName;
public int qty;

public EquipmentTypeFT(String in, String fn, int q) {
internalName = in;
fullName = fn;
qty = q;
}

@Override
public String toString() {
return qty + " " + fullName + ((qty != 1) ? "s" : "");
}
}
28 changes: 28 additions & 0 deletions megamek/src/megamek/client/ui/advancedsearch/FilterToken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package megamek.client.ui.advancedsearch;

/**
* Marker interface for different tokens that can be in a filter expression.
*
* @author Arlith
*/
public interface FilterToken {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package megamek.client.ui.advancedsearch;

public class LeftParensFilterToken extends ParensFT {

public LeftParensFilterToken() {
super("(");
}
}
Loading