Exemple #1
0
 @Override
 protected void doActivate() {
   super.doActivate();
   getContent().addPropertyChangeListener(edgeAttributesPropertyChangeListener);
   // add label part
   if (edgeLabelPart == null) {
     edgeLabelPart = injector.getInstance(EdgeLabelPart.class);
     edgeLabelPart.getVisual().getStyleClass().add(CSS_CLASS_LABEL);
     getParent().addChild(edgeLabelPart);
     edgeLabelPart.addAnchorage(this);
   }
 }
Exemple #2
0
  @Override
  public void doRefreshVisual(FXConnection visual) {
    GraphLayoutContext glc = getGraphLayoutContext();
    if (glc == null || edgeLabelPart == null) {
      return;
    }

    Edge edge = getContent();
    Map<String, Object> attrs = edge.getAttrs();
    FXGeometryNode<ICurve> curveNode = visual.getCurveNode();

    // css class
    visual.getStyleClass().clear();
    visual.getStyleClass().add(CSS_CLASS);
    if (attrs.containsKey(ZestProperties.ELEMENT_CSS_CLASS)) {
      String cssClass = ZestProperties.getCssClass(edge);
      visual.getStyleClass().add(cssClass);
    }

    // css id
    if (attrs.containsKey(ZestProperties.ELEMENT_CSS_ID)) {
      String cssId = ZestProperties.getCssId(edge);
      visual.setId(cssId);
    }

    // css style
    if (attrs.containsKey(ZestProperties.EDGE_CURVE_CSS_STYLE)) {
      String connCssStyle = ZestProperties.getEdgeCurveCssStyle(edge);
      curveNode.setStyle(connCssStyle);
    }
    if (attrs.containsKey(ZestProperties.EDGE_LABEL_CSS_STYLE)) {
      String textCssStyle = ZestProperties.getEdgeLabelCssStyle(edge);
      edgeLabelPart.getVisual().setStyle(textCssStyle);
    }

    // label
    Object label = attrs.get(ZestProperties.ELEMENT_LABEL);
    if (label instanceof String) {
      edgeLabelPart.getVisual().setText((String) label);
    }

    // default decoration for directed graphs
    if (ZestProperties.GRAPH_TYPE_DIRECTED.equals(ZestProperties.getType(glc.getGraph(), true))) {
      visual.setEndDecoration(new ArrowHead());
    } else {
      visual.setEndDecoration(null);
    }

    // custom decoration
    IFXDecoration sourceDecoration = ZestProperties.getSourceDecoration(edge);
    if (sourceDecoration != null) {
      visual.setStartDecoration(sourceDecoration);
    }
    IFXDecoration targetDecoration = ZestProperties.getTargetDecoration(edge);
    if (targetDecoration != null) {
      visual.setEndDecoration(targetDecoration);
    }

    // connection router
    IFXConnectionRouter router = ZestProperties.getRouter(edge);
    if (router != null) {
      visual.setRouter(router);
    }

    // dashes
    Object style = attrs.get(ZestProperties.EDGE_STYLE);
    if (style == ZestProperties.EDGE_STYLE_DASHED) {
      curveNode.getStrokeDashArray().setAll(DASH_LENGTH, GAP_LENGTH);
    } else if (style == ZestProperties.EDGE_STYLE_DASHDOT) {
      curveNode.getStrokeDashArray().setAll(DASH_LENGTH, GAP_LENGTH, DOT_LENGTH, GAP_LENGTH);
    } else if (style == ZestProperties.EDGE_STYLE_DASHDOTDOT) {
      curveNode
          .getStrokeDashArray()
          .setAll(DASH_LENGTH, GAP_LENGTH, DOT_LENGTH, GAP_LENGTH, DOT_LENGTH, GAP_LENGTH);
    } else if (style == ZestProperties.EDGE_STYLE_DOTTED) {
      curveNode.getStrokeDashArray().setAll(DOT_LENGTH, GAP_LENGTH);
    } else {
      curveNode.getStrokeDashArray().clear();
    }
  }