use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.
the class NlDesignProperties method getDefinitionByName.
private static AttributeDefinition getDefinitionByName(@NotNull String name) {
AttributeDefinition definition = ToolsAttributeUtil.getAttrDefByName(name);
assert definition != null;
ResolvingConverter converter = ToolsAttributeUtil.getConverter(definition);
// TODO: Figure out how to provide the correct reference editor depending on the converter.
if (converter instanceof StaticEnumConverter) {
Collection variants = converter.getVariants(null);
for (Object variant : variants) {
definition.addValue(variant.toString());
}
}
return definition;
}
use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.
the class NlBooleanIconEditor method updateDescription.
private void updateDescription(@NotNull NlProperty property) {
AttributeDefinition definition = property.getDefinition();
if (definition != null) {
String description = definition.getValueDoc(myAction.myTrueValue);
if (description != null) {
// TODO: Add a getter of the presentation instance in ActionButton. Then we can get rid of myPresentation.
myPresentation.setDescription(description);
myPresentation.setText(description);
}
}
}
use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.
the class NlPropertyEditors method getEditorType.
@NotNull
private static EditorType getEditorType(@NotNull NlProperty property) {
AttributeDefinition definition = property.getDefinition();
Set<AttributeFormat> formats = definition != null ? definition.getFormats() : Collections.emptySet();
Boolean isBoolean = null;
for (AttributeFormat format : formats) {
switch(format) {
case Boolean:
if (isBoolean == null) {
isBoolean = Boolean.TRUE;
}
break;
case String:
case Color:
case Dimension:
case Integer:
case Float:
case Fraction:
if (isBoolean == null) {
isBoolean = Boolean.FALSE;
}
break;
case Enum:
return EditorType.COMBO;
case Flag:
return EditorType.FLAG;
default:
break;
}
}
// Do not inline this method. Other classes should not know about EnumSupportFactory.
if (isBoolean == Boolean.TRUE) {
return EditorType.BOOLEAN;
} else if (EnumSupportFactory.supportsProperty(property)) {
if (property.getName().equals(ATTR_STYLE)) {
return EditorType.COMBO_WITH_BROWSE;
}
return EditorType.COMBO;
}
return EditorType.DEFAULT;
}
use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.
the class Quantity method addUnit.
@NotNull
public static String addUnit(@NotNull NlProperty property, @NotNull String value) {
AttributeDefinition definition = property.getDefinition();
boolean isDimension = definition != null && definition.getFormats().contains(AttributeFormat.Dimension);
if (!isDimension) {
return value;
}
Quantity quantity = parse(value);
if (quantity == null || !quantity.myUnit.isEmpty()) {
return value;
}
switch(property.getName()) {
case SdkConstants.ATTR_TEXT_SIZE:
case SdkConstants.ATTR_LINE_SPACING_EXTRA:
return quantity.myValue + SdkConstants.UNIT_SP;
default:
return quantity.myValue + SdkConstants.UNIT_DP;
}
}
use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.
the class NlEnumEditor method findBestInsertionPoint.
private int findBestInsertionPoint(@NotNull ValueWithDisplayString newValue) {
AttributeDefinition definition = myProperty.getDefinition();
boolean isDimension = definition != null && definition.getFormats().contains(AttributeFormat.Dimension);
int startIndex = 1;
if (!isDimension) {
return startIndex;
}
String newTextValue = newValue.getDisplayString();
if (StringUtil.isEmpty(newTextValue)) {
return startIndex;
}
Quantity newQuantity = Quantity.parse(newTextValue);
if (newQuantity == null) {
return startIndex;
}
ComboBoxModel<ValueWithDisplayString> model = myCombo.getModel();
for (int index = startIndex, size = model.getSize(); index < size; index++) {
String textValue = model.getElementAt(index).getValue();
if (textValue != null) {
Quantity quantity = Quantity.parse(textValue);
if (newQuantity.compareTo(quantity) <= 0) {
return index;
}
}
}
return model.getSize();
}
Aggregations