javax.swing.ListSelectionModel#clearSelection ( )源码实例Demo

下面列出了javax.swing.ListSelectionModel#clearSelection ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void valueChanged(ListSelectionEvent e) {
   if(e.getValueIsAdjusting()) {
      return;
   }
   
   ListSelectionModel m = (ListSelectionModel) e.getSource();
   if(!m.isSelectionEmpty()) {
      for(ListSelectionModel delegate: delegates) {
         if(delegate == m) {
            continue;
         }
         delegate.clearSelection();
      }
   }
}
 
源代码2 项目: netbeans   文件: SecurityRoleMappingPanel.java
/** Remove all selected items from the specified table.
 */
private void handleRemoveAction(JTable theTable) {
    int [] selectedIndices = theTable.getSelectedRows();
    if(selectedIndices.length > 0) {
        ListSelectionModel selectionModel = theTable.getSelectionModel();
        try {
            SRMBaseTableModel theModel = (SRMBaseTableModel) theTable.getModel();
            selectionModel.setValueIsAdjusting(true);
            theModel.removeElements(selectedIndices);
            int numElements = theTable.getModel().getRowCount();
            if(numElements > 0) {
                int newSelectedIndex = selectedIndices[0];
                if(newSelectedIndex >= numElements) {
                    newSelectedIndex = numElements-1;
                }
                selectionModel.setSelectionInterval(newSelectedIndex, newSelectedIndex);
            } else {
                selectionModel.clearSelection();
            }
        } finally {
            selectionModel.setValueIsAdjusting(false);
        }
    }
}
 
源代码3 项目: sldeditor   文件: SortByPanel.java
/**
 * Sets the text.
 *
 * @param value the new text
 */
public void setText(String value) {
    Map<String, String> options = new HashMap<>();

    ListSelectionModel model = destinationTable.getSelectionModel();
    model.clearSelection();

    SortBy[] sortArray = null;

    if (!value.isEmpty()) {
        options.put(FeatureTypeStyle.SORT_BY, value);

        sortArray = SLDStyleFactory.getSortBy(options);
    }
    destinationModel.populate(sortArray);
    updateLists();

    btnMoveDown.setEnabled(false);
    btnMoveUp.setEnabled(false);
    btnDestToSrcButton.setEnabled(false);
    btnSrcToDestButton.setEnabled(false);
}
 
源代码4 项目: netbeans   文件: OutlineView.java
public void setTo(ListSelectionModel sm) {
    sm.clearSelection();
    sm.setSelectionMode(selectionMode);
    for (int[] itv : intervals) {
        sm.addSelectionInterval(itv[0], itv[1]);
    }
    sm.setAnchorSelectionIndex(anchor);
    sm.setLeadSelectionIndex(lead);
}
 
源代码5 项目: netbeans   文件: VCSStatusTable.java
public final void setSelectedNodes (File[] selectedFiles) {
    Set<File> files = new HashSet<File>(Arrays.asList(selectedFiles));
    ListSelectionModel selection = table.getSelectionModel();
    selection.setValueIsAdjusting(true);
    selection.clearSelection();
    for (int i = 0; i < table.getRowCount(); ++i) {
        T node = tableModel.getNode(table.convertRowIndexToModel(i));
        if (files.contains(node.getFile())) {
            selection.addSelectionInterval(i, i);
        }
    }
    selection.setValueIsAdjusting(false);
}
 
源代码6 项目: netbeans   文件: OptionsPanel.java
private void selectRows(int[] selectedRows, int delta) {
    ListSelectionModel listSelectionModel = mappingsTable.getSelectionModel();
    listSelectionModel.clearSelection();
    for (int selectedRow : selectedRows) {
        listSelectionModel.addSelectionInterval(selectedRow + delta, selectedRow + delta);
    }
}
 
源代码7 项目: sldeditor   文件: SortByPanel.java
/** Move source to destination. */
protected void moveSrcToDestination() {
    List<String> selectedItemList = sourceList.getSelectedValuesList();

    for (String item : selectedItemList) {
        destinationModel.addProperty(item);
        sourceModel.removeElement(item);
    }

    ListSelectionModel model = destinationTable.getSelectionModel();
    model.clearSelection();

    btnSrcToDestButton.setEnabled(false);
}
 
源代码8 项目: sldeditor   文件: SortByPanel.java
/**
 * Select destination rows.
 *
 * @param selectedIndexes the selected indexes
 */
protected void selectDestination(int[] selectedIndexes) {
    ListSelectionModel model = destinationTable.getSelectionModel();
    model.clearSelection();
    for (int index : selectedIndexes) {
        model.addSelectionInterval(index, index);
    }
}
 
源代码9 项目: keystore-explorer   文件: KseFrame.java
public void setSelectedEntriesByAliases(String... aliases) {
	JTable jtKeyStore = getActiveKeyStoreTable();
	jtKeyStore.requestFocusInWindow();

	ListSelectionModel selectionModel = jtKeyStore.getSelectionModel();
	selectionModel.clearSelection();
	Set<String> aliasesToSelect = new HashSet<>(Arrays.asList(aliases));
	for (int i = 0; i < jtKeyStore.getRowCount(); i++) {
		if (aliasesToSelect.contains(jtKeyStore.getValueAt(i, 3))) {
			selectionModel.addSelectionInterval(i, i);
		}
	}
}
 
