Package org.graphstream.graph

Examples of org.graphstream.graph.Graph


    // setLAF();
    new DemoViewerJComponents();
  }

  public DemoViewerJComponents() {
    Graph graph = new MultiGraph("main graph");
    ThreadProxyPipe toSwing = new ThreadProxyPipe(graph);
    Viewer viewer = new Viewer(toSwing);
    ProxyPipe fromSwing = viewer.newThreadProxyOnGraphicGraph();
    SpriteManager sman = new SpriteManager(graph);

    fromSwing.addAttributeSink(graph);
    viewer.addDefaultView(true);

    Node A = graph.addNode("A");
    Node B = graph.addNode("B");
    Node C = graph.addNode("C");

    graph.addEdge("AB", "A", "B");
    graph.addEdge("BC", "B", "C");
    graph.addEdge("CA", "C", "A");

    A.addAttribute("xyz", 0, 1, 0);
    B.addAttribute("xyz", 1, 0, 0);
    C.addAttribute("xyz", -1, 0, 0);

    A.addAttribute("ui.label", "Quit");
    B.addAttribute("ui.label", "Editable text");
    C.addAttribute("ui.label", "Click to edit");

    graph.addAttribute("ui.stylesheet", styleSheet);

    Sprite s1 = sman.addSprite("S1");
    Sprite s2 = sman.addSprite("S2");
    Sprite s3 = sman.addSprite("S3");

    s1.attachToNode("B");
    s2.attachToEdge("BC");
    s1.setPosition(StyleConstants.Units.PX, 1, 0, 0);
    s2.setPosition(0.5f);
    s3.setPosition(0, 0.5f, 0);
    s1.addAttribute("ui.label", "1");
    s2.addAttribute("ui.label", "2");
    // s3.addAttribute( "ui.label", "" );

    boolean loop = true;
    // float x = 0;
    // float y = 1;
    // float dir = 0.005f;
    float angle = 0;

    while (loop) {
      try {
        Thread.sleep(30);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }

      fromSwing.pump();

      if (graph.hasAttribute("ui.viewClosed")) {
        loop = false;
      } else {
        if (A.hasAttribute("ui.clicked")) {
          System.err.printf("A clicked (%s)%n",
              A.getLabel("ui.label"));
View Full Code Here


    // GraphicGraph -> Graph, the
    // graph only listen at attributes since we do not intend to add
    // elements directly in the
    // graphic graph.

    Graph main = new MultiGraph("main");
    ThreadProxyPipe toGraphic = new ThreadProxyPipe();
    toGraphic.init(main);
   
    InTheSwingThread viewerThread = new InTheSwingThread(toGraphic);
    ThreadProxyPipe toMain = viewerThread.getProxy();

    toMain.addAttributeSink(main); // Get the graphic graph proxy.

    // Now launch the graphic graph in the Swing thread using a Swing Timer.

    viewerThread.start();

    // We modify the graph in the main thread.

    Node A = main.addNode("A");
    Node B = main.addNode("B");
    Node C = main.addNode("C");
    main.addEdge("AB", "A", "B");
    main.addEdge("BC", "B", "C");
    main.addEdge("CA", "C", "A");

    SpriteManager sman = new SpriteManager(main);
    Sprite S1 = sman.addSprite("S1");
    Sprite S2 = sman.addSprite("S2");
    Sprite S3 = sman.addSprite("S3");

    S3.setPosition(1, 2, 2);
    S3.setPosition(2, 3, 2);
    S3.setPosition(3, 2, 1);

    A.addAttribute("ui.foo", "bar");
    B.addAttribute("ui.bar", "foo");
    C.addAttribute("truc"); // Not prefixed by UI, will not pass.
    S1.addAttribute("ui.foo", "bar");
    main.stepBegins(1);

    toMain.pump();

    // We ask the Swing thread to modify the graphic graph.

    main.stepBegins(2);
    main.addAttribute("ui.EQUIP"); // Remember GraphicGraph filters
                    // attributes.

    // Wait and stop.

    toMain.pump();
    sleep(1000);
    toMain.pump();

    main.addAttribute("ui.STOP");

    toMain.pump();
    sleep(1000);
    toMain.pump();

    // ****************************************************************************************
    // Now we can begin the real test. We ensure the timer in the Swing
    // graph stopped and check
    // If the two graphs (main and graphic) synchronized correctly.

    GraphicGraph graphic = viewerThread.graphic;

    assertTrue(viewerThread.isStopped());
    assertFalse(main.hasAttribute("ui.EQUIP"));
    assertFalse(graphic.hasAttribute("ui.EQUIP"));
    assertTrue(main.hasAttribute("ui.STOP"));
    assertTrue(graphic.hasAttribute("ui.STOP"));

    assertEquals(3, graphic.getStep(), 0);
    assertEquals(2, main.getStep(), 0); // We do not listen at elements events
                      // the step 3
                      // of the graphic graph did not
                      // reached us.
    // Assert all events passed toward the graphic graph.

    assertEquals(3, graphic.getNodeCount());
    assertEquals(3, graphic.getEdgeCount());
    assertEquals(3, graphic.getSpriteCount());
    assertNotNull(graphic.getNode("A"));
    assertNotNull(graphic.getNode("B"));
    assertNotNull(graphic.getNode("C"));
    assertNotNull(graphic.getEdge("AB"));
    assertNotNull(graphic.getEdge("BC"));
    assertNotNull(graphic.getEdge("CA"));
    assertNotNull(graphic.getSprite("S1"));
    assertNotNull(graphic.getSprite("S2"));
    assertEquals("bar", graphic.getNode("A").getAttribute("ui.foo"));
    assertEquals("foo", graphic.getNode("B").getAttribute("ui.bar"));
    // assertNull( graphic.getNode("C").getAttribute( "truc" ) ); // Should
    // not pass the attribute filter.
    assertEquals("bar", graphic.getSprite("S1").getAttribute("ui.foo"));
    assertEquals("bar", sman.getSprite("S1").getAttribute("ui.foo"));

    // Assert attributes passed back to the graph from the graphic graph.

    Object xyz1[] = { 4, 3, 2 };
    Object xyz2[] = { 2, 1, 0 };
    Object xyz3[] = { 3, 2, 1 };

    assertArrayEquals(xyz1, (Object[]) main.getNode("A")
        .getAttribute("xyz"));
    assertArrayEquals(xyz2, (Object[]) main.getNode("B")
        .getAttribute("xyz"));
    assertArrayEquals(xyz3, (Object[]) main.getNode("C")
        .getAttribute("xyz"));

    assertEquals("foobar", S2.getAttribute("ui.foobar"));

    GraphicSprite gs3 = graphic.getSprite("S3");
View Full Code Here

*
*/
public class ExampleSender {

  public static void main(String[] args) {
    Graph g = new MultiGraph("G");
    // - the sender
    NetStreamSender nsc = null;
    try {
      nsc = new NetStreamSender(2001);
    } catch (UnknownHostException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
   
    nsc.setPacker(new Base64Packer());
   
    // - plug the graph to the sender so that graph events can be
    // sent automatically
    g.addSink(nsc);
    // - generate some events on the client side
    String style = "node{fill-mode:plain;fill-color:#567;size:6px;}";
    g.addAttribute("stylesheet", style);
    g.addAttribute("ui.antialias", true);
    g.addAttribute("layout.stabilization-limit", 0);
    for (int i = 0; i < 500; i++) {
      g.addNode(i + "");
      if (i > 0) {
        g.addEdge(i + "-" + (i - 1), i + "", (i - 1) + "");
        g.addEdge(i + "--" + (i / 2), i + "", (i / 2) + "");
      }
    }
  }
View Full Code Here

  public static void main(String[] args) throws UnknownHostException, IOException, InterruptedException {
    // ----- On the receiver side -----
    //
    // - a graph that will display the received events
    Graph g = new MultiGraph("G",false,true);
    g.display();
    // - the receiver that waits for events
    NetStreamReceiver net = new NetStreamReceiver("localhost",2001,false);
   
    net.setUnpacker(new  Base64Unpacker());
   
View Full Code Here

  }

  public void test(TestEntry entry) throws IOException {
    System.out.printf("> \"%s\"\n", entry.ressourceName);
   
    Graph graph = new MultiGraph("foo");
    FileSourcePajek in = new FileSourcePajek();

    graph.addAttribute("ui.quality");
    if (!entry.veryLarge)
      graph.addAttribute("ui.antialias");
    if (entry.addLabels)
      graph.addAttribute(
          "ui.stylesheet",
          String.format(
              "node { text-alignment: center; size: %dpx; fill-color: grey; %s } edge { fill-color: #333; }",
              entry.veryLarge ? 6 : 16, entry.veryLarge ? ""
                  : "stroke-mode: plain; stroke-color: #333;"));
    else
      graph.addAttribute(
          "ui.stylesheet",
          String.format(
              "node { text-alignment: at-right; size: %dpx; fill-color: grey; %s text-background-mode: plain; text-offset: 2px, 0px; text-padding: 2px; text-background-color: #FFFFFFAA; } edge { fill-color: #333; }",
              entry.veryLarge ? 6 : 16, entry.veryLarge ? ""
                  : "stroke-mode: plain; stroke-color: #333;"));
   
    Viewer v = graph.display(entry.autoLayout);
    v.setCloseFramePolicy(CloseFramePolicy.CLOSE_VIEWER);
   
    in.addSink(graph);
    in.readAll(TestPajekParser.class
        .getResourceAsStream(entry.ressourceName));
View Full Code Here

      e.printStackTrace();
    }
  }
  public void testSmallFile() {
    try {
      Graph graph = new MultiGraph("foo");
      FileSourceGML source = new FileSourceGML();

      graph.addAttribute("ui.quality");
      graph.addAttribute("ui.antialias");
      //graph.addAttribute("ui.stylesheet", "node { text-size:8; text-color: #0008; text-alignment: at-right; } edge { text-size:8; text-color: #0008; }");
      graph.display();
      source.addSink(graph);
      source.begin(TestSourceGML.class.getResourceAsStream("SmallTest.gml"));
      while(source.nextEvents()) {}
      source.end();
    }
View Full Code Here

import org.junit.Test;

public class TestElement {
  @Test(expected=NullAttributeException.class)
  public void testElementSimpleAttributes() {
    Graph graph = new MultiGraph("g1");

    Node A = graph.addNode("A");

    assertEquals("A", A.getId());
    assertEquals(0, A.getAttributeCount());

    // Simple attributes.

    A.addAttribute("foo");

    assertEquals(1, A.getAttributeCount());
    assertTrue(A.hasAttribute("foo"));
    assertTrue(A.hasAttribute("foo", Boolean.class));
    assertFalse(A.hasLabel("foo"));
    assertFalse(A.hasNumber("foo"));
    assertFalse(A.hasVector("foo"));
    assertFalse(A.hasArray("foo"));
    assertFalse(A.hasHash("foo"));
    assertNotNull(A.getAttribute("foo"));
    assertEquals(true, A.getAttribute("foo"));
    assertEquals(Boolean.TRUE, A.getAttribute("foo"));

    // Change.

    A.changeAttribute("foo", false);

    assertEquals(1, A.getAttributeCount());
    assertTrue(A.hasAttribute("foo"));
    assertTrue(A.hasAttribute("foo", Boolean.class));
    assertFalse(A.hasLabel("foo"));
    assertFalse(A.hasNumber("foo"));
    assertFalse(A.hasVector("foo"));
    assertFalse(A.hasArray("foo"));
    assertFalse(A.hasHash("foo"));
    assertNotNull(A.getAttribute("foo"));
    assertEquals(false, A.getAttribute("foo"));
    assertEquals(Boolean.FALSE, A.getAttribute("foo"));

    // Removal.

    A.removeAttribute("foo");
    assertEquals(0, A.getAttributeCount());
    assertFalse(A.hasAttribute("foo"));
    assertNull(A.getAttribute("foo"));
   
    // Test null attributes checking.
   
    assertFalse(graph.nullAttributesAreErrors());
    graph.setNullAttributesAreErrors(true);
    assertTrue(graph.nullAttributesAreErrors());
    A.getAttribute("foo")// NullAttributeException thrown here.
  }
View Full Code Here

    A.getAttribute("foo")// NullAttributeException thrown here.
  }

  @Test
  public void testElementValueAttributes() {
    Graph graph = new MultiGraph("g1");

    Node A = graph.addNode("A");

    assertEquals("A", A.getId());
    assertEquals(0, A.getAttributeCount());

    // Label attributes.
View Full Code Here

    assertEquals(0, A.getAttributeCount());
  }
 
  @Test(expected=NullAttributeException.class)
  public void testElementValueAttributeNull1() {
    Graph graph = new MultiGraph("g");
    graph.setNullAttributesAreErrors(true);
    graph.getAttribute("nonExisting");
  }
View Full Code Here

    graph.getAttribute("nonExisting");
  }
 
  @Test(expected=NullAttributeException.class)
  public void testElementValueAttributeNull2() {
    Graph graph = new MultiGraph("g");
    graph.setNullAttributesAreErrors(true);
    graph.getFirstAttributeOf("nonExisting", "nonExisting2", "nonExisting3");
  }
View Full Code Here

TOP

Related Classes of org.graphstream.graph.Graph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.