List of usage examples for javax.swing ListModel getSize
int getSize();
From source file:org.orbisgis.core.ui.plugins.views.geocatalog.Catalog.java
public void setActiveFiltersId(String[] filterIds) { ListSelectionModel selectionModel = lstFilters.getSelectionModel(); ListModel filterModel = lstFilters.getModel(); selectionModel.clearSelection();//ww w.j a v a 2 s . c o m selectionModel.setValueIsAdjusting(true); for (String filterId : filterIds) { GeocatalogFilterDecorator filter = new GeocatalogFilterDecorator(filterId, null, null); int index = -1; for (int i = 0; i < filterModel.getSize(); i++) { if (filterModel.getElementAt(i).equals(filter)) { index = i; } } if (index != -1) { selectionModel.addSelectionInterval(index, index); } } selectionModel.setValueIsAdjusting(false); }
From source file:org.pentaho.reporting.ui.datasources.jdbc.ui.JdbcDataSourceDialog.java
protected void setScriptingLanguage(final String lang, final JComboBox languageField) { if (lang == null) { languageField.setSelectedItem(null); return;/*from w w w . j a v a 2 s .com*/ } final ListModel model = languageField.getModel(); for (int i = 0; i < model.getSize(); i++) { final ScriptEngineFactory elementAt = (ScriptEngineFactory) model.getElementAt(i); if (elementAt == null) { continue; } if (elementAt.getNames().contains(lang)) { languageField.setSelectedItem(elementAt); return; } } }
From source file:org.pentaho.reporting.ui.datasources.mondrian.MondrianDataSourceEditor.java
protected JdbcConnectionDefinition createConnectionDefinition(final AbstractMDXDataFactory dataFactory) { if (dataFactory == null) { throw new NullPointerException(); }/*from w ww. ja v a2 s .c om*/ String customName = dataFactory.getDesignTimeName(); if (customName == null) { customName = Messages.getString("MondrianDataSourceEditor.CustomConnection"); } final DataSourceProvider provider = dataFactory.getDataSourceProvider(); if (provider instanceof DriverDataSourceProvider) { final DriverDataSourceProvider dcp = (DriverDataSourceProvider) provider; final ListModel model = dialogModel.getConnections(); for (int i = 0; i < model.getSize(); i++) { final JdbcConnectionDefinition definition = (JdbcConnectionDefinition) model.getElementAt(i); if (definition instanceof DriverConnectionDefinition == false) { continue; } final DriverConnectionDefinition dcd = (DriverConnectionDefinition) definition; if (ObjectUtilities.equal(dcd.getDriverClass(), dcp.getDriver()) && ObjectUtilities.equal(dcd.getUsername(), dcp.getProperty("user")) && ObjectUtilities.equal(dcd.getPassword(), dcp.getProperty("password")) && ObjectUtilities.equal(dcd.getConnectionString(), dcp.getUrl()) && ObjectUtilities.equal(dcd.getName(), dcp.getProperty("::pentaho-reporting::name"))) { return definition; } } final String[] strings = dcp.getPropertyNames(); final Properties p = new Properties(); for (int i = 0; i < strings.length; i++) { final String string = strings[i]; p.put(string, dcp.getProperty(string)); } return new DriverConnectionDefinition(customName, dcp.getDriver(), dcp.getUrl(), null, null, dcp.getProperty("::pentaho-reporting::hostname"), // NON-NLS dcp.getProperty("::pentaho-reporting::database-name"), // NON-NLS dcp.getProperty("::pentaho-reporting::database-type"), // NON-NLS dcp.getProperty("::pentaho-reporting::port"), // NON-NLS p); } else if (provider instanceof JndiDataSourceProvider) { final JndiDataSourceProvider jcp = (JndiDataSourceProvider) provider; final ListModel model = dialogModel.getConnections(); for (int i = 0; i < model.getSize(); i++) { final JdbcConnectionDefinition definition = (JdbcConnectionDefinition) model.getElementAt(i); if (definition instanceof JndiConnectionDefinition == false) { continue; } final JndiConnectionDefinition dcd = (JndiConnectionDefinition) definition; if (ObjectUtilities.equal(dcd.getJndiName(), jcp.getConnectionPath())) { return dcd; } } return new JndiConnectionDefinition(customName, jcp.getConnectionPath(), null, null, null); } return null; }
From source file:org.pentaho.reporting.ui.datasources.pmd.PmdDataSourceEditor.java
private void setSelectedQuery(final String query) { final ListModel listModel = queryNameList.getModel(); for (int i = 0; i < listModel.getSize(); i++) { final DataSetQuery dataSet = (DataSetQuery) listModel.getElementAt(i); if (dataSet.getQueryName().equals(query)) { queryNameList.setSelectedValue(dataSet, true); break; }/* www .j av a 2s . c o m*/ } }
From source file:org.springframework.richclient.form.binding.jide.CheckBoxListSelectableBinding.java
/** * @param values/* ww w. j a va2s . c om*/ * @return */ protected int[] determineValueIndexes(Object[] values) { int[] indexes = new int[values.length]; if (values.length == 0) return indexes; Collection lookupValues = new HashSet(Arrays.asList(values)); ListModel model = getList().getModel(); int i = 0; for (int index = 0, size = model.getSize(); index < size && !lookupValues.isEmpty(); index++) { if (lookupValues.remove(model.getElementAt(index))) { indexes[i++] = index; } } int[] result; if (i != values.length) { result = new int[i]; System.arraycopy(indexes, 0, result, 0, i); } else { result = indexes; } return result; }
From source file:org.wings.SList.java
/** * Return the values of the selected cells. * Returns only the selected elements which are in the model. * If the selection model indices a selection outside the the datamodel it is ignored * * @return the selected values// w w w . jav a 2s . co m * @see #isSelectedIndex * @see #getModel * @see #addListSelectionListener */ public Object[] getSelectedValues() { ListSelectionModel sm = getSelectionModel(); ListModel dm = getModel(); int iMin = sm.getMinSelectionIndex(); int iMax = sm.getMaxSelectionIndex(); if ((iMin < 0) || (iMax < 0)) { return new Object[0]; } Object[] rvTmp = new Object[1 + (iMax - iMin)]; int n = 0; for (int i = iMin; i <= iMax; i++) { if (sm.isSelectedIndex(i) && i < dm.getSize()) { rvTmp[n++] = dm.getElementAt(i); } } Object[] rv = new Object[n]; System.arraycopy(rvTmp, 0, rv, 0, n); return rv; }
From source file:org.wings.SList.java
/** * Selects the specified object./*from ww w.j a v a 2s .co m*/ * * @param anObject the Object to be selected */ public void setSelectedValue(Object anObject) { if (anObject == null) setSelectedIndex(-1); else if (!anObject.equals(getSelectedValue())) { int i, c; ListModel dm = getModel(); for (i = 0, c = dm.getSize(); i < c; i++) if (anObject.equals(dm.getElementAt(i))) { setSelectedIndex(i); return; } setSelectedIndex(-1); } }
From source file:org.yccheok.jstock.gui.IndicatorPanel.java
private void syncJListWithIndicatorProjectManager(JList jList, IndicatorProjectManager indicatorProjectManager) { final String projectName = (String) jList.getSelectedValue(); boolean isProjectNameBeingRemoved = false; int newSelection = -1; final ListModel listModel = jList.getModel(); for (int i = 0; i < listModel.getSize(); i++) { if (indicatorProjectManager.contains(listModel.getElementAt(i).toString()) == false) { // Remove from JList, as it is not found in indicator project manager. Object removedObject = ((DefaultListModel) listModel).remove(i); if (projectName.equals(removedObject)) { isProjectNameBeingRemoved = true; newSelection = i;//from w w w . jav a2s . c om } i--; } } for (int i = 0; i < indicatorProjectManager.getNumOfProject(); i++) { final String p = indicatorProjectManager.getProject(i); if (((DefaultListModel) listModel).contains(p) == false) { // Add to JList, as it is found in indicator project manager. ((DefaultListModel) listModel).addElement(p); } } if (!isProjectNameBeingRemoved) { // Ensure list cell renderer is being triggered. jList.setSelectedValue(projectName, true); } else { if (newSelection >= jList.getModel().getSize()) { // Select last row. jList.setSelectedIndex(jList.getModel().getSize() - 1); } else { jList.setSelectedIndex(newSelection); } } }
From source file:unimelb.distributed_project.gui.JacardSimilarityMeasurePanel.java
/** * Measure button action perform function for triggering the thread to perform Jacard * Similarity measurement. It takes topNearestWordtextField's text as an input parameter to * execute the distance measurement in word2vec library. * * @param e ActionEvent object/* w ww.j av a 2 s. c o m*/ */ private void measureButtonActionPerformed(ActionEvent e) { if (!word2vecFilePath1.equals("") && word2vecFilePath1 != null && !word2vecFilePath2.equals("") && word2vecFilePath2 != null && wordList != null) { word2vecFilePath1 = word2vecFilePath1TextField.getText(); word2vecFilePath2 = word2vecFilePath2TextField.getText(); jcardSimFilePath = simOutputPathTextField.getText(); if (!topNearestWordtextField.getText().equals("")) topNearestWords = new Integer(topNearestWordtextField.getText()); Thread measureThread = new Thread(new Runnable() { @Override public void run() { ListModel model = wordList.getModel(); try { if (jcardSimFilePath.equals("")) jcardSimFilePath = "./jcard_sim.txt"; BufferedWriter bw = new BufferedWriter(new FileWriter(jcardSimFilePath)); for (int i = 0; i < model.getSize(); i++) { StringBuilder output = new StringBuilder(); output.append(model.getElementAt(i) + ","); log.debug(model.getElementAt(i)); double jcardSimScore = TweetWord2VecUtils.jcardSim( TweetWord2VecUtils.runModelNearest(word2vecFilePath1, (String) model.getElementAt(i), topNearestWords), TweetWord2VecUtils.runModelNearest(word2vecFilePath2, (String) model.getElementAt(i), topNearestWords)); output.append(jcardSimScore + "\n"); bw.write(output.toString()); log.debug(i + "." + jcardSimScore); } bw.close(); } catch (IOException ioe) { log.debug("create buffer writer fails"); } log.debug( "done JcardSimilarity Measure, enable all the button "); browseButton1.setEnabled(true); browseButton2.setEnabled(true); loadListButton.setEnabled(true); measureButton.setEnabled(true); browseButton3.setEnabled(true); visualizedButton.setEnabled(true); JOptionPane.showMessageDialog(mainFrame, "JacardSimilarity Measurement is done", "JacardSimilarity Measurement", JOptionPane.INFORMATION_MESSAGE); } }); measureThread.start(); browseButton1.setEnabled(false); browseButton2.setEnabled(false); loadListButton.setEnabled(false); measureButton.setEnabled(false); browseButton3.setEnabled(false); visualizedButton.setEnabled(false); } else { JOptionPane.showMessageDialog(this.mainFrame, "Please suggest files and load wordOfList", "file is not selected", JOptionPane.ERROR_MESSAGE); } }