Search in sources :

Example 1 with WarbandDefinition

use of delta.games.lotro.lore.warbands.WarbandDefinition in project lotro-companion by dmorcellet.

the class WarbandsFilterController method getMinLevels.

private Integer[] getMinLevels() {
    WarbandDefinition[] warbands = WarbandsRegistry.getWarbandsRegistry().getAllWarbands();
    Set<Integer> levelSets = new HashSet<Integer>();
    for (WarbandDefinition warband : warbands) {
        Integer minLevel = warband.getLevel();
        if (minLevel != null) {
            levelSets.add(minLevel);
        }
    }
    List<Integer> minLevels = new ArrayList<Integer>(levelSets);
    Collections.sort(minLevels);
    Integer[] ret = minLevels.toArray(new Integer[minLevels.size()]);
    return ret;
}
Also used : WarbandDefinition(delta.games.lotro.lore.warbands.WarbandDefinition) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 2 with WarbandDefinition

use of delta.games.lotro.lore.warbands.WarbandDefinition in project lotro-companion by dmorcellet.

the class WarbandsTableController method buildWarbandCellRenderer.

private TableCellRenderer buildWarbandCellRenderer(final HashMap<String, JPanel> warbandPanels) {
    TableCellRenderer renderer = new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            WarbandDefinition warband = (WarbandDefinition) value;
            JPanel panel = warbandPanels.get(warband.getName());
            int height = panel.getPreferredSize().height;
            table.setRowHeight(row, height);
            return panel;
        }
    };
    return renderer;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JPanel(javax.swing.JPanel) JTable(javax.swing.JTable) WarbandDefinition(delta.games.lotro.lore.warbands.WarbandDefinition)

Example 3 with WarbandDefinition

use of delta.games.lotro.lore.warbands.WarbandDefinition in project lotro-companion by dmorcellet.

the class WarbandsTableController method buildCharacterColumn.

private TableColumnController<WarbandDefinition, WarbandStats> buildCharacterColumn(CharacterFile character) {
    final WarbandsStats warbandsStats = loadToonStats(character);
    CellDataProvider<WarbandDefinition, WarbandStats> cell = new CellDataProvider<WarbandDefinition, WarbandStats>() {

        @Override
        public WarbandStats getData(WarbandDefinition item) {
            return warbandsStats.getWarbandStats(item, true);
        }
    };
    String id = character.getIdentifier();
    TableColumnController<WarbandDefinition, WarbandStats> column = new TableColumnController<WarbandDefinition, WarbandStats>(id, "Stats", WarbandStats.class, cell);
    // Cell renderer
    TableCellRenderer renderer = buildStatCellRenderer(warbandsStats);
    column.setCellRenderer(renderer);
    // Header renderer
    JPanel headerPanel = buildToonHeaderPanel(character);
    TableCellRenderer headerRenderer = buildSimpleCellRenderer(headerPanel);
    column.setHeaderCellRenderer(headerRenderer);
    int minWidth = headerPanel.getPreferredSize().width;
    column.setMinWidth(minWidth);
    column.setPreferredWidth(minWidth);
    // Comparator
    Comparator<WarbandStats> statsComparator = new Comparator<WarbandStats>() {

        @Override
        public int compare(WarbandStats w1, WarbandStats w2) {
            Long d1 = w1.getMostRecentDate();
            Long d2 = w2.getMostRecentDate();
            if (d1 == null) {
                if (d2 == null)
                    return 0;
                return -1;
            }
            if (d2 == null)
                return 1;
            return d1.compareTo(d2);
        }
    };
    column.setComparator(statsComparator);
    return column;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JPanel(javax.swing.JPanel) WarbandsStats(delta.games.lotro.stats.warbands.WarbandsStats) TableColumnController(delta.common.ui.swing.tables.TableColumnController) Comparator(java.util.Comparator) WarbandDefinition(delta.games.lotro.lore.warbands.WarbandDefinition) WarbandStats(delta.games.lotro.stats.warbands.WarbandStats) CellDataProvider(delta.common.ui.swing.tables.CellDataProvider)

Example 4 with WarbandDefinition

use of delta.games.lotro.lore.warbands.WarbandDefinition in project lotro-companion by dmorcellet.

the class WarbandsTableController method buildStatCellRenderer.

private TableCellRenderer buildStatCellRenderer(final WarbandsStats warbandsStats) {
    // Map warband ID -> stats panel
    final Map<String, JPanel> cellPanels = new HashMap<String, JPanel>();
    TableCellRenderer renderer = new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            WarbandStats stats = (WarbandStats) value;
            JPanel panel = null;
            if (stats != null) {
                WarbandDefinition warband = stats.getDefinition();
                panel = cellPanels.get(warband.getName());
                if (panel == null) {
                    panel = buildStatsPanel(stats);
                    cellPanels.put(warband.getName(), panel);
                }
            } else {
                panel = GuiFactory.buildPanel(new BorderLayout());
            }
            return panel;
        }
    };
    return renderer;
}
Also used : JPanel(javax.swing.JPanel) TableCellRenderer(javax.swing.table.TableCellRenderer) BorderLayout(java.awt.BorderLayout) HashMap(java.util.HashMap) JTable(javax.swing.JTable) WarbandDefinition(delta.games.lotro.lore.warbands.WarbandDefinition) WarbandStats(delta.games.lotro.stats.warbands.WarbandStats)

Example 5 with WarbandDefinition

use of delta.games.lotro.lore.warbands.WarbandDefinition in project lotro-companion by dmorcellet.

the class WarbandsStats method parseItem.

private void parseItem(CharacterLogItem item) {
    String label = item.getLabel();
    String warbandName = label.substring(WARBAND_SEED.length()).trim();
    long date = item.getDate();
    WarbandsRegistry registry = WarbandsRegistry.getWarbandsRegistry();
    WarbandDefinition warband = registry.getByName(warbandName);
    if (warband == null) {
        _logger.warn("Unknown warband [" + warbandName + "]. Ignored.");
    } else {
        WarbandStats stat = getWarbandStats(warband, true);
        stat.add(date);
    }
}
Also used : WarbandDefinition(delta.games.lotro.lore.warbands.WarbandDefinition) WarbandsRegistry(delta.games.lotro.lore.warbands.WarbandsRegistry)

Aggregations

WarbandDefinition (delta.games.lotro.lore.warbands.WarbandDefinition)9 WarbandsRegistry (delta.games.lotro.lore.warbands.WarbandsRegistry)4 JPanel (javax.swing.JPanel)4 TableCellRenderer (javax.swing.table.TableCellRenderer)4 ArrayList (java.util.ArrayList)3 CellDataProvider (delta.common.ui.swing.tables.CellDataProvider)2 TableColumnController (delta.common.ui.swing.tables.TableColumnController)2 WarbandStats (delta.games.lotro.stats.warbands.WarbandStats)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 JTable (javax.swing.JTable)2 ListDataProvider (delta.common.ui.swing.tables.ListDataProvider)1 WarbandsStats (delta.games.lotro.stats.warbands.WarbandsStats)1 BorderLayout (java.awt.BorderLayout)1 GridBagLayout (java.awt.GridBagLayout)1