Search in sources :

Example 1 with StringDescriptor

use of com.intellij.uiDesigner.lw.StringDescriptor 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 StringDescriptor

use of com.intellij.uiDesigner.lw.StringDescriptor 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 3 with StringDescriptor

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

the class Palette method processItemElement.

private void processItemElement(@NotNull final Element itemElement, @NotNull final GroupItem group, final boolean skipExisting) {
    // Class name. It's OK if class does not exist.
    final String className = LwXmlReader.getRequiredString(itemElement, ATTRIBUTE_CLASS);
    if (skipExisting && getItem(className) != null) {
        return;
    }
    // Icon (optional)
    final String iconPath = LwXmlReader.getString(itemElement, ATTRIBUTE_ICON);
    // Tooltip text (optional)
    // can be null
    final String toolTipText = LwXmlReader.getString(itemElement, ATTRIBUTE_TOOLTIP_TEXT);
    boolean autoCreateBinding = LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_AUTO_CREATE_BINDING, false);
    boolean canAttachLabel = LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_CAN_ATTACH_LABEL, false);
    boolean isContainer = LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_IS_CONTAINER, false);
    // Default constraint
    final GridConstraints constraints;
    final Element defaultConstraints = itemElement.getChild(ELEMENT_DEFAULT_CONSTRAINTS);
    if (defaultConstraints != null) {
        constraints = processDefaultConstraintsElement(defaultConstraints);
    } else {
        constraints = new GridConstraints();
    }
    final HashMap<String, StringDescriptor> propertyName2initialValue = new HashMap<>();
    {
        final Element initialValues = itemElement.getChild(ELEMENT_INITIAL_VALUES);
        if (initialValues != null) {
            for (final Object o : initialValues.getChildren(ELEMENT_PROPERTY)) {
                final Element e = (Element) o;
                final String name = LwXmlReader.getRequiredString(e, ATTRIBUTE_NAME);
                // TODO[all] currently all initial values are strings
                final StringDescriptor value = StringDescriptor.create(LwXmlReader.getRequiredString(e, ATTRIBUTE_VALUE));
                propertyName2initialValue.put(name, value);
            }
        }
    }
    final boolean removable = LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_REMOVABLE, true);
    final ComponentItem item = new ComponentItem(myProject, className, iconPath, toolTipText, constraints, propertyName2initialValue, removable, autoCreateBinding, canAttachLabel);
    item.setIsContainer(isContainer);
    addItem(group, item);
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints) HashMap(java.util.HashMap) Element(org.jdom.Element) StringDescriptor(com.intellij.uiDesigner.lw.StringDescriptor)

Example 4 with StringDescriptor

use of com.intellij.uiDesigner.lw.StringDescriptor 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 StringDescriptor

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

the class KeyChooserDialog method getDescriptor.

/**
   * @return resolved string descriptor. If user chose nothing then the
   * method returns <code>null</code>.
   */
@Nullable
StringDescriptor getDescriptor() {
    final int selectedRow = myTable.getSelectedRow();
    if (selectedRow < 0 || selectedRow >= myTable.getRowCount()) {
        return null;
    } else {
        final Couple<String> pair = myPairs.get(selectedRow);
        final StringDescriptor descriptor = new StringDescriptor(myBundleName, pair.getFirst());
        descriptor.setResolvedValue(pair.getSecond());
        return descriptor;
    }
}
Also used : StringDescriptor(com.intellij.uiDesigner.lw.StringDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

StringDescriptor (com.intellij.uiDesigner.lw.StringDescriptor)12 IProperty (com.intellij.uiDesigner.lw.IProperty)3 Nullable (org.jetbrains.annotations.Nullable)3 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)2 HashMap (java.util.HashMap)2 Element (org.jdom.Element)2 JavaI18nizeQuickFixDialog (com.intellij.codeInspection.i18n.JavaI18nizeQuickFixDialog)1 InstrumentationClassFinder (com.intellij.compiler.instrumentation.InstrumentationClassFinder)1 Project (com.intellij.openapi.project.Project)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 PsiFile (com.intellij.psi.PsiFile)1 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)1 SupportCode (com.intellij.uiDesigner.core.SupportCode)1 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 Rectangle2D (java.awt.geom.Rectangle2D)1 Map (java.util.Map)1 Type (org.jetbrains.org.objectweb.asm.Type)1 Method (org.jetbrains.org.objectweb.asm.commons.Method)1