use of com.intellij.ui.ListCellRendererWrapper in project android by JetBrains.
the class EmulatorTargetConfigurable method createUIComponents.
private void createUIComponents() {
myAvdCombo = new AvdComboBox(myProject, true, false) {
@Override
public Module getModule() {
return myContext.getModule();
}
};
myAvdCombo.startUpdatingAvds(ModalityState.current());
JComboBox avdComboBox = myAvdCombo.getComboBox();
avdComboBox.setRenderer(new ListCellRendererWrapper() {
@Override
public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (value instanceof IdDisplay) {
setText(((IdDisplay) value).getDisplay());
} else {
setText(String.format("<html><font color='red'>Unknown AVD %1$s</font></html>", value == null ? "" : value.toString()));
}
}
});
avdComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
resetAvdCompatibilityWarningLabel();
}
});
myAvdComboWithButton = new ComboboxWithBrowseButton(avdComboBox);
Disposer.register(myParentDisposable, myAvdCombo);
}
use of com.intellij.ui.ListCellRendererWrapper in project intellij-community by JetBrains.
the class ParametersPerConstructorInspection method createOptionsPanel.
@Override
public JComponent createOptionsPanel() {
final JFormattedTextField valueField = prepareNumberEditor("m_limit");
final JComboBox comboBox = new ComboBox(new Object[] { Scope.NONE, Scope.PRIVATE, Scope.PACKAGE_LOCAL, Scope.PROTECTED });
comboBox.setRenderer(new ListCellRendererWrapper() {
@Override
public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (value instanceof Scope)
setText(((Scope) value).getText());
}
});
comboBox.setSelectedItem(ignoreScope);
comboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ignoreScope = (Scope) comboBox.getSelectedItem();
}
});
comboBox.setPrototypeDisplayValue(Scope.PROTECTED);
final FormBuilder formBuilder = FormBuilder.createFormBuilder();
formBuilder.addLabeledComponent(getConfigurationLabel(), valueField);
formBuilder.addLabeledComponent(InspectionGadgetsBundle.message("constructor.visibility.option"), comboBox);
final JPanel panel = new JPanel(new BorderLayout());
panel.add(formBuilder.getPanel(), BorderLayout.NORTH);
return panel;
}
use of com.intellij.ui.ListCellRendererWrapper in project intellij-community by JetBrains.
the class ParameterTablePanel method init.
public void init(VariableData[] variableData, Project project, PsiElement... scopeElements) {
super.init(variableData);
myParameterTypeSelectors = new TypeSelector[getVariableData().length];
for (int i = 0; i < myParameterTypeSelectors.length; i++) {
final VariableData data = variableData[i];
final TypeSelector selector = createSelector(project, data, scopeElements);
myParameterTypeSelectors[i] = selector;
//reverse order
getVariableData()[i].type = myParameterTypeSelectors[i].getSelectedType();
}
myTypeRendererCombo = new ComboBox<>(getVariableData());
myTypeRendererCombo.setOpaque(true);
myTypeRendererCombo.setBorder(null);
myTypeRendererCombo.setRenderer(new ListCellRendererWrapper<VariableData>() {
@Override
public void customize(JList list, VariableData value, int index, boolean selected, boolean hasFocus) {
if (value != null) {
setText(value.type.getPresentableText());
}
}
});
final TableColumn typeColumn = myTable.getColumnModel().getColumn(1);
typeColumn.setCellEditor(new AbstractTableCellEditor() {
TypeSelector myCurrentSelector;
final JBComboBoxTableCellEditorComponent myEditorComponent = new JBComboBoxTableCellEditorComponent();
final JLabel myTypeLabel = new JLabel();
@Nullable
public Object getCellEditorValue() {
if (myCurrentSelector.getComponent() instanceof JLabel) {
return myCurrentSelector.getSelectedType();
}
return myEditorComponent.getEditorValue();
}
public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int row, final int column) {
myCurrentSelector = myParameterTypeSelectors[row];
if (myParameterTypeSelectors[row].getComponent() instanceof JLabel) {
PsiType selectedType = myCurrentSelector.getSelectedType();
if (selectedType != null) {
myTypeLabel.setText(selectedType.getPresentableText());
}
return myTypeLabel;
}
myEditorComponent.setCell(table, row, column);
myEditorComponent.setOptions(myCurrentSelector.getTypes());
myEditorComponent.setDefaultValue(getVariableData()[row].type);
myEditorComponent.setToString(o -> ((PsiType) o).getPresentableText());
return myEditorComponent;
}
});
myTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {
private final JBComboBoxLabel myLabel = new JBComboBoxLabel();
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value != null) {
myLabel.setText(((PsiType) value).getPresentableText());
myLabel.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
myLabel.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
if (isSelected) {
myLabel.setSelectionIcon();
} else {
myLabel.setRegularIcon();
}
}
return myLabel;
}
});
}
use of com.intellij.ui.ListCellRendererWrapper in project intellij-community by JetBrains.
the class WrapReturnValueDialog method createCenterPanel.
protected JComponent createCenterPanel() {
sourceMethodTextField.setEditable(false);
final DocumentListener docListener = new DocumentAdapter() {
protected void textChanged(final DocumentEvent e) {
validateButtons();
}
};
classNameField.getDocument().addDocumentListener(docListener);
myFieldsCombo.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
validateButtons();
}
});
myInnerClassNameTextField.getDocument().addDocumentListener(docListener);
final PsiFile file = sourceMethod.getContainingFile();
if (file instanceof PsiJavaFile) {
final String packageName = ((PsiJavaFile) file).getPackageName();
packageTextField.setText(packageName);
}
final PsiClass containingClass = sourceMethod.getContainingClass();
assert containingClass != null : sourceMethod;
final String containingClassName = containingClass instanceof PsiAnonymousClass ? "Anonymous " + ((PsiAnonymousClass) containingClass).getBaseClassType().getClassName() : containingClass.getName();
final String sourceMethodName = sourceMethod.getName();
sourceMethodTextField.setText(containingClassName + '.' + sourceMethodName);
final ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(useExistingClassButton);
buttonGroup.add(createNewClassButton);
buttonGroup.add(myCreateInnerClassButton);
createNewClassButton.setSelected(true);
final ActionListener enableListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
toggleRadioEnablement();
}
};
useExistingClassButton.addActionListener(enableListener);
createNewClassButton.addActionListener(enableListener);
myCreateInnerClassButton.addActionListener(enableListener);
toggleRadioEnablement();
final DefaultComboBoxModel model = new DefaultComboBoxModel();
myFieldsCombo.setModel(model);
myFieldsCombo.setRenderer(new ListCellRendererWrapper() {
@Override
public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (value instanceof PsiField) {
final PsiField field = (PsiField) value;
setText(field.getName());
setIcon(field.getIcon(Iconable.ICON_FLAG_VISIBILITY));
}
}
});
existingClassField.getChildComponent().getDocument().addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {
@Override
public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent e) {
final JavaPsiFacade facade = JavaPsiFacade.getInstance(myProject);
final PsiClass currentClass = facade.findClass(existingClassField.getText(), GlobalSearchScope.allScope(myProject));
if (currentClass != null) {
model.removeAllElements();
final PsiType returnType = sourceMethod.getReturnType();
assert returnType != null;
for (PsiField field : currentClass.getFields()) {
final PsiType fieldType = field.getType();
if (TypeConversionUtil.isAssignable(fieldType, returnType)) {
model.addElement(field);
} else {
if (WrapReturnValueProcessor.getInferredType(fieldType, returnType, currentClass, sourceMethod) != null) {
model.addElement(field);
}
}
}
}
}
});
return myWholePanel;
}
use of com.intellij.ui.ListCellRendererWrapper in project intellij-plugins by JetBrains.
the class HbConfigurationPage method resetCommentLanguageCombo.
private void resetCommentLanguageCombo(@NotNull Language commentLanguage) {
final DefaultComboBoxModel model = (DefaultComboBoxModel) myCommenterLanguage.getModel();
final List<Language> languages = TemplateDataLanguageMappings.getTemplateableLanguages();
// add using the native Handlebars commenter as an option
languages.add(HbLanguage.INSTANCE);
Collections.sort(languages, (o1, o2) -> o1.getID().compareTo(o2.getID()));
for (Language language : languages) {
model.addElement(language);
}
myCommenterLanguage.setRenderer(new ListCellRendererWrapper() {
@Override
public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
setText(value == null ? "" : ((Language) value).getDisplayName());
if (value != null) {
final FileType type = ((Language) value).getAssociatedFileType();
if (type != null) {
setIcon(type.getIcon());
}
}
}
});
myCommenterLanguage.setSelectedItem(commentLanguage);
}
Aggregations