use of org.controlsfx.property.BeanProperty in project KNOBS by ESSICS.
the class KnobController method initialize.
@Override
public void initialize(URL location, ResourceBundle resources) {
propertySheet.setPropertyEditorFactory(new KnobPropertyEditorFactory());
long beforeTime = System.currentTimeMillis();
Knob knob = KnobBuilder.create().onAdjusted(e -> LOGGER.info(MessageFormat.format("Current value reached target: {0}", ((Knob) e.getSource()).getCurrentValue()))).onTargetSet(e -> {
LOGGER.info(MessageFormat.format("Target changed: {0}", ((Knob) e.getSource()).getTargetValue()));
updateCurrentValue = true;
}).build();
long afterTime = System.currentTimeMillis();
LOGGER.log(Level.INFO, "Construction time: {0,number,#########0}ms", afterTime - beforeTime);
knobContainer.getChildren().add(knob);
Map<Class<?>, String> categories = new HashMap<>(5);
categories.put(Knob.class, "\u200BKnob");
categories.put(Region.class, "\u200B\u200BRegion");
categories.put(Parent.class, "\u200B\u200B\u200BParent");
categories.put(Node.class, "\u200B\u200B\u200B\u200BNode");
categories.put(Object.class, "\u200B\u200B\u200B\u200B\u200BObject");
try {
BeanInfo beanInfo = Introspector.getBeanInfo(Knob.class, Object.class);
for (PropertyDescriptor p : beanInfo.getPropertyDescriptors()) {
try {
if (p.getReadMethod() != null && p.getWriteMethod() != null) {
p.setValue(BeanProperty.CATEGORY_LABEL_KEY, categories.get(p.getReadMethod().getDeclaringClass()));
propertySheet.getItems().add(new BeanProperty(knob, p));
}
} catch (Exception iex) {
LOGGER.log(Level.SEVERE, MessageFormat.format("Unable to handle property \"{0}\" [{1}].", p.getName(), iex.getMessage()));
}
}
} catch (IntrospectionException ex) {
LOGGER.log(Level.SEVERE, "Unable to initialize the controller.", ex);
}
propertySheet.setMode(PropertySheet.Mode.CATEGORY);
timer.scheduleAtFixedRate(() -> {
if (updateCurrentValue) {
double step = (knob.getMaxValue() - knob.getMinValue()) / 234;
double cValue = knob.getCurrentValue();
double tValue = knob.getTargetValue();
if (cValue < tValue) {
Platform.runLater(() -> {
if ((tValue - cValue) > step) {
knob.setCurrentValue(cValue + step);
} else {
knob.setCurrentValue(tValue);
updateCurrentValue = false;
}
});
} else if (cValue > tValue) {
Platform.runLater(() -> {
if ((cValue - tValue) > step) {
knob.setCurrentValue(cValue - step);
} else {
knob.setCurrentValue(tValue);
updateCurrentValue = false;
}
});
}
}
}, 2000, 50, TimeUnit.MILLISECONDS);
}
Aggregations