use of com.android.tools.idea.uibuilder.model.AttributesTransaction in project android by JetBrains.
the class ResizeTarget method mouseRelease.
@Override
public void mouseRelease(int x, int y, @Nullable Target closestTarget) {
NlComponent component = myComponent.getNlComponent();
AttributesTransaction attributes = component.startAttributeTransaction();
updateAttributes(attributes, x, y);
attributes.apply();
NlModel nlModel = component.getModel();
Project project = nlModel.getProject();
XmlFile file = nlModel.getFile();
String label = "Constraint";
WriteCommandAction action = new WriteCommandAction(project, label, file) {
@Override
protected void run(@NotNull Result result) throws Throwable {
attributes.commit();
}
};
action.execute();
myComponent.getScene().needsLayout(Scene.IMMEDIATE_LAYOUT);
}
use of com.android.tools.idea.uibuilder.model.AttributesTransaction in project android by JetBrains.
the class DragDndTarget method mouseRelease.
public void mouseRelease(int x, int y, @NotNull NlComponent component) {
if (myComponent.getParent() != null) {
AttributesTransaction attributes = component.startAttributeTransaction();
int dx = x - myOffsetX;
int dy = y - myOffsetY;
if (myCurrentNotchX != null) {
dx = myCurrentNotchX.apply(dx);
if (myComponent.allowsAutoConnect()) {
myCurrentNotchX.apply(attributes);
}
myCurrentNotchX = null;
}
if (myCurrentNotchY != null) {
dy = myCurrentNotchY.apply(dy);
if (myComponent.allowsAutoConnect()) {
myCurrentNotchY.apply(attributes);
}
myCurrentNotchY = null;
}
updateAttributes(attributes, dx, dy);
cleanup(attributes);
attributes.apply();
attributes.commit();
}
if (myChangedComponent) {
myComponent.getScene().needsLayout(Scene.IMMEDIATE_LAYOUT);
}
}
use of com.android.tools.idea.uibuilder.model.AttributesTransaction in project android by JetBrains.
the class DragTarget method mouseRelease.
@Override
public void mouseRelease(int x, int y, @Nullable Target closestTarget) {
if (myComponent.getParent() != null) {
boolean commitChanges = true;
if (Math.abs(x - myFirstMouseX) <= 1 && Math.abs(y - myFirstMouseY) <= 1) {
commitChanges = false;
}
NlComponent component = myComponent.getNlComponent();
AttributesTransaction attributes = component.startAttributeTransaction();
int dx = x - myOffsetX;
int dy = y - myOffsetY;
if (myCurrentNotchX != null) {
dx = myCurrentNotchX.apply(dx);
if (myComponent.allowsAutoConnect()) {
myCurrentNotchX.apply(attributes);
}
myCurrentNotchX = null;
}
if (myCurrentNotchY != null) {
dy = myCurrentNotchY.apply(dy);
if (myComponent.allowsAutoConnect()) {
myCurrentNotchY.apply(attributes);
}
myCurrentNotchY = null;
}
updateAttributes(attributes, dx, dy);
cleanup(attributes);
attributes.apply();
if (commitChanges) {
NlModel nlModel = component.getModel();
Project project = nlModel.getProject();
XmlFile file = nlModel.getFile();
String label = "Component dragged";
WriteCommandAction action = new WriteCommandAction(project, label, file) {
@Override
protected void run(@NotNull Result result) throws Throwable {
attributes.commit();
}
};
action.execute();
}
}
if (myChangedComponent) {
myComponent.getScene().needsLayout(Scene.IMMEDIATE_LAYOUT);
}
}
use of com.android.tools.idea.uibuilder.model.AttributesTransaction in project android by JetBrains.
the class DragTarget method mouseDrag.
@Override
public void mouseDrag(int x, int y, @Nullable Target closestTarget) {
if (myComponent.getParent() == null) {
return;
}
NlComponent component = myComponent.getNlComponent();
AttributesTransaction attributes = component.startAttributeTransaction();
int dx = x - myOffsetX;
int dy = y - myOffsetY;
dx = snapX(dx);
dy = snapY(dy);
updateAttributes(attributes, dx, dy);
cleanup(attributes);
attributes.apply();
component.fireLiveChangeEvent();
myComponent.getScene().needsLayout(Scene.IMMEDIATE_LAYOUT);
myChangedComponent = true;
}
use of com.android.tools.idea.uibuilder.model.AttributesTransaction in project android by JetBrains.
the class AnchorTarget method revertToPreviousState.
/**
* Revert to the original (on mouse down) state.
*/
private void revertToPreviousState() {
NlComponent component = myComponent.getNlComponent();
AttributesTransaction attributes = component.startAttributeTransaction();
attributes.setAttribute(SdkConstants.SHERPA_URI, SdkConstants.ATTR_LAYOUT_BASELINE_TO_BASELINE_OF, null);
for (String key : mPreviousAttributes.keySet()) {
if (key.equalsIgnoreCase(SdkConstants.ATTR_LAYOUT_EDITOR_ABSOLUTE_X)) {
attributes.setAttribute(SdkConstants.TOOLS_URI, key, mPreviousAttributes.get(key));
} else if (key.equalsIgnoreCase(SdkConstants.ATTR_LAYOUT_EDITOR_ABSOLUTE_Y)) {
attributes.setAttribute(SdkConstants.TOOLS_URI, key, mPreviousAttributes.get(key));
} else if (key.equalsIgnoreCase(SdkConstants.ATTR_LAYOUT_MARGIN_TOP)) {
attributes.setAttribute(SdkConstants.ANDROID_URI, key, mPreviousAttributes.get(key));
} else if (key.equalsIgnoreCase(SdkConstants.ATTR_LAYOUT_MARGIN_BOTTOM)) {
attributes.setAttribute(SdkConstants.ANDROID_URI, key, mPreviousAttributes.get(key));
} else {
attributes.setAttribute(SdkConstants.SHERPA_URI, key, mPreviousAttributes.get(key));
}
}
attributes.apply();
myComponent.getScene().needsLayout(Scene.ANIMATED_LAYOUT);
}
Aggregations