下面列出了javax.swing.ListSelectionModel#getMaxSelectionIndex ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Copies the selected cells in the table to the clipboard, in tab-delimited format.
*/
public void copySystemPropertiesToClipboard() {
final StringBuffer buffer = new StringBuffer( 500 );
final ListSelectionModel selection = this.table.getSelectionModel();
final int firstRow = selection.getMinSelectionIndex();
final int lastRow = selection.getMaxSelectionIndex();
if ( ( firstRow != -1 ) && ( lastRow != -1 ) ) {
for ( int r = firstRow; r <= lastRow; r++ ) {
for ( int c = 0; c < this.table.getColumnCount(); c++ ) {
buffer.append( this.table.getValueAt( r, c ) );
if ( c != 2 ) {
buffer.append( '\t' );
}
}
buffer.append( '\n' );
}
}
final StringSelection ss = new StringSelection( buffer.toString() );
final Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
cb.setContents( ss, ss );
}
public <E extends TableRowData>TableData<E> getSelectedData(){
ListSelectionModel lsm = getSelectionModel();
List<Integer> indexes = new ArrayList<Integer>();
int start = lsm.getMinSelectionIndex();
int end = lsm.getMaxSelectionIndex();
if (start >= 0){
for(int i = start; i <= end; i++){
if (lsm.isSelectedIndex(i)){
indexes.add(i);
}
}
}
return ((AstrosoftTableModel) getModel()).getData(indexes);
}
public void valueChanged(ListSelectionEvent e) {
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
int firstIndex = e.getFirstIndex();
int lastIndex = e.getLastIndex();
boolean isAdjusting = e.getValueIsAdjusting();
Log.println("Event for indexes "
+ firstIndex + " - " + lastIndex
+ "; isAdjusting is " + isAdjusting
+ "; selected indexes:");
if (lsm.isSelectionEmpty()) {
Log.println(" <none>");
} else {
// Find out which indexes are selected.
int minIndex = lsm.getMinSelectionIndex();
int maxIndex = lsm.getMaxSelectionIndex();
for (int i = minIndex; i <= maxIndex; i++) {
if (lsm.isSelectedIndex(i)) {
Log.println(" " + i);
}
}
}
Log.println("");
}
private void jRemoveItemsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRemoveItemsButtonActionPerformed
ListSelectionModel lsm = jToList.getSelectionModel();
if (lsm.isSelectionEmpty())
return;
// Multiple interval selection. Loop thru them
int minIndex=lsm.getMinSelectionIndex();
int maxIndex=lsm.getMaxSelectionIndex();
for(int i=minIndex; i<=maxIndex; i++){
if (lsm.isSelectedIndex(i)){
String objName=(String) jToList.getModel().getElementAt(i);
if (currentGroup.contains(objName))
currentGroup.remove(dSet.get(objName));
}
}
updateCurrentGroup();
// TODO add your handling code here:
}
private void jAddItemsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAddItemsButtonActionPerformed
// TODO add your handling code here:
// Get selected items from allSetMemebers and add them to currentSetMembers
ListSelectionModel lsm = jFromList.getSelectionModel();
if (lsm.isSelectionEmpty())
return;
// Multiple interval selection. Loop thru them
int minIndex=lsm.getMinSelectionIndex();
int maxIndex=lsm.getMaxSelectionIndex();
for(int i=minIndex; i<=maxIndex; i++){
if (lsm.isSelectedIndex(i)){
String objName=(String) jFromList.getModel().getElementAt(i);
if (!currentGroup.contains(objName))
currentGroup.add(dSet.get(objName));
}
}
updateCurrentGroup();
}
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting())
return;
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty())
return;
if (lsm.equals(jAllGroupsList.getSelectionModel())){
// Due to SINGLE_SELECTION mode we'll break on first match
int minIndex=lsm.getMinSelectionIndex();
int maxIndex=lsm.getMaxSelectionIndex();
for(int i=minIndex; i<=maxIndex; i++){
if (lsm.isSelectedIndex(i)){
Object obj=jAllGroupsList.getModel().getElementAt(i);
if (obj instanceof ObjectGroup){
currentGroup = (ObjectGroup) obj;
updateCurrentGroup();
}
}
}
}
}
@Override
public void valueChanged(ListSelectionEvent e) {
JList<?> list = (JList<?>) e.getSource();
ListModel<?> model = list.getModel();
ListSelectionModel listSelectionModel = list.getSelectionModel();
int minSelectionIndex = listSelectionModel.getMinSelectionIndex();
int maxSelectionIndex = listSelectionModel.getMaxSelectionIndex();
StringBuilder textBuilder = new StringBuilder();
for (int i = minSelectionIndex; i <= maxSelectionIndex; i++) {
if (listSelectionModel.isSelectedIndex(i)) {
Object elementAt = model.getElementAt(i);
formatElement(elementAt, textBuilder, i);
}
}
setText(textBuilder.toString());
}
@Override
public String toString() {
String ret = "[\n";
for (int col=0; col<listSelectionModels.size(); col++) {
ret += "\'"+col+"\'={";
ListSelectionModel lsm = getListSelectionModelAt(col);
int startRow = lsm.getMinSelectionIndex();
int endRow = lsm.getMaxSelectionIndex();
for(int row=startRow; row<endRow; row++) {
if(lsm.isSelectedIndex(row))
ret += row + ", ";
}
if(lsm.isSelectedIndex(endRow))
ret += endRow;
ret += "}\n";
}
ret += "]";
/*String ret = "";
for (int col=0; col<listSelectionModels.size(); col++) {
ret += "\'"+col+"\'={"+getListSelectionModelAt(col)+"}";
}*/
return ret;
}
private ArrayList<Integer> getSelectedPlanes() {
final ArrayList<Integer> selected = new ArrayList<>();
final ListSelectionModel lsm = planeList.getSelectionModel();
if (lsm.getMinSelectionIndex() != -1) {
for (int ix = lsm.getMinSelectionIndex(); ix <= lsm.getMaxSelectionIndex(); ix++) {
if (lsm.isSelectedIndex(ix)) {
selected.add(ix);
}
}
}
return selected;
}
public static boolean canEdit( ListSelectionModel selectionModel, DefaultListModel listModel ) {
boolean can = selectionModel.getMinSelectionIndex() == selectionModel.getMaxSelectionIndex()
&& selectionModel.getMinSelectionIndex() != -1;
if (can) {
ClassPathSupport.Item item = (ClassPathSupport.Item) listModel.get(selectionModel.getMinSelectionIndex());
can = item != null && item.canEdit();
}
return can;
}
private int[] getSelectedIndices() {
ListSelectionModel mdl = listClasses.getSelectionModel();
int min = mdl.getMinSelectionIndex();
int max = mdl.getMaxSelectionIndex();
int[] indices = new int[max - min + 1];
int ix = 0;
for (int i = mdl.getMinSelectionIndex(); i <= max; i++) {
if (mdl.isSelectedIndex(i)) {
indices[ix++] = i;
}
}
int[] result = new int[ix];
System.arraycopy(indices, 0, result, 0, ix);
return result;
}
@Override
@SuppressWarnings("unchecked")
public void valueChanged (ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
List<VCSStatusNode> selectedNodes = new ArrayList<VCSStatusNode>();
ListSelectionModel selection = table.getSelectionModel();
final TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, table);
int min = selection.getMinSelectionIndex();
if (min != -1) {
int max = selection.getMaxSelectionIndex();
for (int i = min; i <= max; i++) {
if (selection.isSelectedIndex(i)) {
int idx = table.convertRowIndexToModel(i);
selectedNodes.add(tableModel.getNode(idx));
}
}
}
final T[] nodeArray = selectedNodes.toArray((T[]) java.lang.reflect.Array.newInstance(tableModel.getItemClass(), selectedNodes.size()));
Mutex.EVENT.readAccess(new Runnable() {
@Override
public void run() {
File[] selectedFiles = new File[nodeArray.length];
for (int i = 0; i < nodeArray.length; ++i) {
selectedFiles[i] = nodeArray[i].getFile();
}
support.firePropertyChange(PROP_SELECTED_FILES, null, selectedFiles);
if (tc != null) {
tc.setActivatedNodes(nodeArray);
}
}
});
}
/**
* CRL entry selected or deselected. Enable/disable the "CRL Extensions" button accordingly (i.e. enable it if only
* one extension is selected and it has extensions.
*/
private void crlEntrySelection()
{
ListSelectionModel listSelectionModel = m_jtRevokedCerts.getSelectionModel();
if (!listSelectionModel.isSelectionEmpty()) // Entry must be selected
{
// Only one entry though
// TODO: probably no longer necessary?
if (listSelectionModel.getMinSelectionIndex() == listSelectionModel.getMaxSelectionIndex())
{
// Get serial number of entry
int iRow = listSelectionModel.getMinSelectionIndex();
BigInteger serialNumber = (BigInteger) m_jtRevokedCerts.getValueAt(iRow, 0);
// Find CRL entry using serial number
Set<? extends X509CRLEntry> revokedCertsSet = m_crl.getRevokedCertificates();
X509CRLEntry x509CrlEntry = null;
for (X509CRLEntry entry : revokedCertsSet)
{
if (serialNumber.equals(entry.getSerialNumber()))
{
x509CrlEntry = entry;
break;
}
}
if (x509CrlEntry != null && x509CrlEntry.hasExtensions())
{
m_jbCrlEntryExtensions.setEnabled(true);
return;
}
}
}
// Disable "CRL Extensions" button
m_jbCrlEntryExtensions.setEnabled(false);
}
/**
* CRL entry extensions button pressed or otherwise activated. Show the extensions of the selected CRL entry.
*/
private void crlEntryExtensionsPressed()
{
ListSelectionModel listSelectionModel = m_jtRevokedCerts.getSelectionModel();
if (!listSelectionModel.isSelectionEmpty()) // Entry must be selected
{
// Only one entry though
// TODO: probably no longer necessary?
if (listSelectionModel.getMinSelectionIndex() == listSelectionModel.getMaxSelectionIndex())
{
// Get serial number of entry
int iRow = listSelectionModel.getMinSelectionIndex();
BigInteger serialNumber = (BigInteger) m_jtRevokedCerts.getValueAt(iRow, 0);
// Find CRL entry using serial number
Set<? extends X509CRLEntry> revokedCertsSet = m_crl.getRevokedCertificates();
X509CRLEntry x509CrlEntry = null;
for (X509CRLEntry entry : revokedCertsSet)
{
if (serialNumber.equals(entry.getSerialNumber()))
{
x509CrlEntry = entry;
break;
}
}
if (x509CrlEntry != null && x509CrlEntry.hasExtensions())
{
DViewExtensions dViewExtensions =
new DViewExtensions(this, RB.getString("DViewCRL.EntryExtensions.Title"), true, x509CrlEntry);
dViewExtensions.setLocationRelativeTo(this);
SwingHelper.showAndWait(dViewExtensions);
}
}
}
}
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 );
}
}
/**
* Method remove
*/
public void remove() {
ListSelectionModel lsm = connectionTable.getSelectionModel();
int bot = lsm.getMinSelectionIndex();
int top = lsm.getMaxSelectionIndex();
for (int i = top; i >= bot; i--) {
((Connection) connections.get(i - 1)).remove();
}
if (bot > connections.size()) {
bot = connections.size();
}
lsm.setSelectionInterval(bot, bot);
}
Vector<ModelPose> getSelectedPoses() {
Vector<ModelPose> selected = new Vector<ModelPose>(2);
ListSelectionModel selectionModel=jList1.getSelectionModel();
int startIndex=selectionModel.getMinSelectionIndex();
int endIndex=selectionModel.getMaxSelectionIndex();
for(int i=startIndex; i<=endIndex;i++){
if (selectionModel.isSelectedIndex(i))
selected.add((ModelPose)posesList.elementAt(i));
}
return selected;
}
@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();
}
public static boolean canMoveDown( ListSelectionModel selectionModel, int modelSize ) {
int iMax = selectionModel.getMaxSelectionIndex();
return iMax != -1 && iMax < modelSize - 1;
}
public static boolean canMoveDown(ListSelectionModel selectionModel, int modelSize) {
int iMax = selectionModel.getMaxSelectionIndex();
return iMax != -1 && iMax < modelSize - 1;
}