Search in sources :

Example 1 with LabelWithEditLink

use of com.android.tools.adtui.LabelWithEditLink in project android by JetBrains.

the class TemplateParameterStep2 method createComponents.

@NotNull
private List<JComponent> createComponents(final Parameter parameter) {
    JLabel label = new JLabel(parameter.name + ":");
    final JComponent dataComponent;
    if (AddAndroidActivityPath.PACKAGE_NAME_PARAMETERS.contains(parameter.id)) {
        Module module = getModule();
        if (module != null) {
            dataComponent = createPackageEntry(parameter, module);
        } else {
            dataComponent = new LabelWithEditLink();
        }
    } else if (AddAndroidActivityPath.CLASS_NAME_PARAMETERS.contains(parameter.id)) {
        Module module = getModule();
        if (module != null) {
            dataComponent = createClassEntry(parameter, module);
        } else {
            dataComponent = new JTextField();
        }
    } else {
        switch(parameter.type) {
            case BOOLEAN:
                label = null;
                dataComponent = new JCheckBox(parameter.name);
                break;
            case ENUM:
                dataComponent = createEnumCombo(parameter);
                break;
            case STRING:
                dataComponent = new JTextField();
                break;
            case SEPARATOR:
                return Collections.singletonList(new JSeparator(SwingConstants.HORIZONTAL));
            default:
                throw new IllegalStateException(parameter.type.toString());
        }
    }
    if (!StringUtil.isEmpty(parameter.help) && dataComponent.getAccessibleContext() != null) {
        dataComponent.getAccessibleContext().setAccessibleDescription(parameter.help);
    }
    register(parameter, dataComponent);
    if (label != null) {
        label.setLabelFor(dataComponent);
    }
    return label != null ? Arrays.asList(label, dataComponent) : Arrays.asList(dataComponent);
}
Also used : LabelWithEditLink(com.android.tools.adtui.LabelWithEditLink) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with LabelWithEditLink

use of com.android.tools.adtui.LabelWithEditLink in project android by JetBrains.

the class TemplateParameterStep2 method addComponent.

private static int addComponent(JComponent parent, JComponent component, int row, int column, boolean isLast) {
    GridConstraints gridConstraints = new GridConstraints();
    gridConstraints.setRow(row);
    gridConstraints.setColumn(column);
    boolean isGreedyComponent = component instanceof JTextField || component instanceof Spacer || component instanceof LabelWithEditLink || component instanceof TextAccessor || component instanceof EditorComboBox;
    int columnSpan = (isLast && isGreedyComponent) ? COLUMN_COUNT - column : 1;
    gridConstraints.setColSpan(columnSpan);
    gridConstraints.setAnchor(GridConstraints.ALIGN_LEFT);
    gridConstraints.setHSizePolicy(isGreedyComponent ? GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW : GridConstraints.SIZEPOLICY_CAN_SHRINK);
    gridConstraints.setVSizePolicy(component instanceof Spacer ? GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW : GridConstraints.SIZEPOLICY_FIXED);
    gridConstraints.setFill(GridConstraints.FILL_HORIZONTAL);
    parent.add(component, gridConstraints);
    if (isLast && !isGreedyComponent && column < COLUMN_COUNT - 1) {
        addComponent(parent, new Spacer(), row, column + 1, true);
    }
    return columnSpan;
}
Also used : LabelWithEditLink(com.android.tools.adtui.LabelWithEditLink) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) Spacer(com.intellij.uiDesigner.core.Spacer)

Example 3 with LabelWithEditLink

use of com.android.tools.adtui.LabelWithEditLink in project android by JetBrains.

the class ConfigureAndroidProjectStepFixture method enterPackageName.

@NotNull
public ConfigureAndroidProjectStepFixture enterPackageName(@NotNull String text) {
    LabelWithEditLink link = robot().finder().findByType(target(), LabelWithEditLink.class);
    HyperlinkLabel editLabel = robot().finder().findByType(link, HyperlinkLabel.class);
    robot().click(editLabel);
    JTextComponent textField = findTextFieldWithLabel("Package name:");
    replaceText(textField, text);
    // click "Done"
    robot().click(editLabel);
    return this;
}
Also used : LabelWithEditLink(com.android.tools.adtui.LabelWithEditLink) JTextComponent(javax.swing.text.JTextComponent) HyperlinkLabel(com.intellij.ui.HyperlinkLabel) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with LabelWithEditLink

use of com.android.tools.adtui.LabelWithEditLink in project android by JetBrains.

the class TextPropertyTest method textPropertyCanWrapLabelWithEditLink.

@Test
public void textPropertyCanWrapLabelWithEditLink() {
    LabelWithEditLink editLabel = new LabelWithEditLink();
    TextProperty textProperty = new TextProperty(editLabel);
    CountListener listener = new CountListener();
    textProperty.addListener(listener);
    assertThat(textProperty.get()).isEqualTo("");
    assertThat(listener.getCount()).isEqualTo(0);
    editLabel.setText("Edit label set directly");
    assertThat(textProperty.get()).isEqualTo("Edit label set directly");
    assertThat(listener.getCount()).isEqualTo(1);
    textProperty.set("Edit label updated via property");
    assertThat(editLabel.getText()).isEqualTo("Edit label updated via property");
    assertThat(listener.getCount()).isEqualTo(2);
}
Also used : LabelWithEditLink(com.android.tools.adtui.LabelWithEditLink) CountListener(com.android.tools.idea.ui.properties.CountListener) Test(org.junit.Test)

Aggregations

LabelWithEditLink (com.android.tools.adtui.LabelWithEditLink)4 NotNull (org.jetbrains.annotations.NotNull)2 CountListener (com.android.tools.idea.ui.properties.CountListener)1 Module (com.intellij.openapi.module.Module)1 HyperlinkLabel (com.intellij.ui.HyperlinkLabel)1 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)1 Spacer (com.intellij.uiDesigner.core.Spacer)1 JTextComponent (javax.swing.text.JTextComponent)1 Test (org.junit.Test)1