Java Code Examples for javafx.beans.value.ObservableValue

The following examples show how to use javafx.beans.value.ObservableValue. These examples are extracted from open source projects. 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 Project: marathonv5   Source File: RFXCheckBoxTreeCell.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String _getValue() {
    @SuppressWarnings("rawtypes")
    CheckBoxTreeCell cell = (CheckBoxTreeCell) node;
    @SuppressWarnings("unchecked")
    ObservableValue<Boolean> call = (ObservableValue<Boolean>) cell.getSelectedStateCallback().call(cell.getTreeItem());
    String cbText;
    if (call != null) {
        int selection = call.getValue() ? 2 : 0;
        cbText = JavaFXCheckBoxElement.states[selection];
    } else {
        Node cb = cell.getGraphic();
        RFXComponent comp = getFinder().findRawRComponent(cb, null, null);
        cbText = comp._getValue();
    }
    return cbText;
}
 
Example 2
Source Project: Open-Lowcode   Source File: ClientSession.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * creates the tab pane if required, and adds a tab with the client display
 * 
 * @param clientdisplay the display to show
 */
private void setupDisplay(ClientDisplay clientdisplay) {
	// initiates the tabpane if called for the first time
	if (this.tabpane == null) {
		this.tabpane = new TabPane();
		this.tabpane.setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
		this.tabpane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS);
		this.tabpane.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
			@Override
			public void changed(ObservableValue<? extends Number> ov, Number oldValue, Number newValue) {
				int index = newValue.intValue();
				activedisplayindex = index;
				logger.warning(" --> Set active display index afterselection to " + index);
			}
		});
	}
	displayTab(clientdisplay);

}
 
Example 3
@Override
public void changed(ObservableValue<? extends Document> observableValue, Document oldDoc, Document newDoc)
{
    if (newDoc == null)
    {
        return;
    }
    NodeList elements = newDoc.getElementsByTagName("input");
    for (int i = 0; i < elements.getLength(); i++)
    {
        HTMLInputElementImpl element = (HTMLInputElementImpl) elements.item(i);
        String key = getInputKey(element);
        if (key == null || key.isEmpty())
        {
            continue;
        }
        setInputValue(element, character.getPreviewSheetVar(key));
        element.addEventListener("change", evt ->
        {
            HTMLInputElement input = (HTMLInputElement) evt.getCurrentTarget();
            character.addPreviewSheetVar(getInputKey(input), getInputValue(input));
        }, false);
    }
}
 
Example 4
Source Project: pattypan   Source File: TemplateField.java    License: MIT License 6 votes vote down vote up
public TemplateField(String name, String label, boolean isSelected, String constant) {
  this.name = name;
  this.label = label;
  this.isSelected = isSelected;
  this.selection = "YES";
  this.value = constant;

  labelElement = new WikiLabel(label).setWidth(200, 500).setHeight(35);
  buttonYes.setSelected(true);

  group.selectedToggleProperty().addListener((ObservableValue<? extends Toggle> ov, Toggle tOld, Toggle tNew) -> {
    RadioButton btn = (RadioButton) tNew.getToggleGroup().getSelectedToggle();
    setSelection(btn.getId());
  });

  valueText.setOnKeyReleased((KeyEvent event) -> {
    this.value = valueText.getText();
  });
}
 
Example 5
Source Project: HealthPlus   Source File: LabAssistantController.java    License: Apache License 2.0 6 votes vote down vote up
public void addFocusListener()
{        
    labPassword.focusedProperty().addListener(new ChangeListener<Boolean>()
    {
        @Override
        public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue)
        {
            if (newPropertyValue)
            {
                System.out.println("Textfield on focus");
            }
            else
            {
                System.out.println("Textfield out focus");
            }
        }
    });
}
 
Example 6
Source Project: MyBox   Source File: GeographyCodeSelectorController.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initializeNext() {
    try {
        super.initializeNext();

        FxmlControl.setTooltip(leafCheck, message("CheckLeafNodesComments"));
        leafCheck.setSelected(AppVariables.getUserConfigBoolean("GeographyCodesTreeCheckLeafNodes", true));
        leafCheck.selectedProperty().addListener(
                (ObservableValue<? extends Boolean> ov, Boolean oldValue, Boolean newValue) -> {
                    AppVariables.setUserConfigValue("GeographyCodesTreeCheckLeafNodes", newValue);
                });

    } catch (Exception e) {
        logger.error(e.toString());
    }
}
 
