Java Code Examples for javax.swing.DefaultComboBoxModel#getIndexOf()

The following examples show how to use javax.swing.DefaultComboBoxModel#getIndexOf() . 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: Repository.java    From netbeans with Apache License 2.0 6 votes vote down vote up
RepositoryConnection getSelectedRCIntern() {
    String urlString;
    try {
        urlString = getUrlString();            
    }
    catch (InterruptedException ex) {
        // should not happen
        Subversion.LOG.log(Level.SEVERE, null, ex);
        return null;
    }
    
    DefaultComboBoxModel dcbm = (DefaultComboBoxModel) repositoryPanel.urlComboBox.getModel();                
    int idx = dcbm.getIndexOf(urlString);        
    
    if(idx > -1) {
        return (RepositoryConnection) dcbm.getElementAt(idx);
    }        
    return getEditedRC();        
}
 
Example 2
Source File: StatusChooser.java    From Shuffle-Move with GNU General Public License v3.0 6 votes vote down vote up
public void setSelectedStatus(Status status) {
   String toSelect = null;
   if (status != null) {
      if (shouldRebuild) {
         refill();
      }
      toSelect = getString(status.getKey());
      DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) getModel();
      if (model.getIndexOf(toSelect) == -1) {
         shouldRebuild = true;
         addItem(toSelect);
      } else {
         shouldRebuild = false;
      }
   }
   setSelectedItem(toSelect);
}
 
Example 3
Source File: EffectChooser.java    From Shuffle-Move with GNU General Public License v3.0 6 votes vote down vote up
public void setSelectedEffect(Effect effect) {
   String toSelect = null;
   if (effect != null) {
      if (shouldRebuild) {
         refill();
      }
      toSelect = convertToBox(effect.toString());
      DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) getModel();
      if (model.getIndexOf(toSelect) == -1) {
         shouldRebuild = true;
         insertItemAt(toSelect, 0);
      } else {
         shouldRebuild = false;
      }
   }
   setSelectedItem(toSelect);
}
 
Example 4
Source File: TypeChooser.java    From Shuffle-Move with GNU General Public License v3.0 6 votes vote down vote up
public void setSelectedType(PkmType type) {
   String toSelect = null;
   if (type != null) {
      if (shouldRebuild) {
         refill();
      }
      toSelect = WordUtils.capitalizeFully(type.toString());
      DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) getModel();
      if (model.getIndexOf(toSelect) == -1) {
         shouldRebuild = true;
         insertItemAt(toSelect, 0);
      } else {
         shouldRebuild = false;
      }
   }
   setSelectedItem(toSelect);
}
 
Example 5
Source File: DirectorySelectorCombo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ComboListElement addPath(String path) {
  DefaultComboBoxModel model = (DefaultComboBoxModel)fileMRU.getModel();
  ComboListElement newPath = new StringComboListElement(path);
  int index = model.getIndexOf(newPath);
  if (index == -1) {
    model.insertElementAt(newPath, 1);
  }
  if (model.getSize() > itemCountLimit + 3) {
    model.removeElementAt(model.getSize() - 3);
  }
  return newPath;
}
 
