Skip to content

Commit

Permalink
Merge pull request #6121 from SJuliez/game-opts-search-textfield-update
Browse files Browse the repository at this point in the history
#5972: Game Options
  • Loading branch information
HammerGS authored Oct 21, 2024
2 parents 7f39a5e + 13d461e commit 5d4e9d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
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,
FocusListener, ActionListener, Comparable<DialogOptionComponent> {

private static final long serialVersionUID = -4190538980884459746L;

Expand All @@ -39,7 +40,7 @@ public class DialogOptionComponent extends FixedYPanel implements ItemListener,
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 @@ public void mouseClicked(MouseEvent evt) {
}
}
});
textField.addFocusListener(this);
textField.setEnabled(editable);
if (!option.isLabelBeforeTextField()) {
add(Box.createHorizontalStrut(2));
Expand All @@ -131,11 +133,11 @@ public static String convertToHtml(String source) {
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 @@ public void setValue(Object v) {
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 @@ public boolean isDefaultValue() {
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 @@ public String toString() {
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

0 comments on commit 5d4e9d6

Please sign in to comment.