Java Code Examples for javax.swing.ComboBoxModel

The following examples show how to use javax.swing.ComboBoxModel. These examples are extracted from open source projects. 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
private ComboBoxModel getListObjDoc()
{
Vector VObjects=new Vector();
try {
DriverGeneric Session=MainWin.getSession();
PDObjDefs Obj = new PDObjDefs(Session);
Cursor CursorId = Obj.getListDocs();
Record Res=Session.NextRec(CursorId);
while (Res!=null)
    {
    Attribute Attr=Res.getAttr(PDObjDefs.fNAME);
    VObjects.add(Attr.getValue());
    Res=Session.NextRec(CursorId);
    }
Session.CloseCursor(CursorId);
} catch (PDException ex)
    {
    MainWin.Message("Error"+ex.getLocalizedMessage());
    }
return(new DefaultComboBoxModel(VObjects));
}
 
Example 2
private void updatePackages() {
    final Object item = createdLocationComboBox.getSelectedItem();
    if (!(item instanceof SourceGroupSupport.SourceGroupProxy)) {
        return;
    }
    WAIT_MODEL.setSelectedItem(createdPackageComboBox.getEditor().getItem());
    createdPackageComboBox.setModel(WAIT_MODEL);

    if (updatePackagesTask != null) {
        updatePackagesTask.cancel();
    }

    updatePackagesTask = new RequestProcessor("ComboUpdatePackages").post(new Runnable() { // NOI18N
        @Override
        public void run() {
            final ComboBoxModel model = ((SourceGroupSupport.SourceGroupProxy) item).getPackagesComboBoxModel();
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    model.setSelectedItem(createdPackageComboBox.getEditor().getItem());
                    createdPackageComboBox.setModel(model);
                }
            });
        }
    });
}
 
Example 3
private ComboBoxModel getListObjDoc()
{
Vector VObjects=new Vector();
try {
DriverGeneric Session=MainWin.getSession();
PDObjDefs Obj = new PDObjDefs(Session);
Cursor CursorId = Obj.getListDocs();
Record Res=Session.NextRec(CursorId);
while (Res!=null)
    {
    Attribute Attr=Res.getAttr(PDObjDefs.fNAME);
    VObjects.add(Attr.getValue());
    Res=Session.NextRec(CursorId);
    }
Session.CloseCursor(CursorId);
} catch (PDException ex)
    {
    MainWin.Message("Error"+ex.getLocalizedMessage());
    }
return(new DefaultComboBoxModel(VObjects));
}
 
Example 4
private ComboBoxModel getListObjFold()
{
Vector VObjects=new Vector();
try {
DriverGeneric Session=MainWin.getSession();
PDObjDefs Obj = new PDObjDefs(Session);
Cursor CursorId = Obj.getListFold();
Record Res=Session.NextRec(CursorId);
while (Res!=null)
    {
    Attribute Attr=Res.getAttr(PDObjDefs.fNAME);
    VObjects.add(Attr.getValue());
    Res=Session.NextRec(CursorId);
    }
Session.CloseCursor(CursorId);
} catch (PDException ex)
    {
    MainWin.Message("Error"+ex.getLocalizedMessage());
    }
return(new DefaultComboBoxModel(VObjects));
}
 
Example 5
public AutoCompletionComboBox(boolean caseSensitive, int preferredWidth, int preferredHeight, boolean wide,
		ComboBoxModel<E> model) {
	super(preferredWidth, preferredHeight, wide, model);

	this.caseSensitive = caseSensitive;

	setEditable(true);
	setEditor(getEditor());

	addFocusListener(new FocusAdapter() {

		@Override
		public void focusLost(FocusEvent e) {
			setSelectedItem(((JTextField) getEditor().getEditorComponent()).getText());
			actionPerformed(new ActionEvent(this, 0, "editingStopped"));
		}
	});
}
 
Example 6
Source Project: netbeans   Source File: FindUsagesDialogOperator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Select the scope
 *
 * @param projectName The name of project or null if find should be
 * performed on all projects
 */
