/**
* {@inheritDoc}
*/
@Override
public void itemStateChanged(ItemEvent e) {
// When the unit type changes, we have to reset the role choices
JComboBox<String> box = this.roleUI.getComponent();
DefaultComboBoxModel<String> model;
boolean enable = false;
UnitType type = (UnitType)this.typeUI.getComponent().getSelectedItem();
if (type != null && type.hasAbility(Ability.CAN_BE_EQUIPPED)) {
final Specification spec = type.getSpecification();
final NationType nt = getOption().getNationType();
int n = 0;
model = new DefaultComboBoxModel<>();
for (String ri : getOption().getRole().getChoices()) {
Role role = spec.getRole(ri);
if (role.isAvailableTo(type, nt)) {
model.addElement(ri);
n++;
}
}
enable = isEditable() && n > 1;
} else {
model = new DefaultComboBoxModel<>(new String[] {
Specification.DEFAULT_ROLE_ID });
}
box.setModel(model);
box.setEnabled(enable);
}
AbstractUnitOptionUI.java 文件源码
java
阅读 40
收藏 0
点赞 0
评论 0
项目:FreeCol
作者:
评论列表
文章目录