Search in sources :

Example 36 with BadLocationException

use of javax.swing.text.BadLocationException in project binnavi by google.

the class BaseTypeTableCellRenderer method renderText.

public static String renderText(final TypeInstance instance) {
    final StyledDocument document = new DefaultStyledDocument();
    generateDocument(instance, false, document);
    try {
        return document.getText(0, document.getLength());
    } catch (final BadLocationException exception) {
        CUtilityFunctions.logException(exception);
    }
    return "";
}
Also used : DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) StyledDocument(javax.swing.text.StyledDocument) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) BadLocationException(javax.swing.text.BadLocationException)

Example 37 with BadLocationException

use of javax.swing.text.BadLocationException in project binnavi by google.

the class BaseTypeTableCellRenderer method convertDocumentToFormattedCharacterBuffer.

public static FormattedCharacterBuffer convertDocumentToFormattedCharacterBuffer(final StyledDocument document, Font font, int desiredWidth) {
    // The following code calculates the number of rows and the number of columns required for the
    // FormattedCharacterBuffer.
    int width = desiredWidth, height = 0;
    String text = "";
    try {
        text = document.getText(0, document.getLength());
    } catch (BadLocationException e) {
    // Cannot happen.
    }
    String[] chunks = text.split("\n");
    height = chunks.length;
    for (String line : chunks) {
        // The +1 is necessary because we wish to store the newline characters in the
        // FormattedCharacterBuffer.
        width = Math.max(width, line.length() + 1);
    }
    // Height & width is calculated, now create the buffer.
    FormattedCharacterBuffer result = new FormattedCharacterBuffer(height, width);
    int lineindex = 0, columnindex = 0;
    for (int index = 0; index < document.getLength(); ++index) {
        if (text.charAt(index) != '\n') {
            AttributeSet attributes = document.getCharacterElement(index).getAttributes();
            Color foreground = document.getForeground(attributes);
            Color background = document.getBackground(attributes);
            columnindex++;
            result.setAt(lineindex, columnindex, text.charAt(index), font, foreground, background);
        } else {
            columnindex = 0;
            lineindex++;
        }
    }
    return result;
}
Also used : AttributeSet(javax.swing.text.AttributeSet) Color(java.awt.Color) BadLocationException(javax.swing.text.BadLocationException) FormattedCharacterBuffer(com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer)

Example 38 with BadLocationException

use of javax.swing.text.BadLocationException in project binnavi by google.

the class BaseTypeTableCellRenderer method renderAtomic.

private static void renderAtomic(final TypeInstance instance, final StyledDocument document, final boolean renderData) {
    final Style atomicStyle = createDeclarationStyle(document);
    try {
        document.remove(0, document.getLength());
        final BaseType baseType = instance.getBaseType();
        appendString(document, baseType.getName(), atomicStyle);
        if (renderData) {
            appendString(document, renderInstanceData(baseType, instance.getAddress().getOffset(), instance.getSection()), createDataStyle(document));
        }
    } catch (final BadLocationException exception) {
        CUtilityFunctions.logException(exception);
    }
}
Also used : BaseType(com.google.security.zynamics.binnavi.disassembly.types.BaseType) Style(javax.swing.text.Style) BadLocationException(javax.swing.text.BadLocationException)

Example 39 with BadLocationException

use of javax.swing.text.BadLocationException in project binnavi by google.

the class BaseTypeTableCellRenderer method renderPointer.

private static void renderPointer(final TypeInstance instance, final StyledDocument document) {
    final Style pointerStyle = createDeclarationStyle(document);
    try {
        document.remove(0, document.getLength());
        appendString(document, instance.getBaseType().getName(), pointerStyle);
    } catch (final BadLocationException exception) {
        CUtilityFunctions.logException(exception);
    }
}
Also used : Style(javax.swing.text.Style) BadLocationException(javax.swing.text.BadLocationException)

Example 40 with BadLocationException

use of javax.swing.text.BadLocationException in project binnavi by google.

the class BaseTypeTableCellRenderer method renderArray.

private static void renderArray(final TypeInstance instance, final StyledDocument document, final boolean renderData) {
    final Style arrayStyle = createDeclarationStyle(document);
    try {
        document.remove(0, document.getLength());
        final BaseType baseType = instance.getBaseType();
        appendString(document, baseType.getName(), arrayStyle);
        if (renderData) {
            appendString(document, renderInstanceData(baseType, instance.getAddress().getOffset(), instance.getSection()), createDataStyle(document));
        }
    } catch (final BadLocationException exception) {
        CUtilityFunctions.logException(exception);
    }
}
Also used : BaseType(com.google.security.zynamics.binnavi.disassembly.types.BaseType) Style(javax.swing.text.Style) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

BadLocationException (javax.swing.text.BadLocationException)88 Document (javax.swing.text.Document)24 Element (javax.swing.text.Element)13 Point (java.awt.Point)10 IOException (java.io.IOException)9 DefaultHighlighter (javax.swing.text.DefaultHighlighter)8 DefaultStyledDocument (javax.swing.text.DefaultStyledDocument)7 Highlighter (javax.swing.text.Highlighter)7 ArrayList (java.util.ArrayList)6 DocumentEvent (javax.swing.event.DocumentEvent)6 StyledDocument (javax.swing.text.StyledDocument)6 HighlightPainter (javax.swing.text.Highlighter.HighlightPainter)5 Dimension (java.awt.Dimension)4 Rectangle (java.awt.Rectangle)4 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 File (java.io.File)4 Date (java.util.Date)4 Style (javax.swing.text.Style)4 HTMLDocument (javax.swing.text.html.HTMLDocument)4