List of usage examples for javax.swing ListModel getElementAt
E getElementAt(int index);
From source file:org.eclipse.wb.tests.designer.swing.model.component.JListTest.java
public void test_parsing() throws Exception { parseContainer("public class Test extends JPanel {", " public Test() {", " JList list = new JList();", " add(list);", " list.setModel(new AbstractListModel() {", " String[] values = {'111', '222', '333'};", " public int getSize() {", " return values.length;", " }", " public Object getElementAt(int i) {", " return values[i];", " }", " });", " }", "}"); refresh();/* w w w . ja v a 2s. co m*/ ComponentInfo listInfo = getJavaInfoByName("list"); JList listObject = (JList) listInfo.getObject(); // validate model { ListModel model = listObject.getModel(); assertNotNull(model); assertEquals(3, model.getSize()); assertEquals("111", model.getElementAt(0)); assertEquals("222", model.getElementAt(1)); assertEquals("333", model.getElementAt(2)); } // validate items from editor { Property modelProperty = listInfo.getPropertyByTitle("model"); String[] actualItems = ListModelPropertyEditor.getItems(modelProperty); assertTrue(ArrayUtils.isEquals(new String[] { "111", "222", "333" }, actualItems)); } }
From source file:org.freeplane.features.export.mindmapmode.ExportWithXSLT.java
/** * @param map/*from w w w . j a v a2s . c om*/ */ static void copyIconsToDirectory(final MapModel map, final String directoryName) { final ListModel icons = map.getIconRegistry().getIconsAsListModel(); for (int i = 0; i < icons.getSize(); i++) { final UIIcon icon = (UIIcon) icons.getElementAt(i); final String iconName = icon.getName(); final StringBuilder sb = new StringBuilder(directoryName); final int lastIndexOfSeparator = iconName.lastIndexOf('/'); if (lastIndexOfSeparator != -1) { sb.append(File.separatorChar); sb.append(iconName.substring(0, lastIndexOfSeparator)); } final File destinationDirectory = new File(sb.toString()); destinationDirectory.mkdirs(); FileUtils.copyFromURL(icon.getUrl(), destinationDirectory); } }
From source file:org.omegat.gui.scripting.ScriptingWindow.java
private void initWindowLayout() { // set default size and position frame.setBounds(50, 80, 1150, 650);//from w w w .j a v a 2 s. c o m StaticUIUtils.persistGeometry(frame, Preferences.SCRIPTWINDOW_GEOMETRY_PREFIX); frame.getContentPane().setLayout(new BorderLayout(0, 0)); m_scriptList = new JList<>(); JScrollPane scrollPaneList = new JScrollPane(m_scriptList); m_scriptList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { onListSelectionChanged(); } } }); m_scriptList.addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { ListModel<ScriptItem> lm = m_scriptList.getModel(); int index = m_scriptList.locationToIndex(e.getPoint()); if (index > -1) { m_scriptList.setToolTipText(lm.getElementAt(index).getFile().getName()); } } }); m_txtResult = new JEditorPane(); JScrollPane scrollPaneResults = new JScrollPane(m_txtResult); //m_txtScriptEditor = new StandardScriptEditor(); m_txtScriptEditor = getScriptEditor(); m_txtScriptEditor.initLayout(this); JSplitPane splitPane1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, m_txtScriptEditor.getPanel(), scrollPaneResults); splitPane1.setOneTouchExpandable(true); splitPane1.setDividerLocation(430); Dimension minimumSize1 = new Dimension(100, 50); //scrollPaneEditor.setMinimumSize(minimumSize1); scrollPaneResults.setMinimumSize(minimumSize1); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scrollPaneList, splitPane1); splitPane.setOneTouchExpandable(true); splitPane.setDividerLocation(250); Dimension minimumSize = new Dimension(100, 50); scrollPaneList.setMinimumSize(minimumSize); scrollPaneResults.setMinimumSize(minimumSize); frame.getContentPane().add(splitPane, BorderLayout.CENTER); JPanel panelSouth = new JPanel(); FlowLayout fl_panelSouth = (FlowLayout) panelSouth.getLayout(); fl_panelSouth.setAlignment(FlowLayout.LEFT); frame.getContentPane().add(panelSouth, BorderLayout.SOUTH); setupRunButtons(panelSouth); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.setJMenuBar(createMenuBar()); }
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();/*from w w w .j a v a 2 s. com*/ 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 va2 s . co m } 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(); }/* ww w. jav a 2 s .co m*/ 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; }// w ww .j ava 2 s . c o m } }
From source file:org.springframework.richclient.form.binding.jide.CheckBoxListSelectableBinding.java
/** * @param values/*from ww w.j a v a 2 s .co m*/ * @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/*from ww w . j a v a 2 s . 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 ava 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); } }