Search in sources :

Example 1 with GenericTableController

use of delta.common.ui.swing.tables.GenericTableController in project lotro-companion by dmorcellet.

the class CharacterLogTableController method buildTable.

private GenericTableController<CharacterLogItem> buildTable() {
    DataProvider<CharacterLogItem> provider = new DataProvider<CharacterLogItem>() {

        @Override
        public CharacterLogItem getAt(int index) {
            return _log.getLogItem(index);
        }

        @Override
        public int getCount() {
            return _log.getNbItems();
        }
    };
    GenericTableController<CharacterLogItem> table = new GenericTableController<CharacterLogItem>(provider);
    // Date column
    {
        CellDataProvider<CharacterLogItem, Date> dateCell = new CellDataProvider<CharacterLogItem, Date>() {

            @Override
            public Date getData(CharacterLogItem item) {
                long timestamp = item.getDate();
                return new Date(timestamp);
            }
        };
        TableColumnController<CharacterLogItem, Date> dateColumn = new TableColumnController<CharacterLogItem, Date>("Date", Date.class, dateCell);
        dateColumn.setWidthSpecs(100, 100, 50);
        dateColumn.setCellRenderer(new DateRenderer(Formats.DATE_PATTERN));
        table.addColumnController(dateColumn);
    }
    // Type column
    {
        CellDataProvider<CharacterLogItem, LogItemType> typeCell = new CellDataProvider<CharacterLogItem, LogItemType>() {

            @Override
            public LogItemType getData(CharacterLogItem item) {
                return item.getLogItemType();
            }
        };
        TableColumnController<CharacterLogItem, LogItemType> typeColumn = new TableColumnController<CharacterLogItem, LogItemType>("Type", LogItemType.class, typeCell);
        typeColumn.setWidthSpecs(100, 100, 50);
        typeColumn.setCellRenderer(new LogItemTypeRenderer());
        typeColumn.setUseToString(Boolean.TRUE);
        table.addColumnController(typeColumn);
    }
    // Label column
    {
        CellDataProvider<CharacterLogItem, String> labelCell = new CellDataProvider<CharacterLogItem, String>() {

            @Override
            public String getData(CharacterLogItem item) {
                return item.getLabel();
            }
        };
        TableColumnController<CharacterLogItem, String> labelColumn = new TableColumnController<CharacterLogItem, String>("Label", String.class, labelCell);
        labelColumn.setWidthSpecs(150, -1, 150);
        table.addColumnController(labelColumn);
    }
    return table;
}
Also used : TableColumnController(delta.common.ui.swing.tables.TableColumnController) DateRenderer(delta.common.ui.swing.tables.GenericTableController.DateRenderer) Date(java.util.Date) CellDataProvider(delta.common.ui.swing.tables.CellDataProvider) DataProvider(delta.common.ui.swing.tables.DataProvider) GenericTableController(delta.common.ui.swing.tables.GenericTableController) CharacterLogItem(delta.games.lotro.character.log.CharacterLogItem) CellDataProvider(delta.common.ui.swing.tables.CellDataProvider) LogItemType(delta.games.lotro.character.log.CharacterLogItem.LogItemType)

Aggregations

CellDataProvider (delta.common.ui.swing.tables.CellDataProvider)1 DataProvider (delta.common.ui.swing.tables.DataProvider)1 GenericTableController (delta.common.ui.swing.tables.GenericTableController)1 DateRenderer (delta.common.ui.swing.tables.GenericTableController.DateRenderer)1 TableColumnController (delta.common.ui.swing.tables.TableColumnController)1 CharacterLogItem (delta.games.lotro.character.log.CharacterLogItem)1 LogItemType (delta.games.lotro.character.log.CharacterLogItem.LogItemType)1 Date (java.util.Date)1