use of javax.swing.text.BadLocationException in project zaproxy by zaproxy.
the class HttpPanelSyntaxHighlightTextArea method highlight.
protected void highlight(int start, int end) {
Highlighter hilite = this.getHighlighter();
HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.LIGHT_GRAY);
try {
// DOBIN
removeAllHighlights();
hilite.addHighlight(start, end, painter);
this.setCaretPosition(start);
} catch (BadLocationException e) {
log.error(e.getMessage(), e);
}
}
use of javax.swing.text.BadLocationException in project pcgen by PCGen.
the class InfoPane method setText.
public void setText(String text) {
//This is done so the vertical scroll bar goes back up to the top when the text is changed
EditorKit kit = textPane.getEditorKit();
Document newDoc = kit.createDefaultDocument();
try {
kit.read(new StringReader(text), newDoc, 0);
} catch (IOException | BadLocationException ex) {
throw new UnreachableError(ex);
}
textPane.setDocument(newDoc);
}
use of javax.swing.text.BadLocationException in project yyl_example by Relucent.
the class Command method registerListener.
private void registerListener() {
txtDebug.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == 8 && execOffset >= doc.getLength()) {
e.setKeyCode(27);
}
if (e.getKeyCode() == 10 && execOffset < doc.getLength()) {
try {
String str = doc.getText(execOffset, doc.getLength() - execOffset);
exec(str + "\n");
} catch (BadLocationException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
public void keyTyped(KeyEvent e) {
// System.out.println(e.getKeyChar());
}
});
doc.addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
}
public void insertUpdate(DocumentEvent e) {
}
public void removeUpdate(DocumentEvent e) {
}
});
txtDebug.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
if (execOffset > caret.getMark() || execOffset > caret.getDot()) {
caret.setDot(execOffset);
}
}
});
}
use of javax.swing.text.BadLocationException in project pcgen by PCGen.
the class NotesView method handleEnter.
private void handleEnter() {
// TODO: this sucks. clean it up
Element elem;
int pos = editor.getCaretPosition();
ExtendedHTMLDocument htmlDoc = (ExtendedHTMLDocument) editor.getStyledDocument();
try {
if (ExtendedHTMLEditorKit.checkParentsTag(htmlDoc.getParagraphElement(editor.getCaretPosition()), HTML.Tag.UL) || ExtendedHTMLEditorKit.checkParentsTag(htmlDoc.getParagraphElement(editor.getCaretPosition()), HTML.Tag.OL)) {
elem = ExtendedHTMLEditorKit.getListItemParent(htmlDoc.getCharacterElement(editor.getCaretPosition()));
int so = elem.getStartOffset();
int eo = elem.getEndOffset();
char[] temp = editor.getText(so, eo - so).toCharArray();
boolean content = false;
for (char aTemp : temp) {
if (!Character.isWhitespace(aTemp)) {
content = true;
}
}
int repos = -1;
if (content) {
int end = -1;
int j = temp.length;
do {
j--;
if (Character.isLetterOrDigit(temp[j])) {
end = j;
}
} while ((end == -1) && (j >= 0));
j = end;
do {
j++;
if (!Character.isSpaceChar(temp[j])) {
repos = j - end - 1;
}
} while ((repos == -1) && (j < temp.length));
if (repos == -1) {
repos = 0;
}
}
if ((elem.getStartOffset() == elem.getEndOffset()) || !content) {
manageListElement(htmlDoc);
} else {
if ((editor.getCaretPosition() + 1) == elem.getEndOffset()) {
ExtendedHTMLEditorKit.insertListElement(editor, "");
editor.setCaretPosition(pos - repos);
} else {
int caret = editor.getCaretPosition();
String tempString = editor.getText(caret, eo - caret);
editor.select(caret, eo - 1);
editor.replaceSelection("");
ExtendedHTMLEditorKit.insertListElement(editor, tempString);
Element newLi = ExtendedHTMLEditorKit.getListItemParent(htmlDoc.getCharacterElement(editor.getCaretPosition()));
editor.setCaretPosition(newLi.getEndOffset());
}
}
}
} catch (BadLocationException ble) {
Logging.errorPrint(ble.getMessage(), ble);
}
}
use of javax.swing.text.BadLocationException in project intellij-community by JetBrains.
the class RequiredAttributesInspection method createOptionsPanel.
@Override
@Nullable
public JComponent createOptionsPanel() {
JPanel panel = new JPanel(new BorderLayout());
FieldPanel additionalAttributesPanel = new FieldPanel(InspectionsBundle.message("inspection.javadoc.html.not.required.label.text"), InspectionsBundle.message("inspection.javadoc.html.not.required.dialog.title"), null, null);
panel.add(additionalAttributesPanel, BorderLayout.NORTH);
additionalAttributesPanel.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
final Document document = e.getDocument();
try {
final String text = document.getText(0, document.getLength());
if (text != null) {
myAdditionalRequiredHtmlAttributes = text.trim();
}
} catch (BadLocationException e1) {
LOG.error(e1);
}
}
});
additionalAttributesPanel.setText(myAdditionalRequiredHtmlAttributes);
return panel;
}
Aggregations