Search in sources :

Example 26 with JBColor

use of com.intellij.ui.JBColor in project android by JetBrains.

the class AndroidRunConfigurationEditor method createUIComponents.

private void createUIComponents() {
    // JBColor keeps a strong reference to its parameter func, so, using a lambda avoids this reference and fixes a leak
    myOldVersionLabel = new HyperlinkLabel("", JBColor.RED, new JBColor(UIUtil::getLabelBackground), PlatformColors.BLUE);
    setSyncLinkMessage("");
    myOldVersionLabel.addHyperlinkListener(this);
}
Also used : JBColor(com.intellij.ui.JBColor) HyperlinkLabel(com.intellij.ui.HyperlinkLabel) UIUtil(com.intellij.util.ui.UIUtil)

Example 27 with JBColor

use of com.intellij.ui.JBColor in project android by JetBrains.

the class StateChartVisualTest method getFruitStateColor.

private static EnumMap<MockFruitState, Color> getFruitStateColor() {
    EnumMap<MockFruitState, Color> colors = new EnumMap<>(MockFruitState.class);
    colors.put(MockFruitState.NONE, new JBColor(new Color(0, 0, 0, 0), new Color(0, 0, 0, 0)));
    colors.put(MockFruitState.APPLE, JBColor.RED);
    colors.put(MockFruitState.GRAPE, JBColor.MAGENTA);
    colors.put(MockFruitState.ORANGE, JBColor.ORANGE);
    colors.put(MockFruitState.BANANA, JBColor.YELLOW);
    return colors;
}
Also used : JBColor(com.intellij.ui.JBColor) JBColor(com.intellij.ui.JBColor) EnumMap(java.util.EnumMap)

Example 28 with JBColor

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

the class HTMLTextPainter method writeHeader.

private void writeHeader(@NonNls Writer writer, String title) throws IOException {
    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    writer.write("<html>\r\n");
    writer.write("<head>\r\n");
    writer.write("<title>" + title + "</title>\r\n");
    writer.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n");
    writeStyles(writer);
    writer.write("</head>\r\n");
    Color color = scheme.getDefaultBackground();
    if (color == null)
        color = JBColor.GRAY;
    writer.write("<BODY BGCOLOR=\"#" + Integer.toString(color.getRGB() & 0xFFFFFF, 16) + "\">\r\n");
    writer.write("<TABLE CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH=\"100%\" BGCOLOR=\"#" + ColorUtil.toHex(new JBColor(Gray.xC0, Gray.x60)) + "\" >\r\n");
    writer.write("<TR><TD><CENTER>\r\n");
    writer.write("<FONT FACE=\"Arial, Helvetica\" COLOR=\"#000000\">\r\n");
    writer.write(title + "</FONT>\r\n");
    writer.write("</center></TD></TR></TABLE>\r\n");
    writer.write("<pre>\r\n");
}
Also used : JBColor(com.intellij.ui.JBColor) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) JBColor(com.intellij.ui.JBColor)

Example 29 with JBColor

use of com.intellij.ui.JBColor 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)

Example 30 with JBColor

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

