1:
31:
32: package ;
33:
34: import ;
35: import ;
36: import ;
37: import ;
38: import ;
39: import ;
40:
41: import ;
42: import ;
43: import ;
44:
45:
48: public class SurveyScaleLegendItem implements Drawable
49: {
50:
51:
54: private Shape shape;
55:
56:
59: private String label;
60:
61:
64: private boolean draw;
65:
66:
69: private boolean fill;
70:
71:
74: private Font font;
75:
76: public SurveyScaleLegendItem ()
77: {
78: font = new Font("Serif", Font.ITALIC, 10);
79: }
80:
81:
89: public SurveyScaleLegendItem (final Shape shape,
90: final String label,
91: final boolean draw,
92: final boolean fill)
93: {
94: this.shape = shape;
95: this.label = label;
96: this.draw = draw;
97: this.fill = fill;
98: }
99:
100:
106: public void draw (final Graphics2D g2, final Rectangle2D area)
107: {
108: if (shape == null || font == null || label == null)
109: {
110: return;
111: }
112: if (draw == false && fill == false)
113: {
114: return;
115: }
116:
117: final Rectangle2D b = this.shape.getBounds2D();
118: double x = area.getMinX() + b.getWidth() / 2.0 + 1.0;
119: final double y = area.getCenterY();
120: final Shape s = getShape();
121: g2.translate(x,y);
122: g2.setPaint(Color.black);
123: if (this.draw)
124: {
125: g2.setStroke(new BasicStroke(0.5f));
126: g2.draw(s);
127: }
128: if (this.fill)
129: {
130: g2.fill(s);
131: }
132: g2.translate(-x, -y);
133: x += b.getWidth() / 2.0 + 3.0;
134: g2.setFont(this.font);
135: TextUtilities.drawAlignedString
136: (this.label, g2, (float) x, (float) y, TextAnchor.HALF_ASCENT_LEFT);
137: }
138:
139: public boolean isDraw ()
140: {
141: return draw;
142: }
143:
144: public void setDraw (final boolean draw)
145: {
146: this.draw = draw;
147: }
148:
149: public boolean isFill ()
150: {
151: return fill;
152: }
153:
154: public void setFill (final boolean fill)
155: {
156: this.fill = fill;
157: }
158:
159: public Font getFont ()
160: {
161: return font;
162: }
163:
164: public void setFont (final Font font)
165: {
166: this.font = font;
167: }
168:
169: public String getLabel ()
170: {
171: return label;
172: }
173:
174: public void setLabel (final String label)
175: {
176: this.label = label;
177: }
178:
179: public Shape getShape ()
180: {
181: return shape;
182: }
183:
184: public void setShape (final Shape shape)
185: {
186: this.shape = shape;
187: }
188:
189: }