Example usage for java.awt.event ItemEvent getStateChange

List of usage examples for java.awt.event ItemEvent getStateChange

Introduction

In this page you can find the example usage for java.awt.event ItemEvent getStateChange.

Prototype

public int getStateChange() 

Source Link

Document

Returns the type of state change (selected or deselected).

Usage

From source file:com.diversityarrays.kdxplore.curate.TrialDataEditor.java

private void updateViewedTraitInstances(ItemEvent e) {
    TraitInstance traitInstance = (TraitInstance) e.getItem();

    List<PlotOrSpecimen> selectedPlotSpecimens = new ArrayList<>();
    Set<TraitInstance> selectedTraitInstances = new HashSet<>();

    // works for no column movement, works for column movement
    collectSelectedPlotsAndColumns(selectedPlotSpecimens, selectedTraitInstances);

    Map<Integer, SortKey> sortKeyByColumn = new LinkedHashMap<>();
    Map<SortKey, String> cnameBySortKey = new LinkedHashMap<>();

    @SuppressWarnings("unchecked")
    TableRowSorter<CurationTableModel> rowSorter = (TableRowSorter<CurationTableModel>) curationTable
            .getRowSorter();// w w w . ja v  a 2s  .  c om
    if (rowSorter != null) {
        // Make a copy because the one we get back is not modifiable!
        for (SortKey skey : rowSorter.getSortKeys()) {
            int columnIndex = skey.getColumn();

            sortKeyByColumn.put(columnIndex, skey);

            cnameBySortKey.put(skey, curationTableModel.getColumnName(columnIndex));
        }
    }

    // final Integer columnIndexForTraitInstance;

    boolean add = ItemEvent.SELECTED == e.getStateChange();
    if (add) {
        curationTableModel.addTraitInstance(traitInstance);
        plotCellChoicesPanel.addSelectedTraitInstance(traitInstance);

        fieldLayoutView.addTraitInstance(traitInstance);
        boolean found = false;
        for (int index = fieldViewTraitInstanceComboBoxModel.getSize(); --index >= 0;) {
            if (traitInstance == fieldViewTraitInstanceComboBoxModel.getElementAt(index)) {
                found = true;
                break;
            }
        }
        if (!found) {
            addToCombo(traitInstance);
        }

        Integer columnIndexForTraitInstance = curationTableModel.getColumnIndexForTraitInstance(traitInstance);

        messages.println("Added " + curationTableModel.getColumnName(columnIndexForTraitInstance));
    } else {
        selectedTraitInstances.remove(traitInstance);

        Integer columnIndexForTraitInstance = curationTableModel.getColumnIndexForTraitInstance(traitInstance);
        if (traitInstance.trait != null) {
            messages.println(
                    "Removed " + traitInstance.trait.getTraitName() + " [" + columnIndexForTraitInstance + "]"); //$NON-NLS-2$ //$NON-NLS-3$
        }

        curationTableModel.removeTraitInstance(traitInstance);
        plotCellChoicesPanel.removeSelectedTraitInstance(traitInstance);

        fieldLayoutView.removeTraitInstance(traitInstance);
        fieldViewTraitInstanceComboBoxModel.removeElement(traitInstance);

        SortKey removed = sortKeyByColumn.remove(columnIndexForTraitInstance);
        if (removed != null) {
            cnameBySortKey.remove(removed);
        }
    }

    if (rowSorter != null) {

        List<SortKey> validated = new ArrayList<>();

        int nColumns = curationTableModel.getColumnCount();

        for (Integer columnIndex : sortKeyByColumn.keySet()) {
            SortKey skey = sortKeyByColumn.get(columnIndex);
            if (columnIndex < nColumns) {
                validated.add(skey);
            }
        }

        if (!cnameBySortKey.isEmpty()) {
            String msg = cnameBySortKey.keySet().stream()
                    .map(skey -> cnameBySortKey.get(skey) + ": " + skey.getSortOrder()) //$NON-NLS-1$
                    .collect(Collectors.joining("\n ", //$NON-NLS-1$
                            "Restoring sort order:", "")); //$NON-NLS-2$
            messages.println(msg);
        }
        rowSorter.setSortKeys(validated);
    }

    if (!selectedPlotSpecimens.isEmpty()) {
        reapplySelection(selectedPlotSpecimens, selectedTraitInstances);
    }

    List<TraitInstance> checkedTraitInstances = null;
    if (curationTableModel.hasAnyTraitInstanceColumns()) {
        checkedTraitInstances = traitsAndInstancesPanel.getCheckedTraitInstances();
    }
    sampleSourcesTablePanel.updateTraitInstancesCombo(checkedTraitInstances);
}

