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);
}
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();
}
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();
}
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);
}
}
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");
}
Aggregations