Search in sources :

Example 1 with DynamicToken

use of me.itay.idemodthingy.programs.bluej.api.tokens.DynamicToken in project IDEProgram by Itay2805.

the class IDELanguageJavaScript method parse.

@Override
public List<Token> parse(Project project, ProjectFile currentFile) {
    List<Token> ret = new ArrayList<>();
    String text = currentFile.getCode();
    if (text.length() == 0) {
        return ret;
    }
    String[] tokens = text.split(DELIMITER);
    StringBuilder sb = new StringBuilder();
    for (String token : tokens) {
        if (text.contains("\"")) {
            if (quote) {
                quote = false;
                ret.add(new DynamicToken(sb.toString()));
                continue;
            }
            quote = true;
        }
        if (quote) {
            sb.append(token);
            continue;
        }
        if (JSKeywordGroup.getTokens().contains(token)) {
            ret.add(new JSKeywordGroup());
            continue;
        }
        if (lastToken.equals("function")) {
            ret.add(new DynamicToken(text));
        }
        lastToken = text;
    }
    return ret;
}
Also used : JSKeywordGroup(me.itay.idemodthingy.languages.js.tokens.JSKeywordGroup) ArrayList(java.util.ArrayList) DynamicToken(me.itay.idemodthingy.programs.bluej.api.tokens.DynamicToken) Token(me.itay.idemodthingy.programs.bluej.api.tokens.Token) DynamicToken(me.itay.idemodthingy.programs.bluej.api.tokens.DynamicToken)

Example 2 with DynamicToken

use of me.itay.idemodthingy.programs.bluej.api.tokens.DynamicToken in project IDEProgram by Itay2805.

the class BlueJCodeEditor method render.

@Override
protected void render(Laptop laptop, Minecraft mc, int x, int y, int mouseX, int mouseY, boolean windowActive, float partialTicks) {
    if (!visible)
        return;
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    Gui.drawRect(xPosition, yPosition, xPosition + width, yPosition + height, backgroundColor);
    FontRenderer font = Minecraft.getMinecraft().fontRendererObj;
    // render text
    if (highlighter == null) {
        // no highlighter
        IDEModProgramThingy.LOGGER.info("No highlighter attached! Using default highlighting!");
        for (int i = from; i < from + maxLines; i++) {
            if (i >= lines.size()) {
                break;
            }
            int Y = i * font.FONT_HEIGHT;
            font.drawString(lines.get(i).replace("\t", "    "), 2 + xPosition, 2 + yPosition + Y, Color.WHITE.getRGB());
        }
    } else {
        // with highlight
        IDEModProgramThingy.LOGGER.info("Using highlighter for: " + highlighter.getName());
        for (int i = from; i < from + maxLines; i++) {
            if (i >= lines.size()) {
                break;
            }
            int Y = i * font.FONT_HEIGHT;
            int X = 0;
            for (Token token : tokens) {
                String text = "";
                if (token instanceof StaticToken) {
                    text = ((StaticToken) token).getToken().replace("\t", "    ");
                } else if (token instanceof DynamicToken) {
                    text = ((DynamicToken) token).getToken().replace("\t", "    ");
                }
                font.drawString(text, 2 + xPosition + X, 2 + yPosition + Y, token.getColor());
                X += font.getStringWidth(text);
            }
        }
        for (Problem problem : problems) {
            if (from >= problem.getLine() || from + maxLines < problem.getLine()) {
                continue;
            }
            int X = font.getStringWidth(lines.get(problem.getLine()).substring(0, problem.getColumn()));
            int Y = problem.getLine() * font.FONT_HEIGHT * 2;
            int length = problem.getLength();
            while ((length--) > 0) {
                font.drawString("~", 2 + xPosition + X, 2 + yPosition + Y, problem.getColor());
                X += errorLength;
            }
        }
    }
    if (editable) {
        // render cursor
        if (cursorState) {
            int X = font.getStringWidth(getCurrentLine().substring(0, cursorX).replace("\t", "   "));
            int Y = (cursorY - from) * font.FONT_HEIGHT;
            font.drawString("|", 2 + xPosition + X, 2 + yPosition + Y, cursorColor);
        }
    }
}
Also used : DynamicToken(me.itay.idemodthingy.programs.bluej.api.tokens.DynamicToken) StaticToken(me.itay.idemodthingy.programs.bluej.api.tokens.StaticToken) Token(me.itay.idemodthingy.programs.bluej.api.tokens.Token) Problem(me.itay.idemodthingy.programs.bluej.api.Problem) FontRenderer(net.minecraft.client.gui.FontRenderer) DynamicToken(me.itay.idemodthingy.programs.bluej.api.tokens.DynamicToken) StaticToken(me.itay.idemodthingy.programs.bluej.api.tokens.StaticToken)

