edu.uci.ics.jung.visualization.transform.shape.GraphicsDecorator Java Examples

The following examples show how to use edu.uci.ics.jung.visualization.transform.shape.GraphicsDecorator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VisualVertexRenderer.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void paintVertexOrVertexShape(RenderContext<V, E> rc, GraphicsDecorator g,
			Layout<V, E> layout, V vertex, Shape compactShape, Shape fullShape) {

		if (isScaledPastVertexPaintingThreshold(rc)) {
			paintScaledVertex(rc, vertex, g, compactShape);
			return;
		}

		Rectangle bounds = fullShape.getBounds();
		paintVertex(rc, g, vertex, bounds, layout);

// DEBUG		
//		Paint oldPaint = g.getPaint();
//		g.setPaint(Color.RED);
//		g.draw(compactShape);
//
//		g.setPaint(Color.CYAN);
//		g.draw(fullShape);
//		g.setPaint(oldPaint);
	}
 
Example #2
Source File: VisualVertexRenderer.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void paintScaledVertex(RenderContext<V, E> rc, V vertex, GraphicsDecorator g,
		Shape shape) {
	Function<? super V, Paint> fillXform = rc.getVertexFillPaintTransformer();
	Paint fillPaint = fillXform.apply(vertex);
	if (fillPaint == null) {
		return;
	}

	Paint oldPaint = g.getPaint();
	g.setPaint(fillPaint);
	g.fill(shape);

	// an outline
	g.setColor(Color.BLACK);
	g.draw(shape);

	g.setPaint(oldPaint);
}
 
Example #3
Source File: AbstractVisualVertexRenderer.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void paintDropShadow(RenderContext<V, E> rc, GraphicsDecorator g, Shape shape) {

		if (!isScaledPastVertexInteractionThreshold(rc)) {
			return;
		}

		g.setColor(Color.GRAY);
		int grayOffset = 15;
		int blackOffset = 5;

		AffineTransform xform = AffineTransform.getTranslateInstance(grayOffset, grayOffset);
		Shape xShape = xform.createTransformedShape(shape);
		g.fill(xShape);
		g.setColor(Color.BLACK);
		AffineTransform xform2 = AffineTransform.getTranslateInstance(blackOffset, blackOffset);
		Shape xShape2 = xform2.createTransformedShape(shape);
		g.fill(xShape2);
	}
 
Example #4
Source File: DiagramGenerator.java    From incubator-batchee with Apache License 2.0 5 votes vote down vote up
public void labelEdge(final RenderContext<Node, Edge> rc, final Layout<Node, Edge> layout, final Edge e, final String label) {
    if (label == null || label.length() == 0) {
        return;
    }

    final Graph<Node, Edge> graph = layout.getGraph();
    // don't draw edge if either incident vertex is not drawn
    final Pair<Node> endpoints = graph.getEndpoints(e);
    final Node v1 = endpoints.getFirst();
    final Node v2 = endpoints.getSecond();
    if (!rc.getEdgeIncludePredicate().evaluate(Context.<Graph<Node, Edge>, Edge>getInstance(graph, e))) {
        return;
    }

    if (!rc.getVertexIncludePredicate().evaluate(Context.<Graph<Node, Edge>, Node>getInstance(graph, v1)) ||
        !rc.getVertexIncludePredicate().evaluate(Context.<Graph<Node, Edge>, Node>getInstance(graph, v2))) {
        return;
    }

    final Point2D p1 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v1));
    final Point2D p2 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v2));

    final GraphicsDecorator g = rc.getGraphicsContext();
    final Component component = prepareRenderer(rc, rc.getEdgeLabelRenderer(), label, rc.getPickedEdgeState().isPicked(e), e);
    final Dimension d = component.getPreferredSize();

    final AffineTransform old = g.getTransform();
    final AffineTransform xform = new AffineTransform(old);
    final FontMetrics fm = g.getFontMetrics();
    int w = fm.stringWidth(e.text);
    double p = Math.max(0, p1.getX() + p2.getX() - w);
    xform.translate(Math.min(layout.getSize().width - w, p / 2), (p1.getY() + p2.getY() - fm.getHeight()) / 2);
    g.setTransform(xform);
    g.draw(component, rc.getRendererPane(), 0, 0, d.width, d.height, true);

    g.setTransform(old);
}
 
