Search in sources :

Example 1 with FormattedCharacterBuffer

use of com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer in project binnavi by google.

the class TypeInstanceTableDatamodel method generateFormattedComment.

private static FormattedCharacterBuffer generateFormattedComment(final List<IComment> comments) {
    // Calculate the number of rows that will be needed.
    int numberOfRows = 0;
    for (final IComment comment : comments) {
        final CommentContainer commentContainer = new CommentContainer(comment);
        final List<String> commentFragments = commentContainer.getCommentingString();
        numberOfRows += commentFragments.size();
    }
    // Generate and fill the buffer.
    FormattedCharacterBuffer result = new FormattedCharacterBuffer(numberOfRows + 1, columns[COMMENTS_INDEX].getWidth());
    int lineIndex = 0;
    int columnIndex = 0;
    for (final IComment comment : comments) {
        final CommentContainer commentContainer = new CommentContainer(comment);
        final List<String> commentFragments = commentContainer.getCommentingString();
        for (final String commentFragment : commentFragments) {
            for (int i = 0; i < commentFragment.length(); i++) {
                result.setAt(lineIndex, columnIndex, commentFragment.charAt(i), STANDARD_FONT, Color.BLACK, Color.WHITE);
                columnIndex++;
            }
            columnIndex = 0;
            lineIndex++;
        }
    }
    return result;
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CommentContainer(com.google.security.zynamics.binnavi.ZyGraph.Builders.CommentContainer) FormattedCharacterBuffer(com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer)

Example 2 with FormattedCharacterBuffer

use of com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer in project binnavi by google.

the class TypeInstanceTableDatamodel method addTypeToDisplay.

private void addTypeToDisplay(TypeInstance instance) {
    // Add the instance to be displayed.
    typesToDisplay.add(instance);
    // Add the rendering of the type declaration.
    FormattedCharacterBuffer typeRendering = BaseTypeTableCellRenderer.renderType(instance, STANDARD_FONT, columns[TYPE_INDEX].getWidth(), false);
    typeDeclarations.add(typeRendering);
    // Calculate how many lines this type occupies.
    int typeRenderingHeight = typeRendering.getNumberOfLines();
    int numberOfReferences = typeContainer.getReferenceCount(instance);
    currentNumberOfLines += Math.max(typeRenderingHeight, numberOfReferences);
}
Also used : FormattedCharacterBuffer(com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer)

Example 3 with FormattedCharacterBuffer

use of com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer in project binnavi by google.

the class TypeInstanceTableDatamodel method getLineFormatted.

@Override
public FormattedCharacterBuffer getLineFormatted(int rowIndex, int columnIndex, int lineIndex) {
    Color backgroundColor = getBackgroundColor(rowIndex, columnIndex);
    switch(columnIndex) {
        case ADDRESS_INDEX:
            TypeInstance type = typesToDisplay.get(rowIndex);
            String addressString = "";
            if (lineIndex == 0) {
                addressString = TypeInstanceAddressTableCellRenderer.getStringToDisplay(false, type.getAddress());
            }
            return stringToFormattedCharacterBuffer(addressString, rowIndex, columnIndex);
        case NAME_INDEX:
            String typeName = "";
            if (lineIndex == 0) {
                typeName = typesToDisplay.get(rowIndex).getName();
            }
            return new FormattedCharacterBuffer(Strings.padEnd(typeName, columns[columnIndex].getWidth(), ' '), STANDARD_FONT, columns[columnIndex].getDefaultFontColor(), backgroundColor);
        case TYPE_INDEX:
            FormattedCharacterBuffer typeDeclaration = typeDeclarations.get(rowIndex);
            if (typeDeclaration.getNumberOfLines() > lineIndex) {
                return typeDeclarations.get(rowIndex).getLine(lineIndex).setBackgroundColor(backgroundColor);
            }
            return stringToFormattedCharacterBuffer("", rowIndex, columnIndex);
        case XREFS_INDEX:
            TypeInstanceReference reference = getTypeInstanceReference(rowIndex, lineIndex);
            String xrefString = "";
            if (reference != null) {
                xrefString = TypeInstanceCrossReferenceRenderer.renderText(reference);
            }
            return stringToFormattedCharacterBuffer(xrefString, rowIndex, columnIndex);
        case COMMENTS_INDEX:
            FormattedCharacterBuffer comment = generateFormattedComment(typeContainer.getComments(typesToDisplay.get(rowIndex)));
            if (lineIndex < comment.getNumberOfLines()) {
                // wasteful, clean it up eventually.
                return comment.getLine(lineIndex).setBackgroundColor(backgroundColor);
            }
            // Return empty buffers for empty lines.
            return stringToFormattedCharacterBuffer("", rowIndex, columnIndex);
        default:
            Logger.warning("Invalid column index, investigate.");
            break;
    }
    return null;
}
Also used : TypeInstanceReference(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceReference) Color(java.awt.Color) TypeInstance(com.google.security.zynamics.binnavi.disassembly.types.TypeInstance) FormattedCharacterBuffer(com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer)

Example 4 with FormattedCharacterBuffer

use of com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer in project binnavi by google.

the class InstructionCommentsDataModel method getCommentUserCharacterBuffer.

private FormattedCharacterBuffer getCommentUserCharacterBuffer(int rowIndex, int columnIndex, int lineIndex) {
    // Return the user string associated with the comment.
    ArrayList<IComment> comments = internalData.get(rowIndex).second();
    int currentLineIndex = 0;
    String username = "";
    for (IComment comment : comments) {
        if ((currentLineIndex + comment.getNumberOfCommentLines() > lineIndex) && (currentLineIndex == lineIndex)) {
            // Found the right comment.
            String temp = comment.getUser().getUserName();
            if (temp != null) {
                username = temp;
            }
            break;
        }
        currentLineIndex += comment.getNumberOfCommentLines();
    }
    username = CodeDisplay.padRight(username, getColumnWidthInCharacters(columnIndex));
    return new FormattedCharacterBuffer(username, STANDARD_FONT, columns[USER_INDEX].getDefaultFontColor(), columns[USER_INDEX].getDefaultBackgroundColor());
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) FormattedCharacterBuffer(com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer)

Example 5 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