the class PluginsTableRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (myPluginDescriptor != null) {
        Couple<Color> colors = UIUtil.getCellColors(table, isSelected, row, column);
        Color fg = colors.getFirst();
        final Color background = colors.getSecond();
        Color grayedFg = isSelected ? fg : new JBColor(Gray._130, Gray._120);
        myPanel.setBackground(background);
        myName.setForeground(fg);
        myCategory.setForeground(grayedFg);
        myStatus.setForeground(grayedFg);
        myLastUpdated.setForeground(grayedFg);
        myDownloads.setForeground(grayedFg);
        myName.clear();
        myName.setOpaque(false);
        myCategory.clear();
        myCategory.setOpaque(false);
        String pluginName = myPluginDescriptor.getName() + "  ";
        Object query = table.getClientProperty(SpeedSearchSupply.SEARCH_QUERY_KEY);
        SimpleTextAttributes attr = new SimpleTextAttributes(UIUtil.getListBackground(isSelected), UIUtil.getListForeground(isSelected), JBColor.RED, SimpleTextAttributes.STYLE_PLAIN);
        Matcher matcher = NameUtil.buildMatcher("*" + query, NameUtil.MatchingCaseSensitivity.NONE);
        if (query instanceof String) {
            SpeedSearchUtil.appendColoredFragmentForMatcher(pluginName, myName, attr, matcher, UIUtil.getTableBackground(isSelected), true);
        } else {
            myName.append(pluginName);
        }
        String category = myPluginDescriptor.getCategory() == null ? null : StringUtil.toUpperCase(myPluginDescriptor.getCategory());
        if (category != null) {
            if (query instanceof String) {
                SpeedSearchUtil.appendColoredFragmentForMatcher(category, myCategory, attr, matcher, UIUtil.getTableBackground(isSelected), true);
            } else {
                myCategory.append(category);
            }
        } else if (!myPluginsView) {
            myCategory.append(AvailablePluginsManagerMain.N_A);
        }
        myStatus.setIcon(AllIcons.Nodes.Plugin);
        if (myPluginDescriptor.isBundled()) {
            myCategory.append(" [Bundled]");
            myStatus.setIcon(AllIcons.Nodes.PluginJB);
        }
        String vendor = myPluginDescriptor.getVendor();
        if (vendor != null && StringUtil.containsIgnoreCase(vendor, "jetbrains")) {
            myStatus.setIcon(AllIcons.Nodes.PluginJB);
        }
        String downloads = myPluginDescriptor.getDownloads();
        if (downloads != null && myPluginDescriptor instanceof PluginNode) {
            if (downloads.length() > 3) {
                downloads = new DecimalFormat("#,###").format(Integer.parseInt(downloads));
            }
            myDownloads.setText(downloads);
            myRating.setRate(((PluginNode) myPluginDescriptor).getRating());
            myLastUpdated.setText(DateFormatUtil.formatBetweenDates(((PluginNode) myPluginDescriptor).getDate(), System.currentTimeMillis()));
        }
        // plugin state-dependent rendering
        PluginId pluginId = myPluginDescriptor.getPluginId();
        IdeaPluginDescriptor installed = PluginManager.getPlugin(pluginId);
        if (installed != null && ((IdeaPluginDescriptorImpl) installed).isDeleted()) {
            // existing plugin uninstalled (both views)
            myStatus.setIcon(AllIcons.Nodes.PluginRestart);
            if (!isSelected)
                myName.setForeground(FileStatus.DELETED.getColor());
            myPanel.setToolTipText(IdeBundle.message("plugin.manager.uninstalled.tooltip"));
        } else if (ourState.wasInstalled(pluginId)) {
            // new plugin installed (both views)
            myStatus.setIcon(AllIcons.Nodes.PluginRestart);
            if (!isSelected)
                myName.setForeground(FileStatus.ADDED.getColor());
            myPanel.setToolTipText(IdeBundle.message("plugin.manager.installed.tooltip"));
        } else if (ourState.wasUpdated(pluginId)) {
            // existing plugin updated (both views)
            myStatus.setIcon(AllIcons.Nodes.PluginRestart);
            if (!isSelected)
                myName.setForeground(FileStatus.ADDED.getColor());
            myPanel.setToolTipText(IdeBundle.message("plugin.manager.updated.tooltip"));
        } else if (ourState.hasNewerVersion(pluginId)) {
            // existing plugin has a newer version (both views)
            myStatus.setIcon(AllIcons.Nodes.Pluginobsolete);
            if (!isSelected)
                myName.setForeground(FileStatus.MODIFIED.getColor());
            if (!myPluginsView && installed != null) {
                myPanel.setToolTipText(IdeBundle.message("plugin.manager.new.version.tooltip", installed.getVersion()));
            } else {
                myPanel.setToolTipText(IdeBundle.message("plugin.manager.update.available.tooltip"));
            }
        } else if (isIncompatible(myPluginDescriptor, table.getModel())) {
            // a plugin is incompatible with current installation (both views)
            if (!isSelected)
                myName.setForeground(JBColor.RED);
            myPanel.setToolTipText(whyIncompatible(myPluginDescriptor, table.getModel()));
        } else if (!myPluginDescriptor.isEnabled() && myPluginsView) {
            // a plugin is disabled (plugins view only)
            myStatus.setIcon(IconLoader.getDisabledIcon(myStatus.getIcon()));
        }
    }
    return myPanel;
}
Also used : Matcher(com.intellij.util.text.Matcher) JBColor(com.intellij.ui.JBColor) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) DecimalFormat(java.text.DecimalFormat) JBColor(com.intellij.ui.JBColor) PluginId(com.intellij.openapi.extensions.PluginId)

Aggregations

JBColor (com.intellij.ui.JBColor)51 GraphicsConfig (com.intellij.openapi.ui.GraphicsConfig)8 NotNull (org.jetbrains.annotations.NotNull)8 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)4 Rectangle2D (java.awt.geom.Rectangle2D)4 UIUtil (com.intellij.util.ui.UIUtil)3 Project (com.intellij.openapi.project.Project)2 BalloonLayout (com.intellij.ui.BalloonLayout)2 BalloonLayoutData (com.intellij.ui.BalloonLayoutData)2 StudyStatus (com.jetbrains.edu.learning.courseFormat.StudyStatus)2 RoundRectangle2D (java.awt.geom.RoundRectangle2D)2 BasicArrowButton (javax.swing.plaf.basic.BasicArrowButton)2 Nullable (org.jetbrains.annotations.Nullable)2 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)1 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)1 LegendComponent (com.android.tools.adtui.LegendComponent)1 LegendRenderData (com.android.tools.adtui.LegendRenderData)1 TimelineComponent (com.android.tools.adtui.TimelineComponent)1 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)1 MergedManifest (com.android.tools.idea.model.MergedManifest)1