01: /*
02: * Copyright (c) 2004 JETA Software, Inc. All rights reserved.
03: *
04: * Redistribution and use in source and binary forms, with or without modification,
05: * are permitted provided that the following conditions are met:
06: *
07: * o Redistributions of source code must retain the above copyright notice,
08: * this list of conditions and the following disclaimer.
09: *
10: * o Redistributions in binary form must reproduce the above copyright notice,
11: * this list of conditions and the following disclaimer in the documentation
12: * and/or other materials provided with the distribution.
13: *
14: * o Neither the name of JETA Software nor the names of its contributors may
15: * be used to endorse or promote products derived from this software without
16: * specific prior written permission.
17: *
18: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21: * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22: * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23: * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26: * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28: */
29:
30: package com.jeta.forms.gui.effects;
31:
32: import java.awt.Color;
33: import java.awt.Component;
34: import java.awt.Graphics;
35: import java.awt.Graphics2D;
36: import java.awt.Rectangle;
37:
38: import com.jeta.forms.store.properties.effects.SolidProperty;
39:
40: /**
41: * This class is an implementation of a painter that renders a solid color on a
42: * part of a canvas or component. Keep in mind that the color is constant only
43: * for the current look and feel. If the look and feel changes, the color may
44: * change depending settings specified by the user in the designer.
45: *
46: * @author Jeff Tassin
47: */
48: public class SolidPainter implements Painter {
49: /**
50: * The property that defines the solid settings.
51: */
52: private SolidProperty m_solid_prop;
53:
54: /**
55: * Creates a <code>SolidPainter</code> instance with no color attributes.
56: */
57: public SolidPainter() {
58:
59: }
60:
61: /**
62: * Creates a <code>SolidPainter</code> instance with the specified color
63: * attributes.
64: */
65: public SolidPainter(SolidProperty prop) {
66: m_solid_prop = prop;
67: }
68:
69: /**
70: * Painter Implementation. Fills a rectangle with a solid color.
71: *
72: * @param g
73: * the graphics context
74: * @param rect
75: * the rectangle that defines the region to paint. Note, that
76: * this is different than the clipping rectangle.
77: */
78: public void paint(Component c, Graphics g, Rectangle rect) {
79: if (rect == null)
80: return;
81:
82: Graphics2D g2 = (Graphics2D) g;
83: Color old_color = g2.getColor();
84:
85: g.setColor(m_solid_prop.getColor());
86: g.fillRect(rect.x, rect.y, rect.width, rect.height);
87: g2.setColor(old_color);
88: }
89:
90: /**
91: * Sets the color attributes for this painter
92: *
93: * @param prop
94: * the color properties to set for this painter.
95: */
96: public void setSolidProperty(SolidProperty prop) {
97: m_solid_prop = prop;
98: }
99: }
|