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