Exemplo n.º 1
0
 protected void toggleSelections() {
   int[] indices = _list.getSelectedIndices();
   CheckBoxListSelectionModel selectionModel = _list.getCheckBoxListSelectionModel();
   selectionModel.removeListSelectionListener(this);
   selectionModel.setValueIsAdjusting(true);
   try {
     if (indices.length > 0) {
       boolean selected = selectionModel.isSelectedIndex(indices[0]);
       for (int index : indices) {
         if (!_list.isCheckBoxEnabled(index)) {
           continue;
         }
         if (selected && selectionModel.isSelectedIndex(index)) {
           selectionModel.removeSelectionInterval(index, index);
         } else if (!selected && !selectionModel.isSelectedIndex(index)) {
           selectionModel.addSelectionInterval(index, index);
         }
       }
     }
   } finally {
     selectionModel.setValueIsAdjusting(false);
     selectionModel.addListSelectionListener(this);
     _list.repaint();
   }
 }
Exemplo n.º 2
0
 public void setCheckBoxListSelectionModel(CheckBoxListSelectionModel checkBoxListSelectionModel) {
   if (_checkBoxListSelectionModel != checkBoxListSelectionModel) {
     if (_checkBoxListSelectionModel != null) {
       getModel().removeListDataListener(_checkBoxListSelectionModel);
     }
     _checkBoxListSelectionModel = checkBoxListSelectionModel;
     if (_checkBoxListSelectionModel != null) {
       _checkBoxListSelectionModel.setModel(getModel());
     }
   }
 }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
0
 /** Initialize the CheckBoxList. */
 protected void init() {
   _checkBoxListSelectionModel = createCheckBoxListSelectionModel(getModel());
   setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
   _listCellRenderer = createCellRenderer();
   _handler = createHandler();
   _checkBoxListSelectionModel.addListSelectionListener(_handler);
   JideSwingUtilities.insertMouseListener(this, _handler, 0);
   addKeyListener(_handler);
   addPropertyChangeListener("model", _handler);
   ListModel model = getModel();
   if (model != null) {
     model.addListDataListener(_handler);
   }
 }
Exemplo n.º 5
0
    protected void toggleSelection(int index) {
      if (!_list.isEnabled() || !_list.isCheckBoxEnabled(index)) {
        return;
      }

      CheckBoxListSelectionModel selectionModel = _list.getCheckBoxListSelectionModel();
      boolean selected = selectionModel.isSelectedIndex(index);
      selectionModel.removeListSelectionListener(this);
      try {
        if (selected) selectionModel.removeSelectionInterval(index, index);
        else selectionModel.addSelectionInterval(index, index);
      } finally {
        selectionModel.addListSelectionListener(this);
        _list.repaint();
      }
    }
Exemplo n.º 6
0
 public void setCheckBoxListSelectionModel(CheckBoxListSelectionModel checkBoxListSelectionModel) {
   _checkBoxListSelectionModel = checkBoxListSelectionModel;
   _checkBoxListSelectionModel.setModel(getModel());
 }