use of com.android.tools.idea.ui.properties.expressions.bool.BooleanExpression in project android by JetBrains.
the class ConfigureIconPanel method initializeListenersAndBindings.
private void initializeListenersAndBindings() {
final BoolProperty trimmed = new SelectedProperty(myTrimmedRadioButton);
final IntProperty paddingPercent = new SliderValueProperty(myPaddingSlider);
final StringProperty paddingValueString = new TextProperty(myPaddingValueLabel);
myGeneralBindings.bind(paddingValueString, new FormatExpression("%d %%", paddingPercent));
myIgnoreForegroundColor = new SelectedProperty(myImageRadioButton);
myForegroundColor = new OptionalToValuePropertyAdapter<>(new ColorProperty(myForegroundColorPanel));
myBackgroundColor = new OptionalToValuePropertyAdapter<>(new ColorProperty(myBackgroundColorPanel));
myCropped = new SelectedProperty(myCropRadioButton);
myDogEared = new SelectedProperty(myDogEarRadioButton);
myTheme = new OptionalToValuePropertyAdapter<>(new SelectedItemProperty<>(myThemeComboBox));
myThemeColor = new OptionalToValuePropertyAdapter<>(new ColorProperty(myCustomThemeColorPanel));
myShape = new OptionalToValuePropertyAdapter<>(new SelectedItemProperty<>(myShapeComboBox));
updateBindingsAndUiForActiveIconType();
ActionListener radioSelectedListener = e -> {
JRadioButton source = ((JRadioButton) e.getSource());
AssetComponent assetComponent = myAssetPanelMap.get(source);
myActiveAsset.set(assetComponent.getAsset());
};
myClipartRadioButton.addActionListener(radioSelectedListener);
myImageRadioButton.addActionListener(radioSelectedListener);
myTextRadioButton.addActionListener(radioSelectedListener);
// If any of our underlying asset panels change, we should pass that on to anyone listening to
// us as well.
ActionListener assetPanelListener = e -> fireAssetListeners();
for (AssetComponent assetComponent : myAssetPanelMap.values()) {
assetComponent.addAssetListener(assetPanelListener);
}
final Runnable onAssetModified = this::fireAssetListeners;
myListeners.listenAll(trimmed, paddingPercent, myForegroundColor, myBackgroundColor, myCropped, myDogEared, myTheme, myThemeColor, myShape).with(onAssetModified);
myListeners.listenAndFire(myActiveAsset, sender -> {
myActiveAssetBindings.releaseAll();
myActiveAssetBindings.bindTwoWay(trimmed, myActiveAsset.get().trimmed());
myActiveAssetBindings.bindTwoWay(paddingPercent, myActiveAsset.get().paddingPercent());
myActiveAssetBindings.bindTwoWay(myForegroundColor, myActiveAsset.get().color());
getIconGenerator().sourceAsset().setValue(myActiveAsset.get());
onAssetModified.run();
});
ObservableBool isLauncherIcon = new BoolValueProperty(myIconType.equals(AndroidIconType.LAUNCHER));
ObservableBool isActionBarIcon = new BoolValueProperty(myIconType.equals(AndroidIconType.ACTIONBAR));
ObservableBool isCustomTheme = myTheme.isEqualTo(ActionBarIconGenerator.Theme.CUSTOM);
ObservableValue<Boolean> isClipartOrText = myActiveAsset.transform(asset -> myClipartAssetButton.getAsset() == asset || myTextAssetEditor.getAsset() == asset);
ObservableBool supportsEffects = new BooleanExpression(myShape) {
@NotNull
@Override
public Boolean get() {
GraphicGenerator.Shape shape = myShape.get();
switch(shape) {
case SQUARE:
case VRECT:
case HRECT:
return true;
default:
return false;
}
}
};
/**
* Hook up a bunch of UI <- boolean expressions, so that when certain conditions are met,
* various components show/hide. This also requires refreshing the panel explicitly, as
* otherwise Swing doesn't realize it should trigger a relayout.
*/
ImmutableMap.Builder<BoolProperty, ObservableBool> layoutPropertiesBuilder = ImmutableMap.builder();
layoutPropertiesBuilder.put(new VisibleProperty(myImageAssetRowPanel), new SelectedProperty(myImageRadioButton));
layoutPropertiesBuilder.put(new VisibleProperty(myClipartAssetRowPanel), new SelectedProperty(myClipartRadioButton));
layoutPropertiesBuilder.put(new VisibleProperty(myTextAssetRowPanel), new SelectedProperty(myTextRadioButton));
layoutPropertiesBuilder.put(new VisibleProperty(myForegroundRowPanel), isLauncherIcon.and(isClipartOrText));
layoutPropertiesBuilder.put(new VisibleProperty(myBackgroundRowPanel), isLauncherIcon);
layoutPropertiesBuilder.put(new VisibleProperty(myScalingRowPanel), isLauncherIcon);
layoutPropertiesBuilder.put(new VisibleProperty(myShapeRowPanel), isLauncherIcon);
layoutPropertiesBuilder.put(new VisibleProperty(myEffectRowPanel), isLauncherIcon);
layoutPropertiesBuilder.put(new EnabledProperty(myDogEarRadioButton), supportsEffects);
layoutPropertiesBuilder.put(new VisibleProperty(myThemeRowPanel), isActionBarIcon);
layoutPropertiesBuilder.put(new VisibleProperty(myCustomThemeRowPanel), isActionBarIcon.and(isCustomTheme));
ImmutableMap<BoolProperty, ObservableBool> layoutProperties = layoutPropertiesBuilder.build();
for (Map.Entry<BoolProperty, ObservableBool> e : layoutProperties.entrySet()) {
// Initialize everything off, as this makes sure the frame that uses this panel won't start
// REALLY LARGE by default.
e.getKey().set(false);
myGeneralBindings.bind(e.getKey(), e.getValue());
}
myListeners.listenAll(layoutProperties.keySet()).with(() -> SwingUtilities.updateComponentTreeUI(myAllOptionsPanel));
}
Aggregations