Search in sources :

Example 1 with DefaultListModel

use of javax.swing.DefaultListModel in project cogtool by cogtool.

the class JListBinding method put.

public void put(IValidatable bean) {
    try {
        DefaultListModel model = new DefaultListModel();
        List list = (List) PropertyUtils.getProperty(bean, _property);
        if (list != null) {
            for (Iterator iter = list.iterator(); iter.hasNext(); ) {
                model.addElement(iter.next());
            }
        }
        _list.setModel(model);
    } catch (Exception e) {
        throw new BindingException(e);
    }
}
Also used : Iterator(java.util.Iterator) DefaultListModel(javax.swing.DefaultListModel) List(java.util.List) JList(javax.swing.JList) ArrayList(java.util.ArrayList)

Example 2 with DefaultListModel

use of javax.swing.DefaultListModel in project CoreNLP by stanfordnlp.

the class MatchesPanel method setMatches.

/**
   * Used to set the trees to be displayed in this panel (which should match
   * the tregex expression).
   *
   * @param matches trees that match the expression
   */
public void setMatches(List<TreeFromFile> matches, Map<TreeFromFile, List<Tree>> matchedParts) {
    // cdm Nov 2010: I rewrote this so the performance wasn't dreadful.
    // In the old days, one by one updates to active Swing components gave dreadful performance, so
    // I changed that, but that wasn't really the problem, it was that the if part didn't honor
    // maxMatches!
    removeAllMatches();
    final DefaultListModel newModel = new DefaultListModel();
    newModel.ensureCapacity(matches.size());
    //
    if (TregexGUI.getInstance().isTdiffEnabled()) {
        //First selected treebank is the reference
        FileTreeNode refTreebank = FilePanel.getInstance().getActiveTreebanks().get(0);
        String refFileName = refTreebank.getFilename();
        List<Tree> treeList = null;
        Map<TreeFromFile, List<Tree>> filteredMatchedParts = Generics.newHashMap();
        for (TreeFromFile t2 : matches) {
            if (t2.getFilename() == null || t2.getSentenceId() < 0) {
                //Trees were not read by PennTreeReader.
                newModel.addElement(t2);
                filteredMatchedParts.put(t2, matchedParts.get(t2));
            } else if (!t2.getFilename().equals(refFileName)) {
                if (//Lazy loading to account for the if statement above
                treeList == null)
                    treeList = getTreebankAsList(refTreebank.getTreebank());
                int treeId = t2.getSentenceId() - 1;
                if (treeId >= treeList.size())
                    continue;
                Tree t1 = treeList.get(treeId);
                Tree treeT2 = t2.getTree();
                Set<Constituent> inT1notT2 = Tdiff.markDiff(t1, treeT2);
                t2.setDiffConstituents(inT1notT2);
                t2.setDiffDecoratedTree(treeT2);
                newModel.addElement(t2);
                if (matchedParts != null && matchedParts.containsKey(t2))
                    filteredMatchedParts.put(t2, matchedParts.get(t2));
            }
            //else skip this tree
            if (newModel.size() >= maxMatches)
                break;
        }
        matchedParts = filteredMatchedParts;
    } else if (!showOnlyMatchedPortion || matchedParts == null) {
        int i = 0;
        for (TreeFromFile t : matches) {
            newModel.addElement(t);
            i++;
            if (i >= maxMatches)
                break;
        }
    } else {
        int i = 0;
        for (TreeFromFile t : matchedParts.keySet()) {
            List<Tree> curMatches = matchedParts.get(t);
            for (Tree match : curMatches) {
                newModel.addElement(new TreeFromFile(match, t.getFilename()));
                i++;
                if (i >= maxMatches)
                    break;
            }
        }
    }
    if (!newModel.isEmpty()) {
        SwingUtilities.invokeLater(() -> {
            list.setModel(newModel);
            list.setSelectedIndex(0);
            sendToListeners();
        });
    }
    setMatchedParts(matchedParts);
    this.setPreferredSize(this.getSize());
}
Also used : Set(java.util.Set) DefaultListModel(javax.swing.DefaultListModel) Tree(edu.stanford.nlp.trees.Tree) ArrayList(java.util.ArrayList) TooltipJList(edu.stanford.nlp.swing.TooltipJList) JList(javax.swing.JList) List(java.util.List)

