Search in sources :

Example 6 with InlineHTML

use of com.google.gwt.user.client.ui.InlineHTML in project opennms by OpenNMS.

the class TagPanel method updatePanel.

private void updatePanel() {
    int minCount = Integer.MAX_VALUE, maxCount = Integer.MIN_VALUE;
    Map<String, Integer> tagCounts = new TreeMap<String, Integer>();
    for (String tag : m_delegate) {
        if (tagCounts.containsKey(tag)) {
            tagCounts.put(tag, tagCounts.get(tag).intValue() + 1);
        } else {
            tagCounts.put(tag, 1);
        }
    }
    for (int entry : tagCounts.values()) {
        if (entry < minCount)
            minCount = entry;
        if (entry > maxCount)
            maxCount = entry;
    }
    tagPanel.clear();
    for (final Map.Entry<String, Integer> entry : tagCounts.entrySet()) {
        final String tagText = entry.getKey();
        final Anchor tagLabel = new Anchor();
        double rawValue = (double) (entry.getValue() - minCount) * TagStyles.COUNT / (double) (maxCount - minCount);
        tagLabel.setHTML(tagText.replace(" ", "&nbsp;"));
        tagLabel.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                selectTag(tagText);
                m_eventBus.fireEvent(new TagSelectedEvent(tagText));
            }
        });
        switch((int) Math.round(rawValue)) {
            case (0):
                tagLabel.addStyleName(tagStyles.tag0());
                break;
            case (1):
                tagLabel.addStyleName(tagStyles.tag1());
                break;
            case (2):
                tagLabel.addStyleName(tagStyles.tag2());
                break;
            case (3):
                tagLabel.addStyleName(tagStyles.tag3());
                break;
            case (4):
                tagLabel.addStyleName(tagStyles.tag4());
                break;
            case (5):
                tagLabel.addStyleName(tagStyles.tag5());
                break;
            case (6):
                tagLabel.addStyleName(tagStyles.tag6());
                break;
            case (7):
                tagLabel.addStyleName(tagStyles.tag7());
                break;
            case (8):
                tagLabel.addStyleName(tagStyles.tag8());
                break;
            case (9):
                tagLabel.addStyleName(tagStyles.tag9());
                break;
            default:
                tagLabel.addStyleName(tagStyles.tag9());
        }
        tagPanel.add(tagLabel);
        // without this, the tag cloud doesn't wrap properly
        tagPanel.add(new InlineHTML(" "));
    }
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) InlineHTML(com.google.gwt.user.client.ui.InlineHTML) TreeMap(java.util.TreeMap) Anchor(com.google.gwt.user.client.ui.Anchor) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

InlineHTML (com.google.gwt.user.client.ui.InlineHTML)6 Anchor (com.google.gwt.user.client.ui.Anchor)2 PreloaderCallback (com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback)1 PreloaderState (com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState)1 Style (com.google.gwt.dom.client.Style)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 Image (com.google.gwt.user.client.ui.Image)1 InlineLabel (com.google.gwt.user.client.ui.InlineLabel)1 Panel (com.google.gwt.user.client.ui.Panel)1 RootPanel (com.google.gwt.user.client.ui.RootPanel)1 SimplePanel (com.google.gwt.user.client.ui.SimplePanel)1 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)1 SafeHtml (com.google.gwtexpui.safehtml.client.SafeHtml)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1