Example 3 with DynamicToken

use of me.itay.idemodthingy.programs.bluej.api.tokens.DynamicToken in project IDEProgram by Itay2805.

the class IDETextArea method render.

@Override
public void render(Laptop laptop, Minecraft mc, int x, int y, int mouseX, int mouseY, boolean windowActive, float partialTicks) {
    GlStateManager.clearColor(1.0f, 1.0f, 1.0f, 1.0f);
    Gui.drawRect(xPosition, yPosition, xPosition + width, yPosition + height, borderColour);
    Gui.drawRect(xPosition + 1, yPosition + 1, xPosition + width - 1, yPosition + height - 1, backgroundColour);
    int to = from + lineCount;
    if (to >= lines.size()) {
        to = lines.size();
    }
    int currentY = 0;
    for (int i = from; i < to; i++) {
        List<Token> tokens = language.parse(this.openedFile.getParentProject(), this.openedFile);
        int currentX = 0;
        for (Token token : tokens) {
            String text = "";
            if (token instanceof StaticToken) {
                text = ((StaticToken) token).getToken().replace("\t", "    ");
            } else if (token instanceof DynamicToken) {
                text = ((DynamicToken) token).getToken().replace("\t", "    ");
            }
            font.drawString(text, 2 + xPosition + currentX, 2 + yPosition + currentY, token.getColor());
            currentX += font.getStringWidth(text);
        }
        currentY += font.FONT_HEIGHT;
    }
    if (editable) {
        if (updateCounter / 2 % 6 == 0 || lastX != cursorX || lastY != cursorY) {
            int toX = this.cursorX;
            if (toX > getCurrentLine().length()) {
                toX = getCurrentLine().length();
            }
            int cursorX = font.getStringWidth(getCurrentLine().substring(0, toX));
            int cursorY = (this.cursorY - from) * font.FONT_HEIGHT;
            font.drawSplitString("|", xPosition + PADDING + 1 + cursorX, yPosition + PADDING + 2 + cursorY, width - PADDING * 2 - 2, Color.WHITE.getRGB());
        }
        lastX = cursorX;
        lastY = cursorY;
    }
    for (ErrorHighlight err : errors) {
        int X = font.getStringWidth(getCurrentLine().substring(0, err.column));
        int Y = (err.line - from) * font.FONT_HEIGHT + font.FONT_HEIGHT;
        StringBuilder finale = new StringBuilder();
        int length = font.getStringWidth(getCurrentLine().substring(err.column, err.column + err.length));
        for (int i = 0; i <= (length / errorLength); i++) {
            finale.append("~");
        }
        font.drawSplitString(finale.toString(), xPosition + PADDING + 1 + X, yPosition + PADDING + 2 + Y, width - PADDING * 2 - 2, err.color);
        if (RenderUtil.isMouseInside(mouseX - xPosition, mouseY - yPosition, X, Y - font.FONT_HEIGHT / 2, X + length, Y + font.FONT_HEIGHT / 2)) {
            Gui.drawRect(mouseX, mouseY - (font.FONT_HEIGHT + 4), mouseX + font.getStringWidth(err.error) + 4, mouseY, borderColour);
            Gui.drawRect(mouseX + 1, mouseY - (font.FONT_HEIGHT + 4) + 1, mouseX + font.getStringWidth(err.error) + 4 - 1, mouseY - 1, backgroundColour);
            font.drawString(err.error, mouseX + 2, mouseY - (font.FONT_HEIGHT + 4) + 2, Color.WHITE.getRGB(), true);
        }
    }
    language.reset();
}
Also used : DynamicToken(me.itay.idemodthingy.programs.bluej.api.tokens.DynamicToken) StaticToken(me.itay.idemodthingy.programs.bluej.api.tokens.StaticToken) Token(me.itay.idemodthingy.programs.bluej.api.tokens.Token) DynamicToken(me.itay.idemodthingy.programs.bluej.api.tokens.DynamicToken) StaticToken(me.itay.idemodthingy.programs.bluej.api.tokens.StaticToken)

Aggregations

DynamicToken (me.itay.idemodthingy.programs.bluej.api.tokens.DynamicToken)3 Token (me.itay.idemodthingy.programs.bluej.api.tokens.Token)3 StaticToken (me.itay.idemodthingy.programs.bluej.api.tokens.StaticToken)2 ArrayList (java.util.ArrayList)1 JSKeywordGroup (me.itay.idemodthingy.languages.js.tokens.JSKeywordGroup)1 Problem (me.itay.idemodthingy.programs.bluej.api.Problem)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1