Example 6
Source File: RunAsRemoteWeb.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void selectRemoteConnection(String remoteConnection) {
    if (remoteConnection == null) {
        remoteConnection = getValue(PhpProjectProperties.REMOTE_CONNECTION);
    }
    // #141849 - can be null if one adds remote config for the first time for a project but already has some remote connection
    DefaultComboBoxModel<RemoteConfiguration> model = (DefaultComboBoxModel<RemoteConfiguration>) remoteConnectionComboBox.getModel();
    if (remoteConnection == null
            || RunConfigRemote.NO_CONFIG_NAME.equals(remoteConnection)) {
        if (model.getIndexOf(RunConfigRemote.NO_REMOTE_CONFIGURATION) < 0) {
            model.insertElementAt(RunConfigRemote.NO_REMOTE_CONFIGURATION, 0);
        }
        remoteConnectionComboBox.setSelectedItem(RunConfigRemote.NO_REMOTE_CONFIGURATION);
        return;
    }

    int size = remoteConnectionComboBox.getModel().getSize();
    for (int i = 0; i < size; ++i) {
        RemoteConfiguration rc = remoteConnectionComboBox.getItemAt(i);
        if (remoteConnection.equals(rc.getName())) {
            remoteConnectionComboBox.setSelectedItem(rc);
            return;
        }
    }

    // remote connection is missing (probably removed?)
    remoteConnectionComboBox.addItem(RunConfigRemote.MISSING_REMOTE_CONFIGURATION);
    remoteConnectionComboBox.setSelectedItem(RunConfigRemote.MISSING_REMOTE_CONFIGURATION);
    // # 162230
    model.removeElement(RunConfigRemote.NO_REMOTE_CONFIGURATION);
}
 
Example 7
Source File: RunAsRemoteWeb.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void selectRemoteConnection() {
    String remoteConnection = getValue(RunConfigurationPanel.REMOTE_CONNECTION);
    // #141849 - can be null if one adds remote config for the first time for a project but already has some remote connection
    DefaultComboBoxModel<RemoteConfiguration> model = (DefaultComboBoxModel<RemoteConfiguration>) remoteConnectionComboBox.getModel();
    if (remoteConnection == null
            && model.getIndexOf(RunConfigRemote.NO_REMOTE_CONFIGURATION) != -1) {
        remoteConnectionComboBox.setSelectedItem(RunConfigRemote.NO_REMOTE_CONFIGURATION);
        return;
    }
    int size = remoteConnectionComboBox.getModel().getSize();
    for (int i = 0; i < size; ++i) {
        RemoteConfiguration rc = remoteConnectionComboBox.getItemAt(i);
        if (remoteConnection == null
                || RunConfigRemote.NO_CONFIG_NAME.equals(remoteConnection)
                || remoteConnection.equals(rc.getName())) {
            // select existing or
            // if no configuration formerly existed and now some were created => so select the first one
            remoteConnectionComboBox.setSelectedItem(rc);
            return;
        }
    }
    // #165549
    if (model.getIndexOf(RunConfigRemote.NO_REMOTE_CONFIGURATION) == -1) {
        model.addElement(RunConfigRemote.NO_REMOTE_CONFIGURATION);
    }
    remoteConnectionComboBox.setSelectedItem(RunConfigRemote.NO_REMOTE_CONFIGURATION);
}
 
Example 8
Source File: TemplateChooserPanelGUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void selectProject (@NullAllowed Project p) {
    if (p != null) {
        DefaultComboBoxModel projectsModel = (DefaultComboBoxModel) projectsComboBox.getModel ();
        if ( projectsModel.getIndexOf( p ) == -1 ) {
            projectsModel.insertElementAt( p, 0 );
        }
        projectsComboBox.setSelectedItem( p );
    } 
    else {
        projectsComboBox.setSelectedItem(null);
    }
}
 
Example 9
Source File: Repository.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**    
 * Always updates UI fields visibility.
 */
private void onSelectedRepositoryChange() {
    setValid(true, "");                                                                            // NOI18N     
    String urlString = "";                                                                         // NOI18N         
    try {
        urlString = getUrlString();
    } catch (InterruptedException ex) {
        return; // should not happen
        }
            
    if(urlString != null) {
                   
        RepositoryConnection editedrc = getEditedRC();
        editedrc.setUrl(urlString);
        
        DefaultComboBoxModel dcbm = (DefaultComboBoxModel) repositoryPanel.urlComboBox.getModel();                
        int idx = dcbm.getIndexOf(editedrc);       
        if(idx > -1) {
            //dcbm.setSelectedItem(urlString);                                                
            currentPanel.refresh((RepositoryConnection)dcbm.getElementAt(idx));
        } 
        currentPanel.onSelectedRepositoryChange(urlString);
        currentPanel.fillRC(editedrc);
        
    }
    message = "";                                                                                   // NOI18N
    updateVisibility();
}
 
