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

The following examples show how to use javax.swing.DefaultListModel#contains() . 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: ClassPathUiSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static int[] addJarFiles( DefaultListModel listModel, int[] indices, String filePaths[], File base, 
        String[] variables, Callback callback) {
    int lastIndex = indices == null || indices.length == 0 ? listModel.getSize() - 1 : indices[indices.length - 1];
    int[] indexes = new int[filePaths.length];
    for( int i = 0, delta = 0; i+delta < filePaths.length; ) {            
        int current = lastIndex + 1 + i;
        ClassPathSupport.Item item = ClassPathSupport.Item.create( filePaths[i], base, null, variables != null ? variables[i] : null);
        if (callback != null) {
            callback.initItem(item);
        }
        if ( !listModel.contains( item ) ) {
            listModel.add( current, item );
            indexes[delta + i] = listModel.indexOf( item );
            i++;
        }
        else {
            indexes[i + delta] = listModel.indexOf( item );
            delta++;
        }            
    }
    return indexes;

}
 
Example 2
Source File: ClassPathUiSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static int[] addArtifacts( DefaultListModel listModel, int[] indices, AntArtifactItem artifactItems[],
        Callback callback) {
    int lastIndex = indices == null || indices.length == 0 ? listModel.getSize() - 1 : indices[indices.length - 1];
    int[] indexes = new int[artifactItems.length];
    for( int i = 0; i < artifactItems.length; i++ ) {
        int current = lastIndex + 1 + i;
        ClassPathSupport.Item item = ClassPathSupport.Item.create( artifactItems[i].getArtifact(), artifactItems[i].getArtifactURI(), null) ;
        if (callback != null) {
            callback.initItem(item);
        }
        if ( !listModel.contains( item ) ) {
            listModel.add( current, item );
        }            
        indexes[i] = listModel.indexOf( item );
    }
    return indexes;
}
 
Example 3
Source File: PathUiSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static int[] addFolders(DefaultListModel<BasePathSupport.Item> listModel, int[] indices, String[] files) {

        int lastIndex = indices == null || indices.length == 0 ? listModel.getSize() - 1 : indices[indices.length - 1];
        int[] indexes = new int[files.length];
        for (int i = 0, delta = 0; i + delta < files.length;) {
            int current = lastIndex + 1 + i;
            BasePathSupport.Item item = BasePathSupport.Item.create(files[i + delta], null);
            if (!listModel.contains(item)) {
                listModel.add(current, item);
                indexes[delta + i] = current;
                i++;
            } else {
                indexes[i + delta] = listModel.indexOf(item);
                delta++;
            }
        }
        return indexes;
    }
 
Example 4
Source File: RoarPreferencePanel.java    From Spark with Apache License 2.0 6 votes vote down vote up
private void toggleDifferentSettingsForKeyword(boolean isSelected) {

        DefaultListModel<ColorTypes> model = (DefaultListModel<ColorTypes>) _singleColorlist.getModel();
        JTextField duration = retrieveComponent("keyword.duration", JTextField.class);

        if (isSelected) {
            if (!model.contains(ColorTypes.BACKGROUNDCOLOR_KEYWORD)) {
                model.addElement(ColorTypes.BACKGROUNDCOLOR_KEYWORD);
                model.addElement(ColorTypes.HEADERCOLOR_KEYWORD);
                model.addElement(ColorTypes.TEXTCOLOR_KEYWORD);
            }
            duration.setEnabled(true);
        } else {
            model.removeElement(ColorTypes.BACKGROUNDCOLOR_KEYWORD);
            model.removeElement(ColorTypes.HEADERCOLOR_KEYWORD);
            model.removeElement(ColorTypes.TEXTCOLOR_KEYWORD);
            duration.setEnabled(false);
            duration.setText(_duration.getText());
        }
    }
 
Example 5
Source File: RoarPreferencePanel.java    From Spark with Apache License 2.0 6 votes vote down vote up
private void toggleDifferentSettingsForGroup(boolean isSelected) {

        DefaultListModel<ColorTypes> model = (DefaultListModel<ColorTypes>) _singleColorlist.getModel();
        JTextField duration = retrieveComponent("group.duration", JTextField.class);

        if (isSelected) {
            if (!model.contains(ColorTypes.BACKGROUNDCOLOR_GROUP)) {
                model.addElement(ColorTypes.BACKGROUNDCOLOR_GROUP);
                model.addElement(ColorTypes.HEADERCOLOR_GROUP);
                model.addElement(ColorTypes.TEXTCOLOR_GROUP);
            }
            duration.setEnabled(true);
        } else {
            model.removeElement(ColorTypes.BACKGROUNDCOLOR_GROUP);
            model.removeElement(ColorTypes.HEADERCOLOR_GROUP);
            model.removeElement(ColorTypes.TEXTCOLOR_GROUP);
            duration.setEnabled(false);
            duration.setText(_duration.getText());
        }
    }
 
Example 6
Source File: NVCompress.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void btnAddFilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddFilesActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Add input files");
    chooser.setMultiSelectionEnabled(true);
    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){
        File[] files = chooser.getSelectedFiles();
        for (File file : files){
            if (file.exists() && !file.isDirectory()){
                // add to file list
                DefaultListModel listModel = (DefaultListModel) lstFileList.getModel();
                if (!listModel.contains(file))
                    listModel.addElement(file);
            }
        }
    }
}
 