public void setScope(String projectName) {
    JComboBoxOperator scopeOperator = getScope();
    String select_item;
    if (projectName == null) {
        select_item = Bundle.getStringTrimmed("org.netbeans.modules.refactoring.java.ui.scope.Bundle", "LBL_AllProjects");
    } else {
        select_item = projectName;
    }

    ComboBoxModel model = scopeOperator.getModel();
    int index = -1;
    String dn;
    for (int i = 0; i < model.getSize()-1; i++) { /// -1 ... it's custom and it fails
        dn = ((org.netbeans.modules.refactoring.spi.impl.DelegatingScopeProvider) model.getElementAt(i)).getDisplayName();
        if (dn.indexOf(select_item) != -1) {
            index = i;
        }
    }
    scopeOperator.selectItem(index);
}
 
Example 7
Source Project: netbeans   Source File: SettingsPanel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Selects a given template.
 *
 * @param  templatePath  path of the template which should be selected;
 *                       may be <code>null</code> - then no item is selected
 */
void selectTemplate(String templatePath) {
    if (templatePath == null) {
        return;
    }
    
    ComboBoxModel model = cboTemplate.getModel();
    int itemsCount = model.getSize();
    
    if (itemsCount == 0) {
        return;
    }
    
    for (int i = 0; i < itemsCount; i++) {
        NamedObject namedObj = (NamedObject) model.getElementAt(i);
        FileObject template = (FileObject) namedObj.object;
        if (template.getPath().equals(templatePath)) {
            cboTemplate.setSelectedIndex(i);
            return;
        }
    }
}
 
Example 8
private ComboBoxModel getListObjDoc()
{
Vector VObjects=new Vector();
try {
DriverGeneric Session=MainWin.getSession();
PDObjDefs Obj = new PDObjDefs(Session);
Cursor CursorId = Obj.getListDocs();
Record Res=Session.NextRec(CursorId);
while (Res!=null)
    {
    Attribute Attr=Res.getAttr(PDObjDefs.fNAME);
    VObjects.add(Attr.getValue());
    Res=Session.NextRec(CursorId);
    }
Session.CloseCursor(CursorId);
} catch (PDException ex)
    {
    MainWin.Message("Error"+ex.getLocalizedMessage());
    }
return(new DefaultComboBoxModel(VObjects));
}
 
Example 9
private void setValue(String value)
{
	if (fieldComboBox != null)
	{
		ComboBoxModel<FieldValue> comboBoxModel = fieldComboBox.getModel();
		for (int i = 0; i < comboBoxModel.getSize(); i++)
		{
			FieldValue fieldValue = comboBoxModel.getElementAt(i);
			if (fieldValue.getEnumValue().equals(value))
			{
				fieldComboBox.setSelectedIndex(i);
			}
		}
	}

	else
	{
		fieldTextField.setText(value);
	}
}
 
Example 10
Source Project: swingsane   Source File: KnownSaneOptions.java    License: Apache License 2.0 6 votes vote down vote up
public static ComboBoxModel<String> getSourceModel(Scanner scanner) {
  DefaultComboBoxModel<String> sourceModel = new DefaultComboBoxModel<String>();

  HashMap<String, StringOption> stringOptions = scanner.getStringOptions();

  StringOption stringOption = stringOptions.get(SANE_NAME_SCAN_SOURCE);

  if (stringOption == null) {
    return null;
  }

  Constraints constraints = stringOption.getConstraints();
  List<String> values = constraints.getStringList();

  for (String value : values) {
    sourceModel.addElement(value);
  }

  if (values.size() > 0) {
    return sourceModel;
  } else {
    return null;
  }
}
 
Example 11
Source Project: azure-devops-intellij   Source File: CreatePullRequestModel.java    License: MIT License 6 votes vote down vote up
private ComboBoxModel createRemoteBranchDropdownModel() {
    final SortedComboBoxModel<GitRemoteBranch> sortedRemoteBranches
            = new SortedComboBoxModel<GitRemoteBranch>(new TfGitHelper.BranchComparator());
    final GitRemoteBranch remoteTrackingBranch = this.getRemoteTrackingBranch();

    // only show valid remote branches
    sortedRemoteBranches.addAll(Collections2.filter(getInfo().getRemoteBranches(),
            remoteBranch -> {
                /* two conditions:
                 *   1. remote must be a vso/tfs remote
                 *   2. this isn't the remote tracking branch of current local branch
                 */
                return tfGitRemotes.contains(remoteBranch.getRemote())
                        && !remoteBranch.equals(remoteTrackingBranch);
            })
    );
    sortedRemoteBranches.setSelectedItem(TfGitHelper.getDefaultBranch(sortedRemoteBranches.getItems(), tfGitRemotes));

    return sortedRemoteBranches;
}
 