Example #5
Source File: VertexDemo.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void paintIconForVertex(RenderContext<V,E> rc, V v, Layout<V,E> layout) {
	
    Point2D p = layout.transform(v);
    p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p);
    float x = (float)p.getX();
    float y = (float)p.getY();

    GraphicsDecorator g = rc.getGraphicsContext();
    boolean outlineImages = false;
    Transformer<V,Icon> vertexIconFunction = rc.getVertexIconTransformer();
    
    if(vertexIconFunction instanceof DemoVertexIconTransformer) {
        outlineImages = ((DemoVertexIconTransformer<V>)vertexIconFunction).isOutlineImages();
    }
    Icon icon = vertexIconFunction.transform(v);
    if(icon == null || outlineImages) {
        
        Shape s = AffineTransform.getTranslateInstance(x,y).
            createTransformedShape(rc.getVertexShapeTransformer().transform(v));
        paintShapeForVertex(rc, v, s);
    }
    if(icon != null) {
        int xLoc = (int) (x - icon.getIconWidth()/2);
        int yLoc = (int) (y - icon.getIconHeight()/2);
        icon.paintIcon(rc.getScreenDevice(), g.getDelegate(), xLoc, yLoc);
    }
}
 
Example #6
Source File: TreeModelNodeRenderer.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Paint <code>v</code>'s icon on <code>g</code> at <code>(x,y)</code>.
 */
protected void paintIconForVertex(RenderContext<V, E> rc, V v, Layout<V, E> layout) {
	GraphicsDecorator g = rc.getGraphicsContext();
	boolean vertexHit = true;
	// get the shape to be rendered
	Shape shape = rc.getVertexShapeTransformer().transform(v);

	Point2D p = layout.transform(v);
	p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p);
	float x = (float) p.getX();
	float y = (float) p.getY();
	// create a transform that translates to the location of
	// the vertex to be rendered
	AffineTransform xform = AffineTransform.getTranslateInstance(x, y);
	// transform the vertex shape with xtransform
	shape = xform.createTransformedShape(shape);

	vertexHit = vertexHit(rc, shape);
	// rc.getViewTransformer().transform(shape).intersects(deviceRectangle);

	if (vertexHit) {
		if (rc.getVertexIconTransformer() != null) {
			Icon icon = rc.getVertexIconTransformer().transform(v);
			if (icon != null) {

				g.draw(icon, rc.getScreenDevice(), shape, (int) x, (int) y);

			} else {
				paintShapeForVertex(rc, v, shape);
			}
		} else {
			paintShapeForVertex(rc, v, shape);
		}
	}
}
 
Example #7
Source File: DNLEdgeLabelRenderer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused") // used during debug
private void labelArticulations(Component component, GraphicsDecorator g,
		RenderContext<V, E> rc, E e) {

	int offset = 5;
	int counter = 1;
	List<Point2D> points = e.getArticulationPoints();
	for (Point2D p : points) {

		MultiLayerTransformer multiLayerTransformer = rc.getMultiLayerTransformer();
		p = multiLayerTransformer.transform(Layer.LAYOUT, p);

		EdgeLabelRenderer labelRenderer = rc.getEdgeLabelRenderer();
		Font font = rc.getEdgeFontTransformer().apply(e);
		boolean isSelected = rc.getPickedEdgeState().isPicked(e);
		component = labelRenderer.getEdgeLabelRendererComponent(rc.getScreenDevice(),
			"p" + counter++, font, isSelected, e);

		Dimension d = component.getPreferredSize();
		AffineTransform old = g.getTransform();
		AffineTransform xform = new AffineTransform(old);
		xform.translate(p.getX() + offset, p.getY());
		g.setTransform(xform);
		g.draw(component, rc.getRendererPane(), 0, 0, d.width, d.height, true);
		g.setTransform(old);
	}
}
 