Example 7
Source File: GUIRegistrationPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void keyStrokeChangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_keyStrokeChangeActionPerformed
    KeyStroke[] keyStrokes = ShortcutEnterPanel.showDialog();
    if (keyStrokes != null && keyStrokes.length > 0) {
        String newShortcut = WizardUtils.keyStrokesToString(keyStrokes);
        DefaultListModel lm = (DefaultListModel)shortcutsList.getModel();
        if (!lm.contains(newShortcut)) {
            lm.addElement(newShortcut);
            data.setKeyStroke(WizardUtils.keyStrokesToLogicalString(keyStrokes));
            shortcutsList.setSelectedValue(newShortcut, true);
            checkValidity();
        }
    }        
}
 
Example 8
Source File: VillageTagFrame.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
private void fireAddTagEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireAddTagEvent
    Tag tag = null;
    try {
        tag = (Tag) jTagsChooser.getSelectedItem();
    } catch (ClassCastException cce) {
        //no tags availabler
        JOptionPaneHelper.showWarningBox(this, "Keine Gruppen vorhanden. Bitte importiere zuerst Gruppen aus dem Spiel oder lege sie in der Gruppen-Ansicht manuell an.", "Warnung");
        return;
    }
    DefaultListModel model = (DefaultListModel) jTagsList.getModel();
    if (jPlayerName.getText().equals("Mehrfachauswahl")) {
        if (tag == null) {
            return;
        }

        for (int i = 0; i < jVillageList.getItemCount(); i++) {
            Village v = (Village) jVillageList.getItemAt(i);
            if (v.getTribe() != Barbarians.getSingleton()) {
                TagManager.getSingleton().addTag(v, tag.getName());
            }
        }
        if (!model.contains(tag)) {
            model.addElement(tag);
        }
    } else {
        Village selection = (Village) jVillageList.getSelectedItem();
        if ((selection == null) || (tag == null)) {
            return;
        }
        if (!model.contains(tag)) {
            model.addElement(tag);
            TagManager.getSingleton().addTag(selection, tag.getName());
        }
    }
}
 
Example 9
Source File: QFixMessengerFrame.java    From quickfix-messenger with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void updateRecentList(Message recentMsg)
{
	if ("Free Text".equals(recentMsg.getName()))
	{
		return;
	}

	String key = frame.activeDictionary.getFullVersion();
	Map<String, DefaultListModel<Message>> tmpMap = frame.recentMessagesMap;
	DefaultListModel<Message> tmpListModel;

	if (tmpMap.containsKey(key))
	{
		tmpListModel = tmpMap.get(key);
		if (tmpListModel.contains(recentMsg))
		{
			tmpListModel.remove(tmpListModel.indexOf(recentMsg));
			tmpListModel.add(0, recentMsg);
		} else
		{
			tmpListModel.add(0, recentMsg);
		}
	} else
	{
		tmpListModel = new DefaultListModel<Message>();
		tmpListModel.add(0, recentMsg);
		tmpMap.put(key, tmpListModel);
	}

	frame.recentMessagesList.setModel(tmpMap.get(key));
}
 
Example 10
Source File: BuildQueuePanel.java    From freecol with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the list of available buildings to build
 *
 * This method will verify whether a building can be built by
 *      checking against the following criteria:
 *       * Does the Colony meet the population limit to build?
 *       * Does the new building require a special circumstance,
 *              such as a prerequisite unit or building?
 */
private void updateBuildingList() {
    final Specification spec = getSpecification();
    final DefaultListModel<BuildableType> current
        = (DefaultListModel<BuildableType>)this.buildQueueList.getModel();
    final DefaultListModel<BuildingType> buildings
        = (DefaultListModel<BuildingType>)this.buildingList.getModel();
    buildings.clear();
    Set<BuildableType> unbuildableTypes = new HashSet<>();

    // For each building type, find out if it is buildable, and
    // reasons to not build it (and perhaps display a lock icon).
    for (BuildingType bt : spec.getBuildingTypeList()) {
        if (unbuildableTypes.contains(bt)) continue;

        // Impossible upgrade path
        if (bt.getUpgradesFrom() != null
            && unbuildableTypes.contains(bt.getUpgradesFrom())) {
            unbuildableTypes.add(bt);
            continue;
        }

        // Ignore pre-built buildings
        if (!bt.needsGoodsToBuild()) continue;
        
        // Only one building of any kind
        if (current.contains(bt) || hasBuildingType(bt)) continue;
        
        List<String> reasons = new ArrayList<>(8);

        // Coastal limit
        if (bt.hasAbility(Ability.COASTAL_ONLY)
            && !this.colony.getTile().isCoastland()) {
            reasons.add(Messages.message(StringTemplate
                    .template("buildQueuePanel.coastalOnly")));
        }

        // Population limit
        if (bt.getRequiredPopulation() > this.colony.getUnitCount()) {
            reasons.add(Messages.message(StringTemplate
                    .template("buildQueuePanel.populationTooSmall")
                    .addAmount("%number%", bt.getRequiredPopulation())));
        }

        // Spec limits
        for (Limit limit : transform(bt.getLimits(),
                                     l -> !l.evaluate(this.colony))) {
            reasons.add(Messages.getDescription(limit));
        }

        // Missing ability
        if (!checkAbilities(bt, reasons)) unbuildableTypes.add(bt);

        // Upgrade path is blocked
        Building colonyBuilding = this.colony.getBuilding(bt);
        BuildingType up = bt.getUpgradesFrom();
        if (up != null && !current.contains(up)
            && (colonyBuilding == null || colonyBuilding.getType() != up)) {
            reasons.add(Messages.getName(up));
        }

        lockReasons.put(bt, (reasons.isEmpty()) ? null
            : Messages.message(StringTemplate
                .template("buildQueuePanel.requires")
                .addName("%string%", join("/", reasons))));
        if (reasons.isEmpty()
            || showAllBox.isSelected()) buildings.addElement(bt);
    }
}