}
@Override
protected void doService(final ToolPageContext page) throws IOException, ServletException {
State state = State.getInstance(Query.from(Object.class).where("_id = ?", page.param(UUID.class, "id")).first());
ColorDistribution distribution = state.as(ColorDistribution.Data.class).getDistribution();
if (distribution == null) {
return;
}
page.writeHeader();
page.writeStart("div", "class", "widget");
page.writeStart("h1", "class", "icon icon-tint");
page.writeHtml("Colors");
page.writeEnd();
page.writeStart("h2");
page.writeHtml("Dominant");
page.writeEnd();
for (Map.Entry<String, Object> entry : distribution.getState().entrySet()) {
String fieldName = entry.getKey();
Object percentage = entry.getValue();
if (fieldName.startsWith("o") && percentage != null) {
int percentageInt = (int) (((Double) percentage) * 100);