Search in sources :

Example 6 with FormattedCharacterBuffer

use of com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer 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)

Aggregations

FormattedCharacterBuffer (com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer)6 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)3 Color (java.awt.Color)2 CommentContainer (com.google.security.zynamics.binnavi.ZyGraph.Builders.CommentContainer)1 TypeInstance (com.google.security.zynamics.binnavi.disassembly.types.TypeInstance)1 TypeInstanceReference (com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceReference)1 Pair (com.google.security.zynamics.zylib.general.Pair)1 CodeDisplayCoordinate (com.google.security.zynamics.zylib.gui.CodeDisplay.CodeDisplayCoordinate)1 AttributeSet (javax.swing.text.AttributeSet)1 BadLocationException (javax.swing.text.BadLocationException)1