Search in sources :

Example 61 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent 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();
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 62 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class WidgetConstraintPanel method setVerticalBias.

public void setVerticalBias() {
    float bias = 1f - (mVerticalSlider.getValue() / 100f);
    NlComponent component = mComponent;
    if (NlComponentUtils.isVerticalChain(mComponent)) {
        component = NlComponentUtils.getTopMostInChain(mComponent);
    }
    setSherpaAttribute(SdkConstants.ATTR_LAYOUT_VERTICAL_BIAS, Float.toString(bias));
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 63 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class WidgetConstraintPanel method configureUI.

/**
   * This loads the parameters form component the ConstraintWidget
   */
private void configureUI() {
    if (mComponent == null) {
        return;
    }
    mConfiguringUI = true;
    final String sherpaNamespace = SdkConstants.SHERPA_URI;
    int top = getMargin(CONNECTION_TOP);
    int left = getMargin(CONNECTION_LEFT);
    int right = getMargin(CONNECTION_RIGHT);
    int bottom = getMargin(CONNECTION_BOTTOM);
    String ratioString = mComponent.getLiveAttribute(sherpaNamespace, SdkConstants.ATTR_LAYOUT_DIMENSION_RATIO);
    String horizontalBias = mComponent.getLiveAttribute(sherpaNamespace, SdkConstants.ATTR_LAYOUT_HORIZONTAL_BIAS);
    String verticalBias = mComponent.getLiveAttribute(sherpaNamespace, SdkConstants.ATTR_LAYOUT_VERTICAL_BIAS);
    boolean baseline = hasBaseline();
    boolean showVerticalSlider = bottom != UNCONNECTED && top != UNCONNECTED;
    boolean showHorizontalSlider = left != UNCONNECTED && right != UNCONNECTED;
    if (showHorizontalSlider) {
        if (NlComponentUtils.isHorizontalChain(mComponent)) {
            NlComponent ctl = NlComponentUtils.getLeftMostInChain(mComponent);
            horizontalBias = ctl.getLiveAttribute(sherpaNamespace, SdkConstants.ATTR_LAYOUT_HORIZONTAL_BIAS);
        }
        float bias = parseFloat(horizontalBias, 0.5f);
        mHorizontalSlider.setValue((int) (bias * 100));
    }
    if (showVerticalSlider) {
        if (NlComponentUtils.isVerticalChain(mComponent)) {
            NlComponent ctl = NlComponentUtils.getTopMostInChain(mComponent);
            verticalBias = ctl.getLiveAttribute(sherpaNamespace, SdkConstants.ATTR_LAYOUT_VERTICAL_BIAS);
        }
        float bias = parseFloat(verticalBias, 0.5f);
        mVerticalSlider.setValue(100 - (int) (bias * 100));
    }
    mVerticalSlider.setEnabled(showVerticalSlider);
    mHorizontalSlider.setEnabled(showHorizontalSlider);
    mHorizontalSlider.invalidate();
    mVerticalSlider.invalidate();
    mVerticalSlider.setToolTipText(showVerticalSlider ? VERTICAL_TOOL_TIP_TEXT : null);
    mHorizontalSlider.setToolTipText(showHorizontalSlider ? HORIZONTAL_TOOL_TIP_TEXT : null);
    int widthValue = convertFromNL(SdkConstants.ATTR_LAYOUT_WIDTH);
    int heightValue = convertFromNL(SdkConstants.ATTR_LAYOUT_HEIGHT);
    mMain.configureUi(bottom, top, left, right, baseline, widthValue, heightValue, ratioString);
    mConfiguringUI = false;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 64 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class WidgetConstraintPanel method setHorizontalBias.

public void setHorizontalBias() {
    float bias = (mHorizontalSlider.getValue() / 100f);
    NlComponent component = mComponent;
    if (NlComponentUtils.isHorizontalChain(mComponent)) {
        component = NlComponentUtils.getLeftMostInChain(mComponent);
    }
    setSherpaAttribute(SdkConstants.ATTR_LAYOUT_HORIZONTAL_BIAS, Float.toString(bias));
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 65 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class GridInfo method getSize.

@AndroidCoordinate
private Dimension getSize() {
    Dimension size = new Dimension();
    if (layout.children != null) {
        Insets padding = layout.getPadding();
        for (NlComponent child : layout.children) {
            size.width = Math.max(child.x - layout.x - padding.left + child.w, size.width);
            size.height = Math.max(child.y - layout.y - padding.top + child.h, size.height);
        }
    }
    return size;
}
Also used : Insets(com.android.tools.idea.uibuilder.model.Insets) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) AndroidCoordinate(com.android.tools.idea.uibuilder.model.AndroidCoordinate)

Aggregations

NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)184 NlModel (com.android.tools.idea.uibuilder.model.NlModel)34 NotNull (org.jetbrains.annotations.NotNull)34 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)18 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)17 Nullable (org.jetbrains.annotations.Nullable)14 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)11 ViewGroupHandler (com.android.tools.idea.uibuilder.api.ViewGroupHandler)9 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)9 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)8 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)7 XmlFile (com.intellij.psi.xml.XmlFile)7 XmlTag (com.intellij.psi.xml.XmlTag)7 ArrayList (java.util.ArrayList)7 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)6 NlGraphics (com.android.tools.idea.uibuilder.graphics.NlGraphics)6 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)6 Project (com.intellij.openapi.project.Project)6 List (java.util.List)6