use of com.intellij.openapi.ui.ComboBox in project android by JetBrains.
the class KeyValuePane method updateUiFromCurrentObject.
/**
* Updates the form UI objects to reflect the currently selected object. Clears the objects and disables them if there is no selected
* object.
*/
public void updateUiFromCurrentObject() {
myIsUpdating = true;
for (Map.Entry<BuildFileKey, JComponent> entry : myProperties.entrySet()) {
BuildFileKey key = entry.getKey();
JComponent component = entry.getValue();
Object value = myCurrentBuildFileObject != null ? myCurrentBuildFileObject.get(key) : null;
final Object modelValue = myCurrentModelObject != null ? myCurrentModelObject.get(key) : null;
switch(key.getType()) {
case BOOLEAN:
{
ComboBox comboBox = (ComboBox) component;
String text = formatDefaultValue(modelValue);
comboBox.removeItemAt(0);
comboBox.insertItemAt(text, 0);
JBTextField editorComponent = (JBTextField) comboBox.getEditor().getEditorComponent();
if (Boolean.FALSE.equals(value)) {
comboBox.setSelectedIndex(2);
editorComponent.setForeground(JBColor.BLACK);
} else if (Boolean.TRUE.equals(value)) {
comboBox.setSelectedIndex(1);
editorComponent.setForeground(JBColor.BLACK);
} else {
comboBox.setSelectedIndex(0);
editorComponent.setForeground(JBColor.GRAY);
}
break;
}
case FILE:
case FILE_AS_STRING:
{
TextFieldWithBrowseButton fieldWithButton = (TextFieldWithBrowseButton) component;
fieldWithButton.setText(value != null ? value.toString() : "");
JBTextField textField = (JBTextField) fieldWithButton.getTextField();
textField.getEmptyText().setText(formatDefaultValue(modelValue));
break;
}
case REFERENCE:
{
String stringValue = (String) value;
if (hasKnownValues(key) && stringValue != null) {
stringValue = getMappedValue(myKeysWithKnownValues.get(key), stringValue);
}
String prefix = getReferencePrefix(key);
if (stringValue == null) {
stringValue = "";
} else if (stringValue.startsWith(prefix)) {
stringValue = stringValue.substring(prefix.length());
}
ComboBox comboBox = (ComboBox) component;
JBTextField textField = (JBTextField) comboBox.getEditor().getEditorComponent();
textField.getEmptyText().setText(formatDefaultValue(modelValue));
comboBox.setSelectedItem(stringValue);
break;
}
case CLOSURE:
if (value instanceof List) {
value = Joiner.on(", ").join((List) value);
}
// Fall through to INTEGER/STRING/default case
case INTEGER:
case STRING:
default:
{
if (hasKnownValues(key)) {
if (value != null) {
value = getMappedValue(myKeysWithKnownValues.get(key), value.toString());
}
ComboBox comboBox = (ComboBox) component;
comboBox.setSelectedItem(value != null ? value.toString() : "");
JBTextField textField = (JBTextField) comboBox.getEditor().getEditorComponent();
textField.getEmptyText().setText(formatDefaultValue(modelValue));
} else {
JBTextField textField = (JBTextField) component;
textField.setText(value != null ? value.toString() : "");
textField.getEmptyText().setText(formatDefaultValue(modelValue));
}
break;
}
}
component.setEnabled(myCurrentBuildFileObject != null);
}
myIsUpdating = false;
}
use of com.intellij.openapi.ui.ComboBox in project android by JetBrains.
the class ServicePanelBuilder method addComboBox.
public JComboBox addComboBox(@NotNull final ObservableList<String> backingList) {
final CollectionComboBoxModel<String> model = new CollectionComboBoxModel<String>(backingList) {
@NotNull
@Override
public List<String> getItems() {
return backingList;
}
};
final ComboBox comboBox = new ComboBox(model);
InvalidationListener onListModified = new InvalidationListener() {
@Override
public void onInvalidated(@NotNull ObservableValue<?> sender) {
model.update();
if (backingList.size() > 0 && comboBox.getSelectedIndex() < 0) {
comboBox.setSelectedIndex(0);
}
}
};
addComponent(comboBox);
backingList.addWeakListener(onListModified);
// Keep weak listener alive as long as the combobox is alive
comboBox.putClientProperty("onListModified", onListModified);
return comboBox;
}
use of com.intellij.openapi.ui.ComboBox in project android by JetBrains.
the class MemoryClassView method buildComponent.
@Nullable
public JComponent buildComponent(@NotNull CaptureObject captureObject) {
myCaptureObject = captureObject;
JPanel classesPanel = new JPanel(new BorderLayout());
JPanel headingPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
headingPanel.add(new JLabel(captureObject.toString()));
JToolBar toolBar = new JToolBar();
toolBar.setFloatable(false);
List<HeapObject> heaps = captureObject.getHeaps();
ComboBoxModel<HeapObject> comboBoxModel = new DefaultComboBoxModel<>(heaps.toArray(new HeapObject[heaps.size()]));
ComboBox<HeapObject> comboBox = new ComboBox<>(comboBoxModel);
comboBox.addActionListener(e -> {
Object item = comboBox.getSelectedItem();
if (item != null && item instanceof HeapObject) {
HeapObject heap = (HeapObject) item;
buildTree(classesPanel, heap);
myStage.selectHeap(heap);
}
});
toolBar.add(comboBox);
headingPanel.add(toolBar);
classesPanel.add(headingPanel, BorderLayout.PAGE_START);
boolean selected = false;
// TODO provide a default selection in the model API?
for (HeapObject heap : heaps) {
if (heap.getHeapName().equals("app")) {
comboBox.setSelectedItem(heap);
myStage.selectHeap(heap);
selected = true;
break;
}
}
if (!selected) {
HeapObject heap = heaps.get(0);
comboBox.setSelectedItem(heap);
myStage.selectHeap(heap);
}
return classesPanel;
}
use of com.intellij.openapi.ui.ComboBox in project intellij-community by JetBrains.
the class PrintDialog method createHeaderAndFooterPanel.
private JPanel createHeaderAndFooterPanel() {
// JPanel panel = createGroupPanel("Header");
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createEmptyBorder(8, 8, 4, 4));
panel.setLayout(new GridBagLayout());
GridBagConstraints gbConstraints = new GridBagConstraints();
gbConstraints.gridy = 0;
gbConstraints.gridx = 0;
gbConstraints.gridwidth = 1;
gbConstraints.gridheight = 1;
gbConstraints.weightx = 1;
gbConstraints.fill = GridBagConstraints.BOTH;
gbConstraints.insets = new Insets(0, 0, 6, 4);
gbConstraints.gridwidth = 3;
myLineTextField1 = new MyTextField(30);
myLinePlacementCombo1 = new ComboBox();
myLineAlignmentCombo1 = new ComboBox();
JPanel linePanel1 = createLinePanel(CodeEditorBundle.message("print.header.line.1.label"), myLineTextField1, myLinePlacementCombo1, myLineAlignmentCombo1);
panel.add(linePanel1, gbConstraints);
myLineTextField2 = new MyTextField(30);
myLinePlacementCombo2 = new ComboBox();
myLineAlignmentCombo2 = new ComboBox();
JPanel linePanel2 = createLinePanel(CodeEditorBundle.message("print.header.line.2.label"), myLineTextField2, myLinePlacementCombo2, myLineAlignmentCombo2);
gbConstraints.gridy++;
panel.add(linePanel2, gbConstraints);
gbConstraints.insets = new Insets(0, 8, 6, 4);
gbConstraints.gridy++;
gbConstraints.gridwidth = 1;
gbConstraints.gridx = 0;
panel.add(new MyLabel(CodeEditorBundle.message("print.header.font.label")), gbConstraints);
myFooterFontNameCombo = new FontComboBox(true);
gbConstraints.gridx = 1;
panel.add(myFooterFontNameCombo, gbConstraints);
myFooterFontSizeCombo = createFontSizesComboBox();
gbConstraints.gridx = 2;
panel.add(myFooterFontSizeCombo, gbConstraints);
return panel;
}
use of com.intellij.openapi.ui.ComboBox in project intellij-community by JetBrains.
the class RedmineRepositoryEditor method createCustomPanel.
@Nullable
@Override
protected JComponent createCustomPanel() {
myProjectLabel = new JBLabel("Project:", SwingConstants.RIGHT);
myProjectCombo = new ComboBox(300);
//myProjectCombo.setRenderer(new TaskUiUtil.SimpleComboBoxRenderer("Set URL and password/token first"));
myProjectCombo.setRenderer(new ListCellRendererWrapper<RedmineProjectItem>() {
@Override
public void customize(JList list, RedmineProjectItem value, int index, boolean selected, boolean hasFocus) {
if (value == null) {
setText("Set URL and password/token first");
} else {
if (myProjectCombo.isPopupVisible()) {
//if (value.myLevel == 0 && value.myProject != RedmineRepository.UNSPECIFIED_PROJECT) {
//setFont(UIUtil.getListFont().deriveFont(Font.BOLD));
//}
setText(StringUtil.repeat(" ", value.myLevel) + value.myProject.getName());
} else {
// Do not indent selected project
setText(value.myProject.getName());
}
}
}
});
myAPIKeyLabel = new JBLabel("API Token:", SwingConstants.RIGHT);
myAPIKey = new JPasswordField();
myAllAssigneesCheckBox = new JBCheckBox("Include issues not assigned to me");
return FormBuilder.createFormBuilder().addLabeledComponent(myAPIKeyLabel, myAPIKey).addLabeledComponent(myProjectLabel, myProjectCombo).addComponentToRightColumn(myAllAssigneesCheckBox).getPanel();
}
Aggregations