1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/*******************************************************************************
* Copyright (c) 2009 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat - initial API and implementation
*******************************************************************************/
package org.eclipse.linuxtools.callgraph;
import java.text.NumberFormat;
import java.util.Locale;
import org.eclipse.draw2d.Label;
import org.eclipse.linuxtools.callgraph.core.MP;
import org.eclipse.swt.widgets.Display;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
public class StapNode extends GraphNode{
private static int nodeSize = 20;
public int id;
public GraphConnection connection; //Each node should have only one connection (to its caller)
static NumberFormat numberFormat = NumberFormat.getInstance(Locale.CANADA);
public StapNode(StapGraph graphModel, int style, StapData data) {
super(graphModel, style, Messages.getString("StapNode.0")); //$NON-NLS-1$
numberFormat.setMaximumFractionDigits(2);
numberFormat.setMinimumFractionDigits(2);
if (Display.getCurrent().getPrimaryMonitor().getBounds().width < 1000)
nodeSize = 10;
if (data.name == StapGraph.CONSTANT_TOP_NODE_NAME)
this.setText(StapGraph.CONSTANT_TOP_NODE_NAME);
else {
String shortName = data.name;
if (data.name.length() > nodeSize)
shortName = data.name.substring(0, nodeSize - 3) + "..."; //$NON-NLS-1$
this.setText(shortName + ": " + //$NON-NLS-1$
numberFormat.format((float) data.getTime()/graphModel.getTotalTime() * 100)
+ "%"); //$NON-NLS-1$
}
if (data.markedMessage != null && data.markedMessage.length() != 0) {
Label tooltip = new Label(data.name + ": " + //$NON-NLS-1$
numberFormat.format((float) data.getTime()/graphModel.getTotalTime() * 100)
+ "%" + "\n " + data.markedMessage); //$NON-NLS-1$ //$NON-NLS-2$
this.setTooltip(tooltip);
} else if (data.name.length() > nodeSize) {
Label tooltip = new Label(data.name + ": " + //$NON-NLS-1$
numberFormat.format((float) data.getTime()/graphModel.getTotalTime() * 100)
+ "%"); //$NON-NLS-1$
this.setTooltip(tooltip);
}
this.id = data.id;
this.connection = null;
if (graphModel.getNode(data.parent) != null) {
this.connection = new GraphConnection( graphModel, style,
this, graphModel.getNode(data.parent));
if (graphModel.isCollapseMode())
connection.setText("" + data.timesCalled); //$NON-NLS-1$
} else if (graphModel.getNode(data.collapsedParent) != null) {
this.connection = new GraphConnection( graphModel, style,
this, graphModel.getNode(data.collapsedParent));
if (graphModel.isCollapseMode())
connection.setText("" + data.timesCalled); //$NON-NLS-1$
} //else do not create any connections (this should usually never happen)
}
/**
* Returns the StapData object associated with this node.
*/
public StapData getData() {
return ((StapGraph) this.getGraphModel()).getNodeData(id);
}
/**
* Creates a connection between this node and the
* specified node. The connection will have the int called as its text.
*
* @param graphModel
* @param style
* @param n
* @param called
*/
public void makeConnection(int style, StapNode n, int called) {
if (n == null) {
MP.println("Error! Attempting to connect null node to " + this.getText()); //$NON-NLS-1$
}
this.connection = new GraphConnection(this.getGraphModel(), style, this, n);
if (((StapGraph)this.getGraphModel()).isCollapseMode())
connection.setText("" + called); //$NON-NLS-1$
}
/**
* Returns this node's connection, or null if none exists.
* @return
*/
public GraphConnection getConnection() {
return connection;
}
public static int getNodeSize() {
return nodeSize;
}
public static void setNodeSize(int nodeSize) {
StapNode.nodeSize = nodeSize;
}
}
|