本文整理汇总了Java中javafx.beans.property.Property类的典型用法代码示例。如果您正苦于以下问题:Java Property类的具体用法?Java Property怎么用?Java Property使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Property类属于javafx.beans.property包,在下文中一共展示了Property类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: normalize
import javafx.beans.property.Property; //导入依赖的package包/类
@SuppressWarnings("unchecked")
static Object normalize(Property<?> prop, Class<?> clz) {
if (clz.isAssignableFrom(IntegerProperty.class)) {
return toInteger((Property<Integer>) prop);
} else if (clz.isAssignableFrom(LongProperty.class)) {
return toLong((Property<Long>) prop);
} else if (clz.isAssignableFrom(FloatProperty.class)) {
return toFloat((Property<Float>) prop);
} else if (clz.isAssignableFrom(DoubleProperty.class)) {
return toDouble((Property<Double>) prop);
} else if (clz.isAssignableFrom(StringProperty.class)) {
return toString((Property<String>) prop);
} else if (clz.isAssignableFrom(ObjectProperty.class)) {
return toObject((Property<Object>) prop);
}
return prop;
}
示例2: 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
}
}
}
示例3: 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");
}
示例4: updateSeries
import javafx.beans.property.Property; //导入依赖的package包/类
private void updateSeries(XYChart.Series<Number, Number> series, long now, double newData) {
long elapsed = now - Time.getStartTime();
XYChart.Data<Number, Number> point = new XYChart.Data<>(elapsed, newData);
ObservableList<XYChart.Data<Number, Number>> dataList = series.getData();
if (!dataList.isEmpty()) {
// Make the graph a square wave
// This prevents the graph from appearing to be continuous when the data is discreet
// Note this only affects the chart; the actual data is not changed
double prev = dataList.get(dataList.size() - 1).getYValue().doubleValue();
if (prev != newData) {
dataList.add(new XYChart.Data<>(elapsed - 1, prev));
}
}
dataList.add(point);
realData.computeIfAbsent(series, __ -> FXCollections.observableArrayList()).add(point);
if (!chart.getData().contains(series)
&& Optional.ofNullable(visibleSeries.get(series)).map(Property::getValue).orElse(true)) {
chart.getData().add(series);
}
updateBounds(elapsed);
}
示例5: bindBidirectional
import javafx.beans.property.Property; //导入依赖的package包/类
/**
* Binds a {@link Property} by traversing the bean's field tree
*
* @param fieldPath
* the <b><code>.</code></b> separated field paths relative to
* the {@link #getBean()} that will be traversed
* @param property
* the {@link Property} to bind to the field class type of the
* property
* @param propertyType
* the class type of the {@link Property} value
*/
@SuppressWarnings("unchecked")
public <T> void bindBidirectional(final String fieldPath,
final Property<T> property, final Class<T> propertyType) {
Class<T> clazz = propertyType != null ? propertyType
: propertyValueClass(property);
if (clazz == null && property.getValue() != null) {
clazz = (Class<T>) property.getValue().getClass();
}
if (clazz == null || clazz == Object.class) {
throw new UnsupportedOperationException(String.format(
"Unable to determine property value class for %1$s "
+ "and declared type %2$s", property, propertyType));
}
getRoot().performOperation(fieldPath, property, clazz,
FieldBeanOperation.BIND);
}
示例6: nestValue
import javafx.beans.property.Property; //导入依赖的package包/类
public static <F, T> ObservableValue<T> nestValue(ObservableValue<F> pf, Function<F, ObservableValue<T>> func) {
ObservableValue<T> current = func.apply(pf.getValue());
Property<T> nestProp = new SimpleObjectProperty<>();
nestProp.bind(current);
pf.addListener((ob, o, n) -> {
ObservableValue<T> pt = func.apply(n);
nestProp.unbind();
nestProp.bind(pt);
});
return nestProp;
}
示例7: propertyValueClass
import javafx.beans.property.Property; //导入依赖的package包/类
/**
* Provides the underlying value class for a given {@link Property}
*
* @param property
* the {@link Property} to check
* @return the value class of the {@link Property}
*/
@SuppressWarnings("unchecked")
protected static <T> Class<T> propertyValueClass(final Property<T> property) {
Class<T> clazz = null;
if (property != null) {
if (StringProperty.class.isAssignableFrom(property.getClass())) {
clazz = (Class<T>) String.class;
} else if (IntegerProperty.class.isAssignableFrom(property
.getClass())) {
clazz = (Class<T>) Integer.class;
} else if (BooleanProperty.class.isAssignableFrom(property
.getClass())) {
clazz = (Class<T>) Boolean.class;
} else if (DoubleProperty.class.isAssignableFrom(property
.getClass())) {
clazz = (Class<T>) Double.class;
} else if (FloatProperty.class
.isAssignableFrom(property.getClass())) {
clazz = (Class<T>) Float.class;
} else if (LongProperty.class.isAssignableFrom(property.getClass())) {
clazz = (Class<T>) Long.class;
} else if (ListProperty.class.isAssignableFrom(property.getClass())) {
clazz = (Class<T>) List.class;
} else if (MapProperty.class.isAssignableFrom(property.getClass())) {
clazz = (Class<T>) Map.class;
} else {
clazz = (Class<T>) Object.class;
}
}
return clazz;
}
示例8: getStyleableProperty
import javafx.beans.property.Property; //导入依赖的package包/类
@Override
public StyleableProperty<T> getStyleableProperty(S styleable) {
Property<T> property = propertyExtractor.apply(styleable);
if (property instanceof StyleableProperty) {
// no need to wrap an already styleable property
return (StyleableProperty<T>) property;
} else {
return new SimpleStyleableObjectPropertyWrapper<>(this, property);
}
}
示例9: observePropertyChanges
import javafx.beans.property.Property; //导入依赖的package包/类
/**
* Observes changes to the given property and marks the project dirty
* (edited) when the property is changed.
*
* @param property
* The property to observe changes.
* @return The observed property.
*/
private <T extends Property<?>> T observePropertyChanges(T property)
{
property.addListener((observable, oldValue, newValue) ->
{
JavaBeanProperty<?> changedProperty = (JavaBeanProperty<?>) observable;
getCayennePropject().setDirty(true);
LOGGER.debug("Property Changed: [" + changedProperty.getBean().getClass().getSimpleName() + " " + changedProperty.getName() + "] " + oldValue + " -> " + newValue);
});
return property;
}
示例10: when
import javafx.beans.property.Property; //导入依赖的package包/类
/**
* A more general version of {@link Bindings#when(ObservableBooleanValue)}
* that can accept general boolean properties as conditions.
*
* @param condition the condition to bind to
*
* @see Bindings#when(ObservableBooleanValue)
*/
public static When when(Property<Boolean> condition) {
if (condition instanceof ObservableBooleanValue) {
return Bindings.when((ObservableBooleanValue) condition);
}
SimpleBooleanProperty realCondition = new SimpleBooleanProperty();
realCondition.bind(condition);
return Bindings.when(realCondition);
}
示例11: bindWithConverter
import javafx.beans.property.Property; //导入依赖的package包/类
/**
* Binds {@code firstProperty} to {@code secondProperty}, using a conversion function to map
* values of type {@code U} to {@code T} so the first property can be bound.
*
* @param firstProperty the property to bind
* @param secondProperty the property to bind to
* @param u2tConverter the conversion function
*/
public static <T, U> void bindWithConverter(
Property<T> firstProperty,
Property<U> secondProperty,
Function<U, T> u2tConverter) {
Binding<T> binding = EasyBind.monadic(secondProperty).map(u2tConverter);
bindings.put(firstProperty, binding);
firstProperty.bind(binding);
}
示例12: bindToMapBidirectionally
import javafx.beans.property.Property; //导入依赖的package包/类
/**
* Binds a property to a specific key in a map. If there is no entry for that key, the property's
* value will be set to null.
*
* @param property the property to bind
* @param map the map to bind to
* @param key the key for the entry to bind to
* @param v2t a conversion function for converting objects of type <i>V</i> to type <i>T</i>
* @param <K> the types of the keys in the map
* @param <V> the types of the values in the map
* @param <T> the type of data in the property
*/
public static <K, V, T extends V> void bindToMapBidirectionally(Property<T> property,
ObservableMap<K, V> map,
K key,
Function<V, T> v2t) {
property.addListener((__, oldValue, newValue) -> map.put(key, newValue));
map.addListener((MapChangeListener<K, V>) change -> {
if (change.getKey().equals(key)) {
if (change.wasRemoved() && !map.containsKey(key)) {
property.setValue(null);
} else if (change.wasAdded()) {
property.setValue(v2t.apply(change.getValueAdded()));
}
}
});
}
示例13: save
import javafx.beans.property.Property; //导入依赖的package包/类
/**
* Saves a property to a preferences object.
*
* @param property the property to save
* @param preferences the preferences object to save to
* @param serializer a function to use to convert the property's value to a String that can be stored in
* @param <T> the type of the property
*
* @throws IllegalArgumentException if the value of the property is null
*/
public static <T> void save(Property<? extends T> property,
Preferences preferences,
Function<? super T, String> serializer) {
T value = property.getValue();
if (value == null) {
throw new IllegalArgumentException("The property must have a value");
}
preferences.put(property.getName(), serializer.apply(value));
}
示例14: ExtendedPropertySheet
import javafx.beans.property.Property; //导入依赖的package包/类
/**
* Creates a new property sheet containing items for each of the given properties.
*/
public ExtendedPropertySheet(Collection<? extends Property<?>> properties) {
this();
getItems().setAll(properties.stream()
.map(PropertyItem::new)
.collect(Collectors.toList()));
}
示例15: testBindBidirectionalWithConverterNullFirstInitialValue
import javafx.beans.property.Property; //导入依赖的package包/类
@Test
public void testBindBidirectionalWithConverterNullFirstInitialValue() {
// given
Property<String> str = new SimpleStringProperty(null);
Property<Number> num = new SimpleDoubleProperty(0.0);
// when
PropertyUtils.bindBidirectionalWithConverter(str, num, Double::parseDouble, Object::toString);
// then
assertAll(
() -> assertEquals("0.0", str.getValue(), "String was not set correctly"),
() -> assertEquals(0.0, num.getValue().doubleValue(), "Number should not have changed")
);
}