use of games.strategy.triplea.util.UnitCategory in project triplea by triplea-game.
the class TerritoryDetailPanel method unitsInTerritoryPanel.
private static JPanel unitsInTerritoryPanel(final Collection<Unit> unitsInTerritory, final UiContext uiContext) {
final JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createEmptyBorder(2, 20, 2, 2));
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
final Set<UnitCategory> units = UnitSeperator.categorize(unitsInTerritory);
PlayerID currentPlayer = null;
for (final UnitCategory item : units) {
// seperate players with a seperator
if (item.getOwner() != currentPlayer) {
currentPlayer = item.getOwner();
panel.add(Box.createVerticalStrut(15));
}
// TODO Kev determine if we need to identify if the unit is hit/disabled
final Optional<ImageIcon> unitIcon = uiContext.getUnitImageFactory().getIcon(item.getType(), item.getOwner(), item.hasDamageOrBombingUnitDamage(), item.getDisabled());
if (unitIcon.isPresent()) {
// overlay flag onto upper-right of icon
final ImageIcon flagIcon = new ImageIcon(uiContext.getFlagImageFactory().getSmallFlag(item.getOwner()));
final Icon flaggedUnitIcon = new OverlayIcon(unitIcon.get(), flagIcon, unitIcon.get().getIconWidth() - (flagIcon.getIconWidth() / 2), 0);
final JLabel label = new JLabel("x" + item.getUnits().size(), flaggedUnitIcon, SwingConstants.LEFT);
final String toolTipText = "<html>" + item.getType().getName() + ": " + item.getType().getTooltip(currentPlayer) + "</html>";
label.setToolTipText(toolTipText);
panel.add(label);
}
}
return panel;
}
use of games.strategy.triplea.util.UnitCategory in project triplea by triplea-game.
the class UnitChooser method createEntries.
private void createEntries(final Collection<Unit> units, final Map<Unit, Collection<Unit>> dependent, final boolean categorizeMovement, final boolean categorizeTransportCost, final Collection<Unit> defaultSelections) {
final Collection<UnitCategory> categories = UnitSeperator.categorize(units, dependent, categorizeMovement, categorizeTransportCost);
final Collection<UnitCategory> defaultSelectionsCategorized = UnitSeperator.categorize(defaultSelections, dependent, categorizeMovement, categorizeTransportCost);
final IntegerMap<UnitCategory> defaultValues = createDefaultSelectionsMap(defaultSelectionsCategorized);
for (final UnitCategory category : categories) {
addCategory(category, defaultValues.getInt(category));
}
}
Aggregations