protected void renderGraph(Graphics2D g2d) {
    if (renderContext.getGraphicsContext() == null) {
      renderContext.setGraphicsContext(new GraphicsDecorator(g2d));
    } else {
      renderContext.getGraphicsContext().setDelegate(g2d);
    }
    renderContext.setScreenDevice(this);
    Layout<V, E> layout = model.getGraphLayout();

    g2d.setRenderingHints(renderingHints);

    // the size of the VisualizationViewer
    Dimension d = getSize();

    // clear the offscreen image
    g2d.setColor(getBackground());
    g2d.fillRect(0, 0, d.width, d.height);

    AffineTransform oldXform = g2d.getTransform();
    AffineTransform newXform = new AffineTransform(oldXform);
    // AffineTransform newXform = new AffineTransform();
    newXform.concatenate(
        renderContext.getMultiLayerTransformer().getTransformer(Layer.VIEW).getTransform());
    //        		viewTransformer.getTransform());

    g2d.setTransform(newXform);

    // if there are  preRenderers set, paint them
    for (Paintable paintable : preRenderers) {

      if (paintable.useTransform()) {
        paintable.paint(g2d);
      } else {
        g2d.setTransform(oldXform);
        paintable.paint(g2d);
        g2d.setTransform(newXform);
      }
    }

    if (layout instanceof Caching) {
      ((Caching) layout).clear();
    }

    renderer.render(renderContext, layout);

    // if there are postRenderers set, do it
    for (Paintable paintable : postRenderers) {

      if (paintable.useTransform()) {
        paintable.paint(g2d);
      } else {
        g2d.setTransform(oldXform);
        paintable.paint(g2d);
        g2d.setTransform(newXform);
      }
    }
    g2d.setTransform(oldXform);
  }
예제 #2
0
  private void test(
      final DOMNode p,
      final DOMNode text,
      final String content,
      final String expected,
      final RenderContext context)
      throws FrameworkException {

    text.setTextContent(content);

    // clear queue
    context.getBuffer().getQueue().clear();
    p.render(context, 0);

    assertEquals(
        "Invalid JavaScript evaluation result", expected, concat(context.getBuffer().getQueue()));
  }
예제 #3
0
    /**
     * Initialization call-back. We initialize our renderer here.
     *
     * @param r the render context that is associated with this render panel
     */
    public void init(RenderContext r) {
      renderContext = r;
      renderContext.setSceneManager(sceneManager);

      // Register a timer task
      Timer timer = new Timer();
      angle = 0.01f;
      timer.scheduleAtFixedRate(new AnimationTask(), 0, 10);
    }
 public void draw(RenderContext context) {
   context.beginTransformation();
   context.translate(offset.add(new Vector(isVerticallyMirrored ? 1 : 0, 0)));
   context.translate(rotationCenter);
   context.scale(scale.multiply(new Vector(isVerticallyMirrored ? -1 : 1, 1)));
   context.rotate(angle);
   context.translate(rotationCenter.negate());
   drawable.draw(context);
   context.endTransformation();
 }
  /**
   * Create an instance with passed parameters.
   *
   * @param model
   * @param renderer
   * @param preferredSize initial preferred size of the view
   */
  @SuppressWarnings("unchecked")
  public BasicVisualizationServer(VisualizationModel<V, E> model, Dimension preferredSize) {
    this.model = model;
    //        renderContext.setScreenDevice(this);
    model.addChangeListener(this);
    setDoubleBuffered(false);
    this.addComponentListener(new VisualizationListener(this));

    setPickSupport(new ShapePickSupport<V, E>(this));
    setPickedVertexState(new MultiPickedState<V>());
    setPickedEdgeState(new MultiPickedState<E>());

    renderContext.setEdgeDrawPaintTransformer(
        new PickableEdgePaintTransformer<E>(getPickedEdgeState(), Color.black, Color.cyan));
    renderContext.setVertexFillPaintTransformer(
        new PickableVertexPaintTransformer<V>(getPickedVertexState(), Color.red, Color.yellow));

    setPreferredSize(preferredSize);
    renderingHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    renderContext.getMultiLayerTransformer().addChangeListener(this);
  }
