List of usage examples for javax.swing DefaultListModel get
public E get(int index)
From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java
public void moveLookupItem(boolean up) { if (canMoveLookupItem(up)) { int currentIndex = theDataLookupList.getSelectedIndex(); int otherIndex; if (up) { otherIndex = currentIndex - 1; } else {// ww w. j ava2 s .c om otherIndex = currentIndex + 1; } DefaultListModel model = (DefaultListModel) theDataLookupList.getModel(); MetaDataListValues currentItem = (MetaDataListValues) model.get(currentIndex); currentItem.setSortOrder(otherIndex); MetaDataListValues itemToSwapWith = (MetaDataListValues) model.get(otherIndex); itemToSwapWith.setSortOrder(currentIndex); model.set(currentIndex, itemToSwapWith); model.set(otherIndex, currentItem); theDataLookupList.setSelectedIndex(otherIndex); setDirty(true); updateDataLookupValues(); configuratorFrame.checkButtons(); } }
From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java
public ArrayList<MetaDataListValues> getDataLookupItems() { DefaultListModel model = (DefaultListModel) theDataLookupList.getModel(); ArrayList<MetaDataListValues> values = new ArrayList<MetaDataListValues>(); for (int i = 0; i < model.size(); i++) { values.add((MetaDataListValues) model.get(i)); }/*from ww w . ja v a2s .co m*/ Collections.sort(values, new MetaDataListValuesComparator()); for (int i = 0; i < values.size(); i++) { values.get(i).setSortOrder(i); } return values; }
From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java
public void saveDataLookupItem(String value, String display) { if (theDataLookupList.getSelectedIndex() > -1) { DefaultListModel model = (DefaultListModel) theDataLookupList.getModel(); MetaDataListValues existingValue = (MetaDataListValues) model.get(theDataLookupList.getSelectedIndex()); existingValue.setValue(value);/* ww w .ja v a 2s . c o m*/ existingValue.setDisplay(display); theDataLookupList.setSelectedIndex(-1); updateDataLookupValues(); } else { configuratorFrame.showError(errorHeader, "Invalid selection saving meta data"); return; } }
From source file:nz.govt.natlib.ndha.manualdeposit.MetaDataTest.java
@Test public final void testLookupData() { loadConfigFile();/*from w w w .ja va 2s .c o m*/ theFrame.lstDataList.setSelectedIndex(0); theFrame.cmbDataType.setSelectedItem(EDataType.MultiSelect); assertTrue(theFrame.getTheData().getDataType().equals(EDataType.MultiSelect)); assertTrue(theFrame.pnlListItems.isVisible()); DefaultListModel model = (DefaultListModel) theFrame.lstListItems.getModel(); assertTrue(model.size() == 0); assertFalse(metaDataPresenter.canSaveLookupData(null)); assertFalse(metaDataPresenter.canSaveLookupData("")); assertTrue(metaDataPresenter.canSaveLookupData("Test")); assertFalse(metaDataPresenter.canDeleteLookupData()); boolean failed = false; try { // Can't save unless something is selected - should add instead // MetaDataListValues value = MetaDataListValues.create("Stuff", // "Stuff", 0); metaDataPresenter.saveDataLookupItem("Stuff", "Stuff"); } catch (Exception ex) { failed = true; } // assertTrue(failed); MetaDataListValues value1 = MetaDataListValues.create("Value 1", "Value 1", 0); metaDataPresenter.addDataLookupItem(value1.getValue(), value1.getDisplay()); MetaDataListValues value2 = MetaDataListValues.create("Value 2", "Value 2", 1); metaDataPresenter.addDataLookupItem(value2.getValue(), value2.getDisplay()); MetaDataListValues value3 = MetaDataListValues.create("Value 3", "Value 3", 2); metaDataPresenter.addDataLookupItem(value3.getValue(), value3.getDisplay()); assertTrue(model.getSize() == 3); theFrame.lstListItems.setSelectedIndex(0); MetaDataListValues newValue = MetaDataListValues.create("New Value", "New Value", 3); metaDataPresenter.saveDataLookupItem(newValue.getValue(), newValue.getDisplay()); MetaDataListValues testValue = (MetaDataListValues) theFrame.lstListItems.getSelectedValue(); assertTrue(testValue.getDisplay().equals(newValue.getDisplay())); assertTrue(testValue.getValue().equals(newValue.getValue())); assertTrue(metaDataPresenter.canMoveLookupItem(false)); assertFalse(metaDataPresenter.canMoveLookupItem(true)); metaDataPresenter.moveLookupItem(false); assertTrue(metaDataPresenter.canMoveLookupItem(false)); assertTrue(metaDataPresenter.canMoveLookupItem(true)); assertTrue(theFrame.lstListItems.getSelectedIndex() == 1); metaDataPresenter.moveLookupItem(true); assertTrue(metaDataPresenter.canMoveLookupItem(false)); assertFalse(metaDataPresenter.canMoveLookupItem(true)); assertTrue(theFrame.lstListItems.getSelectedIndex() == 0); theFrame.lstListItems.setSelectedIndex(2); assertFalse(metaDataPresenter.canMoveLookupItem(false)); assertTrue(metaDataPresenter.canMoveLookupItem(true)); assertTrue(metaDataPresenter.canDeleteLookupData()); metaDataPresenter.deleteLookupItem(); assertTrue(model.size() == 2); testValue = (MetaDataListValues) model.get(0); assertTrue(testValue.getDisplay().equals(newValue.getDisplay())); assertTrue(testValue.getValue().equals(newValue.getValue())); testValue = (MetaDataListValues) model.get(1); assertTrue(testValue.getDisplay().equals(value2.getDisplay())); assertTrue(testValue.getValue().equals(value2.getValue())); }
From source file:org.jtrfp.trcl.flow.GameShell.java
private void registerPODs() { DefaultListModel<String> podList = tr.config.getPodList(); for (int i = 0; i < podList.size(); i++) { final String podPath = podList.get(i); if (podPath != null) { final File file = new File(podPath); PodFile pod = new PodFile(file); try { tr.getResourceManager().registerPOD(file.getAbsolutePath(), pod); } catch (FileLoadException e) { JOptionPane.showMessageDialog(tr.getRootWindow(), "Failed to parse (understand) POD file " + podPath, "Parsing failure", JOptionPane.ERROR_MESSAGE); } //end catch(...) } //end if(!null) } //end for(pods) }
From source file:org.jtrfp.trcl.gui.ConfigWindow.java
private void readSettingsToPanel() { modStereoWidthSlider.setValue((int) (config.getModStereoWidth() * 100.)); chckbxLinearInterpolation.setSelected(config.isAudioLinearFiltering()); chckbxBufferLag.setSelected(config.isAudioBufferLag()); final int bSize = config.getAudioBufferSize(); for (AudioBufferSize abs : AudioBufferSize.values()) if (abs.getSizeInFrames() == bSize) audioBufferSizeCB.setSelectedItem(abs); missionLM.removeAllElements();/*w w w . j a va2 s . c o m*/ for (String vox : config.getMissionList()) { if (isBuiltinVOX(vox)) missionLM.addElement(vox); else if (checkVOX(new File(vox))) missionLM.addElement(vox); } //end for(vox) String missionSelection = config.getVoxFile(); for (int i = 0; i < missionLM.getSize(); i++) { if (missionLM.get(i).contentEquals(missionSelection)) missionList.setSelectedIndex(i); } podLM.removeAllElements(); final DefaultListModel<String> podList = config.getPodList(); for (int i = 0; i < podList.size(); i++) { final String pod = podList.get(i); if (pod != null) if (checkPOD(new File(pod))) podLM.addElement(pod); } soundOutputSelectorGUI.readToPanel(config); }
From source file:tvbrowser.core.search.AbstractSearcher.java
public synchronized Program[] search(ProgramFieldType[] fieldArr, Date startDate, int nrDays, Channel[] channels, boolean sortByStartTime, ProgressMonitor progress, final DefaultListModel listModel) { // Should we search in all channels? if (channels == null) { channels = Settings.propSubscribedChannels.getChannelArray(); }/* w ww . ja va 2 s. co m*/ if (nrDays < 0) { // Search complete data, beginning yesterday to 4 weeks into the future startDate = Date.getCurrentDate().addDays(-1); nrDays = TvDataBase.getInstance().getMaxSupportedDate().getNumberOfDaysSince(startDate); } // Perform the actual search ArrayList<Program> hitList = new ArrayList<Program>(); int lastDayWithData = 0; if (progress != null) { progress.setMaximum(channels.length * (nrDays + 1)); } for (int day = 0; day <= nrDays; day++) { for (int channelIdx = 0; channelIdx < channels.length; channelIdx++) { if (progress != null) { progress.setValue(day * channels.length + channelIdx); } Channel channel = channels[channelIdx]; if (channel != null) { ChannelDayProgram dayProg = TvDataBase.getInstance().getDayProgram(startDate, channel); if (dayProg != null) { // This day has data -> remember it lastDayWithData = day; // Search this day program for (int i = 0; i < dayProg.getProgramCount(); i++) { final Program prog = dayProg.getProgramAt(i); if (matches(prog, fieldArr)) { if (listModel != null) { SwingUtilities.invokeLater(new Runnable() { public void run() { int insertIndex = 0; for (int index = 0; index < listModel.getSize(); index++) { Program p = (Program) listModel.get(index); if (ProgramUtilities.getProgramComparator().compare(p, prog) < 0) { insertIndex = index + 1; } } listModel.add(insertIndex, prog); } }); } hitList.add(prog); } } } } } // Give up if we did not find data for the last 10 days if ((day - lastDayWithData) > 10) { break; } // The next day startDate = startDate.addDays(1); } // Convert the list into an array Program[] hitArr = new Program[hitList.size()]; hitList.toArray(hitArr); // Sort the array if wanted if (sortByStartTime) { Arrays.sort(hitArr, getStartTimeComparator()); } if (progress != null) { progress.setValue(0); progress.setMessage(""); } // return the result return hitArr; }