Search in sources :

Example 1 with IProperty

use of com.intellij.uiDesigner.lw.IProperty in project intellij-community by JetBrains.

the class FormInspectionUtil method getText.

@Nullable
public static String getText(@NotNull final Module module, final IComponent component) {
    IProperty textProperty = findProperty(component, SwingProperties.TEXT);
    if (textProperty != null) {
        Object propValue = textProperty.getPropertyValue(component);
        String value = null;
        if (propValue instanceof StringDescriptor) {
            StringDescriptor descriptor = (StringDescriptor) propValue;
            if (component instanceof RadComponent) {
                value = StringDescriptorManager.getInstance(module).resolve((RadComponent) component, descriptor);
            } else {
                value = StringDescriptorManager.getInstance(module).resolve(descriptor, null);
            }
        } else if (propValue instanceof String) {
            value = (String) propValue;
        }
        if (value != null) {
            return value;
        }
    }
    return null;
}
Also used : IProperty(com.intellij.uiDesigner.lw.IProperty) StringDescriptor(com.intellij.uiDesigner.lw.StringDescriptor) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with IProperty

use of com.intellij.uiDesigner.lw.IProperty in project intellij-community by JetBrains.

the class Java15FormInspection method checkComponentProperties.

protected void checkComponentProperties(Module module, final IComponent component, final FormErrorCollector collector) {
    final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
    final PsiManager psiManager = PsiManager.getInstance(module.getProject());
    final PsiClass aClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(component.getComponentClassName(), scope);
    if (aClass == null) {
        return;
    }
    for (final IProperty prop : component.getModifiedProperties()) {
        final PsiMethod getter = PropertyUtil.findPropertyGetter(aClass, prop.getName(), false, true);
        if (getter == null)
            continue;
        final LanguageLevel languageLevel = LanguageLevelUtil.getEffectiveLanguageLevel(module);
        if (Java15APIUsageInspection.getLastIncompatibleLanguageLevel(getter, languageLevel) != null) {
            registerError(component, collector, prop, "@since " + Java15APIUsageInspection.getShortName(languageLevel));
        }
    }
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) IProperty(com.intellij.uiDesigner.lw.IProperty) PsiMethod(com.intellij.psi.PsiMethod) LanguageLevel(com.intellij.pom.java.LanguageLevel) PsiClass(com.intellij.psi.PsiClass) PsiManager(com.intellij.psi.PsiManager)

Example 3 with IProperty

use of com.intellij.uiDesigner.lw.IProperty in project intellij-community by JetBrains.

the class Painter method paintComponentTag.

public static void paintComponentTag(final RadComponent component, final Graphics g) {
    if (component instanceof RadContainer)
        return;
    for (IProperty prop : component.getModifiedProperties()) {
        if (prop.getName().equals(SwingProperties.TEXT)) {
            final Object desc = prop.getPropertyValue(component);
            if (!(desc instanceof StringDescriptor) || ((StringDescriptor) desc).getValue() == null || ((StringDescriptor) desc).getValue().length() > 0) {
                return;
            }
        } else if (prop.getName().equals(SwingProperties.MODEL)) {
            // don't paint tags on non-empty lists
            final Object value = prop.getPropertyValue(component);
            if (value instanceof String[] && ((String[]) value).length > 0) {
                return;
            }
        }
    }
    Rectangle bounds = component.getDelegee().getBounds();
    if (bounds.width > 100 && bounds.height > 40) {
        StringBuilder tagBuilder = new StringBuilder();
        if (component.getBinding() != null) {
            tagBuilder.append(component.getBinding()).append(':');
        }
        String className = component.getComponentClassName();
        int pos = className.lastIndexOf('.');
        if (pos >= 0) {
            tagBuilder.append(className.substring(pos + 1));
        } else {
            tagBuilder.append(className);
        }
        final Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(tagBuilder.toString(), g);
        Graphics2D g2d = (Graphics2D) g;
        g2d.setColor(PlatformColors.BLUE);
        g2d.fillRect(0, 0, (int) stringBounds.getWidth(), (int) stringBounds.getHeight());
        g2d.setColor(JBColor.WHITE);
        UISettings.setupAntialiasing(g);
        g.drawString(tagBuilder.toString(), 0, g.getFontMetrics().getAscent());
    }
}
Also used : IProperty(com.intellij.uiDesigner.lw.IProperty) StringDescriptor(com.intellij.uiDesigner.lw.StringDescriptor) Rectangle2D(java.awt.geom.Rectangle2D)

