<commit_before>package hypercard.gui.window;

import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import hypercard.gui.HyperCardWindow;
import hypercard.HyperCard;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class MessageWindow extends HyperCardWindow {

    private JTextField messageBox;
    private JPanel messageWindow;

    public MessageWindow() {
        messageBox.addKeyListener(new KeyAdapter() {
            @Override
            public void keyTyped(KeyEvent e) {
                if (e.getKeyChar() == '\n') {
                    executeMessageBox();
                }
            }
        });
    }

    @Override
    public JPanel getWindowPanel() {
        return messageWindow;
    }

    @Override
    public void bindModel(Object data) {
        // Nothing to do
    }

    public void setMsgBoxText(String text) {
        messageBox.setText(text);
    }

    public String getMsgBoxText() {
        return messageBox.getText();
    }

    private void executeMessageBox() {
        HyperCard.getInstance().doMsgBoxText();
    }

    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        messageWindow = new JPanel();
        messageWindow.setLayout(new GridLayoutManager(1, 1, new Insets(10, 10, 10, 10), -1, -1));
        messageWindow.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), null));
        messageBox = new JTextField();
        messageBox.setFont(new Font("Monaco", messageBox.getFont().getStyle(), messageBox.getFont().getSize()));
        messageWindow.add(messageBox, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(600, 25), null, 0, false));
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return messageWindow;
    }
}
<commit_msg>Squiggle-painted message box syntax errors<commit_after>package hypercard.gui.window;

import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import hypercard.gui.HyperCardWindow;
import hypercard.HyperCard;
import hypercard.gui.util.SquigglePainter;
import hypercard.runtime.Interpreter;
import hypertalk.exception.HtException;

import javax.swing.*;
import javax.swing.text.BadLocationException;
import javax.swing.text.Highlighter;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class MessageWindow extends HyperCardWindow {

    private final static Highlighter.HighlightPainter ERROR_HIGHLIGHTER = new SquigglePainter(Color.RED);

    private JTextField messageBox;
    private JPanel messageWindow;

    public MessageWindow() {
        messageBox.addKeyListener(new KeyAdapter() {
            @Override
            public void keyTyped(KeyEvent e) {
                if (e.getKeyChar() == '\n') {
                    executeMessageBox();
                } else {
                    checkSyntax();
                }
            }
        });
    }

    private void checkSyntax() {
        try {
            Interpreter.compile(messageBox.getText());
            messageBox.getHighlighter().removeAllHighlights();
        } catch (HtException e) {
            squiggleHighlight();
        }
    }

    private void squiggleHighlight() {
        try {
            messageBox.getHighlighter().addHighlight(0, messageBox.getText().length(), ERROR_HIGHLIGHTER);
        } catch (BadLocationException e1) {
            // Nothing to do
        }
    }

    @Override
    public JPanel getWindowPanel() {
        return messageWindow;
    }

    @Override
    public void bindModel(Object data) {
        // Nothing to do
    }

    public void setMsgBoxText(String text) {
        messageBox.setText(text);
    }

    public String getMsgBoxText() {
        return messageBox.getText();
    }

    private void executeMessageBox() {
        HyperCard.getInstance().doMsgBoxText();
    }

    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        messageWindow = new JPanel();
        messageWindow.setLayout(new GridLayoutManager(1, 1, new Insets(10, 10, 10, 10), -1, -1));
        messageWindow.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), null));
        messageBox = new JTextField();
        messageBox.setFont(new Font("Monaco", messageBox.getFont().getStyle(), messageBox.getFont().getSize()));
        messageWindow.add(messageBox, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(600, 25), null, 0, false));
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return messageWindow;
    }
}

{'fraction_non_alphanumeric': 0.1118456315883509, 'fraction_numerical': 0.008218688583169554, 'mean_word_length': 2.7419786096256686, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3222436', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1597, 'n_words': 362}