Ejemplo 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();
   }
 }
Ejemplo n.º 2
0
    protected boolean clicksInCheckBox(MouseEvent e) {
      int index = _list.locationToIndex(e.getPoint());
      Rectangle bounds = _list.getCellBounds(index, index);

      if (bounds != null) {
        if (_list.getComponentOrientation().isLeftToRight()) {
          return e.getX() < bounds.x + hotspot;
        } else {
          return e.getX() > bounds.x + bounds.width - hotspot;
        }
      } else {
        return false;
      }
    }
Ejemplo n.º 3
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();
      }
    }
Ejemplo n.º 4
0
 public void intervalRemoved(ListDataEvent e) {
   /* Sync the SelectionModel with the DataModel.
    */
   ListSelectionModel listSelectionModel = _list.getCheckBoxListSelectionModel();
   if (listSelectionModel != null) {
     listSelectionModel.removeIndexInterval(e.getIndex0(), e.getIndex1());
   }
 }
Ejemplo n.º 5
0
    public void mousePressed(MouseEvent e) {
      if (e.isConsumed()) {
        return;
      }

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

      boolean clickInBox = clicksInCheckBox(e);
      if (!_list.isClickInCheckBoxOnly() || clickInBox) {
        int index = _list.locationToIndex(e.getPoint());
        toggleSelection(index);
        if (clickInBox) {
          e.consume();
        }
      }
    }
Ejemplo n.º 6
0
 public void propertyChange(PropertyChangeEvent evt) {
   if (evt.getOldValue() instanceof ListModel) {
     ((ListModel) evt.getOldValue()).removeListDataListener(this);
   }
   if (evt.getNewValue() instanceof ListModel) {
     _list.getCheckBoxListSelectionModel().setModel((ListModel) evt.getNewValue());
     ((ListModel) evt.getNewValue()).addListDataListener(this);
   }
 }
Ejemplo n.º 7
0
    public void keyPressed(KeyEvent e) {
      if (e.isConsumed()) {
        return;
      }

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

      if (e.getModifiers() == 0 && e.getKeyChar() == KeyEvent.VK_SPACE) toggleSelections();
    }
Ejemplo n.º 8
0
    public void intervalAdded(ListDataEvent e) {
      int minIndex = Math.min(e.getIndex0(), e.getIndex1());
      int maxIndex = Math.max(e.getIndex0(), e.getIndex1());

      /* Sync the SelectionModel with the DataModel.
       */

      ListSelectionModel listSelectionModel = _list.getCheckBoxListSelectionModel();
      if (listSelectionModel != null) {
        listSelectionModel.insertIndexInterval(minIndex, maxIndex - minIndex + 1, true);
      }
    }
Ejemplo n.º 9
0
    public void mouseReleased(MouseEvent e) {
      if (e.isConsumed()) {
        return;
      }

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

      if (clicksInCheckBox(e)) {
        e.consume();
      }
    }
Ejemplo n.º 10
0
 protected void toggleSelection() {
   int index = _list.getSelectedIndex();
   toggleSelection(index);
 }
Ejemplo n.º 11
0
 public void valueChanged(ListSelectionEvent e) {
   _list.repaint();
 }