Example 12
Source Project: zap-extensions   Source File: AjaxSpiderExplorer.java    License: Apache License 2.0 6 votes vote down vote up
public void optionsLoaded(QuickStartParam quickStartParam) {
    getSelectCheckBox().setSelected(quickStartParam.isAjaxSpiderEnabled());
    String def = quickStartParam.getAjaxSpiderDefaultBrowser();
    if (def == null || def.length() == 0) {
        // no default
        return;
    }
    ComboBoxModel<ProvidedBrowserUI> model = this.getBrowserComboBox().getModel();
    for (int idx = 0; idx < model.getSize(); idx++) {
        ProvidedBrowserUI el = model.getElementAt(idx);
        if (el.getName().equals(def)) {
            model.setSelectedItem(el);
            break;
        }
    }
}
 
Example 13
public void addLocalRepositoryFolderIfMissing(LocalRepositoryFolder localRepositoryFolder) {
    ComboBoxModel<LocalRepositoryFolder> foldersModel = this.foldersComboBox.getModel();
    boolean foundFolder = false;
    for (int i = 0; i < foldersModel.getSize() && !foundFolder; i++) {
        LocalRepositoryFolder existingFolder = foldersModel.getElementAt(i);
        if (existingFolder != null && existingFolder.getId() == localRepositoryFolder.getId()) {
            foundFolder = true;
        }
    }
    if (!foundFolder) {
        if (foldersModel.getSize() == 0) {
            this.foldersComboBox.addItem(null);
        }
        this.foldersComboBox.addItem(localRepositoryFolder);
    }
}
 
Example 14
public Range getRangeFromFile() {
    final ComboBoxModel<ColorPaletteWrapper> model = getModel();
    final int selectedIndex = getSelectedIndex();
    final ColorPaletteWrapper paletteWrapper = model.getElementAt(selectedIndex);
    String name = paletteWrapper.name;
    final ColorPaletteDef cpd;
    if (name.startsWith(DERIVED_FROM)) {
        name = name.substring(DERIVED_FROM.length()).trim();
        if (name.toLowerCase().endsWith(".cpd")) {
            name = FileUtils.getFilenameWithoutExtension(name);
        }
        cpd = findColorPalette(name);
    } else {
        cpd = paletteWrapper.cpd;
    }
    return new Range(cpd.getMinDisplaySample(), cpd.getMaxDisplaySample());
}
 
Example 15
public void setSelectedView( final FileObject selectedView ) {
  this.selectedView = selectedView;
  if ( selectedView != null ) {
    logger.debug( "Setting selected view to " + selectedView );
    try {
      if ( selectedView.getType() == FileType.FILE ) {
        logger.debug( "Setting filename in selected view to " + selectedView.getName().getBaseName() );
        this.fileNameTextField.setText( URLDecoder.decode( selectedView.getName().getBaseName(), "UTF-8" ) );
      }
    } catch ( Exception e ) {
      // can be ignored ..
      logger.debug( "Unable to determine file type. This is not fatal.", e );
    }
    final ComboBoxModel comboBoxModel = createLocationModel( selectedView );
    this.locationCombo.setModel( comboBoxModel );
    this.table.setSelectedPath( (FileObject) comboBoxModel.getSelectedItem() );
  } else {
    this.fileNameTextField.setText( null );
    this.table.setSelectedPath( null );
    this.locationCombo.setModel( new DefaultComboBoxModel() );
  }
}
 
