Search in sources :

Example 31 with NlModel

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();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 32 with NlModel

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());
    }
}
Also used : NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 33 with NlModel

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();
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ViewHandlerManager(com.android.tools.idea.uibuilder.handlers.ViewHandlerManager) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 34 with NlModel

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);
    }
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel) SyncNlModel(com.android.tools.idea.uibuilder.SyncNlModel)

Example 35 with NlModel

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();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction) Result(com.intellij.openapi.application.Result)

Aggregations

NlModel (com.android.tools.idea.uibuilder.model.NlModel)71 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)33 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)19 NotNull (org.jetbrains.annotations.NotNull)18 XmlFile (com.intellij.psi.xml.XmlFile)14 Project (com.intellij.openapi.project.Project)12 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)11 Result (com.intellij.openapi.application.Result)11 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)11 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)6 ComponentDescriptor (com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor)5 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)5 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)5 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)5 Configuration (com.android.tools.idea.configurations.Configuration)4 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 SelectionModel (com.android.tools.idea.uibuilder.model.SelectionModel)2 XmlTag (com.intellij.psi.xml.XmlTag)2 BufferedImage (java.awt.image.BufferedImage)2