@Override public ObservableObjectValue<Background> getBackground() { if (background == null) { synchronized (lock) { if (background == null) { ObservableObjectValue<Image> bgimg = getBackgroundImage(); background = Bindings.createObjectBinding(() -> new Background(new BackgroundImage( bgimg.get(), BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, true, true, true, true))), bgimg); } } } return background; }
/** * Bind the supplied extractor function which extracts the target data structure T from the source to the source * {@link ObservableObjectValue}, and optionally to the {@link CombinedGrouping} {@link ObservableObjectValue} from * the {@link AbstractViewController} superclass if present. * <p> * @param source the {@link ObservableObjectValue} encapsulating the source from which the target data structure can * be extracted * @param targetExtractor a function which extracts the target from the source Object */ public void bind(ObservableObjectValue<? extends Object> source, Function<Object, T> targetExtractor) { // The createObjectBinding() dependency varargs parameter specifies a number of Observables. If the value of any // of those changes, the Binding is triggered and the specified function is executed. This is IMHO not so // clearly documented in the createObjectBinding() javadoc. // The View does not support CombinedGrouping. if (getGrouping() == null) { sourceBinding = createObjectBinding(() -> targetExtractor.apply(source.get()), source); } // The View supports CombinedGrouping. else { sourceBinding = createObjectBinding( () -> targetExtractor.apply(source.get()), source, getGrouping()); } }
public void initializeTabChangeListener(TabPane tabPane) { ReadOnlyObjectProperty<Tab> itemProperty = tabPane.getSelectionModel().selectedItemProperty(); tabPane.setOnMouseReleased(event -> { Optional.ofNullable(itemProperty) .map(ObservableObjectValue::get) .filter(e -> e instanceof MyTab) .map(e -> (MyTab) e) .map(MyTab::getEditorPane) .ifPresent(EditorPane::focus); }); itemProperty.addListener((observable, oldValue, selectedTab) -> { Optional.ofNullable(selectedTab) .filter(e -> e instanceof MyTab) .map(e -> (MyTab) e) .map(MyTab::getEditorPane) .filter(EditorPane::getReady) .ifPresent(EditorPane::updatePreviewUrl); }); }
public void setItem(Sensor<?> sensor, ObservableObjectValue<Color> color) { color.addListener((observable, oldValue, newValue) -> { valueLabel.setTextFill(newValue); nameLabel.setTextFill(newValue); }); sensor.getUpdateCount().addListener((observable, oldValue, newValue) -> { valueLabel.setText(sensor.getCurrentValueAsString()); nameLabel.setText(sensor.getName()); }); valueLabel.setText(sensor.getCurrentValueAsString()); nameLabel.setText(sensor.getName()); valueLabel.setTextFill(color.get()); nameLabel.setTextFill(color.get()); }
private void initializeRulesPane() { ObservableObjectValue<Colorizer> selectedColorizer = colorizersPane.selectedItemProperty(); selectedColorizerPane.disableProperty().bind(Bindings.isNull(selectedColorizer)); ListBinding<StyleRule> selectedColorizerRules = UIUtils.selectList(selectedColorizer, Colorizer::getRules); rulesPane.setItemFactory(StyleRule::new); rulesPane.setItemDuplicator(StyleRule::new); rulesPane.getList().itemsProperty().bind(selectedColorizerRules); }
private Button makeDeleteMcdirButton(GameVersionProvider provider, Parent parent) { Button button = new Button(); ObservableObjectValue<Image> deleteIcon = ImageLoading.load("img/org.to2mbn.lolixl.ui.sidebar.version/delete_mcdir.png"); button.backgroundProperty().bind(Bindings.createObjectBinding(() -> new Background(new BackgroundImage(deleteIcon.get(), null, null, null, null)), deleteIcon)); button.setOnAction(event -> provider.delete()); return button; }
@Test public void testObservableObjectValue(){ ObservableObjectValue<TestPerson> actual = new SimpleObjectProperty<>(person); assertThat(actual).hasValue(person); assertThat(actual).hasSameValue(actual); }
@Test public void shoud_pass_if_actual_has_given_value(){ TestPerson person = new TestPerson("Name"); ObservableObjectValue<TestPerson> actual = new SimpleObjectProperty<>(person); new ObservableValueAssertions<>(actual).hasValue(person); }
@Test public void should_fail_if_actual_has_wrong_value(){ try{ TestPerson person = new TestPerson("Name"); TestPerson other = new TestPerson("Other"); ObservableObjectValue<TestPerson> actual = new SimpleObjectProperty<>(person); new ObservableValueAssertions<>(actual).hasValue(other); fail("Should throw an AssertionError"); }catch(AssertionError error){ assertThat(error).hasMessageContaining("<Other> but was <Name>"); } }
@Test public void should_fail_if_expectedValue_is_null(){ try{ TestPerson person = new TestPerson("Name"); ObservableObjectValue<TestPerson> actual = new SimpleObjectProperty<>(person); new ObservableValueAssertions<>(actual).hasValue(null); fail("Should throw an AssertionError"); }catch(AssertionError error){ assertThat(error).hasMessageContaining("expected value may not be null"); } }
@Test public void should_pass_if_actual_has_expected_value() { TestPerson person = new TestPerson("Name"); ObservableObjectValue<TestPerson> actual = new SimpleObjectProperty<>(person); ObservableObjectValue<TestPerson> expected = new SimpleObjectProperty<>(person); new ObservableValueAssertions<>(actual).hasSameValue(expected); }
@Test public void should_pass_if_both_observables_has_value_of_null(){ ObservableObjectValue<TestPerson> actual = new SimpleObjectProperty<>(); ObservableObjectValue<TestPerson> expected = new SimpleObjectProperty<>(); new ObservableValueAssertions<>(actual).hasSameValue(expected); }
@Test public void should_fail_if_only_actual_has_value_of_null(){ TestPerson person = new TestPerson("Name"); ObservableObjectValue<TestPerson> actual = new SimpleObjectProperty<>(); ObservableObjectValue<TestPerson> expected = new SimpleObjectProperty<>(person); try{ new ObservableValueAssertions<>(actual).hasSameValue(expected); } catch(AssertionError error){ assertThat(error).hasMessageContaining("<null> but was <Name>"); } }
@Test public void should_fail_if_only_expected_has_value_of_null(){ TestPerson person = new TestPerson("Name"); ObservableObjectValue<TestPerson> actual = new SimpleObjectProperty<>(person); ObservableObjectValue<TestPerson> expected = new SimpleObjectProperty<>(); try{ new ObservableValueAssertions<>(actual).hasSameValue(expected); } catch(AssertionError error){ assertThat(error).hasMessageContaining("<Name> but was <null>"); } }
@Test public void should_fail_if_actual_has_wrong_value() { try { TestPerson person = new TestPerson("Name"); TestPerson other = new TestPerson("Other"); ObservableObjectValue<TestPerson> actual = new SimpleObjectProperty<>(person); ObservableObjectValue<TestPerson> expected = new SimpleObjectProperty<>(other); new ObservableValueAssertions<>(actual).hasSameValue(expected); fail("Should throw an AsssertionError"); } catch (AssertionError error) { assertThat(error).hasMessageContaining("<Name> but was <Other>"); } }
@Test public void should_fail_if_expectedValue_is_null() { try { TestPerson person = new TestPerson("Name"); ObservableObjectValue<TestPerson> actual = new SimpleObjectProperty<>(person); new ObservableValueAssertions<>(actual).hasSameValue(null); fail("Should throw an AsssertionError"); } catch (AssertionError error) { assertThat(error).hasMessageContaining("expected value may not be null"); } }
/** * @deprecated Use {@link Val#suspendable(javafx.beans.value.ObservableValue)}. */ @Deprecated public static <T> ObjectBinding<T> wrap(ObservableObjectValue<T> source) { return new ObjectBinding<T>() { { bind(source); } @Override protected T computeValue() { return source.get(); } }; }
public static StringBinding covertOrDefault(ObservableObjectValue observableObjectValue, String defaultMessage) { return Bindings.when(Bindings.isNotNull(observableObjectValue)) .then(Bindings.convert(observableObjectValue)) .otherwise(defaultMessage); }
public ObservableObjectValue<NPC> getTargetData() { return targetProperty; }
@Override public ObservableObjectValue<Image> getIcon() { return icon; }
public static <T> ObservableObjectValue<T> object(T constant) { return new ObjectConstant<T>(constant); }
default ObservableObjectValue<Image> getIcon() { return FxConstants.object(null); }
static DoubleBinding createPerspectivePropertyBinding(Function<Perspective, Double> func, ObservableObjectValue<Perspective> perspective) { return Bindings.createDoubleBinding(() -> func.apply(perspective.get()), perspective); }
public static ObservableObjectValue<Image> load(String location) { return load0(location, 4); }
private static ObservableObjectValue<Image> load0(String location, int frames) { Class<?> caller = ClassUtils.getClassContext()[frames]; return ServiceUtils.doWithService(ImageLoadingService.class, caller, service -> service.load(location, caller.getClassLoader())); }
@Override public ObservableObjectValue<Image> getIcon() { return ImageLoading.load("img/org.to2mbn.lolixl.ui.download_center/icon.png"); }
@Override public ObservableObjectValue<Image> getIcon() { return ImageLoading.load("img/org.to2mbn.lolixl.settings/icon.png"); }
@Override public ObservableObjectValue<BackgroundProvider> getCurrentBackgroundProvider() { return currentBackgroundProvider; }
@Override public ObservableObjectValue<Background> getCurrentBackground() { return currentBackground; }
@Override public ObservableObjectValue<Image> getBackgroundImage() { return ImageLoading.load("img/org.to2mbn.lolixl.ui.theme.background.default/background.jpg"); }
@Override public ObservableObjectValue<Image> getIcon() { return FxConstants.object(null); }
@Override public ObservableObjectValue<Image> load(String location, ClassLoader caller) { // TODO: 使图像可以通过Theme修改 // TODO: 图像加载缓存 return FxConstants.object(ClassUtils.doWithContextClassLoader(caller, () -> new Image(location))); }
@Override public ObservableObjectValue<Image> getIcon() { // TODO Auto-generated method stub return FxConstants.object(null); }
public PncsItem(String name, int id, ObservableObjectValue<String> displayType) { this.name = name; this.id = id; this.displayType = displayType; }
public PncsItem(Pncs pncs, ObservableObjectValue<String> displayType) { this.name = pncs.getName(); this.id = pncs.getId(); this.displayType = displayType; }
protected ObservableObjectValueAssert(ObservableObjectValue<T> actual) { super(actual, ObservableObjectValueAssert.class); }
@Test public void testObservableObjectValue(){ ObservableObjectValue<TestPerson> actual = new SimpleObjectProperty<>(person); assertThat(actual).hasNotNullValue(); }
@Test public void testObservableObjectValue(){ ObservableObjectValue<TestPerson> actual = new SimpleObjectProperty<>(); assertThat(actual).hasNullValue(); }
/** * Constructor specifying the {@link CombinedGrouping} to be used when aggregating. * <p> * @param grouping the {@link CombinedGrouping} to be used when aggregating */ public TreeExtractor(ObservableObjectValue<CombinedGrouping> grouping) { super(); this.grouping = grouping; }