Skip to content

EN Resources

roosit edited this page Oct 16, 2026 · 2 revisions

Plugin resources

Up | Русский

A description of the files in src/main/resources/: what is there, what it is for, how to add new ones. Resources are packed into the plugin jar and are available at runtime by flat paths from the jar root.

Structure

src/main/resources/
├── sql/setup/          → plugin DB schema
│   └── create.sql
├── localization/       → localization
│   ├── strings.properties        (EN)
│   └── strings_ru.properties     (RU)
└── svg/                → indicator SVG graphics
    └── speedometer/
        ├── background.svg
        ├── delimiter.svg
        ├── arrow.svg, arrow_tail.svg
        └── numeric_40.svg, numeric_80.svg, numeric_160.svg, numeric_320.svg

sql/setup/ — plugin DB

The plugin owns its own database inside the project: getDbVersion() in Plagin returns 1. The file create.sql is the full snapshot of the current schema version. How it is applied:

  • A new plugin database (the project has no saved version) runs only create.sql; the version is recorded as getDbVersion(), and the upgrade-N.sql files are not executed.
  • An existing database is brought up to date by the chain upgrade-(old+1) … upgrade-getDbVersion(): the file upgrade-N.sql moves the database from version N-1 to N, each step runs in its own transaction, and the saved version is updated only after a successful step. There is currently one version, and the plugin has no upgrade-N.sql files.
  • If the database cannot be brought to the required version (a step failed or a file is missing), the plugin is disconnected from the project, the project opens without it, and an entry goes to the application log; the attempt is repeated the next time the project is opened.
  • The getMinSupportedDbVersion() method is not overridden in the plugin (the default is 1): upgrade-N.sql files below this value can be deleted once the old versions are no longer supported.

Current schema (v1). The only table is import_log with the fields source_id (primary key), source_path and processed_at. It is filled by Plagin.onSourceImported: when each source is imported, it records which source was processed and when. There is no business logic on this data: the table shows how to set up the plugin's own database and work with it.

SQL uses the substitution ${table:import_log}: the runtime replaces it with the table name carrying the plugin prefix (plugin_com_velitask_plugin_example_import_log) to rule out collisions with other plugins.

How to change the schema. Everything in one commit: bring create.sql to the new snapshot, add sql/setup/upgrade-N.sql (ALTER TABLE, CREATE TABLE, etc., moving from N-1 to N) and raise getDbVersion() to N (for example, 1 → 2). A released upgrade-N.sql is not edited: any new change gets a new number. In the comments of SQL files use only -- lines and do not put ; inside comments: the file is split by ;.

How to remove the database entirely. If a forked plugin does not need its own database, return 0 from getDbVersion(), delete sql/setup/ and the onSourceImported method in Plagin. Then no database is created for the plugin.

localization/ — localization

Two files in the standard Java .properties format:

  • strings.properties — English strings (the default);
  • strings_ru.properties — Russian strings.

The application finds them by the path localization/; no separate manifest attribute is needed: the manifest needs only Velitask-Plugin-Class. The language is chosen by the file name suffix (_ru).

Keys are built by the scheme PluginExample.Indicator.<name>.<key>. The prefix PluginExample is set by the constant Plagin.KEY, and Plagin.KEY_INDICATOR adds .Indicator. For the speedometer (<name> = speedometer) the following keys are used:

Key What it defines
...speedometer.title, .description, .tags The indicator's title, description and tags.
...speedometer.speedScale.title The title of the "Scale" setting.
...speedometer.bgColor.title, .scaleColor.title, .arrowFillColor.title, .arrowStrokeColor.title, .arrowStrokeWidth.title Titles of the colors and the stroke width.
...speedometer.skin.night, .skin.racing Titles of the "Night" and "Racing" skins.
...speedometer.textTemplate.template.default The default number template ({curr}).
...speedometer.textTemplate.template.float The template for the skinFloat() variant, which is not connected to any skin.
...speedometer.textTemplate.var.curr The title of the curr variable ("Current speed").

The titles of the "Distance", "Font" and "Text Template" settings come from the SDK strings; they are not in the plugin files.

The defineAdditionLocales() method returns ["ru"], so the Russian strings are loaded together with the strings of the current interface language.

Encoding is UTF-8. Cyrillic is written as plain text, without \uXXXX.

Consistency check. Every key that the code requests through localized(...) must be present in both string files. The speedometer assembles keys from constants (localized(KEY + "." + SPEED_SCALE + ".title")) — when renaming a constant or a setting, check the resulting key in strings.properties and strings_ru.properties; a missing key is shown in the interface as is. Before the example is released, the keys are checked automatically.

svg/ — indicator graphics

The speedometer graphics are made with SVG so that they scale without loss. A file is loaded through SvgProperty, and .bind(selector, attribute, property) substitutes the current values of the settings into the attributes of the SVG elements with the given CSS class.

Files in svg/speedometer/ (used in SpeedometerIndicator):

File What it is CSS class and binding
background.svg Round background .ring — fill with the background color (bgColor)
delimiter.svg Scale ticks .tick-major and .tick-minor — stroke with the scale color (scaleColor)
numeric_40.svg, numeric_80.svg, numeric_160.svg, numeric_320.svg Four variants of the scale numbers; the indicator picks one by the "Scale" setting .number — fill with the scale color (scaleColor)
arrow.svg Needle with a stroke and a center hub .arrow-body — fill (arrowFillColor), stroke (arrowStrokeColor), stroke-width (arrowStrokeWidth); .arrow-hub — fill with the stroke color (arrowStrokeColor)
arrow_tail.svg Tail line (class .tail) Not used in code: the tail arc is drawn by drawArrowTailArc with Java 2D

The CSS class names .ring, .tick-major, .tick-minor, .number, .arrow-body, .arrow-hub are stable: the bindings in the indicator depend on them. When editing the SVG, do not rename the classes, otherwise .bind(...) will stop finding the elements.

How to add a new SVG.

  1. Put the file into svg/ (or a subfolder).
  2. Declare an SvgProperty with this path in the indicator: new SvgProperty("name", "svg/file.svg").
  3. Add .bind(...) for each configurable color; the selector must find the SVG element by its CSS class.
  4. Create the property context for the frame (createContext(frame)) in the indicator context and call render(...) in the right order.

How to replace the graphics. When forking, you will most likely redraw arrow.svg or add new numeric_*.svg files for other speed ranges. Keep the set of CSS classes, otherwise the bindings in SpeedometerIndicator will stop working.

Useful links

Clone this wiki locally