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);
}
}
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());
}
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;
}
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);
}
}
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;
}
Aggregations