Example #8
Source File: FGVertexRenderer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintVertex(RenderContext<FGVertex, FGEdge> rc, GraphicsDecorator g,
		FGVertex vertex, Rectangle bounds, Layout<FGVertex, FGEdge> layout) {

	refreshVertexAsNeeded(vertex);

	vertex.setShowing(true); // hack to make sure the component paints 
	super.paintVertex(rc, g, vertex, bounds, layout);
	vertex.setShowing(false); // turn off painting (this fix keeps tooltips from painting)
}
 
Example #9
Source File: FGVertexRenderer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintVertexOrVertexShape(RenderContext<FGVertex, FGEdge> rc, GraphicsDecorator g,
		Layout<FGVertex, FGEdge> layout, FGVertex vertex, Shape compactShape, Shape fullShape) {

	if (isScaledPastVertexPaintingThreshold(rc)) {
		paintScaledVertex(rc, vertex, g, compactShape);
		return;
	}

	if (vertex instanceof GroupedFunctionGraphVertex) {
		// paint depth images offset from main vertex
		Rectangle originalBounds = fullShape.getBounds();
		Rectangle paintBounds = (Rectangle) originalBounds.clone();
		Set<FGVertex> vertices = ((GroupedFunctionGraphVertex) vertex).getVertices();
		int offset = 5;
		int size = vertices.size();
		if (size > 3) {
			size = size / 3; // don't paint one-for-one, that's a bit much
			size = Math.max(size, 2);  // we want at least 2, to give some depth
		}
		int currentOffset = offset * size;
		for (int i = size - 1; i >= 0; i--) {
			paintBounds.x = originalBounds.x + currentOffset;
			paintBounds.y = originalBounds.y + currentOffset;
			currentOffset -= offset;
			paintVertex(rc, g, vertex, paintBounds, layout);
		}
	}

	// paint one final time
	Rectangle bounds = fullShape.getBounds();
	paintVertex(rc, g, vertex, bounds, layout);
}
 
Example #10
Source File: FGVertexRenderer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintDropShadow(RenderContext<FGVertex, FGEdge> rc, GraphicsDecorator g,
		Shape shape, FGVertex vertex) {

	Rectangle bounds = shape.getBounds();
	if (vertex instanceof GroupedFunctionGraphVertex) {
		// paint depth images offset from main vertex
		Rectangle originalBounds = bounds;
		Rectangle paintBounds = (Rectangle) originalBounds.clone();
		Set<FGVertex> vertices = ((GroupedFunctionGraphVertex) vertex).getVertices();
		int offset = 15;
		int size = vertices.size();
		if (size > 3) {
			size = size / 3; // don't paint one-for-one, that's a bit much
			size = Math.max(size, 2);
		}
		int currentOffset = offset * size;
		for (int i = size - 1; i >= 0; i--) {
			paintBounds.x = originalBounds.x + currentOffset;
			paintBounds.y = originalBounds.y + currentOffset;
			currentOffset -= offset;
			super.paintDropShadow(rc, g, paintBounds);
		}
	}

	super.paintDropShadow(rc, g, bounds);
}
 
