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