Search in sources :

Example 21 with Label

use of org.eclipse.draw2d.Label in project linuxtools by eclipse.

the class StapGraph method drawAggregateView.

/**
 * Draws nodes according to the name of the function (not accounting for
 * call heirarchies). Uses colour to indicate the number of calls and size
 * to indicate the percentage time spent.
 */
private void drawAggregateView() {
    if (aggregateNodes == null) {
        aggregateNodes = new ArrayList<>();
    } else {
        aggregateNodes.clear();
    }
    // -------------Format numbers
    float percentage_time;
    float percentage_count;
    int maxTimesCalled = 0;
    final int colorLevels = 15;
    final int colorLevelDifference = 12;
    int primary;
    int secondary;
    NumberFormat num = NumberFormat.getInstance(Locale.CANADA);
    num.setMinimumFractionDigits(2);
    num.setMaximumFractionDigits(2);
    // FIND THE MOST TIMES A FUNCTION IS CALLED
    for (int val : aggregateCount.values()) {
        if (val > maxTimesCalled) {
            maxTimesCalled = val;
        }
    }
    // TEMPORARY STORAGE OF THE ENTRIES
    // IMPLEMENTS A COMPARATOR TO STORE BY ORDER OF THE VALUE
    TreeSet<Entry<String, Long>> sortedValues = new TreeSet<>(StapGraph.VALUE_ORDER);
    HashMap<String, Long> tempMap = new HashMap<>();
    tempMap.putAll(aggregateTime);
    for (String key : tempMap.keySet()) {
        long time = aggregateTime.get(key);
        while (time < 0) {
            time += endTime;
        }
        tempMap.put(key, time);
    }
    sortedValues.addAll(tempMap.entrySet());
    // -------------Draw nodes
    for (Entry<String, Long> ent : sortedValues) {
        String key = ent.getKey();
        GraphNode n = new GraphNode(this.getGraphModel(), SWT.NONE);
        aggregateNodes.add(n);
        percentage_count = (float) aggregateCount.get(key) / (float) maxTimesCalled;
        percentage_time = ((float) ent.getValue() / this.getTotalTime() * 100);
        n.setText(// $NON-NLS-1$
        key + "\n" + num.format(percentage_time) + "%" + // $NON-NLS-1$ //$NON-NLS-2$
        "\n" + aggregateCount.get(key) + // $NON-NLS-1$
        "\n");
        // $NON-NLS-1$
        n.setData("AGGREGATE_NAME", key);
        primary = (int) (percentage_count * colorLevels * colorLevelDifference);
        secondary = (colorLevels * colorLevelDifference) - (int) (percentage_count * colorLevels * colorLevelDifference);
        primary = Math.max(0, primary);
        secondary = Math.max(0, secondary);
        primary = Math.min(primary, 255);
        secondary = Math.min(secondary, 255);
        Color c = new Color(this.getDisplay(), primary, 0, secondary);
        n.setBackgroundColor(c);
        n.setHighlightColor(c);
        n.setForegroundColor(new Color(this.getDisplay(), 255, 255, 255));
        n.setTooltip(new Label(// $NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("StapGraph.Func") + key + "\n" + Messages.getString("StapGraph.Time") + num.format(percentage_time) + "%" + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "\n" + Messages.getString("StapGraph.NumOfCalls") + // $NON-NLS-1$
        aggregateCount.get(key)));
        n.setBorderWidth(2);
    }
    // Set layout to gridlayout
    this.setLayoutAlgorithm(new AggregateLayoutAlgorithm(LayoutStyles.NONE, sortedValues, this.getTotalTime(), this.getBounds().width), true);
}
Also used : HashMap(java.util.HashMap) Color(org.eclipse.swt.graphics.Color) Label(org.eclipse.draw2d.Label) GraphNode(org.eclipse.zest.core.widgets.GraphNode) Entry(java.util.Map.Entry) TreeSet(java.util.TreeSet) NumberFormat(java.text.NumberFormat)

Example 22 with Label