Example #11
Source File: AbstractVisualVertexRenderer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
protected void paintHighlight(RenderContext<V, E> rc, V vertex, GraphicsDecorator g,
			Rectangle bounds) {

		if (!vertex.isSelected()) {
			return;
		}

		Paint oldPaint = g.getPaint();

		int halfishTransparency = 150;
		Color yellowWithTransparency = new Color(255, 255, 0, halfishTransparency);
		g.setPaint(yellowWithTransparency);

		int offset = 10;

		// scale the offset with the scale of the view, but not as fast, so that as we scale down, 
		// the size of the paint area starts to get larger than the vertex
		offset = (int) adjustValueForCurrentScale(rc, offset, .9);
		g.fillOval(bounds.x - offset, bounds.y - offset, bounds.width + (offset * 2),
			bounds.height + (offset * 2));

// DEBUG		
//		g.setPaint(Color.BLUE);
//		g.drawRect(bounds.x - offset, bounds.y - offset, bounds.width + (offset * 2),
//			bounds.height + (offset * 2));
//		g.setPaint(Color.BLACK);
//		g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height);

		g.setPaint(oldPaint);
	}
 
Example #12
Source File: VisualVertexRenderer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
protected void paintVertex(RenderContext<V, E> rc, GraphicsDecorator g, V vertex,
		Rectangle bounds, Layout<V, E> layout) {

	Component component = vertex.getComponent();
	g.draw(component, rc.getRendererPane(), bounds.x, bounds.y, bounds.width, bounds.height,
		true);

	// HACK: we must restore our bounds here, since the renderer pane will change them during
	// the rendering process (not sure if this is still needed; if we figure out why, then
	// update this comment)
	component.setBounds(bounds);
}
 
Example #13
Source File: VisualVertexRenderer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void paintVertex(RenderContext<V, E> rc, Layout<V, E> layout, V vertex) {

	Graph<V, E> graph = layout.getGraph();
	if (!rc.getVertexIncludePredicate().apply(
		Context.<Graph<V, E>, V> getInstance(graph, vertex))) {
		return;
	}

	GraphicsDecorator g = rc.getGraphicsContext();
	GraphicsDecorator gCopy = getEmphasisGraphics(g, vertex, rc, layout);

	// Note: for most graphs, the full/compact shapes are the same
	Shape fullShape = getFullShape(rc, layout, vertex);
	Shape compactShape = getCompactShape(rc, layout, vertex);
	if (!vertexHit(rc, fullShape)) {
		return;
	}

	Rectangle bounds = fullShape.getBounds();

	paintHighlight(rc, vertex, gCopy, bounds);

	paintDropShadow(rc, gCopy, compactShape, vertex);

	paintVertexOrVertexShape(rc, gCopy, layout, vertex, compactShape, fullShape);

	gCopy.dispose();
}
 
Example #14
Source File: CachingSatelliteGraphViewer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public Renderer.Vertex<V, E> getPreferredVertexRenderer() {
	return new VisualVertexSatelliteRenderer<V, E>() {
		@Override
		protected void paintHighlight(RenderContext<V, E> rc, V vertex, GraphicsDecorator g,
				Rectangle bounds) {
			// Stub--we don't want the render to paint highlights, as we use a static, 
			// cached image.  We will manually paint highlights in the paint routine of this
			// viewer.
		}
	};
}
 
Example #15
Source File: VisualVertexSatelliteRenderer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
	protected void paintHighlight(RenderContext<V, E> rc, V vertex, GraphicsDecorator g,
			Rectangle bounds) {

		if (!vertex.isSelected()) {
			return;
		}

		Paint oldPaint = g.getPaint();

		int halfishTransparency = 150;
		Color yellowWithTransparency = new Color(255, 255, 0, halfishTransparency);
		g.setPaint(yellowWithTransparency);

//		int offset = (int) adjustValueForCurrentScale(rc, 10D, .25);
		int offset = 10;

		// scale the offset with the scale of the view, but not as fast, so that as we scale down, 
		// the size of the paint area starts to get larger than the vertex
		offset = (int) adjustValueForCurrentScale(rc, offset, .9);
		g.fillOval(bounds.x - offset, bounds.y - offset, bounds.width + (offset * 2),
			bounds.height + (offset * 2));

		if (isGraphScaledEnoughToBeDifficultToSee(rc)) {
			g.setColor(Color.BLACK);
			g.drawOval(bounds.x - offset, bounds.y - offset, bounds.width + (offset * 2),
				bounds.height + (offset * 2));
			g.drawOval(bounds.x - offset - 1, bounds.y - offset - 1,
				bounds.width + (offset * 2) + 2, bounds.height + (offset * 2) + 2);
			g.drawOval(bounds.x - offset - 2, bounds.y - offset - 2,
				bounds.width + (offset * 2) + 4, bounds.height + (offset * 2) + 4);
		}

		g.setPaint(oldPaint);
	}
 
