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

The following examples show how to use javax.swing.ListSelectionModel#isSelectionEmpty() . 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: 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 3
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 4
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 5
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 6
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 7
Source File: TopicGrid.java    From wandora with GNU General Public License v3.0 6 votes vote down vote up
public ArrayList<int[]> getSelectedCells() {
    ArrayList<int[]> selected = new ArrayList();
    
    TableSelectionModel selection = getTableSelectionModel();
    int colCount = this.getColumnCount();
    int rowCount = this.getRowCount();
    //System.out.println("----");
    for(int c=0; c<colCount; c++) {
        int cc = convertColumnIndexToModel(c);
        ListSelectionModel columnSelectionModel = selection.getListSelectionModelAt(cc);
        if(columnSelectionModel != null && !columnSelectionModel.isSelectionEmpty()) {
            for(int r=0; r<rowCount; r++) {
                if(columnSelectionModel.isSelectedIndex(r)) {
                    selected.add( new int[] { r, c } );
                    //System.out.println("found cell "+cc+","+r);
                }
            }
        }
    }
    return selected;
}
 
Example 8
Source File: InitParamPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void setEnabled() {
    boolean enable = deployData.makeEntry() || Utilities.isJavaEE6Plus(wizard);

    jLinitparams.setEnabled(enable);
    jBnew.setEnabled(enable);
    if (enable) {
        ListSelectionModel lsm = table.getSelectionModel();
        if (lsm.isSelectionEmpty()) {
            jBdelete.setEnabled(false);
            jBedit.setEnabled(false);
        } else {
            jBdelete.setEnabled(true);
            jBedit.setEnabled(true);
        }
    } else {
        jBdelete.setEnabled(false);
        jBedit.setEnabled(false);
    }
    table.setEditable(enable ? Editable.BOTH : Editable.NEITHER);
}
 
Example 9
Source File: SelectionInfo.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void doTableSelection(Wandora admin, SITable table) {
    setDefaultLogger();
    setLogTitle("Subject identifier table selection info");
    int rowsCounter = table.getRowCount();
    int colsCounter = table.getColumnCount();
    //int rowSelectionCounter = 0;
    //int colSelectionCounter = 0;
    int cellSelectionCounter = 0;
    
    TableSelectionModel selection = table.getTableSelectionModel();
    for(int c=0; c<colsCounter; c++) {
        ListSelectionModel columnSelectionModel = selection.getListSelectionModelAt(c);
        if(columnSelectionModel != null && !columnSelectionModel.isSelectionEmpty()) {
            for(int r=0; r<rowsCounter; r++) {
                if(columnSelectionModel.isSelectedIndex(r)) {
                    cellSelectionCounter++;
                }
            }
        }
    }
    String message = "Subject identifier table contains " + rowsCounter + " rows";
    if(colsCounter > 1) message += " and " + (rowsCounter*colsCounter) + " cells.";
    else message += ".";
    if(cellSelectionCounter == 1) message += "\nSelection contains " + cellSelectionCounter + " cell.";
    if(cellSelectionCounter > 1) message += "\nSelection contains " + cellSelectionCounter + " cells.";

    log(message);
    setState(WandoraToolLogger.WAIT);
}
 
Example 10
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 11
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 12
Source File: PlacemarkManagerTopComponent.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void writePlacemarkDataTableText(final Writer writer) {

        String[] additionalColumnNames = placemarkTableModel.getAdditionalColumnNames();

        String[] standardColumnNames = placemarkTableModel.getStandardColumnNames();
        int columnCount = placemarkTableModel.getColumnCount();
        List<Placemark> placemarkList = new ArrayList<>();
        List<Object[]> valueList = new ArrayList<>();
        for (int sortedRow = 0; sortedRow < placemarkTable.getRowCount(); ++sortedRow) {
            ListSelectionModel selectionModel = placemarkTable.getSelectionModel();
            if (selectionModel.isSelectionEmpty() || selectionModel.isSelectedIndex(sortedRow)) {
                final int modelRow = placemarkTable.convertRowIndexToModel(sortedRow);
                placemarkList.add(placemarkTableModel.getPlacemarkAt(modelRow));
                Object[] values = new Object[columnCount];
                for (int col = 0; col < columnCount; col++) {
                    values[col] = placemarkTableModel.getValueAt(modelRow, col);
                }
                valueList.add(values);
            }
        }

        PlacemarkIO.writePlacemarksWithAdditionalData(writer,
                                                      placemarkDescriptor.getRoleLabel(),
                                                      product.getName(),
                                                      placemarkList,
                                                      valueList,
                                                      standardColumnNames,
                                                      additionalColumnNames);
    }
 
