Search in sources :

Example 1 with WordText

use of pl.asie.charset.module.tablet.format.words.WordText in project Charset by CharsetMC.

the class AbstractTypesetter method write.

@Override
public void write(String text) throws TruthError {
    if (Strings.isNullOrEmpty(text))
        return;
    final Tokenizer tokenizer = new Tokenizer(text);
    while (tokenizer.nextToken()) {
        final String token = tokenizer.getToken();
        if (token.isEmpty())
            continue;
        switch(tokenizer.getType()) {
            default:
                throw new TruthError("Unknown tokentype: " + tokenizer.getToken());
            case WORD:
                write(new WordText(token));
                break;
            case PARAMETER:
                write(token);
                break;
            case COMMAND:
                final String cmdName = token.toLowerCase(Locale.ROOT);
                ICommand cmd = TabletAPI.INSTANCE.getCommand(cmdName);
                if (cmd == null) {
                    throw new TruthError("Unknown command: " + cmdName);
                }
                runCommand(cmd, tokenizer);
                break;
        }
    }
}
Also used : TruthError(pl.asie.charset.module.tablet.format.api.TruthError) ICommand(pl.asie.charset.module.tablet.format.api.ICommand) WordText(pl.asie.charset.module.tablet.format.words.WordText)

Example 2 with WordText

use of pl.asie.charset.module.tablet.format.words.WordText in project Charset by CharsetMC.

the class CommandURLMissing method call.

@Override
public void call(ITypesetter typesetter, ITokenizer tokenizer) throws TruthError {
    String content = tokenizer.getParameter("\\urlmissing missing parameter: content");
    try {
        typesetter.pushStyle(new StyleColor(0xFFCC3333), StyleFormat.ITALIC, StyleFormat.UNDERLINE);
        typesetter.write(new WordText(content));
        typesetter.popStyle(3);
    } catch (Exception e) {
        e.printStackTrace();
        throw new TruthError(e.getMessage());
    }
}
Also used : TruthError(pl.asie.charset.module.tablet.format.api.TruthError) StyleColor(pl.asie.charset.module.tablet.format.words.StyleColor) WordText(pl.asie.charset.module.tablet.format.words.WordText)

Aggregations

TruthError (pl.asie.charset.module.tablet.format.api.TruthError)2 WordText (pl.asie.charset.module.tablet.format.words.WordText)2 ICommand (pl.asie.charset.module.tablet.format.api.ICommand)1 StyleColor (pl.asie.charset.module.tablet.format.words.StyleColor)1