Example #16
Source File: VisualVertexSatelliteRenderer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
	 * Overridden to handle painting emphasis.
	 */
	@Override
	protected void paintIconForVertex(RenderContext<V, E> rc, V v, Layout<V, E> layout) {

		GraphicsDecorator defaultGraphics = rc.getGraphicsContext();
		if (v.isSelected()) {
			Shape shape = getFullShape(rc, layout, v);
			Rectangle bounds = shape.getBounds();
			paintHighlight(rc, v, defaultGraphics, bounds);
		}

		double empahsis = v.getEmphasis();
		if (empahsis == 0) {
			super.paintIconForVertex(rc, v, layout);
			return;
		}

// POSTERITY NOTE: we used to let the satellite paint the emphasis of nodes, as a way to call
//		           attention to the selected node.  Now that we use caching, this has the odd 
//		           side-effect of painting a large vertex in the cached image.  Also, we have 
//		           changed how the satellite paints selected vertices, so the effect being 
//		           performed below is no longer necessary.
//		GraphicsDecorator emphasisGraphics = getEmphasisGraphics(defaultGraphics, v, rc, layout);
//		rc.setGraphicsContext(emphasisGraphics);
//		super.paintIconForVertex(rc, v, layout);
//		rc.setGraphicsContext(defaultGraphics);

		super.paintIconForVertex(rc, v, layout);
	}
 
