01: package org.cougaar.core.qos.frame.visualizer;
02:
03: import java.awt.Font;
04: import java.awt.Graphics2D;
05: import java.awt.Paint;
06: import java.awt.Rectangle;
07: import java.awt.Shape;
08:
09: /**
10: * Created by IntelliJ IDEA.
11: * User: mwalczak
12: * Date: Apr 29, 2005
13: * Time: 1:24:36 PM
14: * To change this template use File | Settings | File Templates.
15: */
16: public class LabelRenderer {
17: /*private static HashMap labelRenderers = new HashMap();
18: public static void add(LabelRenderer r) {
19: if (labelRenderers.get(r.getName()) == null)
20: labelRenderers.put(r.getName(), r);
21: }
22: public static LabelRenderer get(String name) {
23: return (LabelRenderer) labelRenderers.get(name);
24: } */
25:
26: protected String rendererName;
27: protected double xoffset, yoffset;
28: protected Paint paint = null;
29: protected Font font = null;
30: boolean onMouseOverOnly = false;
31: protected boolean mouseIsOverShape = false;
32:
33: public LabelRenderer(String rendererName, double xoff, double yoff) {
34: this (rendererName, xoff, yoff, null, null);
35: }
36:
37: public LabelRenderer(String rendererName, double xoff, double yoff,
38: Font font) {
39: this (rendererName, xoff, yoff, font, null);
40: }
41:
42: public LabelRenderer(String rendererName, double xoff, double yoff,
43: Paint paint) {
44: this (rendererName, xoff, yoff, null, paint);
45: }
46:
47: public LabelRenderer(String rendererName, double xoff, double yoff,
48: Font font, Paint paint) {
49: this .rendererName = rendererName;
50: this .xoffset = xoff;
51: this .yoffset = yoff;
52: this .font = font;
53: this .paint = paint;
54: }
55:
56: public void setMouseOverOnly(boolean onmouseover) {
57: onMouseOverOnly = onmouseover;
58: }
59:
60: public Paint getPaint() {
61: return paint;
62: }
63:
64: public String getName() {
65: return rendererName;
66: }
67:
68: public void drawLabel(Graphics2D g2, ShapeGraphic shapeGraphic) {
69: if (shapeGraphic == null || shapeGraphic.getLabel() == null)
70: return;
71: if (onMouseOverOnly && !shapeGraphic.isMouseOver())
72: return;
73: Shape shape = shapeGraphic.getShape();
74: if (shape == null)
75: return;
76: if (paint != null)
77: g2.setPaint(paint);
78: //int sw = getFontMetrics(f).stringWidth(f.getName());
79: if (font != null)
80: g2.setFont(font);
81:
82: Rectangle r = shape.getBounds();
83: g2.drawString(shapeGraphic.getLabel(), (int) (r.x + xoffset),
84: (int) (r.y + yoffset));
85: }
86: }
|