use of com.android.tools.idea.uibuilder.handlers.ViewHandlerManager in project android by JetBrains.
the class DragDropInteraction method moveTo.
private void moveTo(@SwingCoordinate int x, @SwingCoordinate int y, @InputEventMask final int modifiers, boolean commit) {
myScreenView = myDesignSurface.getScreenView(x, y);
if (myScreenView == null) {
return;
}
myDesignSurface.getLayeredPane().scrollRectToVisible(new Rectangle(x - NlConstants.DEFAULT_SCREEN_OFFSET_X, y - NlConstants.DEFAULT_SCREEN_OFFSET_Y, 2 * NlConstants.DEFAULT_SCREEN_OFFSET_X, 2 * NlConstants.DEFAULT_SCREEN_OFFSET_Y));
final int ax = Coordinates.getAndroidX(myScreenView, x);
final int ay = Coordinates.getAndroidY(myScreenView, y);
Project project = myScreenView.getModel().getProject();
ViewGroupHandler handler = findViewGroupHandlerAt(ax, ay);
if (handler != myCurrentHandler) {
if (myDragHandler != null) {
myDragHandler.cancel();
myDragHandler = null;
myScreenView.getSurface().repaint();
}
myCurrentHandler = handler;
if (myCurrentHandler != null) {
assert myDragReceiver != null;
String error = null;
ViewHandlerManager viewHandlerManager = ViewHandlerManager.get(project);
for (NlComponent component : myDraggedComponents) {
if (!myCurrentHandler.acceptsChild(myDragReceiver, component, ax, ay)) {
error = String.format("<%1$s> does not accept <%2$s> as a child", myDragReceiver.getTagName(), component.getTagName());
break;
}
ViewHandler viewHandler = viewHandlerManager.getHandler(component);
if (viewHandler != null && !viewHandler.acceptsParent(myDragReceiver, component)) {
error = String.format("<%1$s> does not accept <%2$s> as a parent", component.getTagName(), myDragReceiver.getTagName());
break;
}
}
if (error == null) {
myDragHandler = myCurrentHandler.createDragHandler(new ViewEditorImpl(myScreenView), myDragReceiver, myDraggedComponents, myType);
if (myDragHandler != null) {
myDragHandler.start(Coordinates.getAndroidX(myScreenView, myStartX), Coordinates.getAndroidY(myScreenView, myStartY), myStartMask);
}
} else {
myCurrentHandler = null;
}
}
}
if (myDragHandler != null && myCurrentHandler != null) {
String error = myDragHandler.update(ax, ay, modifiers);
final List<NlComponent> added = Lists.newArrayList();
if (commit && error == null) {
added.addAll(myDraggedComponents);
final NlModel model = myScreenView.getModel();
XmlFile file = model.getFile();
String label = myType.getDescription();
WriteCommandAction action = new WriteCommandAction(project, label, file) {
@Override
protected void run(@NotNull Result result) throws Throwable {
InsertType insertType = model.determineInsertType(myType, myTransferItem, false);
// TODO: Run this *after* making a copy
myDragHandler.commit(ax, ay, modifiers, insertType);
}
};
action.execute();
model.notifyModified(NlModel.ChangeType.DND_COMMIT);
// Select newly dropped components
model.getSelectionModel().setSelection(added);
}
myScreenView.getSurface().repaint();
}
}
use of com.android.tools.idea.uibuilder.handlers.ViewHandlerManager in project android by JetBrains.
the class BlueprintLayer method paint.
/**
* Base buildDisplayList method. Draw the blueprint background.
* TODO: We might want to simplify the stack of layers and not keep this one.
*
* @param gc The Graphics object to draw into
*/
@Override
public void paint(@NotNull Graphics2D gc) {
myScreenView.getSize(myScreenViewSize);
mySizeRectangle.setBounds(myScreenView.getX(), myScreenView.getY(), myScreenViewSize.width, myScreenViewSize.height);
Rectangle2D.intersect(mySizeRectangle, gc.getClipBounds(), mySizeRectangle);
if (mySizeRectangle.isEmpty()) {
return;
}
// Draw the background
Graphics2D g = (Graphics2D) gc.create();
Shape prevClip = null;
Shape screenShape = myScreenView.getScreenShape();
if (screenShape != null) {
prevClip = g.getClip();
g.clip(screenShape);
}
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(BLUEPRINT_BG_COLOR);
g.fillRect(mySizeRectangle.x, mySizeRectangle.y, mySizeRectangle.width, mySizeRectangle.height);
if (prevClip != null) {
g.setClip(prevClip);
}
// Draw the components
NlModel model = myScreenView.getModel();
if (model.getComponents().size() == 0) {
return;
}
NlComponent component = model.getComponents().get(0);
component = component.getRoot();
ViewHandlerManager viewHandlerManager = ViewHandlerManager.get(model.getFacet());
// Draw the components
if (drawComponent(g, component, viewHandlerManager, false)) {
Dimension size = myScreenView.getSize();
DesignSurface surface = myScreenView.getSurface();
if (size.width != 0 && size.height != 0) {
surface.repaint(myScreenView.getX(), myScreenView.getY(), size.width, size.height);
} else {
surface.repaint();
}
}
g.dispose();
}
use of com.android.tools.idea.uibuilder.handlers.ViewHandlerManager in project android by JetBrains.
the class PaletteTestCase method checkComponent.
private void checkComponent(@NotNull NlComponent component, @NotNull String expectedTitle, @NotNull Icon expectedIcon) {
ViewHandlerManager handlerManager = ViewHandlerManager.get(getProject());
ViewHandler handler = handlerManager.getHandlerOrDefault(component);
String title = handler.getTitle(component);
String attrs = handler.getTitleAttributes(component);
if (!StringUtil.isEmpty(attrs)) {
title += " " + attrs;
}
assertEquals(component.getTagName() + ".Component.Title", expectedTitle, title);
assertEquals(component.getTagName() + ".Component.Icon", expectedIcon, handler.getIcon(component));
}
use of com.android.tools.idea.uibuilder.handlers.ViewHandlerManager in project android by JetBrains.
the class NlModel method handleDeletion.
private void handleDeletion(@NotNull Collection<NlComponent> components) {
// Segment the deleted components into lists of siblings
Map<NlComponent, List<NlComponent>> siblingLists = groupSiblings(components);
ViewHandlerManager viewHandlerManager = ViewHandlerManager.get(myFacet);
// Notify parent components about children getting deleted
for (Map.Entry<NlComponent, List<NlComponent>> entry : siblingLists.entrySet()) {
NlComponent parent = entry.getKey();
if (parent == null) {
continue;
}
List<NlComponent> children = entry.getValue();
boolean finished = false;
ViewHandler handler = viewHandlerManager.getHandler(parent);
if (handler instanceof ViewGroupHandler) {
finished = ((ViewGroupHandler) handler).deleteChildren(parent, children);
}
if (!finished) {
for (NlComponent component : children) {
NlComponent p = component.getParent();
if (p != null) {
p.removeChild(component);
}
component.getTag().delete();
}
}
}
}
use of com.android.tools.idea.uibuilder.handlers.ViewHandlerManager in project android by JetBrains.
the class StyleFilter method getWidgetStyleNames.
@NotNull
private static List<String> getWidgetStyleNames(@NotNull Project project, @NotNull ResourceResolver resolver, @NotNull String tagName) {
ViewHandlerManager manager = ViewHandlerManager.get(project);
ViewHandler handler = manager.getHandler(tagName);
if (handler == null) {
return Collections.emptyList();
}
List<String> possibleNames = handler.getBaseStyles(tagName);
ResourceValueMap frameworkStyles = resolver.getFrameworkResources().get(ResourceType.STYLE);
ResourceValueMap projectStyles = resolver.getProjectResources().get(ResourceType.STYLE);
// This is usually a small list
List<String> names = new ArrayList<>(4);
for (String styleName : possibleNames) {
if (frameworkStyles.containsKey(styleName)) {
names.add(SdkConstants.PREFIX_ANDROID + styleName);
}
if (projectStyles.containsKey(styleName)) {
names.add(styleName);
}
}
return names;
}
Aggregations