use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.
the class MockupEditor method setToolContext.
@Override
public void setToolContext(@Nullable DesignSurface newDesignSurface) {
if (mySurface != null) {
mySurface.removeListener(myDesignSurfaceListener);
mySurface = null;
myExtractWidgetTool.setDesignSurface(null);
}
ScreenView screenView = newDesignSurface != null ? newDesignSurface.getCurrentScreenView() : null;
if (screenView != null) {
mySurface = newDesignSurface;
mySurface.addListener(myDesignSurfaceListener);
setModel(screenView.getModel());
myExtractWidgetTool.setDesignSurface(mySurface);
}
}
use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.
the class MockupTest method testGetBounds_nullPosition.
public void testGetBounds_nullPosition() {
final NlModel model = createModel1Mockup(MOCKUP_PSD, null, 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 destinationRectangle = mockup.getScreenBounds(screenView);
assertEquals(new Rectangle(0, 0, component.w, component.h), destinationRectangle);
}
use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.
the class MockupTest method testGetBounds_Normal_Position.
public void testGetBounds_Normal_Position() {
final NlModel model = createModel1Mockup(MOCKUP_PSD, "0 0 -1 -1 10 10 120 50");
DesignSurface mockSurface = mock(DesignSurface.class);
when(mockSurface.getScale()).thenReturn(1.0);
Configuration configuration = mock(Configuration.class);
when(configuration.getDensity()).thenReturn(Density.DPI_280);
ScreenView screenView = mock(ScreenView.class);
when(screenView.getX()).thenReturn(0);
when(screenView.getY()).thenReturn(0);
when(screenView.getSize()).thenReturn(new Dimension(1000, 2000));
when(screenView.getSize(anyObject())).thenReturn(new Dimension(1000, 2000));
when(screenView.getScale()).thenReturn(2.);
when(screenView.getConfiguration()).thenReturn(configuration);
final Mockup mockup = Mockup.create(model.getComponents().get(0));
assertNotNull(mockup);
assertEquals(new Rectangle(10, 10, 120, 50), mockup.getBounds());
final Rectangle swingBounds = mockup.getScreenBounds(screenView);
assertEquals(Coordinates.getSwingXDip(screenView, 10), swingBounds.x, 2.);
assertEquals(Coordinates.getSwingXDip(screenView, 10), swingBounds.y, 2.);
assertEquals(Coordinates.getSwingDimensionDip(screenView, 110), swingBounds.width, 2.);
assertEquals(Coordinates.getSwingDimensionDip(screenView, 40), swingBounds.height, 2.);
}
use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.
the class GenerateLayoutTestSkeletonAction method getModel.
@Nullable
private static NlModel getModel(@Nullable Project project) {
if (project == null) {
return null;
}
DesignSurface surface = getSurface(project);
if (surface == null) {
return null;
}
ScreenView screenView = surface.getCurrentScreenView();
if (screenView == null) {
return null;
}
return screenView.getModel();
}
use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.
the class GotoComponentAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
ScreenView screenView = mySurface.getCurrentScreenView();
if (screenView != null) {
SelectionModel selectionModel = screenView.getSelectionModel();
NlComponent primary = selectionModel.getPrimary();
if (primary != null) {
XmlTag tag = primary.getTag();
if (tag.isValid()) {
screenView.getSurface().deactivate();
PsiNavigateUtil.navigate(tag);
}
}
}
}
Aggregations