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(" ", " "));
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(" "));
}
}
Aggregations