Search in sources :

Example 1 with JBColor

use of com.intellij.ui.JBColor in project android-selector-intellij-plugin by importre.

the class ColorIcon method getColor.

@Nullable
private JBColor getColor() {
    String regex = "((?:[0-9a-fA-F]{2})?)" + "([0-9a-fA-F]{2})" + "([0-9a-fA-F]{2})" + "([0-9a-fA-F]{2})";
    Pattern p = Pattern.compile(regex);
    try {
        if (color == null) {
            return null;
        }
        Matcher m = p.matcher(color);
        if (m.find()) {
            int r = Integer.parseInt(m.group(2), 16);
            int g = Integer.parseInt(m.group(3), 16);
            int b = Integer.parseInt(m.group(4), 16);
            if (m.group(1).isEmpty()) {
                return new JBColor(new Color(r, g, b), new Color(r, g, b));
            } else {
                int a = Integer.parseInt(m.group(1), 16);
                return new JBColor(new Color(r, g, b, a), new Color(r, g, b, a));
            }
        }
    } catch (Exception ignore) {
    }
    return null;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) JBColor(com.intellij.ui.JBColor) JBColor(com.intellij.ui.JBColor) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with JBColor

use of com.intellij.ui.JBColor in project android-selector-intellij-plugin by importre.

the class ColorIcon method paintIcon.

public void paintIcon(Component c, Graphics g, int x, int y) {
    JBColor color = getColor();
    if (color == null) {
        g.setColor(JBColor.WHITE);
        g.fillRect(1, 1, getIconWidth(), getIconHeight());
        g.setColor(JBColor.DARK_GRAY);
        if (g instanceof Graphics2D) {
            RenderingHints.Key key = RenderingHints.KEY_TEXT_ANTIALIASING;
            Object value = RenderingHints.VALUE_TEXT_ANTIALIAS_ON;
            ((Graphics2D) g).setRenderingHint(key, value);
        }
        String q = "?";
        FontMetrics fm = g.getFontMetrics();
        Rectangle2D r = fm.getStringBounds(q, g);
        x = (int) ((getIconWidth() - (int) r.getWidth()) * 0.7f);
        y = (getIconHeight() - (int) r.getHeight()) / 2 + fm.getAscent();
        g.drawString(q, x, y);
    } else {
        g.setColor(color);
        g.fillRect(1, 1, getIconWidth(), getIconHeight());
    }
    g.setColor(JBColor.DARK_GRAY);
    g.drawRect(1, 1, getIconWidth(), getIconHeight());
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) JBColor(com.intellij.ui.JBColor)

Example 3 with JBColor

use of com.intellij.ui.JBColor in project intellij-plugins by StepicOrg.

the class PresentationDataUtils method setAttributes.

private static void setAttributes(@NotNull Project project, @NotNull PresentationData data, @NotNull StudyNode item) {
    String text = item.getName();
    item.setProject(project);
    StudyStatus status = item.getStatus();
    JBColor color = getColor(status);
    Icon icon = getIcon(item, status);
    setAttributes(data, text, color, icon, item.getWasDeleted());
}
Also used : StudyStatus(org.stepik.core.courseFormat.StudyStatus) JBColor(com.intellij.ui.JBColor) PresentationUtils.getIcon(org.stepik.core.utils.PresentationUtils.getIcon)

Example 4 with JBColor

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

the class XmlReader method createComponent.

