Search in sources :

Example 1 with TooltipAttribute

use of org.omegat.util.gui.TooltipAttribute in project omegat by omegat-org.

the class DictionaryGlossaryRenderer 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);
    boolean hasComments = false;
    for (int i = 0; i < targets.length; i++) {
        if (i == 0 || (!targets[i].equals(targets[i - 1]))) {
            if (hasComments) {
                trg.startIndent(null);
                hasComments = false;
            }
            SimpleAttributeSet attrs = new SimpleAttributeSet(TARGET_ATTRIBUTES);
            if (priorities[i]) {
                StyleConstants.setBold(attrs, true);
            }
            attrs.addAttribute(TooltipAttribute.ATTRIBUTE_KEY, new TooltipAttribute(origins[i]));
            trg.append(bracketEntry(targets[i]), attrs);
            if (i < targets.length - 1) {
                trg.append(", ", null);
            }
        }
        if (!comments[i].equals("")) {
            trg.startIndent(NOTES_ATTRIBUTES);
            trg.append("- " + comments[i], NOTES_ATTRIBUTES);
            hasComments = true;
        }
    }
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) TooltipAttribute(org.omegat.util.gui.TooltipAttribute)

Example 2 with TooltipAttribute

use of org.omegat.util.gui.TooltipAttribute 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 3 with TooltipAttribute

use of org.omegat.util.gui.TooltipAttribute 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)

Aggregations

TooltipAttribute (org.omegat.util.gui.TooltipAttribute)3 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)2 AttributeSet (javax.swing.text.AttributeSet)1 Element (javax.swing.text.Element)1 StyledDocument (javax.swing.text.StyledDocument)1