Ejemplo n.º 1
0
  public void initialize() {
    // create bar layers
    rowBarLayer = new PLayer();
    colBarLayer = new PLayer();

    // create bar nodes
    for (int i = 0; i < 10; i++) {
      // create row bar with node row1, row2,...row10
      PText p = new PText("Row " + i);
      p.setX(0);
      p.setY(nodeHeight * i + nodeHeight);
      p.setPaint(Color.white);
      colBarLayer.addChild(p);

      // create col bar with node col1, col2,...col10
      p = new PText("Col " + i);
      p.setX(nodeWidth * i + nodeWidth);
      p.setY(0);
      p.setPaint(Color.white);
      rowBarLayer.addChild(p);
    }

    // add bar layers to camera
    getCanvas().getCamera().addChild(rowBarLayer);
    getCanvas().getCamera().addChild(colBarLayer);

    // create matrix nodes
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        final PPath path =
            PPath.createRectangle(
                nodeWidth * j + nodeWidth,
                nodeHeight * i + nodeHeight,
                nodeWidth - 1,
                nodeHeight - 1);
        getCanvas().getLayer().addChild(path);
      }
    }

    // catch drag event and move bars corresponding
    getCanvas()
        .addInputEventListener(
            new PDragSequenceEventHandler() {
              Point2D oldP, newP;

              public void mousePressed(final PInputEvent aEvent) {
                oldP = getCanvas().getCamera().getViewBounds().getCenter2D();
              }

              public void mouseReleased(final PInputEvent aEvent) {
                newP = getCanvas().getCamera().getViewBounds().getCenter2D();
                colBarLayer.translate(
                    0, (oldP.getY() - newP.getY()) / getCanvas().getLayer().getScale());
                rowBarLayer.translate(
                    (oldP.getX() - newP.getX()) / getCanvas().getLayer().getScale(), 0);
              }
            });
  }
Ejemplo n.º 2
0
  private static void paintNodeRecursively(PLayer layer, Block node) {
    Rectangle r = node.getBounds();
    PPath rect = PPath.createRectangle(r.x, r.y, r.width, r.height);

    // Color randomColor = new Color(numGen.nextInt(256), numGen.nextInt(256), numGen.nextInt(256));
    // rect.setStrokePaint(randomColor);
    // if (node.isLeaf()){
    if (node.isText()) {
      rect.setStrokePaint(Color.red);
      rect.setPaint(null);
    } else if (node.isLeaf()) {
      rect.setStrokePaint(Color.green);
      // rect.setStrokePaint(Color.red);
      rect.setPaint(Color.green);
      rect.setTransparency(0.3f);
    } else {
      rect.setStrokePaint(Color.cyan);
      rect.setPaint(null);
    }

    layer.addChild(rect);

    for (Block child : node.getChildren()) {
      paintNodeRecursively(layer, child);
    }
  }
 private void addControls() {
   layer.addChild(k1 = PPath.createEllipse(0, 0, DIAM / 2, DIAM / 2));
   layer.addChild(k2 = PPath.createEllipse(0, 0, DIAM / 2, DIAM / 2));
   k1.setStrokePaint(lightBlue);
   k2.setStrokePaint(lightBlue);
   k1.setPickable(false);
   k2.setPickable(false);
 }
 private void addLines() {
   layer.addChild(l1 = PPath.createLine(0, 0, 0, 800));
   layer.addChild(l2 = PPath.createLine(0, 0, 0, 800));
   l1.setStrokePaint(Color.lightGray);
   l2.setStrokePaint(Color.lightGray);
   l1.setPickable(false);
   l2.setPickable(false);
 }
  @Override
  public void initialize() {
    final PSwingCanvas canvas = (PSwingCanvas) getCanvas();
    final PLayer layer = canvas.getLayer();
    final PCamera camera = canvas.getCamera();

    final PText text = new PText("Hello World");
    text.setConstrainHeightToTextHeight(false);
    text.setConstrainWidthToTextWidth(false);
    layer.addChild(text);

    JTextField textField = new JTextField(20);
    PSwing swing = new PSwing(textField);
    layer.addChild(swing);

    canvas.removeInputEventListener(canvas.getPanEventHandler());
    canvas.removeInputEventListener(canvas.getZoomEventHandler());
    canvas.addInputEventListener(new PSelectionEventHandler(layer, layer));
  }
 private void addEnds() {
   layer.addChild(n1 = PPath.createEllipse(0, 0, DIAM, DIAM));
   layer.addChild(n2 = PPath.createEllipse(0, 0, DIAM, DIAM));
   n1.setStrokePaint(veryLightGray);
   n2.setStrokePaint(veryLightGray);
   n1.setPickable(false);
   n2.setPickable(false);
   n1.offset(0, 225);
   n2.offset(0, 325);
 }
