use of javax.swing.text.SimpleAttributeSet in project vcell by virtualcell.
the class SimulationConsolePanel method appendToConsole.
private void appendToConsole(TaskCallbackMessage newCallbackMessage) {
TaskCallbackStatus status = newCallbackMessage.getStatus();
String string = newCallbackMessage.getText();
StyledDocument doc = netGenConsoleText.getStyledDocument();
SimpleAttributeSet keyWord = new SimpleAttributeSet();
try {
switch(status) {
case // clean console, display task initialization message
Clean:
netGenConsoleText.setText("");
break;
case TaskStopped:
StyleConstants.setForeground(keyWord, Color.RED);
StyleConstants.setBold(keyWord, true);
doc.insertString(doc.getLength(), " " + string + "\n", keyWord);
break;
case // normal notification, just display the string
Notification:
doc.insertString(doc.getLength(), string + "\n", null);
break;
case // display this in red, bold
Error:
StyleConstants.setForeground(keyWord, Color.RED);
StyleConstants.setBold(keyWord, true);
doc.insertString(doc.getLength(), string + "\n", keyWord);
break;
case // display this in red
Warning:
StyleConstants.setForeground(keyWord, Color.RED);
doc.insertString(doc.getLength(), string + "\n", keyWord);
break;
default:
break;
}
} catch (Exception e) {
System.out.println(e);
}
}
use of javax.swing.text.SimpleAttributeSet in project n2a by frothga.
the class TextPaneANSI method append.
public void append(String t) {
int count = t.length();
SimpleAttributeSet attributes = new SimpleAttributeSet();
for (int b = 0; b < count; b++) {
int e = t.indexOf(27, b);
if (e < 0) {
append(t.substring(b), attributes);
break;
}
// There is some text to append.
if (b < e)
append(t.substring(b, e), attributes);
// no more text left
if (e >= count)
break;
// Find end of escape sequence.
e++;
b = t.indexOf('m', e);
// escape sequence cut off by end of string
if (b < 0)
break;
// Does not include initial ESC or ending m.
String sequence = t.substring(e, b);
if (sequence.startsWith("[")) {
String[] codes = sequence.substring(1).split(";");
for (int i = 0; i < codes.length; i++) {
String code = codes[i];
switch(code) {
case "0":
attributes.removeAttributes(attributes);
break;
case "1":
attributes.addAttribute(StyleConstants.Bold, true);
break;
case "3":
attributes.addAttribute(StyleConstants.Italic, true);
break;
case "4":
attributes.addAttribute(StyleConstants.Underline, true);
break;
case "9":
attributes.addAttribute(StyleConstants.StrikeThrough, true);
break;
case "22":
attributes.removeAttribute(StyleConstants.Bold);
break;
case "23":
attributes.removeAttribute(StyleConstants.Italic);
break;
case "24":
attributes.removeAttribute(StyleConstants.Underline);
break;
case "29":
attributes.removeAttribute(StyleConstants.StrikeThrough);
break;
case "30":
attributes.addAttribute(StyleConstants.Foreground, Color.black);
break;
case "31":
attributes.addAttribute(StyleConstants.Foreground, Color.red);
break;
case "32":
attributes.addAttribute(StyleConstants.Foreground, Color.green);
break;
case "33":
attributes.addAttribute(StyleConstants.Foreground, yellow80);
break;
case "34":
attributes.addAttribute(StyleConstants.Foreground, Color.blue);
break;
case "35":
attributes.addAttribute(StyleConstants.Foreground, Color.magenta);
break;
case "36":
attributes.addAttribute(StyleConstants.Foreground, Color.cyan);
break;
case "37":
attributes.addAttribute(StyleConstants.Foreground, Color.white);
break;
case "38":
i++;
if (codes[i] == "2") {
i++;
Color c = interpretRGB(codes, i);
attributes.addAttribute(StyleConstants.Foreground, c);
i += 2;
} else if (codes[i] == "5") {
i++;
Color c = interpret256(codes[i]);
attributes.addAttribute(StyleConstants.Foreground, c);
}
break;
case "39":
attributes.removeAttribute(StyleConstants.Foreground);
break;
case "40":
attributes.addAttribute(StyleConstants.Background, Color.black);
break;
case "41":
attributes.addAttribute(StyleConstants.Background, Color.red);
break;
case "42":
attributes.addAttribute(StyleConstants.Background, Color.green);
break;
case "43":
attributes.addAttribute(StyleConstants.Background, Color.yellow);
break;
case "44":
attributes.addAttribute(StyleConstants.Background, Color.blue);
break;
case "45":
attributes.addAttribute(StyleConstants.Background, Color.magenta);
break;
case "46":
attributes.addAttribute(StyleConstants.Background, Color.cyan);
break;
case "47":
attributes.addAttribute(StyleConstants.Background, Color.white);
break;
case "48":
i++;
if (codes[i] == "2") {
i++;
Color c = interpretRGB(codes, i);
attributes.addAttribute(StyleConstants.Background, c);
i += 2;
} else if (codes[i] == "5") {
i++;
Color c = interpret256(codes[i]);
attributes.addAttribute(StyleConstants.Background, c);
}
break;
case "49":
attributes.removeAttribute(StyleConstants.Background);
break;
}
}
}
}
}
use of javax.swing.text.SimpleAttributeSet in project omegat by omegat-org.
the class FontFallbackMarker method getAttributes.
private AttributeSet getAttributes(Font font) {
MutableAttributeSet attrs = new SimpleAttributeSet();
StyleConstants.setFontFamily(attrs, font.getFamily());
StyleConstants.setFontSize(attrs, editorFont.getSize());
return attrs;
}
use of javax.swing.text.SimpleAttributeSet in project omegat by omegat-org.
the class DefaultGlossaryRenderer method render.
@Override
public void render(GlossaryEntry entry, IRenderTarget<?> trg) {
trg.append(entry.getSrcText(), SOURCE_ATTRIBUTES);
trg.append(" = ");
String[] targets = entry.getLocTerms(false);
String[] comments = entry.getComments();
boolean[] priorities = entry.getPriorities();
String[] origins = entry.getOrigins(false);
StringBuilder commentsBuf = new StringBuilder();
for (int i = 0, commentIndex = 0; i < targets.length; i++) {
if (i > 0 && targets[i].equals(targets[i - 1])) {
if (!comments[i].equals("")) {
commentsBuf.append("\n");
commentsBuf.append(commentIndex);
commentsBuf.append(". ");
commentsBuf.append(comments[i]);
}
continue;
}
SimpleAttributeSet attrs = new SimpleAttributeSet(TARGET_ATTRIBUTES);
if (i > 0) {
trg.append(", ", attrs);
}
if (priorities[i]) {
StyleConstants.setBold(attrs, true);
}
attrs.addAttribute(TooltipAttribute.ATTRIBUTE_KEY, new TooltipAttribute(origins[i]));
trg.append(bracketEntry(targets[i]), attrs);
commentIndex++;
if (!comments[i].equals("")) {
commentsBuf.append("\n");
commentsBuf.append(commentIndex);
commentsBuf.append(". ");
commentsBuf.append(comments[i]);
}
}
trg.append(commentsBuf.toString(), NOTES_ATTRIBUTES);
}
use of javax.swing.text.SimpleAttributeSet in project omegat by omegat-org.
the class FontFallbackListener method getAttributes.
private AttributeSet getAttributes(Font font) {
MutableAttributeSet attrs = new SimpleAttributeSet();
StyleConstants.setFontFamily(attrs, font.getFamily());
StyleConstants.setFontSize(attrs, defaultFont.getSize());
return attrs;
}
Aggregations