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;
}
Aggregations