Example 7
Source Project: EasyBind   Source File: EasyBind.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static <A, B, C, D, E, R> MonadicBinding<R> combine(
        ObservableValue<A> src1,
        ObservableValue<B> src2,
        ObservableValue<C> src3,
        ObservableValue<D> src4,
        ObservableValue<E> src5,
        PentaFunction<A, B, C, D, E, R> f) {
    return new PreboundBinding<R>(src1, src2, src3, src4, src5) {
        @Override
        protected R computeValue() {
            return f.apply(
                    src1.getValue(), src2.getValue(), src3.getValue(),
                    src4.getValue(), src5.getValue());
        }
    };
}
 
Example 8
Source Project: zap-extensions   Source File: BrowserPanel.java    License: Apache License 2.0 6 votes vote down vote up
private void listenToStateChangesForAdjustingPanelHeightToWebsite() {
    engine.getLoadWorker()
            .stateProperty()
            .addListener(
                    new ChangeListener<Object>() {
                        @Override
                        public void changed(
                                ObservableValue<?> observable,
                                Object oldValue,
                                Object newValue) {
                            if (State.SUCCEEDED == newValue && resizeOnLoad) {
                                resizeOnLoad = false;
                                final int height = getWebsiteHeight();
                                SwingUtilities.invokeLater(
                                        new Runnable() {
                                            @Override
                                            public void run() {
                                                setWebsiteHeight(height);
                                            }
                                        });
                            }
                        }
                    });
}
 
Example 9
Source Project: oim-fx   Source File: CachedTimelineTransition.java    License: MIT License 6 votes vote down vote up
/**
 * Create new CachedTimelineTransition
 * 
 * @param node
 *            The node that is being animated by the timeline
 * @param timeline
 *            The timeline for the animation, it should be from 0 to 1
 *            seconds
 * @param useCache
 *            When true the node is cached as image during the animation
 */
public CachedTimelineTransition(final Node node, final Timeline timeline, final boolean useCache) {
	this.node = node;
	this.timeline = timeline;
	this.useCache = useCache;
	statusProperty().addListener(new ChangeListener<Status>() {
		@Override
		public void changed(ObservableValue<? extends Status> ov, Status t, Status newStatus) {
			switch (newStatus) {
			case RUNNING:
				starting();
				break;
			default:
				stopping();
				break;
			}
		}
	});
}
 
Example 10
Source Project: oim-fx   Source File: ChatListStage.java    License: MIT License 6 votes vote down vote up
private void addItem(String key, ChatItem chatItem) {
	if (!itemVBox.getChildren().contains(chatItem)) {
		itemVBox.getChildren().add(chatItem);
		chatItem.setChooseGroup(chooseGroup);

		ChangeListener<Boolean> cl = changeListenerMap.get(key);
		if (null == cl) {
			cl = new ChangeListener<Boolean>() {

				@Override
				public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
					Node node = chatPaneMap.get(key);
					setChatPane(node);
				}
			};
			changeListenerMap.put(key, cl);
		}
		chatItem.selectedProperty().removeListener(cl);
		chatItem.selectedProperty().addListener(cl);
		chatItem.setOnCloseAction(a -> {
			remove(key);
		});
		itemMap.put(key, chatItem);
	}
}
 
Example 11
Source Project: MyBox   Source File: TextEditerController.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void initLineBreakTab() {
    try {
        super.initLineBreakTab();
        lineBreakGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
            @Override
            public void changed(ObservableValue<? extends Toggle> ov,
                    Toggle old_toggle, Toggle new_toggle) {
                checkLineBreakGroup();
            }
        });

    } catch (Exception e) {
        logger.error(e.toString());
    }
}
 
