javafx.beans.property.Property Java Examples

The following examples show how to use javafx.beans.property.Property. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GroupAndDatasetStructure.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public GroupAndDatasetStructure(
		final String groupPromptText,
		final String datasetPromptText,
		final Property<String> group,
		final Property<String> dataset,
		final ObservableList<String> datasetChoices,
		final ObservableValue<Boolean> isDropDownReady,
		final BiFunction<String, Scene, String> onBrowseClicked)
{
	super();
	this.groupPromptText = groupPromptText;
	this.datasetPromptText = datasetPromptText;
	this.group = group;
	this.dataset = dataset;
	this.datasetChoices = datasetChoices;
	this.isDropDownReady = isDropDownReady;
	this.onBrowseClicked = onBrowseClicked;
}
 
Example #2
Source File: GenericRootAndDatasetStructure.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public GenericRootAndDatasetStructure(
		final String datasetPromptText,
		final Property<T> group,
		final Property<String> dataset,
		final ObservableList<String> datasetChoices,
		final ObservableValue<Boolean> isDropDownReady,
		final Consumer<Scene> onBrowseClicked,
		final Supplier<Node> groupNode)
{
	super();
	this.datasetPromptText = datasetPromptText;
	this.dataset = dataset;
	this.datasetChoices = datasetChoices;
	this.isDropDownReady = isDropDownReady;
	this.onBrowseClicked = onBrowseClicked;
	this.rootNode = groupNode;
	this.node = createNode();
}
 
Example #3
Source File: TestDatatypes.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void simpleAvgBinding() {
  Property<Double> a = new SimpleObjectProperty<>();
  Property<Double> b = new SimpleObjectProperty<>();
  Property<Double>[] properties = new Property[] {a, b};
  Property<Double> avg = new SimpleObjectProperty<>();

  ObjectBinding<Double> avgBinding = Bindings.createObjectBinding(() -> {
    double sum = 0;
    int n = 0;
    for (Property<Double> p : properties) {
      if (p.getValue() != null) {
        sum += p.getValue().doubleValue();
        n++;
      }
    }
    return n == 0 ? 0 : sum / n;
  }, properties);
  avg.bind(avgBinding);
  logger.info("avg=" + avg.getValue().doubleValue() + "   " + avg.getValue());
  a.setValue(10d);
  logger.info("avg=" + avg.getValue().doubleValue() + "   " + avg.getValue());
  b.setValue(5d);
  logger.info("avg=" + avg.getValue().doubleValue() + "   " + avg.getValue());
}
 
Example #4
Source File: Converters.java    From FxDock with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> StringConverter<T> get(Property<T> p)
{
	if(p instanceof BooleanProperty)
	{
		return (StringConverter<T>)BOOLEAN();
	}
	else if(p instanceof IntegerProperty)
	{
		return (StringConverter<T>)INT();
	}
	else if(p instanceof DoubleProperty)
	{
		return (StringConverter<T>)NUMBER_DOUBLE();
	}
	else if(p instanceof StringProperty)
	{
		return (StringConverter<T>)STRING();
	}
	else
	{
		throw new Error("?" + p);
	}
}
 
