Package javax.swing.text

Examples of javax.swing.text.MutableAttributeSet


        HTMLDocument hdoc = (HTMLDocument)doc;
        int start = getSelectionStart();
        int end = getSelectionEnd();

        Element element = hdoc.getParagraphElement(start);
        MutableAttributeSet newAttrs = new SimpleAttributeSet(element.getAttributes());
        newAttrs.addAttribute(StyleConstants.NameAttribute, tag);

        hdoc.setParagraphAttributes(start, end - start, newAttrs, true);
    }
View Full Code Here


    static class BasicDocument extends DefaultStyledDocument {
        BasicDocument(Font defaultFont, Color foreground, TextAlignment textAlignment, float rightIndent) {
            setFontAndColor(defaultFont, foreground);

            MutableAttributeSet attr = new SimpleAttributeSet();
            StyleConstants.setAlignment(attr, textAlignment.getValue());
            getStyle("default").addAttributes(attr);

            attr = new SimpleAttributeSet();
            StyleConstants.setRightIndent(attr, rightIndent);
View Full Code Here

        }

        private void setFontAndColor(Font font, Color fg) {
            if (fg != null) {

                MutableAttributeSet attr = new SimpleAttributeSet();
                StyleConstants.setForeground(attr, fg);
                getStyle("default").addAttributes(attr);
            }

            if (font != null) {
                MutableAttributeSet attr = new SimpleAttributeSet();
                StyleConstants.setFontFamily(attr, font.getFamily());
                getStyle("default").addAttributes(attr);

                attr = new SimpleAttributeSet();
                StyleConstants.setFontSize(attr, font.getSize());
                getStyle("default").addAttributes(attr);

                attr = new SimpleAttributeSet();
                StyleConstants.setBold(attr, font.isBold());
                getStyle("default").addAttributes(attr);

                attr = new SimpleAttributeSet();
                StyleConstants.setItalic(attr, font.isItalic());
                getStyle("default").addAttributes(attr);
            }

            MutableAttributeSet attr = new SimpleAttributeSet();
            StyleConstants.setSpaceAbove(attr, 0f);
            getStyle("default").addAttributes(attr);

        }
View Full Code Here

        completeCombo = new JComboBox();
        completeCombo.setRenderer(new DefaultListCellRenderer()); // no silly ticks!
        completePopup = new BasicComboPopup(completeCombo);
       
        if (message != null) {
            final MutableAttributeSet messageStyle = new SimpleAttributeSet();
            StyleConstants.setBackground(messageStyle, area.getForeground());
            StyleConstants.setForeground(messageStyle, area.getBackground());
            append(message, messageStyle);
        }
View Full Code Here

                attrs = doc.getCharacterElement(start).getAttributes();

                doc.remove(start, end - start);

                if (StyleConstants.getIcon(attrs) != null) {
                    final MutableAttributeSet newAttrs =
                        new SimpleAttributeSet(attrs);
                    newAttrs.removeAttribute(StyleConstants.IconAttribute);
                    newAttrs.removeAttribute(AbstractDocument
                                             .ElementNameAttribute);
                    attrs = newAttrs;
                }
                if (StyleConstants.getComponent(attrs) != null) {
                    final MutableAttributeSet newAttrs =
                        new SimpleAttributeSet(attrs);
                    newAttrs.removeAttribute(StyleConstants.ComponentAttribute);
                    newAttrs.removeAttribute(AbstractDocument
                                             .ElementNameAttribute);
                    attrs = newAttrs;
                }

            } else {
View Full Code Here

   /**
    * To insert component we should insert in the document whitespace with
    * special attribute StyleConstants.ComponentAttribute
    */
    public synchronized void insertComponent(final Component c) {
        final MutableAttributeSet attrs = new SimpleAttributeSet();
        StyleConstants.setComponent(attrs, c);

        replaceObject(getStyledDocument(),
                     getSelectionStart(),
                     getSelectionEnd(),
View Full Code Here

    /**
     * To insert icon we should insert in the document whitespace with
     * special attribute StyleConstants.IconAttribute
     */
    public synchronized void insertIcon(final Icon g) {
        final MutableAttributeSet attrs = new SimpleAttributeSet();
        StyleConstants.setIcon(attrs, g);

        replaceObject(getStyledDocument(),
                getSelectionStart(),
                getSelectionEnd(),
View Full Code Here

                super.start(tag, attr);
               
                final ElementSpec spec = getLastSpec();
                assert spec != null : "we've just created a spec in super.start()";
                FormElement model = null;
                final MutableAttributeSet specAttr = (MutableAttributeSet)spec.getAttributes();
                if (Tag.INPUT.equals(tag)) {
                    model = handleInput(attr, specAttr);
                } else if (Tag.TEXTAREA.equals(tag)) {
                    model = new FormTextModel(getCurrentForm(), attr);
                    openedBlocks.add(Tag.TEXTAREA);
                } else if (Tag.BUTTON.equals(tag)) {
                    model = new FormButtonModel(getCurrentForm(), attr);
                    openedBlocks.add(Tag.BUTTON);
                } else if (Tag.LEGEND.equals(tag)) {
                    openedBlocks.add(Tag.LEGEND);
                    if (openedBlocks.contains(Tag.FIELDSET)) {
                        handleLegend(null, specAttr);
                    }
                } else if (Tag.FIELDSET.equals(tag)) {
                    model = new FormFieldsetModel(getCurrentForm(), attr);
                    openedBlocks.add(Tag.FIELDSET);
                } else if (Tag.SELECT.equals(tag)) {
                    if (FormAttributes.isListSelect(specAttr)) {
                        selectModel = new FormSelectListModel(getCurrentForm(), attr);
                    } else {
                        selectModel = new FormSelectComboBoxModel(getCurrentForm(), attr);
                    }
                    model = selectModel;
                    openedBlocks.add(Tag.SELECT);
                }
                if (model != null) {
                    specAttr.addAttribute(StyleConstants.ModelAttribute, model);
                    assert currentForm != null : "creating model with getCurrentForm() in constructor assures this";
                    currentForm.addElement(model);
                }
            }
View Full Code Here

        }

        public class PreAction extends BlockAction {
            public void start(final Tag tag, final MutableAttributeSet attr) {
                super.start(tag, attr);
                MutableAttributeSet blockAttr = new SimpleAttributeSet(attr);
                SimpleAttributeSet defaultAttr = getDefaultCSSAttributes(tag);
                if (defaultAttr != null) {
                    blockAttr.addAttributes(defaultAttr);
                }
                blockOpen(Tag.IMPLIED, blockAttr);
                impliedBlockOpen = true;
                needImpliedNewLine = true;
            }
View Full Code Here

                                  ? value : cssKey.getConverter().toCSS(value));
    }

    public AttributeSet addAttributes(final AttributeSet old,
                                      final AttributeSet attr) {
        MutableAttributeSet converted = new SimpleAttributeSet(old);
        Enumeration attrKeys = attr.getAttributeNames();
        while (attrKeys.hasMoreElements()) {
            Object key = attrKeys.nextElement();
            Object value = attr.getAttribute(key);
            Attribute cssKey = (Attribute)CSS.mapToCSSForced(key);
            if (cssKey == null) {
                if (key == StyleConstants.Underline
                    || key == StyleConstants.StrikeThrough) {

                    value = createTextDecoration(converted, key, value);
                    key = CSS.Attribute.TEXT_DECORATION;
                }
                converted.addAttribute(key, value);
            } else {
                if (!(value instanceof CSS.PropertyValueConverter)) {
                    value = cssKey.getConverter().toCSS(value);
                }
                if (value != null) {
                    converted.addAttribute(cssKey, value);
                }
            }
        }
        return super.addAttributes(getEmptySet(), converted);
    }
View Full Code Here

TOP

Related Classes of javax.swing.text.MutableAttributeSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.