use of javax.swing.text.StyledDocument 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.StyledDocument 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.StyledDocument in project groovy-core by groovy.
the class ConsoleSupport method addStylesToDocument.
protected void addStylesToDocument(JTextPane outputArea) {
StyledDocument doc = outputArea.getStyledDocument();
Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
Style regular = doc.addStyle("regular", def);
StyleConstants.setFontFamily(def, "Monospaced");
promptStyle = doc.addStyle("prompt", regular);
StyleConstants.setForeground(promptStyle, Color.BLUE);
commandStyle = doc.addStyle("command", regular);
StyleConstants.setForeground(commandStyle, Color.MAGENTA);
outputStyle = doc.addStyle("output", regular);
StyleConstants.setBold(outputStyle, true);
}
use of javax.swing.text.StyledDocument in project groovy by apache.
the class ConsoleSupport method addStylesToDocument.
protected void addStylesToDocument(JTextPane outputArea) {
StyledDocument doc = outputArea.getStyledDocument();
Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
Style regular = doc.addStyle("regular", def);
StyleConstants.setFontFamily(def, "Monospaced");
promptStyle = doc.addStyle("prompt", regular);
StyleConstants.setForeground(promptStyle, Color.BLUE);
commandStyle = doc.addStyle("command", regular);
StyleConstants.setForeground(commandStyle, Color.MAGENTA);
outputStyle = doc.addStyle("output", regular);
StyleConstants.setBold(outputStyle, true);
}
use of javax.swing.text.StyledDocument in project enclojure by EricThorsen.
the class ClojureCodeCompletionItem method doSubstitute.
private void doSubstitute(final JTextComponent component, final String toAdd, final int backOffset) {
final StyledDocument doc = (StyledDocument) component.getDocument();
class AtomicChange implements Runnable {
public void run() {
int caretOffset = component.getCaretPosition();
String cname = component.getClass().getName();
Boolean _isReplPanel = false;
if (cname.equals("javax.swing.JEditorPane"))
_isReplPanel = true;
String value = getText();
String javaList = "";
if (toAdd != null) {
value += toAdd;
}
try {
String c = component.getText(caretOffset - 1, 1);
if (//java package containing the Class at the end
!_isClojure && _isNamespaceOrPkg) {
value = setValueForClass(value, component);
javaList = getJavaImportListStr(value);
if ((javaList.contains("(")) && (!_isReplPanel)) {
int messageret = (JOptionPane.showConfirmDialog(component, "Do you want to add the import " + value + " to your ns imports?", "add import ?", 0));
if (messageret == 0) {
PersistentArrayMap entry = addImportList(component, javaList);
//component.setCaretPosition(caretOffset + javaList.length());
value = getClassPart(value);
if (entry != null) {
String origNS = (String) entry.get(Keyword.intern(Symbol.create("orignodestr")));
String newNS = (String) entry.get(Keyword.intern(Symbol.create("newnodestr")));
int insertOffset = newNS.length() - origNS.length();
_carretOffset = _carretOffset + insertOffset;
_dotOffset = _dotOffset + insertOffset;
}
}
}
}
if (!c.equals("/") && (_layout != backSlashAfterParen) && (_layout != backSlashNoParen)) {
switch(_layout) {
case LowercaseAfterParen:
doc.remove(_dotOffset, _carretOffset - _dotOffset);
break;
case UppercaseAfterParen:
doc.remove(_dotOffset, _carretOffset - _dotOffset);
break;
case UppercaseAfterParenWithDot:
if (//java method
_isMethodOrFunction && (!_isClojure)) {
if (_isConstructor) {
value = "";
} else if (Character.isLetter(value.charAt(0))) {
{
doc.remove(_dotOffset, _carretOffset - _dotOffset);
value = "." + value;
}
}
} else
doc.remove(_dotOffset, _carretOffset - _dotOffset);
break;
case LowercaseAfterParenWithDot:
if (//java method
_isMethodOrFunction && (!_isClojure)) {
if (_isConstructor) {
value = "";
} else if (Character.isLetter(value.charAt(0))) {
{
doc.remove(_dotOffset, _carretOffset - _dotOffset);
value = "." + value;
}
}
} else
doc.remove(_dotOffset, _carretOffset - _dotOffset);
break;
case backSlashAfterParen:
doc.remove(_dotOffset, _carretOffset - _dotOffset);
break;
case FirstDotAfterParen:
doc.remove(_dotOffset, _carretOffset - _dotOffset);
break;
case FirstDotNoParen:
doc.remove(_dotOffset, _carretOffset - _dotOffset);
break;
case UppercaseNoParen:
doc.remove(_dotOffset, _carretOffset - _dotOffset);
break;
case UppercaseNoParenWithDot:
if (//java method
_isMethodOrFunction && (!_isClojure)) {
if (_isConstructor) {
value = "";
} else if (Character.isLetter(value.charAt(0))) {
{
doc.remove(_dotOffset, _carretOffset - _dotOffset);
value = "." + value;
}
}
} else
doc.remove(_dotOffset, _carretOffset - _dotOffset);
break;
case LowercaseNoParenWithDot:
if (//java method
_isMethodOrFunction && (!_isClojure)) {
if (_isConstructor) {
value = "";
} else if (Character.isLetter(value.charAt(0))) {
{
doc.remove(_dotOffset, _carretOffset - _dotOffset);
value = "." + value;
}
}
} else
doc.remove(_dotOffset, _carretOffset - _dotOffset);
break;
case LowercaseNoParen:
doc.remove(_dotOffset, _carretOffset - _dotOffset);
break;
}
doc.insertString(_dotOffset, value, null);
} else {
if (!c.equals("/")) {
int backSlashOffset = indexOfBackSlash(component);
if (backSlashOffset == -1)
backSlashOffset = caretOffset;
if (_isStatic || _layout == backSlashAfterParen || _layout == backSlashNoParen) {
if (_isClojure && _isMethodOrFunction) {
if (isInCurrentNamespace(_fullclassname, component)) {
doc.remove(_dotOffset, _carretOffset - _dotOffset);
doc.insertString(_dotOffset, setValue(value), null);
} else {
doc.remove(backSlashOffset + 1, caretOffset - backSlashOffset - 1);
doc.insertString(backSlashOffset + 1, value, null);
}
} else {
doc.remove(backSlashOffset + 1, caretOffset - backSlashOffset - 1);
doc.insertString(backSlashOffset + 1, value, null);
}
} else {
doc.remove(_dotOffset, _carretOffset - _dotOffset);
doc.insertString(_dotOffset, setValue(value), null);
}
} else if (_isStatic || _layout == backSlashAfterParen || _layout == backSlashNoParen)
if (_isClojure && _isMethodOrFunction) {
if (isInCurrentNamespace(_fullclassname, component)) {
doc.remove(_dotOffset, _carretOffset - _dotOffset);
doc.insertString(_dotOffset, setValue(value), null);
} else
doc.insertString(_carretOffset, value, null);
} else
doc.insertString(_carretOffset, value, null);
else {
doc.remove(_dotOffset, _carretOffset - _dotOffset);
doc.insertString(_dotOffset, setValue(value), null);
}
}
component.setCaretPosition(component.getCaretPosition() - backOffset);
} catch (BadLocationException e) {
LOG.log(Level.FINEST, e.getMessage());
}
}
}
AtomicChange change = new AtomicChange();
try {
NbDocument.runAtomicAsUser(doc, change);
} catch (BadLocationException ex) {
LOG.log(Level.FINEST, ex.getMessage());
}
}
Aggregations