Example 16
Source Project: netbeans   Source File: CopyDialogTest.java    License: Apache License 2.0 5 votes vote down vote up
private void assertModel (Map<String, String> items, JComboBox combo, List<String> expected) {
    ComboBoxModel model = combo.getModel();
    assertEquals(expected.size() / 2, model.getSize());
    for (int i = 0; i < model.getSize(); ++i) {
        assertEquals(expected.get(i * 2), model.getElementAt(i));
        assertEquals(expected.get(i * 2 + 1), items.get((String) model.getElementAt(i)));
    }
}
 
Example 17
Source Project: openAGV   Source File: SelectionPropertyEditorPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override // DetailsDialogContent
public void setProperty(Property property) {
  fProperty = (AbstractProperty) property;

  @SuppressWarnings("unchecked")
  ComboBoxModel<Object> model
      = new DefaultComboBoxModel<>(((Selectable<Object>) fProperty).getPossibleValues().toArray());
  valueComboBox.setModel(model);

  Object value = fProperty.getValue();
  valueComboBox.setSelectedItem(value);
  valueComboBox.setRenderer(listCellRenderer);
}
 
Example 18
private static ComboBoxModel<String> createPagesModel(int pages)
{
	String[] pageNumbers = new String[pages];
	for (int i = 0; i < pages; i++)
	{
		pageNumbers[i] = (i + 1) + " of " + pages;
	}
	return new DefaultComboBoxModel<>(pageNumbers);
}
 
Example 19
Source Project: bigtable-sql   Source File: UpdateSummaryTable.java    License: Apache License 2.0 5 votes vote down vote up
private void setModel(JComboBox box, ArtifactAction... actions) {
	ComboBoxModel oldModel = box.getModel();
	box.setModel(getComboBoxModel(actions));
	if (oldModel.getSize() != actions.length) {
		box.firePropertyChange("itemCount", oldModel.getSize(), actions.length);
	}
}
 
Example 20
Source Project: swingsane   Source File: ComponentController.java    License: Apache License 2.0 5 votes vote down vote up
private void updateSourceModel(ComboBoxModel<String> sourceModel, String source) {
  JComboBox<String> sourceComboBox = components.getSourceComboBox();
  sourceComboBox.setModel(sourceModel != null ? sourceModel : new DefaultComboBoxModel<String>());
  sourceComboBox.setEnabled(sourceModel != null ? true : false);
  if (source != null) {
    sourceComboBox.setSelectedItem(source);
  }
}
 
Example 21
Source Project: netbeans   Source File: ModifyElementRulesPanel.java    License: Apache License 2.0 5 votes vote down vote up
private ComboBoxModel createSelectorModel() {
    HtmlModel model = HtmlModelFactory.getModel(HtmlVersion.HTML5);
    Collection<String> tagNames = new ArrayList<>();
    tagNames.add(null);
    for (HtmlTag tag : model.getAllTags()) {
        tagNames.add(tag.getName());
    }
    return new DefaultComboBoxModel(tagNames.toArray());

}
 
Example 22
Source Project: netbeans   Source File: ModifyElementRulesPanel.java    License: Apache License 2.0 5 votes vote down vote up
private ComboBoxModel createIdsModel() {
    Collection<String> ids = new ArrayList<>();
    ids.add(null);
    FileObject selectedStyleSheet = (FileObject) styleSheetCB.getSelectedItem();
    if (selectedStyleSheet != null) {
        Collection<String> foundInFile = files2ids.get(selectedStyleSheet);
        if (foundInFile != null) {
            ids.addAll(foundInFile);
        }
    }
    return new DefaultComboBoxModel(ids.toArray());
}
 
Example 23
Source Project: nextreports-designer   Source File: DesignerTablePanel.java    License: Apache License 2.0 5 votes vote down vote up
private boolean hasEmpty(ComboBoxModel model) {
	int size = model.getSize();
	for (int i=0; i<size; i++) {
		if ("".equals(model.getElementAt(i))) {
			return true;
		}
	}
	return false;
}
 
