Java Code Examples for com.intellij.openapi.ui.ComboBox#setSelectedItem()

The following examples show how to use com.intellij.openapi.ui.ComboBox#setSelectedItem() . 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: WriteRulesDialog.java    From PackageTemplates with Apache License 2.0 6 votes vote down vote up
@Override
public void preShow() {
    panel.setLayout(new MigLayout(new LC().gridGap("0", "8pt")));

    //Type
    ArrayList<WriteRules> actionTypes = new ArrayList<>();
    if(hasParent){
        actionTypes.add(WriteRules.FROM_PARENT);
    }
    actionTypes.add(WriteRules.USE_EXISTING);
    actionTypes.add(WriteRules.ASK_ME);
    actionTypes.add(WriteRules.OVERWRITE);

    comboBoxRules = new ComboBox(actionTypes.toArray());
    comboBoxRules.setRenderer(new WriteRulesCellRenderer());
    comboBoxRules.setSelectedItem(writeRules);

    panel.add(comboBoxRules, new CC().pushX().growX().spanX().gapY("10","10"));
}
 
Example 2
Source File: ArtifactConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected JComponent createTopRightComponent(final JTextField nameField) {
  final ComboBox artifactTypeBox = new ComboBox();
  for (ArtifactType type : ArtifactType.EP_NAME.getExtensions()) {
    artifactTypeBox.addItem(type);
  }

  artifactTypeBox.setRenderer(new ArtifactTypeCellRenderer());

  artifactTypeBox.setSelectedItem(getArtifact().getArtifactType());
  artifactTypeBox.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      final ArtifactType selected = (ArtifactType)artifactTypeBox.getSelectedItem();
      if (selected != null && !Comparing.equal(selected, getArtifact().getArtifactType())) {
        getEditor().setArtifactType(selected);
      }
    }
  });

  return LabeledComponent.left(artifactTypeBox, "Type");
}
 
Example 3
Source File: SettingConfigurable.java    From AndroidStringsOneTabTranslation with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public JComponent createComponent() {
    if (settingPanel == null) {
        settingPanel = new JPanel(new VerticalLayout(18));

        // header UI
        Container container = new Container();
        container.setLayout(new BorderLayout());

        currentEngine = TranslationEngineType.fromName(
                PropertiesComponent.getInstance().getValue(StorageDataKey.SettingLanguageEngine));
        TranslationEngineType[] items = TranslationEngineType.getLanguageEngineArray();
        languageEngineBox = new ComboBox(items);
        languageEngineBox.setEnabled(true);
        languageEngineBox.setSelectedItem(currentEngine);
        languageEngineBox.addActionListener(this);

        container.add(new JLabel("Language engine: "), BorderLayout.WEST);
        container.add(languageEngineBox, BorderLayout.CENTER);

        settingPanel.add(container);

        initContentContainer();
        initAndAddFilterContainer();
    }
    return settingPanel;
}
 
Example 4
Source File: SettingsDialog.java    From PackageTemplates with Apache License 2.0 5 votes vote down vote up
private void createLanguageViews() {
    jlLanguage = new JLabel(Localizer.get("settings.Language"));

    comboLanguages = new ComboBox(new EnumComboBoxModel<>(Language.class));
    if (SaveUtil.reader().getLanguage() != null) {
        comboLanguages.setSelectedItem(SaveUtil.reader().getLanguage());
    }
}
 
Example 5
Source File: AbstractAddDialog.java    From nosql4idea with Apache License 2.0 5 votes vote down vote up
void initCombo(final ComboBox combobox, final JPanel parentPanel) {
    combobox.setModel(new DefaultComboBoxModel(JsonDataType.values()));
    combobox.setRenderer(new ColoredListCellRenderer() {

        @Override
        protected void customizeCellRenderer(JList jList, Object o, int i, boolean b, boolean b2) {
            append(((JsonDataType) o).type);
        }
    });

    combobox.setSelectedItem(null);
    combobox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent itemEvent) {
            JsonDataType selectedType = (JsonDataType) combobox.getSelectedItem();
            currentEditor = UI_COMPONENT_BY_JSON_DATATYPE.get(selectedType);
            currentEditor.reset();

            parentPanel.invalidate();
            parentPanel.removeAll();
            parentPanel.add(currentEditor.getComponent(), BorderLayout.CENTER);
            parentPanel.validate();
        }
    });

    combobox.setSelectedItem(JsonDataType.STRING);
}
 
