本文整理汇总了Java中org.graphstream.graph.Node.addAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Node.addAttribute方法的具体用法?Java Node.addAttribute怎么用?Java Node.addAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.graphstream.graph.Node
的用法示例。
在下文中一共展示了Node.addAttribute方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filterGraphNodes
import org.graphstream.graph.Node; //导入方法依赖的package包/类
/**
* Filters and highlights the graph by setting the {@code uiClassForFilteredNodes} class on the filtered nodes based on the boolean value {@code selection} and also pans the view to the last filtered node based on the value of {@code panToNode}.
* @param nodes - nodes to be filtered
* @param selection - flag to determine whether the nodes have to be highlighted
* @param panToNode - flag to determine whether to pan the graph to the last filtered node
* @param uiClassForFilteredNodes - class name to be set on filtered nodes, defaults to <b>filter</b> if the passed in value is null
* @author Shashank B S
*/
private void filterGraphNodes(List<VFNode> nodes, boolean selection, boolean panToNode, String uiClassForFilteredNodes) {
boolean panned = false;
if (uiClassForFilteredNodes == null) {
uiClassForFilteredNodes = "filter";
}
Iterable<? extends Node> graphNodes = graph.getEachNode();
for (Node node : graphNodes) {
if (node.hasAttribute("ui.class")) {
node.removeAttribute("ui.class");
}
for (VFNode vfNode : nodes) {
if (node.getAttribute("unit").toString().contentEquals(vfNode.getUnit().toString())) {
if (selection) {
node.removeAttribute("ui.color");
node.addAttribute("ui.class", uiClassForFilteredNodes);
}
if (!panned && panToNode) {
this.panToNode(node.getId());
panned = true;
}
}
}
}
}
示例2: handleEvent
import org.graphstream.graph.Node; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void handleEvent(Event event) {
if (event.getTopic().contentEquals(DataModel.EA_TOPIC_DATA_MODEL_CHANGED)) {
renderICFG((ICFGStructure) event.getProperty("icfg"));
}
if (event.getTopic().contentEquals(DataModel.EA_TOPIC_DATA_SELECTION)) {
VFMethod selectedMethod = (VFMethod) event.getProperty("selectedMethod");
boolean panToNode = (boolean) event.getProperty("panToNode");
try {
renderMethodCFG(selectedMethod.getControlFlowGraph(), panToNode);
} catch (Exception e) {
e.printStackTrace();
}
}
if (event.getTopic().contentEquals(DataModel.EA_TOPIC_DATA_FILTER_GRAPH)) {
filterGraphNodes((List<VFNode>) event.getProperty("nodesToFilter"), (boolean) event.getProperty("selection"),
(boolean) event.getProperty("panToNode"), (String) event.getProperty("uiClassName"));
}
if (event.getTopic().equals(DataModel.EA_TOPIC_DATA_UNIT_CHANGED)) {
VFUnit unit = (VFUnit) event.getProperty("unit");
for (Edge edge : graph.getEdgeSet()) {
Node src = edge.getSourceNode();
VFNode vfNode = src.getAttribute("nodeUnit");
if (vfNode != null) {
VFUnit currentUnit = vfNode.getVFUnit();
if (unit.getFullyQualifiedName().equals(currentUnit.getFullyQualifiedName())) {
String outset = Optional.fromNullable(unit.getOutSet()).or("").toString();
edge.setAttribute("ui.label", outset);
edge.setAttribute("edgeData.outSet", outset);
src.addAttribute("nodeData.inSet", unit.getInSet());
src.addAttribute("nodeData.outSet", unit.getOutSet());
}
}
}
}
}
示例3: addNode
import org.graphstream.graph.Node; //导入方法依赖的package包/类
public Integer addNode(Node v, Node[] gammaV) {
graph.addNode(v.getId());
int l = gammaV.length;
for (int i = 0; i < l; i++) {
Node u = gammaV[i];
graph.addEdge(v.getId() + u.getId(), v.getId(), u.getId());
}
Integer index = heuristic.getIndex(partitionMap,v);
partitionMap.assignToPartition(v, index);
Node addedV = graph.getNode(v.getId());
addedV.addAttribute(GraphPartitionator.PARTITION_ATTRIBUTE, Integer.toString(index));
Double vColor = 1.0/index;
addedV.addAttribute("ui.color", vColor);
return index;
}
示例4: getPartitionNode
import org.graphstream.graph.Node; //导入方法依赖的package包/类
public Integer getPartitionNode(Node v) {
Integer index = heuristic.getIndex(partitionMap,v);
partitionMap.assignToPartition(v, index);
Node addedV = graph.getNode(v.getId());
addedV.addAttribute(GraphPartitionator.PARTITION_ATTRIBUTE, Integer.toString(index));
Double vColor = 1.0/index;
addedV.addAttribute("ui.color", vColor);
return index;
}
示例5: setupNode
import org.graphstream.graph.Node; //导入方法依赖的package包/类
@Override
public void setupNode(final Node node, final int batt, final long now,
final int net, final NodeAddress addr) {
super.setupNode(node, batt, now, net, addr);
node.addAttribute("ui.label", node.getId());
if (net < NetworkPacket.THRES) {
node.changeAttribute("ui.style", "fill-color: rgb(0," + batt
+ ",0),rgb(0,0,0);");
} else {
node.changeAttribute("ui.style", "fill-color: rgb(" + batt
+ ",0,0),rgb(0,0,0);");
}
}
示例6: showNode
import org.graphstream.graph.Node; //导入方法依赖的package包/类
private void showNode(String nodeId, double x, double y) {
try {
Node node = graph.addNode(nodeId);
if(!Double.isNaN(x)) {
node.addAttribute("x", x);
}
if(!Double.isNaN(y)) {
node.addAttribute("y", y);
}
} catch(IdAlreadyInUseException nodeInUse) { }
}
示例7: buttonReleased
import org.graphstream.graph.Node; //导入方法依赖的package包/类
@Override
/* (non-Javadoc)
* @see org.graphstream.ui.view.ViewerListener#buttonReleased(java.lang.String)
*/
public void buttonReleased(String id) {
Node node = graphDisplay.getNode(id);
// If node color is black or node color is red, change the color to purple and display
// Closeness Centrality.
if (!node.hasAttribute("ui.style") || node.getAttribute("ui.style")
.toString().equals("fill-color: black;") || node.getAttribute("ui.style")
.toString().equals("fill-color: red;")) {
// Round the Closeness Centrality to two decimals.
String closeness = df.format(graph.closeness(new Vertex(Integer.parseInt(id))));
node.addAttribute("ui.style", "fill-color: purple;");
node.addAttribute("ui.label", closeness);
// else if the node color is purple (already clicked node) and its original color is
// black and change its color to black.
}else if (node.getAttribute("ui.style").toString().equals("fill-color: purple;")
&& !node.hasAttribute("ui.class")){
node.changeAttribute("ui.style", "fill-color: black;");
node.changeAttribute("ui.label", id);
// else (if the node is purple and its original color is red) then change node
// color to red and label it with its ID.
}else{
node.changeAttribute("ui.style", "fill-color: red;");
node.changeAttribute("ui.label", id);
}
}
示例8: createControlFlowGraphNode
import org.graphstream.graph.Node; //导入方法依赖的package包/类
/**
* Creates the CFG node and sets the label, unit, escapedHTMLunit, unitType, inSet, outSet, color attributes.
*
* @param node
* @author Shashank B S
*/
private void createControlFlowGraphNode(VFNode node) {
if (graph.getNode(node.getId() + "") == null) {
Node createdNode = graph.addNode(node.getId() + "");
Unit unit = node.getUnit();
String label = unit.toString();
try {
UnitFormatter formatter = UnitFormatterFactory.createFormatter(unit);
//UnitFormatter formatter = new DefaultFormatter();
label = formatter.format(unit, maxLength);
} catch (Exception e) {
logger.error("Unit formatting failed", e);
}
createdNode.setAttribute("ui.label", label);
String str = unit.toString();
String escapedNodename = StringEscapeUtils.escapeHtml(str);
createdNode.setAttribute("unit", str);
createdNode.setAttribute("nodeData.unit", escapedNodename);
createdNode.setAttribute("nodeData.unitType", node.getUnit().getClass());
String str1 = Optional.fromNullable(node.getVFUnit().getInSet()).or("n/a").toString();
String nodeInSet = StringEscapeUtils.escapeHtml(str1);
String str2 = Optional.fromNullable(node.getVFUnit().getOutSet()).or("n/a").toString();
String nodeOutSet = StringEscapeUtils.escapeHtml(str2);
createdNode.setAttribute("nodeData.inSet", nodeInSet);
createdNode.setAttribute("nodeData.outSet", nodeOutSet);
Map<String, String> customAttributes = node.getVFUnit().getHmCustAttr();
String attributeData = "";
if(!customAttributes.isEmpty())
{
Iterator<Entry<String, String>> customAttributeIterator = customAttributes.entrySet().iterator();
while(customAttributeIterator.hasNext())
{
Entry<String, String> curr = customAttributeIterator.next();
attributeData += curr.getKey() + " : " + curr.getValue();
attributeData += "<br />";
}
createdNode.setAttribute(nodeAttributesString, attributeData);
}
createdNode.setAttribute("nodeUnit", node);
Color nodeColor = new Color(new ProjectPreferences().getColorForNode(node.getUnit().getClass().getName().toString()));
createdNode.addAttribute("ui.color", nodeColor);
}
}
示例9: setCustomAttribute
import org.graphstream.graph.Node; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public void setCustomAttribute(VFUnit selectedVF, Node curr) {
JPanel panel = new JPanel(new GridLayout(0, 2));
JTextField attributeName = new JTextField("");
JTextField attributeValue = new JTextField("");
panel.add(attributeName);
panel.add(new JLabel("Attribute: "));
panel.add(attributeValue);
panel.add(new JLabel("Attribute value: "));
int result = JOptionPane.showConfirmDialog(null, panel, "Setting custom attribute", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (result == JOptionPane.OK_OPTION) {
Map<String, String> hmCustAttr = new HashMap<>();
// Get actual customized attributes
Set set = selectedVF.getHmCustAttr().entrySet();
Iterator i = set.iterator();
String attributeString = "";
if(curr.hasAttribute(nodeAttributesString))
{
attributeString += curr.getAttribute(nodeAttributesString) + "<br>";
curr.removeAttribute(nodeAttributesString);
}
else
attributeString += "";
// Display elements
while (i.hasNext()) {
Map.Entry me = (Map.Entry) i.next();
hmCustAttr.put((String) me.getKey(), (String) me.getValue());
}
if ((attributeName.getText().length() > 0) && (attributeValue.getText().length() > 0)) {
try {
hmCustAttr.put(attributeName.getText(), attributeValue.getText());
selectedVF.setHmCustAttr(hmCustAttr);
ArrayList<VFUnit> units = new ArrayList<>();
units.add(selectedVF);
attributeString += attributeName.getText() + ":" + attributeValue.getText();
curr.setAttribute(nodeAttributesString, attributeString);
curr.addAttribute("ui.color", Color.red.getRGB());
} catch (Exception e) {
e.printStackTrace();
}
} else {
JOptionPane.showMessageDialog(new JPanel(), "Please make sure all fields are correctly filled out", "Warning", JOptionPane.WARNING_MESSAGE);
}
}
}
示例10: setupNode
import org.graphstream.graph.Node; //导入方法依赖的package包/类
/**
* Setups a Node.
*
* @param node the node to setup
* @param batt residual charge of the node
* @param now last time time the node was alive
* @param net Node network id
* @param addr Node address
*/
public void setupNode(final Node node, final int batt, final long now,
final int net, final NodeAddress addr) {
node.addAttribute("battery", batt);
node.addAttribute("lastSeen", now);
node.addAttribute("net", net);
node.addAttribute("nodeAddress", addr);
}
示例11: updateNode
import org.graphstream.graph.Node; //导入方法依赖的package包/类
/**
* Updates a existing Node.
*
* @param node the node to setup
* @param batt residual charge of the node
* @param now last time time the node was alive
*/
public void updateNode(final Node node, final int batt, final long now) {
node.addAttribute("battery", batt);
node.addAttribute("lastSeen", now);
}