use of javax.swing.text.BadLocationException in project antlrworks by antlr.
the class AutoCompletionMenu method completePartialWord.
public void completePartialWord(String word) {
try {
Document doc = getTextComponent().getDocument();
doc.remove(insertionStartIndex, insertionEndIndex - insertionStartIndex);
doc.insertString(insertionStartIndex, word, null);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
use of javax.swing.text.BadLocationException in project CoreNLP by stanfordnlp.
the class HighlightUtils method addHighlight.
/**
* Highlight the given label from the first mouse event to the second
* Returns true if the highlight was successful, false otherwise.
*/
public static boolean addHighlight(JTextField label, MouseEvent mouseEvent1, MouseEvent mouseEvent2) {
FontMetrics fm = label.getFontMetrics(label.getFont());
int firstXpos = mouseEvent1.getX();
int lastXpos = mouseEvent2.getX();
int firstOffset = getCharOffset(fm, label.getText(), firstXpos);
int lastOffset = getCharOffset(fm, label.getText(), lastXpos);
if (lastOffset != firstOffset) {
if (firstOffset > lastOffset) {
int tmp = firstOffset;
firstOffset = lastOffset;
lastOffset = tmp;
}
try {
label.getHighlighter().removeAllHighlights();
label.getHighlighter().addHighlight(firstOffset, lastOffset, new DefaultHighlighter.DefaultHighlightPainter(Color.yellow));
return true;
} catch (BadLocationException e1) {
return false;
}
} else
return false;
}
use of javax.swing.text.BadLocationException in project binnavi by google.
the class BaseTypeTableCellRenderer method renderStruct.
private static void renderStruct(final TypeInstance instance, final StyledDocument document, final boolean renderData) {
final Style structNameStyle = createDeclarationStyle(document);
final Style structMemberStyle = document.addStyle("STRUCTMEMBERSTYLE", structNameStyle);
StyleConstants.setForeground(structMemberStyle, Color.GRAY);
final Style structContentStyle = document.addStyle("STRUCTCONTENTSTYLE", structNameStyle);
StyleConstants.setForeground(structContentStyle, Color.BLUE);
StyleConstants.setAlignment(structNameStyle, StyleConstants.ALIGN_RIGHT);
final BaseType baseType = instance.getBaseType();
int maxMemberLength = 0;
for (final TypeMember member : baseType) {
if (member.getBaseType().getName().length() > maxMemberLength) {
maxMemberLength = member.getBaseType().getName().length();
}
}
int maxNameLength = 0;
for (final TypeMember member : baseType) {
if (member.getName().length() > maxNameLength) {
maxNameLength = member.getName().length();
}
}
/* Renders type information for structures - construct a string such as:
*
* struct STRUCT_NAME { BASE_TYPE_NAME
*/
try {
document.remove(0, document.getLength());
appendString(document, "struct " + baseType.getName() + " {\n", structNameStyle);
long memberOffset = 0;
for (final TypeMember member : baseType) {
appendString(document, " " + member.getBaseType().getName(), structNameStyle);
final String separator = Strings.repeat(" ", maxMemberLength - member.getBaseType().getName().length() + 1);
appendString(document, separator + member.getName(), structMemberStyle);
appendString(document, ";", structMemberStyle);
if (renderData) {
final String dataSeperator = Strings.repeat(".", maxNameLength - member.getName().length() + 1);
appendString(document, dataSeperator, structNameStyle);
appendString(document, renderInstanceData(member.getBaseType(), instance.getAddress().getOffset() + memberOffset, instance.getSection()), createDataStyle(document));
memberOffset += member.getBaseType().getByteSize();
}
appendString(document, "\n", structMemberStyle);
}
appendString(document, "};", structNameStyle);
} catch (final BadLocationException exception) {
CUtilityFunctions.logException(exception);
}
}
use of javax.swing.text.BadLocationException in project android-classyshark by google.
the class DisplayArea method displayClass.
@Override
public void displayClass(String classString) {
displayDataState = DisplayDataState.INSIDE_CLASS;
try {
String currentText = jTextPane.getDocument().getText(0, jTextPane.getDocument().getLength());
if (currentText.equals(getOneColorFormattedOutput(classString))) {
return;
}
} catch (BadLocationException e) {
e.printStackTrace();
}
clearText();
StyleConstants.setFontSize(style, 18);
Document doc = new DefaultStyledDocument();
try {
doc.insertString(doc.getLength(), getOneColorFormattedOutput(classString), style);
} catch (BadLocationException e) {
e.printStackTrace();
}
jTextPane.setDocument(doc);
jTextPane.setCaretPosition(1);
}
use of javax.swing.text.BadLocationException in project zaproxy by zaproxy.
the class CustomScanDialog method getAddCustomButton.
private JButton getAddCustomButton() {
if (addCustomButton == null) {
addCustomButton = new JButton(Constant.messages.getString("ascan.custom.button.pt.add"));
addCustomButton.setEnabled(false);
addCustomButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
// Add the selected injection point
int userDefStart = getRequestField().getSelectionStart();
if (userDefStart >= 0) {
int userDefEnd = getRequestField().getSelectionEnd();
Highlighter hl = getRequestField().getHighlighter();
HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.RED);
try {
Highlight hlt = (Highlight) hl.addHighlight(userDefStart, userDefEnd, painter);
injectionPointModel.addElement(hlt);
// Unselect the text
getRequestField().setSelectionStart(userDefEnd);
getRequestField().setSelectionEnd(userDefEnd);
getRequestField().getCaret().setVisible(true);
} catch (BadLocationException e1) {
logger.error(e1.getMessage(), e1);
}
}
}
});
}
return addCustomButton;
}
Aggregations