Example 12
Source Project: oim-fx   Source File: MainStage.java    License: MIT License 6 votes vote down vote up
public void addTab(Image normalImage, Image hoverImage, Image selectedImage, Node node) {
	IconToggleButton tb = new IconToggleButton(normalImage, hoverImage, selectedImage);
	tb.setUserData(node);
	tb.setToggleGroup(group);
	tb.selectedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
		if (oldValue != newValue && newValue) {
			setSelectedNode(node);
			redTab(tb, !newValue);
		}
	});
	tabBox.getChildren().add(tb);
	if (tempTb == null) {
		group.selectToggle(tb);
		tempTb = tb;
	}
	group.selectedToggleProperty().removeListener(listener);
	group.selectedToggleProperty().addListener(listener);
	// group.selectedToggleProperty().addListener((ObservableValue<? extends
	// Toggle> observable, Toggle oldValue, Toggle newValue) -> {
	//
	// if (newValue == null) {
	// group.selectToggle(oldValue);
	// }
	// System.out.println("addTab");
	// });
}
 
Example 13
Source Project: oim-fx   Source File: ChatWritePane.java    License: MIT License 6 votes vote down vote up
private void iniEvent() {
	webView.setOnInputMethodTextChanged(new EventHandler<InputMethodEvent>() {

		@Override
		public void handle(InputMethodEvent e) {
			processInputMethodEvent(e);
		}
	});
	webView.setOnDragDropped(a -> {

	});

	webEngine.getLoadWorker().stateProperty().addListener((ObservableValue<? extends State> ov, State oldState, State newState) -> {

		if (newState == State.SUCCEEDED) {
			initWeb(webEngine);
		}
	});

	webView.addEventHandler(KeyEvent.ANY,
			event -> {
			});

}
 
Example 14
Source Project: latexdraw   Source File: ViewArrow.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void createArc(final double cx, final double cy, final double rx, final double ry, final double angle, final double length,
					final ObservableValue<Color> strokeProp, final ObservableDoubleValue strokeWidthProp) {
	arc.setCenterX(cx);
	arc.setCenterY(cy);
	arc.setRadiusX(rx);
	arc.setRadiusY(ry);
	arc.setStartAngle(angle);
	arc.setLength(length);
	arc.strokeProperty().unbind();
	arc.strokeProperty().bind(strokeProp);
	arc.strokeWidthProperty().unbind();
	arc.strokeWidthProperty().bind(strokeWidthProp);
	arc.setFill(null);
	enableShape(false, true, false);
}
 
Example 15
Source Project: CodenameOne   Source File: CN1CSSCLI.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static void startImpl(Stage stage) throws Exception {
    System.out.println("Opening JavaFX Webview to render some CSS styles");
    web = new WebView();
    web.getEngine().getLoadWorker().exceptionProperty().addListener(new ChangeListener<Throwable>() {
        @Override
        public void changed(ObservableValue<? extends Throwable> ov, Throwable t, Throwable t1) {
            System.out.println("Received exception: "+t1.getMessage());
        }
    });
    
    Scene scene = new Scene(web, 400, 800, Color.web("#666670"));
    stage.setScene(scene);
    stage.show();
    synchronized(lock) {
        lock.notify();
    }
}
 
Example 16
Source Project: jmonkeybuilder   Source File: PaintingComponentContainer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Activate the selected painting component.
 *
 * @param observable the component box's property.
 * @param oldValue   the previous component.
 * @param newValue   the new component.
 */
@FxThread
private void activate(
        @NotNull ObservableValue<? extends PaintingComponent> observable,
        @Nullable PaintingComponent oldValue,
        @Nullable PaintingComponent newValue
) {

    var items = getContainer().getChildren();

    if (oldValue != null) {
        oldValue.notifyHided();
        oldValue.stopPainting();
        items.remove(oldValue);
    }

    var paintedObject = getPaintedObject();

    if (newValue != null) {

        if (paintedObject != null) {
            newValue.startPainting(paintedObject);
        }

        if (isShowed()) {
            newValue.notifyShowed();
        }

        items.add((Node) newValue);
    }

    setCurrentComponent(newValue);
}
 