From source file:com.osparking.osparking.Settings_System.java

private void LanguageBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_LanguageBoxItemStateChanged
    if (evt.getStateChange() == ItemEvent.SELECTED) {
        if (LanguageBox.getSelectedIndex() == localeIndex) {
            changedControls.remove(LanguageBox);
        } else {/*from w  ww.j a va  2s . c  o m*/
            changedControls.add(LanguageBox);
        }
    }
}

From source file:com.osparking.osparking.Settings_System.java

private void PopSizeCBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_PopSizeCBoxItemStateChanged
    if (evt.getStateChange() == ItemEvent.SELECTED) {
        if (PopSizeCBox.getSelectedIndex() == statCountIndex) {
            changedControls.remove(PopSizeCBox);
        } else {// w w  w . jav a  2  s . c o  m
            changedControls.add(PopSizeCBox);
        }
    }
}

From source file:com.osparking.osparking.Settings_System.java

private void Camera2_TypeCBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_Camera2_TypeCBoxItemStateChanged
    if (evt.getStateChange() == ItemEvent.SELECTED) {
        setButtonEnabled_If_DeviceTypeChanged(2, Camera);
        setPortNumber(Camera, Camera2_TypeCBox.getSelectedItem(), (byte) 2, Camera2_Port_TextField);
    }//w w w  . j  av a 2s .  c om
}

From source file:com.osparking.osparking.Settings_System.java

private void Camera3_TypeCBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_Camera3_TypeCBoxItemStateChanged
    if (evt.getStateChange() == ItemEvent.SELECTED) {
        setButtonEnabled_If_DeviceTypeChanged(3, Camera);
        setPortNumber(Camera, Camera3_TypeCBox.getSelectedItem(), (byte) 3, Camera3_Port_TextField);
    }/*  ww w  . j a  v a2  s.  com*/
}

From source file:com.osparking.osparking.Settings_System.java

private void Camera4_TypeCBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_Camera4_TypeCBoxItemStateChanged
    if (evt.getStateChange() == ItemEvent.SELECTED) {
        setButtonEnabled_If_DeviceTypeChanged(4, Camera);
        setPortNumber(Camera, Camera4_TypeCBox.getSelectedItem(), (byte) 4, Camera4_Port_TextField);
    }//from  w ww  .  j  av  a2s .c  om
}

From source file:com.osparking.osparking.Settings_System.java

private void E_Board2_TypeCBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_E_Board2_TypeCBoxItemStateChanged
    if (evt.getStateChange() == ItemEvent.SELECTED) {
        setButtonEnabled_If_DeviceTypeChanged(2, E_Board);
        setPortNumber(E_Board, E_Board2_TypeCBox.getSelectedItem(), (byte) 2, E_Board2_Port_TextField);
    }/* w  ww.  ja v a 2  s  .c om*/
}

From source file:com.osparking.osparking.Settings_System.java

private void E_Board1_TypeCBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_E_Board1_TypeCBoxItemStateChanged
    if (evt.getStateChange() == ItemEvent.SELECTED) {
        setButtonEnabled_If_DeviceTypeChanged(1, E_Board);
        setPortNumber(E_Board, E_Board1_TypeCBox.getSelectedItem(), (byte) 1, E_Board1_Port_TextField);
    }/*from  ww w.  j a v a  2 s .  com*/
}

From source file:com.osparking.osparking.Settings_System.java

private void E_Board3_TypeCBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_E_Board3_TypeCBoxItemStateChanged
    if (evt.getStateChange() == ItemEvent.SELECTED) {
        setButtonEnabled_If_DeviceTypeChanged(3, E_Board);
        setPortNumber(E_Board, E_Board3_TypeCBox.getSelectedItem(), (byte) 3, E_Board3_Port_TextField);
    }// w w  w .j a  v  a2s .  c  o  m
}

From source file:com.osparking.osparking.Settings_System.java

private void E_Board4_TypeCBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_E_Board4_TypeCBoxItemStateChanged
    if (evt.getStateChange() == ItemEvent.SELECTED) {
        setButtonEnabled_If_DeviceTypeChanged(4, E_Board);
        setPortNumber(E_Board, E_Board4_TypeCBox.getSelectedItem(), (byte) 4, E_Board4_Port_TextField);
    }/*from   w  ww. j a  v a2  s.c o m*/
}