Example #17
Source File: AbstractVisualVertexRenderer.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a copy of the given {@link GraphicsDecorator} that may have scaling tweaked to 
 * handle {@link VisualVertex#getEmphasis()} emphasized vertices.
 */
protected GraphicsDecorator getEmphasisGraphics(GraphicsDecorator g, V vertex,
		RenderContext<V, E> rc, Layout<V, E> layout) {

	Graphics2D graphicsCopy = (Graphics2D) g.create();
	GraphicsDecorator decoratorCopy = new GraphicsDecorator(graphicsCopy);

	double alpha = vertex.getAlpha();
	if (alpha < 1D) {
		decoratorCopy.setComposite(
			AlphaComposite.getInstance(AlphaComposite.SrcOver.getRule(), (float) alpha));
	}

	double emphasis = vertex.getEmphasis();
	if (emphasis == 0) {
		return decoratorCopy;
	}

	AffineTransform transform = graphicsCopy.getTransform();
	double scaleX = transform.getScaleX();
	if (((int) scaleX) == 1) {
		return decoratorCopy;
	}

	Point2D p = layout.apply(vertex);
	MultiLayerTransformer multiLayerTransformer = rc.getMultiLayerTransformer();
	p = multiLayerTransformer.transform(Layer.LAYOUT, p);

	double vertexX = p.getX();
	double vertexY = p.getY();
	AffineTransform xf = AffineTransform.getTranslateInstance(vertexX, vertexY);
	emphasis = adjustValueForCurrentScale(rc, emphasis, .5);
	double newScale = 1.0 + emphasis;
	xf.scale(newScale, newScale);
	xf.translate(-vertexX, -vertexY);

	transform.concatenate(xf);

	graphicsCopy.setTransform(transform);

	return decoratorCopy;
}
 
Example #18
Source File: VisualVertexRenderer.java    From ghidra with Apache License 2.0 4 votes vote down vote up
protected void paintDropShadow(RenderContext<V, E> rc, GraphicsDecorator g, Shape shape,
		V vertex) {

	super.paintDropShadow(rc, g, shape);
}
 
Example #19
Source File: TreeModelNodeRenderer.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
protected void paintShapeForVertex(RenderContext<V, E> rc, V v, Shape shape) {
	GraphicsDecorator g = rc.getGraphicsContext();
	Paint oldPaint = g.getPaint();
	Paint fillPaint = rc.getVertexFillPaintTransformer().transform(v);
	if (fillPaint != null) {
		g.setPaint(fillPaint);
		g.fill(shape);
		g.setPaint(oldPaint);
	}
	Paint drawPaint = rc.getVertexDrawPaintTransformer().transform(v);
	if (drawPaint != null) {
		g.setPaint(drawPaint);
		Stroke oldStroke = g.getStroke();
		Stroke stroke = rc.getVertexStrokeTransformer().transform(v);
		if (stroke != null) {
			g.setStroke(stroke);
		}
		g.draw(shape);
		g.setPaint(oldPaint);
		g.setStroke(oldStroke);

	}

	// leaf: draw frequency colors if nominal
	if (graphCreator.isLeaf((String) v)) {
		Attribute label = model.getTrainingHeader().getAttributes().getLabel();
		if (label.isNominal()) {
			Tree tree = graphCreator.getTree((String) v);
			Map<String, Integer> countMap = tree.getCounterMap();
			int numberOfLabels = countMap.size();
			int frequencySum = tree.getFrequencySum();

			double height = tree.getFrequencySum() / (double) maxLeafSize
					* (FREQUENCY_BAR_MAX_HEIGHT - FREQUENCY_BAR_MIN_HEIGHT) + FREQUENCY_BAR_MIN_HEIGHT;
			double width = shape.getBounds().getWidth() - 2 * FREQUENCY_BAR_OFFSET_X - 1;
			double xPos = shape.getBounds().getX() + FREQUENCY_BAR_OFFSET_X;
			double yPos = shape.getBounds().getY() + shape.getBounds().getHeight() - FREQUENCY_BAR_OFFSET_Y - height;
			ColorProvider colorProvider = new ColorProvider();
			for (String labelValue : countMap.keySet()) {
				int count = tree.getCount(labelValue);
				double currentWidth = (double) count / (double) frequencySum * width;
				Rectangle2D.Double frequencyRect = new Rectangle2D.Double(xPos, yPos, currentWidth, height);
				int counter = label.getMapping().mapString(labelValue);
				g.setColor(colorProvider.getPointColor((double) counter / (double) (numberOfLabels - 1)));
				g.fill(frequencyRect);

				g.setColor(Color.BLACK);
				xPos += currentWidth;
			}

			g.setPaint(oldPaint);
		}
	}
}
 
Example #20
Source File: TreeModelEdgeLabelRenderer.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void labelEdge(RenderContext<V, E> rc, Layout<V, E> layout, E e, String label) {
	if (label == null || label.length() == 0) {
		return;
	}

	Graph<V, E> graph = layout.getGraph();
	// don't draw edge if either incident vertex is not drawn
	Pair<V> endpoints = graph.getEndpoints(e);
	V v1 = endpoints.getFirst();
	V v2 = endpoints.getSecond();
	if (!rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V> getInstance(graph, v1))
			|| !rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V> getInstance(graph, v2))) {
		return;
	}

	Point2D p1 = layout.transform(v1);
	Point2D p2 = layout.transform(v2);
	p1 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p1);
	p2 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p2);
	float x1 = (float) p1.getX();
	float y1 = (float) p1.getY();
	float x2 = (float) p2.getX();
	float y2 = (float) p2.getY();

	GraphicsDecorator g = rc.getGraphicsContext();
	float distX = x2 - x1;
	float distY = y2 - y1;
	double totalLength = Math.sqrt(distX * distX + distY * distY);

	double closeness = rc.getEdgeLabelClosenessTransformer().transform(Context.<Graph<V, E>, E> getInstance(graph, e))
			.doubleValue();

	int posX = (int) (x1 + closeness * distX);
	int posY = (int) (y1 + closeness * distY);

	int xDisplacement = 0;
	int yDisplacement = 0;

	xDisplacement = (int) (rc.getLabelOffset() * (distX / totalLength));
	yDisplacement = (int) (rc.getLabelOffset() * (-distY / totalLength));

	AffineTransform old = g.getTransform();
	AffineTransform xform = new AffineTransform(old);
	xform.translate(posX + xDisplacement, posY + yDisplacement);

	double parallelOffset = 0.0d;
	Component component = prepareRenderer(rc, rc.getEdgeLabelRenderer(), label, rc.getPickedEdgeState().isPicked(e), e);
	Dimension d = component.getPreferredSize();
	xform.translate(-d.width / 2.0d, -(d.height / 2.0d - parallelOffset));
	g.setTransform(xform);
	g.setColor(Colors.WHITE);
	g.draw(component, rc.getRendererPane(), 0, 0, d.width, d.height, true);
	g.setTransform(old);
}
 
