本文整理匯總了Java中javafx.beans.property.Property.setValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Property.setValue方法的具體用法?Java Property.setValue怎麽用?Java Property.setValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javafx.beans.property.Property
的用法示例。
在下文中一共展示了Property.setValue方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: read
import javafx.beans.property.Property; //導入方法依賴的package包/類
/**
* Reads a value saved in a preferences object and stores it in a JavaFX property. If no value is present in the
* preferences object corresponding to the property's name, or if it is of an incompatible type, the property is
* not modified.
*
* @param property the property that the read value should be placed in
* @param preferences the preferences object to read from
* @param parser the function to use to convert from the serialized String to an object of the proper type
* @param <T> the type of the property
*/
public static <T> void read(Property<? super T> property,
Preferences preferences,
Function<String, ? extends T> parser) {
String name = property.getName();
String saved = preferences.get(name, null);
if (saved != null) {
try {
property.setValue(parser.apply(saved));
} catch (Exception ignore) { // NOPMD empty catch block
// The saved value probably wasn't the expected type
// No need to bubble the exception up
}
}
}
示例2: testBindBidirectionalWithConverter
import javafx.beans.property.Property; //導入方法依賴的package包/類
@Test
public void testBindBidirectionalWithConverter() {
// given
Property<String> str = new SimpleStringProperty("-42");
Property<Number> num = new SimpleDoubleProperty(1.23);
// when
PropertyUtils.bindBidirectionalWithConverter(str, num, Double::parseDouble, Object::toString);
// then (initial conditions)
assertAll(
() -> assertEquals("1.23", str.getValue(), "String was not set correctly"),
() -> assertEquals(1.23, num.getValue().doubleValue(), "Binding target should not have changed")
);
// when changing one value
str.setValue("89");
// then
assertEquals(89, num.getValue().doubleValue(), "Number was not set correctly");
// when changing the other value
num.setValue(10.01);
// then
assertEquals("10.01", str.getValue(), "String was not set correctly");
}
示例3: invalidated
import javafx.beans.property.Property; //導入方法依賴的package包/類
@Override
public void invalidated(Observable observable) {
if (updating) {
return;
}
final Property<L> leftProperty = getLeftProperty();
final Property<R> rightProperty = getRightProperty();
if (wasGarbageCollected()) {
if (leftProperty != null) {
leftProperty.removeListener(this);
}
if (rightProperty != null) {
rightProperty.removeListener(this);
}
} else {
try {
updating = true;
if (observable == leftProperty) {
rightProperty.setValue(converter.toRight(leftProperty.getValue()));
} else {
leftProperty.setValue(converter.toLeft(rightProperty.getValue()));
}
} finally {
updating = false;
}
}
}
示例4: deserialize
import javafx.beans.property.Property; //導入方法依賴的package包/類
@Override
public Widget deserialize(JsonElement json, JsonDeserializationContext context) throws JsonParseException {
JsonObject obj = json.getAsJsonObject();
String type = obj.get("_type").getAsString();
Widget widget = Components.getDefault().createWidget(type)
.orElseThrow(() -> new JsonParseException("No widget found for " + type));
for (int i = 0; i > Integer.MIN_VALUE; i++) {
String prop = "_source" + i;
if (obj.has(prop)) {
String uri = obj.get(prop).getAsString();
Optional<? extends DataSource<?>> existingSource = Sources.getDefault().get(uri);
try {
if (existingSource.isPresent()) {
widget.addSource(existingSource.get());
} else {
// Attempt to create a new source for the saved URI
DataSource<?> dataSource = SourceTypes.getDefault().forUri(uri);
// Check the source type to make sure it's the same as the one expected in the save file
if (dataSource.getType().equals(SourceTypes.getDefault().typeForUri(uri))) {
widget.addSource(dataSource);
} else {
log.warning("Saved source type is not present, adding destroyed source(s) instead");
sourcedRestorer.addDestroyedSourcesForAllDataTypes(widget, uri);
}
}
} catch (IncompatibleSourceException e) {
log.log(Level.WARNING, "Couldn't load source, adding destroyed source(s) instead", e);
sourcedRestorer.addDestroyedSourcesForAllDataTypes(widget, uri);
}
} else {
break;
}
}
JsonElement title = obj.get("_title");
if (title != null) {
widget.setTitle(title.getAsString());
}
for (Property p : widget.getProperties()) {
p.setValue(context.deserialize(obj.get(p.getName()), p.getValue().getClass()));
}
return widget;
}
示例5: bindBidirectional
import javafx.beans.property.Property; //導入方法依賴的package包/類
/**
* Creates a bidirectional binding between the two given properties of different types via the
* help of a {@link Converter}.
*
* @param leftProperty the left property
* @param rightProperty the right property
* @param converter the converter
* @param <L> the type of the left property
* @param <R> the type of the right property
*/
public static <L, R> void bindBidirectional(Property<L> leftProperty, Property<R> rightProperty, Converter<L, R> converter) {
BidirectionalConversionBinding<L, R> binding = new BidirectionalConversionBinding<>(leftProperty, rightProperty, converter);
leftProperty.addListener(binding);
rightProperty.addListener(binding);
leftProperty.setValue(converter.toLeft(rightProperty.getValue()));
}