Search in sources :

Example 1 with SelectedProperty

use of com.android.tools.idea.ui.properties.swing.SelectedProperty in project android by JetBrains.

the class AnyCheckedDemo method init.

public void init() {
    StringProperty yesNoText = new TextProperty(myYesNoLabel);
    myBindings.bind(yesNoText, new YesNoExpression(any(new SelectedProperty(myCheckBox1), new SelectedProperty(myCheckBox2), new SelectedProperty(myCheckBox3), new SelectedProperty(myCheckBox4))));
}
Also used : StringProperty(com.android.tools.idea.ui.properties.core.StringProperty) TextProperty(com.android.tools.idea.ui.properties.swing.TextProperty) SelectedProperty(com.android.tools.idea.ui.properties.swing.SelectedProperty)

Example 2 with SelectedProperty

use of com.android.tools.idea.ui.properties.swing.SelectedProperty in project android by JetBrains.

the class SyncFieldsDemo method init.

public void init() {
    // Wrap UI elements in properties
    final StringProperty projectText = new TextProperty(myProjectNameField);
    final StringProperty activityText = new TextProperty(myActivityNameField);
    final BoolProperty isSynced = new SelectedProperty(mySyncActivityNameCheckBox);
    final BoolProperty createActivity = new SelectedProperty(myCreateActivityCheckBox);
    BoolProperty isActivityEnabled = new EnabledProperty(myActivityNameField);
    BoolProperty isLinkEnabled = new EnabledProperty(mySyncActivityNameCheckBox);
    projectText.set("MyProject");
    // Bind activityText <- nameExpression(projectText), but only if conditions are met
    final FormatExpression activityNameExpression = new FormatExpression("%1$sActivity", projectText);
    myBindings.bind(activityText, activityNameExpression, isSynced.and(createActivity));
    myBindings.bind(isActivityEnabled, createActivity);
    myBindings.bind(isLinkEnabled, createActivity);
    // Listen to activityText - if it is changed by the user and not its binding, break syncing!
    activityText.addListener(new InvalidationListener() {

        @Override
        public void onInvalidated(@NotNull ObservableValue<?> sender) {
            isSynced.set(activityText.get().equals(activityNameExpression.get()));
        }
    });
}
Also used : StringProperty(com.android.tools.idea.ui.properties.core.StringProperty) EnabledProperty(com.android.tools.idea.ui.properties.swing.EnabledProperty) InvalidationListener(com.android.tools.idea.ui.properties.InvalidationListener) BoolProperty(com.android.tools.idea.ui.properties.core.BoolProperty) TextProperty(com.android.tools.idea.ui.properties.swing.TextProperty) FormatExpression(com.android.tools.idea.ui.properties.expressions.string.FormatExpression) SelectedProperty(com.android.tools.idea.ui.properties.swing.SelectedProperty)

Example 3 with SelectedProperty

use of com.android.tools.idea.ui.properties.swing.SelectedProperty in project android by JetBrains.

the class NewVectorAssetStep method onWizardStarting.

