Search in sources :

Example 1 with DesignSurface

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

the class NlPreviewImagePanelTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    myFile = myFixture.copyFileToProject(BASE_PATH + "colors.xml", "res/values/colors.xml");
    myModel = createModel();
    mySurface = new DesignSurface(getProject(), false);
    mySurface.setModel(myModel);
    myDependencyManager = mock(DependencyManager.class);
    IconPreviewFactory iconPreviewFactory = mock(IconPreviewFactory.class);
    Runnable closeToolWindowCallback = mock(Runnable.class);
    //noinspection UndesirableClassUsage
    BufferedImage image = new BufferedImage(250, 50, TYPE_INT_ARGB);
    when(myDependencyManager.getProject()).thenReturn(getProject());
    when(iconPreviewFactory.renderDragImage(any(Palette.Item.class), any(ScreenView.class))).thenReturn(image);
    myPanel = new NlPreviewImagePanel(iconPreviewFactory, myDependencyManager, closeToolWindowCallback);
    myPanel.setDesignSurface(mySurface);
    myPanel.setItem(PaletteTestCase.findItem(NlPaletteModel.get(getProject()).getPalette(LAYOUT), BUTTON));
    myPanel.setSize(WIDTH, HEIGHT);
    myPanel.doLayout();
    paint();
    myRepaintManager = mock(RepaintManager.class);
    RepaintManager.setCurrentManager(myRepaintManager);
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) BufferedImage(java.awt.image.BufferedImage)

Example 2 with DesignSurface

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

the class NlEditorFixture method startResizeInteraction.

/**
   * Moves the mouse to the resize corner of the screen view, and presses the left mouse button.
   * That starts the canvas resize interaction.
   *
   * @see #resizeToAndroidSize(int, int)
   * @see #endResizeInteraction()
   */
public NlEditorFixture startResizeInteraction() {
    DesignSurface surface = myDesignSurfaceFixture.target();
    ScreenView screenView = surface.getCurrentScreenView();
    Dimension size = screenView.getSize();
    robot().pressMouse(surface, new Point(screenView.getX() + size.width + 24, screenView.getY() + size.height + 24));
    return this;
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView)

Example 3 with DesignSurface

use of com.android.tools.idea.uibuilder.surface.DesignSurface 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 4 with DesignSurface

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

the class ResizeFixture method pressKey.

public ResizeFixture pressKey(@MagicConstant(flagsFromClass = KeyEvent.class) int keyCode, char keyChar) {
    if (keyCode == KeyEvent.VK_SHIFT) {
        myModifiers |= InputEvent.SHIFT_MASK;
    }
    if (keyCode == KeyEvent.VK_META) {
        myModifiers |= InputEvent.META_MASK;
    }
    if (keyCode == KeyEvent.VK_CONTROL) {
        myModifiers |= InputEvent.CTRL_MASK;
    }
    if (keyCode == KeyEvent.VK_ALT) {
        myModifiers |= InputEvent.ALT_MASK;
    }
    DesignSurface surface = myScreen.getSurface();
    KeyEvent event = new KeyEventBuilder(keyCode, keyChar).withSource(surface).build();
    myInteraction.keyPressed(event);
    return this;
}
Also used : KeyEvent(java.awt.event.KeyEvent) DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface)

Example 5 with DesignSurface

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

the class LayoutTestUtilities method createSurface.

public static DesignSurface createSurface() {
    JComponent layeredPane = new JPanel();
    DesignSurface surface = mock(DesignSurface.class);
    when(surface.getLayeredPane()).thenReturn(layeredPane);
    return surface;
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface)

Aggregations

DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)17 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)7 Configuration (com.android.tools.idea.configurations.Configuration)4 KeyEvent (java.awt.event.KeyEvent)4 NlModel (com.android.tools.idea.uibuilder.model.NlModel)3 UsageTracker (com.android.tools.analytics.UsageTracker)2 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)2 AndroidStudioEvent (com.google.wireless.android.sdk.stats.AndroidStudioEvent)2 LinkedList (java.util.LinkedList)2 Result (com.android.ide.common.rendering.api.Result)1 ViewInfo (com.android.ide.common.rendering.api.ViewInfo)1 HtmlLinkManager (com.android.tools.idea.rendering.HtmlLinkManager)1 RenderLogger (com.android.tools.idea.rendering.RenderLogger)1 RenderResult (com.android.tools.idea.rendering.RenderResult)1 LayoutEditorRenderResult (com.google.wireless.android.sdk.stats.LayoutEditorRenderResult)1 LayoutEditorState (com.google.wireless.android.sdk.stats.LayoutEditorState)1 MockModule (com.intellij.mock.MockModule)1 CopyPasteManager (com.intellij.openapi.ide.CopyPasteManager)1 BufferedImage (java.awt.image.BufferedImage)1 Nullable (org.jetbrains.annotations.Nullable)1