Java Code Examples for javax.swing.DefaultListModel#get()

The following examples show how to use javax.swing.DefaultListModel#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: J2SEModularProjectProperties.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void collectLibs(DefaultListModel model, List<String> libs, List<String> jarReferences) {
    for (int i = 0; i < model.size(); i++) {
        ClassPathSupport.Item item = (ClassPathSupport.Item) model.get(i);
        if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) {
            if (!item.isBroken() && !libs.contains(item.getLibrary().getName())) {
                libs.add(item.getLibrary().getName());
            }
        }
        if (item.getType() == ClassPathSupport.Item.TYPE_JAR) {
            if (item.getReference() != null && item.getVariableBasedProperty() == null && !jarReferences.contains(item.getReference())) {
                //TODO reference is null for not yet persisted items.
                // there seems to be no way to generate a reference string without actually
                // creating and writing the property..
                jarReferences.add(item.getReference());
            }
        }
    }
}
 
Example 2
Source File: InjectScript.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
private Boolean reorderProjects(TransferHandler.TransferSupport support) {
    JList list = (JList) support.getComponent();
    try {
        int[] selectedIndices = (int[]) support.getTransferable().getTransferData(INDICES);
        DefaultListModel model = (DefaultListModel) list.getModel();
        JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
        if (dl.getIndex() != -1) {
            for (int selectedIndex : selectedIndices) {
                Object value = model.get(selectedIndex);
                model.removeElement(value);
                model.add(dl.getIndex(), value);
            }
            return true;
        } else {
            LOG.warning("Invalid Drop Location");
        }
    } catch (UnsupportedFlavorException | IOException ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    }
    return false;
}
 
Example 3
Source File: CustomizerLibraries.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void collectLibs(DefaultListModel model, List<String> libs, List<String> jarReferences) {
    for (int i = 0; i < model.size(); i++) {
        ClassPathSupport.Item item = (ClassPathSupport.Item) model.get(i);
        if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) {
            if (!item.isBroken() && !libs.contains(item.getLibrary().getName())) {
                libs.add(item.getLibrary().getName());
            }
        }
        if (item.getType() == ClassPathSupport.Item.TYPE_JAR) {
            if (item.getReference() != null && item.getVariableBasedProperty() == null && !jarReferences.contains(item.getReference())) {
                //TODO reference is null for not yet persisted items.
                // there seems to be no way to generate a reference string without actually
                // creating and writing the property..
                jarReferences.add(item.getReference());
            }
        }
    }
}
 
Example 4
Source File: StateModifier.java    From algorithms-nutshell-2ed with MIT License 6 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e) {
	// must find the one that is selected
	int idx = list.getSelectedIndex();
	DefaultListModel<IMove> dlm = (DefaultListModel<IMove>) list.getModel();
	FreeCellNode node = (FreeCellNode) initial.copy();
	for (int i = 0; i < idx; i++) {
		IMove move = (IMove) dlm.get(i);
		if (move.isValid(node)) {
			move.execute(node);
		} else {
			System.out.println("INVALID MOVE!");
		}
	}
	
	drawer.setNode(node);
	drawer.repaint();
}
 
Example 5
Source File: ListSelectionPanel.java    From nextreports-designer with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void sort(DefaultListModel model) {
	// we need a List for sorting
	int size = model.getSize();
	ArrayList list = new ArrayList();
	for (int x = 0; x < size; ++x) {
		Object o = model.get(x);
		list.add(o);
	}

	if (comp != null) {
	   Collections.sort(list, comp);
	} else {
	   Collections.sort(list);
	}
	// update the model with a sorted List
	for (int x = 0; x < size; ++x) {
		Object obj = list.get(x);			
		if ((model.getElementAt(x) != null) && !model.getElementAt(x).equals(obj)) {
			model.set(x, obj);
		}
	}
}
 
Example 6
Source File: CustomizerLibraries.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void collectLibs(DefaultListModel model, List<String> libs, List<String> jarReferences) {
    for (int i = 0; i < model.size(); i++) {
        ClassPathSupport.Item item = (ClassPathSupport.Item) model.get(i);
        if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) {
            if (!item.isBroken() && !libs.contains(item.getLibrary().getName())) {
                libs.add(item.getLibrary().getName());
            }
        }
        if (item.getType() == ClassPathSupport.Item.TYPE_JAR) {
            if (item.getReference() != null && item.getVariableBasedProperty() == null && !jarReferences.contains(item.getReference())) {
                //TODO reference is null for not yet persisted items.
                // there seems to be no way to generate a reference string without actually
                // creating and writing the property..
                jarReferences.add(item.getReference());
            }
        }
    }
}
 