Example 3 with DefaultListModel

use of javax.swing.DefaultListModel in project GlassRemote by thorikawa.

the class MainFrame method selectDevice.

public void selectDevice() {
    mGlassConnection.close();
    DefaultListModel deviceListModel = SwingUtil.list2ListModel(mGlassConnection.getBondedDevices());
    // mDeviceListModel = new DefaultListModel();
    mDialog = new DeviceDialog(this, deviceListModel, mGlassConnection);
    mGlassConnection.registerListener(mDialog);
    mGlassConnection.scan();
    mDialog.setLocationRelativeTo(this);
    mDialog.setVisible(true);
    if (mDialog.isOK()) {
        int selectedIndex = mDialog.getSelectedIndex();
        if (selectedIndex >= 0) {
            mDevice = (Device) deviceListModel.get(selectedIndex);
            mGlassConnection.connect(mDevice);
            setImage(null);
        }
    }
    mGlassConnection.unregisterListener(mDialog);
    deviceListModel = null;
    mDialog = null;
}
Also used : DefaultListModel(javax.swing.DefaultListModel)

Example 4 with DefaultListModel

use of javax.swing.DefaultListModel in project gephi by gephi.

the class MergeColumnsUI method moveElementsFromListToOtherList.

private void moveElementsFromListToOtherList(JList sourceList, JList targetList) {
    DefaultListModel sourceModel, targetModel;
    sourceModel = (DefaultListModel) sourceList.getModel();
    targetModel = (DefaultListModel) targetList.getModel();
    Object[] selection = sourceList.getSelectedValues();
    for (Object element : selection) {
        sourceModel.removeElement(element);
        targetModel.addElement(element);
    }
}
Also used : DefaultListModel(javax.swing.DefaultListModel)

Example 5 with DefaultListModel

use of javax.swing.DefaultListModel in project gephi by gephi.

the class SplineControlPanel method createTemplates.

private Component createTemplates() {
    DefaultListModel model = new DefaultListModel();
    model.addElement(createTemplate(0.0, 0.0, 1.0, 1.0));
    model.addElement(createTemplate(0.0, 1.0, 0.0, 1.0));
    model.addElement(createTemplate(0.0, 1.0, 1.0, 1.0));
    model.addElement(createTemplate(0.0, 1.0, 1.0, 0.0));
    model.addElement(createTemplate(1.0, 0.0, 0.0, 1.0));
    model.addElement(createTemplate(1.0, 0.0, 1.0, 1.0));
    model.addElement(createTemplate(1.0, 0.0, 1.0, 0.0));
    JList list = new JList(model);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setCellRenderer(new TemplateCellRenderer());
    list.addListSelectionListener(new TemplateSelectionHandler());
    JScrollPane pane = new JScrollPane(list);
    pane.getViewport().setPreferredSize(new Dimension(98, 97 * 3));
    return pane;
}
Also used : JScrollPane(javax.swing.JScrollPane) DefaultListModel(javax.swing.DefaultListModel) Dimension(java.awt.Dimension) JList(javax.swing.JList)

Aggregations

DefaultListModel (javax.swing.DefaultListModel)41 JList (javax.swing.JList)21 ArrayList (java.util.ArrayList)16 JScrollPane (javax.swing.JScrollPane)13 List (java.util.List)8 JButton (javax.swing.JButton)8 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5 JPanel (javax.swing.JPanel)5 Conditional (jmri.Conditional)5 Dimension (java.awt.Dimension)4 GridBagConstraints (java.awt.GridBagConstraints)4 GridBagLayout (java.awt.GridBagLayout)4 Insets (java.awt.Insets)4 Logix (jmri.Logix)4 Component (java.awt.Component)3 JLabel (javax.swing.JLabel)3 SensorGroupConditional (jmri.implementation.SensorGroupConditional)3 FormBuilder (com.jgoodies.forms.builder.FormBuilder)2 FormLayout (com.jgoodies.forms.layout.FormLayout)2