1 |
14 |
jlechner |
/* CellRendererPane.java --
|
2 |
|
|
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
This file is part of GNU Classpath.
|
5 |
|
|
|
6 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
7 |
|
|
it under the terms of the GNU General Public License as published by
|
8 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
9 |
|
|
any later version.
|
10 |
|
|
|
11 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
12 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
|
|
General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License
|
17 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
18 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
|
|
02110-1301 USA.
|
20 |
|
|
|
21 |
|
|
Linking this library statically or dynamically with other modules is
|
22 |
|
|
making a combined work based on this library. Thus, the terms and
|
23 |
|
|
conditions of the GNU General Public License cover the whole
|
24 |
|
|
combination.
|
25 |
|
|
|
26 |
|
|
As a special exception, the copyright holders of this library give you
|
27 |
|
|
permission to link this library with independent modules to produce an
|
28 |
|
|
executable, regardless of the license terms of these independent
|
29 |
|
|
modules, and to copy and distribute the resulting executable under
|
30 |
|
|
terms of your choice, provided that you also meet, for each linked
|
31 |
|
|
independent module, the terms and conditions of the license of that
|
32 |
|
|
module. An independent module is a module which is not derived from
|
33 |
|
|
or based on this library. If you modify this library, you may extend
|
34 |
|
|
this exception to your version of the library, but you are not
|
35 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
36 |
|
|
exception statement from your version. */
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
package javax.swing;
|
40 |
|
|
|
41 |
|
|
import java.awt.Component;
|
42 |
|
|
import java.awt.Container;
|
43 |
|
|
import java.awt.Graphics;
|
44 |
|
|
import java.awt.Rectangle;
|
45 |
|
|
|
46 |
|
|
import javax.accessibility.Accessible;
|
47 |
|
|
import javax.accessibility.AccessibleContext;
|
48 |
|
|
import javax.accessibility.AccessibleRole;
|
49 |
|
|
|
50 |
|
|
/**
|
51 |
|
|
* Paints the cells of JList, JTable and JTree.
|
52 |
|
|
* It intercepts the usual paint tree, so that we don't walk up and
|
53 |
|
|
* repaint everything.
|
54 |
|
|
*
|
55 |
|
|
* @author Andrew Selkirk
|
56 |
|
|
*/
|
57 |
|
|
public class CellRendererPane extends Container implements Accessible
|
58 |
|
|
{
|
59 |
|
|
private static final long serialVersionUID = -7642183829532984273L;
|
60 |
|
|
|
61 |
|
|
/**
|
62 |
|
|
* Provides accessibility support for CellRendererPanes.
|
63 |
|
|
*/
|
64 |
|
|
protected class AccessibleCellRendererPane extends AccessibleAWTContainer
|
65 |
|
|
{
|
66 |
|
|
private static final long serialVersionUID = -8981090083147391074L;
|
67 |
|
|
|
68 |
|
|
/**
|
69 |
|
|
* Constructor AccessibleCellRendererPane
|
70 |
|
|
*/
|
71 |
|
|
protected AccessibleCellRendererPane()
|
72 |
|
|
{
|
73 |
|
|
// Nothing to do here.
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
/**
|
77 |
|
|
* getAccessibleRole
|
78 |
|
|
* @returns AccessibleRole
|
79 |
|
|
*/
|
80 |
|
|
public AccessibleRole getAccessibleRole()
|
81 |
|
|
{
|
82 |
|
|
return AccessibleRole.PANEL;
|
83 |
|
|
}
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
/**
|
87 |
|
|
* accessibleContext
|
88 |
|
|
*/
|
89 |
|
|
protected AccessibleContext accessibleContext = null;
|
90 |
|
|
|
91 |
|
|
/**
|
92 |
|
|
* Constructs a new CellRendererPane.
|
93 |
|
|
*/
|
94 |
|
|
public CellRendererPane()
|
95 |
|
|
{
|
96 |
|
|
// Nothing to do here.
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
/**
|
100 |
|
|
* Should not be called.
|
101 |
|
|
*
|
102 |
|
|
* @param graphics not used here
|
103 |
|
|
*/
|
104 |
|
|
public void update(Graphics graphics)
|
105 |
|
|
{
|
106 |
|
|
//Nothing to do here.
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
/**
|
110 |
|
|
* Despite normal behaviour this does <em>not</em> cause the container
|
111 |
|
|
* to be invalidated. This prevents propagating up the paint tree.
|
112 |
|
|
*/
|
113 |
|
|
public void invalidate()
|
114 |
|
|
{
|
115 |
|
|
// Overridden to do nothing.
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
/**
|
119 |
|
|
* Should not be called.
|
120 |
|
|
*
|
121 |
|
|
* @param graphics not used here
|
122 |
|
|
*/
|
123 |
|
|
public void paint(Graphics graphics)
|
124 |
|
|
{
|
125 |
|
|
// Overridden to do nothing.
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
/**
|
129 |
|
|
* Overridden to check if a component is already a child of this Container.
|
130 |
|
|
* If it's already a child, nothing is done. Otherwise we pass this to
|
131 |
|
|
* <code>super.addImpl()</code>.
|
132 |
|
|
*
|
133 |
|
|
* @param c the component to add
|
134 |
|
|
* @param constraints not used here
|
135 |
|
|
* @param index not used here
|
136 |
|
|
*/
|
137 |
|
|
protected void addImpl(Component c, Object constraints, int index)
|
138 |
|
|
{
|
139 |
|
|
if (!isAncestorOf(c))
|
140 |
|
|
{
|
141 |
|
|
super.addImpl(c, constraints, index);
|
142 |
|
|
}
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
/**
|
146 |
|
|
* Paints the specified component <code>c</code> on the {@link Graphics}
|
147 |
|
|
* context <code>graphics</code>. The Graphics context is tranlated to
|
148 |
|
|
* (x,y) and the components bounds are set to (w,h). If
|
149 |
|
|
* <code>shouldValidate</code>
|
150 |
|
|
* is set to true, then the component is validated before painting.
|
151 |
|
|
*
|
152 |
|
|
* @param graphics the graphics context to paint on
|
153 |
|
|
* @param c the component to be painted
|
154 |
|
|
* @param p the parent of the component
|
155 |
|
|
* @param x the X coordinate of the upper left corner where c should
|
156 |
|
|
be painted
|
157 |
|
|
* @param y the Y coordinate of the upper left corner where c should
|
158 |
|
|
be painted
|
159 |
|
|
* @param w the width of the components drawing area
|
160 |
|
|
* @param h the height of the components drawing area
|
161 |
|
|
* @param shouldValidate if <code>c</code> should be validated before
|
162 |
|
|
* painting
|
163 |
|
|
*/
|
164 |
|
|
public void paintComponent(Graphics graphics, Component c,
|
165 |
|
|
Container p, int x, int y, int w, int h,
|
166 |
|
|
boolean shouldValidate)
|
167 |
|
|
{
|
168 |
|
|
// reparent c
|
169 |
|
|
addImpl(c, null, 0);
|
170 |
|
|
|
171 |
|
|
Rectangle oldClip = graphics.getClipBounds();
|
172 |
|
|
// translate to (x,y)
|
173 |
|
|
graphics.translate(x, y);
|
174 |
|
|
graphics.clipRect(0, 0, w, h);
|
175 |
|
|
// set bounds of c
|
176 |
|
|
c.setBounds(0, 0, w, h);
|
177 |
|
|
|
178 |
|
|
// validate if necessary
|
179 |
|
|
if (shouldValidate)
|
180 |
|
|
{
|
181 |
|
|
c.validate();
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
// paint component
|
185 |
|
|
c.paint(graphics);
|
186 |
|
|
|
187 |
|
|
// untranslate g
|
188 |
|
|
graphics.translate(-x, -y);
|
189 |
|
|
graphics.setClip(oldClip);
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
/**
|
193 |
|
|
* Paints the specified component <code>c</code> on the {@link Graphics}
|
194 |
|
|
* context <code>graphics</code>. The Graphics context is tranlated to (x,y)
|
195 |
|
|
* and the components bounds are set to (w,h). The component is <em>not</em>
|
196 |
|
|
* validated before painting.
|
197 |
|
|
*
|
198 |
|
|
* @param graphics the graphics context to paint on
|
199 |
|
|
* @param c the component to be painted
|
200 |
|
|
* @param p the parent of the component
|
201 |
|
|
* @param x the X coordinate of the upper left corner where c should
|
202 |
|
|
be painted
|
203 |
|
|
* @param y the Y coordinate of the upper left corner where c should
|
204 |
|
|
be painted
|
205 |
|
|
* @param w the width of the components drawing area
|
206 |
|
|
* @param h the height of the components drawing area
|
207 |
|
|
*/
|
208 |
|
|
public void paintComponent(Graphics graphics, Component c,
|
209 |
|
|
Container p, int x, int y, int w, int h)
|
210 |
|
|
{
|
211 |
|
|
paintComponent(graphics, c, p, x, y, w, h, false);
|
212 |
|
|
}
|
213 |
|
|
|
214 |
|
|
/**
|
215 |
|
|
* Paints the specified component <code>c</code> on the {@link Graphics}
|
216 |
|
|
* context <code>g</code>. The Graphics context is tranlated to (r.x,r.y) and
|
217 |
|
|
* the components bounds are set to (r.width,r.height).
|
218 |
|
|
* The component is <em>not</em>
|
219 |
|
|
* validated before painting.
|
220 |
|
|
*
|
221 |
|
|
* @param graphics the graphics context to paint on
|
222 |
|
|
* @param c the component to be painted
|
223 |
|
|
* @param p the component on which we paint
|
224 |
|
|
* @param r the bounding rectangle of c
|
225 |
|
|
*/
|
226 |
|
|
public void paintComponent(Graphics graphics, Component c,
|
227 |
|
|
Container p, Rectangle r)
|
228 |
|
|
{
|
229 |
|
|
paintComponent(graphics, c, p, r.x, r.y, r.width, r.height);
|
230 |
|
|
}
|
231 |
|
|
|
232 |
|
|
/**
|
233 |
|
|
* getAccessibleContext <em>TODO</em>
|
234 |
|
|
* @return AccessibleContext
|
235 |
|
|
*/
|
236 |
|
|
public AccessibleContext getAccessibleContext()
|
237 |
|
|
{
|
238 |
|
|
if (accessibleContext == null)
|
239 |
|
|
accessibleContext = new AccessibleCellRendererPane();
|
240 |
|
|
|
241 |
|
|
return accessibleContext;
|
242 |
|
|
}
|
243 |
|
|
}
|