Repository navigation
AudioPreviewGenerator
Up | Previous | Next | Русский
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 AudioPreviewGenerator.java: the production code stays clean and the explanations live in the wiki.
package com.velitask.plugin.official.previews;
import com.velitask.plugin.official.AudioIndicator;
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;
/* Audio preview generator: puts a single indicator layer on the thumbnail. */
public final class AudioPreviewGenerator extends PreviewGenerator {
@Override
/* Generator name, unique within the plugin. */
public String getName() {
return "audio";
}
@Override
/* Cheap check by source type; the source data is not read. */
public boolean supports(ISource source) {
return source.getType() == SourceType.AUDIO;
}
@Override
/* Preview template: one indicator layer over the whole frame. */
public PreviewTemplate generate(PreviewRequest request) {
PreviewTemplate template = PreviewTemplate.create();
template.layer(VelitaskPlagin.UID + "." + AudioIndicator.NAME).fill();
return template;
}
@Override
/* Baseline solution: another plugin can replace it with its own preview. */
public boolean isBaseline() {
return true;
}
}Preview generator for sound files. For a source of the "audio" type the thumbnail is a layer of the "Audio" indicator.
Data. The generator does not read the source data. The supports(...) condition looks only at the source type (SourceType.AUDIO), so the check is cheap, as the PreviewGenerator contract requires.
Settings. The generator has no settings of its own, only the name "audio". 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 AudioIndicator 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 AudioIndicator.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.
-
isBaseline()returnstrue: 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 returnsnull, so once the generator has supported a source, the chain of generators goes no further. - The class is
finaland public; no constructor is declared, the default constructor is used.