Java Code Examples for javax.swing.event.ListSelectionEvent#getLastIndex()

The following examples show how to use javax.swing.event.ListSelectionEvent#getLastIndex() . 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: 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 2
Source File: JSeparatorTable.java    From jeveassets with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void valueChanged(final ListSelectionEvent e) {
	if (e.getValueIsAdjusting()) {
		for (int row = e.getFirstIndex(); row <= e.getLastIndex(); row++) {
			if (this.isRowSelected(row)) {
				if (!selectedRows.contains(row)) {
					selectedRows.add(row);
				}
			} else {
				if (selectedRows.contains(row)) {
					selectedRows.remove(selectedRows.indexOf(row));
				}
			}
		}
	}
	if (!selectedRows.isEmpty()
			&& selectedRows.get(selectedRows.size() - 1) < getEventTableModel().getRowCount()
			&& (getEventTableModel().getElementAt(selectedRows.get(selectedRows.size() - 1)) instanceof SeparatorList.Separator)) {
		setAutoscrolls(false);
	} else {
		setAutoscrolls(true);
	}
	super.valueChanged(e);
}
 
Example 3
Source File: RevisionListPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void valueChanged (ListSelectionEvent e) {
    if (!e.getValueIsAdjusting() && e.getLastIndex() > -1 && e.getFirstIndex() > -1) {
        reselected = true;
        selectedRevision = null;
    }
}
 
Example 4
Source File: ListSelectionListenerAction.java    From jsonde with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private int getSelectedId(ListSelectionModel mod, ListSelectionEvent e) {
    int result = -1;
    for (int i = e.getFirstIndex(); i <= e.getLastIndex(); i++) {
        if (mod.isSelectedIndex(i)) {
            result = i;
            break;
        }
    }
    return result;
}
 
Example 5
Source File: VariableSelectionPane.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e) {
    if (!e.getValueIsAdjusting()) {
        final CheckBoxListSelectionModel selectionModel = variableList.getCheckBoxListSelectionModel();
        for (int i = e.getFirstIndex(); i <= e.getLastIndex(); i++) {
            model.setSelectedVariableAt(i, selectionModel.isSelectedIndex(i));
        }
    }
}
 
Example 6
Source File: WeaponPanel.java    From megamek with GNU General Public License v2.0 4 votes vote down vote up
public void valueChanged(ListSelectionEvent event) {
    if (event.getValueIsAdjusting()) {
        return;
    }
    if (event.getSource().equals(weaponList)) {
        displaySelected();
        
        // Can't do anything if ClientGUI is null
        if (unitDisplay.getClientGUI() == null) {
            return;
        }
        
        JComponent currPanel = unitDisplay.getClientGUI().getCurrentPanel();
        // When in the Firing Phase, update the targeting information.
        if (currPanel instanceof FiringDisplay) {
            FiringDisplay firingDisplay = (FiringDisplay)currPanel;

            Mounted mounted = null;
            WeaponListModel weaponModel = (WeaponListModel) weaponList
                    .getModel();
            if (weaponList.getSelectedIndex() != -1) {
                mounted = weaponModel.getWeaponAt(weaponList
                        .getSelectedIndex());
            }
            Mounted prevMounted = null;
            if ((event.getLastIndex() != -1) 
                    && (event.getLastIndex() < weaponModel.getSize())) {
                prevMounted = weaponModel.getWeaponAt(event.getLastIndex());
            }
            // Some weapons have a specific target, which gets handled
            // in the target method
            if (mounted != null
                    && mounted.getType().hasFlag(WeaponType.F_VGL)) {
                // Store previous target, if it's a weapon that doesn't 
                // have a forced target
                if ((prevMounted != null)
                        && !prevMounted.getType().hasFlag(WeaponType.F_VGL)) {
                    prevTarget = firingDisplay.getTarget();
                }                    
                firingDisplay.target(null);
            } else {
                if (prevTarget != null) {
                    firingDisplay.target(prevTarget);
                    unitDisplay.getClientGUI().getBoardView()
                            .select(prevTarget.getPosition());
                    prevTarget = null;
                } else {
                    firingDisplay.updateTarget();
                }
            }
        } else if (currPanel instanceof TargetingPhaseDisplay) {
            ((TargetingPhaseDisplay) currPanel).updateTarget();
        }
        
        // Tell the <Phase>Display to update the 
        // firing arc info when a weapon has been de-selected
        if (weaponList.getSelectedIndex() == -1) {
            unitDisplay.getClientGUI().bv.clearFieldofF();
        }
    }
    onResize();
}