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

Show the earliest possible construction year in the summary #1380

Merged
merged 1 commit into from
Jan 16, 2024
Merged
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
28 changes: 25 additions & 3 deletions megameklab/src/megameklab/ui/generalUnit/summary/SummaryView.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/
package megameklab.ui.generalUnit.summary;

import megamek.client.ui.swing.unitSelector.ASAdvancedSearchPanel;
import megamek.client.ui.swing.util.UIUtil;
import megamek.client.ui.swing.widget.SimpleLine;
import megamek.common.Entity;
import megameklab.ui.EntitySource;
import megameklab.ui.util.IView;
Expand All @@ -40,6 +43,8 @@ public class SummaryView extends IView {
private static final Dimension categorySize = new Dimension(110, 25);

private final List<SummaryItem> summaryItemList = new ArrayList<>();
private final JLabel earliestYear = new JLabel("");


/**
* Constructs a new summary table having the given summary items in the order they are listed.
Expand All @@ -56,7 +61,7 @@ public SummaryView(EntitySource entitySource, SummaryItem... summaryItems) {
* Constructs a new summary table having the given summary items in the order they are listed.
*
* @param entitySource The EntitySource (cannot be null)
* @param showCrits When false, the crits column is hidden
* @param showCrits When false, the crits column is hidden
* @param summaryItems The SummaryItems to show
*/
public SummaryView(EntitySource entitySource, boolean showCrits, SummaryItem... summaryItems) {
Expand Down Expand Up @@ -123,22 +128,39 @@ private void initialize(boolean showCrits, List<SummaryItem> getSummaryItems) {
this.add(summaryItem.getAvailabilityComponent(), gbc);
gbc.gridy++;
}

gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.gridx = 0;
gbc.gridy++;
add(Box.createVerticalStrut(12), gbc);

gbc.gridy++;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.gridx = 0;
add(earliestYear, gbc);

gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.gridx = 0;
gbc.gridy++;
add(Box.createVerticalStrut(12), gbc);
}

private JLabel createLabel(String text, Dimension size,int align){
private JLabel createLabel(String text, Dimension size, int align) {
JLabel label = new JLabel(text, SwingConstants.TRAILING);
setFieldSize(label, size);
label.setHorizontalAlignment(align);
return label;
}

private void setFieldSize(JComponent box, Dimension maxSize){
private void setFieldSize(JComponent box, Dimension maxSize) {
box.setPreferredSize(maxSize);
box.setMaximumSize(maxSize);
box.setMinimumSize(maxSize);
}

private void refresh(Entity entity) {
summaryItemList.forEach(summaryItem -> summaryItem.refresh(entity));
entity.recalculateTechAdvancement();
earliestYear.setText("Earliest Possible Year: " + entity.getEarliestTechDate());
}
}
Loading