Example 10
Source File: NamedNativeQueryPanel.java    From jeddict with Apache License 2.0 5 votes vote down vote up
private void addResultClass(String resultClass){
    DefaultComboBoxModel model = (DefaultComboBoxModel) resultClass_jComboBox.getModel();
    String unqualifiedClassName = getClassName(resultClass);
    if (model.getIndexOf(unqualifiedClassName) != -1) { // check if it is Entity then select
        resultClass_jComboBox.setSelectedItem(unqualifiedClassName);
    } else { //if other class
        if (model.getIndexOf(resultClass) == -1) {
            model.addElement(resultClass);
        }
        resultClass_jComboBox.setSelectedItem(resultClass);
    }
}
 
Example 11
Source File: DemoUtils.java    From java-ocr-api with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void savePrefs(Preferences prefs, String prefKey, JComboBox combo, String newValidValue) {
    if (newValidValue == null) { 
        return;
    }

    DefaultComboBoxModel comboModel = (DefaultComboBoxModel) combo.getModel();

    int existingIndex = comboModel.getIndexOf(newValidValue);
    if (existingIndex >= 0) { 
        comboModel.removeElementAt(existingIndex);
    }
    comboModel.insertElementAt(newValidValue, 0);
    combo.setSelectedIndex(0);

    StringBuilder entries = new StringBuilder();
    int size = Math.min(comboModel.getSize(), 20); 
    for (int i = 0; i < size; i++) {
        entries.append(comboModel.getElementAt(i));
        if (i != size - 1) { 
            entries.append(DELIMITER);
        }
    }

    while (entries.length() > Preferences.MAX_VALUE_LENGTH) {
        int lastIndex = entries.lastIndexOf(DELIMITER);
        if (lastIndex == -1) {
            break;
        } else {
            entries.delete(lastIndex, entries.length());
        }
    }

    prefs.put(prefKey, entries.toString());
    try {
        prefs.flush();
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
 
Example 12
Source File: EditSpeciesService.java    From Shuffle-Move with GNU General Public License v3.0 4 votes vote down vote up
private void setDisplayedSpecies(Species species) {
   removeListeners();
   String name;
   PkmType type;
   Integer attack;
   String effectsString;
   String megaName;
   Effect megaEffect;
   if (species == null) {
      name = "";
      type = PkmType.BUG;
      ConfigManager manager = getUser().getPreferencesManager();
      int attackStart = manager.getIntegerValue("ATTACK_CHOSER_START", 30);
      attack = attackStart;
      effectsString = Effect.NONE.toString();
      megaName = null;
      megaEffect = Effect.NONE;
   } else {
      name = species.getName();
      type = species.getType();
      attack = species.getBaseAttack();
      effectsString = species.getEffectsString();
      megaName = species.getMegaName();
      megaEffect = species.getMegaEffect();
   }
   nameField.setText(name);
   typeChooser.setSelectedType(type);
   DefaultComboBoxModel<Integer> attackModel = (DefaultComboBoxModel<Integer>) attackComboBox.getModel();
   if (attackModel.getIndexOf(attack) == -1) {
      attackComboBox.insertItemAt(attack, 0);
   }
   attackComboBox.setSelectedItem(attack);
   effectChooser.setText(effectsString);
   if (megaName != null) {
      megaName = megaName.trim().replaceAll("_", " ");
   }
   megaNameField.setText(megaName);
   megaEffectChooser.setSelectedEffect(megaEffect);
   
   selectedMainIconFile = imageData.getFileValue(name);
   selectedMegaIconFile = imageData.getFileValue(megaName);
   
   revalidateEntryFields();
   addListeners();
}