Package org.graphstream.ui.graphicGraph

Examples of org.graphstream.ui.graphicGraph.StyleGroup


   * @return The length from the node centre along the edge to position the
   *         arrow.
   */
  protected double evalTargetRadius(GraphicEdge edge, GraphMetrics metrics) {
    GraphicNode target = edge.to;
    StyleGroup group = target.getStyle();
    double w = metrics.lengthToGu(group.getSize(), 0);
    double h = group.getSize().size() > 1 ? metrics.lengthToGu(
        group.getSize(), 1) : w;

    if (w == h) {
      double b = group.getStrokeMode() != StrokeMode.NONE ? metrics
          .lengthToGu(group.getStrokeWidth()) : 0;
      return ((w / 2) + b);
    } else {
      return evalEllipseRadius(edge, w, h);
    }
  }
View Full Code Here


  }

  // Rendering

  protected void renderGraph(Graphics2D g) {
    StyleGroup style = graph.getStyle();

    setupGraphics(g);
    renderGraphBackground(g);
    renderBackLayer(g);
    camera.pushView(graph, g);
    renderGraphElements(g);

    if (style.getStrokeMode() != StyleConstants.StrokeMode.NONE
        && style.getStrokeWidth().value != 0) {
      GraphMetrics metrics = camera.getMetrics();
      Rectangle2D rect = new Rectangle2D.Double();
      double px1 = metrics.px1;
      Value stroke = style.getShadowWidth();

      rect.setFrame(metrics.lo.x, metrics.lo.y + px1,
          metrics.size.data[0] - px1, metrics.size.data[1] - px1);
      g.setStroke(new BasicStroke((float) metrics.lengthToGu(stroke)));
      g.setColor(graph.getStyle().getStrokeColor(0));
View Full Code Here

   *
   * @param g
   *            The Swing graphics.
   */
  protected void renderGraphBackground(Graphics2D g) {
    StyleGroup group = graph.getStyle();

    if (group.getFillMode() != FillMode.NONE) {
      g.setColor(group.getFillColor(0));
      g.fillRect(0, 0, (int) camera.getMetrics().viewport[2],
          (int) camera.getMetrics().viewport[3]);
    }
  }
View Full Code Here

  public void testStyleEvents() {
    StyleGroupSet sgs = new StyleGroupSet(stylesheet);

    populateGroupSet(sgs);

    StyleGroup sA = sgs.getStyleForElement(A);
    StyleGroup sB = sgs.getStyleForElement(B);
    StyleGroup sC = sgs.getStyleForElement(C);
    StyleGroup sD = sgs.getStyleForElement(D);

    assertEquals(1, sA.getStrokeWidth().value, 0);
    assertEquals(1, sB.getStrokeWidth().value, 0);
    assertEquals(1, sC.getStrokeWidth().value, 0);
    assertEquals(1, sD.getStrokeWidth().value, 0);

    // Test global events (events that apply to a whole group or groups).

    sgs.pushEvent("clicked"); // This is normally done automatically by the
                  // GraphicElement

    sA = sgs.getStyleForElement(A);
    sB = sgs.getStyleForElement(B);
    sC = sgs.getStyleForElement(C);
    sD = sgs.getStyleForElement(D);

    assertEquals(2, sA.getStrokeWidth().value, 0);
    assertEquals(3, sB.getStrokeWidth().value, 0);
    assertEquals(3, sC.getStrokeWidth().value, 0);
    assertEquals(3, sD.getStrokeWidth().value, 0);

    sgs.popEvent("clicked"); // This is normally done automatically by the
                  // GraphicElement

    sA = sgs.getStyleForElement(A);
    sB = sgs.getStyleForElement(B);
    sC = sgs.getStyleForElement(C);
    sD = sgs.getStyleForElement(D);

    assertEquals(1, sA.getStrokeWidth().value, 0);
    assertEquals(1, sB.getStrokeWidth().value, 0);
    assertEquals(1, sC.getStrokeWidth().value, 0);
    assertEquals(1, sD.getStrokeWidth().value, 0);

    sgs.pushEvent("clicked"); // Both events at a time.
    sgs.pushEvent("selected"); // They should cascade.

    sA = sgs.getStyleForElement(A);
    sB = sgs.getStyleForElement(B);
    sC = sgs.getStyleForElement(C);
    sD = sgs.getStyleForElement(D);

    assertEquals(4, sA.getStrokeWidth().value, 0);
    assertEquals(3, sB.getStrokeWidth().value, 0);
    assertEquals(3, sC.getStrokeWidth().value, 0);
    assertEquals(3, sD.getStrokeWidth().value, 0);

    sgs.popEvent("clicked"); // This is normally done automatically by the
                  // GraphicElement
    sgs.popEvent("selected"); // This is normally done automatically by the
                  // GraphicElement

    // Now test individual events, that is events that apply to
    // an individual element only.

    sA = sgs.getStyleForElement(A);

    assertFalse(sA.hasEventElements());

    sgs.pushEventFor(A, "clicked"); // This is normally done automatically
                    // by the GraphicElement
    sgs.pushEventFor(B, "clicked"); // This is normally done automatically
                    // by the GraphicElement

    sA = sgs.getStyleForElement(A);
    sB = sgs.getStyleForElement(B);
    sC = sgs.getStyleForElement(C);
    sD = sgs.getStyleForElement(D);

    assertTrue(sA.hasEventElements());

    assertEquals(1, sA.getStrokeWidth().value, 0); // Individual events must be
                          // activated
    assertEquals(1, sB.getStrokeWidth().value, 0); // to work, so just pushing
                          // them is not
    assertEquals(1, sC.getStrokeWidth().value, 0); // sufficient.
    assertEquals(1, sD.getStrokeWidth().value, 0);

    sA.activateEventsFor(A);
    assertEquals(2, sA.getStrokeWidth().value, 0); // Only A should change.
    assertEquals(1, sB.getStrokeWidth().value, 0);
    assertEquals(1, sC.getStrokeWidth().value, 0);
    assertEquals(1, sD.getStrokeWidth().value, 0);
    sA.deactivateEvents();
    sB.activateEventsFor(B);
    assertEquals(1, sA.getStrokeWidth().value, 0);
    assertEquals(3, sB.getStrokeWidth().value, 0); // B and all its group
                          // change.
    assertEquals(3, sC.getStrokeWidth().value, 0); // Therefore C also changes.
    assertEquals(1, sD.getStrokeWidth().value, 0);
    sB.deactivateEvents();

    sgs.popEventFor(A, "clicked"); // This is normally done automatically by
                    // the GraphicElement
    sgs.popEventFor(B, "clicked"); // This is normally done automatically by
                    // the GraphicElement

    // Now two individual events at a time.

    sgs.pushEventFor(A, "clicked"); // This is normally done automatically
                    // by the GraphicElement
    sgs.pushEventFor(A, "selected"); // This is normally done automatically
                      // by the GraphicElement

    sA = sgs.getStyleForElement(A);
    sB = sgs.getStyleForElement(B);
    sC = sgs.getStyleForElement(C);
    sD = sgs.getStyleForElement(D);

    assertEquals(1, sA.getStrokeWidth().value, 0); // Individual events must be
                          // activated
    assertEquals(1, sB.getStrokeWidth().value, 0); // to work, so just pushing
                          // them is not
    assertEquals(1, sC.getStrokeWidth().value, 0); // sufficient.
    assertEquals(1, sD.getStrokeWidth().value, 0);

    sA.activateEventsFor(A);
    assertEquals(4, sA.getStrokeWidth().value, 0); // Only A should change,
                          // "selected" has
    assertEquals(1, sB.getStrokeWidth().value, 0); // precedence over "clicked"
                          // since added
    assertEquals(1, sC.getStrokeWidth().value, 0); // after.
    assertEquals(1, sD.getStrokeWidth().value, 0);
    sA.deactivateEvents();

    sgs.popEventFor(A, "clicked"); // This is normally done automatically by
                    // the GraphicElement
    sgs.popEventFor(A, "selected"); // This is normally done automatically
View Full Code Here

    shadow = sgs.getShadowIterator();
    count = 0;

    while (shadow.hasNext()) {
      StyleGroup g = shadow.next();
      assertTrue(groups.contains(g.getId()));
      count++;
    }

    assertTrue(count == 3); // There are three node groups.

    // Then we add a style that adds shadows to a specific edge.

    stylesheet.parseFromString(styleSheet9);
    assertTrue(sgs.getGroupCount() == 6);
    groups.add("e_AB");

    shadow = sgs.getShadowIterator();
    count = 0;

    while (shadow.hasNext()) {
      StyleGroup g = shadow.next();
      assertTrue(groups.contains(g.getId()));
      count++;
    }

    assertTrue(count == 4); // Three node groups, plus one edge group (e_AB)
  }
View Full Code Here

    StyleGroupSet sgs = new StyleGroupSet(stylesheet);

    populateGroupSet(sgs);

    StyleGroup sA = sgs.getStyleForElement(A);
    StyleGroup sB = sgs.getStyleForElement(B);
    StyleGroup sC = sgs.getStyleForElement(C);
    StyleGroup sD = sgs.getStyleForElement(D);

    // First test the basic iterator. B and C should be in the same group.

    assertTrue(sB == sC); // B and C are in the same group.
    assertFalse(sA == sB);
View Full Code Here

TOP

Related Classes of org.graphstream.ui.graphicGraph.StyleGroup

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.