Example 6
Source File: Base64EncodingDialog.java    From StringManipulation with Apache License 2.0 5 votes vote down vote up
private void createUIComponents() {
	model = new DefaultComboBoxModel(new String[]{
					"UTF-8",
					"ASCII",
					"CP1256",
					"ISO-8859-1",
					"ISO-8859-2",
					"ISO-8859-6",
					"ISO-8859-15",
					"Windows-1252"});
	myComboBox = new ComboBox(model, 20);
	myComboBox.setEditable(true);
	myComboBox.setOpaque(true);
	defaultColor = myComboBox.getForeground();
	myComboBox.setSelectedItem("UTF-8");
	final JTextComponent tc = (JTextComponent) myComboBox.getEditor().getEditorComponent();

	tc.getDocument().addDocumentListener(new DocumentAdapter() {
		@Override
		protected void textChanged(DocumentEvent documentEvent) {
			JTextField editorJComp = (JTextField) myComboBox.getEditor().getEditorComponent();
			try {
				Charset instance = Charset.forName(getCharset());
				editorJComp.setForeground(defaultColor);
			} catch (Exception ee) {
				editorJComp.setForeground(JBColor.RED);
			}
		}
	});

}
 
Example 7
Source File: PackageTemplateWrapper.java    From PackageTemplates with Apache License 2.0 4 votes vote down vote up
private void buildProperties() {
    // Header
    JLabel jlName = new JLabel(Localizer.get("Name"));
    JLabel jlDescription = new JLabel(Localizer.get("Description"));

    jtfName = new JBTextField(packageTemplate.getName());
    jtaDescription = new JTextArea(packageTemplate.getDescription());

    panelProperties.add(jlName, new CC().wrap().spanX().pad(0, 0, 0, 8).gapY("0", "4pt"));
    panelProperties.add(jtfName, new CC().spanX().growX().pushX().wrap());
    panelProperties.add(jlDescription, new CC().wrap().spanX().pad(0, 0, 0, 8).gapY("4pt", "4pt"));
    panelProperties.add(jtaDescription, new CC().spanX().growX().pushX().wrap().gapY("0", "4pt"));

    //FileTemplate Source
    ArrayList<FileTemplateSource> actionTypes = new ArrayList<>();
    actionTypes.add(FileTemplateSource.DEFAULT_ONLY);
    actionTypes.add(FileTemplateSource.PROJECT_ONLY);
    actionTypes.add(FileTemplateSource.PROJECT_PRIORITY);
    actionTypes.add(FileTemplateSource.DEFAULT_PRIORITY);

    cboxFileTemplateSource = new ComboBox(actionTypes.toArray());
    cboxFileTemplateSource.setRenderer(new FileTemplateSourceCellRenderer());
    cboxFileTemplateSource.setSelectedItem(packageTemplate.getFileTemplateSource());
    cboxFileTemplateSource.addActionListener(e -> {
        packageTemplate.setFileTemplateSource((FileTemplateSource) cboxFileTemplateSource.getSelectedItem());
    });

    if (mode == ViewMode.USAGE) {
        jtfName.setEditable(false);
        jtaDescription.setEditable(false);
        cboxFileTemplateSource.setEnabled(false);
    } else {
        // Properties
        cbShouldRegisterAction = new JBCheckBox(Localizer.get("property.ShouldRegisterAction"), packageTemplate.isShouldRegisterAction());
        cbSkipDefiningNames = new JBCheckBox(Localizer.get("property.SkipPresettings"), packageTemplate.isSkipDefiningNames());
        panelProperties.add(cbShouldRegisterAction, new CC().wrap().spanX());
        panelProperties.add(cbSkipDefiningNames, new CC().wrap().spanX());
    }

    // Properties
    cbSkipRootDirectory = new JBCheckBox(Localizer.get("property.SkipRootDirectory"), packageTemplate.isSkipRootDirectory());
    cbSkipRootDirectory.addItemListener(e -> {
        collectDataFromFields();
        reBuildElements();
    });
    cbShowReportDialog = new JBCheckBox(Localizer.get("property.ShowReportDialog"), packageTemplate.shouldShowReport());

    panelProperties.add(cbSkipRootDirectory, new CC().spanX().wrap());
    panelProperties.add(cbShowReportDialog, new CC().spanX().wrap());
    panelProperties.add(new JLabel(Localizer.get("FileTemplateSource")), new CC().spanX().split(2));
    panelProperties.add(cboxFileTemplateSource, new CC().pushX().growX().wrap());

}
 
Example 8
Source File: CodeDialogBuilder.java    From android-codegenerator-plugin-intellij with Apache License 2.0 4 votes vote down vote up
public void addSourcePathSection(java.util.List<String> string, String defaultValue) {
    topPanel.add(new JLabel(StringResources.SOURCE_PATH_LABEL));
    sourcePathComboBox = new ComboBox(new CollectionComboBoxModel(string));
    sourcePathComboBox.setSelectedItem(defaultValue);
    topPanel.add(sourcePathComboBox);
}
 
Example 9
Source File: MacroComboBoxWithBrowseButton.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void setText(ComboBox<String> component, @Nonnull String text) {
  if (component != null) component.setSelectedItem(text);
}