< prev index next >

src/java.desktop/share/classes/javax/swing/table/JTableHeader.java

Print this page

        

*** 43,61 **** import java.io.ObjectInputStream; import java.io.IOException; /** ! * This is the object which manages the header of the <code>JTable</code>. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans&trade; ! * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Alan Chung * @author Philip Milne * @see javax.swing.JTable --- 43,61 ---- import java.io.ObjectInputStream; import java.io.IOException; /** ! * This is the object which manages the header of the {@code JTable}. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans&trade; ! * has been added to the {@code java.beans} package. * Please see {@link java.beans.XMLEncoder}. * * @author Alan Chung * @author Philip Milne * @see javax.swing.JTable
*** 72,87 **** // // Instance Variables // /** * The table for which this object is the header; ! * the default is <code>null</code>. */ protected JTable table; /** ! * The <code>TableColumnModel</code> of the table header. */ protected TableColumnModel columnModel; /** * If true, reordering of columns are allowed by the user; --- 72,87 ---- // // Instance Variables // /** * The table for which this object is the header; ! * the default is {@code null}. */ protected JTable table; /** ! * The {@code TableColumnModel} of the table header. */ protected TableColumnModel columnModel; /** * If true, reordering of columns are allowed by the user;
*** 103,146 **** * If this flag is true, then the header will repaint the table as * a column is dragged or resized; the default is true. */ protected boolean updateTableInRealTime; ! /** The index of the column being resized. <code>null</code> if not resizing. */ protected transient TableColumn resizingColumn; ! /** The index of the column being dragged. <code>null</code> if not dragging. */ protected transient TableColumn draggedColumn; /** The distance from its original position the column has been dragged. */ protected transient int draggedDistance; /** ! * The default renderer to be used when a <code>TableColumn</code> ! * does not define a <code>headerRenderer</code>. */ private TableCellRenderer defaultRenderer; // // Constructors // /** ! * Constructs a <code>JTableHeader</code> with a default ! * <code>TableColumnModel</code>. * * @see #createDefaultColumnModel */ public JTableHeader() { this(null); } /** ! * Constructs a <code>JTableHeader</code> which is initialized with ! * <code>cm</code> as the column model. If <code>cm</code> is ! * <code>null</code> this method will initialize the table header ! * with a default <code>TableColumnModel</code>. * * @param cm the column model for the table * @see #createDefaultColumnModel */ public JTableHeader(TableColumnModel cm) { --- 103,146 ---- * If this flag is true, then the header will repaint the table as * a column is dragged or resized; the default is true. */ protected boolean updateTableInRealTime; ! /** The index of the column being resized. {@code null} if not resizing. */ protected transient TableColumn resizingColumn; ! /** The index of the column being dragged. {@code null} if not dragging. */ protected transient TableColumn draggedColumn; /** The distance from its original position the column has been dragged. */ protected transient int draggedDistance; /** ! * The default renderer to be used when a {@code TableColumn} ! * does not define a {@code headerRenderer}. */ private TableCellRenderer defaultRenderer; // // Constructors // /** ! * Constructs a {@code JTableHeader} with a default ! * {@code TableColumnModel}. * * @see #createDefaultColumnModel */ public JTableHeader() { this(null); } /** ! * Constructs a {@code JTableHeader} which is initialized with ! * {@code cm} as the column model. If {@code cm} is ! * {@code null} this method will initialize the table header ! * with a default {@code TableColumnModel}. * * @param cm the column model for the table * @see #createDefaultColumnModel */ public JTableHeader(TableColumnModel cm) {
*** 177,187 **** firePropertyChange("table", old, table); } /** * Returns the table associated with this header. ! * @return the <code>table</code> property */ public JTable getTable() { return table; } --- 177,187 ---- firePropertyChange("table", old, table); } /** * Returns the table associated with this header. ! * @return the {@code table} property */ public JTable getTable() { return table; }
*** 204,214 **** /** * Returns true if the user is allowed to rearrange columns by * dragging their headers, false otherwise. The default is true. You can * rearrange columns programmatically regardless of this setting. * ! * @return the <code>reorderingAllowed</code> property * @see #setReorderingAllowed */ public boolean getReorderingAllowed() { return reorderingAllowed; } --- 204,214 ---- /** * Returns true if the user is allowed to rearrange columns by * dragging their headers, false otherwise. The default is true. You can * rearrange columns programmatically regardless of this setting. * ! * @return the {@code reorderingAllowed} property * @see #setReorderingAllowed */ public boolean getReorderingAllowed() { return reorderingAllowed; }
*** 232,254 **** /** * Returns true if the user is allowed to resize columns by dragging * between their headers, false otherwise. The default is true. You can * resize columns programmatically regardless of this setting. * ! * @return the <code>resizingAllowed</code> property * @see #setResizingAllowed */ public boolean getResizingAllowed() { return resizingAllowed; } /** * Returns the dragged column, if and only if, a drag is in ! * process, otherwise returns <code>null</code>. * * @return the dragged column, if a drag is in ! * process, otherwise returns <code>null</code> * @see #getDraggedDistance */ public TableColumn getDraggedColumn() { return draggedColumn; } --- 232,254 ---- /** * Returns true if the user is allowed to resize columns by dragging * between their headers, false otherwise. The default is true. You can * resize columns programmatically regardless of this setting. * ! * @return the {@code resizingAllowed} property * @see #setResizingAllowed */ public boolean getResizingAllowed() { return resizingAllowed; } /** * Returns the dragged column, if and only if, a drag is in ! * process, otherwise returns {@code null}. * * @return the dragged column, if a drag is in ! * process, otherwise returns {@code null} * @see #getDraggedDistance */ public TableColumn getDraggedColumn() { return draggedColumn; }
*** 267,280 **** return draggedDistance; } /** * Returns the resizing column. If no column is being ! * resized this method returns <code>null</code>. * * @return the resizing column, if a resize is in process, otherwise ! * returns <code>null</code> */ public TableColumn getResizingColumn() { return resizingColumn; } --- 267,280 ---- return draggedDistance; } /** * Returns the resizing column. If no column is being ! * resized this method returns {@code null}. * * @return the resizing column, if a resize is in process, otherwise ! * returns {@code null} */ public TableColumn getResizingColumn() { return resizingColumn; }
*** 296,334 **** public boolean getUpdateTableInRealTime() { return updateTableInRealTime; } /** ! * Sets the default renderer to be used when no <code>headerRenderer</code> ! * is defined by a <code>TableColumn</code>. * @param defaultRenderer the default renderer * @since 1.3 */ public void setDefaultRenderer(TableCellRenderer defaultRenderer) { this.defaultRenderer = defaultRenderer; } /** ! * Returns the default renderer used when no <code>headerRenderer</code> ! * is defined by a <code>TableColumn</code>. * @return the default renderer * @since 1.3 */ @Transient public TableCellRenderer getDefaultRenderer() { return defaultRenderer; } /** ! * Returns the index of the column that <code>point</code> lies in, or -1 if it * lies out of bounds. * ! * @param point if this <code>point</code> lies within a column, the index of * that column will be returned; otherwise it is out of bounds * and -1 is returned * ! * @return the index of the column that <code>point</code> lies in, or -1 if it * lies out of bounds */ public int columnAtPoint(Point point) { int x = point.x; if (!getComponentOrientation().isLeftToRight()) { --- 296,334 ---- public boolean getUpdateTableInRealTime() { return updateTableInRealTime; } /** ! * Sets the default renderer to be used when no {@code headerRenderer} ! * is defined by a {@code TableColumn}. * @param defaultRenderer the default renderer * @since 1.3 */ public void setDefaultRenderer(TableCellRenderer defaultRenderer) { this.defaultRenderer = defaultRenderer; } /** ! * Returns the default renderer used when no {@code headerRenderer} ! * is defined by a {@code TableColumn}. * @return the default renderer * @since 1.3 */ @Transient public TableCellRenderer getDefaultRenderer() { return defaultRenderer; } /** ! * Returns the index of the column that {@code point} lies in, or -1 if it * lies out of bounds. * ! * @param point if this {@code point} lies within a column, the index of * that column will be returned; otherwise it is out of bounds * and -1 is returned * ! * @return the index of the column that {@code point} lies in, or -1 if it * lies out of bounds */ public int columnAtPoint(Point point) { int x = point.x; if (!getComponentOrientation().isLeftToRight()) {
*** 336,352 **** } return getColumnModel().getColumnIndexAtX(x); } /** ! * Returns the rectangle containing the header tile at <code>column</code>. ! * When the <code>column</code> parameter is out of bounds this method uses the ! * same conventions as the <code>JTable</code> method <code>getCellRect</code>. * * @param column index of the column * ! * @return the rectangle containing the header tile at <code>column</code> * @see JTable#getCellRect */ public Rectangle getHeaderRect(int column) { Rectangle r = new Rectangle(); TableColumnModel cm = getColumnModel(); --- 336,352 ---- } return getColumnModel().getColumnIndexAtX(x); } /** ! * Returns the rectangle containing the header tile at {@code column}. ! * When the {@code column} parameter is out of bounds this method uses the ! * same conventions as the {@code JTable} method {@code getCellRect}. * * @param column index of the column * ! * @return the rectangle containing the header tile at {@code column} * @see JTable#getCellRect */ public Rectangle getHeaderRect(int column) { Rectangle r = new Rectangle(); TableColumnModel cm = getColumnModel();
*** 427,437 **** /** * Returns the preferred size of the table header. * This is the size required to display the header and requested for * the viewport. ! * The returned {@code Dimension} {@code width} will always be calculated by * the underlying TableHeaderUI, regardless of any width specified by * {@link JComponent#setPreferredSize(java.awt.Dimension)} * * @return the size */ --- 427,437 ---- /** * Returns the preferred size of the table header. * This is the size required to display the header and requested for * the viewport. ! * The returned {@code Dimension width} will always be calculated by * the underlying TableHeaderUI, regardless of any width specified by * {@link JComponent#setPreferredSize(java.awt.Dimension)} * * @return the size */
*** 450,483 **** // /** * Returns the look and feel (L&amp;F) object that renders this component. * ! * @return the <code>TableHeaderUI</code> object that renders this component */ public TableHeaderUI getUI() { return (TableHeaderUI)ui; } /** * Sets the look and feel (L&amp;F) object that renders this component. * ! * @param ui the <code>TableHeaderUI</code> L&amp;F object * @see UIDefaults#getUI */ public void setUI(TableHeaderUI ui){ if (this.ui != ui) { super.setUI(ui); repaint(); } } /** ! * Notification from the <code>UIManager</code> that the look and feel * (L&amp;F) has changed. * Replaces the current UI object with the latest version from the ! * <code>UIManager</code>. * * @see JComponent#updateUI */ public void updateUI(){ setUI((TableHeaderUI)UIManager.getUI(this)); --- 450,483 ---- // /** * Returns the look and feel (L&amp;F) object that renders this component. * ! * @return the {@code TableHeaderUI} object that renders this component */ public TableHeaderUI getUI() { return (TableHeaderUI)ui; } /** * Sets the look and feel (L&amp;F) object that renders this component. * ! * @param ui the {@code TableHeaderUI} L&amp;F object * @see UIDefaults#getUI */ public void setUI(TableHeaderUI ui){ if (this.ui != ui) { super.setUI(ui); repaint(); } } /** ! * Notification from the {@code UIManager} that the look and feel * (L&amp;F) has changed. * Replaces the current UI object with the latest version from the ! * {@code UIManager}. * * @see JComponent#updateUI */ public void updateUI(){ setUI((TableHeaderUI)UIManager.getUI(this));
*** 507,522 **** // Managing models // /** ! * Sets the column model for this table to <code>newModel</code> and registers * for listener notifications from the new column model. * * @param columnModel the new data source for this table * @exception IllegalArgumentException ! * if <code>newModel</code> is <code>null</code> * @see #getColumnModel * @beaninfo * bound: true * description: The object governing the way columns appear in the view. */ --- 507,522 ---- // Managing models // /** ! * Sets the column model for this table to {@code newModel} and registers * for listener notifications from the new column model. * * @param columnModel the new data source for this table * @exception IllegalArgumentException ! * if {@code newModel} is {@code null} * @see #getColumnModel * @beaninfo * bound: true * description: The object governing the way columns appear in the view. */
*** 536,549 **** resizeAndRepaint(); } } /** ! * Returns the <code>TableColumnModel</code> that contains all column information * of this table header. * ! * @return the <code>columnModel</code> property * @see #setColumnModel */ public TableColumnModel getColumnModel() { return columnModel; } --- 536,549 ---- resizeAndRepaint(); } } /** ! * Returns the {@code TableColumnModel} that contains all column information * of this table header. * ! * @return the {@code columnModel} property * @see #setColumnModel */ public TableColumnModel getColumnModel() { return columnModel; }
*** 554,564 **** /** * Invoked when a column is added to the table column model. * <p> * Application code will not use these methods explicitly, they ! * are used internally by <code>JTable</code>. * * @param e the event received * @see TableColumnModelListener */ public void columnAdded(TableColumnModelEvent e) { resizeAndRepaint(); } --- 554,564 ---- /** * Invoked when a column is added to the table column model. * <p> * Application code will not use these methods explicitly, they ! * are used internally by {@code JTable}. * * @param e the event received * @see TableColumnModelListener */ public void columnAdded(TableColumnModelEvent e) { resizeAndRepaint(); }
*** 566,576 **** /** * Invoked when a column is removed from the table column model. * <p> * Application code will not use these methods explicitly, they ! * are used internally by <code>JTable</code>. * * @param e the event received * @see TableColumnModelListener */ public void columnRemoved(TableColumnModelEvent e) { resizeAndRepaint(); } --- 566,576 ---- /** * Invoked when a column is removed from the table column model. * <p> * Application code will not use these methods explicitly, they ! * are used internally by {@code JTable}. * * @param e the event received * @see TableColumnModelListener */ public void columnRemoved(TableColumnModelEvent e) { resizeAndRepaint(); }
*** 578,588 **** /** * Invoked when a column is repositioned. * <p> * Application code will not use these methods explicitly, they ! * are used internally by <code>JTable</code>. * * @param e the event received * @see TableColumnModelListener */ public void columnMoved(TableColumnModelEvent e) { repaint(); } --- 578,588 ---- /** * Invoked when a column is repositioned. * <p> * Application code will not use these methods explicitly, they ! * are used internally by {@code JTable}. * * @param e the event received * @see TableColumnModelListener */ public void columnMoved(TableColumnModelEvent e) { repaint(); }
*** 590,600 **** /** * Invoked when a column is moved due to a margin change. * <p> * Application code will not use these methods explicitly, they ! * are used internally by <code>JTable</code>. * * @param e the event received * @see TableColumnModelListener */ public void columnMarginChanged(ChangeEvent e) { resizeAndRepaint(); } --- 590,600 ---- /** * Invoked when a column is moved due to a margin change. * <p> * Application code will not use these methods explicitly, they ! * are used internally by {@code JTable}. * * @param e the event received * @see TableColumnModelListener */ public void columnMarginChanged(ChangeEvent e) { resizeAndRepaint(); }
*** 602,617 **** // --Redrawing the header is slow in cell selection mode. // --Since header selection is ugly and it is always clear from the // --view which columns are selected, don't redraw the header. /** ! * Invoked when the selection model of the <code>TableColumnModel</code> * is changed. This method currently has no effect (the header is not * redrawn). * <p> * Application code will not use these methods explicitly, they ! * are used internally by <code>JTable</code>. * * @param e the event received * @see TableColumnModelListener */ public void columnSelectionChanged(ListSelectionEvent e) { } // repaint(); } --- 602,617 ---- // --Redrawing the header is slow in cell selection mode. // --Since header selection is ugly and it is always clear from the // --view which columns are selected, don't redraw the header. /** ! * Invoked when the selection model of the {@code TableColumnModel} * is changed. This method currently has no effect (the header is not * redrawn). * <p> * Application code will not use these methods explicitly, they ! * are used internally by {@code JTable}. * * @param e the event received * @see TableColumnModelListener */ public void columnSelectionChanged(ListSelectionEvent e) { } // repaint(); }
*** 620,641 **** // Package Methods // /** * Returns the default column model object which is ! * a <code>DefaultTableColumnModel</code>. A subclass can override this * method to return a different column model object * * @return the default column model object */ protected TableColumnModel createDefaultColumnModel() { return new DefaultTableColumnModel(); } /** * Returns a default renderer to be used when no header renderer ! * is defined by a <code>TableColumn</code>. * * @return the default table column renderer * @since 1.3 */ protected TableCellRenderer createDefaultRenderer() { --- 620,641 ---- // Package Methods // /** * Returns the default column model object which is ! * a {@code DefaultTableColumnModel}. A subclass can override this * method to return a different column model object * * @return the default column model object */ protected TableColumnModel createDefaultColumnModel() { return new DefaultTableColumnModel(); } /** * Returns a default renderer to be used when no header renderer ! * is defined by a {@code TableColumn}. * * @return the default table column renderer * @since 1.3 */ protected TableCellRenderer createDefaultRenderer() {
*** 664,717 **** setDefaultRenderer(createDefaultRenderer()); } /** * Sizes the header and marks it as needing display. Equivalent ! * to <code>revalidate</code> followed by <code>repaint</code>. */ public void resizeAndRepaint() { revalidate(); repaint(); } /** ! * Sets the header's <code>draggedColumn</code> to <code>aColumn</code>. * <p> * Application code will not use this method explicitly, it is used * internally by the column dragging mechanism. * ! * @param aColumn the column being dragged, or <code>null</code> if * no column is being dragged */ public void setDraggedColumn(TableColumn aColumn) { draggedColumn = aColumn; } /** ! * Sets the header's <code>draggedDistance</code> to <code>distance</code>. * @param distance the distance dragged */ public void setDraggedDistance(int distance) { draggedDistance = distance; } /** ! * Sets the header's <code>resizingColumn</code> to <code>aColumn</code>. * <p> * Application code will not use this method explicitly, it * is used internally by the column sizing mechanism. * ! * @param aColumn the column being resized, or <code>null</code> if * no column is being resized */ public void setResizingColumn(TableColumn aColumn) { resizingColumn = aColumn; } /** ! * See <code>readObject</code> and <code>writeObject</code> in ! * <code>JComponent</code> for more * information about serialization in Swing. */ private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); if ((ui != null) && (getUIClassID().equals(uiClassID))) { --- 664,717 ---- setDefaultRenderer(createDefaultRenderer()); } /** * Sizes the header and marks it as needing display. Equivalent ! * to {@code revalidate} followed by {@code repaint}. */ public void resizeAndRepaint() { revalidate(); repaint(); } /** ! * Sets the header's {@code draggedColumn} to {@code aColumn}. * <p> * Application code will not use this method explicitly, it is used * internally by the column dragging mechanism. * ! * @param aColumn the column being dragged, or {@code null} if * no column is being dragged */ public void setDraggedColumn(TableColumn aColumn) { draggedColumn = aColumn; } /** ! * Sets the header's {@code draggedDistance} to {@code distance}. * @param distance the distance dragged */ public void setDraggedDistance(int distance) { draggedDistance = distance; } /** ! * Sets the header's {@code resizingColumn} to {@code aColumn}. * <p> * Application code will not use this method explicitly, it * is used internally by the column sizing mechanism. * ! * @param aColumn the column being resized, or {@code null} if * no column is being resized */ public void setResizingColumn(TableColumn aColumn) { resizingColumn = aColumn; } /** ! * See {@code readObject} and {@code writeObject} in ! * {@code JComponent} for more * information about serialization in Swing. */ private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); if ((ui != null) && (getUIClassID().equals(uiClassID))) {
*** 726,745 **** } return super.getWidth(); } /** ! * Returns a string representation of this <code>JTableHeader</code>. This method * is intended to be used only for debugging purposes, and the * content and format of the returned string may vary between * implementations. The returned string may be empty but may not ! * be <code>null</code>. * <P> ! * Overriding <code>paramString</code> to provide information about the * specific new aspects of the JFC components. * ! * @return a string representation of this <code>JTableHeader</code> */ protected String paramString() { String reorderingAllowedString = (reorderingAllowed ? "true" : "false"); String resizingAllowedString = (resizingAllowed ? --- 726,745 ---- } return super.getWidth(); } /** ! * Returns a string representation of this {@code JTableHeader}. This method * is intended to be used only for debugging purposes, and the * content and format of the returned string may vary between * implementations. The returned string may be empty but may not ! * be {@code null}. * <P> ! * Overriding {@code paramString} to provide information about the * specific new aspects of the JFC components. * ! * @return a string representation of this {@code JTableHeader} */ protected String paramString() { String reorderingAllowedString = (reorderingAllowed ? "true" : "false"); String resizingAllowedString = (resizingAllowed ?
*** 778,798 **** // *** should also implement AccessibleSelection? // *** and what's up with keyboard navigation/manipulation? // /** * This class implements accessibility support for the ! * <code>JTableHeader</code> class. It provides an implementation of the * Java Accessibility API appropriate to table header user-interface * elements. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans&trade; ! * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. */ @SuppressWarnings("serial") // Same-version serialization only protected class AccessibleJTableHeader extends AccessibleJComponent { --- 778,798 ---- // *** should also implement AccessibleSelection? // *** and what's up with keyboard navigation/manipulation? // /** * This class implements accessibility support for the ! * {@code JTableHeader} class. It provides an implementation of the * Java Accessibility API appropriate to table header user-interface * elements. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans&trade; ! * has been added to the {@code java.beans} package. * Please see {@link java.beans.XMLEncoder}. */ @SuppressWarnings("serial") // Same-version serialization only protected class AccessibleJTableHeader extends AccessibleJComponent {
*** 895,906 **** /** * Constructs an AccessiblJTableHeaaderEntry * @since 1.4 * * @param c the column index ! * @param p the parent <code>JTableHeader</code> ! * @param t the table <code>JTable</code> */ public AccessibleJTableHeaderEntry(int c, JTableHeader p, JTable t) { parent = p; column = c; table = t; --- 895,906 ---- /** * Constructs an AccessiblJTableHeaaderEntry * @since 1.4 * * @param c the column index ! * @param p the parent {@code JTableHeader} ! * @param t the table {@code JTable} */ public AccessibleJTableHeaderEntry(int c, JTableHeader p, JTable t) { parent = p; column = c; table = t;
< prev index next >