author | malenkov |
Wed, 30 Apr 2014 19:28:05 +0400 | |
changeset 24544 | c0133e7c7162 |
parent 22574 | 7f8ce0c8c20a |
child 25172 | b345c47c02b3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
21278
diff
changeset
|
2 |
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.swing.table; |
|
27 |
||
28 |
import sun.swing.table.DefaultTableCellHeaderRenderer; |
|
29 |
||
30 |
import java.util.*; |
|
31 |
import java.awt.*; |
|
32 |
import java.awt.event.*; |
|
33 |
||
34 |
import javax.swing.*; |
|
35 |
import javax.swing.event.*; |
|
36 |
import javax.swing.plaf.*; |
|
37 |
import javax.accessibility.*; |
|
38 |
||
39 |
import java.beans.PropertyChangeListener; |
|
466
6acd5ec503a8
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents:
2
diff
changeset
|
40 |
import java.beans.Transient; |
2 | 41 |
|
42 |
import java.io.ObjectOutputStream; |
|
43 |
import java.io.ObjectInputStream; |
|
44 |
import java.io.IOException; |
|
45 |
||
46 |
||
47 |
/** |
|
48 |
* This is the object which manages the header of the <code>JTable</code>. |
|
49 |
* <p> |
|
50 |
* <strong>Warning:</strong> |
|
51 |
* Serialized objects of this class will not be compatible with |
|
52 |
* future Swing releases. The current serialization support is |
|
53 |
* appropriate for short term storage or RMI between applications running |
|
54 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 55 |
* of all JavaBeans™ |
2 | 56 |
* has been added to the <code>java.beans</code> package. |
57 |
* Please see {@link java.beans.XMLEncoder}. |
|
58 |
* |
|
59 |
* @author Alan Chung |
|
60 |
* @author Philip Milne |
|
61 |
* @see javax.swing.JTable |
|
62 |
*/ |
|
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
21278
diff
changeset
|
63 |
@SuppressWarnings("serial") // Same-version serialization only |
2 | 64 |
public class JTableHeader extends JComponent implements TableColumnModelListener, Accessible |
65 |
{ |
|
66 |
/** |
|
67 |
* @see #getUIClassID |
|
68 |
* @see #readObject |
|
69 |
*/ |
|
70 |
private static final String uiClassID = "TableHeaderUI"; |
|
71 |
||
72 |
// |
|
73 |
// Instance Variables |
|
74 |
// |
|
75 |
/** |
|
76 |
* The table for which this object is the header; |
|
77 |
* the default is <code>null</code>. |
|
78 |
*/ |
|
79 |
protected JTable table; |
|
80 |
||
81 |
/** |
|
82 |
* The <code>TableColumnModel</code> of the table header. |
|
83 |
*/ |
|
84 |
protected TableColumnModel columnModel; |
|
85 |
||
86 |
/** |
|
87 |
* If true, reordering of columns are allowed by the user; |
|
88 |
* the default is true. |
|
89 |
*/ |
|
90 |
protected boolean reorderingAllowed; |
|
91 |
||
92 |
/** |
|
93 |
* If true, resizing of columns are allowed by the user; |
|
94 |
* the default is true. |
|
95 |
*/ |
|
96 |
protected boolean resizingAllowed; |
|
97 |
||
98 |
/** |
|
99 |
* Obsolete as of Java 2 platform v1.3. Real time repaints, in response |
|
100 |
* to column dragging or resizing, are now unconditional. |
|
101 |
*/ |
|
102 |
/* |
|
103 |
* If this flag is true, then the header will repaint the table as |
|
104 |
* a column is dragged or resized; the default is true. |
|
105 |
*/ |
|
106 |
protected boolean updateTableInRealTime; |
|
107 |
||
108 |
/** The index of the column being resized. <code>null</code> if not resizing. */ |
|
109 |
transient protected TableColumn resizingColumn; |
|
110 |
||
111 |
/** The index of the column being dragged. <code>null</code> if not dragging. */ |
|
112 |
transient protected TableColumn draggedColumn; |
|
113 |
||
114 |
/** The distance from its original position the column has been dragged. */ |
|
115 |
transient protected int draggedDistance; |
|
116 |
||
117 |
/** |
|
118 |
* The default renderer to be used when a <code>TableColumn</code> |
|
119 |
* does not define a <code>headerRenderer</code>. |
|
120 |
*/ |
|
121 |
private TableCellRenderer defaultRenderer; |
|
122 |
||
123 |
// |
|
124 |
// Constructors |
|
125 |
// |
|
126 |
||
127 |
/** |
|
128 |
* Constructs a <code>JTableHeader</code> with a default |
|
129 |
* <code>TableColumnModel</code>. |
|
130 |
* |
|
131 |
* @see #createDefaultColumnModel |
|
132 |
*/ |
|
133 |
public JTableHeader() { |
|
134 |
this(null); |
|
135 |
} |
|
136 |
||
137 |
/** |
|
138 |
* Constructs a <code>JTableHeader</code> which is initialized with |
|
139 |
* <code>cm</code> as the column model. If <code>cm</code> is |
|
140 |
* <code>null</code> this method will initialize the table header |
|
141 |
* with a default <code>TableColumnModel</code>. |
|
142 |
* |
|
143 |
* @param cm the column model for the table |
|
144 |
* @see #createDefaultColumnModel |
|
145 |
*/ |
|
146 |
public JTableHeader(TableColumnModel cm) { |
|
147 |
super(); |
|
148 |
||
149 |
//setFocusable(false); // for strict win/mac compatibility mode, |
|
150 |
// this method should be invoked |
|
151 |
||
152 |
if (cm == null) |
|
153 |
cm = createDefaultColumnModel(); |
|
154 |
setColumnModel(cm); |
|
155 |
||
156 |
// Initialize local ivars |
|
157 |
initializeLocalVars(); |
|
158 |
||
159 |
// Get UI going |
|
160 |
updateUI(); |
|
161 |
} |
|
162 |
||
163 |
// |
|
164 |
// Local behavior attributes |
|
165 |
// |
|
166 |
||
167 |
/** |
|
168 |
* Sets the table associated with this header. |
|
169 |
* @param table the new table |
|
170 |
* @beaninfo |
|
171 |
* bound: true |
|
172 |
* description: The table associated with this header. |
|
173 |
*/ |
|
174 |
public void setTable(JTable table) { |
|
175 |
JTable old = this.table; |
|
176 |
this.table = table; |
|
177 |
firePropertyChange("table", old, table); |
|
178 |
} |
|
179 |
||
180 |
/** |
|
181 |
* Returns the table associated with this header. |
|
182 |
* @return the <code>table</code> property |
|
183 |
*/ |
|
184 |
public JTable getTable() { |
|
185 |
return table; |
|
186 |
} |
|
187 |
||
188 |
/** |
|
189 |
* Sets whether the user can drag column headers to reorder columns. |
|
190 |
* |
|
191 |
* @param reorderingAllowed true if the table view should allow |
|
192 |
* reordering; otherwise false |
|
193 |
* @see #getReorderingAllowed |
|
194 |
* @beaninfo |
|
195 |
* bound: true |
|
196 |
* description: Whether the user can drag column headers to reorder columns. |
|
197 |
*/ |
|
198 |
public void setReorderingAllowed(boolean reorderingAllowed) { |
|
199 |
boolean old = this.reorderingAllowed; |
|
200 |
this.reorderingAllowed = reorderingAllowed; |
|
201 |
firePropertyChange("reorderingAllowed", old, reorderingAllowed); |
|
202 |
} |
|
203 |
||
204 |
/** |
|
205 |
* Returns true if the user is allowed to rearrange columns by |
|
206 |
* dragging their headers, false otherwise. The default is true. You can |
|
207 |
* rearrange columns programmatically regardless of this setting. |
|
208 |
* |
|
209 |
* @return the <code>reorderingAllowed</code> property |
|
210 |
* @see #setReorderingAllowed |
|
211 |
*/ |
|
212 |
public boolean getReorderingAllowed() { |
|
213 |
return reorderingAllowed; |
|
214 |
} |
|
215 |
||
216 |
/** |
|
217 |
* Sets whether the user can resize columns by dragging between headers. |
|
218 |
* |
|
219 |
* @param resizingAllowed true if table view should allow |
|
220 |
* resizing |
|
221 |
* @see #getResizingAllowed |
|
222 |
* @beaninfo |
|
223 |
* bound: true |
|
224 |
* description: Whether the user can resize columns by dragging between headers. |
|
225 |
*/ |
|
226 |
public void setResizingAllowed(boolean resizingAllowed) { |
|
227 |
boolean old = this.resizingAllowed; |
|
228 |
this.resizingAllowed = resizingAllowed; |
|
229 |
firePropertyChange("resizingAllowed", old, resizingAllowed); |
|
230 |
} |
|
231 |
||
232 |
/** |
|
233 |
* Returns true if the user is allowed to resize columns by dragging |
|
234 |
* between their headers, false otherwise. The default is true. You can |
|
235 |
* resize columns programmatically regardless of this setting. |
|
236 |
* |
|
237 |
* @return the <code>resizingAllowed</code> property |
|
238 |
* @see #setResizingAllowed |
|
239 |
*/ |
|
240 |
public boolean getResizingAllowed() { |
|
241 |
return resizingAllowed; |
|
242 |
} |
|
243 |
||
244 |
/** |
|
245 |
* Returns the the dragged column, if and only if, a drag is in |
|
246 |
* process, otherwise returns <code>null</code>. |
|
247 |
* |
|
248 |
* @return the dragged column, if a drag is in |
|
249 |
* process, otherwise returns <code>null</code> |
|
250 |
* @see #getDraggedDistance |
|
251 |
*/ |
|
252 |
public TableColumn getDraggedColumn() { |
|
253 |
return draggedColumn; |
|
254 |
} |
|
255 |
||
256 |
/** |
|
257 |
* Returns the column's horizontal distance from its original |
|
258 |
* position, if and only if, a drag is in process. Otherwise, the |
|
259 |
* the return value is meaningless. |
|
260 |
* |
|
261 |
* @return the column's horizontal distance from its original |
|
262 |
* position, if a drag is in process, otherwise the return |
|
263 |
* value is meaningless |
|
264 |
* @see #getDraggedColumn |
|
265 |
*/ |
|
266 |
public int getDraggedDistance() { |
|
267 |
return draggedDistance; |
|
268 |
} |
|
269 |
||
270 |
/** |
|
271 |
* Returns the resizing column. If no column is being |
|
272 |
* resized this method returns <code>null</code>. |
|
273 |
* |
|
274 |
* @return the resizing column, if a resize is in process, otherwise |
|
275 |
* returns <code>null</code> |
|
276 |
*/ |
|
277 |
public TableColumn getResizingColumn() { |
|
278 |
return resizingColumn; |
|
279 |
} |
|
280 |
||
281 |
/** |
|
282 |
* Obsolete as of Java 2 platform v1.3. Real time repaints, in response to |
|
283 |
* column dragging or resizing, are now unconditional. |
|
284 |
*/ |
|
285 |
/* |
|
286 |
* Sets whether the body of the table updates in real time when |
|
287 |
* a column is resized or dragged. |
|
288 |
* |
|
289 |
* @param flag true if tableView should update |
|
290 |
* the body of the table in real time |
|
291 |
* @see #getUpdateTableInRealTime |
|
292 |
*/ |
|
293 |
public void setUpdateTableInRealTime(boolean flag) { |
|
294 |
updateTableInRealTime = flag; |
|
295 |
} |
|
296 |
||
297 |
/** |
|
298 |
* Obsolete as of Java 2 platform v1.3. Real time repaints, in response to |
|
299 |
* column dragging or resizing, are now unconditional. |
|
300 |
*/ |
|
301 |
/* |
|
302 |
* Returns true if the body of the table view updates in real |
|
303 |
* time when a column is resized or dragged. User can set this flag to |
|
304 |
* false to speed up the table's response to user resize or drag actions. |
|
305 |
* The default is true. |
|
306 |
* |
|
307 |
* @return true if the table updates in real time |
|
308 |
* @see #setUpdateTableInRealTime |
|
309 |
*/ |
|
310 |
public boolean getUpdateTableInRealTime() { |
|
311 |
return updateTableInRealTime; |
|
312 |
} |
|
313 |
||
314 |
/** |
|
315 |
* Sets the default renderer to be used when no <code>headerRenderer</code> |
|
316 |
* is defined by a <code>TableColumn</code>. |
|
317 |
* @param defaultRenderer the default renderer |
|
318 |
* @since 1.3 |
|
319 |
*/ |
|
320 |
public void setDefaultRenderer(TableCellRenderer defaultRenderer) { |
|
321 |
this.defaultRenderer = defaultRenderer; |
|
322 |
} |
|
323 |
||
324 |
/** |
|
325 |
* Returns the default renderer used when no <code>headerRenderer</code> |
|
326 |
* is defined by a <code>TableColumn</code>. |
|
327 |
* @return the default renderer |
|
328 |
* @since 1.3 |
|
329 |
*/ |
|
466
6acd5ec503a8
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents:
2
diff
changeset
|
330 |
@Transient |
2 | 331 |
public TableCellRenderer getDefaultRenderer() { |
332 |
return defaultRenderer; |
|
333 |
} |
|
334 |
||
335 |
/** |
|
336 |
* Returns the index of the column that <code>point</code> lies in, or -1 if it |
|
337 |
* lies out of bounds. |
|
338 |
* |
|
339 |
* @return the index of the column that <code>point</code> lies in, or -1 if it |
|
340 |
* lies out of bounds |
|
341 |
*/ |
|
342 |
public int columnAtPoint(Point point) { |
|
343 |
int x = point.x; |
|
344 |
if (!getComponentOrientation().isLeftToRight()) { |
|
345 |
x = getWidthInRightToLeft() - x - 1; |
|
346 |
} |
|
347 |
return getColumnModel().getColumnIndexAtX(x); |
|
348 |
} |
|
349 |
||
350 |
/** |
|
351 |
* Returns the rectangle containing the header tile at <code>column</code>. |
|
352 |
* When the <code>column</code> parameter is out of bounds this method uses the |
|
353 |
* same conventions as the <code>JTable</code> method <code>getCellRect</code>. |
|
354 |
* |
|
355 |
* @return the rectangle containing the header tile at <code>column</code> |
|
356 |
* @see JTable#getCellRect |
|
357 |
*/ |
|
358 |
public Rectangle getHeaderRect(int column) { |
|
359 |
Rectangle r = new Rectangle(); |
|
360 |
TableColumnModel cm = getColumnModel(); |
|
361 |
||
362 |
r.height = getHeight(); |
|
363 |
||
364 |
if (column < 0) { |
|
365 |
// x = width = 0; |
|
366 |
if( !getComponentOrientation().isLeftToRight() ) { |
|
367 |
r.x = getWidthInRightToLeft(); |
|
368 |
} |
|
369 |
} |
|
370 |
else if (column >= cm.getColumnCount()) { |
|
371 |
if( getComponentOrientation().isLeftToRight() ) { |
|
372 |
r.x = getWidth(); |
|
373 |
} |
|
374 |
} |
|
375 |
else { |
|
376 |
for(int i = 0; i < column; i++) { |
|
377 |
r.x += cm.getColumn(i).getWidth(); |
|
378 |
} |
|
379 |
if( !getComponentOrientation().isLeftToRight() ) { |
|
380 |
r.x = getWidthInRightToLeft() - r.x - cm.getColumn(column).getWidth(); |
|
381 |
} |
|
382 |
||
383 |
r.width = cm.getColumn(column).getWidth(); |
|
384 |
} |
|
385 |
return r; |
|
386 |
} |
|
387 |
||
388 |
||
389 |
/** |
|
390 |
* Allows the renderer's tips to be used if there is text set. |
|
391 |
* @param event the location of the event identifies the proper |
|
392 |
* renderer and, therefore, the proper tip |
|
393 |
* @return the tool tip for this component |
|
394 |
*/ |
|
395 |
public String getToolTipText(MouseEvent event) { |
|
396 |
String tip = null; |
|
397 |
Point p = event.getPoint(); |
|
398 |
int column; |
|
399 |
||
400 |
// Locate the renderer under the event location |
|
401 |
if ((column = columnAtPoint(p)) != -1) { |
|
402 |
TableColumn aColumn = columnModel.getColumn(column); |
|
403 |
TableCellRenderer renderer = aColumn.getHeaderRenderer(); |
|
404 |
if (renderer == null) { |
|
405 |
renderer = defaultRenderer; |
|
406 |
} |
|
407 |
Component component = renderer.getTableCellRendererComponent( |
|
408 |
getTable(), aColumn.getHeaderValue(), false, false, |
|
409 |
-1, column); |
|
410 |
||
411 |
// Now have to see if the component is a JComponent before |
|
412 |
// getting the tip |
|
413 |
if (component instanceof JComponent) { |
|
414 |
// Convert the event to the renderer's coordinate system |
|
415 |
MouseEvent newEvent; |
|
416 |
Rectangle cellRect = getHeaderRect(column); |
|
417 |
||
418 |
p.translate(-cellRect.x, -cellRect.y); |
|
419 |
newEvent = new MouseEvent(component, event.getID(), |
|
420 |
event.getWhen(), event.getModifiers(), |
|
421 |
p.x, p.y, event.getXOnScreen(), event.getYOnScreen(), |
|
422 |
event.getClickCount(), |
|
423 |
event.isPopupTrigger(), MouseEvent.NOBUTTON); |
|
424 |
||
425 |
tip = ((JComponent)component).getToolTipText(newEvent); |
|
426 |
} |
|
427 |
} |
|
428 |
||
429 |
// No tip from the renderer get our own tip |
|
430 |
if (tip == null) |
|
431 |
tip = getToolTipText(); |
|
432 |
||
433 |
return tip; |
|
434 |
} |
|
435 |
||
436 |
// |
|
437 |
// Managing TableHeaderUI |
|
438 |
// |
|
439 |
||
440 |
/** |
|
20428
929cd48fca8a
8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents:
5506
diff
changeset
|
441 |
* Returns the look and feel (L&F) object that renders this component. |
2 | 442 |
* |
443 |
* @return the <code>TableHeaderUI</code> object that renders this component |
|
444 |
*/ |
|
445 |
public TableHeaderUI getUI() { |
|
446 |
return (TableHeaderUI)ui; |
|
447 |
} |
|
448 |
||
449 |
/** |
|
20428
929cd48fca8a
8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents:
5506
diff
changeset
|
450 |
* Sets the look and feel (L&F) object that renders this component. |
2 | 451 |
* |
20428
929cd48fca8a
8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents:
5506
diff
changeset
|
452 |
* @param ui the <code>TableHeaderUI</code> L&F object |
2 | 453 |
* @see UIDefaults#getUI |
454 |
*/ |
|
455 |
public void setUI(TableHeaderUI ui){ |
|
456 |
if (this.ui != ui) { |
|
457 |
super.setUI(ui); |
|
458 |
repaint(); |
|
459 |
} |
|
460 |
} |
|
461 |
||
462 |
/** |
|
463 |
* Notification from the <code>UIManager</code> that the look and feel |
|
20428
929cd48fca8a
8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents:
5506
diff
changeset
|
464 |
* (L&F) has changed. |
2 | 465 |
* Replaces the current UI object with the latest version from the |
466 |
* <code>UIManager</code>. |
|
467 |
* |
|
468 |
* @see JComponent#updateUI |
|
469 |
*/ |
|
470 |
public void updateUI(){ |
|
471 |
setUI((TableHeaderUI)UIManager.getUI(this)); |
|
472 |
||
473 |
TableCellRenderer renderer = getDefaultRenderer(); |
|
474 |
if (renderer instanceof Component) { |
|
475 |
SwingUtilities.updateComponentTreeUI((Component)renderer); |
|
476 |
} |
|
477 |
} |
|
478 |
||
479 |
||
480 |
/** |
|
481 |
* Returns the suffix used to construct the name of the look and feel |
|
20428
929cd48fca8a
8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents:
5506
diff
changeset
|
482 |
* (L&F) class used to render this component. |
2 | 483 |
* @return the string "TableHeaderUI" |
484 |
* |
|
485 |
* @return "TableHeaderUI" |
|
486 |
* @see JComponent#getUIClassID |
|
487 |
* @see UIDefaults#getUI |
|
488 |
*/ |
|
489 |
public String getUIClassID() { |
|
490 |
return uiClassID; |
|
491 |
} |
|
492 |
||
493 |
||
494 |
// |
|
495 |
// Managing models |
|
496 |
// |
|
497 |
||
498 |
||
499 |
/** |
|
500 |
* Sets the column model for this table to <code>newModel</code> and registers |
|
501 |
* for listener notifications from the new column model. |
|
502 |
* |
|
503 |
* @param columnModel the new data source for this table |
|
504 |
* @exception IllegalArgumentException |
|
505 |
* if <code>newModel</code> is <code>null</code> |
|
506 |
* @see #getColumnModel |
|
507 |
* @beaninfo |
|
508 |
* bound: true |
|
509 |
* description: The object governing the way columns appear in the view. |
|
510 |
*/ |
|
511 |
public void setColumnModel(TableColumnModel columnModel) { |
|
512 |
if (columnModel == null) { |
|
513 |
throw new IllegalArgumentException("Cannot set a null ColumnModel"); |
|
514 |
} |
|
515 |
TableColumnModel old = this.columnModel; |
|
516 |
if (columnModel != old) { |
|
517 |
if (old != null) { |
|
518 |
old.removeColumnModelListener(this); |
|
519 |
} |
|
520 |
this.columnModel = columnModel; |
|
521 |
columnModel.addColumnModelListener(this); |
|
522 |
||
523 |
firePropertyChange("columnModel", old, columnModel); |
|
524 |
resizeAndRepaint(); |
|
525 |
} |
|
526 |
} |
|
527 |
||
528 |
/** |
|
529 |
* Returns the <code>TableColumnModel</code> that contains all column information |
|
530 |
* of this table header. |
|
531 |
* |
|
532 |
* @return the <code>columnModel</code> property |
|
533 |
* @see #setColumnModel |
|
534 |
*/ |
|
535 |
public TableColumnModel getColumnModel() { |
|
536 |
return columnModel; |
|
537 |
} |
|
538 |
||
539 |
// |
|
540 |
// Implementing TableColumnModelListener interface |
|
541 |
// |
|
542 |
||
543 |
/** |
|
544 |
* Invoked when a column is added to the table column model. |
|
545 |
* <p> |
|
546 |
* Application code will not use these methods explicitly, they |
|
547 |
* are used internally by <code>JTable</code>. |
|
548 |
* |
|
549 |
* @param e the event received |
|
550 |
* @see TableColumnModelListener |
|
551 |
*/ |
|
552 |
public void columnAdded(TableColumnModelEvent e) { resizeAndRepaint(); } |
|
553 |
||
554 |
||
555 |
/** |
|
556 |
* Invoked when a column is removed from the table column model. |
|
557 |
* <p> |
|
558 |
* Application code will not use these methods explicitly, they |
|
559 |
* are used internally by <code>JTable</code>. |
|
560 |
* |
|
561 |
* @param e the event received |
|
562 |
* @see TableColumnModelListener |
|
563 |
*/ |
|
564 |
public void columnRemoved(TableColumnModelEvent e) { resizeAndRepaint(); } |
|
565 |
||
566 |
||
567 |
/** |
|
568 |
* Invoked when a column is repositioned. |
|
569 |
* <p> |
|
570 |
* Application code will not use these methods explicitly, they |
|
571 |
* are used internally by <code>JTable</code>. |
|
572 |
* |
|
573 |
* @param e the event received |
|
574 |
* @see TableColumnModelListener |
|
575 |
*/ |
|
576 |
public void columnMoved(TableColumnModelEvent e) { repaint(); } |
|
577 |
||
578 |
||
579 |
/** |
|
580 |
* Invoked when a column is moved due to a margin change. |
|
581 |
* <p> |
|
582 |
* Application code will not use these methods explicitly, they |
|
583 |
* are used internally by <code>JTable</code>. |
|
584 |
* |
|
585 |
* @param e the event received |
|
586 |
* @see TableColumnModelListener |
|
587 |
*/ |
|
588 |
public void columnMarginChanged(ChangeEvent e) { resizeAndRepaint(); } |
|
589 |
||
590 |
||
591 |
// --Redrawing the header is slow in cell selection mode. |
|
592 |
// --Since header selection is ugly and it is always clear from the |
|
593 |
// --view which columns are selected, don't redraw the header. |
|
594 |
/** |
|
595 |
* Invoked when the selection model of the <code>TableColumnModel</code> |
|
596 |
* is changed. This method currently has no effect (the header is not |
|
597 |
* redrawn). |
|
598 |
* <p> |
|
599 |
* Application code will not use these methods explicitly, they |
|
600 |
* are used internally by <code>JTable</code>. |
|
601 |
* |
|
602 |
* @param e the event received |
|
603 |
* @see TableColumnModelListener |
|
604 |
*/ |
|
605 |
public void columnSelectionChanged(ListSelectionEvent e) { } // repaint(); } |
|
606 |
||
607 |
// |
|
608 |
// Package Methods |
|
609 |
// |
|
610 |
||
611 |
/** |
|
612 |
* Returns the default column model object which is |
|
613 |
* a <code>DefaultTableColumnModel</code>. A subclass can override this |
|
614 |
* method to return a different column model object |
|
615 |
* |
|
616 |
* @return the default column model object |
|
617 |
*/ |
|
618 |
protected TableColumnModel createDefaultColumnModel() { |
|
619 |
return new DefaultTableColumnModel(); |
|
620 |
} |
|
621 |
||
622 |
/** |
|
623 |
* Returns a default renderer to be used when no header renderer |
|
624 |
* is defined by a <code>TableColumn</code>. |
|
625 |
* |
|
626 |
* @return the default table column renderer |
|
627 |
* @since 1.3 |
|
628 |
*/ |
|
629 |
protected TableCellRenderer createDefaultRenderer() { |
|
630 |
return new DefaultTableCellHeaderRenderer(); |
|
631 |
} |
|
632 |
||
633 |
||
634 |
/** |
|
635 |
* Initializes the local variables and properties with default values. |
|
636 |
* Used by the constructor methods. |
|
637 |
*/ |
|
638 |
protected void initializeLocalVars() { |
|
639 |
setOpaque(true); |
|
640 |
table = null; |
|
641 |
reorderingAllowed = true; |
|
642 |
resizingAllowed = true; |
|
643 |
draggedColumn = null; |
|
644 |
draggedDistance = 0; |
|
645 |
resizingColumn = null; |
|
646 |
updateTableInRealTime = true; |
|
647 |
||
648 |
// I'm registered to do tool tips so we can draw tips for the |
|
649 |
// renderers |
|
650 |
ToolTipManager toolTipManager = ToolTipManager.sharedInstance(); |
|
651 |
toolTipManager.registerComponent(this); |
|
652 |
setDefaultRenderer(createDefaultRenderer()); |
|
653 |
} |
|
654 |
||
655 |
/** |
|
656 |
* Sizes the header and marks it as needing display. Equivalent |
|
657 |
* to <code>revalidate</code> followed by <code>repaint</code>. |
|
658 |
*/ |
|
659 |
public void resizeAndRepaint() { |
|
660 |
revalidate(); |
|
661 |
repaint(); |
|
662 |
} |
|
663 |
||
664 |
/** |
|
665 |
* Sets the header's <code>draggedColumn</code> to <code>aColumn</code>. |
|
666 |
* <p> |
|
667 |
* Application code will not use this method explicitly, it is used |
|
668 |
* internally by the column dragging mechanism. |
|
669 |
* |
|
670 |
* @param aColumn the column being dragged, or <code>null</code> if |
|
671 |
* no column is being dragged |
|
672 |
*/ |
|
673 |
public void setDraggedColumn(TableColumn aColumn) { |
|
674 |
draggedColumn = aColumn; |
|
675 |
} |
|
676 |
||
677 |
/** |
|
678 |
* Sets the header's <code>draggedDistance</code> to <code>distance</code>. |
|
679 |
* @param distance the distance dragged |
|
680 |
*/ |
|
681 |
public void setDraggedDistance(int distance) { |
|
682 |
draggedDistance = distance; |
|
683 |
} |
|
684 |
||
685 |
/** |
|
686 |
* Sets the header's <code>resizingColumn</code> to <code>aColumn</code>. |
|
687 |
* <p> |
|
688 |
* Application code will not use this method explicitly, it |
|
689 |
* is used internally by the column sizing mechanism. |
|
690 |
* |
|
691 |
* @param aColumn the column being resized, or <code>null</code> if |
|
692 |
* no column is being resized |
|
693 |
*/ |
|
694 |
public void setResizingColumn(TableColumn aColumn) { |
|
695 |
resizingColumn = aColumn; |
|
696 |
} |
|
697 |
||
698 |
/** |
|
699 |
* See <code>readObject</code> and <code>writeObject</code> in |
|
700 |
* <code>JComponent</code> for more |
|
701 |
* information about serialization in Swing. |
|
702 |
*/ |
|
703 |
private void writeObject(ObjectOutputStream s) throws IOException { |
|
704 |
s.defaultWriteObject(); |
|
705 |
if ((ui != null) && (getUIClassID().equals(uiClassID))) { |
|
706 |
ui.installUI(this); |
|
707 |
} |
|
708 |
} |
|
709 |
||
710 |
private int getWidthInRightToLeft() { |
|
711 |
if ((table != null) && |
|
712 |
(table.getAutoResizeMode() != JTable.AUTO_RESIZE_OFF)) { |
|
713 |
return table.getWidth(); |
|
714 |
} |
|
715 |
return super.getWidth(); |
|
716 |
} |
|
717 |
||
718 |
/** |
|
719 |
* Returns a string representation of this <code>JTableHeader</code>. This method |
|
720 |
* is intended to be used only for debugging purposes, and the |
|
721 |
* content and format of the returned string may vary between |
|
722 |
* implementations. The returned string may be empty but may not |
|
723 |
* be <code>null</code>. |
|
724 |
* <P> |
|
725 |
* Overriding <code>paramString</code> to provide information about the |
|
726 |
* specific new aspects of the JFC components. |
|
727 |
* |
|
728 |
* @return a string representation of this <code>JTableHeader</code> |
|
729 |
*/ |
|
730 |
protected String paramString() { |
|
731 |
String reorderingAllowedString = (reorderingAllowed ? |
|
732 |
"true" : "false"); |
|
733 |
String resizingAllowedString = (resizingAllowed ? |
|
734 |
"true" : "false"); |
|
735 |
String updateTableInRealTimeString = (updateTableInRealTime ? |
|
736 |
"true" : "false"); |
|
737 |
||
738 |
return super.paramString() + |
|
739 |
",draggedDistance=" + draggedDistance + |
|
740 |
",reorderingAllowed=" + reorderingAllowedString + |
|
741 |
",resizingAllowed=" + resizingAllowedString + |
|
742 |
",updateTableInRealTime=" + updateTableInRealTimeString; |
|
743 |
} |
|
744 |
||
745 |
///////////////// |
|
746 |
// Accessibility support |
|
747 |
//////////////// |
|
748 |
||
749 |
/** |
|
750 |
* Gets the AccessibleContext associated with this JTableHeader. |
|
751 |
* For JTableHeaders, the AccessibleContext takes the form of an |
|
752 |
* AccessibleJTableHeader. |
|
753 |
* A new AccessibleJTableHeader instance is created if necessary. |
|
754 |
* |
|
755 |
* @return an AccessibleJTableHeader that serves as the |
|
756 |
* AccessibleContext of this JTableHeader |
|
757 |
*/ |
|
758 |
public AccessibleContext getAccessibleContext() { |
|
759 |
if (accessibleContext == null) { |
|
760 |
accessibleContext = new AccessibleJTableHeader(); |
|
761 |
} |
|
762 |
return accessibleContext; |
|
763 |
} |
|
764 |
||
765 |
// |
|
766 |
// *** should also implement AccessibleSelection? |
|
767 |
// *** and what's up with keyboard navigation/manipulation? |
|
768 |
// |
|
769 |
/** |
|
770 |
* This class implements accessibility support for the |
|
771 |
* <code>JTableHeader</code> class. It provides an implementation of the |
|
772 |
* Java Accessibility API appropriate to table header user-interface |
|
773 |
* elements. |
|
774 |
* <p> |
|
775 |
* <strong>Warning:</strong> |
|
776 |
* Serialized objects of this class will not be compatible with |
|
777 |
* future Swing releases. The current serialization support is |
|
778 |
* appropriate for short term storage or RMI between applications running |
|
779 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 780 |
* of all JavaBeans™ |
2 | 781 |
* has been added to the <code>java.beans</code> package. |
782 |
* Please see {@link java.beans.XMLEncoder}. |
|
783 |
*/ |
|
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
21278
diff
changeset
|
784 |
@SuppressWarnings("serial") // Same-version serialization only |
2 | 785 |
protected class AccessibleJTableHeader extends AccessibleJComponent { |
786 |
||
787 |
/** |
|
788 |
* Get the role of this object. |
|
789 |
* |
|
790 |
* @return an instance of AccessibleRole describing the role of the |
|
791 |
* object |
|
792 |
* @see AccessibleRole |
|
793 |
*/ |
|
794 |
public AccessibleRole getAccessibleRole() { |
|
795 |
return AccessibleRole.PANEL; |
|
796 |
} |
|
797 |
||
798 |
/** |
|
799 |
* Returns the Accessible child, if one exists, contained at the local |
|
800 |
* coordinate Point. |
|
801 |
* |
|
802 |
* @param p The point defining the top-left corner of the Accessible, |
|
803 |
* given in the coordinate space of the object's parent. |
|
804 |
* @return the Accessible, if it exists, at the specified location; |
|
805 |
* else null |
|
806 |
*/ |
|
807 |
public Accessible getAccessibleAt(Point p) { |
|
808 |
int column; |
|
809 |
||
810 |
// Locate the renderer under the Point |
|
811 |
if ((column = JTableHeader.this.columnAtPoint(p)) != -1) { |
|
812 |
TableColumn aColumn = JTableHeader.this.columnModel.getColumn(column); |
|
813 |
TableCellRenderer renderer = aColumn.getHeaderRenderer(); |
|
814 |
if (renderer == null) { |
|
815 |
if (defaultRenderer != null) { |
|
816 |
renderer = defaultRenderer; |
|
817 |
} else { |
|
818 |
return null; |
|
819 |
} |
|
820 |
} |
|
821 |
Component component = renderer.getTableCellRendererComponent( |
|
822 |
JTableHeader.this.getTable(), |
|
823 |
aColumn.getHeaderValue(), false, false, |
|
824 |
-1, column); |
|
825 |
||
826 |
return new AccessibleJTableHeaderEntry(column, JTableHeader.this, JTableHeader.this.table); |
|
827 |
} else { |
|
828 |
return null; |
|
829 |
} |
|
830 |
} |
|
831 |
||
832 |
/** |
|
833 |
* Returns the number of accessible children in the object. If all |
|
834 |
* of the children of this object implement Accessible, than this |
|
835 |
* method should return the number of children of this object. |
|
836 |
* |
|
837 |
* @return the number of accessible children in the object. |
|
838 |
*/ |
|
839 |
public int getAccessibleChildrenCount() { |
|
840 |
return JTableHeader.this.columnModel.getColumnCount(); |
|
841 |
} |
|
842 |
||
843 |
/** |
|
844 |
* Return the nth Accessible child of the object. |
|
845 |
* |
|
846 |
* @param i zero-based index of child |
|
847 |
* @return the nth Accessible child of the object |
|
848 |
*/ |
|
849 |
public Accessible getAccessibleChild(int i) { |
|
850 |
if (i < 0 || i >= getAccessibleChildrenCount()) { |
|
851 |
return null; |
|
852 |
} else { |
|
853 |
TableColumn aColumn = JTableHeader.this.columnModel.getColumn(i) |
|
854 |
; |
|
855 |
TableCellRenderer renderer = aColumn.getHeaderRenderer(); |
|
856 |
if (renderer == null) { |
|
857 |
if (defaultRenderer != null) { |
|
858 |
renderer = defaultRenderer; |
|
859 |
} else { |
|
860 |
return null; |
|
861 |
} |
|
862 |
} |
|
863 |
Component component = renderer.getTableCellRendererComponent( |
|
864 |
JTableHeader.this.getTable(), |
|
865 |
aColumn.getHeaderValue(), false, false, |
|
866 |
-1, i); |
|
867 |
||
868 |
return new AccessibleJTableHeaderEntry(i, JTableHeader.this, JTableHeader.this.table); |
|
869 |
} |
|
870 |
} |
|
871 |
||
872 |
/** |
|
873 |
* This class provides an implementation of the Java Accessibility |
|
21278 | 874 |
* API appropriate for JTableHeader entries. |
2 | 875 |
*/ |
876 |
protected class AccessibleJTableHeaderEntry extends AccessibleContext |
|
877 |
implements Accessible, AccessibleComponent { |
|
878 |
||
879 |
private JTableHeader parent; |
|
880 |
private int column; |
|
881 |
private JTable table; |
|
882 |
||
883 |
/** |
|
884 |
* Constructs an AccessiblJTableHeaaderEntry |
|
885 |
* @since 1.4 |
|
886 |
*/ |
|
887 |
public AccessibleJTableHeaderEntry(int c, JTableHeader p, JTable t) { |
|
888 |
parent = p; |
|
889 |
column = c; |
|
890 |
table = t; |
|
891 |
this.setAccessibleParent(parent); |
|
892 |
} |
|
893 |
||
894 |
/** |
|
895 |
* Get the AccessibleContext associated with this object. |
|
896 |
* In the implementation of the Java Accessibility API |
|
897 |
* for this class, returns this object, which serves as |
|
898 |
* its own AccessibleContext. |
|
899 |
* |
|
900 |
* @return this object |
|
901 |
*/ |
|
902 |
public AccessibleContext getAccessibleContext() { |
|
903 |
return this; |
|
904 |
} |
|
905 |
||
906 |
private AccessibleContext getCurrentAccessibleContext() { |
|
907 |
TableColumnModel tcm = table.getColumnModel(); |
|
908 |
if (tcm != null) { |
|
909 |
// Fixes 4772355 - ArrayOutOfBoundsException in |
|
910 |
// JTableHeader |
|
911 |
if (column < 0 || column >= tcm.getColumnCount()) { |
|
912 |
return null; |
|
913 |
} |
|
914 |
TableColumn aColumn = tcm.getColumn(column); |
|
915 |
TableCellRenderer renderer = aColumn.getHeaderRenderer(); |
|
916 |
if (renderer == null) { |
|
917 |
if (defaultRenderer != null) { |
|
918 |
renderer = defaultRenderer; |
|
919 |
} else { |
|
920 |
return null; |
|
921 |
} |
|
922 |
} |
|
923 |
Component c = renderer.getTableCellRendererComponent( |
|
924 |
JTableHeader.this.getTable(), |
|
925 |
aColumn.getHeaderValue(), false, false, |
|
926 |
-1, column); |
|
927 |
if (c instanceof Accessible) { |
|
928 |
return ((Accessible) c).getAccessibleContext(); |
|
929 |
} |
|
930 |
} |
|
931 |
return null; |
|
932 |
} |
|
933 |
||
934 |
private Component getCurrentComponent() { |
|
935 |
TableColumnModel tcm = table.getColumnModel(); |
|
936 |
if (tcm != null) { |
|
937 |
// Fixes 4772355 - ArrayOutOfBoundsException in |
|
938 |
// JTableHeader |
|
939 |
if (column < 0 || column >= tcm.getColumnCount()) { |
|
940 |
return null; |
|
941 |
} |
|
942 |
TableColumn aColumn = tcm.getColumn(column); |
|
943 |
TableCellRenderer renderer = aColumn.getHeaderRenderer(); |
|
944 |
if (renderer == null) { |
|
945 |
if (defaultRenderer != null) { |
|
946 |
renderer = defaultRenderer; |
|
947 |
} else { |
|
948 |
return null; |
|
949 |
} |
|
950 |
} |
|
951 |
return renderer.getTableCellRendererComponent( |
|
952 |
JTableHeader.this.getTable(), |
|
953 |
aColumn.getHeaderValue(), false, false, |
|
954 |
-1, column); |
|
955 |
} else { |
|
956 |
return null; |
|
957 |
} |
|
958 |
} |
|
959 |
||
960 |
// AccessibleContext methods |
|
961 |
||
962 |
public String getAccessibleName() { |
|
963 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
964 |
if (ac != null) { |
|
965 |
String name = ac.getAccessibleName(); |
|
966 |
if ((name != null) && (name != "")) { |
|
967 |
// return the cell renderer's AccessibleName |
|
968 |
return name; |
|
969 |
} |
|
970 |
} |
|
971 |
if ((accessibleName != null) && (accessibleName != "")) { |
|
972 |
return accessibleName; |
|
973 |
} else { |
|
974 |
// fall back to the client property |
|
975 |
String name = (String)getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY); |
|
976 |
if (name != null) { |
|
977 |
return name; |
|
978 |
} else { |
|
979 |
return table.getColumnName(column); |
|
980 |
} |
|
981 |
} |
|
982 |
} |
|
983 |
||
984 |
public void setAccessibleName(String s) { |
|
985 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
986 |
if (ac != null) { |
|
987 |
ac.setAccessibleName(s); |
|
988 |
} else { |
|
989 |
super.setAccessibleName(s); |
|
990 |
} |
|
991 |
} |
|
992 |
||
993 |
// |
|
994 |
// *** should check toolTip text for desc. (needs MouseEvent) |
|
995 |
// |
|
996 |
public String getAccessibleDescription() { |
|
997 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
998 |
if (ac != null) { |
|
999 |
return ac.getAccessibleDescription(); |
|
1000 |
} else { |
|
1001 |
return super.getAccessibleDescription(); |
|
1002 |
} |
|
1003 |
} |
|
1004 |
||
1005 |
public void setAccessibleDescription(String s) { |
|
1006 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1007 |
if (ac != null) { |
|
1008 |
ac.setAccessibleDescription(s); |
|
1009 |
} else { |
|
1010 |
super.setAccessibleDescription(s); |
|
1011 |
} |
|
1012 |
} |
|
1013 |
||
1014 |
public AccessibleRole getAccessibleRole() { |
|
1015 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1016 |
if (ac != null) { |
|
1017 |
return ac.getAccessibleRole(); |
|
1018 |
} else { |
|
1019 |
return AccessibleRole.COLUMN_HEADER; |
|
1020 |
} |
|
1021 |
} |
|
1022 |
||
1023 |
public AccessibleStateSet getAccessibleStateSet() { |
|
1024 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1025 |
if (ac != null) { |
|
1026 |
AccessibleStateSet states = ac.getAccessibleStateSet(); |
|
1027 |
if (isShowing()) { |
|
1028 |
states.add(AccessibleState.SHOWING); |
|
1029 |
} |
|
1030 |
return states; |
|
1031 |
} else { |
|
1032 |
return new AccessibleStateSet(); // must be non null? |
|
1033 |
} |
|
1034 |
} |
|
1035 |
||
1036 |
public int getAccessibleIndexInParent() { |
|
1037 |
return column; |
|
1038 |
} |
|
1039 |
||
1040 |
public int getAccessibleChildrenCount() { |
|
1041 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1042 |
if (ac != null) { |
|
1043 |
return ac.getAccessibleChildrenCount(); |
|
1044 |
} else { |
|
1045 |
return 0; |
|
1046 |
} |
|
1047 |
} |
|
1048 |
||
1049 |
public Accessible getAccessibleChild(int i) { |
|
1050 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1051 |
if (ac != null) { |
|
1052 |
Accessible accessibleChild = ac.getAccessibleChild(i); |
|
1053 |
ac.setAccessibleParent(this); |
|
1054 |
return accessibleChild; |
|
1055 |
} else { |
|
1056 |
return null; |
|
1057 |
} |
|
1058 |
} |
|
1059 |
||
1060 |
public Locale getLocale() { |
|
1061 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1062 |
if (ac != null) { |
|
1063 |
return ac.getLocale(); |
|
1064 |
} else { |
|
1065 |
return null; |
|
1066 |
} |
|
1067 |
} |
|
1068 |
||
1069 |
public void addPropertyChangeListener(PropertyChangeListener l) { |
|
1070 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1071 |
if (ac != null) { |
|
1072 |
ac.addPropertyChangeListener(l); |
|
1073 |
} else { |
|
1074 |
super.addPropertyChangeListener(l); |
|
1075 |
} |
|
1076 |
} |
|
1077 |
||
1078 |
public void removePropertyChangeListener(PropertyChangeListener l) { |
|
1079 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1080 |
if (ac != null) { |
|
1081 |
ac.removePropertyChangeListener(l); |
|
1082 |
} else { |
|
1083 |
super.removePropertyChangeListener(l); |
|
1084 |
} |
|
1085 |
} |
|
1086 |
||
1087 |
public AccessibleAction getAccessibleAction() { |
|
1088 |
return getCurrentAccessibleContext().getAccessibleAction(); |
|
1089 |
} |
|
1090 |
||
1091 |
/** |
|
1092 |
* Get the AccessibleComponent associated with this object. In the |
|
1093 |
* implementation of the Java Accessibility API for this class, |
|
1094 |
* return this object, which is responsible for implementing the |
|
1095 |
* AccessibleComponent interface on behalf of itself. |
|
1096 |
* |
|
1097 |
* @return this object |
|
1098 |
*/ |
|
1099 |
public AccessibleComponent getAccessibleComponent() { |
|
1100 |
return this; // to override getBounds() |
|
1101 |
} |
|
1102 |
||
1103 |
public AccessibleSelection getAccessibleSelection() { |
|
1104 |
return getCurrentAccessibleContext().getAccessibleSelection(); |
|
1105 |
} |
|
1106 |
||
1107 |
public AccessibleText getAccessibleText() { |
|
1108 |
return getCurrentAccessibleContext().getAccessibleText(); |
|
1109 |
} |
|
1110 |
||
1111 |
public AccessibleValue getAccessibleValue() { |
|
1112 |
return getCurrentAccessibleContext().getAccessibleValue(); |
|
1113 |
} |
|
1114 |
||
1115 |
||
1116 |
// AccessibleComponent methods |
|
1117 |
||
1118 |
public Color getBackground() { |
|
1119 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1120 |
if (ac instanceof AccessibleComponent) { |
|
1121 |
return ((AccessibleComponent) ac).getBackground(); |
|
1122 |
} else { |
|
1123 |
Component c = getCurrentComponent(); |
|
1124 |
if (c != null) { |
|
1125 |
return c.getBackground(); |
|
1126 |
} else { |
|
1127 |
return null; |
|
1128 |
} |
|
1129 |
} |
|
1130 |
} |
|
1131 |
||
1132 |
public void setBackground(Color c) { |
|
1133 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1134 |
if (ac instanceof AccessibleComponent) { |
|
1135 |
((AccessibleComponent) ac).setBackground(c); |
|
1136 |
} else { |
|
1137 |
Component cp = getCurrentComponent(); |
|
1138 |
if (cp != null) { |
|
1139 |
cp.setBackground(c); |
|
1140 |
} |
|
1141 |
} |
|
1142 |
} |
|
1143 |
||
1144 |
public Color getForeground() { |
|
1145 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1146 |
if (ac instanceof AccessibleComponent) { |
|
1147 |
return ((AccessibleComponent) ac).getForeground(); |
|
1148 |
} else { |
|
1149 |
Component c = getCurrentComponent(); |
|
1150 |
if (c != null) { |
|
1151 |
return c.getForeground(); |
|
1152 |
} else { |
|
1153 |
return null; |
|
1154 |
} |
|
1155 |
} |
|
1156 |
} |
|
1157 |
||
1158 |
public void setForeground(Color c) { |
|
1159 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1160 |
if (ac instanceof AccessibleComponent) { |
|
1161 |
((AccessibleComponent) ac).setForeground(c); |
|
1162 |
} else { |
|
1163 |
Component cp = getCurrentComponent(); |
|
1164 |
if (cp != null) { |
|
1165 |
cp.setForeground(c); |
|
1166 |
} |
|
1167 |
} |
|
1168 |
} |
|
1169 |
||
1170 |
public Cursor getCursor() { |
|
1171 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1172 |
if (ac instanceof AccessibleComponent) { |
|
1173 |
return ((AccessibleComponent) ac).getCursor(); |
|
1174 |
} else { |
|
1175 |
Component c = getCurrentComponent(); |
|
1176 |
if (c != null) { |
|
1177 |
return c.getCursor(); |
|
1178 |
} else { |
|
1179 |
Accessible ap = getAccessibleParent(); |
|
1180 |
if (ap instanceof AccessibleComponent) { |
|
1181 |
return ((AccessibleComponent) ap).getCursor(); |
|
1182 |
} else { |
|
1183 |
return null; |
|
1184 |
} |
|
1185 |
} |
|
1186 |
} |
|
1187 |
} |
|
1188 |
||
1189 |
public void setCursor(Cursor c) { |
|
1190 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1191 |
if (ac instanceof AccessibleComponent) { |
|
1192 |
((AccessibleComponent) ac).setCursor(c); |
|
1193 |
} else { |
|
1194 |
Component cp = getCurrentComponent(); |
|
1195 |
if (cp != null) { |
|
1196 |
cp.setCursor(c); |
|
1197 |
} |
|
1198 |
} |
|
1199 |
} |
|
1200 |
||
1201 |
public Font getFont() { |
|
1202 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1203 |
if (ac instanceof AccessibleComponent) { |
|
1204 |
return ((AccessibleComponent) ac).getFont(); |
|
1205 |
} else { |
|
1206 |
Component c = getCurrentComponent(); |
|
1207 |
if (c != null) { |
|
1208 |
return c.getFont(); |
|
1209 |
} else { |
|
1210 |
return null; |
|
1211 |
} |
|
1212 |
} |
|
1213 |
} |
|
1214 |
||
1215 |
public void setFont(Font f) { |
|
1216 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1217 |
if (ac instanceof AccessibleComponent) { |
|
1218 |
((AccessibleComponent) ac).setFont(f); |
|
1219 |
} else { |
|
1220 |
Component c = getCurrentComponent(); |
|
1221 |
if (c != null) { |
|
1222 |
c.setFont(f); |
|
1223 |
} |
|
1224 |
} |
|
1225 |
} |
|
1226 |
||
1227 |
public FontMetrics getFontMetrics(Font f) { |
|
1228 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1229 |
if (ac instanceof AccessibleComponent) { |
|
1230 |
return ((AccessibleComponent) ac).getFontMetrics(f); |
|
1231 |
} else { |
|
1232 |
Component c = getCurrentComponent(); |
|
1233 |
if (c != null) { |
|
1234 |
return c.getFontMetrics(f); |
|
1235 |
} else { |
|
1236 |
return null; |
|
1237 |
} |
|
1238 |
} |
|
1239 |
} |
|
1240 |
||
1241 |
public boolean isEnabled() { |
|
1242 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1243 |
if (ac instanceof AccessibleComponent) { |
|
1244 |
return ((AccessibleComponent) ac).isEnabled(); |
|
1245 |
} else { |
|
1246 |
Component c = getCurrentComponent(); |
|
1247 |
if (c != null) { |
|
1248 |
return c.isEnabled(); |
|
1249 |
} else { |
|
1250 |
return false; |
|
1251 |
} |
|
1252 |
} |
|
1253 |
} |
|
1254 |
||
1255 |
public void setEnabled(boolean b) { |
|
1256 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1257 |
if (ac instanceof AccessibleComponent) { |
|
1258 |
((AccessibleComponent) ac).setEnabled(b); |
|
1259 |
} else { |
|
1260 |
Component c = getCurrentComponent(); |
|
1261 |
if (c != null) { |
|
1262 |
c.setEnabled(b); |
|
1263 |
} |
|
1264 |
} |
|
1265 |
} |
|
1266 |
||
1267 |
public boolean isVisible() { |
|
1268 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1269 |
if (ac instanceof AccessibleComponent) { |
|
1270 |
return ((AccessibleComponent) ac).isVisible(); |
|
1271 |
} else { |
|
1272 |
Component c = getCurrentComponent(); |
|
1273 |
if (c != null) { |
|
1274 |
return c.isVisible(); |
|
1275 |
} else { |
|
1276 |
return false; |
|
1277 |
} |
|
1278 |
} |
|
1279 |
} |
|
1280 |
||
1281 |
public void setVisible(boolean b) { |
|
1282 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1283 |
if (ac instanceof AccessibleComponent) { |
|
1284 |
((AccessibleComponent) ac).setVisible(b); |
|
1285 |
} else { |
|
1286 |
Component c = getCurrentComponent(); |
|
1287 |
if (c != null) { |
|
1288 |
c.setVisible(b); |
|
1289 |
} |
|
1290 |
} |
|
1291 |
} |
|
1292 |
||
1293 |
public boolean isShowing() { |
|
1294 |
if (isVisible() && JTableHeader.this.isShowing()) { |
|
1295 |
return true; |
|
1296 |
} else { |
|
1297 |
return false; |
|
1298 |
} |
|
1299 |
} |
|
1300 |
||
1301 |
public boolean contains(Point p) { |
|
1302 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1303 |
if (ac instanceof AccessibleComponent) { |
|
1304 |
Rectangle r = ((AccessibleComponent) ac).getBounds(); |
|
1305 |
return r.contains(p); |
|
1306 |
} else { |
|
1307 |
Component c = getCurrentComponent(); |
|
1308 |
if (c != null) { |
|
1309 |
Rectangle r = c.getBounds(); |
|
1310 |
return r.contains(p); |
|
1311 |
} else { |
|
1312 |
return getBounds().contains(p); |
|
1313 |
} |
|
1314 |
} |
|
1315 |
} |
|
1316 |
||
1317 |
public Point getLocationOnScreen() { |
|
1318 |
if (parent != null) { |
|
1319 |
Point parentLocation = parent.getLocationOnScreen(); |
|
1320 |
Point componentLocation = getLocation(); |
|
1321 |
componentLocation.translate(parentLocation.x, parentLocation.y); |
|
1322 |
return componentLocation; |
|
1323 |
} else { |
|
1324 |
return null; |
|
1325 |
} |
|
1326 |
} |
|
1327 |
||
1328 |
public Point getLocation() { |
|
1329 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1330 |
if (ac instanceof AccessibleComponent) { |
|
1331 |
Rectangle r = ((AccessibleComponent) ac).getBounds(); |
|
1332 |
return r.getLocation(); |
|
1333 |
} else { |
|
1334 |
Component c = getCurrentComponent(); |
|
1335 |
if (c != null) { |
|
1336 |
Rectangle r = c.getBounds(); |
|
1337 |
return r.getLocation(); |
|
1338 |
} else { |
|
1339 |
return getBounds().getLocation(); |
|
1340 |
} |
|
1341 |
} |
|
1342 |
} |
|
1343 |
||
1344 |
public void setLocation(Point p) { |
|
1345 |
// if ((parent != null) && (parent.contains(p))) { |
|
1346 |
// ensureIndexIsVisible(indexInParent); |
|
1347 |
// } |
|
1348 |
} |
|
1349 |
||
1350 |
public Rectangle getBounds() { |
|
1351 |
Rectangle r = table.getCellRect(-1, column, false); |
|
1352 |
r.y = 0; |
|
1353 |
return r; |
|
1354 |
||
1355 |
// AccessibleContext ac = getCurrentAccessibleContext(); |
|
1356 |
// if (ac instanceof AccessibleComponent) { |
|
1357 |
// return ((AccessibleComponent) ac).getBounds(); |
|
1358 |
// } else { |
|
1359 |
// Component c = getCurrentComponent(); |
|
1360 |
// if (c != null) { |
|
1361 |
// return c.getBounds(); |
|
1362 |
// } else { |
|
1363 |
// Rectangle r = table.getCellRect(-1, column, false); |
|
1364 |
// r.y = 0; |
|
1365 |
// return r; |
|
1366 |
// } |
|
1367 |
// } |
|
1368 |
} |
|
1369 |
||
1370 |
public void setBounds(Rectangle r) { |
|
1371 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1372 |
if (ac instanceof AccessibleComponent) { |
|
1373 |
((AccessibleComponent) ac).setBounds(r); |
|
1374 |
} else { |
|
1375 |
Component c = getCurrentComponent(); |
|
1376 |
if (c != null) { |
|
1377 |
c.setBounds(r); |
|
1378 |
} |
|
1379 |
} |
|
1380 |
} |
|
1381 |
||
1382 |
public Dimension getSize() { |
|
1383 |
return getBounds().getSize(); |
|
1384 |
// AccessibleContext ac = getCurrentAccessibleContext(); |
|
1385 |
// if (ac instanceof AccessibleComponent) { |
|
1386 |
// Rectangle r = ((AccessibleComponent) ac).getBounds(); |
|
1387 |
// return r.getSize(); |
|
1388 |
// } else { |
|
1389 |
// Component c = getCurrentComponent(); |
|
1390 |
// if (c != null) { |
|
1391 |
// Rectangle r = c.getBounds(); |
|
1392 |
// return r.getSize(); |
|
1393 |
// } else { |
|
1394 |
// return getBounds().getSize(); |
|
1395 |
// } |
|
1396 |
// } |
|
1397 |
} |
|
1398 |
||
1399 |
public void setSize (Dimension d) { |
|
1400 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1401 |
if (ac instanceof AccessibleComponent) { |
|
1402 |
((AccessibleComponent) ac).setSize(d); |
|
1403 |
} else { |
|
1404 |
Component c = getCurrentComponent(); |
|
1405 |
if (c != null) { |
|
1406 |
c.setSize(d); |
|
1407 |
} |
|
1408 |
} |
|
1409 |
} |
|
1410 |
||
1411 |
public Accessible getAccessibleAt(Point p) { |
|
1412 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1413 |
if (ac instanceof AccessibleComponent) { |
|
1414 |
return ((AccessibleComponent) ac).getAccessibleAt(p); |
|
1415 |
} else { |
|
1416 |
return null; |
|
1417 |
} |
|
1418 |
} |
|
1419 |
||
1420 |
public boolean isFocusTraversable() { |
|
1421 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1422 |
if (ac instanceof AccessibleComponent) { |
|
1423 |
return ((AccessibleComponent) ac).isFocusTraversable(); |
|
1424 |
} else { |
|
1425 |
Component c = getCurrentComponent(); |
|
1426 |
if (c != null) { |
|
1427 |
return c.isFocusTraversable(); |
|
1428 |
} else { |
|
1429 |
return false; |
|
1430 |
} |
|
1431 |
} |
|
1432 |
} |
|
1433 |
||
1434 |
public void requestFocus() { |
|
1435 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1436 |
if (ac instanceof AccessibleComponent) { |
|
1437 |
((AccessibleComponent) ac).requestFocus(); |
|
1438 |
} else { |
|
1439 |
Component c = getCurrentComponent(); |
|
1440 |
if (c != null) { |
|
1441 |
c.requestFocus(); |
|
1442 |
} |
|
1443 |
} |
|
1444 |
} |
|
1445 |
||
1446 |
public void addFocusListener(FocusListener l) { |
|
1447 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1448 |
if (ac instanceof AccessibleComponent) { |
|
1449 |
((AccessibleComponent) ac).addFocusListener(l); |
|
1450 |
} else { |
|
1451 |
Component c = getCurrentComponent(); |
|
1452 |
if (c != null) { |
|
1453 |
c.addFocusListener(l); |
|
1454 |
} |
|
1455 |
} |
|
1456 |
} |
|
1457 |
||
1458 |
public void removeFocusListener(FocusListener l) { |
|
1459 |
AccessibleContext ac = getCurrentAccessibleContext(); |
|
1460 |
if (ac instanceof AccessibleComponent) { |
|
1461 |
((AccessibleComponent) ac).removeFocusListener(l); |
|
1462 |
} else { |
|
1463 |
Component c = getCurrentComponent(); |
|
1464 |
if (c != null) { |
|
1465 |
c.removeFocusListener(l); |
|
1466 |
} |
|
1467 |
} |
|
1468 |
} |
|
1469 |
||
1470 |
} // inner class AccessibleJTableHeaderElement |
|
1471 |
||
1472 |
} // inner class AccessibleJTableHeader |
|
1473 |
||
1474 |
} // End of Class JTableHeader |