Search in sources :

Example 61 with Font

use of org.eclipse.swt.graphics.Font in project knime-core by knime.

the class NodeContainerFigure method setLabelText.

/**
 * Sets the text of the heading label.
 *
 * @param text The text to set.
 */
@SuppressWarnings("unchecked")
public void setLabelText(final String text) {
    m_label = text;
    m_headingContainer.removeAll();
    // needed, otherwise labels disappear after font size has changed
    m_headingContainer.setBounds(new Rectangle(0, 0, 0, 0));
    Font boldFont = FontStore.INSTANCE.getDefaultFontBold(FontStore.getFontSizeFromKNIMEPrefPage());
    m_headingContainer.setFont(boldFont);
    int width = 0;
    for (String s : wrapText(text).split("\n")) {
        Label l = new Label(s) {

            /**
             * {@inheritDoc}
             */
            @Override
            public Dimension getPreferredSize(final int wHint, final int hHint) {
                Dimension d = super.getPreferredSize(wHint, hHint).getCopy();
                // headings labels are too small when the editor is zoomed.
                d.width = (int) (d.width * 1.1);
                return d;
            }
        };
        l.setForegroundColor(ColorConstants.black);
        l.setFont(boldFont);
        m_headingContainer.add(l);
        Dimension size = l.getPreferredSize();
        width = Math.max(width, size.width);
    }
    int height = 0;
    for (IFigure child : (List<IFigure>) m_headingContainer.getChildren()) {
        Dimension size = child.getPreferredSize();
        int offset = (width - size.width) / 2;
        child.setBounds(new Rectangle(offset, height, size.width, size.height));
        height += size.height;
    }
    m_headingContainer.setBounds(new Rectangle(0, 0, width, height));
    repaint();
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) Label(org.eclipse.draw2d.Label) List(java.util.List) Dimension(org.eclipse.draw2d.geometry.Dimension) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.draw2d.geometry.Point) IFigure(org.eclipse.draw2d.IFigure)

Example 62 with Font

use of org.eclipse.swt.graphics.Font in project knime-core by knime.

the class NodeContainerFigure method setFontSize.

/**
 * Set a new font size which is applied to the node name and label.
 *
 * @param fontSize the new font size to ba applied.
 */
public void setFontSize(final int fontSize) {
    setLabelText(m_label);
    // apply new font for node label
    Font font2 = super.getFont();
    FontData fontData2 = font2.getFontData()[0];
    Font newFont2 = FontStore.INSTANCE.getFont(fontData2.getName(), fontSize, fontData2.getStyle());
    // apply the standard node label font also to its parent figure to allow
    // editing the node label with the same font (size)
    super.setFont(newFont2);
    FontStore.INSTANCE.releaseFont(font2);
}
Also used : FontData(org.eclipse.swt.graphics.FontData) Font(org.eclipse.swt.graphics.Font)

Example 63 with Font

use of org.eclipse.swt.graphics.Font in project knime-core by knime.

the class NodeUsageComposite method createNodeGrid.

private void createNodeGrid(final SubNodeContainer subNodeContainer, @SuppressWarnings("rawtypes") final Map<NodeIDSuffix, WizardNode> viewNodes) {
    ScrolledComposite scrollPane = new ScrolledComposite(this, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    scrollPane.setExpandHorizontal(true);
    scrollPane.setExpandVertical(true);
    Composite composite = new Composite(scrollPane, SWT.NONE);
    scrollPane.setContent(composite);
    scrollPane.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    composite.setLayout(new GridLayout(3, false));
    composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
    // titles
    new Composite(composite, SWT.NONE);
    /* Placeholder */
    Label wizardLabel = new Label(composite, SWT.CENTER);
    FontData fontData = wizardLabel.getFont().getFontData()[0];
    Font boldFont = new Font(Display.getCurrent(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
    wizardLabel.setText("WebPortal /\nWrapped Metanode View");
    wizardLabel.setFont(boldFont);
    Label dialogLabel = new Label(composite, SWT.CENTER);
    dialogLabel.setText("\nWrapped Metanode Dialog");
    dialogLabel.setFont(boldFont);
    // select all checkboxes
    Label selectAllLabel = new Label(composite, SWT.LEFT);
    selectAllLabel.setText("Enable/Disable");
    Button selectAllWizard = createCheckbox(composite);
    Button selectAllDialog = createCheckbox(composite);
    // individual nodes
    for (@SuppressWarnings("rawtypes") Entry<NodeIDSuffix, WizardNode> entry : viewNodes.entrySet()) {
        NodeIDSuffix suffix = entry.getKey();
        NodeID id = suffix.prependParent(subNodeContainer.getWorkflowManager().getID());
        NodeContainer nodeContainer = viewNodes.containsKey(suffix) ? subNodeContainer.getWorkflowManager().getNodeContainer(id) : null;
        createNodeLabelComposite(composite, id, nodeContainer);
        @SuppressWarnings("rawtypes") WizardNode model = entry.getValue();
        Button wizardButton = createCheckbox(composite);
        wizardButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                checkAllSelected(m_wizardUsageMap, selectAllWizard);
            }
        });
        wizardButton.setToolTipText("Enable/disable for usage in WebPortal and wizard execution.");
        wizardButton.setSelection(!((WizardNode<?, ?>) model).isHideInWizard());
        m_wizardUsageMap.put(id, wizardButton);
        if (model instanceof DialogNode) {
            Button dialogButton = createCheckbox(composite);
            dialogButton.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(final SelectionEvent e) {
                    checkAllSelected(m_dialogUsageMap, selectAllDialog);
                }
            });
            dialogButton.setToolTipText("Enable/disable for usage in wrapped metanode configure dialog.");
            dialogButton.setSelection(!((DialogNode<?, ?>) model).isHideInDialog());
            m_dialogUsageMap.put(id, dialogButton);
        } else {
            new Composite(composite, SWT.NONE);
        /* Placeholder */
        }
    }
    checkAllSelected(m_wizardUsageMap, selectAllWizard);
    checkAllSelected(m_dialogUsageMap, selectAllDialog);
    selectAllWizard.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            selectAllWizard.setGrayed(false);
            for (Button b : m_wizardUsageMap.values()) {
                b.setSelection(selectAllWizard.getSelection());
            }
        }
    });
    if (m_wizardUsageMap.size() < 1) {
        selectAllWizard.setEnabled(false);
    }
    selectAllDialog.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            selectAllDialog.setGrayed(false);
            for (Button b : m_dialogUsageMap.values()) {
                b.setSelection(selectAllDialog.getSelection());
            }
        }
    });
    if (m_dialogUsageMap.size() < 1) {
        selectAllDialog.setEnabled(false);
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) FontData(org.eclipse.swt.graphics.FontData) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) DialogNode(org.knime.core.node.dialog.DialogNode) WizardNode(org.knime.core.node.wizard.WizardNode) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) NodeID(org.knime.core.node.workflow.NodeID) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite)