Example 24
Source Project: netbeans   Source File: EntityClassesPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void updatePackageComboBox() {
    SourceGroup sourceGroup = (SourceGroup)locationComboBox.getSelectedItem();
    if (sourceGroup != null) {
        ComboBoxModel model = PackageView.createListView(sourceGroup);
        if (model.getSelectedItem()!= null && model.getSelectedItem().toString().startsWith("META-INF")
                && model.getSize() > 1) { // NOI18N
            model.setSelectedItem(model.getElementAt(1));
        }
        packageComboBox.setModel(model);
    }
}
 
Example 25
Source Project: netbeans   Source File: DBScriptPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void updatePackageComboBox() {
    SourceGroup sourceGroup = (SourceGroup) locationComboBox.getSelectedItem();
    if (sourceGroup != null) {
        ComboBoxModel model = PackageView.createListView(sourceGroup);
        if (model.getSelectedItem() != null && model.getSelectedItem().toString().startsWith("META-INF")
                && model.getSize() > 1) { // NOI18N
            model.setSelectedItem(model.getElementAt(1));
        }
        packageComboBox.setModel(model);
    }
}
 
Example 26
/**
 * Sets the characters per inch.
 *
 * @param cpi
 *          the characters per inch.
 */
public void setCharsPerInch( final float cpi ) {
  final Float cpiObj = new Float( cpi );
  final ComboBoxModel model = cbCharsPerInch.getModel();
  for ( int i = 0; i < model.getSize(); i++ ) {
    if ( cpiObj.equals( model.getElementAt( i ) ) ) {
      cbCharsPerInch.setSelectedIndex( i );
      return;
    }
  }
  throw new IllegalArgumentException( messages.getErrorString( "PlainTextExportDialog.ERROR_0002_NO_SUCH_CPI", String
      .valueOf( cpi ) ) ); //$NON-NLS-1$ //$NON-NLS-2$
}
 
Example 27
Source Project: netbeans   Source File: ShowEffPomDiffPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates new form ShowEffPomDiffPanel
 */
public ShowEffPomDiffPanel(ProjectConfigurationProvider<MavenConfiguration> configs) {
    initComponents();
    ComboBoxModel<MavenConfiguration> model = new DefaultComboBoxModel<MavenConfiguration>(configs.getConfigurations().toArray(new MavenConfiguration[0]));
    comConfiguration.setModel(model);
    comConfiguration.setEditable(false);
    comConfiguration.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            return super.getListCellRendererComponent(list, ((ProjectConfiguration)value).getDisplayName(), index, isSelected, cellHasFocus);
        }
    });
    comConfiguration.setSelectedItem(configs.getActiveConfiguration());
    enableFields();
    epProperties.setContentType("text/x-properties");
}
 
Example 28
@SuppressWarnings("unchecked")
public ValueTypeCellEditor(final int valueType) {
	super(new JComboBox<String>());
	ComboBoxModel<String> model = new DefaultComboBoxModel<String>() {

		private static final long serialVersionUID = 914764579359633239L;

		private String[] valueTypes = new String[VALUE_TYPE_OPTIONS[valueType].length];
		{
			for (int i = 0; i < VALUE_TYPE_OPTIONS[valueType].length; i++) {
				valueTypes[i] = Ontology.ATTRIBUTE_VALUE_TYPE.mapIndex(VALUE_TYPE_OPTIONS[valueType][i]);
			}
		}

		@Override
		public String getElementAt(int index) {
			return valueTypes[index];
		}

		@Override
		public int getSize() {
			return valueTypes.length;
		}
	};
	((JComboBox<?>) super.getComponent()).setEnabled(editValueTypes);
	((JComboBox<String>) super.getComponent()).setModel(model);
}
 
Example 29
@Override
protected void done()
{
	try
	{
		ComboBoxModel<Object> model = new DefaultComboBoxModel<>(get());
		model.setSelectedItem(null);
		sheetBox.setModel(model);
	}
	catch (InterruptedException | ExecutionException ex)
	{
		Logging.errorPrint("could not load sheets", ex);
	}
}
 
Example 30
/**
 * Maps {@code JComboBox.getModel()} through queue
 */
public ComboBoxModel<?> getModel() {
    return (runMapping(new MapAction<ComboBoxModel<?>>("getModel") {
        @Override
        public ComboBoxModel<?> map() {
            return ((JComboBox) getSource()).getModel();
        }
    }));
}