Example 7
Source File: CSVColumnPanel.java    From javamoney-examples with Apache License 2.0 6 votes vote down vote up
private
void
storeCSVColumnOrder()
{
  DefaultListModel model = (DefaultListModel)getList().getModel();
  int[] order = new int[CSVColumnKeys.values().length];

  for(int len = 0; len < model.getSize(); ++len)
  {
    CSVColumnKeys key = (CSVColumnKeys)model.get(len);

    order[len] = key.ordinal();
  }

  setCSVColumnOrder(order);
}
 
Example 8
Source File: ClassPathFormImpl.java    From jmkvpropedit with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
	DefaultListModel model = (DefaultListModel) _classpathList.getModel();
	int x = _classpathList.getSelectedIndex();
	if (x == -1 || x >= model.getSize() - 1) {
		return;
	}
	Object o = model.get(x + 1);
	model.set(x + 1, model.get(x));
	model.set(x, o);
	_classpathList.setSelectedIndex(x + 1);
}
 
Example 9
Source File: ClassPathUiSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean canEdit( ListSelectionModel selectionModel, DefaultListModel listModel ) {        
    boolean can =  selectionModel.getMinSelectionIndex() == selectionModel.getMaxSelectionIndex() 
                      && selectionModel.getMinSelectionIndex() != -1;
    if (can) {
        ClassPathSupport.Item item = (ClassPathSupport.Item) listModel.get(selectionModel.getMinSelectionIndex());
        can = item != null && item.canEdit();
    }
    return can;
}
 
Example 10
Source File: CPluginDialog.java    From binnavi with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(final ActionEvent event) {
  if (event.getActionCommand().equals("OK")) {
    // When the OK button is clicked, the new plugin
    // selection is written back to the config file.

    configFile.getGeneralSettings().getPlugins().clear();

    final DefaultListModel model = (DefaultListModel) pluginList.getModel();

    for (int i = 0; i < model.getSize(); i++) {
      @SuppressWarnings("unchecked")
      final PluginItem<T> pluginItem = (PluginItem<T>) model.get(i);

      final PluginConfigItem pluginType = new PluginConfigItem();

      pluginType.setName(pluginItem.getObject().getName());
      pluginType.setGUID(pluginItem.getObject().getGuid());
      pluginType.setLoad(pluginList.isChecked(i));

      configFile.getGeneralSettings().getPlugins().add(pluginType);
    }

    setVisible(false);
    dispose();
  } else if (event.getActionCommand().equals("Cancel")) {
    // Don't write the new plugin settings if the user
    // hits the Cancel button.

    setVisible(false);
    dispose();
  }
}
 
Example 11
Source File: BreakpointNestedGroupsDialog.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void moveDownButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveDownButtonActionPerformed
    int[] indexes = displayedGroupsList.getSelectedIndices();
    DefaultListModel displayedModel = (DefaultListModel) displayedGroupsList.getModel();
    for (int index : indexes) {
        Object down = displayedModel.get(index);
        Object up = displayedModel.get(index + 1);
        displayedModel.set(index + 1, down);
        displayedModel.set(index, up);
    }
    for (int i = 0; i < indexes.length; i++) {
        indexes[i]++;
    }
    displayedGroupsList.setSelectedIndices(indexes);
}
 
Example 12
Source File: BreakpointNestedGroupsDialog.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void moveUpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveUpButtonActionPerformed
    int[] indexes = displayedGroupsList.getSelectedIndices();
    DefaultListModel displayedModel = (DefaultListModel) displayedGroupsList.getModel();
    for (int index : indexes) {
        Object down = displayedModel.get(index - 1);
        Object up = displayedModel.get(index);
        displayedModel.set(index, down);
        displayedModel.set(index - 1, up);
    }
    for (int i = 0; i < indexes.length; i++) {
        indexes[i]--;
    }
    displayedGroupsList.setSelectedIndices(indexes);
}
 
Example 13
Source File: TroopFilterDialog.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
private void fireSaveFilterSettingsEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireSaveFilterSettingsEvent
    String setName = jNewFilterName.getText();
    DefaultListModel filterModel = (DefaultListModel) jFilterList.getModel();

    if (setName == null || setName.length() == 0) {
        JOptionPaneHelper.showInformationBox(this, "Bitte einen Namen für das neue Filterset angeben", "Information");
        return;
    }

    if (filterModel.getSize() == 0) {
        JOptionPaneHelper.showInformationBox(this, "Ein Filterset muss mindestens einen Eintrag enthalten", "Information");
        return;
    }

    if (filterSets.get(setName) != null) {
        if (JOptionPaneHelper.showQuestionConfirmBox(this, "Das Filterset '" + setName + "' existiert bereits.\nMöchtest du es überschreiben?", "Bestätigung", "Nein", "Ja") != JOptionPane.OK_OPTION) {
            return;
        }
    }

    StringBuilder b = new StringBuilder();
    b.append(setName).append(",");
    List<TroopFilterElement> elements = new LinkedList<>();
    for (int j = 0; j < filterModel.size(); j++) {
        TroopFilterElement elem = (TroopFilterElement) filterModel.get(j);
        elements.add(new TroopFilterElement(elem.getUnit(), elem.getMin(), elem.getMax()));
    }

    filterSets.put(setName, elements);
    updateFilterSetList();
    saveFilterSets();
}
 
