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

#5972: Game Options #6121

Merged
merged 1 commit into from
Oct 21, 2024
Merged
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
23 changes: 17 additions & 6 deletions megamek/src/megamek/client/ui/swing/DialogOptionComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
import megamek.common.options.*;

/** @author Cord Awtry */
public class DialogOptionComponent extends FixedYPanel implements ItemListener, ActionListener, Comparable<DialogOptionComponent> {
public class DialogOptionComponent extends FixedYPanel implements ItemListener,

Check warning

Code scanning / CodeQL

Inconsistent compareTo Warning

This class declares
compareTo
but inherits equals; the two could be inconsistent.
FocusListener, ActionListener, Comparable<DialogOptionComponent> {

private static final long serialVersionUID = -4190538980884459746L;

Expand All @@ -39,7 +40,7 @@
private JComboBox<String> choice;
private JTextField textField;
private final DialogOptionListener dialogOptionListener;

/** Value used to force a change */
private boolean hasOptionChanged = false;

Expand Down Expand Up @@ -110,6 +111,7 @@
}
}
});
textField.addFocusListener(this);
textField.setEnabled(editable);
if (!option.isLabelBeforeTextField()) {
add(Box.createHorizontalStrut(2));
Expand All @@ -131,11 +133,11 @@
result.append("</DIV></html>");
return result.toString();
}

public boolean hasChanged() {
return !option.getValue().equals(getValue()) || hasOptionChanged;
}

public void setOptionChanged(boolean v) {
hasOptionChanged = v;
}
Expand Down Expand Up @@ -164,6 +166,8 @@
break;
case IOption.INTEGER:
case IOption.FLOAT:
textField.setText(v + "");
break;
case IOption.STRING:
textField.setText((String) v);
break;
Expand Down Expand Up @@ -234,9 +238,9 @@
return choice.getSelectedIndex() == 0;
default:
return textField.getText().equals(String.valueOf(option.getDefault()));
}
}
}

public void resetToDefault() {
switch (option.getType()) {
case IOption.BOOLEAN:
Expand Down Expand Up @@ -276,4 +280,11 @@
return option.getDisplayableName();
}

@Override
public void focusGained(FocusEvent e) { }

@Override
public void focusLost(FocusEvent e) {
dialogOptionListener.optionClicked(this, option, true);
}
}
1 change: 1 addition & 0 deletions megamek/src/megamek/client/ui/swing/GameOptionsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ public void removeUpdate(DocumentEvent e) {
panSearch.add(panSearchBar);
panSearch.add(panSearchOptions);
panOptions.addTab(Messages.getString("GameOptionsDialog.Search"), scrOptions);
refreshSearchPanel();
}

private void addOption(JPanel groupPanel, IOption option) {
Expand Down