use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.
the class MockupFileHelper method writePositionToXML.
/**
* Write the attribute {@link SdkConstants#ATTR_MOCKUP_CROP} and its value using the provided mockup
* @param mockup The mockup to retrieve the position string from
* @see #getPositionString(Mockup)
*/
public static void writePositionToXML(@NotNull Mockup mockup) {
NlComponent component = mockup.getComponent();
if (component == null) {
return;
}
final NlModel model = component.getModel();
final WriteCommandAction action = new WriteCommandAction(model.getProject(), "Edit Mockup Crop", model.getFile()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
if (mockup.isFullScreen()) {
component.removeAttribute(SdkConstants.TOOLS_URI, SdkConstants.ATTR_MOCKUP_CROP);
} else {
final String cropping = getPositionString(mockup);
component.setAttribute(SdkConstants.TOOLS_URI, SdkConstants.ATTR_MOCKUP_CROP, cropping);
}
}
};
action.execute();
}
use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.
the class TreeTransferHandler method exportDone.
@Override
protected void exportDone(JComponent c, Transferable transferable, int dropAction) {
if (dropAction == DnDConstants.ACTION_MOVE) {
// All we need to do is deleting the components that were moved out of this designer.
// Internal moves are handled by {@see NlDropListener} such that both the copy and the delete
// are in a single undo transaction.
NlComponentTree tree = (NlComponentTree) c;
NlModel model = tree.getDesignerModel();
assert model != null;
model.delete(tree.getSelectedComponents());
}
}
use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.
the class BlueprintLayer method paint.
/**
* Base buildDisplayList method. Draw the blueprint background.
* TODO: We might want to simplify the stack of layers and not keep this one.
*
* @param gc The Graphics object to draw into
*/
@Override
public void paint(@NotNull Graphics2D gc) {
myScreenView.getSize(myScreenViewSize);
mySizeRectangle.setBounds(myScreenView.getX(), myScreenView.getY(), myScreenViewSize.width, myScreenViewSize.height);
Rectangle2D.intersect(mySizeRectangle, gc.getClipBounds(), mySizeRectangle);
if (mySizeRectangle.isEmpty()) {
return;
}
// Draw the background
Graphics2D g = (Graphics2D) gc.create();
Shape prevClip = null;
Shape screenShape = myScreenView.getScreenShape();
if (screenShape != null) {
prevClip = g.getClip();
g.clip(screenShape);
}
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(BLUEPRINT_BG_COLOR);
g.fillRect(mySizeRectangle.x, mySizeRectangle.y, mySizeRectangle.width, mySizeRectangle.height);
if (prevClip != null) {
g.setClip(prevClip);
}
// Draw the components
NlModel model = myScreenView.getModel();
if (model.getComponents().size() == 0) {
return;
}
NlComponent component = model.getComponents().get(0);
component = component.getRoot();
ViewHandlerManager viewHandlerManager = ViewHandlerManager.get(model.getFacet());
// Draw the components
if (drawComponent(g, component, viewHandlerManager, false)) {
Dimension size = myScreenView.getSize();
DesignSurface surface = myScreenView.getSurface();
if (size.width != 0 && size.height != 0) {
surface.repaint(myScreenView.getX(), myScreenView.getY(), size.width, size.height);
} else {
surface.repaint();
}
}
g.dispose();
}
use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.
the class ModelBuilder method updateModel.
/** Update the given model to reflect the component hierarchy in the given builder */
public void updateModel(NlModel model, boolean preserveXmlTags) {
assertThat(model).isNotNull();
// temporary workaround: replacing contents not working
name("linear2.xml");
NlModel newModel = preserveXmlTags ? model : build();
model.updateHierarchy(newModel.getFile().getRootTag(), buildViewInfos(newModel));
for (NlComponent component : newModel.getComponents()) {
checkStructure(component);
}
}
use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.
the class WidgetConstraintPanel method removeAttribute.
private void removeAttribute(int type) {
String label = "Constraint Disconnected";
String[] attribute = ourDeleteAttributes[type];
String[] namespace = ourDeleteNamespace[type];
NlModel nlModel = mComponent.getModel();
Project project = nlModel.getProject();
XmlFile file = nlModel.getFile();
AttributesTransaction transaction = mComponent.startAttributeTransaction();
for (int i = 0; i < attribute.length; i++) {
transaction.setAttribute(namespace[i], attribute[i], null);
}
ConstraintComponentUtilities.ensureHorizontalPosition(mComponent, transaction);
ConstraintComponentUtilities.ensureVerticalPosition(mComponent, transaction);
transaction.apply();
WriteCommandAction action = new WriteCommandAction(project, label, file) {
@Override
protected void run(@NotNull Result result) throws Throwable {
transaction.commit();
}
};
action.execute();
}
Aggregations