Java Code Examples for javax.swing.ListSelectionModel#addSelectionInterval()
The following examples show how to use
javax.swing.ListSelectionModel#addSelectionInterval() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwingUtilities2.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Set the lead and anchor without affecting selection. */ public static void setLeadAnchorWithoutSelection(ListSelectionModel model, int lead, int anchor) { if (anchor == -1) { anchor = lead; } if (lead == -1) { model.setAnchorSelectionIndex(-1); model.setLeadSelectionIndex(-1); } else { if (model.isSelectedIndex(lead)) { model.addSelectionInterval(lead, lead); } else { model.removeSelectionInterval(lead, lead); } model.setAnchorSelectionIndex(anchor); } }
Example 2
Source File: AnySelectionTable.java From wandora with GNU General Public License v3.0 | 6 votes |
public void invertSelection() { if(tableSelectionModel != null) { int colCount = this.getColumnCount(); int rowCount = this.getRowCount(); for(int c=0; c<colCount; c++) { ListSelectionModel columnSelectionModel = tableSelectionModel.getListSelectionModelAt(c); if(columnSelectionModel != null) { for(int r=0; r<rowCount; r++) { if(columnSelectionModel.isSelectedIndex(r)) { columnSelectionModel.removeSelectionInterval(r, r); } else { columnSelectionModel.addSelectionInterval(r, r); } } } } } this.repaint(); }
Example 3
Source File: MListTable.java From javamelody with Apache License 2.0 | 6 votes |
/** * Définit la liste d'objets sélectionnés. * * @param newSelectedList * List * @see #getSelectedList */ public void setSelectedList(final List<T> newSelectedList) { clearSelection(); if (newSelectedList == null || newSelectedList.isEmpty()) { return; } final ListSelectionModel listSelectionModel = getSelectionModel(); final List<T> list = getList(); for (final T object : newSelectedList) { int rowIndex = list.indexOf(object); rowIndex = convertRowIndexToView(rowIndex); if (rowIndex > -1) { listSelectionModel.addSelectionInterval(rowIndex, rowIndex); } } // scrolle pour afficher la première ligne sélectionnée final int firstIndex = getSelectionModel().getMinSelectionIndex(); final Rectangle cellRect = getCellRect(firstIndex, 0, true); scrollRectToVisible(cellRect); }
Example 4
Source File: ListParameterComponent.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
public void initialize() throws ReportDataFactoryException { adjustingToExternalInput = true; try { final KeyedComboBoxModel keyedComboBoxModel = DefaultParameterComponentFactory.createModel( listParameter, parameterContext ); list.setModel( keyedComboBoxModel ); final ListSelectionModel selectionModel = list.getSelectionModel(); final Object value = updateContext.getParameterValue( listParameter.getName() ); final HashSet keylist = getNormalizedSet( value ); selectionModel.setValueIsAdjusting( true ); list.clearSelection(); final int size = keyedComboBoxModel.getSize(); for ( int i = 0; i < size; i++ ) { final Object key = keyedComboBoxModel.getKeyAt( i ); if ( isSafeMatch( key, keylist ) ) { selectionModel.addSelectionInterval( i, i ); } } selectionModel.setValueIsAdjusting( false ); } finally { adjustingToExternalInput = false; } }
Example 5
Source File: AnySelectionTable.java From wandora with GNU General Public License v3.0 | 5 votes |
public void selectArea(int c1, int r1, int c2, int r2) { if(tableSelectionModel != null) { int colCount = this.getColumnCount(); int rowCount = this.getRowCount(); c1 = Math.min(c1, colCount); c2 = Math.min(c2, colCount); r1 = Math.min(r1, rowCount); r2 = Math.min(r2, rowCount); int cs = c1; int ce = c2; if(c2 < c1) { cs = c2; ce = c1; } int rs = r1; int re = r2; if(r2 < r1) { rs = r2; re = r1; } for(int c=cs; c<=ce; c++) { ListSelectionModel columnSelectionModel = tableSelectionModel.getListSelectionModelAt(c); if(columnSelectionModel != null) { columnSelectionModel.addSelectionInterval(rs, re); } } } this.repaint(); }
Example 6
Source File: AnySelectionTable.java From wandora with GNU General Public License v3.0 | 5 votes |
public void selectCell(int c, int r) { //System.out.println("Selecting c,r == "+c+","+r); if(tableSelectionModel != null) { int colCount = this.getColumnCount(); int rowCount = this.getRowCount(); if(c >= 0 && c < colCount && r >= 0 && r < rowCount) { ListSelectionModel columnSelectionModel = tableSelectionModel.getListSelectionModelAt(c); if(columnSelectionModel != null) { //System.out.println("Selecting c,r == "+c+","+r); columnSelectionModel.addSelectionInterval(r, r); } } } this.repaint(); }
Example 7
Source File: AnySelectionTable.java From wandora with GNU General Public License v3.0 | 5 votes |
public void selectRows() { if(tableSelectionModel != null) { int colCount = this.getColumnCount(); int rowCount = this.getRowCount(); ListSelectionModel columnSelectionModel = null; for(int r=0; r<rowCount; r++) { boolean selectRow = false; for(int c=0; c<colCount; c++) { columnSelectionModel = tableSelectionModel.getListSelectionModelAt(c); if(columnSelectionModel != null) { if(columnSelectionModel.isSelectedIndex(r)) { selectRow = true; break; } } } if(selectRow) { for(int c=0; c<colCount; c++) { columnSelectionModel = tableSelectionModel.getListSelectionModelAt(c); if(columnSelectionModel != null) { columnSelectionModel.addSelectionInterval(r, r); } } } } } this.repaint(); }
Example 8
Source File: AnySelectionTable.java From wandora with GNU General Public License v3.0 | 5 votes |
public void selectRow(int row) { int colCount = this.getColumnCount(); int rowCount = this.getRowCount(); if(tableSelectionModel != null && row < rowCount) { ListSelectionModel columnSelectionModel = null; for(int c=0; c<colCount; c++) { columnSelectionModel = tableSelectionModel.getListSelectionModelAt(c); if(columnSelectionModel != null) { columnSelectionModel.addSelectionInterval(row, row); } } } this.repaint(); }
Example 9
Source File: AnySelectionTable.java From wandora with GNU General Public License v3.0 | 5 votes |
public void selectColumns() { if(tableSelectionModel != null) { int colCount = this.getColumnCount(); int rowCount = this.getRowCount(); for(int c=0; c<colCount; c++) { ListSelectionModel columnSelectionModel = tableSelectionModel.getListSelectionModelAt(c); if(columnSelectionModel != null) { if(!columnSelectionModel.isSelectionEmpty()) { columnSelectionModel.addSelectionInterval(0, rowCount-1); } } } } this.repaint(); }
Example 10
Source File: AnySelectionTable.java From wandora with GNU General Public License v3.0 | 5 votes |
public void selectColumn(int column) { int rowCount = this.getRowCount(); int colCount = this.getColumnCount(); if(tableSelectionModel != null && column < colCount) { ListSelectionModel columnSelectionModel = tableSelectionModel.getListSelectionModelAt(column); if(columnSelectionModel != null) { columnSelectionModel.addSelectionInterval(0, rowCount-1); } } this.repaint(); }
Example 11
Source File: AnySelectionTable.java From wandora with GNU General Public License v3.0 | 5 votes |
@Override public void selectAll() { if(tableSelectionModel != null) { int colCount = this.getColumnCount(); int rowCount = this.getRowCount(); for(int c=0; c<colCount; c++) { ListSelectionModel columnSelectionModel = tableSelectionModel.getListSelectionModelAt(c); if(columnSelectionModel != null) { columnSelectionModel.addSelectionInterval(0, rowCount); } } } this.repaint(); }
Example 12
Source File: KseFrame.java From keystore-explorer with GNU General Public License v3.0 | 5 votes |
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); } } }
Example 13
Source File: TranslateGroupManuallyPopup.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
public static void reSelect(final ListSelectionModel lsm) { final int maxSelectionIndex = lsm.getMaxSelectionIndex(); for (int i = 0; i <= maxSelectionIndex; i++) if (lsm.isSelectedIndex( i )) { lsm.removeSelectionInterval( i, i ); lsm.addSelectionInterval( i, i ); } }
Example 14
Source File: SortByPanel.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * 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); } }
Example 15
Source File: RowTreeTable.java From ramus with GNU General Public License v3.0 | 5 votes |
public void setSelectedRows(int[] rows, final boolean scrollToSel) { final ListSelectionModel model = getSelectionModel(); int i = -1; for (int j : rows) { i = j; model.addSelectionInterval(i, i); } if (scrollToSel) scrollRowToVisible(i); }
Example 16
Source File: OptionsPanel.java From netbeans with Apache License 2.0 | 5 votes |
private void selectRows(int[] selectedRows, int delta) { ListSelectionModel listSelectionModel = mappingsTable.getSelectionModel(); listSelectionModel.clearSelection(); for (int selectedRow : selectedRows) { listSelectionModel.addSelectionInterval(selectedRow + delta, selectedRow + delta); } }
Example 17
Source File: VCSStatusTable.java From netbeans with Apache License 2.0 | 5 votes |
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); }
Example 18
Source File: OutlineView.java From netbeans with Apache License 2.0 | 5 votes |
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); }
Example 19
Source File: TableSelectionModel.java From wandora with GNU General Public License v3.0 | 4 votes |
/** * Forwards the request to the ListSelectionModel * at the specified column. */ public void addSelection(int row, int column) { ListSelectionModel lsm = getListSelectionModelAt(column); lsm.addSelectionInterval(row, row); }
Example 20
Source File: SourceRootsUi.java From netbeans with Apache License 2.0 | 4 votes |
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(); }