예제 #6
0
  /**
   * Creates a master shape of the letter.
   *
   * @param shape
   * @return the master shape
   */
  private final Master createMaster(RenderContext ctx, Shape shape, double ascent) {
    final Area area = new Area(shape);
    final double scale = MASTER_HEIGHT / ascent;

    area.transform(AffineTransform.getScaleInstance(scale, scale));
    final Rectangle bounds = area.getBounds();
    // System.out.println("createMaster bounds " + bounds);
    // area.transform(AffineTransform.getTranslateInstance(-bounds.getMinX(),
    // -bounds.getMinY()));
    // bounds = area.getBounds();

    final int minX = (int) (bounds.getMinX() - 0.5);
    final int maxX = (int) (bounds.getMaxX() + 0.5);
    final int minY = (int) (bounds.getMinY() - 0.5);
    final int maxY = (int) (bounds.getMaxY() + 0.5);
    final int width = maxX - minX;
    final int height = maxY - minY;

    BitSet bits = (BitSet) ctx.getObject(BITS_NAME);
    if (bits == null) {
      bits = new BitSet(width * height);
      ctx.setObject(BITS_NAME, bits);
    } else {
      bits.clear();
    }
    int ofs = 0;
    for (int y = maxY; y > minY; y--) {
      for (int x = minX; x < maxX; x++) {
        if (area.contains(x, y)) {
          bits.set(ofs);
        }
        ofs++;
      }
    }

    return new Master(bits, width, height, minX, minY);
  }
예제 #7
0
  /** Draw rectangle to render context. */
  @Override
  public void draw(RenderContext g) {
    if (brush != null) {
      g.setBrush(
          brush,
          Math.min(xFrom, xTo),
          Math.min(yFrom, yTo),
          Math.abs(xFrom - xTo),
          Math.abs(yFrom - yTo));
      g.getCanvas().drawLine((float) xFrom, (float) yFrom, (float) xTo, (float) yTo, g.getPaint());
    }

    if (pen != null) {
      g.setPen(pen);
      g.getCanvas().drawLine((float) xFrom, (float) yFrom, (float) xTo, (float) yTo, g.getPaint());
    }
  }
예제 #8
0
  private RouteMatch _find(RenderContext context) {
    // Match first the static parameteters
    for (RouteParam param : routeParamArray) {
      RenderContext.Parameter entry = context.getParameter(param.name);
      if (entry != null && !entry.isMatched() && param.value.equals(entry.getValue())) {
        entry.remove(entry.getValue());
      } else {
        return null;
      }
    }

    // Match any request parameter
    for (RequestParam requestParamDef : requestParamArray) {
      RenderContext.Parameter entry = context.getParameter(requestParamDef.name);
      boolean matched = false;
      if (entry != null && !entry.isMatched()) {
        if (requestParamDef.matchPattern == null
            || context.matcher(requestParamDef.matchPattern).matches(entry.getValue())) {
          matched = true;
        }
      }
      if (matched) {
        entry.remove(entry.getValue());
      } else {
        switch (requestParamDef.controlMode) {
          case OPTIONAL:
            // Do nothing
            break;
          case REQUIRED:
            return null;
          default:
            throw new AssertionError();
        }
      }
    }

    // Match any pattern parameter
    if (this instanceof PatternRoute) {
      PatternRoute prt = (PatternRoute) this;
      for (int i = 0; i < prt.params.length; i++) {
        PathParam param = prt.params[i];
        RenderContext.Parameter s = context.getParameter(param.name);
        String matched = null;
        if (s != null && !s.isMatched()) {
          switch (param.encodingMode) {
            case FORM:
            case PRESERVE_PATH:
              for (int j = 0; j < param.matchingRegex.length; j++) {
                Regex renderingRegex = param.matchingRegex[j];
                if (context.matcher(renderingRegex).matches(s.getValue())) {
                  matched = param.templatePrefixes[j] + s.getValue() + param.templateSuffixes[j];
                  break;
                }
              }
              break;
            default:
              throw new AssertionError();
          }
        }
        if (matched != null) {
          s.remove(matched);
        } else {
          return null;
        }
      }
    }

    //
    if (context.isEmpty() && terminal) {
      Map<QualifiedName, String> matches = Collections.emptyMap();
      for (QualifiedName name : context.getNames()) {
        RenderContext.Parameter parameter = context.getParameter(name);
        if (matches.isEmpty()) {
          matches = new HashMap<QualifiedName, String>();
        }
        String match = parameter.getMatch();
        matches.put(name, match);
      }
      return new RouteMatch(context, this, matches);
    }

    //
    for (Route route : children) {
      RouteMatch a = route.find(context);
      if (a != null) {
        return a;
      }
    }

    //
    return null;
  }
