Example usage for javax.swing.text StyledDocument putProperty

List of usage examples for javax.swing.text StyledDocument putProperty

Introduction

In this page you can find the example usage for javax.swing.text StyledDocument putProperty.

Prototype

public void putProperty(Object key, Object value);

Source Link

Document

Associates a property with the document.

Usage

From source file:de.codesourcery.jasm16.ide.ui.views.CPUView.java

private void internalRefreshDisplay() {
    if (emulator == null) {
        return;//from   w w w. ja v  a 2 s.c o m
    }
    final IReadOnlyCPU cpu = emulator.getCPU();

    final StringBuilder builder = new StringBuilder();
    final List<ITextRegion> redRegions = new ArrayList<ITextRegion>();

    Throwable lastError = emulator.getLastEmulationError();
    if (lastError != null) {
        final String msg = StringUtils.isBlank(lastError.getMessage()) ? lastError.getClass().getName()
                : lastError.getMessage();
        builder.append("Emulation stopped with an error: " + msg + "\n");
        redRegions.add(new TextRegion(0, builder.length()));
    }

    int itemsInLine = 0;
    for (int i = 0; i < ICPU.COMMON_REGISTER_NAMES.length; i++) {
        final int value = cpu.getRegisterValue(ICPU.COMMON_REGISTERS[i]);
        builder.append(ICPU.COMMON_REGISTER_NAMES[i] + ": " + Misc.toHexString(value) + "    ");

        Address address = Address.wordAddress(value);
        final byte[] data = MemUtils.getBytes(emulator.getMemory(), address, Size.words(4), true);

        builder.append(Misc.toHexDump(address, data, data.length, 4, true, false, true));
        builder.append("\n");
        itemsInLine++;
        if (itemsInLine == 4) {
            itemsInLine = 0;
            builder.append("\n");
        }
    }
    builder.append("\nPC: " + Misc.toHexString(cpu.getPC().getValue()));
    builder.append(" (elapsed cycles: " + cpu.getCurrentCycleCount()).append(")");
    builder.append("\n");

    builder.append("EX: " + Misc.toHexString(cpu.getEX())).append("\n");
    builder.append("IA: " + Misc.toHexString(cpu.getInterruptAddress())).append("\n");

    builder.append("IQ: Interrupt queueing is ");
    if (cpu.isQueueInterrupts()) {
        int start = builder.length();
        builder.append("ON");
        redRegions.add(new TextRegion(start, builder.length() - start));
    } else {
        builder.append("OFF");
    }
    builder.append("\n");
    builder.append("IRQs: " + StringUtils.join(cpu.getInterruptQueue(), ",")).append("\n");
    builder.append("SP: " + Misc.toHexString(cpu.getSP().getValue())).append("\n");

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            final StyledDocument doc = textArea.getStyledDocument();
            doc.putProperty(Document.StreamDescriptionProperty, null);

            textArea.setText(builder.toString());
            for (ITextRegion region : redRegions) {
                doc.setCharacterAttributes(region.getStartingOffset(), region.getLength(), errorStyle, true);
            }
        }
    });
}