use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class AnchorTarget method mouseDrag.
/**
* On mouse drag, we can connect (in memory) to existing targets, or revert to the
* original state that we capatured on mouseDown.
*
* @param x
* @param y
* @param closestTarget
*/
@Override
public void mouseDrag(int x, int y, @Nullable Target closestTarget) {
myLastX = x;
myLastY = y;
if (closestTarget != null && closestTarget instanceof AnchorTarget) {
NlComponent component = myComponent.getNlComponent();
String attribute = getAttribute(closestTarget);
if (attribute != null) {
AnchorTarget targetAnchor = (AnchorTarget) closestTarget;
if (targetAnchor.myComponent != myComponent && !targetAnchor.isConnected(this)) {
NlComponent targetComponent = targetAnchor.myComponent.getNlComponent();
connectMe(component, attribute, targetComponent);
return;
}
}
}
revertToPreviousState();
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class AnchorTarget method mouseDown.
@Override
public void mouseDown(int x, int y) {
myLastX = -1;
myLastY = -1;
myConnectedX = -1;
myConnectedY = -1;
NlComponent component = myComponent.getNlComponent();
mPreviousAttributes.clear();
mPreviousAttributes.put(SdkConstants.ATTR_LAYOUT_EDITOR_ABSOLUTE_X, component.getLiveAttribute(SdkConstants.TOOLS_URI, SdkConstants.ATTR_LAYOUT_EDITOR_ABSOLUTE_X));
mPreviousAttributes.put(SdkConstants.ATTR_LAYOUT_EDITOR_ABSOLUTE_Y, component.getLiveAttribute(SdkConstants.TOOLS_URI, SdkConstants.ATTR_LAYOUT_EDITOR_ABSOLUTE_Y));
mPreviousAttributes.put(SdkConstants.ATTR_LAYOUT_BASELINE_TO_BASELINE_OF, component.getLiveAttribute(SdkConstants.SHERPA_URI, SdkConstants.ATTR_LAYOUT_BASELINE_TO_BASELINE_OF));
if (myComponent.getParent() != null) {
myComponent.getParent().setExpandTargetArea(true);
}
switch(myType) {
case LEFT:
{
rememberPreviousAttribute(SdkConstants.SHERPA_URI, ourLeftAttributes);
}
break;
case RIGHT:
{
rememberPreviousAttribute(SdkConstants.SHERPA_URI, ourRightAttributes);
}
break;
case TOP:
{
rememberPreviousAttribute(SdkConstants.SHERPA_URI, ourTopAttributes);
}
break;
case BOTTOM:
{
rememberPreviousAttribute(SdkConstants.SHERPA_URI, ourBottomAttributes);
}
break;
case BASELINE:
{
rememberPreviousAttribute(SdkConstants.SHERPA_URI, ourTopAttributes);
rememberPreviousAttribute(SdkConstants.SHERPA_URI, ourBottomAttributes);
mPreviousAttributes.put(SdkConstants.ATTR_LAYOUT_MARGIN_TOP, component.getLiveAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_LAYOUT_MARGIN_TOP));
mPreviousAttributes.put(SdkConstants.ATTR_LAYOUT_MARGIN_BOTTOM, component.getLiveAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_LAYOUT_MARGIN_BOTTOM));
mPreviousAttributes.put(SdkConstants.ATTR_LAYOUT_VERTICAL_BIAS, component.getLiveAttribute(SdkConstants.SHERPA_URI, SdkConstants.ATTR_LAYOUT_VERTICAL_BIAS));
}
break;
}
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class AnchorTarget method mouseRelease.
/**
* On mouseRelease, we can either disconnect the current anchor (if the mouse release is on ourselve)
* or connect the anchor to a given target. Modifications are applied first in memory then commited
* to the XML model.
*
* @param x
* @param y
* @param closestTarget
*/
@Override
public void mouseRelease(int x, int y, @Nullable Target closestTarget) {
myLastX = -1;
myLastY = -1;
if (myComponent.getParent() != null) {
myComponent.getParent().setExpandTargetArea(false);
}
if (closestTarget != null && closestTarget instanceof AnchorTarget && !(((AnchorTarget) closestTarget).isConnected(this))) {
NlComponent component = myComponent.getNlComponent();
if (closestTarget == this) {
disconnectMe(component);
} else {
String attribute = getAttribute(closestTarget);
if (attribute != null) {
AnchorTarget targetAnchor = (AnchorTarget) closestTarget;
NlComponent targetComponent = targetAnchor.myComponent.getNlComponent();
AttributesTransaction attributes = connectMe(component, attribute, targetComponent);
NlModel nlModel = component.getModel();
Project project = nlModel.getProject();
XmlFile file = nlModel.getFile();
String label = "Constraint Connected";
WriteCommandAction action = new WriteCommandAction(project, label, file) {
@Override
protected void run(@NotNull Result result) throws Throwable {
attributes.commit();
}
};
action.execute();
myComponent.getScene().needsLayout(Scene.ANIMATED_LAYOUT);
}
}
}
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class DragTarget method getTargetComponent.
//endregion
/////////////////////////////////////////////////////////////////////////////
//region Utilities
/////////////////////////////////////////////////////////////////////////////
@Nullable
private SceneComponent getTargetComponent(@NotNull String uri, @NotNull ArrayList<String> attributes) {
NlComponent nlComponent = myComponent.getNlComponent();
String target = null;
int count = attributes.size();
for (int i = 0; i < count; i++) {
target = nlComponent.getAttribute(uri, attributes.get(i));
if (target != null) {
if (target.equalsIgnoreCase(SdkConstants.ATTR_PARENT)) {
return myComponent.getParent();
}
target = NlComponent.extractId(target);
if (target != null) {
return myComponent.getScene().getSceneComponent(target);
}
}
}
return null;
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class NlPropertyOrderingTest method testGrouping.
public void testGrouping() {
@Language("XML") String source = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\" >" + " <TextView />" + "</RelativeLayout>";
NlComponent component = getFirstComponent(source);
Table<String, String, NlPropertyItem> properties = NlProperties.getInstance().getProperties(ImmutableList.of(component));
List<NlPropertyItem> propertyList = new ArrayList<>(properties.values());
List<PTableItem> items = new NlPropertiesGrouper().group(propertyList, ImmutableList.of(component));
// assert that all padding related attributes are grouped together
PTableItem padding = findItemByName(items, "Padding");
assertNotNull(padding);
assertNotNull("Attribute paddingStart missing inside padding attributes", findItemByName(padding.getChildren(), "paddingStart"));
assertNotNull("Attribute paddingEnd missing inside padding attributes", findItemByName(padding.getChildren(), "paddingEnd"));
// assert that textview attributes are grouped together (disabled for now)
//PTableItem textView = findItemByName(items, "TextView");
//assertNotNull("Missing group for TextView attributes", textView);
//assertNotNull("Attribute capitalize missing inside textview attributes", findItemByName(textView.getChildren(), "capitalize"));
//assertNotNull("Attribute password missing inside textview attributes", findItemByName(textView.getChildren(), "password"));
// certain special attrs should be at the top level
assertNotNull("Missing attribute id at the top level after grouping", findItemByName(items, "id"));
}
Aggregations