Search in sources :

Example 36 with NlModel

use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.

the class TreeTransferHandler method createTransferable.

@Override
protected Transferable createTransferable(JComponent c) {
    NlComponentTree tree = (NlComponentTree) c;
    setDragImage(getDragImageOfSelection(tree));
    NlModel model = tree.getDesignerModel();
    if (model == null || model.getSelectionModel().isEmpty()) {
        return null;
    }
    return model.getSelectionAsTransferable();
}
Also used : NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 37 with NlModel

use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.

the class ConstraintsLayer method paint.

/**
   * Base paint method. Draw the layer's background and call drawComponent() on the root component.
   *
   * @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;
    }
    NlModel myModel = myScreenView.getModel();
    if (!myShowOnHover && showOnSelection) {
        return;
    }
    if (myModel.getComponents().size() == 0) {
        return;
    }
    NlComponent component = myModel.getComponents().get(0);
    component = component.getRoot();
    // Draw the background
    Graphics2D g = (Graphics2D) gc.create();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Draw the components
    if (drawComponent(g, component, false)) {
        Dimension size = myScreenView.getSize();
        if (size.width != 0 && size.height != 0) {
            myDesignSurface.repaint(myScreenView.getX(), myScreenView.getY(), size.width, size.height);
        } else {
            myDesignSurface.repaint();
        }
    }
    g.dispose();
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 38 with NlModel

use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.

the class LayoutTestUtilities method createModel.

public static NlModel createModel(DesignSurface surface, AndroidFacet facet, XmlFile xmlFile) {
    NlModel model = SyncNlModel.create(surface, xmlFile.getProject(), facet, xmlFile);
    model.notifyModified(NlModel.ChangeType.UPDATE_HIERARCHY);
    return model;
}
Also used : NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 39 with NlModel

use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.

the class NlProperties method currentActivityIfFoundIsDerivedFromAppCompatActivity.

private static boolean currentActivityIfFoundIsDerivedFromAppCompatActivity(@NotNull List<NlComponent> components) {
    assert !components.isEmpty();
    NlModel model = components.get(0).getModel();
    Configuration configuration = model.getConfiguration();
    String activityClassName = configuration.getActivity();
    if (activityClassName == null) {
        // Assume we are since this is how the default activities are created.
        return true;
    }
    if (activityClassName.startsWith(".")) {
        MergedManifest manifest = MergedManifest.get(model.getModule());
        String pkg = StringUtil.notNullize(manifest.getPackage());
        activityClassName = pkg + activityClassName;
    }
    JavaPsiFacade facade = JavaPsiFacade.getInstance(model.getProject());
    PsiClass activityClass = facade.findClass(activityClassName, model.getModule().getModuleScope());
    while (activityClass != null && !CLASS_APP_COMPAT_ACTIVITY.equals(activityClass.getQualifiedName())) {
        activityClass = activityClass.getSuperClass();
    }
    return activityClass != null;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) Configuration(com.android.tools.idea.configurations.Configuration) MergedManifest(com.android.tools.idea.model.MergedManifest) PsiClass(com.intellij.psi.PsiClass) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 40 with NlModel

use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.

the class ViewEditorImpl method displayResourceInput.

@Nullable
@Override
public String displayResourceInput(@NotNull String title, @NotNull EnumSet<ResourceType> types) {
    NlModel model = myScreen.getModel();
    ChooseResourceDialog dialog = ChooseResourceDialog.builder().setModule(model.getModule()).setTypes(types).setConfiguration(model.getConfiguration()).build();
    if (!title.isEmpty()) {
        dialog.setTitle(title);
    }
    dialog.show();
    if (dialog.isOK()) {
        String resource = dialog.getResourceName();
        if (resource != null && !resource.isEmpty()) {
            return resource;
        }
    }
    return null;
}
Also used : ChooseResourceDialog(com.android.tools.idea.ui.resourcechooser.ChooseResourceDialog) NlModel(com.android.tools.idea.uibuilder.model.NlModel) Nullable(org.jetbrains.annotations.Nullable)

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