use of org.eclipse.draw2d.Label in project knime-core by knime.

the class WorkflowFigure method setMessage.

/**
 * @param msg message to display at the top of the editor
 */
public void setMessage(final String msg) {
    if (msg == null) {
        if (m_message != null) {
            remove(m_message);
            m_message = null;
        }
    } else {
        if (m_message == null) {
            m_message = new Label(msg);
            m_message.setOpaque(true);
            m_message.setBackgroundColor(MSG_BG);
            m_message.setIcon(ImageRepository.getUnscaledIconImage(SharedImages.Warning));
            Rectangle msgBounds = new Rectangle(m_message.getBounds());
            msgBounds.x += 10;
            msgBounds.y += 10;
            m_message.setBounds(msgBounds);
            add(m_message, new Rectangle(msgBounds.x, msgBounds.y, getBounds().width - 20, 120));
        } else {
            m_message.setText(msg);
        }
    }
    repaint();
}
Also used : Label(org.eclipse.draw2d.Label) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 23 with Label

use of org.eclipse.draw2d.Label 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 24 with Label

use of org.eclipse.draw2d.Label in project knime-core by knime.

the class ProgressFigure method mouseEntered.

@Override
public void mouseEntered(final MouseEvent me) {
    m_mouseEvent = me;
    // tooltip
    if (m_currentProgressMessage != null && !m_currentProgressMessage.equals("") && m_mouseEvent != null) {
        IFigure tip = new Label(m_currentProgressMessage);
        getToolTipHelper().displayToolTipNear(ProgressFigure.this, tip, m_mouseEvent.x, m_mouseEvent.y);
    }
}
Also used : Label(org.eclipse.draw2d.Label) IFigure(org.eclipse.draw2d.IFigure)

Example 25 with Label

use of org.eclipse.draw2d.Label in project yamcs-studio by yamcs.

the class ScrollbarFigure method initializeParts.

/**
 * Initilization of the ScrollBar. Sets the Scrollbar to have a ScrollBarLayout with vertical orientation. Creates
 * the Figures that make up the components of the ScrollBar.
 *
 * @since 2.0
 */
protected void initializeParts() {
    setLayoutManager(new ScrollBarFigureLayout(transposer));
    setUpClickable(createDefaultUpButton());
    setDownClickable(createDefaultDownButton());
    setPageUp(createPageUp());
    setPageDown(createPageDown());
    setThumb(createDefaultThumb());
    label = new Label();
    label.setBackgroundColor(LABEL_COLOR);
    label.setBorder(new LineBorder(GRAY_COLOR));
    label.setVisible(false);
    // $NON-NLS-1$
    add(label, "Label");
}
Also used : LineBorder(org.eclipse.draw2d.LineBorder) Label(org.eclipse.draw2d.Label)

Aggregations

Label (org.eclipse.draw2d.Label)56 IFigure (org.eclipse.draw2d.IFigure)8 Rectangle (org.eclipse.draw2d.geometry.Rectangle)8 Point (org.eclipse.draw2d.geometry.Point)7 LineBorder (org.eclipse.draw2d.LineBorder)6 WrapLabel (org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel)6 Image (org.eclipse.swt.graphics.Image)6 MouseEvent (org.eclipse.draw2d.MouseEvent)5 MouseListener (org.eclipse.draw2d.MouseListener)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Figure (org.eclipse.draw2d.Figure)4 RectangleFigure (org.eclipse.draw2d.RectangleFigure)4 Dimension (org.eclipse.draw2d.geometry.Dimension)4 PolylineConnection (org.eclipse.draw2d.PolylineConnection)3 ToolbarLayout (org.eclipse.draw2d.ToolbarLayout)3 EImage (org.talend.commons.ui.runtime.image.EImage)3 ComboCellLabel (org.talend.designer.gefabstractmap.figures.ComboCellLabel)3 RowBorder (org.talend.designer.gefabstractmap.figures.borders.RowBorder)3 CompoundBorder (org.eclipse.draw2d.CompoundBorder)2