Example 17
Source Project: EasyBind   Source File: EasyBind.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <A, B, C, D, R> MonadicBinding<R> combine(
        ObservableValue<A> src1,
        ObservableValue<B> src2,
        ObservableValue<C> src3,
        ObservableValue<D> src4,
        TetraFunction<A, B, C, D, R> f) {
    return new PreboundBinding<R>(src1, src2, src3, src4) {
        @Override
        protected R computeValue() {
            return f.apply(
                    src1.getValue(), src2.getValue(),
                    src3.getValue(), src4.getValue());
        }
    };
}
 
Example 18
Source Project: mars-sim   Source File: Story.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** @return content wrapped in a vertical, pannable scroll pane. */
private ScrollPane makeScrollable(final Control content) {
  final ScrollPane scroll = new ScrollPane();
  scroll.setContent(content);
  scroll.setPannable(true);
  scroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
  scroll.viewportBoundsProperty().addListener(new ChangeListener<Bounds>() {
    @Override public void changed(ObservableValue<? extends Bounds> observableValue, Bounds oldBounds, Bounds newBounds) {
      content.setPrefWidth(newBounds.getWidth() - 10);
    }
  });

  return scroll;
}
 
Example 19
public void fixedTableHeader(TableView table){
    table.widthProperty().addListener((ObservableValue
            <? extends Number> source, Number oldWidth, Number newWidth) -> {
        TableHeaderRow header = (TableHeaderRow) table.lookup("TableHeaderRow");
        header.reorderingProperty().addListener((ObservableValue
                <? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
            header.setReordering(false);
        });
    });
}
 
Example 20
Source Project: marathonv5   Source File: TooltipSample.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Tooltip Sample");
    stage.setWidth(330);
    stage.setHeight(150);

    total.setFont(new Font("Arial", 20));

    for (int i = 0; i < rooms.length; i++) {
        final CheckBox cb = cbs[i] = new CheckBox(rooms[i]);
        final Integer rate = rates[i];
        final Tooltip tooltip = new Tooltip("$" + rates[i].toString());
        tooltip.setFont(new Font("Arial", 16));
        cb.setTooltip(tooltip);
        cb.selectedProperty().addListener((ObservableValue<? extends Boolean> ov, Boolean old_val, Boolean new_val) -> {
            if (cb.isSelected()) {
                sum = sum + rate;
            } else {
                sum = sum - rate;
            }
            total.setText("Total: $" + sum.toString());
        });
    }

    VBox vbox = new VBox();
    vbox.getChildren().addAll(cbs);
    vbox.setSpacing(5);
    HBox root = new HBox();
    root.getChildren().add(vbox);
    root.getChildren().add(total);
    root.setSpacing(40);
    root.setPadding(new Insets(20, 10, 10, 20));

    ((Group) scene.getRoot()).getChildren().add(root);

    stage.setScene(scene);
    stage.show();
}
 
Example 21
Source Project: marathonv5   Source File: TableCellFactorySample.java    License: Apache License 2.0 5 votes vote down vote up
private Person(boolean invited, String fName, String lName, String email) {
    this.invited = new SimpleBooleanProperty(invited);
    this.firstName = new SimpleStringProperty(fName);
    this.lastName = new SimpleStringProperty(lName);
    this.email = new SimpleStringProperty(email);
    this.invited = new SimpleBooleanProperty(invited);
    
    this.invited.addListener(new ChangeListener<Boolean>() {
        public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
            System.out.println(firstNameProperty().get() + " invited: " + t1);
        }
    });            
}
 
Example 22
@Override
public void changed(ObservableValue<? extends Boolean> observable,
		Boolean oldValue, Boolean newValue) {
	if (newValue.booleanValue()) {
		register();
	} else {
		unregister();
	}
}
 
Example 23
private void selectionChanged(final ObservableValue<? extends Toggle> obs, final Toggle oldval, final Toggle newval)
{
    if (!active  &&  newval != null)
    {
        active = true;
        try
        {
            // For now reset to old value.
            // New value will be shown if the PV accepts it and sends a value update.
            toggle.selectToggle(oldval);

            if (enabled)
            {
                final Object value;
                final VType pv_value = model_widget.runtimePropValue().getValue();
                if (pv_value instanceof VEnum  ||  pv_value instanceof VNumber)
                    // PV uses enumerated or numeric type, so write the index
                    value = toggle.getToggles().indexOf(newval);
                else // PV uses text
                    value = FormatOptionHandler.parse(pv_value,
                                                      ((ButtonBase) newval).getText(),
                                                      FormatOption.DEFAULT);
                logger.log(Level.FINE, "Writing " + value);
                Platform.runLater(() -> confirm(value));
            }
        }
        finally
        {
            active = false;
        }
    }
}
 
