Search in sources :

Example 1 with LogItemType

use of delta.games.lotro.character.log.CharacterLogItem.LogItemType in project lotro-companion by dmorcellet.

the class CharacterLogFilterController method build.

private JPanel build() {
    JPanel panel = GuiFactory.buildPanel(new GridBagLayout());
    // Dates
    JPanel datesPanel = GuiFactory.buildPanel(new GridBagLayout());
    {
        GridBagConstraints c = new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0);
        List<Long> dates = _log.getDates();
        datesPanel.add(GuiFactory.buildLabel("After:"), c);
        _minDates = buildDatesChooser(dates);
        c.gridx = 1;
        datesPanel.add(_minDates.getComboBox(), c);
        c.gridy = 1;
        c.gridx = 0;
        datesPanel.add(GuiFactory.buildLabel("Before:"), c);
        _maxDates = buildDatesChooser(dates);
        c.gridx = 1;
        datesPanel.add(_maxDates.getComboBox(), c);
        ItemSelectionListener<Long> listenerMinDates = new ItemSelectionListener<Long>() {

            @Override
            public void itemSelected(Long selected) {
                _filter.setMinDate(selected);
                updateFilter();
            }
        };
        _minDates.addListener(listenerMinDates);
        ItemSelectionListener<Long> listenerMaxDates = new ItemSelectionListener<Long>() {

            @Override
            public void itemSelected(Long selected) {
                _filter.setMaxDate(selected);
                updateFilter();
            }
        };
        _maxDates.addListener(listenerMaxDates);
    }
    // Label filter
    JPanel containsPanel = GuiFactory.buildPanel(new FlowLayout(FlowLayout.LEADING));
    {
        containsPanel.add(GuiFactory.buildLabel("Label filter:"));
        _contains = GuiFactory.buildTextField("");
        _contains.setColumns(20);
        containsPanel.add(_contains);
        DocumentListener dl = new DocumentListener() {

            @Override
            public void removeUpdate(DocumentEvent e) {
                doIt();
            }

            @Override
            public void insertUpdate(DocumentEvent e) {
                doIt();
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
                doIt();
            }

            private void doIt() {
                String text = _contains.getText();
                if (text.length() == 0)
                    text = null;
                _filter.setLabelFilter(text);
                updateFilter();
            }
        };
        _contains.getDocument().addDocumentListener(dl);
    }
    // Checkboxes
    JPanel cbPanel = GuiFactory.buildPanel(new GridBagLayout());
    {
        LogItemType[] types = { LogItemType.QUEST, LogItemType.DEED, LogItemType.LEVELUP, LogItemType.PROFESSION, LogItemType.VOCATION, LogItemType.PVMP };
        String[] labels = { "Quests", "Deeds", "Level-ups", "Profession", "Vocation", "PvM" };
        _types.clear();
        int nbInRow = 3;
        int nbTypes = types.length;
        for (int i = 0; i < nbTypes; i++) {
            LogItemType type = types[i];
            JCheckBox checkbox = GuiFactory.buildCheckbox(labels[i]);
            _types.put(type, checkbox);
            checkbox.addItemListener(this);
            GridBagConstraints c = new GridBagConstraints(i % nbInRow, i / nbInRow, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0);
            cbPanel.add(checkbox, c);
        }
    }
    GridBagConstraints c = new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0);
    panel.add(datesPanel, c);
    c = new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0);
    panel.add(cbPanel, c);
    c = new GridBagConstraints(0, 1, 2, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0);
    panel.add(containsPanel, c);
    return panel;
}
Also used : JPanel(javax.swing.JPanel) DocumentListener(javax.swing.event.DocumentListener) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) FlowLayout(java.awt.FlowLayout) GridBagLayout(java.awt.GridBagLayout) ItemSelectionListener(delta.common.ui.swing.combobox.ItemSelectionListener) DocumentEvent(javax.swing.event.DocumentEvent) JCheckBox(javax.swing.JCheckBox) List(java.util.List) LogItemType(delta.games.lotro.character.log.CharacterLogItem.LogItemType)

Example 2 with LogItemType

use of delta.games.lotro.character.log.CharacterLogItem.LogItemType 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)

Example 3 with LogItemType

use of delta.games.lotro.character.log.CharacterLogItem.LogItemType in project lotro-companion by dmorcellet.

the class WarbandsStats method getWarbandItems.

private List<CharacterLogItem> getWarbandItems(CharacterLog log) {
    List<CharacterLogItem> ret = new ArrayList<CharacterLogItem>();
    int nb = log.getNbItems();
    for (int i = 0; i < nb; i++) {
        CharacterLogItem item = log.getLogItem(i);
        if (item != null) {
            LogItemType type = item.getLogItemType();
            if (type == LogItemType.QUEST) {
                String label = item.getLabel();
                if (label.startsWith(WARBAND_SEED)) {
                    ret.add(item);
                }
            }
        }
    }
    Collections.reverse(ret);
    return ret;
}
Also used : ArrayList(java.util.ArrayList) CharacterLogItem(delta.games.lotro.character.log.CharacterLogItem) LogItemType(delta.games.lotro.character.log.CharacterLogItem.LogItemType)

