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

The following examples show how to use javax.swing.ListSelectionModel#getMinSelectionIndex() . 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: HistView.java    From rest-client 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;
    }

    int row = lsm.getMinSelectionIndex();
    String key = this.tabMdl.getRowKey(row);
    HttpHist hist = RESTCache.getHists().get(key);
    if (null == hist)
    {
        return;
    }

    RESTView.getView().getReqView().setReqView(hist.getReq());
    RESTView.getView().getRspView().setRspView(hist.getRsp());
}
 
Example 2
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 3
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 4
Source File: SystemPropertiesPanel.java    From ccu-historian with GNU General Public License v3.0 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();
    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 5
Source File: UpDownToggler.java    From GpsPrune with GNU General Public License v2.0 6 votes vote down vote up
/**
 * list selection has changed
 */
public void valueChanged(ListSelectionEvent e)
{
	ListSelectionModel lsm = (ListSelectionModel) e.getSource();
	if (lsm.isSelectionEmpty())
	{
		// no rows are selected
		_upButton.setEnabled(false);
		_downButton.setEnabled(false);
	}
	else
	{
		// single row is selected
		int row = lsm.getMinSelectionIndex();
		_upButton.setEnabled(row > 0);
		_downButton.setEnabled(row >= 0 && row < _maxIndex);
	}
}
 
Example 6
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 7
Source File: ContinuousLoadPanel.java    From openAGV with Apache License 2.0 5 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e) {
  if (e.getSource() == table.getSelectionModel() && table.getRowSelectionAllowed()) {
    ListSelectionModel model = (ListSelectionModel) e.getSource();
    int row = model.getMinSelectionIndex();
    buildTableModels(row);
    updateElementStates();
  }
}
 
Example 8
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 9
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 10
Source File: DetailPanel.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** @see ListSelectionListener **/
public void valueChanged(ListSelectionEvent aEvent) {
    //Ignore extra messages.
    if (aEvent.getValueIsAdjusting()) {
        return;
    }

    final ListSelectionModel lsm = (ListSelectionModel) aEvent.getSource();
    if (lsm.isSelectionEmpty()) {
        mDetails.setText("Nothing selected");
    } else {
        final int selectedRow = lsm.getMinSelectionIndex();
        final EventDetails e = mModel.getEventDetails(selectedRow);
        final Object[] args =
        {
            new Date(e.getTimeStamp()),
            e.getPriority(),
            escape(e.getThreadName()),
            escape(e.getNDC()),
            escape(e.getCategoryName()),
            escape(e.getLocationDetails()),
            escape(e.getMessage()),
            escape(getThrowableStrRep(e))
        };
        mDetails.setText(FORMATTER.format(args));
        mDetails.setCaretPosition(0);
    }
}
 
Example 11
Source File: AnnotationSettings.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void onDownClick() {
    ListSelectionModel listSelectionModel = getSelectionModel();
    int r = listSelectionModel.getMinSelectionIndex();                
    DefaultTableModel model = getModel();
    if(r > -1 && r < model.getRowCount() - 1) {     
       int rNew = r + 1;
       model.moveRow(r, r, rNew) ;
       listSelectionModel.setSelectionInterval(rNew, rNew);
    }        
}
 
Example 12
Source File: AnnotationSettings.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void onUpClick() {
    ListSelectionModel listSelectionModel = getSelectionModel();
    int r = listSelectionModel.getMinSelectionIndex();        
    if(r > 0) {
        DefaultTableModel model = getModel();
        int rNew = r - 1;
        model.moveRow(r, r, rNew) ;
        listSelectionModel.setSelectionInterval(rNew, rNew);
    }
}
 
Example 13
Source File: TubesProjectConfigPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected int getSelectedRow(boolean client) {
    JTable table = client ? tubeTableClient : tubeTableService;
    ListSelectionModel lsm = (ListSelectionModel) table.getSelectionModel();
    if (lsm.isSelectionEmpty()) {
        return -1;
    } else {
        return lsm.getMinSelectionIndex();
    }
}
 
