use of org.apache.batik.anim.timing.TimedElement in project yamcs-studio by yamcs.
the class AnimatedSVGCache method addImage.
public Image addImage(BufferedImage awtImage) {
if (filled) {
return null;
}
if (entries.size() == maxSize) {
flush();
}
Image image = null;
long currentWaitTime = Long.MAX_VALUE;
if (!initialized) {
// Initialize
for (TimedElement te : timedDocumentRoot.getChildren()) {
timeHandlers.put(te, new TimedElementHandler(te));
}
entries.clear();
filled = false;
repeatCount = 0;
initialized = true;
} else {
// Compare time of each element with previous call
for (TimedElement te : timedDocumentRoot.getChildren()) {
if (timeHandlers.get(te) != null && timeHandlers.get(te).update(te) && timeHandlers.get(te).getWaitTime() < currentWaitTime) {
// Take the minimum
currentWaitTime = timeHandlers.get(te).getWaitTime();
}
}
// Check if all images have been cached
filled = hasRepeated();
// Avoid first repeat
if (filled && repeatCount == 0) {
repeatCount++;
// Reset time counters
timeHandlers.clear();
for (TimedElement te : timedDocumentRoot.getChildren()) {
timeHandlers.put(te, new TimedElementHandler(te));
}
filled = false;
}
}
if (filled) {
// End of the loop, back to first image
entries.get(0).setWaitTime(currentWaitTime);
return entries.get(0).getImage();
}
ImageData imageData = SVGUtils.toSWT(swtDisplay, awtImage);
image = new Image(swtDisplay, imageData);
// Avoid first repeat
if (repeatCount == 0) {
return image;
}
entries.add(new Entry(currentWaitTime, image));
return image;
}
Aggregations