Java Code Examples for javafx.beans.property.BooleanProperty#set()
The following examples show how to use
javafx.beans.property.BooleanProperty#set() .
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: WebViewHyperlinkListenerDemo.java From mars-sim with GNU General Public License v3.0 | 6 votes |
/** * Attaches/detaches the specified listener to/from the specified web view according to the specified property's * value. * * @param webView * the {@link WebView} to which the listener will be added * @param listener * the added listener * @param attachedProperty * defines whether the listener is attached or not */ private static void manageListener(WebView webView, WebViewHyperlinkListener listener, BooleanProperty attachedProperty) { attachedProperty.set(true); ListenerHandle listenerHandle = WebViews.addHyperlinkListener(webView, listener); attachedProperty.addListener((obs, wasAttached, isAttached) -> { if (isAttached) { listenerHandle.attach(); System.out.println("LISTENER: attached."); } else { listenerHandle.detach(); System.out.println("LISTENER: detached."); } }); }
Example 2
Source File: FXBinderTest.java From dolphin-platform with Apache License 2.0 | 6 votes |
@Test public void testJavaFXBooleanBidirectional() { Property<Boolean> booleanDolphinProperty = new MockedProperty<>(); BooleanProperty booleanJavaFXProperty = new SimpleBooleanProperty(); booleanDolphinProperty.set(true); assertNotEquals(booleanJavaFXProperty.get(), true); Binding binding = FXBinder.bind(booleanJavaFXProperty).bidirectionalTo(booleanDolphinProperty); assertEquals(booleanJavaFXProperty.get(), true); booleanDolphinProperty.set(false); assertEquals(booleanJavaFXProperty.get(), false); booleanDolphinProperty.set(null); assertEquals(booleanJavaFXProperty.get(), false); booleanJavaFXProperty.set(true); assertEquals(booleanDolphinProperty.get().booleanValue(), true); booleanJavaFXProperty.setValue(null); assertEquals(booleanDolphinProperty.get().booleanValue(), false); binding.unbind(); booleanDolphinProperty.set(true); assertEquals(booleanJavaFXProperty.get(), false); }
Example 3
Source File: SessionManager.java From mokka7 with Eclipse Public License 1.0 | 5 votes |
public void bind(final BooleanProperty property, final String propertyName) { String value = props.getProperty(propertyName); if (value != null) { property.set(Boolean.valueOf(value)); } property.addListener(new InvalidationListener() { @Override public void invalidated(Observable o) { props.setProperty(propertyName, property.getValue().toString()); } }); }
Example 4
Source File: MainWindow.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 5 votes |
/** * Creates a boolean property that is bound to another boolean value * of the active editor's SmartEdit. */ private BooleanProperty createActiveEditBooleanProperty(Function<SmartEdit, ObservableBooleanValue> func) { BooleanProperty b = new SimpleBooleanProperty() { @Override public void set(boolean newValue) { // invoked when the user invokes an action // do not try to change SmartEdit properties because this // would throw a "bound value cannot be set" exception } }; ChangeListener<? super FileEditor> listener = (observable, oldFileEditor, newFileEditor) -> { b.unbind(); if (newFileEditor != null) { if (newFileEditor.getEditor() != null) b.bind(func.apply(newFileEditor.getEditor().getSmartEdit())); else { newFileEditor.editorProperty().addListener((ob, o, n) -> { b.bind(func.apply(n.getSmartEdit())); }); } } else b.set(false); }; FileEditor fileEditor = fileEditorTabPane.getActiveFileEditor(); listener.changed(null, null, fileEditor); fileEditorTabPane.activeFileEditorProperty().addListener(listener); return b; }
Example 5
Source File: FXBinderTest.java From dolphin-platform with Apache License 2.0 | 5 votes |
@Test public void testJavaFXBooleanBidirectionalWithConverter() { Property<String> stringDolphinProperty = new MockedProperty<>(); BooleanProperty booleanJavaFXProperty = new SimpleBooleanProperty(); Converter<Boolean, String> booleanStringConverter = b -> b == null ? null : b.toString(); Converter<String, Boolean> stringBooleanConverter = s -> s == null ? null : Boolean.parseBoolean(s); BidirectionalConverter<Boolean, String> booleanStringBidirectionalConverter = new DefaultBidirectionalConverter<>(booleanStringConverter, stringBooleanConverter); stringDolphinProperty.set("true"); assertNotEquals(booleanJavaFXProperty.get(), true); Binding binding = FXBinder.bind(booleanJavaFXProperty).bidirectionalTo(stringDolphinProperty, booleanStringBidirectionalConverter.invert()); assertEquals(booleanJavaFXProperty.get(), true); stringDolphinProperty.set("false"); assertEquals(booleanJavaFXProperty.get(), false); stringDolphinProperty.set(null); assertEquals(booleanJavaFXProperty.get(), false); booleanJavaFXProperty.set(true); assertEquals(stringDolphinProperty.get(), "true"); booleanJavaFXProperty.setValue(null); assertEquals(stringDolphinProperty.get(), "false"); binding.unbind(); stringDolphinProperty.set("true"); assertEquals(booleanJavaFXProperty.get(), false); }
Example 6
Source File: SessionContext.java From jfxvnc with Apache License 2.0 | 5 votes |
public void bind(final BooleanProperty property, final String propertyName) { String value = props.getProperty(propertyName); if (value != null) { property.set(Boolean.valueOf(value)); } property.addListener(o -> { props.setProperty(propertyName, property.getValue().toString()); }); }
Example 7
Source File: TorNetworkNode.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
private BooleanProperty torNetworkNodeShutDown() { final BooleanProperty done = new SimpleBooleanProperty(); if (executorService != null) { executorService.submit(() -> { Utilities.setThreadName("torNetworkNodeShutDown"); long ts = System.currentTimeMillis(); log.debug("Shutdown torNetworkNode"); try { /** * make sure we get tor. * - there have been situations where <code>tor</code> isn't set yet, which would leave tor running * - downside is that if tor is not already started, we start it here just to shut it down. However, * that can only be the case if Bisq gets shutdown even before it reaches step 2/4 at startup. * The risk seems worth it compared to the risk of not shutting down tor. */ tor = Tor.getDefault(); if (tor != null) tor.shutdown(); log.debug("Shutdown torNetworkNode done after " + (System.currentTimeMillis() - ts) + " ms."); } catch (Throwable e) { log.error("Shutdown torNetworkNode failed with exception: " + e.getMessage()); e.printStackTrace(); } finally { UserThread.execute(() -> done.set(true)); } }); } else { done.set(true); } return done; }
Example 8
Source File: PrefBind.java From erlyberly with GNU General Public License v3.0 | 5 votes |
public static void bindBoolean(final String propName, BooleanProperty boolProp){ if(props == null) { return; } Boolean storedValue = (Boolean) props.get(propName); if(storedValue != null) { boolProp.set(storedValue); } boolProp.addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { set(propName, newValue); }); }
Example 9
Source File: ConditionalBindingTest.java From EasyBind with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void test() { Property<String> target = new SimpleStringProperty(); Property<String> source = new SimpleStringProperty("1"); BooleanProperty condition = new SimpleBooleanProperty(true); Subscription sub = EasyBind.bindConditionally(target, source, condition); assertTrue(target.isBound()); assertEquals("1", target.getValue()); source.setValue("2"); assertEquals("2", target.getValue()); condition.set(false); assertFalse(target.isBound()); source.setValue("3"); assertEquals("2", target.getValue()); condition.set(true); assertTrue(target.isBound()); assertEquals("3", target.getValue()); sub.unsubscribe(); assertFalse(target.isBound()); condition.set(false); condition.set(true); assertFalse(target.isBound()); source.setValue("4"); assertEquals("3", target.getValue()); target.bind(source); sub.unsubscribe(); assertTrue(target.isBound()); }
Example 10
Source File: WhenTest.java From EasyBind with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testPropertyBind() { Property<String> target = new SimpleStringProperty(); Property<String> source = new SimpleStringProperty("1"); BooleanProperty condition = new SimpleBooleanProperty(true); Subscription sub = EasyBind.when(condition).bind(target, source); assertTrue(target.isBound()); assertEquals("1", target.getValue()); source.setValue("2"); assertEquals("2", target.getValue()); condition.set(false); assertFalse(target.isBound()); source.setValue("3"); assertEquals("2", target.getValue()); condition.set(true); assertTrue(target.isBound()); assertEquals("3", target.getValue()); sub.unsubscribe(); assertFalse(target.isBound()); condition.set(false); condition.set(true); assertFalse(target.isBound()); source.setValue("4"); assertEquals("3", target.getValue()); target.bind(source); sub.unsubscribe(); assertTrue(target.isBound()); }
Example 11
Source File: SuspendedWhenTest.java From ReactFX with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void test() { Property<Integer> p = new SimpleObjectProperty<>(0); BooleanProperty suspended = new SimpleBooleanProperty(true); List<Integer> emitted = new ArrayList<>(); SuspendableEventStream<Integer> pausable = EventStreams.valuesOf(p).pausable(); Subscription sub = pausable.suspendedWhen(suspended).subscribe(emitted::add); // test that the stream started suspended assertEquals(Arrays.asList(), emitted); suspended.set(false); assertEquals(Arrays.asList(0), emitted); p.setValue(1); assertEquals(Arrays.asList(0, 1), emitted); suspended.set(true); p.setValue(2); p.setValue(3); p.setValue(4); assertEquals(Arrays.asList(0, 1), emitted); List<Integer> emitted2 = new ArrayList<>(); pausable.subscribe(emitted2::add); assertEquals(Arrays.asList(), emitted2); suspended.set(false); assertEquals(Arrays.asList(0, 1, 2, 3, 4), emitted); assertEquals(Arrays.asList(2, 3, 4), emitted2); suspended.set(true); p.setValue(5); p.setValue(6); assertEquals(Arrays.asList(2, 3, 4), emitted2); sub.unsubscribe(); // testing resume on unsubscribe assertEquals(Arrays.asList(0, 1, 2, 3, 4), emitted); assertEquals(Arrays.asList(2, 3, 4, 5, 6), emitted2); }
Example 12
Source File: TorNetworkNode.java From bisq with GNU Affero General Public License v3.0 | 4 votes |
private BooleanProperty networkNodeShutDown() { final BooleanProperty done = new SimpleBooleanProperty(); super.shutDown(() -> done.set(true)); return done; }
Example 13
Source File: IncludeWhenTest.java From EasyBind with BSD 2-Clause "Simplified" License | 4 votes |
@Test public void test() { ObservableList<String> list = FXCollections.observableArrayList("a", "b"); BooleanProperty condC = new SimpleBooleanProperty(false); BooleanProperty condD = new SimpleBooleanProperty(true); Subscription subC = EasyBind.includeWhen(list, "c", condC); Subscription subD = EasyBind.includeWhen(list, "d", condD); assertEquals(Arrays.asList("a", "b", "d"), list); list.add("c"); assertEquals(Arrays.asList("a", "b", "d", "c"), list); condC.set(true); assertEquals(Arrays.asList("a", "b", "d", "c", "c"), list); condC.set(false); assertEquals(Arrays.asList("a", "b", "d", "c"), list); list.remove("c"); assertEquals(Arrays.asList("a", "b", "d"), list); condC.set(true); assertEquals(Arrays.asList("a", "b", "d", "c"), list); list.add("c"); assertEquals(Arrays.asList("a", "b", "d", "c", "c"), list); condC.set(false); assertEquals(Arrays.asList("a", "b", "d", "c"), list); subC.unsubscribe(); list.remove("c"); condC.set(true); assertEquals(Arrays.asList("a", "b", "d"), list); subD.unsubscribe(); condD.set(false); assertEquals(Arrays.asList("a", "b", "d"), list); }