Search in sources :

Example 41 with SimpleAttributeSet

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);
    }
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) StyledDocument(javax.swing.text.StyledDocument) TaskCallbackStatus(cbit.vcell.mapping.TaskCallbackMessage.TaskCallbackStatus)

Example 42 with SimpleAttributeSet

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;
                }
            }
        }
    }
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) Color(java.awt.Color)

Example 43 with SimpleAttributeSet

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;
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) MutableAttributeSet(javax.swing.text.MutableAttributeSet)

Example 44 with SimpleAttributeSet

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);
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) TooltipAttribute(org.omegat.util.gui.TooltipAttribute)

Example 45 with SimpleAttributeSet

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;
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) MutableAttributeSet(javax.swing.text.MutableAttributeSet)

Aggregations

SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)58 StyledDocument (javax.swing.text.StyledDocument)11 BadLocationException (javax.swing.text.BadLocationException)8 MutableAttributeSet (javax.swing.text.MutableAttributeSet)7 HTMLDocument (javax.swing.text.html.HTMLDocument)5 Color (java.awt.Color)3 AttributeSet (javax.swing.text.AttributeSet)3 View (javax.swing.text.View)3 HTML (javax.swing.text.html.HTML)3 User (lib.pircbot.User)3 Font (java.awt.Font)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 URL (java.net.URL)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Document (javax.swing.text.Document)2 Test (org.junit.Test)2 TaskCallbackStatus (cbit.vcell.mapping.TaskCallbackMessage.TaskCallbackStatus)1 ColorSet (com.android.tools.sherpa.drawing.ColorSet)1