Search in sources :

Example 11 with ScreenView

use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.

the class NlPropertiesManager method setToolContext.

@Override
public void setToolContext(@Nullable DesignSurface designSurface) {
    if (designSurface == mySurface) {
        return;
    }
    if (mySurface != null) {
        mySurface.removeListener(this);
    }
    mySurface = designSurface;
    if (mySurface == null) {
        setScreenView(null);
    } else {
        mySurface.addListener(this);
        ScreenView screenView = mySurface.getCurrentScreenView();
        setScreenView(screenView);
        List<NlComponent> selection = screenView != null ? screenView.getSelectionModel().getSelection() : Collections.emptyList();
        componentSelectionChanged(mySurface, selection);
    }
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 12 with ScreenView

use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.

the class MockupTest method testGetBounds_0000_Position.

public void testGetBounds_0000_Position() {
    final NlModel model = createModel1Mockup(MOCKUP_PSD, "0 0 0 0", null);
    final NlComponent component = model.getComponents().get(0);
    final Mockup mockup = Mockup.create(component);
    assertNotNull(mockup);
    DesignSurface mockSurface = mock(DesignSurface.class);
    when(mockSurface.getScale()).thenReturn(1.0);
    final ScreenView screenView = new ScreenView(mockSurface, ScreenView.ScreenViewType.BLUEPRINT, model);
    final Rectangle componentSwingCoordinates = new Rectangle(0, 0, Coordinates.getSwingDimension(screenView, 1000), // See createModel for the 1000 value
    Coordinates.getSwingDimension(screenView, 1000));
    final Rectangle destinationRectangle = mockup.getScreenBounds(screenView);
    assertEquals(componentSwingCoordinates, destinationRectangle);
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 13 with ScreenView

use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.

the class WidgetNavigatorPanel method updateComponents.

/**
   * Set the selected component. If no component is selected, it will set the root of the previous selected component as the selected one
   *
   * @param selectedComponents
   */
public void updateComponents(@Nullable List<NlComponent> selectedComponents) {
    if (selectedComponents != null && !selectedComponents.isEmpty()) {
        myComponent = selectedComponents.get(0);
    } else if (myComponent != null) {
        // If not component are selected, displays the full screen
        myComponent = myComponent.getRoot();
    } else if (myDesignSurface != null) {
        final ScreenView currentScreenView = myDesignSurface.getCurrentScreenView();
        if (currentScreenView != null) {
            final List<NlComponent> components = currentScreenView.getModel().getComponents();
            myComponent = !components.isEmpty() ? components.get(0) : null;
        }
    }
    myMiniMap.repaint();
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 14 with ScreenView

use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.

the class WidgetNavigatorPanel method panningChanged.

@Override
public void panningChanged(AdjustmentEvent adjustmentEvent) {
    if (myDesignSurface == null) {
        return;
    }
    final Point scrollPosition = myDesignSurface.getScrollPosition();
    final ScreenView currentScreenView = myDesignSurface.getCurrentScreenView();
    if (currentScreenView != null) {
        myDesignSurfaceSize = myDesignSurface.getSize(myDesignSurfaceSize);
        final Dimension contentSize = myDesignSurface.getContentSize(null);
        computeScale(currentScreenView, myDesignSurfaceSize, contentSize);
    }
    myDesignSurfaceOffset.setLocation(scrollPosition.getX() * myScreenViewScale, scrollPosition.getY() * myScreenViewScale);
    repaint();
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 15 with ScreenView

use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.

the class ExtractWidgetTool method createAnActionButton.

@NotNull
private AnAction createAnActionButton(@NotNull final CreatorAction creatorAction, boolean viewGroupOnly) {
    return new AnAction(creatorAction.myTitle, creatorAction.myTitle, creatorAction.myIcon) {

        @Override
        public void update(AnActionEvent e) {
            Mockup mockup = myMockupEditor.getMockup();
            if (viewGroupOnly && (mockup == null || !canAddChild(creatorAction, mockup.getComponent()))) {
                e.getPresentation().setEnabledAndVisible(false);
            } else {
                e.getPresentation().setEnabledAndVisible(true);
            }
        }

        @Override
        public void actionPerformed(AnActionEvent e) {
            Mockup mockup = myMockupEditor.getMockup();
            ScreenView currentScreenView = mySurface.getCurrentScreenView();
            if (mockup == null) {
                myMockupEditor.showError("Cannot create a widget from an empty mockup");
                LOGGER.warn("MockupEditor has no associated mockup");
                return;
            }
            if (currentScreenView == null) {
                myMockupEditor.showError("The designer is not ready to create a new widget");
                LOGGER.warn("The DesignSurface does not have a current screen view");
                return;
            }
            WidgetCreator creator = WidgetCreatorFactory.create(creatorAction.myAndroidClassName, mockup, currentScreenView.getModel(), currentScreenView, mySelection);
            executeCreator(creator);
        }
    };
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) Mockup(com.android.tools.idea.uibuilder.mockup.Mockup) WidgetCreator(com.android.tools.idea.uibuilder.mockup.editor.creators.WidgetCreator) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)42 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)16 NlModel (com.android.tools.idea.uibuilder.model.NlModel)6 SelectionModel (com.android.tools.idea.uibuilder.model.SelectionModel)6 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)6 Nullable (org.jetbrains.annotations.Nullable)5 NotNull (org.jetbrains.annotations.NotNull)4 Configuration (com.android.tools.idea.configurations.Configuration)3 LintAnnotationsModel (com.android.tools.idea.uibuilder.lint.LintAnnotationsModel)2 Presentation (com.intellij.openapi.actionSystem.Presentation)2 BufferedImage (java.awt.image.BufferedImage)2 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)1 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)1 GradleDependencyManager (com.android.tools.idea.gradle.dependencies.GradleDependencyManager)1 RenderResult (com.android.tools.idea.rendering.RenderResult)1 InsertType (com.android.tools.idea.uibuilder.api.InsertType)1 ViewEditor (com.android.tools.idea.uibuilder.api.ViewEditor)1 ViewHandler (com.android.tools.idea.uibuilder.api.ViewHandler)1 ViewEditorImpl (com.android.tools.idea.uibuilder.handlers.ViewEditorImpl)1 LintNotificationPanel (com.android.tools.idea.uibuilder.lint.LintNotificationPanel)1