Ejemplo n.º 7
0
  public BufferedImage createImage() {
    final PCanvas canvas = new PCanvas();
    final PLayer layer = canvas.getLayer();

    final PImage background = new PImage(backgroundImage);
    layer.addChild(background);
    canvas.setBounds(0, 0, backgroundImage.getWidth(), backgroundImage.getHeight());

    PLayer foregroundLayer = new PLayer();
    layer.addChild(foregroundLayer);
    layer.addChild(foregroundLayer);

    for (Element element : getElements()) {
      PNode node = PNodeFactory.createFrom(element);
      foregroundLayer.addChild(node);
    }

    return VisionUtils.createComponentImage(canvas);

    // add memory release stuff
  }
Ejemplo n.º 8
0
  public void testPick() {
    PCanvas canvas = new PCanvas();
    PCamera camera = canvas.getCamera();
    PLayer layer = canvas.getLayer();

    camera.setBounds(0, 0, 100, 100);

    PNode a = PPath.createRectangle(0, 0, 100, 100);
    PNode b = PPath.createRectangle(0, 0, 100, 100);
    PNode c = PPath.createRectangle(0, 0, 100, 100);

    layer.addChild(a);
    layer.addChild(b);
    layer.addChild(c);

    PPickPath pickPath = camera.pick(50, 50, 2);

    assertTrue(pickPath.getPickedNode() == c);
    assertTrue(pickPath.nextPickedNode() == b);
    assertTrue(pickPath.nextPickedNode() == a);
    assertTrue(pickPath.nextPickedNode() == camera);
    assertTrue(pickPath.nextPickedNode() == null);
    assertTrue(pickPath.nextPickedNode() == null);
  }
Ejemplo n.º 9
0
  public void initialize() {
    // Create the Target for our Activities.

    // Create a new node that we will apply different activities to, and
    // place that node at location 200, 200.
    final PNode aNode = PPath.createRectangle(0, 0, 100, 80);
    final PLayer layer = getCanvas().getLayer();
    layer.addChild(aNode);
    aNode.setOffset(200, 200);

    // Extend PActivity.

    // Store the current time in milliseconds for use below.
    final long currentTime = System.currentTimeMillis();

    // Create a new custom "flash" activity. This activity will start
    // running in five seconds, and while it runs it will flash aNode's
    // paint between red and green every half second.
    final PActivity flash =
        new PActivity(-1, 500, currentTime + 5000) {
          boolean fRed = true;

          protected void activityStep(final long elapsedTime) {
            super.activityStep(elapsedTime);

            // Toggle the target node's brush color between red and green
            // each time the activity steps.
            if (fRed) {
              aNode.setPaint(Color.red);
            } else {
              aNode.setPaint(Color.green);
            }

            fRed = !fRed;
          }
        };

    // Schedule the activity.
    getCanvas().getRoot().addActivity(flash);

    // Create three activities that animate the node's position. Since our
    // node already descends from the root node the animate methods will
    // automatically schedule these activities for us.
    final PActivity a1 = aNode.animateToPositionScaleRotation(0, 0, 0.5, 0, 5000);
    final PActivity a2 =
        aNode.animateToPositionScaleRotation(100, 0, 1.5, Math.toRadians(110), 5000);
    final PActivity a3 = aNode.animateToPositionScaleRotation(200, 100, 1, 0, 5000);

    // The animate activities will start immediately (in the next call to
    // PRoot.processInputs) by default. Here we set their start times (in
    // PRoot global time) so that they start when the previous one has
    // finished.
    a1.setStartTime(currentTime);
    a2.startAfter(a1);
    a3.startAfter(a2);

    a1.setDelegate(
        new PActivity.PActivityDelegate() {
          public void activityStarted(final PActivity activity) {
            System.out.println("a1 started");
          }

          public void activityStepped(final PActivity activity) {}

          public void activityFinished(final PActivity activity) {
            System.out.println("a1 finished");
          }
        });
  }
Ejemplo n.º 10
0
 private void addToEdgeLayer(PEdgeView edge) {
   edgeLayer.addChild(edge);
 }
Ejemplo n.º 11
0
 private void addToNodeLayer(PNodeView node) {
   nodeLayer.addChild(node);
 }
 private void addMessage() {
   layer.addChild(arc = new PPath());
   arc.setPickable(false);
 }
 private void addArrows() {
   layer.addChild(a1 = new PPath());
   a1.setPaint(Color.white);
 }
 private void addHandles() {
   layer.addChild(h1 = PPath.createRectangle(0, 0, DIAM, DIAM));
   layer.addChild(h2 = PPath.createRectangle(0, 0, DIAM, DIAM));
   h1.offset(300, 120);
   h2.offset(400, 120);
 }