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);
}
}
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);
}
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();
}
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();
}
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);
}
};
}
Aggregations