コード例 #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();
   }
 }
コード例 #2
0
    public void keyPressed(KeyEvent e) {
      if (e.isConsumed()) {
        return;
      }

      if (!_list.isCheckBoxEnabled()) {
        return;
      }

      if (e.getModifiers() == 0 && e.getKeyChar() == KeyEvent.VK_SPACE) toggleSelections();
    }
コード例 #3
0
    public void mouseReleased(MouseEvent e) {
      if (e.isConsumed()) {
        return;
      }

      if (!_list.isCheckBoxEnabled()) {
        return;
      }

      if (!_list.isClickInCheckBoxOnly() || clicksInCheckBox(e)) {
        e.consume();
      }
    }
コード例 #4
0
    public void mousePressed(MouseEvent e) {
      if (e.isConsumed()) {
        return;
      }

      if (!_list.isCheckBoxEnabled()) {
        return;
      }

      if (!_list.isClickInCheckBoxOnly() || clicksInCheckBox(e)) {
        int index = _list.locationToIndex(e.getPoint());
        toggleSelection(index);
        e.consume();
      }
    }
コード例 #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();
      }
    }