Exemplo n.º 1
0
 private void removeFigureForNode(InternalNodeLayout internalNode) {
   IFigure figure = internalNode.getNode().getFigure();
   GraphLabel label = (GraphLabel) nodeFigureToLabel.get(figure);
   if (label != null && label.getParent() != null) {
     label.getParent().remove(label);
   }
   nodeFigureToLabel.remove(figure);
 }
Exemplo n.º 2
0
 public void fisheyeAdded(GraphWidget graph, IFigure originalFigure, IFigure fisheyeFigure) {
   originalFigure.removeFigureListener(nodeFigureListener);
   fisheyeFigure.addFigureListener(nodeFigureListener);
   GraphLabel label = (GraphLabel) nodeFigureToLabel.get(originalFigure);
   if (label == null) {
     return;
   }
   nodeFigureToLabel.put(fisheyeFigure, label);
   refreshLabelBounds(fisheyeFigure, label);
   addLabelForFigure(fisheyeFigure, label);
   LabelAncestorListener labelAncestorListener =
       new LabelAncestorListener(originalFigure, fisheyeFigure);
   label.addAncestorListener(labelAncestorListener);
   labelToAncestorListener.put(label, labelAncestorListener);
 }
Exemplo n.º 3
0
  void updateNodeLabel(InternalNodeLayout internalNode) {
    if (internalNode.isDisposed()) {
      return;
    }
    IFigure figure = internalNode.getNode().getFigure();
    GraphLabel label = (GraphLabel) nodeFigureToLabel.get(figure);
    IFigure fisheye = getFisheyeFigure(figure);
    if (fisheye != null) {
      figure = fisheye;
    }
    if (label == null) {
      label = new GraphLabel(false);
      label.setForegroundColor(ColorConstants.white);
      label.setBackgroundColor(ColorConstants.red);
      FontData fontData = Display.getDefault().getSystemFont().getFontData()[0];
      fontData.setHeight(6);
      label.setFont(new Font(Display.getCurrent(), fontData));
      figure.addFigureListener(nodeFigureListener);
      addLabelForFigure(figure, label);
      nodeFigureToLabel.put(figure, label);
    }

    GraphNode graphNode = internalNode.getNode();
    if (!graphNode.getGraphModel().canExpand(graphNode)
        || graphNode.getGraphModel().canCollapse(graphNode)
        || internalNode.isPruned()) {
      label.setVisible(false);
    } else {
      NodeLayout[] successors = internalNode.getSuccessingNodes();
      int numberOfHiddenSuccessors = 0;
      for (int i = 0; i < successors.length; i++) {
        if (successors[i].isPruned()) {
          numberOfHiddenSuccessors++;
        }
      }
      String labelText = numberOfHiddenSuccessors > 0 ? "" + numberOfHiddenSuccessors : "";
      if (!labelText.equals(label.getText())) {
        label.setText(labelText);
      }
      label.setVisible(true);
    }

    refreshLabelBounds(figure, label);
  }
Exemplo n.º 4
0
 private void refreshLabelBounds(IFigure figure, GraphLabel label) {
   Rectangle figureBounds = figure.getBounds();
   if (figureBounds.width * figureBounds.height > 0) {
     label.setText(label.getText()); // hack: resets label's size
     Dimension labelSize = label.getSize();
     labelSize.expand(-6, -4);
     Point anchorPoint = figure.getBounds().getBottomRight();
     anchorPoint.x -= labelSize.width / 2;
     anchorPoint.y -= labelSize.height / 2;
     Rectangle bounds = new Rectangle(anchorPoint, labelSize);
     label.setBounds(bounds);
     label.getParent().setConstraint(label, bounds);
   } else {
     label.getParent().setConstraint(label, new Rectangle(figureBounds.x, figureBounds.y, 0, 0));
     label.setBounds(new Rectangle(figureBounds.x, figureBounds.y, 0, 0));
   }
 }