Example usage for javax.swing ListModel getElementAt

List of usage examples for javax.swing ListModel getElementAt

Introduction

In this page you can find the example usage for javax.swing ListModel getElementAt.

Prototype

E getElementAt(int index);

Source Link

Document

Returns the value at the specified index.

Usage

From source file:SelectionHandler.java

private void addToDestination(String item) {
    ListModel model = destination.getModel();
    Vector listData = new Vector();
    for (int i = 0; i < model.getSize(); i++) {
        listData.addElement(model.getElementAt(i));
    }//w ww . ja  va 2 s .c om
    listData.addElement(item);
    destination.setListData(listData);
}

From source file:SortedListModel.java

private void fillListModel(SortedListModel model, ListModel newValues) {
    int size = newValues.getSize();
    for (int i = 0; i < size; i++) {
        model.add(newValues.getElementAt(i));
    }/*from  ww  w  . j  a v  a  2 s .  c  o m*/
}

From source file:edu.ku.brc.specify.tasks.DataEntryConfigDlg.java

@Override
protected void addItem(final JList list, final Vector<TaskConfigItemIFace> itemList) {
    // Hash all the names so we can figure out which forms are not used
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    ListModel model = stdPanel.getOrderModel();
    for (int i = 0; i < model.getSize(); i++) {
        DataEntryView dev = (DataEntryView) model.getElementAt(i);
        hash.put(dev.getView(), dev);/*w  ww.j a v  a2s .  com*/
    }

    model = miscPanel.getOrderModel();
    for (int i = 0; i < model.getSize(); i++) {
        DataEntryView dev = (DataEntryView) model.getElementAt(i);
        hash.put(dev.getView(), dev);
    }

    // Add only the unused forms (does NOT return internal views).
    List<String> uniqueList = new Vector<String>();
    List<ViewIFace> views = ((SpecifyAppContextMgr) AppContextMgr.getInstance()).getAllViews();
    Hashtable<String, ViewIFace> newAvailViews = new Hashtable<String, ViewIFace>();
    for (ViewIFace view : views) {
        //System.out.println("["+view.getName()+"]["+view.getTitle()+"]");

        if (hash.get(view.getName()) == null) {
            DBTableInfo ti = DBTableIdMgr.getInstance().getByClassName(view.getClassName());
            if (ti != null) {
                if (!ti.isHidden() && !InteractionsTask.isInteractionTable(ti.getTableId())) {
                    hash.put(view.getName(), view);
                    String title = StringUtils.isNotEmpty(view.getObjTitle()) ? view.getObjTitle()
                            : ti != null ? ti.getTitle() : view.getName();
                    if (newAvailViews.get(title) != null) {
                        title = view.getName();
                    }
                    uniqueList.add(title);
                    newAvailViews.put(title, view);
                }
            } else {
                System.err.println("DBTableInfo was null for class[" + view.getClassName() + "]");
            }
        }
    }

    if (uniqueList.size() == 0) {
        JOptionPane.showMessageDialog(this, getResourceString("DET_DEV_NONE_AVAIL"),
                getResourceString("DET_DEV_NONE_AVAIL_TITLE"), JOptionPane.INFORMATION_MESSAGE);
        return;
    }

    Collections.sort(uniqueList);

    ToggleButtonChooserDlg<String> dlg = new ToggleButtonChooserDlg<String>((Frame) UIRegistry.getTopWindow(),
            "DET_AVAIL_VIEWS", uniqueList);

    dlg.setUseScrollPane(true);
    UIHelper.centerAndShow(dlg);

    if (!dlg.isCancelled()) {
        model = list.getModel();

        for (String title : dlg.getSelectedObjects()) {
            ViewIFace view = newAvailViews.get(title);
            DBTableInfo ti = DBTableIdMgr.getInstance().getByClassName(view.getClassName());

            String frmTitle = StringUtils.isNotEmpty(view.getObjTitle()) ? view.getObjTitle()
                    : ti != null ? ti.getTitle() : view.getName();
            DataEntryView dev = new DataEntryView(frmTitle, // Title 
                    view.getName(), // Name
                    ti != null ? ti.getName() : null, // Icon Name
                    view.getObjTitle(), // ToolTip
                    model.getSize(), // Order
                    true);
            dev.setTableInfo(ti);
            ((DefaultListModel) model).addElement(dev);
            itemList.add(dev);
        }
        //pack();
    }
    setHasChanged(true);
}

From source file:com.sec.ose.osi.ui.frm.main.identification.JListMatchedFiles.java

private boolean isExistInJList(String filePath) {
    ListModel model = this.getModel();

    for (int i = 0; i < model.getSize(); i++) {
        if (filePath.equals(model.getElementAt(i))) {
            return true;
        }/*from   ww w. jav a  2 s.  c  o m*/
    }
    return false;
}

