Exemple #1
0
  /**
   * Returns an array of the values for the selected cells. The returned values are sorted in
   * increasing index order.
   *
   * @return the selected values or an empty list if nothing is selected
   * @see #isSelectedIndex
   * @see #getModel
   * @see #addListSelectionListener
   */
  public Object[] getCheckBoxListSelectedValues() {
    CheckBoxListSelectionModel listSelectionModel = getCheckBoxListSelectionModel();
    ListModel model = getModel();

    int iMin = listSelectionModel.getMinSelectionIndex();
    int iMax = listSelectionModel.getMaxSelectionIndex();

    if ((iMin < 0) || (iMax < 0)) {
      return new Object[0];
    }

    Object[] temp = new Object[1 + (iMax - iMin)];
    int n = 0;
    for (int i = iMin; i <= iMax; i++) {
      if (listSelectionModel.isAllEntryConsidered() && i == listSelectionModel.getAllEntryIndex()) {
        continue;
      }
      if (listSelectionModel.isSelectedIndex(i)) {
        temp[n] = model.getElementAt(i);
        n++;
      }
    }
    Object[] indices = new Object[n];
    System.arraycopy(temp, 0, indices, 0, n);
    return indices;
  }