Example 13
Source File: TableSelectionModel.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
/**
* Forwards the request to the ListSelectionModel
* at the specified column.
*/
public void setLeadSelectionIndex(int row, int column) {
    ListSelectionModel lsm = getListSelectionModelAt(column);
    if (lsm.isSelectionEmpty())
        lsm.setSelectionInterval(row, row);
    else
        //calling that method throws an IndexOutOfBoundsException when selection is empty (?, JDK 1.1.8, Swing 1.1)
        lsm.setLeadSelectionIndex(row);
}
 
Example 14
Source File: SelectWorkItemsModel.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
public String getComment() {
    final ListSelectionModel selectionModel = getTableSelectionModel();
    if (!selectionModel.isSelectionEmpty()) {
        final StringBuilder sb = new StringBuilder();
        String separator = "";
        for (final WorkItem item : tableModel.getSelectedWorkItems()) {
            sb.append(separator);
            sb.append(WorkItemHelper.getWorkItemCommitMessage(item));
            separator = "\n";
        }
        return sb.toString();
    }

    return StringUtils.EMPTY;
}
 
Example 15
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 16
Source File: MappingPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void setEnabled(boolean enable) {
    jLtableheader.setEnabled(enable);
    jBnew.setEnabled(enable);

    if (!enable) {
        jBedit.setEnabled(false);
        jBdelete.setEnabled(false);
        jBup.setEnabled(false);
        jBdown.setEnabled(false);
        return;
    }

    ListSelectionModel lsm = table.getSelectionModel();
    if (lsm.isSelectionEmpty()) {
        // disable the relevant buttons
        jBdelete.setEnabled(false);
        jBedit.setEnabled(false);
        jBdown.setEnabled(false);
        jBup.setEnabled(false);
    } else {
        // We only allow single selections
        int selectedRow = lsm.getMinSelectionIndex();
        String str = (String) (table.getValueAt(selectedRow, 0));
        boolean canEdit = str.equals(deployData.getName());
        jBdelete.setEnabled(canEdit);
        jBedit.setEnabled(canEdit);
        int numRows = table.getRowCount();
        if (selectedRow > 0) {
            jBup.setEnabled(true);
        } else {
            jBup.setEnabled(false);
        }
        if (selectedRow < numRows - 1) {
            jBdown.setEnabled(true);
        } else {
            jBdown.setEnabled(false);
        }
    }
}
 
Example 17
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 18
Source File: GroupEditorPanel.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
private void jDeleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jDeleteButtonActionPerformed
   //jAllGroupsList.r
   ListSelectionModel lsm = jAllGroupsList.getSelectionModel();
   if (lsm.isSelectionEmpty())
      return;
   int minIndex=lsm.getMinSelectionIndex();
   int maxIndex=lsm.getMaxSelectionIndex();
   //remove listeners temporarily
   lsm.removeListSelectionListener(this);
   for(int i=minIndex; i<=maxIndex; i++){
      if (lsm.isSelectedIndex(i)){
         Object obj=jAllGroupsList.getModel().getElementAt(i);
         if (obj instanceof ObjectGroup){
            ObjectGroup groupToDelete = (ObjectGroup) obj;
            // Find an alternate group and make it current
            if (jAllGroupsList.getModel().getSize()==1){
               throw new UnsupportedOperationException("Not yet implemented");
            }
            else {
               currentGroup=(ObjectGroup) jAllGroupsList.getModel().getElementAt(0);
               dSet.removeGroup(groupToDelete.getName());
            }
            
         }
      }
   }
   updateGroupsList();
   // Restore listeners
   lsm.addListSelectionListener(this);

}
 
Example 19
Source File: SelectionInfo.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void doGridSelection(Wandora admin, TopicGrid grid) {
    setDefaultLogger();
    setLogTitle("Grid selection info");
    int rowsCounter = grid.getRowCount();
    int colsCounter = grid.getColumnCount();
    //int rowSelectionCounter = 0;
    //int colSelectionCounter = 0;
    int cellSelectionCounter = 0;
    
    TableSelectionModel selection = grid.getTableSelectionModel();
    for(int c=0; c<colsCounter; c++) {
        ListSelectionModel columnSelectionModel = selection.getListSelectionModelAt(c);
        if(columnSelectionModel != null && !columnSelectionModel.isSelectionEmpty()) {
            for(int r=0; r<rowsCounter; r++) {
                if(columnSelectionModel.isSelectedIndex(r)) {
                    cellSelectionCounter++;
                }
            }
        }
    }
    String message =  "Grid contains " + rowsCounter + " rows";
    if(colsCounter > 1) message += " and " + (rowsCounter*colsCounter) + " cells.";
    else message += ".";
    if(cellSelectionCounter == 1) message += "\nSelection contains " + cellSelectionCounter + " cell.";
    if(cellSelectionCounter > 1) message += "\nSelection contains " + cellSelectionCounter + " cells.";

    log(message);
    setState(WandoraToolLogger.WAIT);
}
 
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
    {
        //
    }
}