javax.swing.DefaultListModel#contains ( )源码实例Demo

下面列出了javax.swing.DefaultListModel#contains ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: ClassPathUiSupport.java
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;

}
 
源代码2 项目: netbeans   文件: ClassPathUiSupport.java
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;
}
 
源代码3 项目: netbeans   文件: PathUiSupport.java
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;
    }
 
源代码4 项目: Spark   文件: RoarPreferencePanel.java
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());
        }
    }
 
源代码5 项目: Spark   文件: RoarPreferencePanel.java
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());
        }
    }
 
源代码6 项目: MikuMikuStudio   文件: NVCompress.java
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);
            }
        }
    }
}
 
源代码7 项目: netbeans   文件: GUIRegistrationPanel.java
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();
        }
    }        
}
 
源代码8 项目: dsworkbench   文件: VillageTagFrame.java
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());
        }
    }
}
 
源代码9 项目: quickfix-messenger   文件: QFixMessengerFrame.java
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));
}
 
源代码10 项目: freecol   文件: BuildQueuePanel.java
/**
 * 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);
    }
}