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;
}
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);
}
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;
}
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());
}
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;
}
Aggregations