< prev index next >

## src/java.desktop/share/classes/javax/swing/table/DefaultTableColumnModel.java

Print this page

     410     // implements javax.swing.table.TableColumnModel
     411     /**
     412      * Returns true if column selection is allowed, otherwise false.
     413      * The default is false.
     414      * @return the <code>columnSelectionAllowed</code> property
     415      */
     416     public boolean getColumnSelectionAllowed() {
     417         return columnSelectionAllowed;
     418     }
     419
     420     // implements javax.swing.table.TableColumnModel
     421     /**
     422      * Returns an array of selected columns.  If <code>selectionModel</code>
     423      * is <code>null</code>, returns an empty array.
     424      * @return an array of selected columns or an empty array if nothing
     425      *                  is selected or the <code>selectionModel</code> is
     426      *                  <code>null</code>
     427      */
     428     public int[] getSelectedColumns() {
     429         if (selectionModel != null) {
     430             int iMin = selectionModel.getMinSelectionIndex();
     431             int iMax = selectionModel.getMaxSelectionIndex();
     432
     433             if ((iMin == -1) || (iMax == -1)) {
     434                 return new int[0];
     435             }
     436
     437             int[] rvTmp = new int[1+ (iMax - iMin)];
     438             int n = 0;
     439             for(int i = iMin; i <= iMax; i++) {
     440                 if (selectionModel.isSelectedIndex(i)) {
     441                     rvTmp[n++] = i;
     442                 }
     443             }
     444             int[] rv = new int[n];
     445             System.arraycopy(rvTmp, 0, rv, 0, n);
     446             return rv;
     447         }
     448         return  new int[0];
     449     }
     450
     451     // implements javax.swing.table.TableColumnModel
     452     /**
     453      * Returns the number of columns selected.
     454      * @return the number of columns selected
     455      */
     456     public int getSelectedColumnCount() {
     457         if (selectionModel != null) {
     458             int iMin = selectionModel.getMinSelectionIndex();
     459             int iMax = selectionModel.getMaxSelectionIndex();
     460             int count = 0;
     461
     462             for(int i = iMin; i <= iMax; i++) {
     463                 if (selectionModel.isSelectedIndex(i)) {
     464                     count++;
     465                 }
     466             }
     467             return count;
     468         }
     469         return 0;
     470     }
     471
     472 //
     473 // Listener Support Methods
     474 //
     475
     476     // implements javax.swing.table.TableColumnModel
     477     /**
     478      * Adds a listener for table column model events.
     479      * @param x  a <code>TableColumnModelListener</code> object
     480      */
     481     public void addColumnModelListener(TableColumnModelListener x) {
     482         listenerList.add(TableColumnModelListener.class, x);
     483     }
     484
     485     // implements javax.swing.table.TableColumnModel
     486     /**
     487      * Removes a listener for table column model events.
     410     // implements javax.swing.table.TableColumnModel
     411     /**
     412      * Returns true if column selection is allowed, otherwise false.
     413      * The default is false.
     414      * @return the <code>columnSelectionAllowed</code> property
     415      */
     416     public boolean getColumnSelectionAllowed() {
     417         return columnSelectionAllowed;
     418     }
     419
     420     // implements javax.swing.table.TableColumnModel
     421     /**
     422      * Returns an array of selected columns.  If <code>selectionModel</code>
     423      * is <code>null</code>, returns an empty array.
     424      * @return an array of selected columns or an empty array if nothing
     425      *                  is selected or the <code>selectionModel</code> is
     426      *                  <code>null</code>
     427      */
     428     public int[] getSelectedColumns() {
     429         if (selectionModel != null) {
     430             return selectionModel.getSelectedIndices();

     431         }
     432         return  new int[0];
     433     }
     434
     435     // implements javax.swing.table.TableColumnModel
     436     /**
     437      * Returns the number of columns selected.
     438      * @return the number of columns selected
     439      */
     440     public int getSelectedColumnCount() {
     441         if (selectionModel != null) {
     442             return selectionModel.getSelectedItemsCount();

     443         }
     444         return 0;
     445     }
     446
     447 //
     448 // Listener Support Methods
     449 //
     450
     451     // implements javax.swing.table.TableColumnModel
     452     /**
     453      * Adds a listener for table column model events.
     454      * @param x  a <code>TableColumnModelListener</code> object
     455      */
     456     public void addColumnModelListener(TableColumnModelListener x) {
     457         listenerList.add(TableColumnModelListener.class, x);
     458     }
     459
     460     // implements javax.swing.table.TableColumnModel
     461     /**
     462      * Removes a listener for table column model events.

< prev index next >