List of usage examples for javax.swing DefaultListModel getSize
public int getSize()
From source file:nz.govt.natlib.ndha.manualdeposit.MetaDataTest.java
@Test public final void testMoveItems() { loadConfigFile();/* w w w.j a v a 2s. c o m*/ DefaultListModel model = (DefaultListModel) theFrame.lstDataList.getModel(); theFrame.lstDataList.setSelectedIndex(0); assertTrue(metaDataPresenter.canMoveItem(false)); assertFalse(metaDataPresenter.canMoveItem(true)); metaDataPresenter.moveItem(false); assertTrue(theFrame.lstDataList.getSelectedIndex() == 1); assertTrue(metaDataPresenter.canMoveItem(false)); assertTrue(metaDataPresenter.canMoveItem(true)); metaDataPresenter.moveItem(true); assertTrue(theFrame.lstDataList.getSelectedIndex() == 0); assertTrue(metaDataPresenter.canMoveItem(false)); assertFalse(metaDataPresenter.canMoveItem(true)); theFrame.lstDataList.setSelectedIndex(model.getSize() - 1); assertTrue(metaDataPresenter.canMoveItem(true)); assertFalse(metaDataPresenter.canMoveItem(false)); }
From source file:org.executequery.gui.editor.ManageShortcutsPanel.java
public void deleteShortcut() { int index = selectedIndex(); if (index != -1) { try {//from w w w .ja v a2s .c om list.removeListSelectionListener(this); DefaultListModel model = modelFromList(); model.remove(index); lastSelectedIndex = -1; int size = model.getSize(); if (size > 0) { if (index > size - 1) { list.setSelectedIndex(size - 1); } else { list.setSelectedIndex(index); } shortcutSelected(); } else { textPane.setText(""); } } finally { list.addListSelectionListener(this); } } }
From source file:org.n52.ifgicopter.spf.output.GpxOutputPlugin.java
/** * /* w w w . j a va 2 s . c o m*/ */ protected void updateGUI() { if (this.gpx == null) return; final String t = this.gpx.xmlText(GPX_OPTIONS); EventQueue.invokeLater(new Runnable() { @Override public void run() { GpxOutputPlugin.this.textPane.setText(t); GpxOutputPlugin.this.outputFileLabel .setText("<html><b>Output file: </b>" + getGpxFilePath() + "</html>"); DefaultListModel model = (DefaultListModel) GpxOutputPlugin.this.valuesToSaveList.getModel(); // update list if (model.getSize() < GpxOutputPlugin.this.availableDataKeys.size()) { if (model.contains(NO_DATA_LIST_ELEMENT)) model.remove(model.indexOf(NO_DATA_LIST_ELEMENT)); for (String s : GpxOutputPlugin.this.availableDataKeys) { if (!model.contains(s)) { model.addElement(s); } } } } }); }
From source file:org.openmrs.module.muzimabiometrics.panels.ScanFingerprint.java
private boolean SearchDevice() { DefaultListModel model = (DefaultListModel) scannerList.getModel(); model.clear();//from w w w . ja v a 2 s. co m for (NDevice device : deviceManager.getDevices()) { model.addElement(device); } NFingerScanner scanner = (NFingerScanner) FingersTools.getInstance().getClient().getFingerScanner(); if ((scanner == null) && (model.getSize() > 0)) { scannerList.setSelectedIndex(0); return true; } else if (scanner != null) { scannerList.setSelectedValue(scanner, true); return true; } return false; }
From source file:se.cambio.cds.gdl.editor.view.panels.ListPanel.java
private void updateListModel(DefaultListModel dlm) { List<String> elements = new ArrayList<String>(); for (int i = 0; i < dlm.getSize(); i++) { String value = (String) dlm.getElementAt(i); if (value != null) { value = value.replace("\"", "\\\""); }//from w w w . j a va 2 s. c om elements.add(value); } _context.setValue(_xPath, elements); }
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(); }//from w w w. ja va2 s . c o 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; }
From source file:util.ui.UiUtilities.java
/** * Moves Selected Items from one List to another * * @param fromList/*from w w w . j ava 2s . c om*/ * Move from this List * @param toList * Move into this List * @return Moved Elements */ public static Object[] moveSelectedItems(JList fromList, JList toList) { DefaultListModel fromModel = (DefaultListModel) fromList.getModel(); DefaultListModel toModel = (DefaultListModel) toList.getModel(); // get the selection int[] selection = fromList.getSelectedIndices(); if (selection.length == 0) { return new Object[] {}; } Object[] objects = new Object[selection.length]; for (int i = 0; i < selection.length; i++) { objects[i] = fromModel.getElementAt(selection[i]); } // get the target insertion position int targetPos = toList.getMaxSelectionIndex(); if (targetPos == -1) { targetPos = toModel.getSize(); } else { targetPos++; } // suppress updates on both lists if (selection.length >= 5) { fromList.setModel(new DefaultListModel()); toList.setModel(new DefaultListModel()); } // move the elements for (int i = selection.length - 1; i >= 0; i--) { Object value = fromModel.remove(selection[i]); toModel.add(targetPos, value); } if (selection.length >= 5) { fromList.setModel(fromModel); toList.setModel(toModel); } // change selection of the fromList if (fromModel.getSize() > 0) { int newSelection = selection[0]; if (newSelection >= fromModel.getSize()) { newSelection = fromModel.getSize() - 1; } fromList.setSelectedIndex(newSelection); } if (selection.length >= 5) { fromList.repaint(); fromList.revalidate(); toList.repaint(); toList.revalidate(); } // change selection of the toList toList.setSelectionInterval(targetPos, targetPos + selection.length - 1); // ensure the selection is visible toList.ensureIndexIsVisible(toList.getMaxSelectionIndex()); toList.ensureIndexIsVisible(toList.getMinSelectionIndex()); return objects; }
From source file:util.ui.UiUtilities.java
/** * Moves Selected Items from one List to another * * @param fromList/*from w w w. j a v a2 s.c om*/ * Move from this List * @param toList * Move into this List * @param row * The target row where to insert * @return Moved Elements */ public static Object[] moveSelectedItems(JList fromList, JList toList, int row) { DefaultListModel fromModel = (DefaultListModel) fromList.getModel(); DefaultListModel toModel = (DefaultListModel) toList.getModel(); // get the selection int[] selection = fromList.getSelectedIndices(); if (selection.length == 0) { return new Object[] {}; } Object[] objects = new Object[selection.length]; for (int i = 0; i < selection.length; i++) { objects[i] = fromModel.getElementAt(selection[i]); } // move the elements for (int i = selection.length - 1; i >= 0; i--) { Object value = fromModel.remove(selection[i]); toModel.insertElementAt(value, row); } // change selection of the fromList if (fromModel.getSize() > 0) { int newSelection = selection[0]; if (newSelection >= fromModel.getSize()) { newSelection = fromModel.getSize() - 1; } // fromList.setSelectedIndex(-1); } // change selection of the toList toList.setSelectionInterval(row, row + selection.length - 1); // ensure the selection is visible toList.ensureIndexIsVisible(toList.getMaxSelectionIndex()); toList.ensureIndexIsVisible(toList.getMinSelectionIndex()); return objects; }
From source file:util.ui.UiUtilities.java
/** * Move selected Items in the JList/*from w ww .j a v a 2 s. c o m*/ * * @param list * Move Items in this List * @param nrRows * Move Items nrRows up/down */ public static void moveSelectedItems(JList list, int nrRows) { DefaultListModel model = (DefaultListModel) list.getModel(); // get the selection int[] selection = list.getSelectedIndices(); if (selection.length == 0) { return; } // Remove the selected items Object[] items = new Object[selection.length]; for (int i = selection.length - 1; i >= 0; i--) { items[i] = model.remove(selection[i]); } // insert the elements at the target position int targetPos = selection[0] + nrRows; targetPos = Math.max(targetPos, 0); targetPos = Math.min(targetPos, model.getSize()); for (int i = 0; i < items.length; i++) { model.add(targetPos + i, items[i]); } // change selection of the toList list.setSelectionInterval(targetPos, targetPos + selection.length - 1); // ensure the selection is visible list.ensureIndexIsVisible(list.getMaxSelectionIndex()); list.ensureIndexIsVisible(list.getMinSelectionIndex()); }