Skip to content

Commit

Permalink
Merge pull request #5369 from AaronGullickson/dialogoption-add-listener
Browse files Browse the repository at this point in the history
Add actionlistener for combobox in DialogOptionComponent
  • Loading branch information
SJuliez authored Apr 20, 2024
2 parents 98284ce + e9c5169 commit 94111f0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
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 @@ -396,6 +396,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> {

private static final long serialVersionUID = -4190538980884459746L;

Expand Down Expand Up @@ -85,13 +85,15 @@ public void mouseClicked(MouseEvent evt) {
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 setSelected(String value) {
}

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 @@ public void itemStateChanged(ItemEvent itemEvent) {
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 int compareTo(DialogOptionComponent doc) {
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);
}
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

0 comments on commit 94111f0

Please sign in to comment.