Java Code Examples for javax.swing.ListSelectionModel#getMaxSelectionIndex()

The following examples show how to use javax.swing.ListSelectionModel#getMaxSelectionIndex() . 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: TableSelectionModel.java    From wandora with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: ListSelectionDocument.java    From blog with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 3
Source File: SystemPropertiesPanel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 );

}
 
Example 4
Source File: GroupEditorPanel.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
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();
            }
         }
      }
   }
}
 
Example 5
Source File: GroupEditorPanel.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
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();
   }
 
Example 6
Source File: AstrosoftTable.java    From Astrosoft with GNU General Public License v2.0 6 votes vote down vote up
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);
  }
 
Example 7
Source File: GroupEditorPanel.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
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:
   }
 
Example 8
Source File: SharedListSelectionHandler.java    From FoxTelem with GNU General Public License v3.0 6 votes vote down vote up
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("");
}
 
Example 9
Source File: TranslateGroupManuallyPopup.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
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 10
Source File: NamesAssociationDialog.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@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();
}
 
Example 11
Source File: PoseSelectionJPanel.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: Listener.java    From tcpmon with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 13
Source File: PlaneManagerTopComponent.java    From constellation with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: DViewCRL.java    From portecle with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
			}
		}
	}
}
 
Example 15
Source File: DViewCRL.java    From portecle with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 16
Source File: VCSStatusTable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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);
            }
        }
    });
}
 
Example 17
Source File: ClassNameList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 18
Source File: ClassPathUiSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 19
Source File: PathUiSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static boolean canMoveDown(ListSelectionModel selectionModel, int modelSize) {
    int iMax = selectionModel.getMaxSelectionIndex();
    return iMax != -1 && iMax < modelSize - 1;
}
 
Example 20
Source File: ClassPathUiSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static boolean canMoveDown( ListSelectionModel selectionModel, int modelSize ) {
    int iMax = selectionModel.getMaxSelectionIndex();
    return iMax != -1 && iMax < modelSize - 1;         
}