Search in sources :

Example 1 with SSTextLayout

use of org.csstudio.autocomplete.ui.util.SSTextLayout in project yamcs-studio by yamcs.

the class ContentProposalPopup method initializeTextLayouts.

private void initializeTextLayouts() {
    Display display = Display.getCurrent();
    FontData defaultFontData = display.getSystemFont().getFontData()[0];
    String fontName = defaultFontData.getName();
    int fontHeight = defaultFontData.getHeight();
    Font headerFont = new Font(display, new FontData(fontName, fontHeight, SWT.ITALIC | SWT.BOLD));
    Font noFont = new Font(display, new FontData(fontName, fontHeight, SWT.NORMAL));
    Color black = display.getSystemColor(SWT.COLOR_BLACK);
    int index = 0;
    textLayouts = new SSTextLayout[getTableLength()];
    for (Proposal proposal : proposalList.getTopProposalList()) {
        textLayouts[index] = AutoCompleteUIPlugin.getUIHelper().newTextLayout();
        String text = getString(proposal);
        textLayouts[index].init(display, text);
        textLayouts[index].addStyle(noFont, black, 0, text.length());
        if (proposal.getStyles() != null && !proposal.getStyles().isEmpty()) {
            for (ProposalStyle style : proposal.getStyles()) {
                FontData newFontData = new FontData(fontName, fontHeight, style.fontStyle);
                Font font = new Font(display, newFontData);
                Color color = display.getSystemColor(style.fontColor);
                textLayouts[index].addStyle(font, color, style.from, style.to);
            }
        }
        index++;
    }
    for (String provider : proposalList.getProviderList()) {
        textLayouts[index] = AutoCompleteUIPlugin.getUIHelper().newTextLayout();
        int count = proposalList.getCount(provider);
        String headerText = provider + " (" + count + " matching items)";
        textLayouts[index].init(display, headerText);
        textLayouts[index].addStyle(headerFont, black, 0, headerText.length());
        index++;
        for (Proposal proposal : proposalList.getProposals(provider)) {
            textLayouts[index] = AutoCompleteUIPlugin.getUIHelper().newTextLayout();
            String text = getString(proposal);
            textLayouts[index].init(display, text);
            textLayouts[index].addStyle(noFont, black, 0, text.length());
            if (proposal.getStyles() != null && !proposal.getStyles().isEmpty()) {
                for (ProposalStyle style : proposal.getStyles()) {
                    FontData newFontData = new FontData(fontName, fontHeight, style.fontStyle);
                    Font font = new Font(display, newFontData);
                    Color color = display.getSystemColor(style.fontColor);
                    textLayouts[index].addStyle(font, color, style.from, style.to);
                }
            }
            index++;
        }
    }
    for (SSTextLayout sstl : textLayouts) if (sstl != null && sstl.getBounds() != null && sstl.getBounds().width > maxItemWidth)
        maxItemWidth = sstl.getBounds().width;
    adjustTableBounds();
}
Also used : SSTextLayout(org.csstudio.autocomplete.ui.util.SSTextLayout) ProposalStyle(org.csstudio.autocomplete.proposals.ProposalStyle) FontData(org.eclipse.swt.graphics.FontData) Color(org.eclipse.swt.graphics.Color) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) Proposal(org.csstudio.autocomplete.proposals.Proposal) Display(org.eclipse.swt.widgets.Display)

Aggregations

Proposal (org.csstudio.autocomplete.proposals.Proposal)1 ProposalStyle (org.csstudio.autocomplete.proposals.ProposalStyle)1 SSTextLayout (org.csstudio.autocomplete.ui.util.SSTextLayout)1 Color (org.eclipse.swt.graphics.Color)1 Font (org.eclipse.swt.graphics.Font)1 FontData (org.eclipse.swt.graphics.FontData)1 Point (org.eclipse.swt.graphics.Point)1 Display (org.eclipse.swt.widgets.Display)1