Search in sources :

Example 1 with SeparatorWithText

use of com.intellij.ui.SeparatorWithText in project intellij-community by JetBrains.

the class ListPopupImpl method handleNextStep.

private boolean handleNextStep(final PopupStep nextStep, Object parentValue, InputEvent e) {
    if (nextStep != PopupStep.FINAL_CHOICE) {
        final Point point = myList.indexToLocation(myList.getSelectedIndex());
        SwingUtilities.convertPointToScreen(point, myList);
        myChild = createPopup(this, nextStep, parentValue);
        if (myChild instanceof ListPopupImpl) {
            for (ListSelectionListener listener : myList.getListSelectionListeners()) {
                ((ListPopupImpl) myChild).addListSelectionListener(listener);
            }
        }
        final JComponent container = getContent();
        assert container != null : "container == null";
        int y = point.y;
        if (parentValue != null && getListModel().isSeparatorAboveOf(parentValue)) {
            SeparatorWithText swt = new SeparatorWithText();
            swt.setCaption(getListModel().getCaptionAboveOf(parentValue));
            y += swt.getPreferredSize().height - 1;
        }
        myChild.show(container, point.x + container.getWidth() - STEP_X_PADDING, y, true);
        setIndexForShowingChild(myList.getSelectedIndex());
        return false;
    } else {
        setOk(true);
        setFinalRunnable(myStep.getFinalRunnable());
        disposeAllParents(e);
        setIndexForShowingChild(-1);
        return true;
    }
}
Also used : SeparatorWithText(com.intellij.ui.SeparatorWithText) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 2 with SeparatorWithText

use of com.intellij.ui.SeparatorWithText in project intellij-community by JetBrains.

the class GutterIconsConfigurable method createUIComponents.

private void createUIComponents() {
    myList = new CheckBoxList<GutterIconDescriptor>() {

        @Override
        protected JComponent adjustRendering(JComponent rootComponent, JCheckBox checkBox, int index, boolean selected, boolean hasFocus) {
            JPanel panel = new JPanel(new BorderLayout());
            panel.setBorder(BorderFactory.createEmptyBorder());
            GutterIconDescriptor descriptor = myList.getItemAt(index);
            Icon icon = descriptor == null ? null : descriptor.getIcon();
            JLabel label = new JLabel(icon == null ? EmptyIcon.ICON_16 : icon);
            label.setOpaque(true);
            label.setPreferredSize(new Dimension(25, -1));
            label.setHorizontalAlignment(SwingConstants.CENTER);
            panel.add(label, BorderLayout.WEST);
            panel.add(checkBox, BorderLayout.CENTER);
            panel.setBackground(getBackground(false));
            label.setBackground(getBackground(selected));
            if (!checkBox.isOpaque()) {
                checkBox.setOpaque(true);
            }
            checkBox.setBorder(null);
            PluginDescriptor pluginDescriptor = myFirstDescriptors.get(descriptor);
            if (pluginDescriptor instanceof IdeaPluginDescriptor) {
                SeparatorWithText separator = new SeparatorWithText();
                String name = ((IdeaPluginDescriptor) pluginDescriptor).getName();
                separator.setCaption("IDEA CORE".equals(name) ? "Common" : name);
                panel.add(separator, BorderLayout.NORTH);
            }
            return panel;
        }

        @Nullable
        @Override
        protected Point findPointRelativeToCheckBox(int x, int y, @NotNull JCheckBox checkBox, int index) {
            return super.findPointRelativeToCheckBoxWithAdjustedRendering(x, y, checkBox, index);
        }
    };
    myList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    myList.setBorder(BorderFactory.createEmptyBorder());
}
Also used : IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint) LanguageExtensionPoint(com.intellij.lang.LanguageExtensionPoint) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint) LanguageExtensionPoint(com.intellij.lang.LanguageExtensionPoint) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginDescriptor(com.intellij.openapi.extensions.PluginDescriptor) SeparatorWithText(com.intellij.ui.SeparatorWithText) EmptyIcon(com.intellij.util.ui.EmptyIcon) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with SeparatorWithText

use of com.intellij.ui.SeparatorWithText 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;
}
Also used : PopupListElementRenderer(com.intellij.ui.popup.list.PopupListElementRenderer) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) PsiFile(com.intellij.psi.PsiFile) JBColor(com.intellij.ui.JBColor) PsiElement(com.intellij.psi.PsiElement) JBColor(com.intellij.ui.JBColor) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) SeparatorWithText(com.intellij.ui.SeparatorWithText) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem)

Aggregations

SeparatorWithText (com.intellij.ui.SeparatorWithText)3 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)1 LanguageExtensionPoint (com.intellij.lang.LanguageExtensionPoint)1 GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)1 ExtensionPoint (com.intellij.openapi.extensions.ExtensionPoint)1 PluginDescriptor (com.intellij.openapi.extensions.PluginDescriptor)1 PopupStep (com.intellij.openapi.ui.popup.PopupStep)1 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 ColoredListCellRenderer (com.intellij.ui.ColoredListCellRenderer)1 JBColor (com.intellij.ui.JBColor)1 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 ListPopupImpl (com.intellij.ui.popup.list.ListPopupImpl)1 PopupListElementRenderer (com.intellij.ui.popup.list.PopupListElementRenderer)1 EmptyIcon (com.intellij.util.ui.EmptyIcon)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1 Nullable (org.jetbrains.annotations.Nullable)1