Search in sources :

Example 26 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 27 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 28 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)

Aggregations

SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)28 StyledDocument (javax.swing.text.StyledDocument)5 AttributeSet (javax.swing.text.AttributeSet)3 BadLocationException (javax.swing.text.BadLocationException)3 HTML (javax.swing.text.html.HTML)3 User (lib.pircbot.User)3 URL (java.net.URL)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Document (javax.swing.text.Document)2 HTMLDocument (javax.swing.text.html.HTMLDocument)2 ColorSet (com.android.tools.sherpa.drawing.ColorSet)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 HyperlinkAdapter (com.intellij.ui.HyperlinkAdapter)1 Icons (face.Icons)1 ChatPane (gui.ChatPane)1 CombinedChatPane (gui.CombinedChatPane)1 GUIMain (gui.forms.GUIMain)1