use of com.intellij.ui.ColoredListCellRenderer in project android by JetBrains.
the class TraceViewPanel method setTrace.
public void setTrace(@NotNull VmTraceData trace) {
myTraceData = trace;
List<ThreadInfo> threads = trace.getThreads(true);
if (threads.isEmpty()) {
return;
}
ThreadInfo defaultThread = Iterables.find(threads, new Predicate<ThreadInfo>() {
@Override
public boolean apply(ThreadInfo input) {
return MAIN_THREAD_NAME.equals(input.getName());
}
}, threads.get(0));
myTraceViewCanvas.setTrace(trace, defaultThread, getCurrentRenderClock());
myThreadCombo.setModel(new DefaultComboBoxModel(threads.toArray()));
myThreadCombo.setSelectedItem(defaultThread);
myThreadCombo.setRenderer(new ColoredListCellRenderer() {
@Override
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
String name = value instanceof ThreadInfo ? ((ThreadInfo) value).getName() : value.toString();
append(name);
}
});
myThreadCombo.setEnabled(true);
myRenderClockSelectorCombo.setEnabled(true);
myVmStatsTreeTableModel.setTraceData(trace, defaultThread);
myVmStatsTreeTableModel.setClockType(getCurrentRenderClock());
myTreeTable.setModel(myVmStatsTreeTableModel);
VmStatsTreeUtils.adjustTableColumnWidths(myTreeTable);
VmStatsTreeUtils.setCellRenderers(myTreeTable);
VmStatsTreeUtils.setSpeedSearch(myTreeTable);
VmStatsTreeUtils.enableSorting(myTreeTable, myVmStatsTreeTableModel);
}
use of com.intellij.ui.ColoredListCellRenderer in project intellij-community by JetBrains.
the class JumpFromRemoteFileToLocalAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
Collection<VirtualFile> files = findLocalFiles(myProject, Urls.newFromVirtualFile(myFile), myFile.getName());
if (files.isEmpty()) {
Messages.showErrorDialog(myProject, "Cannot find local file for '" + myFile.getUrl() + "'", CommonBundle.getErrorTitle());
return;
}
if (files.size() == 1) {
navigateToFile(myProject, ContainerUtil.getFirstItem(files, null));
} else {
final JList list = new JBList(files);
//noinspection unchecked
list.setCellRenderer(new ColoredListCellRenderer() {
@Override
protected void customizeCellRenderer(@NotNull JList list, Object value, int index, boolean selected, boolean hasFocus) {
FileAppearanceService.getInstance().forVirtualFile((VirtualFile) value).customize(this);
}
});
new PopupChooserBuilder(list).setTitle("Select Target File").setMovable(true).setItemChoosenCallback(() -> {
//noinspection deprecation
for (Object value : list.getSelectedValues()) {
navigateToFile(myProject, (VirtualFile) value);
}
}).createPopup().showUnderneathOf(e.getInputEvent().getComponent());
}
}
use of com.intellij.ui.ColoredListCellRenderer in project intellij-community by JetBrains.
the class NavigationUtil method getPsiElementPopup.
private static JBPopup getPsiElementPopup(final Object[] elements, final Map<PsiElement, GotoRelatedItem> itemsMap, final String title, final boolean showContainingModules, final Processor<Object> processor) {
final Ref<Boolean> hasMnemonic = Ref.create(false);
final DefaultPsiElementCellRenderer renderer = new DefaultPsiElementCellRenderer() {
{
setFocusBorderEnabled(false);
}
@Override
public String getElementText(PsiElement element) {
String customName = itemsMap.get(element).getCustomName();
return (customName != null ? customName : super.getElementText(element));
}
@Override
protected Icon getIcon(PsiElement element) {
Icon customIcon = itemsMap.get(element).getCustomIcon();
return customIcon != null ? customIcon : super.getIcon(element);
}
@Override
public String getContainerText(PsiElement element, String name) {
String customContainerName = itemsMap.get(element).getCustomContainerName();
if (customContainerName != null) {
return customContainerName;
}
PsiFile file = element.getContainingFile();
return file != null && !getElementText(element).equals(file.getName()) ? "(" + file.getName() + ")" : null;
}
@Override
protected DefaultListCellRenderer getRightCellRenderer(Object value) {
return showContainingModules ? super.getRightCellRenderer(value) : null;
}
@Override
protected boolean customizeNonPsiElementLeftRenderer(ColoredListCellRenderer renderer, JList list, Object value, int index, boolean selected, boolean hasFocus) {
final GotoRelatedItem item = (GotoRelatedItem) value;
Color color = list.getForeground();
final SimpleTextAttributes nameAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, color);
final String name = item.getCustomName();
if (name == null)
return false;
renderer.append(name, nameAttributes);
renderer.setIcon(item.getCustomIcon());
return true;
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
final JPanel component = (JPanel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (!hasMnemonic.get())
return component;
final JPanel panelWithMnemonic = new JPanel(new BorderLayout());
final int mnemonic = getMnemonic(value, itemsMap);
final JLabel label = new JLabel("");
if (mnemonic != -1) {
label.setText(mnemonic + ".");
label.setDisplayedMnemonicIndex(0);
}
label.setPreferredSize(new JLabel("8.").getPreferredSize());
final JComponent leftRenderer = (JComponent) component.getComponents()[0];
component.remove(leftRenderer);
panelWithMnemonic.setBorder(BorderFactory.createEmptyBorder(0, 7, 0, 0));
panelWithMnemonic.setBackground(leftRenderer.getBackground());
label.setBackground(leftRenderer.getBackground());
panelWithMnemonic.add(label, BorderLayout.WEST);
panelWithMnemonic.add(leftRenderer, BorderLayout.CENTER);
component.add(panelWithMnemonic);
return component;
}
};
final ListPopupImpl popup = new ListPopupImpl(new BaseListPopupStep<Object>(title, Arrays.asList(elements)) {
@Override
public boolean isSpeedSearchEnabled() {
return true;
}
@Override
public String getIndexedString(Object value) {
if (value instanceof GotoRelatedItem) {
//noinspection ConstantConditions
return ((GotoRelatedItem) value).getCustomName();
}
PsiElement element = (PsiElement) value;
if (!element.isValid())
return "INVALID";
return renderer.getElementText(element) + " " + renderer.getContainerText(element, null);
}
@Override
public PopupStep onChosen(Object selectedValue, boolean finalChoice) {
processor.process(selectedValue);
return super.onChosen(selectedValue, finalChoice);
}
}) {
};
popup.getList().setCellRenderer(new PopupListElementRenderer(popup) {
Map<Object, String> separators = new HashMap<>();
{
final ListModel model = popup.getList().getModel();
String current = null;
boolean hasTitle = false;
for (int i = 0; i < model.getSize(); i++) {
final Object element = model.getElementAt(i);
final GotoRelatedItem item = itemsMap.get(element);
if (item != null && !StringUtil.equals(current, item.getGroup())) {
current = item.getGroup();
separators.put(element, current);
if (!hasTitle && !StringUtil.isEmpty(current)) {
hasTitle = true;
}
}
}
if (!hasTitle) {
separators.remove(model.getElementAt(0));
}
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
final Component component = renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
final String separator = separators.get(value);
if (separator != null) {
JPanel panel = new JPanel(new BorderLayout());
panel.add(component, BorderLayout.CENTER);
final SeparatorWithText sep = new SeparatorWithText() {
@Override
protected void paintComponent(Graphics g) {
g.setColor(new JBColor(Color.WHITE, UIUtil.getSeparatorColor()));
g.fillRect(0, 0, getWidth(), getHeight());
super.paintComponent(g);
}
};
sep.setCaption(separator);
panel.add(sep, BorderLayout.NORTH);
return panel;
}
return component;
}
});
popup.setMinimumSize(new Dimension(200, -1));
for (Object item : elements) {
final int mnemonic = getMnemonic(item, itemsMap);
if (mnemonic != -1) {
final Action action = createNumberAction(mnemonic, popup, itemsMap, processor);
popup.registerAction(mnemonic + "Action", KeyStroke.getKeyStroke(String.valueOf(mnemonic)), action);
popup.registerAction(mnemonic + "Action", KeyStroke.getKeyStroke("NUMPAD" + String.valueOf(mnemonic)), action);
hasMnemonic.set(true);
}
}
return popup;
}
use of com.intellij.ui.ColoredListCellRenderer in project intellij-community by JetBrains.
the class ExpressionEditorWithHistory method showHistory.
private void showHistory() {
List<XExpression> expressions = getRecentExpressions();
if (!expressions.isEmpty()) {
ListPopupImpl historyPopup = new ListPopupImpl(new BaseListPopupStep<XExpression>(null, expressions) {
@Override
public PopupStep onChosen(XExpression selectedValue, boolean finalChoice) {
setExpression(selectedValue);
requestFocusInEditor();
return FINAL_CHOICE;
}
}) {
@Override
protected ListCellRenderer getListElementRenderer() {
return new ColoredListCellRenderer<XExpression>() {
@Override
protected void customizeCellRenderer(@NotNull JList list, XExpression value, int index, boolean selected, boolean hasFocus) {
append(value.getExpression(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
};
}
};
historyPopup.getList().setFont(EditorUtil.getEditorFont());
historyPopup.showUnderneathOf(getEditorComponent());
}
}
use of com.intellij.ui.ColoredListCellRenderer in project intellij-community by JetBrains.
the class LibraryOptionsPanel method showSettingsPanel.
private void showSettingsPanel(CustomLibraryDescription libraryDescription, NotNullComputable<String> pathProvider, FrameworkLibraryVersionFilter versionFilter, boolean showDoNotCreateOption, final List<? extends FrameworkLibraryVersion> versions) {
//todo[nik] create mySettings only in apply() method
mySettings = new LibraryCompositionSettings(libraryDescription, pathProvider, versionFilter, versions);
Disposer.register(this, mySettings);
List<Library> libraries = calculateSuitableLibraries();
myButtonEnumModel = RadioButtonEnumModel.bindEnum(Choice.class, myButtonGroup);
myButtonEnumModel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateState();
onVersionChanged(getPresentableVersion());
}
});
myDoNotCreateRadioButton.setVisible(showDoNotCreateOption);
myLibraryComboBoxModel = new SortedComboBoxModel<>((o1, o2) -> {
final String name1 = o1.getName();
final String name2 = o2.getName();
return -StringUtil.notNullize(name1).compareToIgnoreCase(StringUtil.notNullize(name2));
});
for (Library library : libraries) {
ExistingLibraryEditor libraryEditor = myLibrariesContainer.getLibraryEditor(library);
if (libraryEditor == null) {
libraryEditor = mySettings.getOrCreateEditor(library);
}
myLibraryComboBoxModel.add(libraryEditor);
}
myExistingLibraryComboBox.setModel(myLibraryComboBoxModel);
if (libraries.isEmpty()) {
myLibraryComboBoxModel.add(null);
}
myExistingLibraryComboBox.setSelectedIndex(0);
myExistingLibraryComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED && e.getItem() != null) {
myButtonEnumModel.setSelected(Choice.USE_LIBRARY);
}
updateState();
onVersionChanged(getPresentableVersion());
}
});
myExistingLibraryComboBox.setRenderer(new ColoredListCellRenderer<LibraryEditor>(myExistingLibraryComboBox) {
@Override
protected void customizeCellRenderer(@NotNull JList<? extends LibraryEditor> list, LibraryEditor value, int index, boolean selected, boolean hasFocus) {
if (value == null) {
append("[No library selected]");
} else if (value instanceof ExistingLibraryEditor) {
final Library library = ((ExistingLibraryEditor) value).getLibrary();
final boolean invalid = !((LibraryEx) library).getInvalidRootUrls(OrderRootType.CLASSES).isEmpty();
OrderEntryAppearanceService.getInstance().forLibrary(getProject(), library, invalid).customize(this);
} else if (value instanceof NewLibraryEditor) {
setIcon(PlatformIcons.LIBRARY_ICON);
final String name = value.getName();
append(name != null ? name : "<unnamed>");
}
}
});
boolean canDownload = mySettings.getDownloadSettings() != null;
boolean canUseFromProvider = myLibraryProvider != null;
myDownloadRadioButton.setVisible(canDownload);
myUseFromProviderRadioButton.setVisible(canUseFromProvider);
Choice selectedOption;
if (canUseFromProvider) {
selectedOption = Choice.USE_FROM_PROVIDER;
} else if (libraries.isEmpty() && canDownload) {
selectedOption = Choice.DOWNLOAD;
} else {
selectedOption = Choice.USE_LIBRARY;
doCreate(true);
}
myButtonEnumModel.setSelected(selectedOption);
if (!canDownload && !canUseFromProvider && !showDoNotCreateOption) {
myUseLibraryRadioButton.setVisible(false);
myUseLibraryLabel.setVisible(true);
} else {
myUseLibraryLabel.setVisible(false);
}
final Dimension minimumSize = new Dimension(-1, myMessageLabel.getFontMetrics(myMessageLabel.getFont()).getHeight() * 2);
myHiddenLabel.setMinimumSize(minimumSize);
myCreateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doCreate(false);
}
});
myConfigureButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
doConfigure();
}
});
updateState();
showCard("editing");
}
Aggregations