@NotNull
public static RadComponent createComponent(@NotNull final ModuleProvider module, @NotNull final LwComponent lwComponent, @NotNull final ClassLoader loader, final Locale stringDescriptorLocale) throws Exception {
    // Id
    final String id = lwComponent.getId();
    final RadComponent component;
    Class componentClass = null;
    if (lwComponent instanceof LwNestedForm) {
        LwNestedForm nestedForm = (LwNestedForm) lwComponent;
        boolean recursiveNesting = false;
        try {
            Utils.validateNestedFormLoop(nestedForm.getFormFileName(), new PsiNestedFormLoader(module.getModule()));
        } catch (RecursiveFormNestingException ex) {
            recursiveNesting = true;
        }
        if (recursiveNesting) {
            component = RadErrorComponent.create(module, id, lwComponent.getComponentClassName(), lwComponent.getErrorComponentProperties(), UIDesignerBundle.message("error.recursive.form.nesting"));
        } else {
            component = new RadNestedForm(module, nestedForm.getFormFileName(), id);
        }
    } else {
        if (lwComponent.getErrorComponentProperties() == null) {
            componentClass = Class.forName(lwComponent.getComponentClassName(), true, loader);
        }
        if (lwComponent instanceof LwHSpacer) {
            component = new RadHSpacer(module, id);
        } else if (lwComponent instanceof LwVSpacer) {
            component = new RadVSpacer(module, id);
        } else if (lwComponent instanceof LwAtomicComponent) {
            if (componentClass == null) {
                component = createErrorComponent(module, id, lwComponent, loader);
            } else {
                RadComponent component1;
                try {
                    if (JTable.class.isAssignableFrom(componentClass)) {
                        component1 = new RadTable(module, componentClass, id);
                    } else {
                        component1 = new RadAtomicComponent(module, componentClass, id);
                    }
                } catch (final Exception exc) {
                    String errorDescription = MessageFormat.format(UIDesignerBundle.message("error.class.cannot.be.instantiated"), lwComponent.getComponentClassName());
                    final String message = FormEditingUtil.getExceptionMessage(exc);
                    if (message != null) {
                        errorDescription += ": " + message;
                    }
                    component1 = RadErrorComponent.create(module, id, lwComponent.getComponentClassName(), lwComponent.getErrorComponentProperties(), errorDescription);
                }
                component = component1;
            }
        } else if (lwComponent instanceof LwScrollPane) {
            component = new RadScrollPane(module, componentClass, id);
        } else if (lwComponent instanceof LwTabbedPane) {
            component = new RadTabbedPane(module, componentClass, id);
        } else if (lwComponent instanceof LwSplitPane) {
            component = new RadSplitPane(module, componentClass, id);
        } else if (lwComponent instanceof LwToolBar) {
            component = new RadToolBar(module, componentClass, id);
        } else if (lwComponent instanceof LwContainer) {
            final LwContainer lwContainer = (LwContainer) lwComponent;
            LayoutManager layout = lwContainer.getLayout();
            if (layout instanceof XYLayoutManager) {
                // replace stub layout with the real one
                final XYLayoutManagerImpl xyLayoutManager = new XYLayoutManagerImpl();
                layout = xyLayoutManager;
                xyLayoutManager.setPreferredSize(lwComponent.getBounds().getSize());
            }
            if (componentClass == null) {
                component = createErrorComponent(module, id, lwComponent, loader);
            } else {
                if (lwContainer instanceof LwRootContainer) {
                    component = new RadRootContainer(module, id);
                    if (stringDescriptorLocale != null) {
                        ((RadRootContainer) component).setStringDescriptorLocale(stringDescriptorLocale);
                    }
                } else {
                    component = new RadContainer(module, componentClass, id);
                    String layoutManagerName = lwContainer.getLayoutManager();
                    if (layoutManagerName == null || layoutManagerName.length() == 0) {
                        if (layout instanceof XYLayoutManager) {
                            layoutManagerName = UIFormXmlConstants.LAYOUT_XY;
                        } else {
                            layoutManagerName = UIFormXmlConstants.LAYOUT_INTELLIJ;
                        }
                    }
                    RadLayoutManager layoutManager = LayoutManagerRegistry.createLayoutManager(layoutManagerName);
                    RadContainer container = (RadContainer) component;
                    layoutManager.readLayout(lwContainer, container);
                    container.setLayoutManager(layoutManager);
                }
                ((RadContainer) component).setLayout(layout);
            }
        } else {
            throw new IllegalArgumentException("unexpected component: " + lwComponent);
        }
    }
    // binding
    component.setBinding(lwComponent.getBinding());
    component.setCustomCreate(lwComponent.isCustomCreate());
    component.setDefaultBinding(lwComponent.isDefaultBinding());
    // bounds
    component.setBounds(lwComponent.getBounds());
    // properties
    if (stringDescriptorLocale != null) {
        component.putClientProperty(RadComponent.CLIENT_PROP_LOAD_TIME_LOCALE, stringDescriptorLocale);
    }
    final LwIntrospectedProperty[] properties = lwComponent.getAssignedIntrospectedProperties();
    if (componentClass != null) {
        final Palette palette = Palette.getInstance(module.getProject());
        for (final LwIntrospectedProperty lwProperty : properties) {
            final IntrospectedProperty property = palette.getIntrospectedProperty(component, lwProperty.getName());
            if (property == null) {
                continue;
            }
            component.loadLwProperty(lwComponent, lwProperty, property);
        }
    }
    // GridConstraints
    component.getConstraints().restore(lwComponent.getConstraints());
    component.setCustomLayoutConstraints(lwComponent.getCustomLayoutConstraints());
    HashMap clientProps = lwComponent.getDelegeeClientProperties();
    for (Object o : clientProps.entrySet()) {
        Map.Entry entry = (Map.Entry) o;
        Object value = entry.getValue();
        if (value instanceof StringDescriptor) {
            value = ((StringDescriptor) value).getValue();
        }
        component.getDelegee().putClientProperty(entry.getKey(), value);
    }
    if (component instanceof RadContainer) {
        final RadContainer container = (RadContainer) component;
        //noinspection ConstantConditions
        final LwContainer lwContainer = (LwContainer) lwComponent;
        copyBorder(container, lwContainer);
        // add children
        for (int i = 0; i < lwContainer.getComponentCount(); i++) {
            container.addComponent(createComponent(module, (LwComponent) lwContainer.getComponent(i), loader, stringDescriptorLocale));
        }
    }
    if (component instanceof RadRootContainer) {
        final RadRootContainer radRootContainer = (RadRootContainer) component;
        //noinspection ConstantConditions
        final LwRootContainer lwRootContainer = (LwRootContainer) lwComponent;
        radRootContainer.setClassToBind(lwRootContainer.getClassToBind());
        radRootContainer.setMainComponentBinding(lwRootContainer.getMainComponentBinding());
        radRootContainer.setButtonGroups(lwRootContainer.getButtonGroups());
        radRootContainer.setInspectionSuppressions(lwRootContainer.getInspectionSuppressions());
        radRootContainer.getDelegee().setBackground(new JBColor(Color.WHITE, UIUtil.getListBackground()));
    }
    component.doneLoadingFromLw();
    component.putClientProperty(RadComponent.CLIENT_PROP_LOAD_TIME_LOCALE, null);
    return component;
}
Also used : Palette(com.intellij.uiDesigner.palette.Palette) HashMap(java.util.HashMap) JBColor(com.intellij.ui.JBColor) XYLayoutManager(com.intellij.uiDesigner.shared.XYLayoutManager) RecursiveFormNestingException(com.intellij.uiDesigner.compiler.RecursiveFormNestingException) RecursiveFormNestingException(com.intellij.uiDesigner.compiler.RecursiveFormNestingException) XYLayoutManager(com.intellij.uiDesigner.shared.XYLayoutManager) IntrospectedProperty(com.intellij.uiDesigner.propertyInspector.IntrospectedProperty) HashMap(java.util.HashMap) Map(java.util.Map) PsiNestedFormLoader(com.intellij.uiDesigner.make.PsiNestedFormLoader) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with JBColor

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

the class DataFrameTableCellRenderer method getTableCellRendererComponent.

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
    super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
    if (value != null) {
        setText(value.toString());
    }
    if (!(value instanceof TableValueDescriptor)) {
        return this;
    }
    TableValueDescriptor descriptor = (TableValueDescriptor) value;
    if (hasFocus) {
        this.setBorder(new LineBorder(JBColor.BLUE, 2));
    }
    if (myColored) {
        try {
            double rangedValue = descriptor.getRangedValue();
            if (!Double.isNaN(rangedValue)) {
                this.setBackground(PyNumericViewUtil.rangedValueToColor(rangedValue));
            }
        } catch (NumberFormatException ignored) {
        }
    } else {
        this.setBackground(new JBColor(UIUtil.getBgFillColor(table), UIUtil.getBgFillColor(table)));
    }
    return this;
}
Also used : LineBorder(javax.swing.border.LineBorder) JBColor(com.intellij.ui.JBColor)

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