Search in sources :

Example 1 with OverlayIcon

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;
}
Also used : JPanel(javax.swing.JPanel) PlayerID(games.strategy.engine.data.PlayerID) ImageIcon(javax.swing.ImageIcon) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) Icon(javax.swing.Icon) OverlayIcon(games.strategy.ui.OverlayIcon) ImageIcon(javax.swing.ImageIcon) OverlayIcon(games.strategy.ui.OverlayIcon) UnitCategory(games.strategy.triplea.util.UnitCategory)

Aggregations

PlayerID (games.strategy.engine.data.PlayerID)1 UnitCategory (games.strategy.triplea.util.UnitCategory)1 OverlayIcon (games.strategy.ui.OverlayIcon)1 BoxLayout (javax.swing.BoxLayout)1 Icon (javax.swing.Icon)1 ImageIcon (javax.swing.ImageIcon)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1