Example 14
Source File: CustomizerLibraries.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void updateJars(DefaultListModel model) {
    for (int i = 0; i < model.size(); i++) {
        ClassPathSupport.Item item = (ClassPathSupport.Item) model.get(i);
        if (item.getType() == ClassPathSupport.Item.TYPE_JAR) {
            if (item.getReference() != null) {
                item.updateJarReference(uiProperties.getProject().getAntProjectHelper());
            }
        }
    }
    
}
 
Example 15
Source File: ClassPathFormImpl.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
	DefaultListModel model = (DefaultListModel) _classpathList.getModel();
	int x = _classpathList.getSelectedIndex();
	if (x == -1 || x >= model.getSize() - 1) {
		return;
	}
	Object o = model.get(x + 1);
	model.set(x + 1, model.get(x));
	model.set(x, o);
	_classpathList.setSelectedIndex(x + 1);
}
 
Example 16
Source File: IconCellEditor.java    From gameserver with Apache License 2.0 5 votes vote down vote up
@Override
	public Component getTableCellEditorComponentAtModel(JTable table, Object value,
			boolean isSelected, int row, int column) {
		this.cellValue = value;
		
		DefaultListModel listModel = new DefaultListModel();
//		File iconDir = ImageUtil.TMP_ASSETS_ICONS_FILE;
//		File[] iconFiles = iconDir.listFiles(new FilenameFilter() {
//			
//			@Override
//			public boolean accept(File dir, String name) {
//				if ( name.endsWith(".png") ) {
//					return true;
//				}
//				return false;
//			}
//		});
//		for ( int i=0; i<iconFiles.length; i++ ) {
//			listModel.addElement(iconFiles[i]);
//		}
		for ( String iconName : MainFrame.ICON_MAPS.keySet() ) {
			listModel.addElement(iconName);
		}
		
		ListSelectDialog dialog = new ListSelectDialog(listModel, new IconCellRenderer());
		int selectIndex = dialog.getList().getSelectedIndex();
		if ( selectIndex > -1 ) {
			Object selectValue = listModel.get(selectIndex);
			String iconId = selectValue.toString();
			this.cellValue = iconId;
			table.getModel().setValueAt(cellValue, row, column);
		}
		
		return null;
	}
 
Example 17
Source File: CustomizerLibraries.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void updateJars(DefaultListModel model) {
    for (int i = 0; i < model.size(); i++) {
        ClassPathSupport.Item item = (ClassPathSupport.Item) model.get(i);
        if (item.getType() == ClassPathSupport.Item.TYPE_JAR) {
            if (item.getReference() != null) {
                item.updateJarReference(uiProperties.getProject().getAntProjectHelper());
            }
        }
    }
    
}
 
Example 18
Source File: ClassPathFormImpl.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
	int x = _classpathList.getSelectedIndex();
	if (x < 1) {
		return;
	}
	DefaultListModel model = (DefaultListModel) _classpathList.getModel();
	Object o = model.get(x - 1);
	model.set(x - 1, model.get(x));
	model.set(x, o);
	_classpathList.setSelectedIndex(x - 1);
}
 
Example 19
Source File: ClassPathFormImpl.java    From PyramidShader with GNU General Public License v3.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
	int x = _classpathList.getSelectedIndex();
	if (x < 1) {
		return;
	}
	DefaultListModel model = (DefaultListModel) _classpathList.getModel();
	Object o = model.get(x - 1);
	model.set(x - 1, model.get(x));
	model.set(x, o);
	_classpathList.setSelectedIndex(x - 1);
}
 
Example 20
Source File: CommonSettingsDialog.java    From megamek with GNU General Public License v2.0 4 votes vote down vote up
private <T> void moveElement(DefaultListModel<T> srcModel, int srcIndex, int trgIndex) {
    T dragElement = srcModel.get(srcIndex);
    srcModel.remove(srcIndex);
    srcModel.add(trgIndex, dragElement);
}