Package org.graphstream.graph.implementations

Examples of org.graphstream.graph.implementations.MultiGraph


    // 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


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

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

    graph.getNumber("foo");
  }
 
  @Test(expected=NullAttributeException.class)
  public void testElementValueAttributeNull4() {
    Graph graph = new MultiGraph("g");
    graph.setNullAttributesAreErrors(true);
    graph.addAttribute("foo","ah ah ah");
    graph.getNumber("foo");
  }
View Full Code Here

    graph.getNumber("foo");
  }
 
  @Test(expected=NullAttributeException.class)
  public void testElementValueAttributeNull5() {
    Graph graph = new MultiGraph("g");
    graph.setNullAttributesAreErrors(true);
    graph.getLabel("foo");
  }
View Full Code Here

    graph.getLabel("foo");
  }
 
  @Test(expected=NullAttributeException.class)
  public void testElementValueAttributeNull6() {
    Graph graph = new MultiGraph("g");
    graph.setNullAttributesAreErrors(true);
    graph.addAttribute("foo",5);
    graph.getLabel("foo");
  }
View Full Code Here

    graph.getLabel("foo");
  }

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

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

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

    // Arrays
View Full Code Here

TOP

Related Classes of org.graphstream.graph.implementations.MultiGraph

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.