use of javax.swing.text.BadLocationException in project JMRI by JMRI.
the class JTextPaneAppender method append.
/**
* @see
* org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent)
*/
@Override
public void append(LoggingEvent event) {
if (myTextPane == null) {
LogLog.warn("TextPane is not initialized");
return;
}
// if myTextPane == null
String text = this.layout.format(event);
String[] stackTrace = event.getThrowableStrRep();
if (stackTrace != null) {
StringBuffer sb = new StringBuffer(text);
for (int i = 0; i < stackTrace.length; i++) {
sb.append(" ").append(stackTrace[i]).append("\n");
}
// for i
text = sb.toString();
}
StyledDocument myDoc = myTextPane.getStyledDocument();
try {
myDoc.insertString(myDoc.getLength(), text, myAttributeSet.get(event.getLevel().toString()));
} catch (BadLocationException badex) {
// can't log this, as it would be recursive error
System.err.println(badex);
}
myTextPane.setCaretPosition(myDoc.getLength());
}
use of javax.swing.text.BadLocationException in project jabref by JabRef.
the class JEditorPaneWithHighlighting method highlightPattern.
public void highlightPattern(Optional<Pattern> highlightPattern) {
Highlighter highlighter = getHighlighter();
highlighter.removeAllHighlights();
if ((highlightPattern == null) || !highlightPattern.isPresent()) {
return;
}
String text = getDocumentText();
Matcher matcher = highlightPattern.get().matcher(text);
LayerPainter painter = DefaultHighlighter.DefaultPainter;
while (matcher.find()) {
try {
highlighter.addHighlight(matcher.start(), matcher.end(), painter);
} catch (BadLocationException ble) {
// should not occur if matcher works right
LOGGER.warn("Highlighting not possible, bad location", ble);
}
}
}
use of javax.swing.text.BadLocationException in project jabref by JabRef.
the class JTextAreaWithHighlighting method highLight.
/**
* Highlight words in the Textarea
*
* @param words to highlight
*/
private void highLight() {
// highlight all characters that appear in charsToHighlight
Highlighter highlighter = getHighlighter();
highlighter.removeAllHighlights();
if ((highlightPattern == null) || !highlightPattern.isPresent()) {
return;
}
String content = getText();
if (content.isEmpty()) {
return;
}
highlightPattern.ifPresent(pattern -> {
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
try {
highlighter.addHighlight(matcher.start(), matcher.end(), DefaultHighlighter.DefaultPainter);
} catch (BadLocationException ble) {
LOGGER.warn("Highlighting not possible, bad location", ble);
}
}
});
}
use of javax.swing.text.BadLocationException in project processdash by dtuma.
the class AssignedToDocument method getWords.
public List<Word> getWords() {
List<Word> result = new ArrayList();
try {
Word prev = null;
Matcher m = wordPattern.matcher(getText(0, getLength()));
while (m.find()) {
Word w = new Word();
w.beg = m.start();
w.end = m.end();
w.letters = m.start(1) != -1;
w.prev = prev;
if (prev != null)
prev.next = w;
result.add(w);
prev = w;
}
} catch (BadLocationException ble) {
}
return result;
}
use of javax.swing.text.BadLocationException in project gephi by gephi.
the class FileCompletionPopup method keyPressed.
/****** implementation of KeyListener of fileNameTextField ******/
@Override
public void keyPressed(KeyEvent e) {
if (!isVisible()) {
return;
}
int code = e.getKeyCode();
switch(code) {
case KeyEvent.VK_DOWN:
setSelectNext();
e.consume();
break;
case KeyEvent.VK_UP:
setSelectPrevious();
e.consume();
break;
case KeyEvent.VK_ESCAPE:
setVisible(false);
textField.requestFocus();
e.consume();
break;
}
if (isCompletionKey(code, textField)) {
File file = (File) list.getSelectedValue();
if (file != null) {
if (file.equals(chooser.getCurrentDirectory())) {
chooser.firePropertyChange(JFileChooser.DIRECTORY_CHANGED_PROPERTY, false, true);
} else {
chooser.setSelectedFiles(new File[] { file });
chooser.setCurrentDirectory(file);
}
if (file.isDirectory()) {
try {
Document doc = textField.getDocument();
doc.insertString(doc.getLength(), File.separator, null);
} catch (BadLocationException ex) {
Logger.getLogger(getClass().getName()).log(Level.FINE, "Cannot append directory separator.", ex);
}
}
}
setVisible(false);
textField.requestFocus();
e.consume();
}
}
Aggregations