本文整理汇总了Java中net.sf.freecol.client.gui.label.UnitLabel.UnitAction类的典型用法代码示例。如果您正苦于以下问题:Java UnitAction类的具体用法?Java UnitAction怎么用?Java UnitAction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UnitAction类属于net.sf.freecol.client.gui.label.UnitLabel包,在下文中一共展示了UnitAction类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createUnitMenu
import net.sf.freecol.client.gui.label.UnitLabel.UnitAction; //导入依赖的package包/类
/**
* Creates a popup menu for a Unit.
*
* @param unitLabel The {@code UnitLabel} to create items for.
*/
private void createUnitMenu(final UnitLabel unitLabel) {
final Unit unit = unitLabel.getUnit();
this.setLabel("Unit");
ImageIcon unitIcon = new ImageIcon(gui.getImageLibrary()
.getSmallUnitImage(unit));
JMenuItem name = new JMenuItem(unit.getDescription(Unit.UnitLabelType.NATIONAL)
+ " (" + Messages.message("colopedia") + ")", unitIcon);
name.setActionCommand(UnitAction.COLOPEDIA.toString());
name.addActionListener(unitLabel);
this.add(name);
this.addSeparator();
if (addCarrierItems(unitLabel)) this.addSeparator();
if (unit.isInEurope()) {
if (addCommandItems(unitLabel)) this.addSeparator();
if (addBoardItems(unitLabel, unit.getOwner().getEurope())) {
this.addSeparator();
}
} else if (unit.hasTile()) {
Colony colony = unit.getLocation().getTile().getColony();
if (colony != null) {
if (addTileItem(unitLabel)) this.addSeparator();
if (addWorkItems(unitLabel)) this.addSeparator();
if (unit.isInColony()
&& addEducationItems(unitLabel)) this.addSeparator();
if (unit.isInColony() && colony.canReducePopulation()) {
JMenuItem menuItem = Utility.localizedMenuItem("quickActionMenu.leaveTown");
menuItem.setActionCommand(UnitAction.LEAVE_TOWN.toString());
menuItem.addActionListener(unitLabel);
this.add(menuItem);
addBoardItems(unitLabel, colony.getTile());
this.addSeparator();
} else {
if (addCommandItems(unitLabel)) this.addSeparator();
if (addBoardItems(unitLabel, colony.getTile())) {
this.addSeparator();
}
}
} else {
if (addCommandItems(unitLabel)) this.addSeparator();
}
}
if (unit.hasAbility(Ability.CAN_BE_EQUIPPED)) {
if (addRoleItems(unitLabel)) this.addSeparator();
}
}
示例2: addRoleItems
import net.sf.freecol.client.gui.label.UnitLabel.UnitAction; //导入依赖的package包/类
/**
* Add menu items for role manipulation for a unit.
*
* Note "clear speciality" is here too to keep it well separated from
* other items.
*
* @param unitLabel The {@code UnitLabel} specifying the unit.
* @return True if menu items were added and a separator is now needed.
*/
private boolean addRoleItems(final UnitLabel unitLabel) {
final Specification spec = freeColClient.getGame().getSpecification();
final Unit unit = unitLabel.getUnit();
final Role role = unit.getRole();
final int roleCount = unit.getRoleCount();
boolean separatorNeeded = false;
UnitLocation uloc = (unit.isInEurope()) ? unit.getOwner().getEurope()
: unit.getSettlement();
if (uloc == null) return false;
for (Role r : transform(unit.getAvailableRoles(null),
r2 -> r2 != role)) {
JMenuItem newItem;
if (r.isDefaultRole()) { // Always valid
newItem = createRoleItem(unitLabel, role, roleCount, r, 0, 0);
} else {
newItem = null;
for (int count = r.getMaximumCount(); count > 0; count--) {
List<AbstractGoods> req = unit.getGoodsDifference(r, count);
try {
int price = uloc.priceGoods(req);
if (unit.getOwner().checkGold(price)) {
newItem = createRoleItem(unitLabel, role, roleCount,
r, count, price);
break;
}
} catch (FreeColException fce) {
continue;
}
}
}
if (newItem != null) {
this.add(newItem);
separatorNeeded = true;
}
}
UnitTypeChange uc = unit.getUnitChange(UnitChangeType.CLEAR_SKILL);
if (uc != null) {
if (separatorNeeded) this.addSeparator();
JMenuItem menuItem = Utility.localizedMenuItem("quickActionMenu.clearSpeciality",
new ImageIcon(gui.getImageLibrary().getTinyUnitImage(uc.to)));
menuItem.setActionCommand(UnitAction.CLEAR_SPECIALITY.toString());
menuItem.addActionListener(unitLabel);
this.add(menuItem);
if (unit.getLocation() instanceof Building
&& !((Building)unit.getLocation()).canAddType(uc.to)) {
menuItem.setEnabled(false);
}
separatorNeeded = true;
}
return separatorNeeded;
}
示例3: createUnitMenu
import net.sf.freecol.client.gui.label.UnitLabel.UnitAction; //导入依赖的package包/类
/**
* Creates a popup menu for a Unit.
*
* @param unitLabel The {@code UnitLabel} to create items for.
*/
private void createUnitMenu(final UnitLabel unitLabel) {
final Unit unit = unitLabel.getUnit();
this.setLabel("Unit");
ImageIcon unitIcon = new ImageIcon(gui.getImageLibrary()
.getSmallUnitImage(unit));
JMenuItem name = new JMenuItem(unit.getDescription(Unit.UnitLabelType.NATIONAL)
+ " (" + Messages.message("colopedia") + ")", unitIcon);
name.setActionCommand(UnitAction.COLOPEDIA.toString());
name.addActionListener(unitLabel);
this.add(name);
this.addSeparator();
if (addCarrierItems(unitLabel)) this.addSeparator();
if (unit.isInEurope()) {
if (addCommandItems(unitLabel)) this.addSeparator();
if (addBoardItems(unitLabel, unit.getOwner().getEurope())) {
this.addSeparator();
}
} else if (unit.hasTile()) {
Colony colony = unit.getLocation().getTile().getColony();
if (colony != null) {
if (addTileItem(unitLabel)) this.addSeparator();
if (addWorkItems(unitLabel)) this.addSeparator();
if (addEducationItems(unitLabel)) this.addSeparator();
if (unit.isInColony() && colony.canReducePopulation()) {
JMenuItem menuItem = Utility.localizedMenuItem("quickActionMenu.leaveTown");
menuItem.setActionCommand(UnitAction.LEAVE_TOWN.toString());
menuItem.addActionListener(unitLabel);
this.add(menuItem);
addBoardItems(unitLabel, colony.getTile());
this.addSeparator();
} else {
if (addCommandItems(unitLabel)) this.addSeparator();
if (addBoardItems(unitLabel, colony.getTile())) {
this.addSeparator();
}
}
} else {
if (addCommandItems(unitLabel)) this.addSeparator();
}
}
if (unit.hasAbility(Ability.CAN_BE_EQUIPPED)) {
if (addRoleItems(unitLabel)) this.addSeparator();
}
}