Example 4 with LogItemType

use of delta.games.lotro.character.log.CharacterLogItem.LogItemType in project lotro-companion by dmorcellet.

the class CharacterLogFilterController method itemStateChanged.

/**
 * Invoked when a 'type' checkbox state has changed.
 * @param event Source event.
 */
@Override
public void itemStateChanged(ItemEvent event) {
    Set<LogItemType> types = new HashSet<LogItemType>();
    for (Map.Entry<LogItemType, JCheckBox> entry : _types.entrySet()) {
        JCheckBox checkbox = entry.getValue();
        LogItemType type = entry.getKey();
        if (checkbox.isSelected()) {
            types.add(type);
        }
    }
    _filter.setSelectedTypes(types);
    updateFilter();
}
Also used : JCheckBox(javax.swing.JCheckBox) HashMap(java.util.HashMap) Map(java.util.Map) LogItemType(delta.games.lotro.character.log.CharacterLogItem.LogItemType) HashSet(java.util.HashSet)

Example 5 with LogItemType

use of delta.games.lotro.character.log.CharacterLogItem.LogItemType in project lotro-tools by dmorcellet.

the class CharacterLogPageParser method parseLogItem.

private CharacterLogItem parseLogItem(Element tr) {
    /*
<td class="char">
<a href="/home/character/2427907/146366987891794854">Glumlug</a>
</td>
<td class="date">2011/11/24</td>
<td class="details">
<img src="http://content.turbine.com/sites/playerportal/modules/lotro-base/images/icons/log/icon_levelup.png">
Reached level 70
</td>
 */
    /*
<td class="char">
<a href="/home/character/2427907/146366987891794854">Glumlug</a>
</td>
<td class="date">2011/11/24</td>
<td class="details">
<a href="http://lorebook.lotro.com/wiki/Special:LotroResource?id=1879208735">
<img src="http://content.turbine.com/sites/playerportal/modules/lotro-base/images/icons/log/icon_quest.png">
Completed 'The Practiced Arm'
</a>
</td>
 */
    CharacterLogItem ret = null;
    List<Element> tds = tr.getAllElements(HTMLElementName.TD);
    if ((tds != null) && (tds.size() == 3)) {
        if (_characterName == null) {
            Element charName = tds.get(0);
            _characterName = JerichoHtmlUtils.getTagContents(charName, HTMLElementName.A);
        }
        Element tdDate = tds.get(1);
        String dateStr = CharacterReference.decodeCollapseWhiteSpace(tdDate.getContent());
        LogItemType type = null;
        Element tdDetails = tds.get(2);
        List<Element> imgs = tdDetails.getAllElements(HTMLElementName.IMG);
        Element img = null;
        if ((imgs != null) && (imgs.size() == 1)) {
            img = imgs.get(0);
            String imgSrc = img.getAttributeValue("src");
            type = findType(imgSrc);
        }
        String url = null;
        Element a = tdDetails.getFirstElement(HTMLElementName.A);
        if (a != null) {
            url = a.getAttributeValue("href");
        }
        TextExtractor extractor = tdDetails.getTextExtractor();
        if (img != null)
            extractor.excludeElement(img.getStartTag());
        if (a != null)
            extractor.excludeElement(a.getStartTag());
        String label = extractor.toString().trim();
        if ((dateStr != null) && (type != null) && (label != null)) {
            try {
                Calendar c = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"));
                String[] items = dateStr.split("/");
                int year = Integer.parseInt(items[0]);
                int month = Integer.parseInt(items[1]);
                int day = Integer.parseInt(items[2]);
                label = tuneLabel(label);
                if (url != null) {
                    url = url.trim();
                }
                c.setTimeInMillis(0);
                c.set(year, month - 1, day);
                long date = c.getTimeInMillis();
                ret = new CharacterLogItem(date, type, label, url);
            } catch (Exception e) {
                _logger.error("Cannot parse LOTRO character log item!", e);
            }
        }
    }
    return ret;
}
Also used : Element(net.htmlparser.jericho.Element) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) TextExtractor(net.htmlparser.jericho.TextExtractor) CharacterLogItem(delta.games.lotro.character.log.CharacterLogItem) LogItemType(delta.games.lotro.character.log.CharacterLogItem.LogItemType)

Aggregations

LogItemType (delta.games.lotro.character.log.CharacterLogItem.LogItemType)5 CharacterLogItem (delta.games.lotro.character.log.CharacterLogItem)3 JCheckBox (javax.swing.JCheckBox)2 ItemSelectionListener (delta.common.ui.swing.combobox.ItemSelectionListener)1 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 FlowLayout (java.awt.FlowLayout)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1