private void animateValue(double from, double to, Duration duration, Interpolator interpolator, DoubleConsumer consumer, EventHandler<ActionEvent> l) { timeline.stop(); timeline.getKeyFrames().clear(); KeyValue keyValue = new KeyValue(new WritableValue<Double>() { @Override public Double getValue() { return from; } @Override public void setValue(Double value) { consumer.accept(value); } }, to, interpolator == null ? Interpolator.LINEAR : interpolator); timeline.getKeyFrames().add(new KeyFrame(duration, keyValue)); timeline.setOnFinished(l); timeline.play(); }
private static <T> T setIfUpdate(ObservableMap<? extends String, ? extends Object> map, String key, WritableValue<T>... props) { T newValue = (T) map.get(key); if (newValue != null) { boolean stringEmpty = false; if (newValue instanceof String) { String newStr = (String) newValue; stringEmpty = newStr.isEmpty(); } for (WritableValue<T> prop : props) { if (stringEmpty) { if (prop.getValue() == null) { prop.setValue(newValue); } } else { prop.setValue(newValue); } } } return newValue; }
protected <T extends Enum<T>> Supplier<WritableValue<String>> enumToString(Class<T> enumClass, ObjectProperty<T> property) { return () -> { val stringProperty = new SimpleStringProperty(); stringProperty.bindBidirectional(property, new StringConverter<T>() { @Override public String toString(T object) { if (object == null) { return "null"; } return object.name(); } @Override public T fromString(String string) { if ("null".equals(string)) { return null; } try { return Enum.valueOf(enumClass, string); } catch (IllegalArgumentException e) { try { val number = (int) Double.parseDouble(string); return enumClass.cast(EnumSet.allOf(enumClass).toArray()[number]); } catch (Exception ex) { throw new HotaruRuntimeException("No constant " + string + " for type " + enumClass.getSimpleName()); } } } }); return stringProperty; }; }
public void propertyCopy(Node from, Node to) throws Exception { Method[] fromMethods = from.getClass().getMethods(); Class<? extends Node> class1 = to.getClass(); for (Method fromMethod : fromMethods) { String methodName = fromMethod.getName(); if (methodName.endsWith("Property")) { Method targetMethod = class1.getMethod(methodName); targetMethod.setAccessible(true); if (targetMethod != null) { Object fromPropertValue = fromMethod.invoke(from); Object toPropertValue = targetMethod.invoke(from); if (Property.class.isAssignableFrom(fromPropertValue.getClass())) { if (WritableValue.class.isAssignableFrom(fromPropertValue.getClass())) { // System.out.println("Writable : " + // fromPropertValue); // if // (StyleConverter.class.isAssignableFrom(fromPropertValue.getClass())) // { Property fromProp = (Property) fromPropertValue; Property toProp = (Property) toPropertValue; Object value = fromProp.getValue(); if (value == null) continue; System.out.println("set value : " + fromProp.getValue()); toProp.setValue(fromProp.getValue()); } // } } } } } }
public PropertyTimeline<T> setIfEmptyThenGet(Supplier<WritableValue<T>> supplier) { return setIfEmpty(wrap(supplier)).get(); }
private Supplier<PropertyTimeline<T>> wrap(Supplier<WritableValue<T>> supplier) { return () -> new PropertyTimeline<>(supplier.get()); }
public PropertyTimeline(WritableValue<T> property) { this.property = property; keyFrames = new TreeMap<>(); }
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { WritableValue<T> property = createProperty(); final T value = (T) context.convertAnother(null, readType(reader)); property.setValue(value); return property; }
@Override protected WritableValue<Boolean> createProperty() { return new SimpleBooleanProperty(); }
@Override protected WritableValue<String> createProperty() { return new SimpleStringProperty(); }
@Override protected WritableValue<Number> createProperty() { return new SimpleLongProperty(); }
@Override protected WritableValue<Number> createProperty() { return new SimpleIntegerProperty(); }
@Override protected WritableValue<Object> createProperty() { return new SimpleObjectProperty(); }
@Override protected WritableValue<Number> createProperty() { return new SimpleDoubleProperty(); }
public void setProperty(Node node, String name, Object value) { try { if (value == null) return; Method method = node.getClass().getMethod(name + "Property"); if (method == null) return; method.setAccessible(true); Object fromPropertValue = method.invoke(node); if (Property.class.isAssignableFrom(fromPropertValue.getClass())) { if (WritableValue.class.isAssignableFrom(fromPropertValue.getClass())) { Method setMethod = null; if (fromPropertValue instanceof BooleanProperty || fromPropertValue instanceof DoubleProperty) { setMethod = fromPropertValue.getClass().getMethod("setValue", Object.class); } else { setMethod = fromPropertValue.getClass().getMethod("set", Object.class); } if (setMethod != null) { setMethod.setAccessible(true); if (value.getClass().isPrimitive()) { setMethod.invoke(fromPropertValue, value.getClass()); } else { setMethod.invoke(fromPropertValue, value); } } } else { } } else { System.out.println(fromPropertValue); } } catch (Exception e) { System.out.println("error prop name : " + name + " value : " + value + " value type : " + value.getClass()); // e.printStackTrace(); } }
@Override public StyleableProperty<Boolean> getStyleableProperty(Pagination n) { final CPagenationSkin skin = (CPagenationSkin) n.getSkin(); return (StyleableProperty<Boolean>) (WritableValue<Boolean>) skin.arrowsVisibleProperty(); }
@Override public StyleableProperty<Boolean> getStyleableProperty(Pagination n) { final CPagenationSkin skin = (CPagenationSkin) n.getSkin(); return (StyleableProperty<Boolean>) (WritableValue<Boolean>) skin.pageInformationVisibleProperty(); }
@Override public StyleableProperty<Side> getStyleableProperty(Pagination n) { final CPagenationSkin skin = (CPagenationSkin) n.getSkin(); return (StyleableProperty<Side>) (WritableValue<Side>) skin.pageInformationAlignmentProperty(); }
@Override public StyleableProperty<Boolean> getStyleableProperty(Pagination n) { final CPagenationSkin skin = (CPagenationSkin) n.getSkin(); return (StyleableProperty<Boolean>) (WritableValue<Boolean>) skin.tooltipVisibleProperty(); }
@Override public StyleableProperty<Number> getStyleableProperty(Pagination n) { final CPagenationSkin skin = (CPagenationSkin) n.getSkin(); return (StyleableProperty<Number>) (WritableValue<Number>) skin.arrowButtonGapProperty(); }
public void undo() { initialValues.forEach(WritableValue::setValue); setValue(false); }
public SkinTransition(Duration duration, Function<Double, Double> expression, WritableValue<Number>... observables) { setCycleDuration(duration); this.expression = expression; this.observables = Arrays.asList(observables); }
@SuppressWarnings("RedundantCast") @Override public StyleableProperty<Number> getStyleableProperty(RadialMenuItem rmi) { return (StyleableProperty<Number>) (WritableValue<Number>) rmi.sizeProperty(); }
public Object toDataStoreValue(ValueMapping vm, Object val, JDBCStore store) { if (val instanceof String) { return val; } return (val == null) ? null : ((WritableValue<?>) val).getValue(); }
public WritableValue<?> getTarget() { return target == null ? targetSupplier.get() : target; }
public JFXKeyValueBuilder setTarget(WritableValue<?> target) { this.target = target; return this; }
public JFXKeyValueBuilder setTargetSupplier(Supplier<WritableValue<?>> targetSupplier) { this.targetSupplier = targetSupplier; return this; }
public DefaultJavaFXBinder(final WritableValue<S> javaFxValue) { this.javaFxValue = Assert.requireNonNull(javaFxValue, "javaFxValue"); }
@Override public StyleableProperty<Number> getStyleableProperty(TreeCell<?> n) { final EditingTreeCellSkin<?> skin = (EditingTreeCellSkin<?>) n.getSkin(); return (StyleableProperty<Number>)(WritableValue<Number>)skin.indentProperty(); }
private void cleanUpRepeatingFramesAndValues() { ObservableList<KeyFrame> timelineKeyFrames = timeline.getKeyFrames().sorted(new KeyFrameComparator()); // Timeline timeline; int kfTotal = timelineKeyFrames.size(), kfRemoved = 0; int kvTotal = 0, kvRemoved = 0; Map<Duration, KeyFrame> kfUnique = new HashMap<>(); Map<WritableValue, KeyValue> kvUnique = new HashMap<>(); MapOfLists<KeyFrame, KeyFrame> duplicates = new MapOfLists<>(); Iterator<KeyFrame> iterator = timelineKeyFrames.iterator(); while (iterator.hasNext()) { KeyFrame duplicate = iterator.next(); KeyFrame original = kfUnique.put(duplicate.getTime(), duplicate); if (original != null) { kfRemoved++; iterator.remove(); // removing duplicate keyFrame duplicates.add(original, duplicate); kfUnique.put(duplicate.getTime(), original); } kvUnique.clear(); for (KeyValue kvDup : duplicate.getValues()) { kvTotal++; KeyValue kvOrig = kvUnique.put(kvDup.getTarget(), kvDup); if (kvOrig != null) { kvRemoved++; if (!kvOrig.getEndValue().equals(kvDup.getEndValue()) && kvOrig.getTarget() == kvDup.getTarget()) { System.err.println("KeyValues set different values for KeyFrame " + duplicate.getTime() + ":" + "\n kvOrig = " + kvOrig + ", \nkvDup = " + kvDup); } } } } for (KeyFrame orig : duplicates.keySet()) { List<KeyValue> keyValues = new ArrayList<>(); for (KeyFrame dup : duplicates.get(orig)) { keyValues.addAll(dup.getValues()); } timelineKeyFrames.set(timelineKeyFrames.indexOf(orig), new KeyFrame(orig.getTime(), keyValues.toArray(new KeyValue[keyValues.size()]))); } System.out.printf("Removed %d (%.2f%%) duplicate KeyFrames out of total %d.\n", kfRemoved, 100d * kfRemoved / kfTotal, kfTotal); System.out.printf("Identified %d (%.2f%%) duplicate KeyValues out of total %d.\n", kvRemoved, 100d * kvRemoved / kvTotal, kvTotal); }
@Override public WritableValue<Number> getWritableValue(CategoryDateAxis n) { return n.startMarginProperty(); }
@Override public WritableValue<Number> getWritableValue(CategoryDateAxis n) { return n.endMarginProperty(); }
@Override public WritableValue<Boolean> getWritableValue(CategoryDateAxis n) { return n.gapStartAndEndProperty(); }
public void push(WritableValue p, long time, Object value) { KeyValue kv = new KeyValue(p, value); KeyFrame kf = new KeyFrame(Duration.millis(time), kv); timeline.getKeyFrames().add(kf); }
@Override public WritableValue<Number> getWritableValue(DoubleSlider n) { return n.blockIncrementProperty(); }
@Override public WritableValue<Boolean> getWritableValue(DoubleSlider n) { return n.showTickLabelsProperty(); }
@Override public WritableValue<Boolean> getWritableValue(DoubleSlider n) { return n.showTickMarksProperty(); }
@Override public WritableValue<Boolean> getWritableValue(DoubleSlider n) { return n.snapToTicksProperty(); }