1:
37:
38:
39: package ;
40:
41: import ;
42:
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53:
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60: import ;
61: import ;
62: import ;
63: import ;
64: import ;
65: import ;
66: import ;
67: import ;
68: import ;
69: import ;
70: import ;
71:
72:
77: public class JTableHeader extends JComponent
78: implements TableColumnModelListener, Accessible
79: {
80: protected class AccessibleJTableHeader extends AccessibleJComponent
81: {
82: protected class AccessibleJTableHeaderEntry extends AccessibleContext
83: implements Accessible, AccessibleComponent
84: {
85: public AccessibleJTableHeaderEntry(int c, JTableHeader p, JTable t)
86: throws NotImplementedException
87: {
88: throw new Error("not implemented");
89: }
90:
91: public void addFocusListener(FocusListener l)
92: throws NotImplementedException
93: {
94: throw new Error("not implemented");
95: }
96:
97: public void addPropertyChangeListener(PropertyChangeListener l)
98: throws NotImplementedException
99: {
100: throw new Error("not implemented");
101: }
102:
103: public boolean contains(Point p)
104: throws NotImplementedException
105: {
106: throw new Error("not implemented");
107: }
108:
109: public AccessibleAction getAccessibleAction()
110: throws NotImplementedException
111: {
112: throw new Error("not implemented");
113: }
114:
115: public Accessible getAccessibleAt(Point p)
116: throws NotImplementedException
117: {
118: throw new Error("not implemented");
119: }
120:
121: public Accessible getAccessibleChild(int i)
122: throws NotImplementedException
123: {
124: throw new Error("not implemented");
125: }
126:
127: public int getAccessibleChildrenCount()
128: throws NotImplementedException
129: {
130: throw new Error("not implemented");
131: }
132:
133: public AccessibleComponent getAccessibleComponent()
134: throws NotImplementedException
135: {
136: throw new Error("not implemented");
137: }
138:
139: public AccessibleContext getAccessibleContext()
140: throws NotImplementedException
141: {
142: throw new Error("not implemented");
143: }
144:
145: public String getAccessibleDescription()
146: throws NotImplementedException
147: {
148: throw new Error("not implemented");
149: }
150:
151: public int getAccessibleIndexInParent()
152: throws NotImplementedException
153: {
154: throw new Error("not implemented");
155: }
156:
157: public String getAccessibleName()
158: throws NotImplementedException
159: {
160: throw new Error("not implemented");
161: }
162:
163: public AccessibleRole getAccessibleRole()
164: throws NotImplementedException
165: {
166: throw new Error("not implemented");
167: }
168:
169: public AccessibleSelection getAccessibleSelection()
170: throws NotImplementedException
171: {
172: throw new Error("not implemented");
173: }
174:
175: public AccessibleStateSet getAccessibleStateSet()
176: throws NotImplementedException
177: {
178: throw new Error("not implemented");
179: }
180:
181: public AccessibleText getAccessibleText()
182: throws NotImplementedException
183: {
184: throw new Error("not implemented");
185: }
186:
187: public AccessibleValue getAccessibleValue()
188: throws NotImplementedException
189: {
190: throw new Error("not implemented");
191: }
192:
193: public Color getBackground()
194: throws NotImplementedException
195: {
196: throw new Error("not implemented");
197: }
198:
199: public Rectangle getBounds()
200: throws NotImplementedException
201: {
202: throw new Error("not implemented");
203: }
204:
205: public Cursor getCursor()
206: throws NotImplementedException
207: {
208: throw new Error("not implemented");
209: }
210:
211: public Font getFont()
212: throws NotImplementedException
213: {
214: throw new Error("not implemented");
215: }
216:
217: public FontMetrics getFontMetrics(Font f)
218: throws NotImplementedException
219: {
220: throw new Error("not implemented");
221: }
222:
223: public Color getForeground()
224: throws NotImplementedException
225: {
226: throw new Error("not implemented");
227: }
228:
229: public Locale getLocale()
230: throws NotImplementedException
231: {
232: throw new Error("not implemented");
233: }
234:
235: public Point getLocation()
236: throws NotImplementedException
237: {
238: throw new Error("not implemented");
239: }
240:
241: public Point getLocationOnScreen()
242: throws NotImplementedException
243: {
244: throw new Error("not implemented");
245: }
246:
247: public Dimension getSize()
248: throws NotImplementedException
249: {
250: throw new Error("not implemented");
251: }
252:
253: public boolean isEnabled()
254: throws NotImplementedException
255: {
256: throw new Error("not implemented");
257: }
258:
259: public boolean isFocusTraversable()
260: throws NotImplementedException
261: {
262: throw new Error("not implemented");
263: }
264:
265: public boolean isShowing()
266: throws NotImplementedException
267: {
268: throw new Error("not implemented");
269: }
270:
271: public boolean isVisible()
272: throws NotImplementedException
273: {
274: throw new Error("not implemented");
275: }
276:
277: public void removeFocusListener(FocusListener l)
278: throws NotImplementedException
279: {
280: throw new Error("not implemented");
281: }
282:
283: public void removePropertyChangeListener(PropertyChangeListener l)
284: throws NotImplementedException
285: {
286: throw new Error("not implemented");
287: }
288:
289: public void requestFocus()
290: throws NotImplementedException
291: {
292: throw new Error("not implemented");
293: }
294:
295: public void setAccessibleDescription(String s)
296: throws NotImplementedException
297: {
298: throw new Error("not implemented");
299: }
300:
301: public void setAccessibleName(String s)
302: throws NotImplementedException
303: {
304: throw new Error("not implemented");
305: }
306:
307: public void setBackground(Color c)
308: throws NotImplementedException
309: {
310: throw new Error("not implemented");
311: }
312:
313: public void setBounds(Rectangle r)
314: throws NotImplementedException
315: {
316: throw new Error("not implemented");
317: }
318:
319: public void setCursor(Cursor c)
320: throws NotImplementedException
321: {
322: throw new Error("not implemented");
323: }
324:
325: public void setEnabled(boolean b)
326: throws NotImplementedException
327: {
328: throw new Error("not implemented");
329: }
330:
331: public void setFont(Font f)
332: throws NotImplementedException
333: {
334: throw new Error("not implemented");
335: }
336:
337: public void setForeground(Color c)
338: throws NotImplementedException
339: {
340: throw new Error("not implemented");
341: }
342:
343: public void setLocation(Point p)
344: throws NotImplementedException
345: {
346: throw new Error("not implemented");
347: }
348:
349: public void setSize(Dimension d)
350: throws NotImplementedException
351: {
352: throw new Error("not implemented");
353: }
354:
355: public void setVisible(boolean b)
356: throws NotImplementedException
357: {
358: throw new Error("not implemented");
359: }
360: };
361: }
362:
363:
366: private static final long serialVersionUID = 5144633983372967710L;
367:
368:
371: protected TableColumnModel columnModel;
372:
373:
376: protected TableColumn draggedColumn;
377:
378:
381: protected int draggedDistance;
382:
383:
386: boolean opaque;
387:
388:
391: protected boolean reorderingAllowed;
392:
393:
396: protected boolean resizingAllowed = true;
397:
398:
401: protected TableColumn resizingColumn;
402:
403:
406: protected JTable table;
407:
408:
411: protected boolean updateTableInRealTime;
412:
413: TableCellRenderer cellRenderer;
414:
415:
418: public JTableHeader()
419: {
420: this(null);
421: }
422:
423:
430: public JTableHeader(TableColumnModel cm)
431: {
432: columnModel = cm == null ? createDefaultColumnModel() : cm;
433: initializeLocalVars();
434: updateUI();
435: }
436:
437:
442: protected TableColumnModel createDefaultColumnModel()
443: {
444: return new DefaultTableColumnModel();
445: }
446:
447:
452: public AccessibleContext getAccessibleContext()
453: {
454: return accessibleContext;
455: }
456:
457:
462: public TableColumnModel getColumnModel()
463: {
464: return columnModel;
465: }
466:
467:
473: public TableColumn getDraggedColumn()
474: {
475: return draggedColumn;
476: }
477:
478:
483: public int getDraggedDistance()
484: {
485: return draggedDistance;
486: }
487:
488:
495: public boolean getReorderingAllowed()
496: {
497: return reorderingAllowed;
498: }
499:
500:
507: public boolean getResizingAllowed()
508: {
509: return resizingAllowed;
510: }
511:
512:
518: public TableColumn getResizingColumn()
519: {
520: return resizingColumn;
521: }
522:
523:
528: public JTable getTable()
529: {
530: return table;
531: }
532:
533:
538: public boolean getUpdateTableInRealTime()
539: {
540: return updateTableInRealTime;
541: }
542:
543:
548: public boolean isOpaque()
549: {
550: return opaque;
551: }
552:
553:
558: public void setColumnModel(TableColumnModel c)
559: {
560: columnModel.removeColumnModelListener(this);
561: columnModel = c;
562: columnModel.addColumnModelListener(this);
563: }
564:
565:
572: public void setDraggedColumn(TableColumn draggingIt)
573: {
574: draggedColumn = draggingIt;
575: }
576:
577:
582: public void setDraggedDistance(int d)
583: {
584: draggedDistance = d;
585: }
586:
587:
592: public void setOpaque(boolean o)
593: {
594: opaque = o;
595: }
596:
597:
604: public void setReorderingAllowed(boolean allowed)
605: {
606: reorderingAllowed = allowed;
607: }
608:
609:
616: public void setResizingAllowed(boolean allowed)
617: {
618: resizingAllowed = allowed;
619: }
620:
621:
628: public void setResizingColumn(TableColumn resizingIt)
629: {
630: resizingColumn = resizingIt;
631: }
632:
633:
638: public void setTable(JTable t)
639: {
640: table = t;
641: }
642:
643:
648: public void setUpdateTableInRealTime(boolean u)
649: {
650: updateTableInRealTime = u;
651: }
652:
653:
658: protected TableCellRenderer createDefaultRenderer()
659: {
660: return new DefaultTableCellRenderer();
661: }
662:
663:
668: public TableCellRenderer getDefaultRenderer()
669: {
670: return cellRenderer;
671: }
672:
673:
678: public void setDefaultRenderer(TableCellRenderer cellRenderer)
679: {
680: this.cellRenderer = cellRenderer;
681: }
682:
683:
690: public Rectangle getHeaderRect(int column)
691: {
692: Rectangle r = getTable().getCellRect(-1, column, false);
693: r.height = getHeight();
694: return r;
695: }
696:
697: protected String paramString()
698: {
699: return "JTableHeader";
700: }
701:
702:
703:
704: public String getUIClassID()
705: {
706: return "TableHeaderUI";
707: }
708:
709: public TableHeaderUI getUI()
710: {
711: return (TableHeaderUI) ui;
712: }
713:
714: public void setUI(TableHeaderUI u)
715: {
716: super.setUI(u);
717: }
718:
719: public void updateUI()
720: {
721: setUI((TableHeaderUI) UIManager.getUI(this));
722: }
723:
724:
731: public int columnAtPoint(Point point)
732: {
733: if (getBounds().contains(point))
734: return columnModel.getColumnIndexAtX(point.x);
735:
736: return -1;
737: }
738:
739:
744: public void columnAdded(TableColumnModelEvent event)
745: {
746:
747: resizeAndRepaint();
748: }
749:
750:
755: public void columnMarginChanged(ChangeEvent event)
756: {
757:
758: resizeAndRepaint();
759: }
760:
761:
766: public void columnMoved(TableColumnModelEvent event)
767: {
768:
769: resizeAndRepaint();
770: }
771:
772:
777: public void columnRemoved(TableColumnModelEvent event)
778: {
779:
780: resizeAndRepaint();
781: }
782:
783:
788: public void columnSelectionChanged(ListSelectionEvent event)
789: {
790:
791: resizeAndRepaint();
792: }
793:
794:
799: public void resizeAndRepaint()
800: {
801: revalidate();
802: repaint();
803: }
804:
805:
809: protected void initializeLocalVars()
810: {
811: accessibleContext = new AccessibleJTableHeader();
812: draggedColumn = null;
813: draggedDistance = 0;
814: opaque = true;
815: reorderingAllowed = true;
816: resizingAllowed = true;
817: resizingColumn = null;
818: table = null;
819: updateTableInRealTime = true;
820: cellRenderer = createDefaultRenderer();
821: }
822: }