Search in sources :

Example 21 with AttributeSet

use of javax.swing.text.AttributeSet in project omegat by omegat-org.

the class SegmentBuilder method insertTextWithTags.

/**
 * Inserts the texts and formats the text
 * @param text source or translation text
 * @param isSource true if it is a source text, false if it is a translation
 * @throws BadLocationException
 */
private String insertTextWithTags(String text, boolean isSource) throws BadLocationException {
    if (!isSource && hasRTL && controller.targetLangIsRTL) {
        text = EditorUtils.addBidiAroundTags(text, ste);
    }
    AttributeSet normal = attrs(isSource, false, false, false);
    insert(text, normal);
    return text;
}
Also used : MutableAttributeSet(javax.swing.text.MutableAttributeSet) AttributeSet(javax.swing.text.AttributeSet)

Example 22 with AttributeSet

use of javax.swing.text.AttributeSet in project omegat by omegat-org.

the class SegmentBuilder method addOtherLanguagePart.

/**
 * Add inactive segment part, without segment begin/end marks.
 *
 * @param text other language translation text
 * @throws BadLocationException
 */
private void addOtherLanguagePart(String text, Language language) throws BadLocationException {
    int prevOffset = offset;
    boolean rtl = Language.isRTL(language.getLanguageCode());
    insertDirectionEmbedding(false);
    AttributeSet normal = attrs(true, false, false, false);
    insert(language.getLanguage() + ": ", normal);
    insertDirectionEndEmbedding();
    insertDirectionEmbedding(rtl);
    AttributeSet attrs = settings.getOtherLanguageTranslationAttributeSet();
    insert(text, attrs);
    insertDirectionEndEmbedding();
    insert("\n", null);
    setAlignment(prevOffset, offset, rtl);
}
Also used : MutableAttributeSet(javax.swing.text.MutableAttributeSet) AttributeSet(javax.swing.text.AttributeSet)

Example 23 with AttributeSet

use of javax.swing.text.AttributeSet in project omegat by omegat-org.

the class GlossaryTextArea method getToolTipText.

@Override
public String getToolTipText(MouseEvent event) {
    StyledDocument doc = getStyledDocument();
    Element elem = doc.getCharacterElement(Java8Compat.viewToModel(this, event.getPoint()));
    AttributeSet as = elem.getAttributes();
    Object attr = as.getAttribute(TooltipAttribute.ATTRIBUTE_KEY);
    if (attr instanceof TooltipAttribute) {
        return ((TooltipAttribute) attr).getPayload();
    } else {
        return super.getToolTipText(event);
    }
}
Also used : TooltipAttribute(org.omegat.util.gui.TooltipAttribute) AttributeSet(javax.swing.text.AttributeSet) Element(javax.swing.text.Element) StyledDocument(javax.swing.text.StyledDocument)

Example 24 with AttributeSet

use of javax.swing.text.AttributeSet in project jphp by jphp-compiler.

the class WrapHyperlinkEvent method __getAttributes.

@Signature
protected Memory __getAttributes(Environment env, Memory... args) {
    AttributeSet attrs = event.getSourceElement().getAttributes();
    List<?> keys = Collections.list(attrs.getAttributeNames());
    ArrayMemory result = new ArrayMemory();
    for (Object key : keys) {
        result.put(key.toString(), new StringMemory(attrs.getAttribute(key).toString()));
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) AttributeSet(javax.swing.text.AttributeSet) StringMemory(php.runtime.memory.StringMemory) Signature(php.runtime.annotation.Reflection.Signature)

Example 25 with AttributeSet

use of javax.swing.text.AttributeSet in project gradle by gradle.

the class TextPaneSearchInteraction method highlightText.

/**
     * This highlights the text within the specified range
     *
     * @param startingIndex where to start the highlight
     * @param endingIndex where to end the highlight
     * @param ensureVisible true to scroll to the text
     * @param isEmphasized true to use an emphasized highlight (versus a regular highlight). Useful for showing the 'current' highlighted result.
     */
public void highlightText(int startingIndex, int endingIndex, boolean ensureVisible, boolean isEmphasized) {
    int length = endingIndex - startingIndex;
    AttributeSet style;
    if (isEmphasized) {
        style = emphasizedHighlightStyle;
    } else {
        style = highlightStyle;
    }
    ((DefaultStyledDocument) textComponentToSearch.getDocument()).setCharacterAttributes(startingIndex, length, style, true);
    if (ensureVisible) {
        Utility.scrollToText(textComponentToSearch, startingIndex, endingIndex);
        textComponentToSearch.setCaretPosition(endingIndex);
    }
    textComponentToSearch.repaint();
}
Also used : AttributeSet(javax.swing.text.AttributeSet) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument)

Aggregations

AttributeSet (javax.swing.text.AttributeSet)44 Element (javax.swing.text.Element)15 MutableAttributeSet (javax.swing.text.MutableAttributeSet)10 BadLocationException (javax.swing.text.BadLocationException)9 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)9 HTMLDocument (javax.swing.text.html.HTMLDocument)7 AbstractDocument (javax.swing.text.AbstractDocument)6 Document (javax.swing.text.Document)5 DocumentFilter (javax.swing.text.DocumentFilter)5 Font (java.awt.Font)3 Point (java.awt.Point)3 URL (java.net.URL)3 HTML (javax.swing.text.html.HTML)3 java.awt (java.awt)2 Color (java.awt.Color)2 Dimension (java.awt.Dimension)2 FontMetrics (java.awt.FontMetrics)2 Rectangle (java.awt.Rectangle)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2