本文整理汇总了Java中edu.uci.ics.jung.visualization.RenderContext.getGraphicsContext方法的典型用法代码示例。如果您正苦于以下问题:Java RenderContext.getGraphicsContext方法的具体用法?Java RenderContext.getGraphicsContext怎么用?Java RenderContext.getGraphicsContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.uci.ics.jung.visualization.RenderContext
的用法示例。
在下文中一共展示了RenderContext.getGraphicsContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderSet
import edu.uci.ics.jung.visualization.RenderContext; //导入方法依赖的package包/类
private void renderSet(
RenderContext<ViwnNode, ViwnEdge> rc,
Point2D p,
ViwnNodeSet node) {
GraphicsDecorator g = rc.getGraphicsContext();
String text = "" + node.getSynsets().size();
Font f = new Font("Sansserif", Font.BOLD, 14);
Font old_font = g.getFont();
g.setFont(f);
FontMetrics metrics = g.getFontMetrics(g.getFont());
int width = metrics.stringWidth(text);
int height = metrics.getHeight();
g.setColor(Color.black);
g.drawString(text,
(int) p.getX() - width / 2,
(int) p.getY());
width = metrics.stringWidth("...");
g.drawString("...",
(int) p.getX() - width / 2,
(int) p.getY() + 0.25f * height);
g.setFont(old_font);
}
示例2: labelVertex
import edu.uci.ics.jung.visualization.RenderContext; //导入方法依赖的package包/类
@Override
public void labelVertex(RenderContext<GUINode, GUILink> rc, Layout<GUINode, GUILink> layout, GUINode v, String label)
{
if (!callback.getVisualizationState().isVisibleInCanvas(v)) return;
if (callback.getVisualizationState().isCanvasShowNodeNames() && v.getLayer().isDefaultLayer())
{
Point2D vertexPositionInPixels = layout.transform(v);
vertexPositionInPixels = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, vertexPositionInPixels);
final Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(), "<html><font color='black'>" + v.getLabel() + "</font></html>", rc.getPickedVertexState().isPicked(v), v);
final GraphicsDecorator g = rc.getGraphicsContext();
final Dimension dimensionMessage = component.getPreferredSize();
final Icon vertexIcon = v.getIcon();
final Rectangle2D boundsVertex = new Rectangle2D.Double(vertexPositionInPixels.getX() - vertexIcon.getIconWidth() / 2, vertexPositionInPixels.getY() - vertexIcon.getIconHeight() / 2, vertexIcon.getIconWidth(), vertexIcon.getIconHeight());
final Point anchorPointInPixels = getAnchorPoint(boundsVertex, dimensionMessage, Renderer.VertexLabel.Position.NE);
g.draw(component, rc.getRendererPane(), anchorPointInPixels.x, anchorPointInPixels.y, dimensionMessage.width, dimensionMessage.height, true);
}
}
示例3: paintVertex
import edu.uci.ics.jung.visualization.RenderContext; //导入方法依赖的package包/类
@Override public void paintVertex(RenderContext<String, String> rc,
Layout<String, String> layout, String vertex) {
GraphicsDecorator graphicsContext = rc.getGraphicsContext();
Point2D center = layout.transform(vertex);
Shape shape = null;
Color color = null;
if(vertex.equals("Square")) {
shape = new Rectangle((int)center.getX()-10, (int)center.getY()-10, 20, 20);
color = new Color(127, 127, 0);
} else if(vertex.equals("Rectangle")) {
shape = new Rectangle((int)center.getX()-10, (int)center.getY()-20, 20, 40);
color = new Color(127, 0, 127);
} else if(vertex.equals("Circle")) {
shape = new Ellipse2D.Double(center.getX()-10, center.getY()-10, 20, 20);
color = new Color(0, 127, 127);
}
graphicsContext.setPaint(color);
graphicsContext.fill(shape);
}
示例4: paintEdge
import edu.uci.ics.jung.visualization.RenderContext; //导入方法依赖的package包/类
public void paintEdge(RenderContext<V,E> rc, Layout<V, E> layout, E e) {
GraphicsDecorator g2d = rc.getGraphicsContext();
Graph<V,E> graph = layout.getGraph();
if (!rc.getEdgeIncludePredicate().evaluate(Context.<Graph<V,E>,E>getInstance(graph,e)))
return;
// 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;
Stroke new_stroke = rc.getEdgeStrokeTransformer().transform(e);
Stroke old_stroke = g2d.getStroke();
if (new_stroke != null)
g2d.setStroke(new_stroke);
drawSimpleEdge(rc, layout, e);
// restore paint and stroke
if (new_stroke != null)
g2d.setStroke(old_stroke);
}
示例5: labelVertex
import edu.uci.ics.jung.visualization.RenderContext; //导入方法依赖的package包/类
/**
* 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.
*/
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;
}
GraphicsDecorator g = rc.getGraphicsContext();
Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(), label,
rc.getPickedVertexState().isPicked(v), v);
Dimension d = component.getPreferredSize();
int h_offset = -d.width / 2;
int v_offset = -d.height / 2;
Point2D p = layout.transform(v);
p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p);
int x = (int)p.getX();
int y = (int)p.getY();
g.draw(component, rc.getRendererPane(), x+h_offset, y+v_offset, d.width, d.height, true);
Dimension size = component.getPreferredSize();
Rectangle bounds = new Rectangle(-size.width/2 -2, -size.height/2 -2, size.width+4, size.height);
shapes.put(v, bounds);
}
示例6: paintShapeForVertex
import edu.uci.ics.jung.visualization.RenderContext; //导入方法依赖的package包/类
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);
}
}
示例7: paintIconForVertex
import edu.uci.ics.jung.visualization.RenderContext; //导入方法依赖的package包/类
/**
* 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);
}
}
}
示例8: renderWord
import edu.uci.ics.jung.visualization.RenderContext; //导入方法依赖的package包/类
private void renderWord(
RenderContext<ViwnNode, ViwnEdge> rc,
Point2D p,
ViwnNodeWord node) {
GraphicsDecorator g = rc.getGraphicsContext();
String text = node.getLabel();
FontMetrics metrics = g.getFontMetrics(g.getFont());
int width = metrics.stringWidth(text);
g.setColor(Color.black);
g.drawString(text,
(int) p.getX() - width / 2,
(int) p.getY() + 5);
}
示例9: paintIconForVertex
import edu.uci.ics.jung.visualization.RenderContext; //导入方法依赖的package包/类
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);
}
}
示例10: labelEdge
import edu.uci.ics.jung.visualization.RenderContext; //导入方法依赖的package包/类
@Override
public void labelEdge(RenderContext<V, E> rc, Layout<V, E> layout, E e, String label) {
if (Strings.isNullOrEmpty(label)) {
return;
}
Shape edgeShape = JungUtils.getTransformedEdgeShape(rc, layout, e);
if (edgeShape == null) {
return;
}
Line2D line = JungUtils.getLineInMiddle(edgeShape);
GraphicsDecorator g = rc.getGraphicsContext();
Font font = rc.getEdgeFontTransformer().transform(e);
double width = font.getStringBounds(label, g.getFontRenderContext()).getWidth();
AffineTransform old = g.getTransform();
AffineTransform trans = new AffineTransform(old);
double angle = Math.atan2(line.getY2() - line.getY1(), line.getX2() - line.getX1());
if (angle < -Math.PI / 2) {
angle += Math.PI;
} else if (angle > Math.PI / 2) {
angle -= Math.PI;
}
trans.translate(line.getX1(), line.getY1());
trans.rotate(angle);
g.setTransform(trans);
g.setColor(rc.getPickedEdgeState().isPicked(e) ? Color.GREEN : Color.BLACK);
g.setFont(rc.getEdgeFontTransformer().transform(e));
g.drawString(label, (int) (-width / 2), 0);
g.setTransform(old);
}
示例11: paintShapeForVertex
import edu.uci.ics.jung.visualization.RenderContext; //导入方法依赖的package包/类
protected void paintShapeForVertex(RenderContext<V,E> rc, V v, Shape shape) {
GraphicsDecorator g = rc.getGraphicsContext();
Paint oldPaint = g.getPaint();
Rectangle r = shape.getBounds();
float y2 = (float)r.getMaxY();
if(cyclic) {
y2 = (float)(r.getMinY()+r.getHeight()/2);
}
Paint fillPaint = null;
if(pickedState != null && pickedState.isPicked(v)) {
fillPaint = new GradientPaint((float)r.getMinX(), (float)r.getMinY(), pickedColorOne,
(float)r.getMinX(), y2, pickedColorTwo, cyclic);
} else {
fillPaint = new GradientPaint((float)r.getMinX(), (float)r.getMinY(), colorOne,
(float)r.getMinX(), y2, colorTwo, cyclic);
}
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);
}
示例12: paintIconForVertex
import edu.uci.ics.jung.visualization.RenderContext; //导入方法依赖的package包/类
/**
* 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);
}
}
}
示例13: paintIconForVertex
import edu.uci.ics.jung.visualization.RenderContext; //导入方法依赖的package包/类
/**
* 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);
}
}
}
示例14: labelEdge
import edu.uci.ics.jung.visualization.RenderContext; //导入方法依赖的package包/类
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);
}
示例15: paintShapeForVertex
import edu.uci.ics.jung.visualization.RenderContext; //导入方法依赖的package包/类
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 (graphCreator.isLeaf((String) v)) {
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);
Attribute label = model.getTrainingHeader().getAttributes().getLabel();
if (label.isNominal()) {
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.setColor(Color.BLACK);
g.draw(new Rectangle2D.Double(shape.getBounds().getX() + FREQUENCY_BAR_OFFSET_X, yPos, width, height));
g.setPaint(oldPaint);
}
}