From source file:ListInput.java

public void actionPerformed(ActionEvent e) {
    ListModel model = list.getModel();
    String key = textfield.getText().toLowerCase();
    for (int i = 0; i < model.getSize(); i++) {
        String data = (String) model.getElementAt(i);
        if (data.toLowerCase().startsWith(key)) {
            list.setSelectedValue(data, true);
            break;
        }/*from w w  w  .  j a  v a  2 s.  co  m*/
    }
}

From source file:com.sec.ose.osi.ui.frm.main.identification.JListMatchedFiles.java

int getIndexOfFilePath(String selectedFilePath) {
    ListModel model = this.getModel();

    for (int i = 0; i < model.getSize(); i++) {
        if (selectedFilePath.equals(model.getElementAt(i))) {
            return i;
        }//www  .  jav a  2  s.co m
    }
    return -1;
}

From source file:com.anrisoftware.prefdialog.fields.listbox.AbstractListBoxField.java

/**
 * Sets the selected indices./*from w w  w .j a v  a2 s . c o m*/
 * <p>
 * <h2>AWT Thread</h2>
 * <p>
 * Should be called in the AWT thread.
 * 
 * @param indices
 *            the selected indices.
 * 
 * @throws PropertyVetoException
 *             if the first index's value is vetoed.
 * 
 * @see JList#setSelectedIndices(int[])
 */
@OnAwt
public void setSelectedIndices(int[] indices) throws PropertyVetoException {
    ComponentType list = getComponent();
    ListModel<?> model = list.getModel();
    if (indices.length == 1) {
        setValue(model.getElementAt(indices[0]));
    } else if (indices.length > 1) {
        setValues(findSelectedValues(indices));
    }
    dataListener.lock();
    list.setSelectedIndices(indices);
    dataListener.unlock();
}

From source file:com.anrisoftware.prefdialog.fields.listbox.AbstractListBoxField.java

private Object[] findSelectedValues(int[] indices) {
    ComponentType list = getComponent();
    ListModel<?> model = list.getModel();
    Object[] values = new Object[indices.length];
    for (int i : indices) {
        values[i] = model.getElementAt(indices[i]);
    }/*from   w  w  w  .j a  v  a  2  s  . com*/
    return values;
}

From source file:com.pironet.tda.AbstractDumpParser.java

/**
 * check threads in given thread dump and add appropriate
 * custom categories (if any defined).//  www .  j  ava 2  s  .  c  o m
 *
 * @param threadDump the thread dump info object.
 */
public void addCustomCategories(DefaultMutableTreeNode threadDump) {
    ThreadDumpInfo tdi = (ThreadDumpInfo) threadDump.getUserObject();
    Category threads = tdi.getThreads();
    ListModel cats = PrefManager.get().getCategories();
    for (int i = 0; i < cats.getSize(); i++) {
        final Category cat = new TableCategory(((CustomCategory) cats.getElementAt(i)).getName(),
                IconFactory.CUSTOM_CATEGORY);
        for (int j = 0; j < threads.getNodeCount(); j++) {
            Iterator filterIter = ((CustomCategory) cats.getElementAt(i)).iterOfFilters();
            boolean matches = true;
            ThreadInfo ti = (ThreadInfo) threads.getNodeAt(j).getUserObject();
            while (matches && filterIter.hasNext()) {
                Filter filter = (Filter) filterIter.next();
                matches = filter.matches(ti, true);
            }

            if (matches) {
                cat.addToCatNodes(new DefaultMutableTreeNode(ti));
            }
        }
        if (cat.getNodeCount() > 0) {
            cat.setName(cat.getName() + " (" + cat.getNodeCount() + " Threads overall)");
            threadDump.add(new DefaultMutableTreeNode(cat));
        }
    }
}

From source file:misc.TextBatchPrintingDemo.java

/**
 * Synchronize the selection in the print list with the current page item.
 * If the current page item isn't in the print list, clear selection.
 *//*from  w w w  . java 2s .  c om*/
void updateSelectedPages() {
    ListModel pages = selectedPages.getModel();
    int n = pages.getSize();
    if (n > 0) {
        URL page = pageItem.getPage();
        int index = selectedPages.getSelectedIndex();
        if (index >= 0) {
            PageItem selected = (PageItem) pages.getElementAt(index);
            if (page.equals(selected.getPage())) {
                // Currently displayed page is selected in the print list.
                return;
            }
        }
        for (int i = 0; i < n; i++) {
            PageItem pi = (PageItem) pages.getElementAt(i);
            if (page.equals(pi.getPage())) {
                // Currently displayed page is in the print list, select it.
                selectedPages.setSelectedIndex(i);
                return;
            }
        }
        // Currently displayed page is not in the print list. 
        selectedPages.clearSelection();
    }
}