Example #5
Source File: DirtyState.java    From tornadofx-controls with Apache License 2.0 6 votes vote down vote up
private void addDeclaredProperties() {
	Object bean = getBean();
	if (bean == null) return;

	for (Method method : bean.getClass().getDeclaredMethods()) {
		if (method.getName().endsWith("Property") && Property.class.isAssignableFrom(method.getReturnType())
			&& !DirtyState.class.isAssignableFrom(method.getReturnType())) {
			try {
				Property property = (Property) method.invoke(bean);
				if (property != null)
					properties.add(property);
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
	}
}
 
Example #6
Source File: DirtyState.java    From tornadofx-controls with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("SuspiciousMethodCalls")
public void changed(ObservableValue property, Object oldValue, Object newValue) {
 if (dirtyProperties.contains(property)) {
  // Remove dirty state if newValue equals inititalValue
  if (Objects.equals(initialValues.get(property), newValue))
   dirtyProperties.remove(property);

  // If no other properties dirty, remove dirty state
  if (dirtyProperties.isEmpty() && isDirty())
   setValue(false);
 } else {
  // Configure initital value and add to dirty property list
  initialValues.put((Property) property, oldValue);
  dirtyProperties.add((Property) property);

  // Only trigger dirty state change if previously clean
  if (!isDirty())
   setValue(true);
 }

}
 
Example #7
Source File: RegexConfigFragment.java    From mdict-java with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void changed(ObservableValue observable, Object oldValue, Object newValue) {
	if(observable instanceof Property) {
		Property prop = (Property) observable;
		if(prop.getBean() instanceof Node) {
			Node node = (Node) prop.getBean();
			switch (node.getId()) {
				case ps_case:
					opt.SetPageSearchCaseSensitive((boolean) newValue);
				break;
				case ps_separate:
					opt.SetPageSearchSeparateWord((boolean) newValue);
				break;
				case regex_head:
					opt.SetRegexSearchEngineAutoAddHead((boolean) newValue);
				break;
				case regex_case:
					opt.SetRegexSearchEngineCaseSensitive((boolean) newValue);
				break;
				case page_regex_case:
					opt.SetPageSearchCaseSensitive((boolean) newValue);
				break;
				case pagewutsp:
					opt.SetPageWithoutSpace((boolean)newValue);
				break;
			}
		}
	}
}
 
Example #8
Source File: Var.java    From ReactFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
static <T> SuspendableVar<T> suspendable(Property<T> p) {
    if(p instanceof SuspendableVar) {
        return (SuspendableVar<T>) p;
    } else {
        Var<T> var = p instanceof Var
                ? (Var<T>) p
                : new VarWrapper<>(p);
        return new SuspendableVarWrapper<>(var);
    }
}
 
Example #9
Source File: SessionContext.java    From jfxvnc with Apache License 2.0 5 votes vote down vote up
/**
 * session scope bindings
 * 
 * @return
 */
public ObservableMap<String, Property<?>> getBindings() {
  if (bindings == null) {
    bindings = FXCollections.observableHashMap();
  }
  return bindings;
}
 
Example #10
Source File: ConditionalBinding.java    From EasyBind with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void changed(ObservableValue<? extends Boolean> cond,
        Boolean wasTrue, Boolean isTrue) {
    Property<T> tgt = this.target.get();
    if(tgt == null) {
        condition.removeListener((ChangeListener<Boolean>) this);
    } else if(isTrue) {
        tgt.bind(source);
    } else {
        tgt.unbind();
    }
}
 
Example #11
Source File: SessionContext.java    From jfxvnc with Apache License 2.0 5 votes vote down vote up
public Optional<DoubleProperty> getDoubleBinding(String key) {
  Optional<Property<?>> b = getBinding(key);
  if (!b.isPresent() || !DoubleProperty.class.isInstance(b.get())) {
    return Optional.empty();
  }
  return Optional.of((DoubleProperty) b.get());
}
 
Example #12
Source File: FlatMap.java    From EasyBind with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void setValue(U value) {
    Property<U> target = getTargetObservable();
    if(target != null) {
        target.setValue(value);
    }
}
 
Example #13
Source File: SimpleSingleValuePropertyCommandExecutor.java    From SynchronizeFX with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void execute(final SetPropertyValue command) {
    @SuppressWarnings("unchecked")
    final Property<Object> property = (Property<Object>) objectRegistry.getByIdOrFail(command.getPropertyId());

    changeExecutor.execute(property, new Runnable() {
        @Override
        public void run() {
            property.setValue(valueMapper.map(command.getValue()));
        }
    });
}
 
Example #14
Source File: SessionContext.java    From jfxvnc with Apache License 2.0 5 votes vote down vote up
public Optional<StringProperty> getStringBinding(String key) {
  Optional<Property<?>> b = getBinding(key);
  if (!b.isPresent() || !StringProperty.class.isInstance(b.get())) {
    return Optional.empty();
  }
  return Optional.of((StringProperty) b.get());
}
 
Example #15
Source File: FlatMap.java    From EasyBind with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void unbind() {
    Property<U> target = getTargetObservable();
    if(target != null) {
        target.unbind();
    }
    boundTo = null;
}
 
Example #16
Source File: DirtyState.java    From tornadofx-controls with Apache License 2.0 5 votes vote down vote up
private void monitorChanges() {
    properties.addListener((ListChangeListener<Property>) change -> {
        while (change.next()) {
            if (change.wasAdded()) change.getAddedSubList().forEach(p -> p.addListener(dirtyListener));
            if (change.wasRemoved()) change.getRemoved().forEach(p -> p.removeListener(dirtyListener));
        }
    });
}
 
Example #17
Source File: FloatRangeType.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ObjectBinding<?> createBinding(BindingsType bind, ModularFeatureListRow row) {
  // get all properties of all features
  @SuppressWarnings("unchecked")
  Property<Range<Float>>[] prop =
      row.streamFeatures().map(f -> f.get(this)).toArray(Property[]::new);
  switch (bind) {
    case RANGE:
      return Bindings.createObjectBinding(() -> {
        Range<Float> result = null;
        for (Property<Range<Float>> p : prop) {
          if (p.getValue() != null) {
            if (result == null)
              result = p.getValue();
            else
              result = result.span(p.getValue());
          }
        }
        return result;
      }, prop);
    case AVERAGE:
    case MIN:
    case MAX:
    case SUM:
    case COUNT:
    default:
      throw new UndefinedRowBindingException(this, bind);
  }
}
 
Example #18
Source File: IntegerType.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
@Nonnull
public String getFormattedString(@Nonnull Property<Integer> value) {
  if (value.getValue() == null)
    return "";
  return getFormatter().format(value.getValue().intValue());
}
 
Example #19
Source File: SimpleSerializer.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
public SimpleSerializer(final Property property) {
    this.property = property;
    if (property instanceof BooleanProperty) {
        editionType = EditionType.COMBO;
    } else if (property instanceof ObjectProperty && property.getValue() instanceof Color) {
        editionType = EditionType.COLOR_PICKER;
    } else {
        editionType = EditionType.TEXT_FIELD;
    }
}
 
Example #20
Source File: FibTest.java    From ReactFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void setupFor(Property<Number> resultHolder) {
    resultHolder.bind(fib[N-2].add(fib[N-1]));

    // count the invalidations of the result
    resultHolder.addListener(o -> {
        invalidationCount += 1;
        resultHolder.getValue(); // force recomputation
    });
}
 
Example #21
Source File: AreaShareChart.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public AreaShareChart(@Nonnull ModularFeatureListRow row, AtomicDouble progress) {
  Float sum = row.streamFeatures().map(ModularFeature::getArea).filter(p -> p.getValue() != null)
      .map(Property<Float>::getValue).reduce(0f, Float::sum);

  List<Rectangle> all = new ArrayList<>();
  int i = 0;
  int size = row.getFeatures().size();
  for (Entry<RawDataFile, ModularFeature> entry : row.getFeatures().entrySet()) {
    Property<Float> areaProperty = entry.getValue().get(AreaType.class);
    if (areaProperty.getValue() != null) {
      // color from sample
      Color color = entry.getValue().get(RawColorType.class).getValue();
      if (color == null)
        color = Color.DARKORANGE;

      float ratio = areaProperty.getValue() / sum;
      Rectangle rect = new Rectangle();
      rect.setFill(color);
      // bind width
      rect.widthProperty().bind(this.widthProperty().multiply(ratio));
      rect.setHeight(i % 2 == 0 ? 20 : 25);
      all.add(rect);
      i++;
      if (progress != null)
        progress.addAndGet(1.0 / size);
    }
  }
  HBox box = new HBox(0, all.toArray(Rectangle[]::new));
  box.setPrefWidth(100);
  box.setAlignment(Pos.CENTER_LEFT);

  this.getChildren().add(box);
}
 
Example #22
Source File: DoubleRangeType.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ObjectBinding<?> createBinding(BindingsType bind, ModularFeatureListRow row) {
  // get all properties of all features
  @SuppressWarnings("unchecked")
  Property<Range<Double>>[] prop =
      row.streamFeatures().map(f -> f.get(this)).toArray(Property[]::new);
  switch (bind) {
    case RANGE:
      return Bindings.createObjectBinding(() -> {
        Range<Double> result = null;
        for (Property<Range<Double>> p : prop) {
          if (p.getValue() != null) {
            if (result == null)
              result = p.getValue();
            else
              result = result.span(p.getValue());
          }
        }
        return result;
      }, prop);
    case AVERAGE:
    case MIN:
    case MAX:
    case SUM:
    case COUNT:
    default:
      throw new UndefinedRowBindingException(this, bind);
  }
}
 
Example #23
Source File: DoubleType.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
@Nonnull
public String getFormattedString(@Nonnull Property<Double> value) {
  if (value.getValue() == null)
    return "";
  return getFormatter().format(value.getValue().doubleValue());
}
 
Example #24
Source File: SessionContext.java    From jfxvnc with Apache License 2.0 5 votes vote down vote up
/**
 * add session scope binding (Property.getName() required)
 * 
 * @param value
 */
public void addBinding(Property<?> value) {
  if (value.getName() == null || value.getName().isEmpty()) {
    throw new IllegalArgumentException("property name must not be empty");
  }
  getBindings().put(value.getName(), value);
}
 
Example #25
Source File: SessionContext.java    From jfxvnc with Apache License 2.0 5 votes vote down vote up
public Optional<FloatProperty> getFloatBinding(String key) {
  Optional<Property<?>> b = getBinding(key);
  if (!b.isPresent() || !FloatProperty.class.isInstance(b.get())) {
    return Optional.empty();
  }
  return Optional.of((FloatProperty) b.get());
}
 
Example #26
Source File: PCGenStatusBarModel.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
Property<Number> percentDoneProperty()
{
	return percentDone;
}
 
Example #27
Source File: SettingsPresenter.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public SliderOption(Node graphic, String caption, String description, String category, IntegerProperty value, 
        boolean isEditable, int min, int max) {
    super(graphic, caption, description, category, (Property<Number>) value, isEditable);
    this.min = min;
    this.max = max;
}
 
Example #28
Source File: MetaCheat.java    From jace with GNU General Public License v2.0 4 votes vote down vote up
public Property<String> searchValueProperty() {
    return searchValueProperty;
}
 
Example #29
Source File: LogFilterView.java    From dolphin-platform with Apache License 2.0 4 votes vote down vote up
public Property<LoggerSearchRequest> loggerSearchRequestProperty() {
    return loggerSearchRequest;
}
 
Example #30
Source File: MultilineGraphView.java    From diirt with MIT License 4 votes vote down vote up
public Property< InterpolationScheme > interpolationSchemeProperty() {
    return this.interpolationScheme;
}