Search in sources :

Example 36 with SimpleAttributeSet

use of javax.swing.text.SimpleAttributeSet in project pcgen by PCGen.

the class ExtendedHTMLEditorKit method removeTag.

/**
     * Remove a tag
     * @param pane
     * @param element
     * @param closingTag
     */
public static void removeTag(JTextPane pane, Element element, boolean closingTag) {
    if (element == null) {
        return;
    }
    HTML.Tag tag = getHTMLTag(element);
    // Versieht den Tag mit einer einmaligen ID
    String source = pane.getText();
    boolean hit;
    String idString;
    int counter = 0;
    do {
        hit = false;
        idString = "diesisteineidzumsuchenimsource" + counter;
        if (source.contains(idString)) {
            counter++;
            hit = true;
            if (counter > 10000) {
                return;
            }
        }
    } while (hit);
    SimpleAttributeSet sa = new SimpleAttributeSet(element.getAttributes());
    sa.addAttribute("id", idString);
    ((ExtendedHTMLDocument) pane.getStyledDocument()).replaceAttributes(element, sa, tag);
    source = pane.getText();
    StringBuilder newHtmlString = new StringBuilder();
    int[] position = getPositions(element, source, closingTag, idString);
    if (position == null) {
        return;
    }
    for (final int aPosition : position) {
        if (aPosition < 0) {
            return;
        }
    }
    int beginStartTag = position[0];
    int endStartTag = position[1];
    if (closingTag) {
        int beginEndTag = position[2];
        int endEndTag = position[3];
        newHtmlString.append(source.substring(0, beginStartTag));
        newHtmlString.append(source.substring(endStartTag, beginEndTag));
        newHtmlString.append(source.substring(endEndTag, source.length()));
    } else {
        newHtmlString.append(source.substring(0, beginStartTag));
        newHtmlString.append(source.substring(endStartTag, source.length()));
    }
    pane.setText(newHtmlString.toString());
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) HTML(javax.swing.text.html.HTML)

Example 37 with SimpleAttributeSet

use of javax.swing.text.SimpleAttributeSet in project jdk8u_jdk by JetBrains.

the class DocumentParser method handleStartTag.

/**
     * Handle Start Tag.
     */
protected void handleStartTag(TagElement tag) {
    Element elem = tag.getElement();
    if (elem == dtd.body) {
        inbody++;
    } else if (elem == dtd.html) {
    } else if (elem == dtd.head) {
        inhead++;
    } else if (elem == dtd.title) {
        intitle++;
    } else if (elem == dtd.style) {
        instyle++;
    } else if (elem == dtd.script) {
        inscript++;
    }
    if (debugFlag) {
        if (tag.fictional()) {
            debug("Start Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
        } else {
            debug("Start Tag: " + tag.getHTMLTag() + " attributes: " + getAttributes() + " pos: " + getCurrentPos());
        }
    }
    if (tag.fictional()) {
        SimpleAttributeSet attrs = new SimpleAttributeSet();
        attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED, Boolean.TRUE);
        callback.handleStartTag(tag.getHTMLTag(), attrs, getBlockStartPosition());
    } else {
        callback.handleStartTag(tag.getHTMLTag(), getAttributes(), getBlockStartPosition());
        flushAttributes();
    }
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet)

Example 38 with SimpleAttributeSet

use of javax.swing.text.SimpleAttributeSet in project pcgen by PCGen.

the class NotesView method colorButtonActionPerformed.

//GEN-LAST:event_leftJustifyButtonActionPerformed
private void colorButtonActionPerformed() {
    //GEN-FIRST:event_colorButtonActionPerformed
    AttributeSet as = editor.getCharacterAttributes();
    SimpleAttributeSet sas = new SimpleAttributeSet(as);
    Color newColor = JColorChooser.showDialog(GMGenSystem.inst, "Choose Text Color", editor.getStyledDocument().getForeground(as));
    if (newColor != null) {
        StyleConstants.setForeground(sas, newColor);
        editor.setCharacterAttributes(sas, true);
    }
    editor.repaint();
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) AttributeSet(javax.swing.text.AttributeSet) SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) Color(java.awt.Color)

Example 39 with SimpleAttributeSet

use of javax.swing.text.SimpleAttributeSet in project litiengine by gurkenlabs.

the class ConsoleLogHandler method publish.

@Override
public void publish(final LogRecord record) {
    StyledDocument doc = textPane.getStyledDocument();
    SimpleAttributeSet keyWord = new SimpleAttributeSet();
    StyleConstants.setForeground(keyWord, getColor(record.getLevel()));
    StyleConstants.setBold(keyWord, true);
    StyleConstants.setFontSize(keyWord, 12);
    StyleConstants.setFontFamily(keyWord, CONSOLE_FONT);
    SimpleAttributeSet text = new SimpleAttributeSet();
    StyleConstants.setForeground(text, getColor(record.getLevel()));
    StyleConstants.setFontFamily(text, CONSOLE_FONT);
    try {
        doc.insertString(doc.getLength(), String.format("%1$-10s", record.getLevel()), keyWord);
        if (record.getParameters() != null) {
            doc.insertString(doc.getLength(), MessageFormat.format(record.getMessage(), record.getParameters()), text);
        } else {
            doc.insertString(doc.getLength(), record.getMessage(), text);
        }
        doc.insertString(doc.getLength(), "\n", text);
    } catch (BadLocationException e) {
    }
    textPane.setCaretPosition(doc.getLength());
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) StyledDocument(javax.swing.text.StyledDocument) BadLocationException(javax.swing.text.BadLocationException)

Example 40 with SimpleAttributeSet

use of javax.swing.text.SimpleAttributeSet in project org.alloytools.alloy by AlloyTools.

the class OurConsole method style.

/*
     * Helper method that construct a mutable style with the given font name, font
     * size, boldness, color, and left indentation.
     */
static MutableAttributeSet style(String fontName, int fontSize, boolean boldness, boolean italic, boolean strike, Color color, int leftIndent) {
    MutableAttributeSet s = new SimpleAttributeSet();
    StyleConstants.setFontFamily(s, fontName);
    StyleConstants.setFontSize(s, fontSize);
    StyleConstants.setLineSpacing(s, -0.2f);
    StyleConstants.setBold(s, boldness);
    StyleConstants.setItalic(s, italic);
    StyleConstants.setForeground(s, color);
    StyleConstants.setLeftIndent(s, leftIndent);
    StyleConstants.setStrikeThrough(s, strike);
    return s;
}
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