use of org.opengis.util.ProgressListener in project polymap4-core by Polymap4.
the class ColorMap2FilterEditor method createRandomColorMap.
/**
* Creates a new #colorMap with default color for values of the current #propertyName.
*/
protected void createRandomColorMap() throws IOException {
colorMap.clear();
// count occurences; maps property value into count
Map<Object, AtomicInteger> valueOccurences = new HashMap(MAX_VALUES * 2);
ProgressListener progress = new DefaultProgressListener();
site().featureStore.get().getFeatures().accepts(feature -> {
// get value
Object value = feature.getProperty(propertyName).getValue();
valueOccurences.computeIfAbsent(value, v -> new AtomicInteger()).incrementAndGet();
// check MAX_VALUES
if (valueOccurences.size() > MAX_VALUES) {
progress.setCanceled(true);
}
}, progress);
log.info("Color map entries: " + valueOccurences.size());
if (progress.isCanceled()) {
StatusDispatcher.handle(new Status(IStatus.INFO, CorePlugin.PLUGIN_ID, i18n.get("tooManyEntries", MAX_VALUES), null), Style.SHOW, Style.LOG);
} else {
valueOccurences.entrySet().stream().sorted((e1, e2) -> e2.getValue().get() - e1.getValue().get()).forEach(entry -> colorMap.add(new Triple(entry.getKey(), entry.getValue().get(), DefaultStyle.randomColor())));
}
}
Aggregations