Skip to content

Commit

Permalink
GUI tweaks in the equipment search tab, naval gauss flag fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Oct 22, 2024
1 parent 3b8e964 commit da365f1
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 120 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;

public class EquipmentCostRenderer extends DefaultTableCellRenderer {

public EquipmentCostRenderer() {
super();
setHorizontalAlignment(SwingConstants.RIGHT);
}

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value instanceof Double number) {
if (number < 0) {
value = "variable";
} else {
value = "%,d".formatted(Math.round(number));
}
}
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;

public class EquipmentDataRenderer extends DefaultTableCellRenderer {

public EquipmentDataRenderer() {
super();
setHorizontalAlignment(SwingConstants.CENTER);
}

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

if (value instanceof Integer number && number < 0) {
value = "var.";
}
if (value instanceof Double number && number < 0) {
value = "var.";
}
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
* 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 {

/**
* This is a superclass for filter tokens that are actual equipment, not operators or parentheses
*/
public abstract class EquipmentFilterToken implements FilterToken {

}
19 changes: 19 additions & 0 deletions megamek/src/megamek/client/ui/advancedsearch/NoSelectionModel.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@

/*
* 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 javax.swing.*;
Expand Down
13 changes: 6 additions & 7 deletions megamek/src/megamek/client/ui/advancedsearch/OperatorFT.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @author Arlith
*/
public abstract class OperatorFT implements FilterToken {

public MekSearchFilter.BoolOp op;

protected OperatorFT(MekSearchFilter.BoolOp o) {
Expand All @@ -16,12 +17,10 @@ protected OperatorFT(MekSearchFilter.BoolOp o) {

@Override
public String toString() {
if (op == MekSearchFilter.BoolOp.AND) {
return "And";
} else if (op == MekSearchFilter.BoolOp.OR) {
return "Or";
} else {
return "";
}
return switch (op) {
case AND -> "and";
case OR -> "or";
default -> "";
};
}
}
39 changes: 39 additions & 0 deletions megamek/src/megamek/client/ui/advancedsearch/TechBaseRenderer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;

public class TechBaseRenderer extends DefaultTableCellRenderer {

public TechBaseRenderer() {
super();
setHorizontalAlignment(SwingConstants.CENTER);
}

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value.equals("Inner Sphere")) {
value = "IS";
}
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
}
20 changes: 20 additions & 0 deletions megamek/src/megamek/client/ui/advancedsearch/WeaponClassFT.java
Original file line number Diff line number Diff line change
@@ -1,6 +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 WeaponClassFT extends EquipmentFilterToken {

public WeaponClass weaponClass;
public int qty;

Expand Down
14 changes: 14 additions & 0 deletions megamek/src/megamek/client/ui/advancedsearch/WeaponSearchTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableRowSorter;
import java.awt.*;
Expand Down Expand Up @@ -159,6 +160,14 @@ public Dimension getPreferredScrollableViewportSize() {
tblWeapons.addKeyListener(this);
tblWeapons.addFocusListener(this);

var tableDataRenderer = new EquipmentDataRenderer();
for (int column : List.of(0, 2, 3, 4, 5, 6)) {
tblWeapons.getColumnModel().getColumn(column).setCellRenderer(tableDataRenderer);
}

var techBaseRenderer = new TechBaseRenderer();
tblWeapons.getColumnModel().getColumn(7).setCellRenderer(techBaseRenderer);

for (int i = 0; i < weaponsModel.getColumnCount(); i++) {
tblWeapons.getColumnModel().getColumn(i).setPreferredWidth(weaponsModel.getPreferredWidth(i));
}
Expand Down Expand Up @@ -186,6 +195,11 @@ public Dimension getPreferredScrollableViewportSize() {
tblEquipment.getColumnModel().getColumn(i).setPreferredWidth(equipmentModel.getPreferredWidth(i));
}

tblEquipment.getColumnModel().getColumn(0).setCellRenderer(tableDataRenderer);
var costRenderer = new EquipmentCostRenderer();
tblEquipment.getColumnModel().getColumn(2).setCellRenderer(costRenderer);
tblEquipment.getColumnModel().getColumn(3).setCellRenderer(techBaseRenderer);

scrTableEquipment.setViewportView(tblEquipment);

// Populate Tables
Expand Down
Loading

0 comments on commit da365f1

Please sign in to comment.