本文整理汇总了Java中edu.uci.ics.jung.visualization.transform.shape.GraphicsDecorator.getFontMetrics方法的典型用法代码示例。如果您正苦于以下问题:Java GraphicsDecorator.getFontMetrics方法的具体用法?Java GraphicsDecorator.getFontMetrics怎么用?Java GraphicsDecorator.getFontMetrics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.uci.ics.jung.visualization.transform.shape.GraphicsDecorator
的用法示例。
在下文中一共展示了GraphicsDecorator.getFontMetrics方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderSet
import edu.uci.ics.jung.visualization.transform.shape.GraphicsDecorator; //导入方法依赖的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: renderWord
import edu.uci.ics.jung.visualization.transform.shape.GraphicsDecorator; //导入方法依赖的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);
}
示例3: labelEdge
import edu.uci.ics.jung.visualization.transform.shape.GraphicsDecorator; //导入方法依赖的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);
}