源代码10 项目: snap-desktop   文件: NamesAssociationDialog.java
@Override
public void actionPerformed(ActionEvent e) {
    final ListSelectionModel selectionModel = aliasNames.getSelectionModel();
    final int minSelectionIndex = selectionModel.getMinSelectionIndex();
    final int maxSelectionIndex = selectionModel.getMaxSelectionIndex();
    selectionModel.clearSelection();
    if (minSelectionIndex != -1) {
        for (int i = maxSelectionIndex; i >= minSelectionIndex; i--) {
            associationModel.removeAlias(getAliasNameAt(i));
        }
    }
    removeButton.setEnabled(associationModel.getAliasNames().size() > 0);
    aliasNameScrollPane.repaint();
}
 
源代码11 项目: snap-desktop   文件: MosaicExpressionsPanel.java
private static void selectRows(final JTable table, final int[] rows) {
    final ListSelectionModel selectionModel = table.getSelectionModel();
    selectionModel.clearSelection();
    for (int row : rows) {
        selectionModel.addSelectionInterval(row, row);
    }
}
 
源代码12 项目: wandora   文件: TableSelectionModel.java
/**
* Calls clearSelection() of all ListSelectionModels.
*/
public void clearSelection() {
    for(Iterator enu=listSelectionModels.iterator(); enu.hasNext();) {
        ListSelectionModel lm = (ListSelectionModel)(enu.next());
        lm.clearSelection();
    }
}
 
源代码13 项目: tcpmon   文件: Listener.java
/**
 * Method removeAll
 */
public void removeAll() {
    ListSelectionModel lsm = connectionTable.getSelectionModel();
    lsm.clearSelection();
    while (connections.size() > 0) {
        ((Connection) connections.get(0)).remove();
    }
    lsm.setSelectionInterval(0, 0);
}
 
源代码14 项目: netbeans   文件: SourceRootsUi.java
private void addFolders( File files[] ) {
            int[] si = rootsList.getSelectedRows();
            int lastIndex = si == null || si.length == 0 ? -1 : si[si.length - 1];
            ListSelectionModel selectionModel = this.rootsList.getSelectionModel();
            selectionModel.clearSelection();
            Set<File> rootsFromOtherProjects = new HashSet<File>();
            Set<File> rootsFromRelatedSourceRoots = new HashSet<File>();
            String type = RootsAccessor.getInstance().getType(sourceRoots);
            boolean isModule = JavaProjectConstants.SOURCES_TYPE_MODULES.equals(type);
out:        for( int i = 0; i < files.length; i++ ) {
                File normalizedFile = FileUtil.normalizeFile(files[i]);
                Project p;
                if (ownedFolders.contains(normalizedFile)) {
                    Vector dataVector = rootsModel.getDataVector();
                    for (int j=0; j<dataVector.size();j++) {
                        //Sequential search in this minor case is faster than update of positions during each modification
                        File f = (File )((Vector)dataVector.elementAt(j)).elementAt(0);
                        if (f.equals(normalizedFile)) {
                            selectionModel.addSelectionInterval(j,j);
                        }
                    }
                }
                else if (this.relatedEditMediator != null && this.relatedEditMediator.ownedFolders.contains(normalizedFile)) {
                    rootsFromRelatedSourceRoots.add (normalizedFile);
                    continue;
                }
                if ((p=FileOwnerQuery.getOwner(Utilities.toURI(normalizedFile)))!=null && !p.getProjectDirectory().equals(project.getProjectDirectory())) {
                    final Sources sources = p.getLookup().lookup(Sources.class);
                    if (sources == null) {
                        rootsFromOtherProjects.add (normalizedFile);
                        continue;
                    }
                    final SourceGroup[] sourceGroups = sources.getSourceGroups(Sources.TYPE_GENERIC);
                    final SourceGroup[] javaGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
                    final SourceGroup[] groups = new SourceGroup [sourceGroups.length + javaGroups.length];
                    System.arraycopy(sourceGroups,0,groups,0,sourceGroups.length);
                    System.arraycopy(javaGroups,0,groups,sourceGroups.length,javaGroups.length);
                    final FileObject projectDirectory = p.getProjectDirectory();
                    final FileObject fileObject = FileUtil.toFileObject(normalizedFile);
                    if (projectDirectory == null || fileObject == null) {
                        rootsFromOtherProjects.add (normalizedFile);
                        continue;
                    }
                    for (int j=0; j<groups.length; j++) {
                        final FileObject sgRoot = groups[j].getRootFolder();
                        if (fileObject.equals(sgRoot)) {
                            rootsFromOtherProjects.add (normalizedFile);
                            continue out;
                        }
                        if (!projectDirectory.equals(sgRoot) && FileUtil.isParentOf(sgRoot, fileObject)) {
                            rootsFromOtherProjects.add (normalizedFile);
                            continue out;
                        }
                    }
                }
                int current = lastIndex + 1 + i;
                rootsModel.insertRow( current, new Object[] {normalizedFile, isModule
                            ? ((ModuleRoots)sourceRoots).createInitialPath()
                            : sourceRoots.createInitialDisplayName(normalizedFile)});
                selectionModel.addSelectionInterval(current,current);
                this.ownedFolders.add (normalizedFile);
            }
            if (rootsFromOtherProjects.size() > 0 || rootsFromRelatedSourceRoots.size() > 0) {
                rootsFromOtherProjects.addAll(rootsFromRelatedSourceRoots);
                showIllegalRootsDialog (rootsFromOtherProjects);
            }
            // fireActionPerformed();
        }