@Override
protected void onWizardStarting(@NotNull ModelWizard.Facade wizard) {
    final Runnable onAssetModified = myPreviewUpdater::enqueueUpdate;
    loadAssetPath();
    SelectedProperty iconSelected = new SelectedProperty(myMaterialIconRadioButton);
    myListeners.receiveAndFire(iconSelected, isIconActive -> {
        myIconPickerPanel.setVisible(isIconActive);
        myBrowserPanel.setVisible(!isIconActive);
        myActiveAsset.set(isIconActive ? myIconButton.getAsset() : myBrowser.getAsset());
    });
    ActionListener assetListener = actionEvent -> {
        onAssetModified.run();
        saveAssetPath();
    };
    myIconButton.addAssetListener(assetListener);
    myBrowser.addAssetListener(assetListener);
    Disposer.register(this, myIconButton);
    Disposer.register(this, myBrowser);
    final BoolProperty overrideSize = new SelectedProperty(myOverrideSizeCheckBox);
    final IntProperty width = new IntValueProperty();
    final IntProperty height = new IntValueProperty();
    myGeneralBindings.bindTwoWay(new StringToIntAdapterProperty(new TextProperty(myWidthTextField)), width);
    myGeneralBindings.bindTwoWay(new StringToIntAdapterProperty(new TextProperty(myHeightTextField)), height);
    myGeneralBindings.bind(new EnabledProperty(myWidthTextField), overrideSize);
    myGeneralBindings.bind(new EnabledProperty(myHeightTextField), overrideSize);
    myListeners.listenAll(overrideSize, myOriginalSize).withAndFire(() -> {
        if (!overrideSize.get() || !myOriginalSize.get().isPresent()) {
            width.set(DEFAULT_MATERIAL_ICON_SIZE);
            height.set(DEFAULT_MATERIAL_ICON_SIZE);
        } else {
            width.set(myOriginalSize.getValue().width);
            height.set(myOriginalSize.getValue().height);
        }
    });
    final IntProperty opacityValue = new SliderValueProperty(myOpacitySlider);
    myGeneralBindings.bind(new TextProperty(myOpacityValueLabel), new FormatExpression("%d %%", opacityValue));
    final BoolProperty autoMirrored = new SelectedProperty(myEnableAutoMirroredCheckBox);
    myListeners.listenAll(myActiveAsset, overrideSize, width, height, opacityValue, autoMirrored).with(onAssetModified);
    final StringProperty name = new TextProperty(myOutputNameField);
    myListeners.listenAndFire(myActiveAsset, sender -> {
        myActiveAssetBindings.releaseAll();
        myActiveAssetBindings.bind(name, new Expression<String>(myActiveAsset.get().path()) {

            @NotNull
            @Override
            public String get() {
                File path = myActiveAsset.get().path().get();
                if (path.exists() && !path.isDirectory()) {
                    String name1 = FileUtil.getNameWithoutExtension(path).toLowerCase(Locale.getDefault());
                    if (!name1.startsWith(ICON_PREFIX)) {
                        name1 = ICON_PREFIX + AndroidResourceUtil.getValidResourceFileName(name1);
                    }
                    return AndroidResourceUtil.getValidResourceFileName(name1);
                } else {
                    return "ic_vector_name";
                }
            }
        });
        myActiveAssetBindings.bind(myActiveAsset.get().opacity(), opacityValue);
        myActiveAssetBindings.bind(myActiveAsset.get().autoMirrored(), autoMirrored);
        myActiveAssetBindings.bind(myActiveAsset.get().outputWidth(), width);
        myActiveAssetBindings.bind(myActiveAsset.get().outputHeight(), height);
    });
    // Refresh the asset preview, but fire using invokeLater, as this lets the UI lay itself out,
    // which should happen before the "generate preview" logic runs.
    ApplicationManager.getApplication().invokeLater(onAssetModified, ModalityState.any());
    // Cast VectorAsset -> BaseAsset
    myGeneralBindings.bind(myIconGenerator.sourceAsset(), new AsOptionalExpression<>(myActiveAsset));
    myGeneralBindings.bind(myIconGenerator.name(), name);
}
Also used : com.android.tools.idea.ui.properties.core(com.android.tools.idea.ui.properties.core) ActionListener(java.awt.event.ActionListener) AndroidSourceSet(com.android.tools.idea.npw.project.AndroidSourceSet) ModalityState(com.intellij.openapi.application.ModalityState) ModelWizard(com.android.tools.idea.wizard.model.ModelWizard) VectorImageComponent(com.android.tools.idea.ui.VectorImageComponent) VectorIconButton(com.android.tools.idea.npw.assetstudio.ui.VectorIconButton) JBLabel(com.intellij.ui.components.JBLabel) FormatExpression(com.android.tools.idea.ui.properties.expressions.string.FormatExpression) AndroidVectorIconGenerator(com.android.tools.idea.npw.assetstudio.icon.AndroidVectorIconGenerator) TextProperty(com.android.tools.idea.ui.properties.swing.TextProperty) VectorAssetBrowser(com.android.tools.idea.npw.assetstudio.ui.VectorAssetBrowser) Locale(java.util.Locale) Disposer(com.intellij.openapi.util.Disposer) AndroidResourceUtil(org.jetbrains.android.util.AndroidResourceUtil) BindingsManager(com.android.tools.idea.ui.properties.BindingsManager) Project(com.intellij.openapi.project.Project) StringToIntAdapterProperty(com.android.tools.idea.ui.properties.adapters.StringToIntAdapterProperty) SliderValueProperty(com.android.tools.idea.ui.properties.swing.SliderValueProperty) FileUtil(com.intellij.openapi.util.io.FileUtil) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) Collection(java.util.Collection) AsOptionalExpression(com.android.tools.idea.ui.properties.expressions.optional.AsOptionalExpression) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) ModelWizardStep(com.android.tools.idea.wizard.model.ModelWizardStep) SelectedProperty(com.android.tools.idea.ui.properties.swing.SelectedProperty) File(java.io.File) JBScrollPane(com.intellij.ui.components.JBScrollPane) EnabledProperty(com.android.tools.idea.ui.properties.swing.EnabledProperty) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) VectorAsset(com.android.tools.idea.npw.assetstudio.assets.VectorAsset) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) Expression(com.android.tools.idea.ui.properties.expressions.Expression) Collections(java.util.Collections) ListenerManager(com.android.tools.idea.ui.properties.ListenerManager) javax.swing(javax.swing) StringToIntAdapterProperty(com.android.tools.idea.ui.properties.adapters.StringToIntAdapterProperty) SliderValueProperty(com.android.tools.idea.ui.properties.swing.SliderValueProperty) NotNull(org.jetbrains.annotations.NotNull) ActionListener(java.awt.event.ActionListener) EnabledProperty(com.android.tools.idea.ui.properties.swing.EnabledProperty) File(java.io.File) TextProperty(com.android.tools.idea.ui.properties.swing.TextProperty) FormatExpression(com.android.tools.idea.ui.properties.expressions.string.FormatExpression) SelectedProperty(com.android.tools.idea.ui.properties.swing.SelectedProperty)

