本文整理汇总了Java中net.sf.freecol.client.gui.label.UnitLabel类的典型用法代码示例。如果您正苦于以下问题:Java UnitLabel类的具体用法?Java UnitLabel怎么用?Java UnitLabel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UnitLabel类属于net.sf.freecol.client.gui.label包,在下文中一共展示了UnitLabel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setSelectedUnitLabel
import net.sf.freecol.client.gui.label.UnitLabel; //导入依赖的package包/类
/**
* Selects a unit that is located somewhere on this panel.
*
* @param unitLabel The {@code UnitLabel} for the unit that
* is being selected.
*/
@Override
public void setSelectedUnitLabel(UnitLabel unitLabel) {
if (selectedUnitLabel != unitLabel) {
if (selectedUnitLabel != null) {
selectedUnitLabel.setSelected(false);
}
selectedUnitLabel = unitLabel;
if (unitLabel == null) {
cargoPanel.setCarrier(null);
} else {
cargoPanel.setCarrier(unitLabel.getUnit());
unitLabel.setSelected(true);
}
}
inPortPanel.revalidate();
inPortPanel.repaint();
}
示例2: addMenuItems
import net.sf.freecol.client.gui.label.UnitLabel; //导入依赖的package包/类
/**
* Add specific menu items for a given component.
*
* @param comp The specific {@code JComponent}.
* @return This {@code QuickActionMenu}.
*/
public QuickActionMenu addMenuItems(JComponent comp) {
if (comp instanceof UnitLabel) {
createUnitMenu((UnitLabel)comp);
} else if (comp instanceof GoodsLabel) {
createGoodsMenu((GoodsLabel)comp);
} else if (comp instanceof MarketLabel) {
createMarketMenu((MarketLabel)comp);
} else if (comp instanceof ASingleTilePanel) {
createTileMenu((ASingleTilePanel)comp);
} else if (comp.getParent() instanceof ASingleTilePanel) {
// Also check the parent to show the popup in the
// center of the colony panel tile.
createTileMenu((ASingleTilePanel)comp.getParent());
}
return this;
}
示例3: addBoardItems
import net.sf.freecol.client.gui.label.UnitLabel; //导入依赖的package包/类
private boolean addBoardItems(final UnitLabel unitLabel, Location loc) {
final Unit tempUnit = unitLabel.getUnit();
if (tempUnit.isCarrier()) return false;
final InGameController igc = freeColClient.getInGameController();
boolean added = false;
for (Unit unit : transform(loc.getUnitList(), u ->
(u.isCarrier() && u.canCarryUnits() && u.canAdd(tempUnit)
&& tempUnit.getLocation() != u))) {
StringTemplate template
= StringTemplate.template("quickActionMenu.board")
.addStringTemplate("%unit%",
unit.getLabel(Unit.UnitLabelType.NATIONAL));
JMenuItem menuItem = Utility.localizedMenuItem(template);
menuItem.addActionListener((ActionEvent ae) -> {
igc.boardShip(tempUnit, unit);
});
this.add(menuItem);
added = true;
}
return added;
}
示例4: makeProductionItem
import net.sf.freecol.client.gui.label.UnitLabel; //导入依赖的package包/类
private JMenuItem makeProductionItem(GoodsType type, WorkLocation wl,
int amount, UnitLabel unitLabel,
boolean claim) {
StringTemplate t = StringTemplate.template(type.getId() + ".workAs")
.addAmount("%amount%", amount);
if (claim) {
t.addStringTemplate("%claim%", wl.getClaimTemplate());
} else if (FreeColDebugger.isInDebugMode(FreeColDebugger.DebugMode.MENUS)) {
t.addStringTemplate("%claim%", wl.getLocationLabel());
} else {
t.addName("%claim%", "");
}
JMenuItem menuItem = Utility.localizedMenuItem(t,
new ImageIcon(gui.getImageLibrary().getSmallIconImage(type)));
menuItem.setActionCommand(getWorkLabel(wl)
+ "/" + wl.getId() + "/" + type.getId()
+ "/" + ((claim) ? "!" : ""));
menuItem.addActionListener(unitLabel);
return menuItem;
}
示例5: setSelectedUnitLabel
import net.sf.freecol.client.gui.label.UnitLabel; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void setSelectedUnitLabel(UnitLabel unitLabel) {
if (selectedUnitLabel != unitLabel) {
inPortPanel.removePropertyChangeListeners();
if (selectedUnitLabel != null) {
selectedUnitLabel.setSelected(false);
selectedUnitLabel.getUnit().removePropertyChangeListener(this);
}
super.setSelectedUnitLabel(unitLabel);
if (unitLabel == null) {
cargoPanel.setCarrier(null);
} else {
cargoPanel.setCarrier(unitLabel.getUnit());
unitLabel.setSelected(true);
unitLabel.getUnit().addPropertyChangeListener(this);
}
inPortPanel.addPropertyChangeListeners();
}
updateCarrierButtons();
inPortPanel.revalidate();
inPortPanel.repaint();
}
示例6: add
import net.sf.freecol.client.gui.label.UnitLabel; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Component add(Component comp, boolean editState) {
if (editState) {
if (comp instanceof UnitLabel) {
UnitLabel label = (UnitLabel)comp;
if (!tryWork(label.getUnit())) return null;
label.setSmall(false);
} else {
logger.warning("An invalid component was dropped"
+ " on this ASingleTilePanel.");
return null;
}
}
update();
return comp;
}
示例7: importUnit
import net.sf.freecol.client.gui.label.UnitLabel; //导入依赖的package包/类
/**
* Import a unit specified by its label to a component.
*
* @param comp The component to import to.
* @param label The {@code UnitLabel} specifying the unit.
* @param oldSelectedUnit A label for the old {@code Unit} to restore
* selection to.
* @return True if the import succeeds.
*/
private boolean importUnit(JComponent comp, UnitLabel label,
UnitLabel oldSelectedUnit) {
if (!(comp instanceof DropTarget)) return importFail(comp, "unit");
final DropTarget target = (DropTarget)comp;
// Check if the unit can be dragged to comp.
final Unit unit = label.getUnit();
if (!target.accepts(unit)) {
return importFail(comp, "unacceptable unit (" + unit + ")");
}
// OK, add it.
target.add(label, true);
// Update unit selection.
// New unit selection has already been taken care of
// if this unit was moved to ToAmericaPanel
restoreSelection(oldSelectedUnit);
comp.revalidate();
return true;
}
示例8: update
import net.sf.freecol.client.gui.label.UnitLabel; //导入依赖的package包/类
/**
* Update this DestinationPanel.
*/
public void update() {
removeAll();
HighSeas highSeas = getMyPlayer().getHighSeas();
if (highSeas != null) {
for (Unit unit : highSeas.getUnitList()) {
boolean belongs;
if (destination instanceof Europe) {
belongs = unit.getDestination() == destination;
} else if (destination instanceof Map) {
belongs = unit.getDestination() == destination
|| (unit.getDestination() != null
&& unit.getDestination().getTile() != null
&& unit.getDestination().getTile().getMap()
== destination);
} else {
logger.warning("Bogus DestinationPanel location: "
+ destination
+ " for unit: " + unit);
belongs = false;
}
if (belongs) {
UnitLabel unitLabel
= new UnitLabel(getFreeColClient(), unit);
unitLabel.setTransferHandler(defaultTransferHandler);
unitLabel.addMouseListener(pressListener);
add(unitLabel);
}
}
}
// "ship" is a tag, not a key
Utility.localizeBorder(this, Unit.getDestinationLabel("ship",
destination, getMyPlayer()));
revalidate();
}
示例9: setSelectedUnit
import net.sf.freecol.client.gui.label.UnitLabel; //导入依赖的package包/类
/**
* Select a given unit.
*
* @param unit The {@code Unit} to select.
* @return True if the selection succeeds.
*/
public boolean setSelectedUnit(Unit unit) {
for (Component component : getComponents()) {
if (component instanceof UnitLabel) {
UnitLabel label = (UnitLabel)component;
if (label.getUnit() == unit) {
setSelectedUnitLabel(label);
return true;
}
}
}
return false;
}
示例10: update
import net.sf.freecol.client.gui.label.UnitLabel; //导入依赖的package包/类
/**
* Update this unit panel.
*/
public void update() {
removeAll();
if (portPanel != null) {
for (Unit unit : transform(portPanel.getUnitList(),
u -> accepts(u))) {
UnitLabel unitLabel
= new UnitLabel(portPanel.getFreeColClient(), unit);
TradeRoute tradeRoute = unit.getTradeRoute();
if (tradeRoute != null) {
unitLabel.setDescriptionLabel(unit
.getDescription(Unit.UnitLabelType.NATIONAL)
+ " (" + tradeRoute.getName() + ")");
}
if (editable) {
unitLabel.setTransferHandler(portPanel.getTransferHandler());
unitLabel.addMouseListener(portPanel.getPressListener());
}
add(unitLabel);
}
}
selectLabel();
revalidate();
repaint();
}
示例11: setSelectedUnit
import net.sf.freecol.client.gui.label.UnitLabel; //导入依赖的package包/类
/**
* Select a given unit.
*
* @param unit The {@code Unit} to select.
* @return True if the selection succeeds.
*/
public boolean setSelectedUnit(Unit unit) {
for (Component component : getComponents()) {
if (component instanceof UnitLabel) {
UnitLabel label = (UnitLabel)component;
if (label.getUnit() == unit) {
getPortPanel().setSelectedUnitLabel(label);
return true;
}
}
}
return false;
}
示例12: addTileItem
import net.sf.freecol.client.gui.label.UnitLabel; //导入依赖的package包/类
/**
* Add a menu item for the tile a unit is working.
*
* @param unitLabel The {@code UnitLabel} specifying the unit.
* @return True if an item was added.
*/
private boolean addTileItem(final UnitLabel unitLabel) {
final Unit unit = unitLabel.getUnit();
final Tile tile = (unit == null) ? null : unit.getWorkTile();
if (tile != null) {
addTileItem(tile);
return true;
}
return false;
}
示例13: update
import net.sf.freecol.client.gui.label.UnitLabel; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void update() {
super.update();
if (ColonyPanel.this.isEditable()) {
for (UnitLabel unitLabel : getUnitLabels()) {
unitLabel.setTransferHandler(defaultTransferHandler);
unitLabel.addMouseListener(pressListener);
}
}
}
示例14: updateDescriptionLabel
import net.sf.freecol.client.gui.label.UnitLabel; //导入依赖的package包/类
/**
* Updates the description label, which is a tooltip with
* the terrain type, road and plow indicator, if any.
*
* If a unit is on it update the tooltip of it instead.
*
* @param unitLabel The {@code UnitLabel} to update.
*/
private void updateDescriptionLabel(UnitLabel unitLabel) {
String tileMsg = Messages.message(this.colonyTile.getLabel());
if (unitLabel == null) {
setToolTipText(tileMsg);
} else {
final Unit unit = unitLabel.getUnit();
unitLabel.setDescriptionLabel(tileMsg + " ["
+ unit.getDescription(Unit.UnitLabelType.NATIONAL)
+ "]");
}
}
示例15: equipUnitIfPossible
import net.sf.freecol.client.gui.label.UnitLabel; //导入依赖的package包/类
private boolean equipUnitIfPossible(UnitLabel unitLabel,
AbstractGoods goods) {
final Unit unit = unitLabel.getUnit();
if (!unit.hasAbility(Ability.CAN_BE_EQUIPPED)
|| unit.getRole().hasAbility(Ability.ESTABLISH_MISSION)) {
// Do not equip missionaries. The test below will succeed
// when dragging incompatible goods (anything:-) because
// there is no actual missionary equipment.
return false;
}
for (Role role : transform(unit.getAvailableRoles(null),
r -> !r.isDefaultRole())) {
List<AbstractGoods> required = unit.getGoodsDifference(role, 1);
int count;
if (required.size() == 1
&& required.get(0).getType() == goods.getType()
&& (count = Math.min(role.getMaximumCount(),
goods.getAmount() / required.get(0).getAmount())) > 0
&& (role != unit.getRole() || count != unit.getRoleCount())) {
freeColClient.getInGameController()
.equipUnitForRole(unit, role, count);
unitLabel.updateIcon();
return true;
}
}
return false;
}