Example usage for javax.swing ListModel getSize

List of usage examples for javax.swing ListModel getSize

Introduction

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

Prototype

int getSize();

Source Link

Document

Returns the length of the list.

Usage

From source file:com.anrisoftware.prefdialog.miscswing.lists.RubberBandingList.java

private int[] getIntersectsIdices(Shape shape) {
    ListModel<E> model = getModel();
    List<Integer> list = new ArrayList<Integer>(model.getSize());
    for (int i = 0; i < model.getSize(); i++) {
        Rectangle r = getCellBounds(i, i);
        if (shape.intersects(r)) {
            list.add(i);/* w  ww . ja v  a  2  s. c o m*/
        }
    }
    int[] indices = new int[list.size()];
    for (int i = 0; i < list.size(); i++) {
        indices[i] = list.get(i);
    }
    return indices;
}

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  a2  s. co m*/
    }

    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

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

    for (int i = 0; i < model.getSize(); i++) {
        if (selectedFilePath.equals(model.getElementAt(i))) {
            return i;
        }/*from   w ww .  ja  va2 s .c  o m*/
    }
    return -1;
}

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;
        }/*  w  w  w  .j  a  v a 2s . 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   www. j a  v a2s.com
    }
}

From source file:com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel.java

private void buildUI() {
    editor = new GroovyEditor(new ScriptStepGroovyEditorModel());

    logArea = new JLogList("Groovy Test Log");
    logArea.addLogger(groovyStep.getName() + "#" + hashCode(), true);
    logArea.getLogList().addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() < 2)
                return;

            String value = logArea.getLogList().getSelectedValue().toString();
            if (value == null)
                return;

            editor.selectError(value);/*from   w  w w  . jav  a  2  s .  c  o m*/
        }
    });

    logArea.getLogList().getModel().addListDataListener(new ListDataChangeListener() {

        @Override
        public void dataChanged(ListModel model) {
            logInspector.setTitle("Log Output (" + model.getSize() + ")");

        }
    });

    inspectorPanel = JInspectorPanelFactory.build(editor);
    logInspector = inspectorPanel.addInspector(new JComponentInspector<JComponent>(logArea, "Log Output (0)",
            "Groovy Log output for this script", true));
    inspectorPanel.setDefaultDividerLocation(0.8F);
    inspectorPanel.activate(logInspector);
    add(inspectorPanel.getComponent(), BorderLayout.CENTER);
    add(buildToolbar(), BorderLayout.NORTH);
    add(buildStatusBar(), BorderLayout.SOUTH);

    componentEnabler.add(editor);
}

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.
 *//* w  ww  .  j  a  va 2 s  .co m*/
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();
    }
}

From source file:de.codesourcery.eve.skills.ui.components.ListEditingComponent.java

public ListEditingComponent(ListModel model) {
    if (model == null) {
        throw new IllegalArgumentException("model cannot be NULL");
    }/*  ww  w.j a va  2  s  .c o m*/

    this.model = model;
    this.list.setCellRenderer(createListRenderer());
    this.list.setModel(model);
    if (model.getSize() > 0) {
        this.list.setSelectedIndex(0);
    }
    this.list.getSelectionModel().addListSelectionListener(this);

    addButton.addActionListener(this);
    removeButton.addActionListener(this);
    editButton.addActionListener(this);
}

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

/**
 * check threads in given thread dump and add appropriate
 * custom categories (if any defined).// w  w w .jav a2  s  .c  om
 *
 * @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:com.kstenschke.copypastestack.ToolWindow.java

/**
 * Bubble all color-tagged items to the top of the list (groups: yellow, green, reed, untagged)
 *//*from  w  w w . ja v  a  2s  .c o m*/
private void sortClipboardListByTags(boolean sortAlphabetically) {
    ListModel<String> listModel = this.form.listClipItems.getModel();
    int amountItems = listModel.getSize();

    if (amountItems > 0) {
        String[] itemsYellow = new String[amountItems + 1];
        int indexYellow = 0;

        String[] itemsGreen = new String[amountItems + 1];
        int indexGreen = 0;

        String[] itemsRed = new String[amountItems + 1];
        int indexRed = 0;

        String[] itemsUntagged = new String[amountItems + 1];
        int indexUntagged = 0;

        // Refill items from listModel into sortable arrays
        for (int i = 0; i < amountItems; i++) {
            String item = listModel.getElementAt(i);
            if (item != null && !item.trim().isEmpty()) {
                switch (TagManager.getIdColorByValue(item)) {
                case StaticValues.ID_COLOR_YELLOW:
                    itemsYellow[indexYellow] = item;
                    indexYellow++;
                    break;

                case StaticValues.ID_COLOR_GREEN:
                    itemsGreen[indexGreen] = item;
                    indexGreen++;
                    break;

                case StaticValues.ID_COLOR_RED:
                    itemsRed[indexRed] = item;
                    indexRed++;
                    break;

                case StaticValues.ID_COLOR_NONE:
                    itemsUntagged[indexUntagged] = item;
                    indexUntagged++;
                    break;
                }
            }
        }

        // Reduce arrays to size of actual content
        itemsYellow = Arrays.copyOfRange(itemsYellow, 0, indexYellow);
        itemsRed = Arrays.copyOfRange(itemsRed, 0, indexRed);
        itemsGreen = Arrays.copyOfRange(itemsGreen, 0, indexGreen);
        itemsUntagged = Arrays.copyOfRange(itemsUntagged, 0, indexUntagged);

        // Sort string items alphabetically
        if (sortAlphabetically) {
            if (itemsYellow.length > 1)
                Arrays.sort(itemsYellow, String.CASE_INSENSITIVE_ORDER);
            if (itemsGreen.length > 1)
                Arrays.sort(itemsGreen, String.CASE_INSENSITIVE_ORDER);
            if (itemsRed.length > 1)
                Arrays.sort(itemsRed, String.CASE_INSENSITIVE_ORDER);
            if (itemsUntagged.length > 1)
                Arrays.sort(itemsUntagged, String.CASE_INSENSITIVE_ORDER);
        }

        // Update list from sorted items
        this.setClipboardListData(ArrayUtils.addAll(
                ArrayUtils.addAll(ArrayUtils.addAll(itemsYellow, itemsGreen), itemsRed), itemsUntagged), false);
    }
}