Example 4 with SelectedProperty

use of com.android.tools.idea.ui.properties.swing.SelectedProperty in project android by JetBrains.

the class ConfigureDeviceOptionsStep method attachBindingsAndValidators.

private void attachBindingsAndValidators() {
    final AvdDeviceData deviceModel = getModel().getDeviceData();
    myBindings.bindTwoWay(new TextProperty(myDeviceName), deviceModel.name());
    myBindings.bind(deviceModel.diagonalScreenSize(), myDiagScreenSizeAdapter);
    myBindings.bind(deviceModel.screenResolutionWidth(), myScreenResWidthAdapter);
    myBindings.bind(deviceModel.screenResolutionHeight(), myScreenResHeightAdapter);
    myBindings.bindTwoWay(myRamField.storage(), deviceModel.ramStorage());
    myBindings.bindTwoWay(new SelectedProperty(myHasHardwareButtons), deviceModel.hasHardwareButtons());
    myBindings.bindTwoWay(new SelectedProperty(myHasHardwareKeyboard), deviceModel.hasHardwareKeyboard());
    myBindings.bindTwoWay(new SelectedItemProperty<>(myNavigationControlsCombo), deviceModel.navigation());
    myBindings.bindTwoWay(new SelectedProperty(myIsScreenRound), deviceModel.isScreenRound());
    myBindings.bindTwoWay(new SelectedProperty(mySupportsLandscape), deviceModel.supportsLandscape());
    myBindings.bindTwoWay(new SelectedProperty(mySupportsPortrait), deviceModel.supportsPortrait());
    myBindings.bindTwoWay(new SelectedProperty(myHasBackFacingCamera), deviceModel.hasBackCamera());
    myBindings.bindTwoWay(new SelectedProperty(myHasFrontFacingCamera), deviceModel.hasFrontCamera());
    myBindings.bindTwoWay(new SelectedProperty(myHasAccelerometer), deviceModel.hasAccelerometer());
    myBindings.bindTwoWay(new SelectedProperty(myHasGyroscope), deviceModel.hasGyroscope());
    myBindings.bindTwoWay(new SelectedProperty(myHasGps), deviceModel.hasGps());
    myBindings.bindTwoWay(new SelectedProperty(myHasProximitySensor), deviceModel.hasProximitySensor());
    myBindings.bindTwoWay(new SelectedItemProperty<>(myCustomSkinPath.getComboBox()), deviceModel.customSkinFile());
    SelectedItemProperty<IdDisplay> selectedDeviceType = new SelectedItemProperty<>(myDeviceTypeComboBox);
    myBindings.bindTwoWay(selectedDeviceType, deviceModel.deviceType());
    myListeners.receive(selectedDeviceType, idDisplayOptional -> {
        if (idDisplayOptional.isPresent()) {
            IdDisplay selectedType = idDisplayOptional.get();
            getModel().getDeviceData().isWear().set(selectedType.equals(SystemImage.WEAR_TAG));
            getModel().getDeviceData().isTv().set(selectedType.equals(SystemImage.TV_TAG));
            myIsScreenRound.setEnabled(selectedType.equals(SystemImage.WEAR_TAG));
            myIsScreenRound.setSelected(getModel().getDeviceData().isScreenRound().get());
        }
    });
    myValidatorPanel.registerValidator(deviceModel.name().isEmpty().not(), "Please write a name for the new device.");
    myValidatorPanel.registerValidator(myDiagScreenSizeAdapter.inSync().and(deviceModel.diagonalScreenSize().isEqualTo(myDiagScreenSizeAdapter)), "Please enter a non-zero positive floating point value for the screen size.");
    myValidatorPanel.registerValidator(myScreenResWidthAdapter.inSync().and(deviceModel.screenResolutionWidth().isEqualTo(myScreenResWidthAdapter)), "Please enter a valid value for the screen width.");
    myValidatorPanel.registerValidator(myScreenResHeightAdapter.inSync().and(deviceModel.screenResolutionHeight().isEqualTo(myScreenResHeightAdapter)), "Please enter a valid value for the screen height.");
    myValidatorPanel.registerValidator(deviceModel.ramStorage(), value -> (value.getSize() > 0) ? Result.OK : new Result(Validator.Severity.ERROR, "Please specify a non-zero amount of RAM."));
    myValidatorPanel.registerValidator(deviceModel.screenDpi().isGreaterThan(0), "The given resolution and screen size specified have a DPI that is too low.");
    myValidatorPanel.registerValidator(deviceModel.supportsLandscape().or(deviceModel.supportsPortrait()), "A device must support at least one orientation (Portrait or Landscape).");
    myValidatorPanel.registerValidator(deviceModel.customSkinFile(), value -> {
        File skinPath = value.orElse(null);
        if (skinPath != null && !FileUtil.filesEqual(skinPath, AvdWizardUtils.NO_SKIN) && !skinPath.getPath().equals(skinPath.getName())) {
            File layoutFile = new File(skinPath, SdkConstants.FN_SKIN_LAYOUT);
            if (!layoutFile.isFile()) {
                return new Result(Validator.Severity.ERROR, "The skin directory does not point to a valid skin.");
            }
        }
        return Result.OK;
    });
    myValidatorPanel.registerValidator(getModel().getDeviceData().compatibleSkinSize(), Validator.Severity.WARNING, "The selected skin is not large enough to view the entire screen.");
}
Also used : SelectedItemProperty(com.android.tools.idea.ui.properties.swing.SelectedItemProperty) IdDisplay(com.android.sdklib.repository.IdDisplay) File(java.io.File) TextProperty(com.android.tools.idea.ui.properties.swing.TextProperty) SelectedProperty(com.android.tools.idea.ui.properties.swing.SelectedProperty) Result(com.android.tools.idea.ui.validation.Validator.Result)

