/** * Selects a single cell and keeps all previous selections. * * @param index the index of the one cell to select * @see ListSelectionModel#setSelectionInterval * @see #isSelectedIndex * @see #addListSelectionListener */ public void addCheckBoxListSelectedIndex(int index) { if (index >= 0 && index < getModel().getSize()) { getCheckBoxListSelectionModel().addSelectionInterval(index, index); } }
@Override public void run() { final String text = maskNameSearchField.getText(); final DefaultListModel<Object> updatedListModel = new DefaultListModel<>(); List<Boolean> selected = new ArrayList<>(); int[] newIndexesInMaskNameList = new int[maskNameListModel.getSize()]; int counter = 0; for (int i = 0; i < maskNameListModel.getSize(); i++) { if (maskNameListModel.get(i).toLowerCase().contains(text.toLowerCase())) { updatedListModel.addElement(maskNameListModel.get(i)); if (indexesInMaskNameList[i] >= 0) { selected.add(maskNameList.getCheckBoxListSelectionModel().isSelectedIndex(indexesInMaskNameList[i])); } else { selected.add(false); } newIndexesInMaskNameList[i] = counter++; } else { newIndexesInMaskNameList[i] = -1; } } indexesInMaskNameList = newIndexesInMaskNameList; maskNameList.setModel(updatedListModel); for (int i = 0; i < selected.size(); i++) { if (selected.get(i)) { maskNameList.getCheckBoxListSelectionModel().addSelectionInterval(i, i); } } } });
public void actionPerformed(ActionEvent e) { _list.getCheckBoxListSelectionModel().addSelectionInterval(0, _list.getModel().getSize() - 1); } });
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(); } }
private void resetMaskListState() { maskNameListModel = new DefaultListModel<>(); final String[] currentSelectedMaskNames = getSelectedMaskNames(); if (product != null && raster != null) { //todo [multisize_products] compare scenerastertransform (or its successor) rather than size (tf) final ProductNodeGroup<Mask> maskGroup = product.getMaskGroup(); for (int i = 0; i < maskGroup.getNodeCount(); i++) { final Mask mask = maskGroup.get(i); if (mask.getRasterSize().equals(raster.getRasterSize())) { maskNameListModel.addElement(mask.getName()); } } maskNameList.setModel(maskNameListModel); } final String[] allNames = StringUtils.toStringArray(maskNameListModel.toArray()); indexesInMaskNameList = new int[allNames.length]; for (int i = 0; i < allNames.length; i++) { String name = allNames[i]; if (StringUtils.contains(currentSelectedMaskNames, name)) { maskNameList.getCheckBoxListSelectionModel().addSelectionInterval(i, i); } indexesInMaskNameList[i] = i; } updateEnablement(); }
addSelectionInterval(index + length, index + length);
String name = allNames[i]; if (StringUtils.contains(currentSelectedMaskNames, name)) { maskNameList.getCheckBoxListSelectionModel().addSelectionInterval(i, i);
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(); } }