Search in sources :

Example 16 with ScreenView

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

the class LayoutTestUtilities method createScreen.

public static ScreenView createScreen(DesignSurface surface, NlModel model, SelectionModel selectionModel, double scale, @SwingCoordinate int x, @SwingCoordinate int y, Density density) {
    Configuration configuration = mock(Configuration.class);
    when(configuration.getDensity()).thenReturn(density);
    when(configuration.getFile()).thenReturn(model.getFile().getVirtualFile());
    when(configuration.getFullConfig()).thenReturn(new FolderConfiguration());
    ScreenView screenView = mock(ScreenView.class);
    when(screenView.getConfiguration()).thenReturn(configuration);
    when(screenView.getModel()).thenReturn(model);
    when(screenView.getScale()).thenReturn(scale);
    when(screenView.getSelectionModel()).thenReturn(selectionModel);
    when(screenView.getSize()).thenReturn(new Dimension());
    when(screenView.getSurface()).thenReturn(surface);
    when(screenView.getX()).thenReturn(x);
    when(screenView.getY()).thenReturn(y);
    when(surface.getScreenView(anyInt(), anyInt())).thenReturn(screenView);
    return screenView;
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration)

Example 17 with ScreenView

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

the class WidgetNavigatorPanel method setSurface.

/**
   * Set the DesignSurface to display the minimap from
   *
   * @param surface
   */
public void setSurface(@Nullable DesignSurface surface) {
    updateScreenNumber(surface);
    if (surface == myDesignSurface) {
        return;
    }
    // Removing all listener for the oldSurface
    if (myDesignSurface != null) {
        myDesignSurface.removeListener(this);
        myDesignSurface.removePanZoomListener(this);
        myDesignSurface.removeAncestorListener(myAncestorListener);
        final ScreenView currentScreenView = myDesignSurface.getCurrentScreenView();
        if (currentScreenView != null) {
            currentScreenView.getModel().removeListener(this);
        }
    }
    myDesignSurface = surface;
    if (myDesignSurface == null) {
        return;
    }
    myDesignSurface.addListener(this);
    myDesignSurface.addPanZoomListener(this);
    myDesignSurface.addAncestorListener(myAncestorListener);
    final ScreenView currentScreenView = myDesignSurface.getCurrentScreenView();
    if (currentScreenView != null) {
        currentScreenView.getModel().addListener(this);
    }
    final Configuration configuration = myDesignSurface.getConfiguration();
    if (configuration != null) {
        updateDeviceConfiguration(configuration);
    }
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) Configuration(com.android.tools.idea.configurations.Configuration)

Example 18 with ScreenView

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

the class NlDropListener method captureDraggedComponents.

@Nullable
private InsertType captureDraggedComponents(@NotNull NlDropEvent event, boolean isPreview) {
    clearDraggedComponents();
    ScreenView screenView = myTree.getScreenView();
    if (screenView == null) {
        return null;
    }
    NlModel model = screenView.getModel();
    if (event.isDataFlavorSupported(ItemTransferable.DESIGNER_FLAVOR)) {
        try {
            myTransferItem = (DnDTransferItem) event.getTransferable().getTransferData(ItemTransferable.DESIGNER_FLAVOR);
            InsertType insertType = determineInsertType(event, isPreview);
            if (insertType.isMove()) {
                myDragged.addAll(keepOnlyAncestors(model.getSelectionModel().getSelection()));
            } else {
                Collection<NlComponent> captured = ApplicationManager.getApplication().runWriteAction((Computable<Collection<NlComponent>>) () -> model.createComponents(screenView, myTransferItem, insertType));
                if (captured != null) {
                    myDragged.addAll(keepOnlyAncestors(captured));
                }
            }
            return insertType;
        } catch (IOException | UnsupportedFlavorException exception) {
            Logger.getInstance(NlDropListener.class).warn(exception);
        }
    }
    return null;
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) InsertType(com.android.tools.idea.uibuilder.api.InsertType) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with ScreenView

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

the class NlPropertiesManager method getDefaultProperties.

@NotNull
public PropertiesMap getDefaultProperties(@NotNull List<NlComponent> components) {
    if (components.isEmpty()) {
        return PropertiesMap.EMPTY_MAP;
    }
    if (mySurface == null) {
        return PropertiesMap.EMPTY_MAP;
    }
    ScreenView view = mySurface.getCurrentScreenView();
    if (view == null) {
        return PropertiesMap.EMPTY_MAP;
    }
    Map<Object, PropertiesMap> map = view.getModel().getDefaultProperties();
    List<PropertiesMap> propertiesMaps = new ArrayList<>(components.size());
    for (NlComponent component : components) {
        PropertiesMap propertiesMap = map.get(component.getSnapshot());
        if (propertiesMap == null) {
            return PropertiesMap.EMPTY_MAP;
        }
        propertiesMaps.add(propertiesMap);
    }
    PropertiesMap first = propertiesMaps.get(0);
    if (propertiesMaps.size() == 1) {
        return first;
    }
    PropertiesMap commonProperties = new PropertiesMap();
    for (Map.Entry<String, PropertiesMap.Property> property : first.entrySet()) {
        boolean include = true;
        for (int index = 1; index < propertiesMaps.size(); index++) {
            PropertiesMap other = propertiesMaps.get(index);
            if (!property.getValue().equals(other.get(property.getKey()))) {
                include = false;
                break;
            }
        }
        if (include) {
            commonProperties.put(property.getKey(), property.getValue());
        }
    }
    return commonProperties;
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) ArrayList(java.util.ArrayList) PropertiesMap(com.android.util.PropertiesMap) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) PropertiesMap(com.android.util.PropertiesMap) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with ScreenView

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

the class ItemTransferHandler method createTransferable.

@Override
@Nullable
protected Transferable createTransferable(@NotNull JComponent component) {
    Palette.Item item = myItemSupplier.get();
    if (item == null) {
        return null;
    }
    ScreenView screenView = myDesignSurface.getCurrentScreenView();
    if (screenView == null) {
        return null;
    }
    @AndroidCoordinate Dimension size;
    BufferedImage image = myIconFactory.renderDragImage(item, screenView);
    if (image != null) {
        size = new Dimension(image.getWidth(), image.getHeight());
        double scale = myDesignSurface.getScale();
        image = ImageUtils.scale(image, scale);
    } else {
        Icon icon = item.getIcon();
        //noinspection UndesirableClassUsage
        image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = (Graphics2D) image.getGraphics();
        icon.paintIcon(component, g2, 0, 0);
        g2.dispose();
        double scale = myDesignSurface.getScale();
        size = new Dimension((int) (image.getWidth() / scale), (int) (image.getHeight() / scale));
    }
    setDragImage(image);
    setDragImageOffset(new Point(-image.getWidth() / 2, -image.getHeight() / 2));
    DnDTransferComponent dndComponent = new DnDTransferComponent(item.getTagName(), item.getXml(), size.width, size.height);
    return new ItemTransferable(new DnDTransferItem(dndComponent));
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) ItemTransferable(com.android.tools.idea.uibuilder.model.ItemTransferable) BufferedImage(java.awt.image.BufferedImage) AndroidCoordinate(com.android.tools.idea.uibuilder.model.AndroidCoordinate) DnDTransferComponent(com.android.tools.idea.uibuilder.model.DnDTransferComponent) DnDTransferItem(com.android.tools.idea.uibuilder.model.DnDTransferItem) Nullable(org.jetbrains.annotations.Nullable)

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