Example 14
Source File: MessageHandlerPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private int getSelectedRow() {
    ListSelectionModel lsm = (ListSelectionModel) handlerTable.getSelectionModel();
    if (lsm.isSelectionEmpty()) {
        return -1;
    } else {
        return lsm.getMinSelectionIndex();
    }
}
 
Example 15
Source File: OptionsPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private int getSelectedRow() {
    ListSelectionModel lsm = (ListSelectionModel) optionsTable.getSelectionModel();
    if (lsm.isSelectionEmpty()) {
        return -1;
    } else {
        return lsm.getMinSelectionIndex();
    }
}
 
Example 16
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 17
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 18
Source File: PathUiSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static boolean canMoveUp(ListSelectionModel selectionModel) {
    return selectionModel.getMinSelectionIndex() > 0;
}
 
Example 19
Source File: ClassPathUiSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static boolean canMoveUp( ListSelectionModel selectionModel ) {        
    return selectionModel.getMinSelectionIndex() > 0;
}
 
Example 20
Source File: EditVariablePanel.java    From KEEL with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e) {
    // If cell selection is enabled, both column and column change events are fired
    if (!e.getValueIsAdjusting() && e.getSource() == jTable1.getSelectionModel() && jTable1.getRowSelectionAllowed() && jTable1.getColumnSelectionAllowed()) {
        // Row selection changed
        ListSelectionModel csm = (ListSelectionModel) e.getSource();
        if (!csm.isSelectionEmpty()) {
            deletejButton.setEnabled(true);
            int row = csm.getMinSelectionIndex();

            if (row >= 0) {
                if (editDataPanel.getData().getAttributeTypeIndex(row).equalsIgnoreCase("nominal")) {
                    nominalValuejLabel.setEnabled(true);
                    nominalValuejTextField.setEnabled(true);
                    rangeNominaljComboBox.setEnabled(true);
                    addNominalValuejButton.setEnabled(true);
                    deleteNominalValuejButton.setEnabled(true);

                    valueRangejLabel.setEnabled(false);
                    minjTextField.setEnabled(false);
                    comajLabel.setEnabled(false);
                    maxjTextField.setEnabled(false);
                    rightBracketjLabel.setEnabled(false);
                    leftBracketjLabel.setEnabled(false);
                    changejButton.setEnabled(false);

                    rangeNominaljComboBox.removeAllItems();
                    for (int i = 0; i < editDataPanel.getData().getRange(row).size(); i++) {
                        rangeNominaljComboBox.addItem(new String(editDataPanel.getData().getRangesEnum(row, i)));
                    }
                } else {
                    nominalValuejLabel.setEnabled(false);
                    nominalValuejTextField.setEnabled(false);
                    rangeNominaljComboBox.setEnabled(false);
                    addNominalValuejButton.setEnabled(false);
                    deleteNominalValuejButton.setEnabled(false);

                    valueRangejLabel.setEnabled(true);
                    minjTextField.setEnabled(true);
                    comajLabel.setEnabled(true);
                    maxjTextField.setEnabled(true);
                    rightBracketjLabel.setEnabled(true);
                    leftBracketjLabel.setEnabled(true);
                    changejButton.setEnabled(true);

                    if (editDataPanel.getData().getAttributeTypeIndex(row).equalsIgnoreCase("integer")) {
                        minjTextField.setText(editDataPanel.getData().getRangesInt(row, 0).toString());
                        maxjTextField.setText(editDataPanel.getData().getRangesInt(row, 1).toString());
                    } else {
                        minjTextField.setText(editDataPanel.getData().getRangesReal(row, 0).toString());
                        maxjTextField.setText(editDataPanel.getData().getRangesReal(row, 1).toString());
                    }
                }
            }
        } else {
        }
    } else // e.getValueIsAdjusting() --> true. Se estan metiendo datos en una variable nueva
    {
        //
    }
}