Example 4 with IProperty

use of com.intellij.uiDesigner.lw.IProperty in project intellij-community by JetBrains.

the class AssignMnemonicFix method run.

public void run() {
    IProperty textProperty = FormInspectionUtil.findProperty(myComponent, SwingProperties.TEXT);
    StringDescriptor descriptor = (StringDescriptor) textProperty.getPropertyValue(myComponent);
    String value = StringDescriptorManager.getInstance(myComponent.getModule()).resolve(myComponent, descriptor);
    String[] variants = fillMnemonicVariants(SupportCode.parseText(value).myText);
    String result = Messages.showEditableChooseDialog(UIDesignerBundle.message("inspection.missing.mnemonics.quickfix.prompt"), UIDesignerBundle.message("inspection.missing.mnemonics.quickfix.title"), Messages.getQuestionIcon(), variants, variants[0], null);
    if (result != null) {
        if (!myEditor.ensureEditable()) {
            return;
        }
        FormInspectionUtil.updateStringPropertyValue(myEditor, myComponent, (IntroStringProperty) textProperty, descriptor, result);
    }
}
Also used : IProperty(com.intellij.uiDesigner.lw.IProperty) StringDescriptor(com.intellij.uiDesigner.lw.StringDescriptor)

Example 5 with IProperty

use of com.intellij.uiDesigner.lw.IProperty in project intellij-community by JetBrains.

the class IntroStringProperty method checkUpdateBindingFromText.

private static void checkUpdateBindingFromText(final RadComponent component, final StringDescriptor value, final SupportCode.TextWithMnemonic textWithMnemonic) {
    if (component.isLoadingProperties()) {
        return;
    }
    // only generate binding from text if default locale is active (IDEADEV-9427)
    if (value.getValue() == null) {
        RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(component);
        Locale locale = root.getStringDescriptorLocale();
        if (locale != null && locale.getDisplayName().length() > 0) {
            return;
        }
    }
    BindingProperty.checkCreateBindingFromText(component, textWithMnemonic.myText);
    if (component.getDelegee() instanceof JLabel) {
        for (IProperty prop : component.getModifiedProperties()) {
            if (prop.getName().equals(SwingProperties.LABEL_FOR) && prop instanceof IntroComponentProperty) {
                ((IntroComponentProperty) prop).updateLabelForBinding(component);
            }
        }
    }
}
Also used : Locale(java.util.Locale) IProperty(com.intellij.uiDesigner.lw.IProperty) RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer)

Aggregations

IProperty (com.intellij.uiDesigner.lw.IProperty)10 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)5 StringDescriptor (com.intellij.uiDesigner.lw.StringDescriptor)3 Ref (com.intellij.openapi.util.Ref)2 IComponent (com.intellij.uiDesigner.lw.IComponent)2 BindingProperty (com.intellij.uiDesigner.propertyInspector.properties.BindingProperty)2 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)2 LanguageLevel (com.intellij.pom.java.LanguageLevel)1 PsiClass (com.intellij.psi.PsiClass)1 PsiManager (com.intellij.psi.PsiManager)1 PsiMethod (com.intellij.psi.PsiMethod)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)1 ComponentTree (com.intellij.uiDesigner.componentTree.ComponentTree)1 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)1 SupportCode (com.intellij.uiDesigner.core.SupportCode)1 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)1 ComponentItem (com.intellij.uiDesigner.palette.ComponentItem)1 Palette (com.intellij.uiDesigner.palette.Palette)1 DesignerToolWindow (com.intellij.uiDesigner.propertyInspector.DesignerToolWindow)1