Search in sources :

Example 1 with PlayerManager

use of games.strategy.engine.data.PlayerManager in project triplea by triplea-game.

the class PlayerChatRenderer method setIconMap.

private void setIconMap() {
    final PlayerManager playerManager = game.getPlayerManager();
    PlayerList playerList;
    game.getData().acquireReadLock();
    try {
        playerList = game.getData().getPlayerList();
    } finally {
        game.getData().releaseReadLock();
    }
    // new HashSet removes duplicates
    for (final INode playerNode : new HashSet<>(playerManager.getPlayerMapping().values())) {
        final Set<String> players = playerManager.getPlayedBy(playerNode);
        if (players.size() > 0) {
            final List<Icon> icons = players.stream().filter(player -> uiContext != null && uiContext.getFlagImageFactory() != null).map(player -> new ImageIcon(uiContext.getFlagImageFactory().getSmallFlag(playerList.getPlayerId(player)))).collect(Collectors.toList());
            maxIconCounter = Math.max(maxIconCounter, icons.size());
            playerMap.put(playerNode.toString(), players);
            if (uiContext == null) {
                iconMap.put(playerNode.toString(), null);
            } else {
                iconMap.put(playerNode.toString(), icons);
            }
        }
    }
}
Also used : DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) INode(games.strategy.net.INode) JList(javax.swing.JList) Set(java.util.Set) PlayerList(games.strategy.engine.data.PlayerList) HashMap(java.util.HashMap) Icon(javax.swing.Icon) Component(java.awt.Component) Collectors(java.util.stream.Collectors) SwingConstants(javax.swing.SwingConstants) PlayerManager(games.strategy.engine.data.PlayerManager) HashSet(java.util.HashSet) List(java.util.List) UiContext(games.strategy.triplea.ui.UiContext) IGame(games.strategy.engine.framework.IGame) ImageIcon(javax.swing.ImageIcon) Joiner(com.google.common.base.Joiner) ImageIcon(javax.swing.ImageIcon) INode(games.strategy.net.INode) PlayerManager(games.strategy.engine.data.PlayerManager) PlayerList(games.strategy.engine.data.PlayerList) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) HashSet(java.util.HashSet)

Aggregations

Joiner (com.google.common.base.Joiner)1 PlayerList (games.strategy.engine.data.PlayerList)1 PlayerManager (games.strategy.engine.data.PlayerManager)1 IGame (games.strategy.engine.framework.IGame)1 INode (games.strategy.net.INode)1 UiContext (games.strategy.triplea.ui.UiContext)1 Component (java.awt.Component)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 DefaultListCellRenderer (javax.swing.DefaultListCellRenderer)1 Icon (javax.swing.Icon)1 ImageIcon (javax.swing.ImageIcon)1 JList (javax.swing.JList)1 SwingConstants (javax.swing.SwingConstants)1