简体   繁体   English

如何在graphstream中为节点分配类

[英]how to assign class to nodes in graphstream

I try to construct graph in java by Graphstream. 我尝试通过Graphstream在Java中构造图形。 I want to have two types of nodes which the shapes are circle by default or box. 我想要两种类型的节点,这些节点的形状默认为圆形或框形。 Thus assign class to nodes.The code: 因此将类分配给节点。代码:

 System.setProperty("org.graphstream.ui.renderer","org.graphstream.ui.j2dviewer.J2DGraphRenderer");
 Graph g1= new  MultiGraph("db");
 g1.addAttribute("ui.stylesheet", "ui.label"," node.att{shape:box;}");
 Node n1 = g1.addNode("a");
 n1.setAttribute("ui.class","att");
 g1.display();

But in display the node is not box and is circle with this message in the output: 但是在显示中,该节点不是框,并且在输出中带有以下消息:

" Error with stylesheet specification what to do with '[Ljava.lang.Object;@192b996' ? " “样式表规范错误,如何处理'[Ljava.lang.Object; @ 192b996'?”

Where i was wrong? 我哪里错了? Thanks for any help. 谢谢你的帮助。

import javax.swing.JFrame;
import javax.swing.JPanel;

import org.graphstream.graph.*;
import org.graphstream.graph.implementations.*;
import org.graphstream.ui.spriteManager.Sprite;
import org.graphstream.ui.spriteManager.SpriteManager;
import org.graphstream.ui.swingViewer.View;
import org.graphstream.ui.swingViewer.Viewer;

public class Main {
    /**
     * @param args
     */
    public static void main(String[] args) {
        Graph graph = new MultiGraph("graph");

        String styleSheet="node {"+
   " fill-color: grey;"+
   " size: 10px;"+
   " stroke-mode: plain;"+
   " stroke-color: black;"+
   " stroke-width: 1px;"+
   "}"+
   "node.important {"+
   " fill-color: red;"+
   " size: 30px;"+
   "}";

        graph.addNode("A");
        graph.addNode("B");
        graph.addEdge("AB", "A", "B");
        Node e1=graph.getNode("A");
        graph.addAttribute("ui.stylesheet", styleSheet);

        e1.addAttribute("ui.class", "important"); 
        e1.addAttribute("ui.label", "A Node");
        //e1.addAttribute( "ui.hide" );

        graph.display();
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM