private PPath redrawArrows(double... curve) {
    double[] sub = subdivide(curve, ARROW_LENGTH);

    double x1 = sub[0];
    double y1 = sub[1];
    double x4 = sub[6];
    double y4 = sub[7];

    Point2D e = makeDistanceFromOrigin(x1 - x4, y1 - y4, ARROW_LENGTH);
    x1 = x4 + e.getX();
    y1 = y4 + e.getY();

    // arrow tails
    double m = (y4 - y1) / (x4 - x1);
    double at_x1 = x1 + m * ARROW_WIDTH / Math.sqrt(m * m + 1);
    double at_y1 = y1 - ARROW_WIDTH / Math.sqrt(m * m + 1);
    double at_x2 = x1 - m * ARROW_WIDTH / Math.sqrt(m * m + 1);
    double at_y2 = y1 + ARROW_WIDTH / Math.sqrt(m * m + 1);
    a1.reset();
    a1.moveTo((float) at_x1, (float) at_y1);
    a1.lineTo((float) at_x2, (float) at_y2);
    a1.lineTo((float) x4, (float) y4);
    a1.lineTo((float) at_x1, (float) at_y1);

    return a1;
  }
  @Override
  public void initialize() {
    setSize(800, 600);
    setResizable(false);
    final PCanvas canvas = getCanvas();
    layer = canvas.getLayer();

    addEnds();
    addControls();
    addLines();
    addMessage();
    addHandles();
    addArrows();

    PDragEventHandler drag =
        new PDragEventHandler() {
          // override drag to only permit horizontal dragging
          protected void drag(final PInputEvent event) {
            final PDimension d = event.getDeltaRelativeTo(getDraggedNode());
            getDraggedNode().localToParent(d);
            getDraggedNode().offset(d.getWidth(), 0);
            event.setHandled(true);
            redrawAll();
          }
        };
    h1.addInputEventListener(drag);
    h2.addInputEventListener(drag);

    redrawAll();
  }
Esempio n. 3
0
  /** The mouse is getting dragged - create an SVET_MOUSE event. */
  @Override
  public void mouseDragged(PInputEvent e) {
    processEvent(
        new SVEvent(
            SVEventType.SVET_MOUSE,
            svWindow,
            (int) e.getPosition().getX(),
            (int) e.getPosition().getY(),
            (int) e.getPosition().getX() - lastX,
            (int) e.getPosition().getY() - lastY,
            null));

    // Paint a selection rectangle.
    if (selection == null) {
      startX = (int) e.getPosition().getX();
      startY = (int) e.getPosition().getY();
      selection = PPath.createRectangle(startX, startY, 1, 1);
      selection.setTransparency(rubberBandTransparency);
      svWindow.canvas.getLayer().addChild(selection);
    } else {
      int right = Math.max(startX, (int) e.getPosition().getX());
      int left = Math.min(startX, (int) e.getPosition().getX());
      int bottom = Math.max(startY, (int) e.getPosition().getY());
      int top = Math.min(startY, (int) e.getPosition().getY());
      svWindow.canvas.getLayer().removeChild(selection);
      selection = PPath.createRectangle(left, top, right - left, bottom - top);
      selection.setPaint(Color.YELLOW);
      selection.setTransparency(rubberBandTransparency);
      svWindow.canvas.getLayer().addChild(selection);
    }
  }
Esempio n. 4
0
  protected void calcConnectorLine() {
    Polygon linePoints = getRawPolygon();

    connectorLine = new PPath();
    connectorLine.setStroke(stroke);
    connectorLine.setStrokePaint(this.color);

    applyAffineTransform(linePoints);
  }
Esempio n. 5
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);
    }
  }
Esempio n. 6
0
  ///////////////////////////////////////////////////////////////////////////
  /// Marquee
  protected void initializeMarquee(PInputEvent e) {
    marquee = PPath.createRectangle((float) presspt.getX(), (float) presspt.getY(), 0, 0);
    marquee.setPaint(marqueePaint);
    marquee.setTransparency(marqueePaintTransparency);
    marquee.setStrokePaint(marqueeStrokePaint);
    marquee.setStroke(strokes[0]);

    marqueeParent.getPiccolo().addChild(marquee);

    marqueeObjects.clear();
  }
Esempio n. 7
0
 public void updateEdgeColorsTo(double value) {
   PPath ppath = getEdgePPath();
   if (ppath != null) {
     double normValue = normalizeForColorScale(value);
     if (isSelfLoop) {
       ppath.setPaint(createPaintFor(normValue));
     } else {
       ppath.setStrokePaint(createPaintFor(normValue));
     }
   }
 }
Esempio n. 8
0
 public void updateEdgeWidthTo(double value) {
   PPath ppath = getEdgePPath();
   if (ppath != null) {
     if (isSelfLoop) {
       //        ppath.setBounds(getSelfLoopBoundsFor(value));
       ppath.setPathTo(createSelfLoopShape());
       ppath.setStroke(null);
     } else {
       double strokeWidth = normalizeForWidthScale(value);
       Stroke stroke = createStrokeFor(strokeWidth);
       ppath.setStroke(stroke);
     }
   }
   updateVisibilityFor(value);
 }
    public VisualFlowMapLayer(VisualFlowMap visualFlowMap, PCamera camera) {
      this.visualFlowMap = visualFlowMap;
      this.camera = camera;
      this.camera.addLayer(this);
      //      this.camera.addChild(visualFlowMap.getTooltipBox());

      // border
      pp = new PPath(new PBounds(0, 0, 1, 1));
      pp.setStroke(new PFixedWidthStroke(2));
      pp.setStrokePaint(Color.gray);
      camera.addChild(pp);

      visualFlowMap.setFlowWeightAttrLabelVisibile(true);

      addChild(visualFlowMap);
    }
Esempio n. 10
0
 public void setHighlighted(
     boolean value, boolean showDirection, boolean asOutgoing, boolean propagateEvent) {
   if (this.highlighted != value) {
     this.highlighted = value;
     PPath ppath = getEdgePPath();
     if (ppath != null) {
       Paint paint;
       if (value) {
         Color color;
         if (showDirection) {
           if (asOutgoing) {
             color = visualFlowMap.getColor(ColorCodes.EDGE_STROKE_HIGHLIGHTED_OUTGOING_PAINT);
           } else {
             color = visualFlowMap.getColor(ColorCodes.EDGE_STROKE_HIGHLIGHTED_INCOMING_PAINT);
           }
         } else {
           color = visualFlowMap.getColor(ColorCodes.EDGE_STROKE_HIGHLIGHTED_PAINT);
         }
         paint = color;
       } else {
         paint = createPaintFor(normalizeForColorScale(getEdgeWeight()));
       }
       ppath.setStrokePaint(paint);
     }
     repaint();
     if (propagateEvent) {
       if (logger.isDebugEnabled()) {
         logger.debug(
             (value ? "H" : "Unh")
                 + "ighlight edge ["
                 + getLabel()
                 + " ("
                 + visualFlowMap.getValueAttr()
                 + " = "
                 + getEdgeWeight()
                 + ")]");
       }
       getVisualFlowMap()
           .firePropertyChange(
               VisualFlowMap.PROPERTY_CODE_HIGHLIGHTED,
               VisualFlowMap.PROPERTY_HIGHLIGHTED,
               Pair.of(edge, !value),
               Pair.of(edge, value));
     }
   }
 }
  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);
              }
            });
  }
 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);
 }
 public void adjustBounds(double x, double y, double w, double h) {
   PBounds viewBounds = getCamera().getViewBounds();
   getCamera().setBounds(x, y, w, h);
   pp.setBounds(x, y, w, h);
   visualFlowMap.updateFlowWeightAttrLabel();
   if (!viewBounds.isEmpty()) {
     camera.setViewBounds(viewBounds);
   }
 }
Esempio n. 14
0
  /** This gets called continuously during the drag, and is used to animate the marquee */
  protected void dragActivityStep(PInputEvent aEvent) {
    if (marquee != null) {
      float origStrokeNum = strokeNum;

      // Increment by partial steps to slow down animation
      strokeNum = (strokeNum + 0.5f) % NUM_STROKES;
      if ((int) strokeNum != (int) origStrokeNum) {
        marquee.setStroke(strokes[(int) strokeNum]);
      }
    }
  }
Esempio n. 15
0
  public void initialize() {
    final PClip clip = new PClip();
    clip.setPathToEllipse(0, 0, 100, 100);
    clip.setPaint(Color.red);

    clip.addChild(PPath.createRectangle(20, 20, 100, 50));
    getCanvas().getLayer().addChild(clip);

    getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
    getCanvas().addInputEventListener(new PDragEventHandler());
  }
Esempio n. 16
0
  public void initialize() {
    final PComposite composite = new PComposite();

    final PNode circle = PPath.createEllipse(0, 0, 100, 100);
    final PNode rectangle = PPath.createRectangle(50, 50, 100, 100);
    final PNode text = new PText("Hello world!");

    composite.addChild(circle);
    composite.addChild(rectangle);
    composite.addChild(text);

    rectangle.rotate(Math.toRadians(45));
    rectangle.setPaint(Color.RED);

    text.scale(2.0);
    text.setPaint(Color.GREEN);

    getCanvas().getLayer().addChild(composite);
    getCanvas().removeInputEventListener(getCanvas().getPanEventHandler());
    getCanvas().addInputEventListener(new PDragEventHandler());
  }
 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);
 }
 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);
 }
Esempio n. 19
0
 @Override
 protected void paint(PPaintContext paintContext) {
   layoutManager.updateZoomLayout(paintContext.getScale());
   if (layoutManager.isZUIVisibleChanged()) {
     if (getParent() instanceof ElementView) {
       ((ElementView) getParent()).getLayoutManager().updateLayout();
     }
     for (ConnectionView cv : getConnections()) {
       cv.updateLine();
     }
   }
   if (layoutManager.isZUIVisible()) {
     super.paint(paintContext);
   }
 }
