1 | /*
|
---|
2 | * 01/22/2005
|
---|
3 | *
|
---|
4 | * ColorBackgroundPainterStrategy.java - Renders an RTextAreaBase's background
|
---|
5 | * as a single color.
|
---|
6 | *
|
---|
7 | * This library is distributed under a modified BSD license. See the included
|
---|
8 | * RSyntaxTextArea.License.txt file for details.
|
---|
9 | */
|
---|
10 | package org.fife.ui.rtextarea;
|
---|
11 |
|
---|
12 | import java.awt.Color;
|
---|
13 | import java.awt.Graphics;
|
---|
14 | import java.awt.Rectangle;
|
---|
15 |
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * A strategy for painting the background of an <code>RTextAreaBase</code>
|
---|
19 | * as a solid color. The default background for <code>RTextAreaBase</code>s
|
---|
20 | * is this strategy using the color white.
|
---|
21 | *
|
---|
22 | * @author Robert Futrell
|
---|
23 | * @version 0.1
|
---|
24 | * @see org.fife.ui.rtextarea.ImageBackgroundPainterStrategy
|
---|
25 | */
|
---|
26 | public class ColorBackgroundPainterStrategy
|
---|
27 | implements BackgroundPainterStrategy {
|
---|
28 |
|
---|
29 | private Color color;
|
---|
30 |
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Constructor.
|
---|
34 | *
|
---|
35 | * @param color The color to use when painting the background.
|
---|
36 | */
|
---|
37 | public ColorBackgroundPainterStrategy(Color color) {
|
---|
38 | setColor(color);
|
---|
39 | }
|
---|
40 |
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Returns whether or not the specified object is equivalent to
|
---|
44 | * this one.
|
---|
45 | *
|
---|
46 | * @param o2 The object to which to compare.
|
---|
47 | * @return Whether <code>o2</code> is another
|
---|
48 | * <code>ColorBackgroundPainterStrategy</code> representing
|
---|
49 | * the same color as this one.
|
---|
50 | */
|
---|
51 | public boolean equals(Object o2) {
|
---|
52 | return o2!=null &&
|
---|
53 | (o2 instanceof ColorBackgroundPainterStrategy) &&
|
---|
54 | this.color.equals(
|
---|
55 | ((ColorBackgroundPainterStrategy)o2).getColor());
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Returns the color used to paint the background.
|
---|
61 | *
|
---|
62 | * @return The color.
|
---|
63 | * @see #setColor
|
---|
64 | */
|
---|
65 | public Color getColor() {
|
---|
66 | return color;
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Returns the hash code to use when placing an object of this type into
|
---|
72 | * hash maps. This method is implemented since we overrode
|
---|
73 | * {@link #equals(Object)}, to keep FindBugs happy.
|
---|
74 | *
|
---|
75 | * @return The hash code.
|
---|
76 | */
|
---|
77 | public int hashCode() {
|
---|
78 | return color.hashCode();
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Paints the background.
|
---|
84 | *
|
---|
85 | * @param g The graphics context.
|
---|
86 | * @param bounds The bounds of the object whose backgrouns we're
|
---|
87 | * painting.
|
---|
88 | */
|
---|
89 | public void paint(Graphics g, Rectangle bounds) {
|
---|
90 | Color temp = g.getColor();
|
---|
91 | g.setColor(color);
|
---|
92 | g.fillRect(bounds.x,bounds.y, bounds.width,bounds.height);
|
---|
93 | g.setColor(temp);
|
---|
94 | }
|
---|
95 |
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * Sets the color used to paint the background.
|
---|
99 | *
|
---|
100 | * @param color The color to use.
|
---|
101 | * @see #getColor
|
---|
102 | */
|
---|
103 | public void setColor(Color color) {
|
---|
104 | this.color = color;
|
---|
105 | }
|
---|
106 |
|
---|
107 |
|
---|
108 | } |
---|