下面列出了javax.swing.ListSelectionModel#setValueIsAdjusting ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** 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);
}
}
}
@Override
public void valueChanged(ListSelectionEvent e) {
// get list selection model
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
// set value-adjusting to true, so we don't fire multiple value-changed events...
lsm.setValueIsAdjusting(true);
// check for any values
if (null == selectedAuthors || selectedAuthors.isEmpty()) {
jButtonApply.setEnabled(false);
return;
}
// en- or disable apply-button
if (!jRadioButtonManualBibkey.isSelected()) {
// else when file-option is selected, en- or disable depending on table-selection
jButtonApply.setEnabled(jTablePreview.getSelectedRow() != -1);
}
}
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;
}
}
/** Popup a dialog that lets the user add a new principal to this mapping.
* The new name will not be allowed to match any existing name. The
* new item will be preselected afterwards. The new name will either come
* from the existing master list or will be a new name and automatically added
* to the master list.
*/
private void handleAddPrincipalAction() {
ListSelectionModel selectionModel = jTblPrincipals.getSelectionModel();
try {
selectionModel.setValueIsAdjusting(true);
SecurityAddPrincipalPanel.addPrincipalName(this, principalTableModel, version);
int index = principalTableModel.getRowCount()-1;
selectionModel.setSelectionInterval(index, index);
} finally {
selectionModel.setValueIsAdjusting(false);
}
}
/** Popup a dialog that lets the user edit the selected entry. The changed
* name will not be allowed to match any existing name. The item will
* remain selected once the action is completed.
*/
private void handleEditPrincipalAction() {
int [] selectedIndices = jTblPrincipals.getSelectedRows();
if(selectedIndices.length > 0) {
ListSelectionModel selectionModel = jTblPrincipals.getSelectionModel();
try {
PrincipalNameMapping entry = principalTableModel.getElementAt(selectedIndices[0]);
SecurityEditPrincipalPanel.editPrincipalName(this, entry, principalTableModel, version);
selectionModel.setSelectionInterval(selectedIndices[0], selectedIndices[0]);
} finally {
selectionModel.setValueIsAdjusting(false);
}
}
}
/** Popup a dialog that lets the user add a new entry to the specifed master
* list. The new name will not be allowed to match any existing name. The
* new item will be preselected afterwards. The new name will either come
* from the existing master list or will be a new name and automatically added
* to the master list.
*/
private void handleAddGroupAction() {
ListSelectionModel selectionModel = jTblGroups.getSelectionModel();
try {
selectionModel.setValueIsAdjusting(true);
SecurityAddGroupPanel.addGroupName(this, groupTableModel);
int index = groupTableModel.getRowCount()-1;
selectionModel.setSelectionInterval(index, index);
} finally {
selectionModel.setValueIsAdjusting(false);
}
}
/** Popup a dialog that lets the user edit the selected entry. The changed
* name will not be allowed to match any existing name. The item will
* remain selected once the action is completed.
*/
private void handleEditGroupAction() {
int [] selectedIndices = jTblGroups.getSelectedRows();
if(selectedIndices.length > 0) {
ListSelectionModel selectionModel = jTblGroups.getSelectionModel();
try {
String entry = groupTableModel.getElementAt(selectedIndices[0]);
SecurityEditGroupPanel.editGroupName(this, entry, groupTableModel);
selectionModel.setSelectionInterval(selectedIndices[0], selectedIndices[0]);
} finally {
selectionModel.setValueIsAdjusting(false);
}
}
}
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);
}
@Override
public void valueChanged(ListSelectionEvent e) {
// if we have an update, don't react on selection changes
if (tableUpdateActive) return;
// get list selection model
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
// set value-adjusting to true, so we don't fire multiple value-changed events...
lsm.setValueIsAdjusting(true);
if (jTableResults==table) updateDisplay();
}
private void updateSelectedLines(int[] currentLineSelections,
int currentLeadRow, int currentAnchorRow,
int[] newLineSelections,
int newLeadRow, int newAnchorRow) {
//System.err.println("updateSelectedLines("+Arrays.toString(currentLineSelections)+" => "+
// Arrays.toString(newLineSelections));
boolean wasAutoScroll = getAutoscrolls();
setAutoscrolls(false);
DefaultListSelectionModel rsm = (DefaultListSelectionModel) getSelectionModel();
rsm.setValueIsAdjusting(true);
ListSelectionModel csm = getColumnModel().getSelectionModel();
csm.setValueIsAdjusting(true);
//System.err.println("Orig lead and anchor selection indexes: "+rsm.getLeadSelectionIndex()+", "+rsm.getAnchorSelectionIndex());
//int leadRow = convertRowIndexToView(selectedRows.leadInModel);
//int anchorRow = convertRowIndexToView(selectedRows.anchorInModel);
int i = 0;
int j = 0;
while (i < currentLineSelections.length || j < newLineSelections.length) {
int selected = (i < currentLineSelections.length) ? currentLineSelections[i] : Integer.MAX_VALUE;
int toSelect = (j < newLineSelections.length) ? newLineSelections[j] : Integer.MAX_VALUE;
if (selected == toSelect) {
i++;
j++;
continue;
}
if (selected < toSelect) {
if (selected > -1) {
int selected2 = selected;
while ((i + 1) < currentLineSelections.length && currentLineSelections[i+1] == (selected2 + 1) && (selected2 + 1) < toSelect) {
selected2++;
i++;
}
rsm.removeSelectionInterval(selected, selected2);
//System.err.println(" removing selection ("+selected+", "+selected2+")");
}
i++;
} else {
if (toSelect > -1) {
int toSelect2 = toSelect;
while ((j + 1) < newLineSelections.length && newLineSelections[j + 1] == (toSelect2 + 1) && (toSelect2 + 1) < selected) {
toSelect2++;
j++;
}
rsm.addSelectionInterval(toSelect, toSelect2);
//System.err.println(" adding selection ("+toSelect+", "+toSelect2+")");
}
j++;
}
}
if (newAnchorRow != currentAnchorRow) {
//System.err.println(" Setting anchor selection index: "+anchorRow);
rsm.setAnchorSelectionIndex(newAnchorRow);
}
if (newLeadRow != currentLeadRow) {
if (newLeadRow == -1) {
for (int k = 0; k < newLineSelections.length; k++) {
if (newLineSelections[k] == -1) {
while((k + 1) < newLineSelections.length && newLineSelections[k+1] == -1) {
k++;
}
if ((k + 1) < newLineSelections.length) {
newLeadRow = newLineSelections[k+1];
break;
}
if (k > 0) {
newLeadRow = newLineSelections[0];
break;
}
}
}
}
//System.err.println(" Setting lead selection index: "+leadRow);
// DO NOT CALL setLeadSelectionIndex() as it screws up selection!
rsm.moveLeadSelectionIndex(newLeadRow);
}
rsm.setValueIsAdjusting(false);
csm.setValueIsAdjusting(false);
if (wasAutoScroll) {
setAutoscrolls(true);
}
}