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