Esempio n. 20
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);
  }
Esempio n. 21
0
  @SuppressWarnings("unchecked")
  protected void updateMarquee(PInputEvent pie) {
    PBounds b = new PBounds();

    if (marqueeParent.getPiccolo() instanceof PCamera) {
      b.add(canvasPressPt);
      b.add(pie.getCanvasPosition());
    } else {
      b.add(presspt);
      b.add(pie.getPosition());
    }

    b.reset();
    b.add(presspt);
    b.add(pie.getPosition());

    PBounds marqueeBounds = (PBounds) b.clone();

    selectableParent.globalToLocal(marqueeBounds);
    marqueeParent.viewToLocal(marqueeBounds);
    // marquee.globalToLocal(b);

    marquee.setPathToRectangle(
        (float) marqueeBounds.x,
        (float) marqueeBounds.y,
        (float) marqueeBounds.width,
        (float) marqueeBounds.height);

    allObjects.clear();
    PNodeFilter filter = new BoundsFilter(b);

    Collection<PNode> items;

    items = selectableParent.getPiccolo().getAllNodes(filter, null);

    Iterator<PNode> itemsIt = items.iterator();
    while (itemsIt.hasNext()) {
      PNode next = itemsIt.next();
      if (next instanceof PiccoloNodeInWorld) {
        WorldObjectImpl wo = (WorldObjectImpl) ((PiccoloNodeInWorld) next).getWorldObject();
        allObjects.add(wo);
      }
    }
  }
Esempio n. 22
0
  public void endSelection(boolean unselect) {
    if (marquee != null) {
      // Remove marquee
      marquee.removeFromParent();
      marquee = null;
    }
    if (!shouldStartMarqueeMode()) {
      if (dragAction != null) {
        dragAction.setFinalPositions();
        dragAction.doAction();
        dragAction = null;
      }

      if (unselect
          && (pressNode == null || pressNode instanceof Window)
          && getSelection().size() > 0) {
        unselectAll();
      }
      endStandardSelection();
    }
  }
Esempio n. 23
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");
          }
        });
  }
Esempio n. 24
0
 @Override
 public void addChild(int index, PNode child) {
   super.addChild(index, child);
   layoutManager.addNode(child);
 }
  private void redrawAll() {
    l1.setOffset(h1.getXOffset() + h1.getWidth() / 2, l1.getYOffset());
    l2.setOffset(h2.getXOffset() + h2.getWidth() / 2, l2.getYOffset());

    n1.setOffset(h1.getXOffset(), n1.getYOffset());
    n2.setOffset(h2.getXOffset(), n2.getYOffset());

    Point2D c1 = n1.getFullBounds().getCenter2D();
    Point2D c2 = n2.getFullBounds().getCenter2D();

    double dist = Math.abs(n2.getXOffset() - N - n1.getXOffset());
    double t = dist < F ? dist / F : 1;

    Point2D t1 = translate(rotate(new Point2D.Double(R[0] * (1 - t), 0), -A[0]), c1);
    Point2D t2 = translate(rotate(new Point2D.Double(R[1], 0), -A[1]), clipX(c2, c1));
    t2 =
        translate(
            makeDistanceFromOrigin(
                t2.getX() - c1.getX(), t2.getY() - c1.getY(), dist(t2, c1) * (1 - t)),
            c1);

    k1.centerBoundsOnPoint(t1.getX(), t1.getY());
    k2.centerBoundsOnPoint(t2.getX(), t2.getY());

    arc.reset();
    arc.moveTo((float) c1.getX(), (float) c1.getY());
    arc.curveTo(
        (float) t1.getX(), (float) t1.getY(),
        (float) t2.getX(), (float) t2.getY(),
        (float) c2.getX(), (float) c2.getY());

    redrawArrows(
        c1.getX(), c1.getY(),
        t1.getX(), t1.getY(),
        t2.getX(), t2.getY(),
        c2.getX(), c2.getY());
  }
Esempio n. 26
0
 public Polygon getPolygon() {
   return calico.utils.Geometry.getPolyFromPath(
       connectorLine.getPathReference().getPathIterator(null));
 }
Esempio n. 27
0
 public static PPath rect(double x, double y, double w, double h, Paint stroke, Paint fill) {
   PPath rect = new PPath(new Rectangle2D.Double(x, y, w, h));
   rect.setPaint(fill);
   rect.setStrokePaint(stroke);
   return rect;
 }
Esempio n. 28
0
 protected PBounds getMarqueeBounds() {
   if (marquee != null) {
     return marquee.getBounds();
   }
   return new PBounds();
 }
Esempio n. 29
0
 public GeneralPath getPathReference() {
   return connectorLine.getPathReference();
 }
Esempio n. 30
0
 protected void applyAffineTransform(Polygon points) {
   PAffineTransform piccoloTextTransform = getPTransform(points);
   GeneralPath p =
       (GeneralPath) getBezieredPoly(points).createTransformedShape(piccoloTextTransform);
   connectorLine.setPathTo(p);
 }