Search in sources :

Example 1 with NewsWidget

use of net.technicpack.launcher.ui.controls.feeds.NewsWidget in project LauncherV3 by TechnicPack.

the class NewsSelector method loadNewsItems.

protected void loadNewsItems(NewsData news) {
    int count = 0;
    newLatestNewsArticle = settings.getLatestNewsArticle();
    for (int i = 0; i < news.getArticles().size(); i++) {
        if (news.getArticles().get(i).getId() > settings.getLatestNewsArticle()) {
            count++;
            if (news.getArticles().get(i).getId() > newLatestNewsArticle)
                newLatestNewsArticle = news.getArticles().get(i).getId();
        }
    }
    if (count > 0) {
        circle.setVisible(true);
        circle.setCount(count);
    } else {
        circle.setVisible(false);
    }
    Collections.sort(news.getArticles(), new Comparator<NewsArticle>() {

        @Override
        public int compare(NewsArticle o1, NewsArticle o2) {
            if (o1.getDate().getTime() > o2.getDate().getTime())
                return -1;
            else if (o1.getDate().getTime() < o2.getDate().getTime())
                return 1;
            else
                return 0;
        }
    });
    widgetHost.removeAll();
    GridBagConstraints constraints = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0);
    for (int i = 0; i < news.getArticles().size(); i++) {
        NewsWidget widget = new NewsWidget(resources, news.getArticles().get(i), avatarRepo.startImageJob(news.getArticles().get(i).getAuthorshipInfo()));
        widget.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() instanceof NewsWidget)
                    selectNewsItem((NewsWidget) e.getSource());
            }
        });
        widgetHost.add(widget, constraints);
        constraints.gridy++;
        if (selectedItem == null)
            selectNewsItem(widget);
    }
    constraints.weighty = 1.0;
    widgetHost.add(Box.createGlue(), constraints);
}
Also used : NewsWidget(net.technicpack.launcher.ui.controls.feeds.NewsWidget) NewsArticle(net.technicpack.platform.io.NewsArticle) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 NewsWidget (net.technicpack.launcher.ui.controls.feeds.NewsWidget)1 NewsArticle (net.technicpack.platform.io.NewsArticle)1