Example 5 with SelectedProperty

use of com.android.tools.idea.ui.properties.swing.SelectedProperty in project android by JetBrains.

the class ConfigureAvdOptionsStep method bindComponents.

private void bindComponents() {
    myBindings.bindTwoWay(new TextProperty(myAvdDisplayName), getModel().avdDisplayName());
    myBindings.bind(new TextProperty(myAvdId), new StringExpression(getModel().avdDisplayName()) {

        @NotNull
        @Override
        public String get() {
            String displayName = getModel().avdDisplayName().get();
            getModel().avdId().set(StringUtil.isNotEmpty(displayName) ? AvdWizardUtils.cleanAvdName(connection, displayName, !displayName.equals(myOriginalName)) : "");
            return getModel().avdId().get();
        }
    });
    myBindings.bindTwoWay(new TextProperty(mySystemImageName), getModel().systemImageName());
    myBindings.bindTwoWay(new TextProperty(mySystemImageDetails), getModel().systemImageDetails());
    myBindings.bindTwoWay(new SelectedProperty(myQemu2CheckBox), getModel().useQemu2());
    myBindings.bindTwoWay(new SelectedItemProperty<Integer>(myCoreCount), getModel().cpuCoreCount());
    myBindings.bindTwoWay(myRamStorage.storage(), getModel().getAvdDeviceData().ramStorage());
    myBindings.bindTwoWay(myVmHeapStorage.storage(), getModel().vmHeapStorage());
    myBindings.bindTwoWay(myInternalStorage.storage(), getModel().internalStorage());
    myBindings.bindTwoWay(myBuiltInSdCardStorage.storage(), new OptionalToValuePropertyAdapter<Storage>(getModel().sdCardStorage()));
    myBindings.bindTwoWay(new SelectedItemProperty<GpuMode>(myHostGraphics), getModel().hostGpuMode());
    myBindings.bindTwoWay(new SelectedProperty(myDeviceFrameCheckbox), getModel().hasDeviceFrame());
    myBindings.bindTwoWay(new SelectedItemProperty<File>(mySkinComboBox.getComboBox()), getModel().getAvdDeviceData().customSkinFile());
    myOrientationToggle.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            ScreenOrientation orientation = myOrientationToggle.getSelectedElement();
            if (orientation == null) {
                getModel().selectedAvdOrientation().set(ScreenOrientation.PORTRAIT);
            } else {
                getModel().selectedAvdOrientation().set(orientation);
            }
        }
    });
    FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, false) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return super.isFileVisible(file, true);
        }
    };
    fileChooserDescriptor.setHideIgnored(false);
    myExternalSdCard.addBrowseFolderListener("Select SD Card", "Select an existing SD card image", myProject, fileChooserDescriptor);
    myBindings.bindTwoWay(new TextProperty(myExternalSdCard.getTextField()), getModel().externalSdCardLocation());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdCamera>(new SelectedItemProperty<AvdCamera>(myFrontCameraCombo)), getModel().selectedFrontCamera());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdCamera>(new SelectedItemProperty<AvdCamera>(myBackCameraCombo)), getModel().selectedBackCamera());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdNetworkSpeed>(new SelectedItemProperty<AvdNetworkSpeed>(mySpeedCombo)), getModel().selectedNetworkSpeed());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdNetworkLatency>(new SelectedItemProperty<AvdNetworkLatency>(myLatencyCombo)), getModel().selectedNetworkLatency());
    myBindings.bindTwoWay(new SelectedProperty(myEnableComputerKeyboard), getModel().enableHardwareKeyboard());
    myBindings.bindTwoWay(new SelectedProperty(myExternalRadioButton), getModel().useExternalSdCard());
    myBindings.bindTwoWay(new SelectedProperty(myBuiltInRadioButton), getModel().useBuiltInSdCard());
    myCheckSdForChanges = true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GpuMode(com.android.sdklib.internal.avd.GpuMode) ListSelectionEvent(javax.swing.event.ListSelectionEvent) NotNull(org.jetbrains.annotations.NotNull) TextProperty(com.android.tools.idea.ui.properties.swing.TextProperty) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ListSelectionListener(javax.swing.event.ListSelectionListener) ScreenOrientation(com.android.resources.ScreenOrientation) SelectedItemProperty(com.android.tools.idea.ui.properties.swing.SelectedItemProperty) StringExpression(com.android.tools.idea.ui.properties.expressions.string.StringExpression) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) SelectedProperty(com.android.tools.idea.ui.properties.swing.SelectedProperty)