Example #21
Source File: TreeModelNodeLabelRenderer.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Labels the specified vertex with the specified label. Uses the font specified by this
 * instance's <code>VertexFontFunction</code>. (If the font is unspecified, the existing font
 * for the graphics context is used.) If vertex label centering is active, the label is centered
 * on the position of the vertex; otherwise the label is offset slightly.
 */
@Override
public void labelVertex(RenderContext<V, E> rc, Layout<V, E> layout, V v, String label) {
	Graph<V, E> graph = layout.getGraph();
	if (rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V> getInstance(graph, v)) == false) {
		return;
	}
	Point2D pt = layout.transform(v);
	pt = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, pt);

	float x = (float) pt.getX();
	float y = (float) pt.getY();

	Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(), label, rc.getPickedVertexState().isPicked(v),
			v);
	GraphicsDecorator g = rc.getGraphicsContext();
	Dimension d = component.getPreferredSize();
	AffineTransform xform = AffineTransform.getTranslateInstance(x, y);

	Shape shape = rc.getVertexShapeTransformer().transform(v);
	shape = xform.createTransformedShape(shape);
	if (rc.getGraphicsContext() instanceof TransformingGraphics) {
		BidirectionalTransformer transformer = ((TransformingGraphics) rc.getGraphicsContext()).getTransformer();
		if (transformer instanceof ShapeTransformer) {
			ShapeTransformer shapeTransformer = (ShapeTransformer) transformer;
			shape = shapeTransformer.transform(shape);
		}
	}
	Rectangle2D bounds = shape.getBounds2D();

	Point p = null;
	if (position == Position.AUTO) {
		Dimension vvd = rc.getScreenDevice().getSize();
		if (vvd.width == 0 || vvd.height == 0) {
			vvd = rc.getScreenDevice().getPreferredSize();
		}
		p = getAnchorPoint(bounds, d, positioner.getPosition(x, y, vvd));
	} else {
		p = getAnchorPoint(bounds, d, position);
	}

	if (graphCreator.isLeaf((String) v) && !graphCreator.getModel().getRoot().isNumerical()) {
		// shift the label if there is a frequency bar
		p.setLocation(p.x, p.y + LEAF_LABEL_OFFSET_Y);
	}
	g.draw(component, rc.getRendererPane(), p.x, p.y, d.width, d.height, true);
}
 
Example #22
Source File: DebugShape.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public void paint(GraphicsDecorator g) {
	Graphics2D delegate = g.getDelegate();
	doPaint(delegate);
}