01: package org.cougaar.core.qos.frame.visualizer;
02:
03: import java.awt.BasicStroke;
04: import java.awt.Color;
05: import java.awt.Graphics2D;
06: import java.awt.Paint;
07: import java.awt.Shape;
08:
09: /**
10: * Created by IntelliJ IDEA.
11: * User: mwalczak
12: * Date: May 2, 2005
13: * Time: 10:58:31 AM
14: * To change this template use File | Settings | File Templates.
15: */
16: public class ShapeRenderer {
17:
18: public final static Paint DEFAULT_PAINT = Color.blue;
19: public final static Paint DEFAULT_SELECTED_PAINT = Color.magenta;
20: public final static Paint DEFAULT_FILL_PAINT = Color.blue;
21: public final static Paint DEFAULT_SELECTED_FILL_PAINt = Color.blue
22: .brighter();
23: public final static int DEFAULT_LINE_WIDTH = 2;
24:
25: String rendererName;
26: Paint paint = DEFAULT_PAINT,
27: selectedPaint = DEFAULT_SELECTED_PAINT;
28: Paint fillPaint = DEFAULT_FILL_PAINT,
29: selectedFillPaint = DEFAULT_SELECTED_FILL_PAINt;
30: BasicStroke lineStroke = new BasicStroke(DEFAULT_LINE_WIDTH);
31: boolean drawBorder = true, drawFilled = false;
32:
33: public ShapeRenderer() {
34: }
35:
36: public ShapeRenderer(String rendererName, Paint paint,
37: Paint selectedPaint, Paint fillPaint,
38: Paint selectedFillPaint, int lineWidth, boolean bordered,
39: boolean filled) {
40: this .rendererName = rendererName;
41: this .paint = paint;
42: this .selectedPaint = selectedPaint;
43: this .fillPaint = fillPaint;
44: this .selectedFillPaint = selectedFillPaint;
45: this .lineStroke = new BasicStroke(lineWidth);
46: this .drawBorder = bordered;
47: this .drawFilled = filled;
48: //if (paint == null || selectedPaint == null)
49: // throw new NullPointerException("paint or selecrtedPaint is null");
50: }
51:
52: public void setName(String name) {
53: this .rendererName = name;
54: }
55:
56: public String getName() {
57: return rendererName;
58: }
59:
60: public void drawShape(Graphics2D g2, ShapeGraphic shapeGraphic) {
61: if (shapeGraphic == null || shapeGraphic.getShape() == null)
62: return;
63: Paint drawP = (shapeGraphic.isSelected() ? selectedPaint
64: : paint);
65: Paint fillP = (shapeGraphic.isSelected() ? selectedFillPaint
66: : fillPaint);
67: Shape shape = shapeGraphic.getShape();
68: if (drawBorder && drawP != null) {
69: g2.setPaint(drawP);
70: g2.setStroke(lineStroke);
71: g2.draw(shape);
72: }
73: if (drawFilled) {
74: g2.setPaint((fillP != null ? fillP : drawP));
75: g2.fill(shape);
76: }
77: }
78: }
|