Skip to content

ImagePreviewGenerator

roosit edited this page Nov 15, 2026 · 1 revision

ImagePreviewGenerator

Up | Previous | Next | Русский

Full source with short explanations

Below is the full source of the class in documentation form. The comments inside the block explain the purpose of the parts of the class, but they are not stored in the working file ImagePreviewGenerator.java: the production code stays clean and the explanations live in the wiki.

package com.velitask.plugin.official.previews;

import com.velitask.plugin.official.ImageIndicator;
import com.velitask.plugin.official.VelitaskPlagin;
import com.velitask.sdk.ISource;
import com.velitask.sdk.SourceType;
import com.velitask.sdk.preview.PreviewGenerator;
import com.velitask.sdk.preview.PreviewRequest;
import com.velitask.sdk.preview.PreviewTemplate;

/* Image preview generator: puts a single indicator layer on the thumbnail. */
public final class ImagePreviewGenerator extends PreviewGenerator {

    @Override
    /* Generator name, unique within the plugin. */
    public String getName() {
        return "image";
    }

    @Override
    /* Cheap check by source type; the source data is not read. */
    public boolean supports(ISource source) {
        return source.getType() == SourceType.IMAGE;
    }

    @Override
    /* Preview template: one indicator layer over the whole frame. */
    public PreviewTemplate generate(PreviewRequest request) {
        PreviewTemplate template = PreviewTemplate.create();
        template.layer(VelitaskPlagin.UID + "." + ImageIndicator.NAME).fill();
        return template;
    }

    @Override
    /* Baseline solution: another plugin can replace it with its own preview. */
    public boolean isBaseline() {
        return true;
    }
}

Purpose

Preview generator for images. For a source of the "image" type the thumbnail template consists of a single layer of the "Image" indicator.

How it works

Data. The generator does not read the source data. The supports(...) condition looks only at the source type (SourceType.IMAGE), so the check is cheap, as the PreviewGenerator contract requires.

Settings. The generator has no settings of its own, only the name "image". The generate(...) method does not use the PreviewRequest with the preview size: the template depends neither on the size nor on the source content.

Drawing. generate(...) creates a PreviewTemplate, adds a layer of the ImageIndicator indicator and calls fill() so that the layer takes the whole preview frame. The full layer name is assembled from the plugin identifier VelitaskPlagin.UID, a dot and ImageIndicator.NAME. No additional values are passed to the layer: the other indicator properties stay at their defaults. The picture itself is built by the application from this template.

The generator is registered in VelitaskPlagin.definePreviewGenerators(); the order there is: video, image, audio, geo. The application polls the generators of all plugins by the priority getPriority() (here the default value) and draws the first non-empty template.

Features and limitations

  • isBaseline() returns true: this is a baseline solution that other plugins can replace. With equal priority, the generator of a non-baseline plugin is asked first.
  • generate(...) never returns null, so once the generator has supported a source, the chain of generators goes no further.
  • The class is final and public; no constructor is declared, the default constructor is used.

Clone this wiki locally