예제 #1
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));
   }
 }
예제 #2
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);
  }