use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class NlTreeDumper method describe.
private void describe(@NotNull StringBuilder sb, @NotNull NlComponent component, int depth) {
for (int i = 0; i < depth; i++) {
sb.append(" ");
}
sb.append(describe(component));
sb.append('\n');
for (NlComponent child : component.getChildren()) {
describe(sb, child, depth + 1);
}
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class ModelBuilder method updateModel.
/** Update the given model to reflect the component hierarchy in the given builder */
public void updateModel(NlModel model, boolean preserveXmlTags) {
assertThat(model).isNotNull();
// temporary workaround: replacing contents not working
name("linear2.xml");
NlModel newModel = preserveXmlTags ? model : build();
model.updateHierarchy(newModel.getFile().getRootTag(), buildViewInfos(newModel));
for (NlComponent component : newModel.getComponents()) {
checkStructure(component);
}
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class MarqueeInteraction method update.
@Override
public void update(@SwingCoordinate int x, @SwingCoordinate int y, @InputEventMask int modifiers) {
if (myOverlay == null) {
return;
}
int xp = Math.min(x, myStartX);
int yp = Math.min(y, myStartY);
int w = Math.abs(x - myStartX);
int h = Math.abs(y - myStartY);
myOverlay.updateSize(xp, yp, w, h);
// Convert to Android coordinates and compute selection overlaps
int ax = Coordinates.getAndroidX(myScreenView, xp);
int ay = Coordinates.getAndroidY(myScreenView, yp);
int aw = Coordinates.getAndroidDimension(myScreenView, w);
int ah = Coordinates.getAndroidDimension(myScreenView, h);
Collection<NlComponent> within = myScreenView.getModel().findWithin(ax, ay, aw, ah);
List<NlComponent> selection = Lists.newArrayList();
if (!myInitialSelection.isEmpty()) {
// Copy; we're not allowed to touch the passed in collection
Set<NlComponent> result = new HashSet<NlComponent>(myInitialSelection);
for (NlComponent component : selection) {
if (myInitialSelection.contains(component)) {
result.remove(component);
} else {
result.add(component);
}
}
within = result;
}
myScreenView.getSelectionModel().setSelection(within);
myScreenView.getSurface().repaint();
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class GuidelinePainter method paint.
public static void paint(@NotNull NlGraphics g, GuidelineHandler myState) {
g.useStyle(DRAGGED);
for (NlComponent dragged : myState.myDraggedNodes) {
if (dragged.w > 0 && dragged.h > 0) {
g.fillRect(dragged.x, dragged.y, dragged.w, dragged.h);
}
}
Set<NlComponent> horizontalDeps = myState.myHorizontalDeps;
Set<NlComponent> verticalDeps = myState.myVerticalDeps;
Set<NlComponent> deps = new HashSet<NlComponent>(horizontalDeps.size() + verticalDeps.size());
deps.addAll(horizontalDeps);
deps.addAll(verticalDeps);
if (deps.size() > 0) {
g.useStyle(DEPENDENCY);
for (NlComponent n : deps) {
// Don't highlight the selected nodes themselves
if (myState.myDraggedNodes.contains(n)) {
continue;
}
g.fillRect(n.x, n.y, n.w, n.h);
}
}
// If the layout has padding applied, draw the padding bounds to make it obvious what the boundaries are
if (!myState.layout.getPadding().isEmpty() || !myState.layout.getMargins().isEmpty()) {
g.useStyle(NlDrawingStyle.PADDING_BOUNDS);
NlComponent layout = myState.layout;
Insets padding = layout.getPadding();
g.drawRect(layout.x + padding.left, layout.y + padding.top, Math.max(0, layout.w - padding.left - padding.right), Math.max(0, layout.h - padding.top - padding.bottom));
}
if (myState.myBounds != null) {
Rectangle bounds = myState.myBounds;
if (myState instanceof RelativeDragHandler) {
g.useStyle(DROP_PREVIEW);
} else {
// Resizing
if (myState.haveSuggestions()) {
g.useStyle(RESIZE_PREVIEW);
} else {
g.useStyle(RESIZE_FAIL);
}
}
g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height);
// Draw baseline preview too
// TODO: Implement when we have drag information from palette drag previews
//if (myFeedback.dragBaseline != -1) {
// int y = myState.myBounds.y + myFeedback.dragBaseline;
// g.drawLine(myState.myBounds.x, y, myState.myBounds.x + myState.myBounds.width, y);
//}
}
showMatch(g, myState.getCurrentLeftMatch(), myState);
showMatch(g, myState.getCurrentRightMatch(), myState);
showMatch(g, myState.getCurrentTopMatch(), myState);
showMatch(g, myState.getCurrentBottomMatch(), myState);
if (myState.myHorizontalCycle != null) {
paintCycle(myState, g, myState.myHorizontalCycle);
}
if (myState.myVerticalCycle != null) {
paintCycle(myState, g, myState.myVerticalCycle);
}
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class RelativeLayoutHandler method paintConstraints.
@Override
public boolean paintConstraints(@NotNull ScreenView screenView, @NotNull Graphics2D graphics, @NotNull NlComponent component) {
NlGraphics g = new NlGraphics(graphics, screenView);
Iterable<NlComponent> iterable = component.getChildren();
List<NlComponent> children = Lists.newArrayList(iterable);
ConstraintPainter.paintSelectionFeedback(g, component, children, true, TextDirection.LEFT_TO_RIGHT);
return false;
}
Aggregations