Example usage for javax.swing DefaultListModel size

List of usage examples for javax.swing DefaultListModel size

Introduction

In this page you can find the example usage for javax.swing DefaultListModel size.

Prototype

public int size() 

Source Link

Document

Returns the number of components in this list.

Usage

From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java

public void deleteUser() {
    if (theUserList == null) {
        return;/*from  w w w  . j av  a 2 s.c o m*/
    }
    DefaultListModel model = (DefaultListModel) theUserList.getModel();
    int selectedIndex = theUserList.getSelectedIndex();
    IndigoUser user = (IndigoUser) model.get(selectedIndex);
    userData.deleteUser(user);
    model.remove(selectedIndex);
    int newSize = model.size();
    if (newSize > 0) {
        if (selectedIndex >= (newSize - 1)) {
            selectedIndex = newSize - 1;
        }
        theUserList.setSelectedIndex(selectedIndex);
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java

public ArrayList<MetaDataListValues> getDataLookupItems() {
    DefaultListModel model = (DefaultListModel) theDataLookupList.getModel();
    ArrayList<MetaDataListValues> values = new ArrayList<MetaDataListValues>();
    for (int i = 0; i < model.size(); i++) {
        values.add((MetaDataListValues) model.get(i));
    }/*from   w  w w. j ava  2 s .  co  m*/
    Collections.sort(values, new MetaDataListValuesComparator());
    for (int i = 0; i < values.size(); i++) {
        values.get(i).setSortOrder(i);
    }
    return values;
}

From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java

public void addNewItem() {
    MetaDataTypeImpl data = new MetaDataTypeImpl();
    data.setDataType(EDataType.Text);
    data.setDataFieldName("New item");
    data.setIsVisible(true);/*from   w  ww  .j  av a  2 s.  c  o  m*/
    metaData.addMetaData(data);
    DefaultListModel model = (DefaultListModel) theDataList.getModel();
    model.addElement(data);
    theDataList.setSelectedIndex(model.size() - 1);
    setDirty(true);
}

From source file:nz.govt.natlib.ndha.manualdeposit.MetaDataTest.java

@Test
public final void testLoadData() {
    loadConfigFile();/*  w w  w  . jav a  2  s . co m*/
    assertTrue(metaDataPresenter.getIsDirty() == false);
    DefaultListModel model = (DefaultListModel) theFrame.lstDataList.getModel();
    assertTrue(model.getSize() == 9);
    theFrame.lstDataList.setSelectedIndex(0);
    assertTrue(theFrame.getTheData().equals(theFrame.lstDataList.getSelectedValue()));
    if (theFrame.lstDNX.getSelectedIndex() == 0) {
        theFrame.lstDNX.setSelectedIndex(1);
    } else {
        theFrame.lstDNX.setSelectedIndex(0);
    }
    assertTrue(theFrame.lstDNXDetail.getSelectedValue() == null);
    // assertTrue(_presenter.getIsDirty() == true);
    assertTrue(theFrame.getTheData().getDnxType().equals(theFrame.lstDNX.getSelectedValue()));
    theFrame.lstDNXDetail.setSelectedIndex(0);
    assertTrue(theFrame.getTheData().getDnxSubType().equals(theFrame.lstDNXDetail.getSelectedValue()));
    theFrame.tabDnxDc.setSelectedIndex(1);
    // Ajusted by Ben 2.12.2013
    assertTrue(theFrame.getTheData().isDNX());
    assertFalse(theFrame.getTheData().isDNXState());
    theFrame.lstDC.setSelectedIndex(0);
    assertTrue(theFrame.getTheData().getDcType().equals(theFrame.lstDC.getSelectedValue()));
    theFrame.cmbDataType.setSelectedItem(EDataType.Boolean);
    assertTrue(theFrame.getTheData().getDataType().equals(EDataType.Boolean));
    assertFalse(theFrame.pnlListItems.isVisible());
    theFrame.cmbDataType.setSelectedItem(EDataType.MultiSelect);
    assertTrue(theFrame.getTheData().getDataType().equals(EDataType.MultiSelect));
    assertTrue(theFrame.pnlListItems.isVisible());
    model = (DefaultListModel) theFrame.lstListItems.getModel();
    assertTrue(model.size() == 0);
    // MetaDataListValues value = MetaDataListValues.create("Stuff",
    // "Stuff");
    metaDataPresenter.addDataLookupItem("Stuff", "Stuff");
    // MetaDataListValues value2 = MetaDataListValues.create("Stuff2",
    // "Stuff2");
    metaDataPresenter.addDataLookupItem("Stuff2", "Stuff2");
    assertTrue(model.size() == 2);
    theFrame.editingLookupValue = false;
    theFrame.lstListItems.setSelectedIndex(0);
    assertTrue(theFrame.getIsEditingLookupValue());
    loadConfigFile();
    model = (DefaultListModel) theFrame.lstDataList.getModel();
    metaDataPresenter.addNewItem();
    assertTrue(model.getSize() == 10);
    assertTrue(theFrame.lstDataList.getSelectedIndex() == 9);
    metaDataPresenter.deleteItem();
    model = (DefaultListModel) theFrame.lstDataList.getModel();
    assertTrue(model.getSize() == 9);
    assertTrue(theFrame.lstDataList.getSelectedValue() == null);
}

From source file:nz.govt.natlib.ndha.manualdeposit.MetaDataTest.java

@Test
public final void testLookupData() {
    loadConfigFile();/*from   w  w w  .java  2s .  com*/
    theFrame.lstDataList.setSelectedIndex(0);
    theFrame.cmbDataType.setSelectedItem(EDataType.MultiSelect);
    assertTrue(theFrame.getTheData().getDataType().equals(EDataType.MultiSelect));
    assertTrue(theFrame.pnlListItems.isVisible());
    DefaultListModel model = (DefaultListModel) theFrame.lstListItems.getModel();
    assertTrue(model.size() == 0);
    assertFalse(metaDataPresenter.canSaveLookupData(null));
    assertFalse(metaDataPresenter.canSaveLookupData(""));
    assertTrue(metaDataPresenter.canSaveLookupData("Test"));
    assertFalse(metaDataPresenter.canDeleteLookupData());
    boolean failed = false;
    try {
        // Can't save unless something is selected - should add instead
        // MetaDataListValues value = MetaDataListValues.create("Stuff",
        // "Stuff", 0);
        metaDataPresenter.saveDataLookupItem("Stuff", "Stuff");
    } catch (Exception ex) {
        failed = true;
    }
    // assertTrue(failed);
    MetaDataListValues value1 = MetaDataListValues.create("Value 1", "Value 1", 0);
    metaDataPresenter.addDataLookupItem(value1.getValue(), value1.getDisplay());
    MetaDataListValues value2 = MetaDataListValues.create("Value 2", "Value 2", 1);
    metaDataPresenter.addDataLookupItem(value2.getValue(), value2.getDisplay());
    MetaDataListValues value3 = MetaDataListValues.create("Value 3", "Value 3", 2);
    metaDataPresenter.addDataLookupItem(value3.getValue(), value3.getDisplay());
    assertTrue(model.getSize() == 3);
    theFrame.lstListItems.setSelectedIndex(0);
    MetaDataListValues newValue = MetaDataListValues.create("New Value", "New Value", 3);
    metaDataPresenter.saveDataLookupItem(newValue.getValue(), newValue.getDisplay());
    MetaDataListValues testValue = (MetaDataListValues) theFrame.lstListItems.getSelectedValue();
    assertTrue(testValue.getDisplay().equals(newValue.getDisplay()));
    assertTrue(testValue.getValue().equals(newValue.getValue()));
    assertTrue(metaDataPresenter.canMoveLookupItem(false));
    assertFalse(metaDataPresenter.canMoveLookupItem(true));
    metaDataPresenter.moveLookupItem(false);
    assertTrue(metaDataPresenter.canMoveLookupItem(false));
    assertTrue(metaDataPresenter.canMoveLookupItem(true));
    assertTrue(theFrame.lstListItems.getSelectedIndex() == 1);
    metaDataPresenter.moveLookupItem(true);
    assertTrue(metaDataPresenter.canMoveLookupItem(false));
    assertFalse(metaDataPresenter.canMoveLookupItem(true));
    assertTrue(theFrame.lstListItems.getSelectedIndex() == 0);
    theFrame.lstListItems.setSelectedIndex(2);
    assertFalse(metaDataPresenter.canMoveLookupItem(false));
    assertTrue(metaDataPresenter.canMoveLookupItem(true));
    assertTrue(metaDataPresenter.canDeleteLookupData());
    metaDataPresenter.deleteLookupItem();
    assertTrue(model.size() == 2);
    testValue = (MetaDataListValues) model.get(0);
    assertTrue(testValue.getDisplay().equals(newValue.getDisplay()));
    assertTrue(testValue.getValue().equals(newValue.getValue()));
    testValue = (MetaDataListValues) model.get(1);
    assertTrue(testValue.getDisplay().equals(value2.getDisplay()));
    assertTrue(testValue.getValue().equals(value2.getValue()));
}

From source file:org.executequery.gui.editor.ManageShortcutsPanel.java

private EditorSQLShortcut getShortcutAt(int index) {

    DefaultListModel model = modelFromList();

    if (index >= model.size()) {

        return null;
    }//from   ww  w  .  j  av  a2 s.  co  m

    return (EditorSQLShortcut) model.elementAt(index);
}

From source file:org.jtrfp.trcl.flow.GameShell.java

private void registerPODs() {
    DefaultListModel<String> podList = tr.config.getPodList();
    for (int i = 0; i < podList.size(); i++) {
        final String podPath = podList.get(i);
        if (podPath != null) {
            final File file = new File(podPath);
            PodFile pod = new PodFile(file);
            try {
                tr.getResourceManager().registerPOD(file.getAbsolutePath(), pod);
            } catch (FileLoadException e) {
                JOptionPane.showMessageDialog(tr.getRootWindow(),
                        "Failed to parse (understand) POD file " + podPath, "Parsing failure",
                        JOptionPane.ERROR_MESSAGE);
            } //end catch(...)
        } //end if(!null)
    } //end for(pods)
}

From source file:org.jtrfp.trcl.gui.ConfigWindow.java

private void readSettingsToPanel() {
    modStereoWidthSlider.setValue((int) (config.getModStereoWidth() * 100.));
    chckbxLinearInterpolation.setSelected(config.isAudioLinearFiltering());
    chckbxBufferLag.setSelected(config.isAudioBufferLag());
    final int bSize = config.getAudioBufferSize();
    for (AudioBufferSize abs : AudioBufferSize.values())
        if (abs.getSizeInFrames() == bSize)
            audioBufferSizeCB.setSelectedItem(abs);

    missionLM.removeAllElements();/* w  w  w . j a  v  a 2 s. c o m*/
    for (String vox : config.getMissionList()) {
        if (isBuiltinVOX(vox))
            missionLM.addElement(vox);
        else if (checkVOX(new File(vox)))
            missionLM.addElement(vox);
    } //end for(vox)
    String missionSelection = config.getVoxFile();
    for (int i = 0; i < missionLM.getSize(); i++) {
        if (missionLM.get(i).contentEquals(missionSelection))
            missionList.setSelectedIndex(i);
    }

    podLM.removeAllElements();
    final DefaultListModel<String> podList = config.getPodList();
    for (int i = 0; i < podList.size(); i++) {
        final String pod = podList.get(i);
        if (pod != null)
            if (checkPOD(new File(pod)))
                podLM.addElement(pod);
    }
    soundOutputSelectorGUI.readToPanel(config);
}

From source file:org.opendatakit.briefcase.ui.CharsetConverterDialog.java

protected void initialize() {
    DefaultListModel<CharsetEntry> defaultListModel = new DefaultListModel<CharsetEntry>();

    for (CharsetEntry commonCharsetEntry : commonCharsetEntries) {
        try {//  w w  w.  j  a v  a  2  s .  c o m
            if (Charset.isSupported(commonCharsetEntry.getCharsetName())) {
                defaultListModel.addElement(commonCharsetEntry);
            }
        } catch (IllegalCharsetNameException e) {
            // just ignore it. It will happen for "Mac OS Roman" under Windows
        }
    }

    SortedMap<String, Charset> charsetSortedMap = Charset.availableCharsets();
    for (Map.Entry<String, Charset> charsetMapEntry : charsetSortedMap.entrySet()) {
        CharsetEntry charsetEntry = new CharsetEntry(charsetMapEntry.getValue().displayName(),
                charsetMapEntry.getKey());
        if (!defaultListModel.contains(charsetEntry)) {
            defaultListModel.addElement(charsetEntry);
        }
    }

    listCharset.setModel(defaultListModel);

    if (defaultListModel.size() > 0) {
        listCharset.setSelectedIndex(0);

        listCharset.addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                updatePreview();
            }
        });
    } else {
        JOptionPane.showMessageDialog(this,
                "It appears that your installed Java Runtime Environment does not support any charset encodings!",
                "Error!", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:org.shaman.rpg.editor.dialog.DialogVisualElement.java

private void updatePersons() {
    if (isInsideSetupVisuals) {
        return;/*  w  w w.j  a va2  s. c  o  m*/
    }
    //Extract persons
    @SuppressWarnings("unchecked")
    final DefaultListModel<String> listModel = (DefaultListModel<String>) personsList.getModel();
    final String[] newPersons = new String[listModel.size()];
    listModel.copyInto(newPersons);
    LOG.info("settings persons to " + Arrays.toString(newPersons));
    final String[] oldPersons = dialog.getPersonList();

    //send to dialog
    dialog.setPersonList(newPersons);
    updateDialogPersons();

    // undo/redo
    undoRedo.undoableEditHappened(new UndoableEditEvent(dialog, new AbstractUndoableEdit() {

        @Override
        public void undo() throws CannotUndoException {
            super.undo();
            isInsideSetupVisuals = true;
            listModel.clear();
            listModel.ensureCapacity(oldPersons.length);
            for (String s : oldPersons) {
                listModel.addElement(s);
            }
            LOG.info("settings persons to " + Arrays.toString(oldPersons));
            dialog.setPersonList(oldPersons);
            updateDialogPersons();
            isInsideSetupVisuals = false;
        }

        @Override
        public void redo() throws CannotRedoException {
            super.redo();
            isInsideSetupVisuals = true;
            listModel.clear();
            listModel.ensureCapacity(newPersons.length);
            for (String s : newPersons) {
                listModel.addElement(s);
            }
            LOG.info("settings persons to " + Arrays.toString(newPersons));
            dialog.setPersonList(newPersons);
            updateDialogPersons();
            isInsideSetupVisuals = false;
        }

    }));
}