Skip to content

TextIndicator

roosit edited this page May 31, 2026 · 2 revisions

TextIndicator

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

Full source code with brief explanations

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

package com.velitask.plugin.official;

import com.velitask.sdk.Indicator;
import com.velitask.sdk.IndicatorContext;
import com.velitask.sdk.properties.FontColorProperty;
import com.velitask.sdk.properties.IProperty;
import com.velitask.sdk.properties.StringProperty;
import com.velitask.sdk.properties.TextAlignProperty;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import org.abricos.core.state.maket.HorizontalAlign;
import org.abricos.core.state.maket.Maket;
import org.abricos.core.state.maket.VerticalAlign;

/*
 * Free-text indicator for an arbitrary caption: draws a static string
 * that the user types manually, with font, color, and alignment settings.
 * No sensors and no time data — the text does not depend on the player position.
 */
public class TextIndicator extends Indicator {

    /* Stable indicator name for saved projects, templates, and localization. */
    public static final String NAME = "text";

    /* Base localization key for title, description, tags, and default text. */
    private static final String KEY = _KEY + "." + NAME;

    /*
     * Arbitrary string typed by the user.
     * The constructor sets the default text, the stable name "value", and the field title.
     */
    private final StringProperty mValue = new StringProperty(
            localized(KEY + ".value.default"),
            "value",
            localized(KEY + ".value.title")
    );

    /* Font and color of the caption. */
    private final FontColorProperty mFont = new FontColorProperty();

    /* Text alignment inside the layer. */
    private final TextAlignProperty mTextAlign = new TextAlignProperty();

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    public String getTitle() {
        return localized(KEY + ".title");
    }

    @Override
    public String getDescription() {
        return localized(KEY + ".description");
    }

    @Override
    public String getTags() {
        return localized(KEY + ".tags");
    }

    /*
     * Initial layout: top-left, 100 px margin, 600 x 120 size.
     * The layer is wider than for numeric texts, to fit an arbitrary caption.
     */
    @Override
    public void defineMaket(Maket maket) {
        maket.setVertical(VerticalAlign.TOP);
        maket.setHorizontal(HorizontalAlign.LEFT);
        maket.setLayerMargin(null, 100d, 100d, null);
        maket.setLayerSize(600d, 120d);
    }

    /*
     * Registers properties in UI order:
     * text, font, alignment.
     */
    @Override
    public IProperty[] defineProperties() {
        return new IProperty[]{
            mValue,
            mFont,
            mTextAlign
        };
    }

    /*
     * Render takes a snapshot of the string and draws it.
     * An empty or missing string draws nothing.
     */
    @Override
    public void render(IndicatorContext indicatorContext) {
        TextContext ctx = (TextContext) indicatorContext;
        Graphics2D g = ctx.graphics;

        String text = ctx.value.value;
        if (text == null || text.isEmpty()) {
            return;
        }

        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);

        Font font = ctx.font.toFont(ctx.scale);
        g.setFont(font);
        g.setColor(ctx.font.color.value);

        ctx.textAlign.drawText(g, text, ctx.width, ctx.height);
    }

    /* Context fixes property snapshots for a specific frame. */
    public class TextContext extends IndicatorContext {

        public final StringProperty.StringContext value;
        public final FontColorProperty.FontColorContext font;
        public final TextAlignProperty.TextAlignContext textAlign;

        public TextContext(Player player, Canvas canvas) {
            super(player, canvas);
            value = mValue.createContext();
            font = mFont.createContext();
            textAlign = mTextAlign.createContext();
        }
    }

    @Override
    public IndicatorContext createContext(IndicatorContext.Player player, IndicatorContext.Canvas canvas) {
        return new TextContext(player, canvas);
    }
}

Purpose

TextIndicator is a free-text indicator for an arbitrary caption. It draws a static string that the user types manually, with font, color, and alignment settings. The main use case is adding a title, caption, or comment to a video that is not tied to track data.

How it works

Data. The indicator has no data source and no sensors. The text is stored in a StringProperty and does not depend on player time: the same string is drawn on every frame. Time and raw-time are not used.

Settings. Three properties: arbitrary text (StringProperty), font and color (FontColorProperty), and alignment (TextAlignProperty). StringProperty has the stable name value; the default text and the field title come from localization.

Drawing. Render reads the string snapshot from the context. If the string is empty or missing, the frame is not drawn. Otherwise antialiasing is enabled, the font (scaled to the current scale) and color are taken from FontColorProperty, and TextAlignProperty.drawText places the text inside the layer.

Features and limitations

  • If the text field is empty, the indicator draws nothing.
  • The text is static: it does not change over the video and does not depend on track data or the player position.
  • The indicator has no text template and no variables — it is a plain string, not a format with substitutions.
  • The indicator has no skins: defineSkins is not overridden.
  • The initial layer is wider (600 px) than for numeric text indicators, to fit a long caption.

Clone this wiki locally