use of games.strategy.ui.OverlayIcon 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;
}
Aggregations