Aggregations

SelectedProperty (com.android.tools.idea.ui.properties.swing.SelectedProperty)7 TextProperty (com.android.tools.idea.ui.properties.swing.TextProperty)5 File (java.io.File)3 InvalidationListener (com.android.tools.idea.ui.properties.InvalidationListener)2 StringProperty (com.android.tools.idea.ui.properties.core.StringProperty)2 FormatExpression (com.android.tools.idea.ui.properties.expressions.string.FormatExpression)2 EnabledProperty (com.android.tools.idea.ui.properties.swing.EnabledProperty)2 SelectedItemProperty (com.android.tools.idea.ui.properties.swing.SelectedItemProperty)2 NotNull (org.jetbrains.annotations.NotNull)2 ScreenOrientation (com.android.resources.ScreenOrientation)1 GpuMode (com.android.sdklib.internal.avd.GpuMode)1 IdDisplay (com.android.sdklib.repository.IdDisplay)1 VectorAsset (com.android.tools.idea.npw.assetstudio.assets.VectorAsset)1 AndroidVectorIconGenerator (com.android.tools.idea.npw.assetstudio.icon.AndroidVectorIconGenerator)1 VectorAssetBrowser (com.android.tools.idea.npw.assetstudio.ui.VectorAssetBrowser)1 VectorIconButton (com.android.tools.idea.npw.assetstudio.ui.VectorIconButton)1 AndroidSourceSet (com.android.tools.idea.npw.project.AndroidSourceSet)1 VectorImageComponent (com.android.tools.idea.ui.VectorImageComponent)1 BindingsManager (com.android.tools.idea.ui.properties.BindingsManager)1 ListenerManager (com.android.tools.idea.ui.properties.ListenerManager)1