739 lines · 25.9 KB · Java
RawDownload
     * @see #addColumnModelListener     * @see #removeColumnModelListener     *     * @since 1.4     */    public TableColumnModelListener[] getColumnModelListeners() {        return listenerList.getListeners(TableColumnModelListener.class);    } ////   Event firing methods//     /**     * Notifies all listeners that have registered interest for     * notification on this event type.  The event instance     * is lazily created using the parameters passed into     * the fire method.     * @param e  the event received     * @see EventListenerList     */    protected void fireColumnAdded(TableColumnModelEvent e) {        // Guaranteed to return a non-null array        Object[] listeners = listenerList.getListenerList();        // Process the listeners last to first, notifying        // those that are interested in this event        for (int i = listeners.length-2; i>=0; i-=2) {            if (listeners[i]==TableColumnModelListener.class) {                // Lazily create the event:                // if (e == null)                //  e = new ChangeEvent(this);                ((TableColumnModelListener)listeners[i+1]).                    columnAdded(e);            }        }    }     /**     * Notifies all listeners that have registered interest for     * notification on this event type.  The event instance     * is lazily created using the parameters passed into     * the fire method.     * @param  e  the event received     * @see EventListenerList     */    protected void fireColumnRemoved(TableColumnModelEvent e) {        // Guaranteed to return a non-null array        Object[] listeners = listenerList.getListenerList();        // Process the listeners last to first, notifying        // those that are interested in this event        for (int i = listeners.length-2; i>=0; i-=2) {            if (listeners[i]==TableColumnModelListener.class) {                // Lazily create the event:                // if (e == null)                //  e = new ChangeEvent(this);                ((TableColumnModelListener)listeners[i+1]).                    columnRemoved(e);            }        }    }     /**     * Notifies all listeners that have registered interest for     * notification on this event type.  The event instance     * is lazily created using the parameters passed into     * the fire method.     * @param  e the event received     * @see EventListenerList     */    protected void fireColumnMoved(TableColumnModelEvent e) {        // Guaranteed to return a non-null array        Object[] listeners = listenerList.getListenerList();        // Process the listeners last to first, notifying        // those that are interested in this event        for (int i = listeners.length-2; i>=0; i-=2) {            if (listeners[i]==TableColumnModelListener.class) {                // Lazily create the event:                // if (e == null)                //  e = new ChangeEvent(this);                ((TableColumnModelListener)listeners[i+1]).                    columnMoved(e);            }        }    }     /**     * Notifies all listeners that have registered interest for     * notification on this event type.  The event instance     * is lazily created using the parameters passed into     * the fire method.     * @param e the event received     * @see EventListenerList     */    protected void fireColumnSelectionChanged(ListSelectionEvent e) {        // Guaranteed to return a non-null array        Object[] listeners = listenerList.getListenerList();        // Process the listeners last to first, notifying        // those that are interested in this event        for (int i = listeners.length-2; i>=0; i-=2) {            if (listeners[i]==TableColumnModelListener.class) {                // Lazily create the event:                // if (e == null)                //  e = new ChangeEvent(this);                ((TableColumnModelListener)listeners[i+1]).                    columnSelectionChanged(e);            }        }    }     /**     * Notifies all listeners that have registered interest for     * notification on this event type.  The event instance     * is lazily created using the parameters passed into     * the fire method.     * @see EventListenerList     */    protected void fireColumnMarginChanged() {        // Guaranteed to return a non-null array        Object[] listeners = listenerList.getListenerList();        // Process the listeners last to first, notifying        // those that are interested in this event        for (int i = listeners.length-2; i>=0; i-=2) {            if (listeners[i]==TableColumnModelListener.class) {                // Lazily create the event:                if (changeEvent == null)                    changeEvent = new ChangeEvent(this);                ((TableColumnModelListener)listeners[i+1]).                    columnMarginChanged(changeEvent);            }        }    }     /**     * Returns an array of all the objects currently registered     * as <code><em>Foo</em>Listener</code>s     * upon this model.     * <code><em>Foo</em>Listener</code>s are registered using the     * <code>add<em>Foo</em>Listener</code> method.     *     * <p>     *     * You can specify the <code>listenerType</code> argument     * with a class literal,     * such as     * <code><em>Foo</em>Listener.class</code>.     * For example, you can query a     * <code>DefaultTableColumnModel</code> <code>m</code>     * for its column model listeners with the following code:     *     * <pre>ColumnModelListener[] cmls = (ColumnModelListener[])(m.getListeners(ColumnModelListener.class));</pre>     *     * If no such listeners exist, this method returns an empty array.     *     * @param listenerType the type of listeners requested; this parameter     *          should specify an interface that descends from     *          <code>java.util.EventListener</code>     * @return an array of all objects registered as     *          <code><em>Foo</em>Listener</code>s on this model,     *          or an empty array if no such     *          listeners have been added     * @exception ClassCastException if <code>listenerType</code>     *          doesn't specify a class or interface that implements     *          <code>java.util.EventListener</code>     *     * @see #getColumnModelListeners     * @since 1.3     */    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {        return listenerList.getListeners(listenerType);    } //// Implementing the PropertyChangeListener interface//     // PENDING(alan)    // implements java.beans.PropertyChangeListener    /**     * Property Change Listener change method.  Used to track changes     * to the column width or preferred column width.     *     * @param  evt  <code>PropertyChangeEvent</code>     */    public void propertyChange(PropertyChangeEvent evt) {        String name = evt.getPropertyName();         if (name == "width" || name == "preferredWidth") {            invalidateWidthCache();            // This is a misnomer, we're using this method            // simply to cause a relayout.            fireColumnMarginChanged();        }     } //// Implementing ListSelectionListener interface//     // implements javax.swing.event.ListSelectionListener    /**     * A <code>ListSelectionListener</code> that forwards     * <code>ListSelectionEvents</code> when there is a column     * selection change.     *     * @param e  the change event     */    public void valueChanged(ListSelectionEvent e) {        fireColumnSelectionChanged(e);    } //// Protected Methods//     /**     * Creates a new default list selection model.     */    protected ListSelectionModel createSelectionModel() {        return new DefaultListSelectionModel();    }     /**     * Recalculates the total combined width of all columns.  Updates the     * <code>totalColumnWidth</code> property.     */    protected void recalcWidthCache() {        Enumeration enumeration = getColumns();        totalColumnWidth = 0;        while (enumeration.hasMoreElements()) {            totalColumnWidth += ((TableColumn)enumeration.nextElement()).getWidth();        }    }     private void invalidateWidthCache() {        totalColumnWidth = -1;    } } // End of class DefaultTableColumnModel

Lines 501–739 of 739. Previous lines