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

The following examples show how to use javax.swing.event.ListSelectionEvent#getFirstIndex() . 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: DatFileViewer.java    From settlers-remake with MIT License 6 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e) {
	if (e.getFirstIndex() < 0 || e.getValueIsAdjusting()) { return; }

	String fileName = (String) listView.getSelectedValue();

	DatFileType type = DatFileType.RGB565;
	File file = new File(gfxDirectory, fileName);

	if (file.getName().contains(DatFileType.RGB555.getFileSuffix())) {
		type = DatFileType.RGB555;
	} else if (file.getName().contains(DatFileType.RGB565.getFileSuffix())) {
		type = DatFileType.RGB565;
	}

	reader = new AdvancedDatFileReader(file, type, null);
	showFileInfo(type, reader);

	glCanvas.resetOffset();
	glCanvas.resetZoom();
	glCanvas.invalidate();
	glCanvas.requestFocus();
}
 
Example 4
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 5
Source File: View.java    From jplag with GNU General Public License v3.0 5 votes vote down vote up
public void valueChanged(ListSelectionEvent arg0) {
	int row = arg0.getFirstIndex();
	if (row >= 0) {
		if (getJTable().isRowSelected(row)
				|| getJTable().isRowSelected(arg0.getLastIndex())) {
			enableButtons(true);
			if (!dontHideInfoPanelOnFocus && View.this.infoPanel != null
					&& View.this.infoPanel.isShowing())
				hideInfoPanel();
			return;
		}
	}
	enableButtons(false);
}
 
Example 6
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 7
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 8
Source File: PlacemarkManagerTopComponent.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() || e.getFirstIndex() == -1 || synchronizingPlacemarkSelectedState) {
        return;
    }

    try {
        synchronizingPlacemarkSelectedState = true;
        Placemark[] placemarks = placemarkTableModel.getPlacemarks();
        ArrayList<Placemark> selectedPlacemarks = new ArrayList<>();
        for (int i = 0; i < placemarks.length; i++) {
            Placemark placemark = placemarks[i];
            int sortedIndex = placemarkTable.convertRowIndexToView(i);
            if (placemarkTable.isRowSelected(sortedIndex)) {
                selectedPlacemarks.add(placemark);
            }
        }
        ProductSceneView sceneView = getSceneView();
        if (sceneView != null) {
            Placemark[] placemarkArray = selectedPlacemarks.toArray(new Placemark[selectedPlacemarks.size()]);
            //todo remove code smell - tf 20151118
            if (getPlacemarkDescriptor() instanceof PinDescriptor) {
                sceneView.selectPins(placemarkArray);
            } else {
                sceneView.selectGcps(placemarkArray);
            }
        }
    } finally {
        updateUIState();
        synchronizingPlacemarkSelectedState = false;
    }

}