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;
}
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());
}
}
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);
}
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);
}
}
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;
}
}
Aggregations