예제 #9
0
 final RouteMatch find(RenderContext context) {
   context.enter();
   RouteMatch route = _find(context);
   context.leave();
   return route;
 }
예제 #10
0
  @Test
  public void testScripting() {

    NodeInterface detailsDataObject = null;
    Page page = null;
    DOMNode html = null;
    DOMNode head = null;
    DOMNode body = null;
    DOMNode title = null;
    DOMNode div = null;
    DOMNode p = null;
    DOMNode text = null;

    try (final Tx tx = app.tx()) {

      detailsDataObject = app.create(TestOne.class, "TestOne");
      page = Page.createNewPage(securityContext, "testpage");

      page.setProperties(
          page.getSecurityContext(), new PropertyMap(Page.visibleToPublicUsers, true));

      assertTrue(page != null);
      assertTrue(page instanceof Page);

      html = (DOMNode) page.createElement("html");
      head = (DOMNode) page.createElement("head");
      body = (DOMNode) page.createElement("body");
      title = (DOMNode) page.createElement("title");
      div = (DOMNode) page.createElement("div");
      p = (DOMNode) page.createElement("p");
      text = (DOMNode) page.createTextNode("x");

      // add HTML element to page
      page.appendChild(html);

      // add HEAD and BODY elements to HTML
      html.appendChild(head);
      html.appendChild(body);

      // add TITLE element to HEAD
      head.appendChild(title);

      body.appendChild(div);
      div.appendChild(p);

      final PropertyMap changedProperties = new PropertyMap();
      changedProperties.put(DOMElement.restQuery, "/divs");
      changedProperties.put(DOMElement.dataKey, "div");
      p.setProperties(p.getSecurityContext(), changedProperties);

      p.appendChild(text);

      tx.success();

    } catch (FrameworkException fex) {

      fail("Unexpected exception");
    }

    try (final Tx tx = app.tx()) {

      final RenderContext ctx =
          new RenderContext(
              securityContext,
              new RequestMockUp(),
              new ResponseMockUp(),
              RenderContext.EditMode.NONE);
      ctx.setDetailsDataObject(detailsDataObject);
      ctx.setPage(page);

      test(p, text, "${{ return Structr.get('div').id}}", "<p>" + div.getUuid() + "</p>", ctx);
      test(p, text, "${{ return Structr.get('page').id}}", "<p>" + page.getUuid() + "</p>", ctx);
      test(p, text, "${{ return Structr.get('parent').id}}", "<p>" + p.getUuid() + "</p>", ctx);

      tx.success();

    } catch (FrameworkException fex) {

      logger.warn("", fex);
      fail("Unexpected exception.");
    }
  }
 /* (non-Javadoc)
  * @see edu.uci.ics.jung.visualization.VisualizationServer#setPickSupport(edu.uci.ics.jung.visualization.GraphElementAccessor)
  */
 public void setPickSupport(GraphElementAccessor<V, E> pickSupport) {
   renderContext.setPickSupport(pickSupport);
 }
 /* (non-Javadoc)
  * @see edu.uci.ics.jung.visualization.VisualizationServer#getPickSupport()
  */
 public GraphElementAccessor<V, E> getPickSupport() {
   return renderContext.getPickSupport();
 }