OSDN Git Service

95ff92006cf057425bcd9c7f00726c4b3da7f05d
[pf3gnuchains/gcc-fork.git] / libjava / javax / swing / table / JTableHeader.java
1 /* JTableHeader.java --
2    Copyright (C) 2003, 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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 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.table;
40
41 import java.awt.Color;
42 import java.awt.Cursor;
43 import java.awt.Dimension;
44 import java.awt.Font;
45 import java.awt.FontMetrics;
46 import java.awt.Point;
47 import java.awt.Rectangle;
48 import java.awt.event.FocusListener;
49 import java.beans.PropertyChangeListener;
50 import java.util.Locale;
51
52 import javax.accessibility.Accessible;
53 import javax.accessibility.AccessibleAction;
54 import javax.accessibility.AccessibleComponent;
55 import javax.accessibility.AccessibleContext;
56 import javax.accessibility.AccessibleRole;
57 import javax.accessibility.AccessibleSelection;
58 import javax.accessibility.AccessibleStateSet;
59 import javax.accessibility.AccessibleText;
60 import javax.accessibility.AccessibleValue;
61 import javax.swing.JComponent;
62 import javax.swing.JTable;
63 import javax.swing.UIManager;
64 import javax.swing.plaf.TableHeaderUI;
65
66 public class JTableHeader extends JComponent
67 {
68   protected class AccessibleJTableHeader extends AccessibleJComponent
69   {
70     protected class AccessibleJTableHeaderEntry extends AccessibleContext
71       implements Accessible, AccessibleComponent
72     {
73       public void addFocusListener(FocusListener l)
74       {
75         throw new Error("not implemented");
76       }
77       
78       public void addPropertyChangeListener(PropertyChangeListener l)
79       {
80         throw new Error("not implemented");
81       }
82       
83       public boolean contains(Point p)
84       {
85         throw new Error("not implemented");
86       }
87       
88       public AccessibleAction getAccessibleAction()
89       {
90         throw new Error("not implemented");
91       }
92       
93       public Accessible getAccessibleAt(Point p)
94       {
95         throw new Error("not implemented");
96       }
97       
98       public Accessible getAccessibleChild(int i)
99       {
100         throw new Error("not implemented");
101       }
102       
103       public int getAccessibleChildrenCount()
104       {
105         throw new Error("not implemented");
106       }
107       
108       public AccessibleComponent getAccessibleComponent()
109       {
110         throw new Error("not implemented");
111       }
112       
113       public AccessibleContext getAccessibleContext()
114       {
115         throw new Error("not implemented");
116       }
117       
118       public String getAccessibleDescription()
119       {
120         throw new Error("not implemented");
121       }
122       
123       public int getAccessibleIndexInParent()
124       {
125         throw new Error("not implemented");
126       }
127       
128       public String getAccessibleName()
129       {
130         throw new Error("not implemented");
131       }
132       
133       public AccessibleRole getAccessibleRole()
134       {
135         throw new Error("not implemented");
136       }
137       
138       public AccessibleSelection getAccessibleSelection()
139       {
140         throw new Error("not implemented");
141       }
142       
143       public AccessibleStateSet getAccessibleStateSet()
144       {
145         throw new Error("not implemented");
146       }
147       
148       public AccessibleText getAccessibleText()
149       {
150         throw new Error("not implemented");
151       }
152       
153       public AccessibleValue getAccessibleValue()
154       {
155         throw new Error("not implemented");
156       }
157       
158       public Color getBackground()
159       {
160         throw new Error("not implemented");
161       }
162       
163       public Rectangle getBounds()
164       {
165         throw new Error("not implemented");
166       }
167       
168       public Cursor getCursor()
169       {
170         throw new Error("not implemented");
171       }
172       
173       public Font getFont()
174       {
175         throw new Error("not implemented");
176       }
177       
178       public FontMetrics getFontMetrics(Font f)
179       {
180         throw new Error("not implemented");
181       }
182       
183       public Color getForeground()
184       {
185         throw new Error("not implemented");
186       }
187       
188       public Locale getLocale()
189       {
190         throw new Error("not implemented");
191       }
192       
193       public Point getLocation()
194       {
195         throw new Error("not implemented");
196       }
197       
198       public Point getLocationOnScreen()
199       {
200         throw new Error("not implemented");
201       }
202       
203       public Dimension getSize()
204       {
205         throw new Error("not implemented");
206       }
207       
208       public boolean isEnabled()
209       {
210         throw new Error("not implemented");
211       }
212       
213       public boolean isFocusTraversable()
214       {
215         throw new Error("not implemented");
216       }
217       
218       public boolean isShowing()
219       {
220         throw new Error("not implemented");
221       }
222       
223       public boolean isVisible()
224       {
225         throw new Error("not implemented");
226       }
227       
228       public void removeFocusListener(FocusListener l)
229       {
230         throw new Error("not implemented");
231       }
232       
233       public void removePropertyChangeListener(PropertyChangeListener l)
234       {
235         throw new Error("not implemented");
236       }
237       
238       public void requestFocus()
239       {
240         throw new Error("not implemented");
241       }
242       
243       public void setAccessibleDescription(String s)
244       {
245         throw new Error("not implemented");
246       }
247       
248       public void setAccessibleName(String s)
249       {
250         throw new Error("not implemented");
251       }
252       
253       public void setBackground(Color c)
254       {
255         throw new Error("not implemented");
256       }
257       
258       public void setBounds(Rectangle r)
259       {
260         throw new Error("not implemented");
261       }
262       
263       public void setCursor(Cursor c)
264       {
265         throw new Error("not implemented");
266       }
267       
268       public void setEnabled(boolean b)
269       {
270         throw new Error("not implemented");
271       }
272       
273       public void setFont(Font f)
274       {
275         throw new Error("not implemented");
276       }
277       
278       public void setForeground(Color c)
279       {
280         throw new Error("not implemented");
281       }
282       
283       public void setLocation(Point p)
284       {
285         throw new Error("not implemented");
286       }
287       
288       public void setSize(Dimension d)
289       {
290         throw new Error("not implemented");
291       }
292       
293       public void setVisible(boolean b)
294       {
295         throw new Error("not implemented");
296       }
297     };
298   }
299
300   private static final long serialVersionUID = 5144633983372967710L;
301
302   /**
303    * The accessibleContext property.
304    */
305   AccessibleContext accessibleContext;
306
307   /**
308    * The columnModel property.
309    */
310   protected TableColumnModel columnModel;
311
312   /**
313    * The draggedColumn property.
314    */
315   protected TableColumn draggedColumn;
316
317   /**
318    * The draggedDistance property.
319    */
320   protected int draggedDistance;
321
322   /**
323    * The opaque property.
324    */
325   boolean opaque;
326
327   /**
328    * The reorderingAllowed property.
329    */
330   protected boolean reorderingAllowed;
331
332   /**
333    * The resizingAllowed property.
334    */
335   protected boolean resizingAllowed = true;
336
337   /**
338    * The resizingColumn property.
339    */
340   protected TableColumn resizingColumn;
341
342   /**
343    * The table property.
344    */
345   protected JTable table;
346
347   /**
348    * The updateTableInRealTime property.
349    */
350   protected boolean updateTableInRealTime;
351
352   TableCellRenderer cellRenderer; 
353
354   public JTableHeader()
355   {
356     this(null);
357   }
358
359   public JTableHeader(TableColumnModel cm)
360   {
361     accessibleContext = new AccessibleJTableHeader();
362     columnModel = cm == null ? createDefaultColumnModel() : cm; 
363     draggedColumn = null;
364     draggedDistance = 0;
365     opaque = true;
366     reorderingAllowed = true;
367     resizingAllowed = true;
368     resizingColumn = null;
369     table = null;
370     updateTableInRealTime = true;
371     cellRenderer = createDefaultRenderer();
372     updateUI();
373   }
374
375   protected TableColumnModel createDefaultColumnModel()
376   {
377     return new DefaultTableColumnModel();
378   }
379
380   /**
381    * Get the value of the {@link #accessibleContext} property.
382    *
383    * @return The current value of the property
384    */
385   public AccessibleContext getAccessibleContext()
386   {
387     return accessibleContext;
388   }
389
390   /**
391    * Get the value of the {@link #columnModel} property.
392    *
393    * @return The current value of the property
394    */
395   public TableColumnModel getColumnModel()
396   {
397     return columnModel;
398   }
399
400   /**
401    * Get the value of the {@link #draggedColumn} property.
402    *
403    * @return The current value of the property
404    */
405   public TableColumn getDraggedColumn()
406   {
407     return draggedColumn;
408   }
409
410   /**
411    * Get the value of the {@link #draggedDistance} property.
412    *
413    * @return The current value of the property
414    */
415   public int getDraggedDistance()
416   {
417     return draggedDistance;
418   }
419
420   /**
421    * Get the value of the {@link #reorderingAllowed} property.
422    *
423    * @return The current value of the property
424    */
425   public boolean getReorderingAllowed()
426   {
427     return reorderingAllowed;
428   }
429
430   /**
431    * Get the value of the {@link #resizingAllowed} property.
432    *
433    * @return The current value of the property
434    */
435   public boolean getResizingAllowed()
436   {
437     return resizingAllowed;
438   }
439
440   /**
441    * Get the value of the {@link #resizingColumn} property.
442    *
443    * @return The current value of the property
444    */
445   public TableColumn getResizingColumn()
446   {
447     return resizingColumn;
448   }
449
450   /**
451    * Get the value of the {@link #table} property.
452    *
453    * @return The current value of the property
454    */
455   public JTable getTable()
456   {
457     return table;
458   }
459
460   /**
461    * Get the value of the {@link #updateTableInRealTime} property.
462    *
463    * @return The current value of the property
464    */
465   public boolean getUpdateTableInRealTime()
466   {
467     return updateTableInRealTime;
468   }
469
470   /**
471    * Get the value of the {@link #opaque} property.
472    *
473    * @return The current value of the property
474    */
475   public boolean isOpaque()
476   {
477     return opaque;
478   }
479
480   /**
481    * Set the value of the {@link #columnModel} property.
482    *
483    * @param c The new value of the property
484    */ 
485   public void setColumnModel(TableColumnModel c)
486   {
487     columnModel = c;
488   }
489
490   /**
491    * Set the value of the {@link #draggedColumn} property.
492    *
493    * @param d The new value of the property
494    */ 
495   public void setDraggedColumn(TableColumn d)
496   {
497     draggedColumn = d;
498   }
499
500   /**
501    * Set the value of the {@link #draggedDistance} property.
502    *
503    * @param d The new value of the property
504    */ 
505   public void setDraggedDistance(int d)
506   {
507     draggedDistance = d;
508   }
509
510   /**
511    * Set the value of the {@link #opaque} property.
512    *
513    * @param o The new value of the property
514    */ 
515   public void setOpaque(boolean o)
516   {
517     opaque = o;
518   }
519
520   /**
521    * Set the value of the {@link #reorderingAllowed} property.
522    *
523    * @param r The new value of the property
524    */ 
525   public void setReorderingAllowed(boolean r)
526   {
527     reorderingAllowed = r;
528   }
529
530   /**
531    * Set the value of the {@link #resizingAllowed} property.
532    *
533    * @param r The new value of the property
534    */ 
535   public void setResizingAllowed(boolean r)
536   {
537     resizingAllowed = r;
538   }
539
540   /**
541    * Set the value of the {@link #resizingColumn} property.
542    *
543    * @param r The new value of the property
544    */ 
545   public void setResizingColumn(TableColumn r)
546   {
547     resizingColumn = r;
548   }
549
550   /**
551    * Set the value of the {@link #table} property.
552    *
553    * @param t The new value of the property
554    */ 
555   public void setTable(JTable t)
556   {
557     table = t;
558   }
559
560   /**
561    * Set the value of the {@link #updateTableInRealTime} property.
562    *
563    * @param u The new value of the property
564    */ 
565   public void setUpdateTableInRealTime(boolean u)
566   {
567     updateTableInRealTime = u;
568   }
569
570   protected TableCellRenderer createDefaultRenderer()
571   {
572     return new DefaultTableCellRenderer();
573   }
574
575   public TableCellRenderer getDefaultRenderer()
576   {
577     return cellRenderer;
578   }
579
580   public void setDefaultRenderer(TableCellRenderer cellRenderer)
581   {
582     this.cellRenderer = cellRenderer;
583   }
584
585   public Rectangle getHeaderRect(int column)
586   {
587     Rectangle r = getTable().getCellRect(-1, column, true);
588     r.height = getHeight();
589     return r;
590   }
591
592   protected String paramString()
593   {
594     return "JTableHeader";
595   }
596
597   // UI support
598
599   public String getUIClassID()
600   {
601     return "TableHeaderUI";
602   }
603
604   public TableHeaderUI getUI()
605   {
606     return (TableHeaderUI) ui;
607   }
608
609   public void setUI(TableHeaderUI u)
610   {
611     super.setUI(u);
612   }
613
614   public void updateUI()
615   {
616     setUI((TableHeaderUI) UIManager.getUI(this));
617   }
618
619 }