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

Add actionlistener for combobox in DialogOptionComponent #5369

Merged
merged 1 commit into from
Apr 20, 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
5 changes: 5 additions & 0 deletions megamek/src/megamek/client/ui/swing/CustomMechDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ private void addPartRep(IOption option, boolean editable) {
@Override
public void optionClicked(DialogOptionComponent comp, IOption option, boolean state) { }

@Override
public void optionSwitched(DialogOptionComponent clickedComp, IOption option, int i) {
// nothing implemented yet
}

public boolean isOkay() {
return okay;
}
Expand Down
13 changes: 12 additions & 1 deletion megamek/src/megamek/client/ui/swing/DialogOptionComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import megamek.common.options.*;

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

private static final long serialVersionUID = -4190538980884459746L;

Expand Down Expand Up @@ -85,13 +85,15 @@
label.setLabelFor(choice);
label.setToolTipText(convertToHtml(option.getDescription()));
choice.setEnabled(editable);
choice.addActionListener(this);
if (choiceLabelFirst) {
add(choice);
add(label);
} else {
add(label);
add(choice);
}

break;
default:
textField = new JTextField(option.stringValue(), option.getTextFieldLength());
Expand Down Expand Up @@ -217,7 +219,10 @@
}

public void addValue(String value) {
//turn off listener when adding the item
choice.removeActionListener(this);
choice.addItem(value);
choice.addActionListener(this);
}

public boolean isDefaultValue() {
Expand Down Expand Up @@ -256,6 +261,11 @@
dialogOptionListener.optionClicked(this, option, checkbox.isSelected());
}

@Override
public void actionPerformed(ActionEvent actionEvent) {
dialogOptionListener.optionSwitched(this, option, choice.getSelectedIndex());
}

@Override
public int compareTo(DialogOptionComponent doc) {
return option.getDisplayableName().compareTo(doc.option.getDisplayableName());
Expand All @@ -265,4 +275,5 @@
public String toString() {
return option.getDisplayableName();
}

}
2 changes: 2 additions & 0 deletions megamek/src/megamek/client/ui/swing/DialogOptionListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@
public interface DialogOptionListener {

void optionClicked(DialogOptionComponent comp, IOption option, boolean state);

void optionSwitched(DialogOptionComponent comp, IOption option, int i);
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
}
5 changes: 5 additions & 0 deletions megamek/src/megamek/client/ui/swing/GameOptionsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,11 @@ public void optionClicked(DialogOptionComponent clickedComp, IOption option, boo
}
}

@Override
public void optionSwitched(DialogOptionComponent clickedComp, IOption option, int i) {
// tracks changes to a combobox option - nothing implemented yet
}

@Override
protected void okAction() {
if (clientGui != null) {
Expand Down
Loading