Example 24
Source Project: gef   Source File: GeometryNode.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void changed(ObservableValue<? extends Number> observable,
		Number oldValue, Number newValue) {
	listeningCount--;
	geometryProperty.removeListener(geometryChangeListener);
	relocateGeometryToMatchLayoutXY(getLayoutX(),
			newValue.doubleValue());
	geometryProperty.addListener(geometryChangeListener);
	listeningCount++;
}
 
Example 25
Source Project: MyBox   Source File: ImageViewerController.java    License: Apache License 2.0 5 votes vote down vote up
protected void initOperationBox() {
    if (imageView != null) {
        if (operationBox != null) {
            operationBox.disableProperty().bind(Bindings.isNull(imageView.imageProperty()));
        }
        if (leftPaneControl != null) {
            leftPaneControl.visibleProperty().bind(Bindings.isNotNull(imageView.imageProperty()));
        }
        if (rightPaneControl != null) {
            rightPaneControl.visibleProperty().bind(Bindings.isNotNull(imageView.imageProperty()));
        }
    }

    if (selectAreaCheck != null) {
        selectAreaCheck.selectedProperty().addListener(new ChangeListener<Boolean>() {
            @Override
            public void changed(ObservableValue ov, Boolean oldValue, Boolean newValue) {
                AppVariables.setUserConfigValue("ImageSelect", selectAreaCheck.isSelected());
                checkSelect();
            }
        });
        selectAreaCheck.setSelected(AppVariables.getUserConfigBoolean("ImageSelect", false));
        checkSelect();
        FxmlControl.setTooltip(selectAreaCheck, new Tooltip("CTRL+t"));
    }

}
 
Example 26
Source Project: JFoenix   Source File: JFXTreeTableColumn.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param param tree item
 * @return the data represented by the tree item
 */
public final ObservableValue<T> getComputedValue(CellDataFeatures<S, T> param) {
    Object rowObject = param.getValue().getValue();
    if (rowObject instanceof RecursiveTreeObject) {
        RecursiveTreeObject<?> item = (RecursiveTreeObject<?>) rowObject;
        if (item.getGroupedColumn() == this) {
            return new ReadOnlyObjectWrapper(item.getGroupedValue());
        }
    }
    return null;
}
 
Example 27
private void setValueFactory() {
	setCellValueFactory(new Callback<CellDataFeatures<CObjectGridLine<E>, E>, ObservableValue<E>>() {

		@Override
		public ObservableValue<E> call(javafx.scene.control.TableColumn.CellDataFeatures<CObjectGridLine<E>, E> p) {
			CObjectGridLine<E> line = p.getValue();
			return new SimpleObjectProperty<E>(line.getLabelObject());

		}

	});
}
 
Example 28
Source Project: gef   Source File: GeometryNode.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void changed(ObservableValue<? extends Number> observable,
		Number oldValue, Number newValue) {
	listeningCount--;
	geometryProperty.removeListener(geometryChangeListener);
	resizeGeometryToMatchLayoutBoundsSize(getWidth(),
			newValue.doubleValue());
	geometryProperty.addListener(geometryChangeListener);
	listeningCount++;
}
 
Example 29
private void setNumberTextField(TextField txt) {
    txt.textProperty().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
        if (!newValue.matches("\\d*")) {
            txt.setText(newValue.replaceAll("[^\\d]", ""));
        }
    });
}
 
Example 30
public ObservableValue<JFXTableCellValue<T>> call(CellDataFeatures<UITableItem<T>, JFXTableCellValue<T>> cdf) {
int index = cdf.getTableView().getColumns().indexOf(cdf.getTableColumn());
if( index >= 0 ) {
	return new ReadOnlyObjectWrapper<JFXTableCellValue<T>>(this.findOrCreateCell(cdf.getValue(), index));
}
      return new ReadOnlyObjectWrapper<JFXTableCellValue<T>>(null);
  }