Example 64 with Font

use of org.eclipse.swt.graphics.Font in project knime-core by knime.

the class EditorUISettingsDialog method createHeader.

private void createHeader(final Composite parent) {
    Composite header = new Composite(parent, SWT.FILL);
    Color white = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
    header.setBackground(white);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    header.setLayoutData(gridData);
    header.setLayout(new GridLayout(2, false));
    // 1st row
    Label exec = new Label(header, SWT.NONE);
    exec.setBackground(white);
    exec.setText("Workflow Editor Settings");
    FontData[] fd = parent.getFont().getFontData();
    for (FontData f : fd) {
        f.setStyle(SWT.BOLD);
        f.setHeight(f.getHeight() + 2);
    }
    exec.setFont(new Font(parent.getDisplay(), fd));
    exec.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    Label execIcon = new Label(header, SWT.NONE);
    execIcon.setBackground(white);
    execIcon.setImage(IMG_PERMS.createImage());
    execIcon.setLayoutData(new GridData(SWT.END, SWT.BEGINNING, true, true));
    // 2nd row
    Label txt = new Label(header, SWT.NONE);
    txt.setBackground(white);
    txt.setText("Modify the settings for the active workflow editor. \n" + "All settings will be store with the workflow.\n" + "To change default settings for new workflow editors go to the preference page.\n" + "Snap to grid behavior can be toggled by pressing 'Ctrl-Shift-X'.");
    txt.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    new Label(header, SWT.NONE);
    // 3rd row
    m_error = new Label(header, SWT.NONE);
    m_error.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, true, false));
    m_error.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
    m_error.setBackground(white);
    new Label(header, SWT.NONE);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) FontData(org.eclipse.swt.graphics.FontData) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Font(org.eclipse.swt.graphics.Font)

Example 65 with Font

use of org.eclipse.swt.graphics.Font in project knime-core by knime.

the class AnnotationEditPart method toSWTStyleRanges.

public static StyleRange[] toSWTStyleRanges(final AnnotationData t, final Font defaultFont) {
    AnnotationData.StyleRange[] knimeStyleRanges = t.getStyleRanges();
    ArrayList<StyleRange> swtStyleRange = new ArrayList<StyleRange>(knimeStyleRanges.length);
    for (AnnotationData.StyleRange knimeSR : knimeStyleRanges) {
        StyleRange swtStyle = new StyleRange();
        Font f = FontStore.INSTANCE.getAnnotationFont(knimeSR, defaultFont);
        swtStyle.font = f;
        if (knimeSR.getFgColor() >= 0) {
            int rgb = knimeSR.getFgColor();
            RGB rgbObj = RGBintToRGBObj(rgb);
            swtStyle.foreground = new Color(null, rgbObj);
        }
        swtStyle.start = knimeSR.getStart();
        swtStyle.length = knimeSR.getLength();
        swtStyleRange.add(swtStyle);
    }
    return swtStyleRange.toArray(new StyleRange[swtStyleRange.size()]);
}
Also used : AnnotationData(org.knime.core.node.workflow.AnnotationData) StyleRange(org.eclipse.swt.custom.StyleRange) Color(org.eclipse.swt.graphics.Color) ArrayList(java.util.ArrayList) RGB(org.eclipse.swt.graphics.RGB) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

Font (org.eclipse.swt.graphics.Font)235 FontData (org.eclipse.swt.graphics.FontData)93 GridData (org.eclipse.swt.layout.GridData)52 Point (org.eclipse.swt.graphics.Point)51 Composite (org.eclipse.swt.widgets.Composite)50 GridLayout (org.eclipse.swt.layout.GridLayout)47 Color (org.eclipse.swt.graphics.Color)45 Label (org.eclipse.swt.widgets.Label)38 Test (org.junit.Test)26 GC (org.eclipse.swt.graphics.GC)22 Image (org.eclipse.swt.graphics.Image)22 Rectangle (org.eclipse.swt.graphics.Rectangle)22 Button (org.eclipse.swt.widgets.Button)19 Display (org.eclipse.swt.widgets.Display)19 SelectionEvent (org.eclipse.swt.events.SelectionEvent)17 Text (org.eclipse.swt.widgets.Text)16 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)15 StyledText (org.eclipse.swt.custom.StyledText)13 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)12 StyleRange (org.eclipse.swt.custom.StyleRange)11