javafx.beans.Observable Java Examples

The following examples show how to use javafx.beans.Observable. 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: IconsListElementSkin.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates a region with the miniature of the list element
 *
 * @return A region with the miniature of the list element
 */
private Region createMiniature() {
    final Region miniature = new Region();
    miniature.getStyleClass().add("iconListMiniatureImage");
    miniature.styleProperty().bind(
            Bindings.createStringBinding(
                    () -> String.format("-fx-background-image: url(\"%s\");",
                            getControl().getMiniatureUri().toString()),
                    getControl().miniatureUriProperty()));

    final Tooltip tooltip = new Tooltip();
    tooltip.textProperty().bind(getControl().titleProperty());

    Tooltip.install(miniature, tooltip);

    // set a gray filter for this element if it is not enabled
    getControl().enabledProperty().addListener((Observable invalidation) -> updateEnabled(miniature));
    // adopt the enable status during initialisation
    updateEnabled(miniature);

    return miniature;
}
 
Example #2
Source File: NoticeFrame.java    From oim-fx with MIT License 6 votes vote down vote up
private void initComponent() {
	this.setTitle("消息通知");
	this.setResizable(false);
	this.setWidth(550);
	this.setHeight(480);
	this.setTitlePaneStyle(2);
	this.setRadius(5);
	BorderPane rootPane = new BorderPane();
	this.setCenter(rootPane);

	scrollPane.setBackground(Background.EMPTY);
	scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
	scrollPane.setContent(box);
	scrollPane.widthProperty().addListener((Observable observable) -> {
		box.setPrefWidth(scrollPane.getWidth());
	});

	box.setMaxWidth(550);
	box.setSpacing(10);
	box.setPadding(new Insets(5, 20, 5, 10));

	centerPane.getChildren().add(scrollPane);

	rootPane.setCenter(centerPane);
	rootPane.setBottom(page);
}
 
Example #3
Source File: MultipleAxesLineChart.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
public MultipleAxesLineChart(final LineChart<?, ?> baseChart, final Color lineColor, final Double strokeWidth) {
    if (strokeWidth != null) {
        this.strokeWidth = strokeWidth;
    }
    this.baseChart = baseChart;

    chartColorMap.put(baseChart, lineColor);

    styleBaseChart(baseChart);
    styleChartLine(baseChart, lineColor);
    setFixedAxisWidth(baseChart);

    setAlignment(Pos.CENTER_LEFT);

    backgroundCharts.addListener((final Observable observable) -> rebuildChart());

    detailsWindow = new AnchorPane();
    bindMouseEvents(baseChart, this.strokeWidth);

    rebuildChart();
}
 
Example #4
Source File: IOSVideoService.java    From attach with GNU General Public License v3.0 6 votes vote down vote up
public IOSVideoService() {
    super();
    
    playlist.addListener((Observable o) -> {
        List<String> list = new ArrayList<>();
        for (String s : playlist) {
            if (checkFileInResources(s)) {
                File videoFile = getFileFromAssets(s);
                list.add(videoFile.getAbsolutePath());
            } else {
                list.add(s);
            }
        }
        setVideoPlaylist(list.toArray(new String[0]));
    });
    
    FULL_SCREEN.addListener((obs, ov, nv) -> setFullScreenMode(nv));
    CURRENT_INDEX.addListener((obs, ov, nv) -> currentIndex(nv.intValue()));
}
 
Example #5
Source File: CollectionBindings.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Maps an {@link ObservableValue<I>} object to an {@link ObservableMap} by applying the given converter function
 * and adding the result to the {@link ObservableMap}.
 * In case the input value is empty, i.e. contains <code>null</code>, the returned {@link ObservableMap} is also
 * empty
 *
 * @param property The input value
 * @param converter The converter function
 * @param <I> The type of the input value
 * @param <O1> The input type of the result map
 * @param <O2> The output type of the result map
 * @return A {@link ObservableMap} containing the converted map
 */
public static <I, O1, O2> ObservableMap<O1, O2> mapToMap(ObservableValue<I> property,
        Function<I, Map<O1, O2>> converter) {
    final ObservableMap<O1, O2> result = FXCollections.observableHashMap();

    final InvalidationListener listener = (Observable invalidation) -> {
        final I input = property.getValue();

        result.clear();

        if (input != null) {
            result.putAll(converter.apply(input));
        }
    };

    // add the listener to the property
    property.addListener(listener);

    // ensure that the result map is initialised correctly
    listener.invalidated(property);

    return result;
}
 
Example #6
Source File: SidebarGroupSkin.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialise() {
    final Label title = createTitleLabel();

    // ensure that the title label is only shown when it contains a nonempty string
    title.textProperty().addListener((Observable invalidation) -> updateTitleLabelVisibility(title));
    // ensure that the title label is correctly shown during initialisation
    updateTitleLabelVisibility(title);

    VBox container = new VBox();
    container.getStyleClass().add("sidebarInside");

    Bindings.bindContent(container.getChildren(), components);

    getChildren().addAll(container);
}
 
Example #7
Source File: NumberField.java    From trex-stateless-gui with Apache License 2.0 6 votes vote down vote up
private void handleValueChanged(final Observable observable, final Number oldValue, final Number newValue) {
    final double value = newValue.doubleValue();

    if (minValue == null || maxValue == null || minValue < maxValue) {
        if (minValue != null && value < minValue) {
            setValue(minValue);
            return;
        }
        if (maxValue != null && value > maxValue) {
            setValue(maxValue);
            return;
        }
    } else {
        LOG.error("Min value should to be less then max value");
    }

    if (!isSkipSetText) {
        setTextInner(convertValueToText(value, isFocused()));
    }

    setTooltip(new Tooltip(String.valueOf(valueProperty.get())));
}
 
Example #8
Source File: IconsListElementSkin.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialise() {
    final VBox container = new VBox(createMiniature(), createLabel());
    container.getStyleClass().add("iconListElement");

    container.widthProperty().addListener((observable, oldValue, newValue) -> container
            .setClip(new Rectangle(container.getWidth(), container.getHeight())));

    container.heightProperty().addListener((observable, oldValue, newValue) -> container
            .setClip(new Rectangle(container.getWidth(), container.getHeight())));

    // update the selected pseudo class according to the selected state of the component
    getControl().selectedProperty().addListener((Observable invalidation) -> container
            .pseudoClassStateChanged(SELECTED_PSEUDO_CLASS, getControl().isSelected()));
    // adopt the selected state during initialisation
    container.pseudoClassStateChanged(SELECTED_PSEUDO_CLASS, getControl().isSelected());

    getChildren().addAll(container);
}
 
Example #9
Source File: ShortcutEditingPanelSkin.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new {@link GridPane} containing the properties of the selected shortcut
 *
 * @return a new {@link GridPane} containing the properties of the selected shortcut
 */
private GridPane createPropertiesGrid() {
    final GridPane propertiesGrid = new GridPane();
    propertiesGrid.getStyleClass().add("grid");

    ColumnConstraints titleColumn = new ColumnConstraintsWithPercentage(30);
    ColumnConstraints valueColumn = new ColumnConstraintsWithPercentage(70);

    propertiesGrid.getColumnConstraints().addAll(titleColumn, valueColumn);

    // ensure that changes to the shortcutProperties map result in updates to the GridPane
    shortcutProperties.addListener((Observable invalidation) -> updateProperties(propertiesGrid));
    // initialize the properties grid correctly
    updateProperties(propertiesGrid);

    return propertiesGrid;
}
 
Example #10
Source File: HighlightingStreamConverter.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void invalidated(final Observable observable)
{
	final Map<Long, Color> map                       = new HashMap<>();
	final TLongIntMap      explicitlySpecifiedColors = stream.getExplicitlySpecifiedColorsCopy();
	explicitlySpecifiedColors.forEachEntry((k, v) -> {
		map.put(k, Colors.toColor(new ARGBType(v)));
		return true;
	});
	LOG.debug("internal map={} updated map={}", userSpecifiedColors, map);
	if (!userSpecifiedColors.equals(map))
	{
		userSpecifiedColors.clear();
		userSpecifiedColors.putAll(map);
	}
}
 
Example #11
Source File: StringTable.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Listener to table selection */
private void selectionChanged(final Observable what)
{
    final StringTableListener copy = listener;
    if (copy == null)
        return;

    @SuppressWarnings("rawtypes")
    final ObservableList<TablePosition> cells = table.getSelectionModel().getSelectedCells();
    int num = cells.size();
    // Don't select the magic last row
    if (num > 0  &&  data.get(cells.get(num-1).getRow()) == MAGIC_LAST_ROW)
        --num;
    final int[] rows = new int[num], cols = new int[num];
    for (int i=0; i<num; ++i)
    {
        rows[i] = cells.get(i).getRow();
        cols[i] = cells.get(i).getColumn();
    }
    copy.selectionChanged(this, rows, cols);
}
 
Example #12
Source File: SpriteView.java    From quantumjava with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Lamb(SpriteView following) {
    super(LAMB, following);
    direction.addListener(directionListener);
    directionListener.changed(direction, direction.getValue(), direction.getValue());
    startValueAnimation();
    valueProperty.addListener(new InvalidationListener() {
        @Override
        public void invalidated(Observable observable) {
            double value = valueProperty.get();
            if (value > .5){
                imageView.setEffect(new InnerShadow(150, Color.BLACK));
            } else {
                imageView.setEffect(null);
            }
        }
    });
}
 
Example #13
Source File: NodePropertiesSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private RadioButton createRadioButton(final Node rect, String name, final boolean toFront, ToggleGroup tg) {
    final RadioButton radioButton = new RadioButton(name);
    radioButton.setToggleGroup(tg);
    radioButton.selectedProperty().addListener(new InvalidationListener() {
        public void invalidated(Observable ov) {
            if (radioButton.isSelected()) {
                if (toFront) {
                    rect.toFront();
                } else {
                    rect.toBack();
                }
            }
        }
    });

    return radioButton;
}
 
Example #14
Source File: NodePropertiesSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private RadioButton createRadioButton(final Node rect, String name, final boolean toFront, ToggleGroup tg) {
    final RadioButton radioButton = new RadioButton(name);
    radioButton.setToggleGroup(tg);
    radioButton.selectedProperty().addListener(new InvalidationListener() {
        public void invalidated(Observable ov) {
            if (radioButton.isSelected()) {
                if (toFront) {
                    rect.toFront();
                } else {
                    rect.toBack();
                }
            }
        }
    });

    return radioButton;
}
 
Example #15
Source File: SessionManager.java    From mokka7 with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void bind(final ObjectProperty<?> property, final String propertyName, Class<?> type) {
    String value = props.getProperty(propertyName);
    if (value != null) {
        if (type.getName().equals(Color.class.getName())) {
            ((ObjectProperty<Color>) property).set(Color.valueOf(value));
        } else if (type.getName().equals(String.class.getName())) {
            ((ObjectProperty<String>) property).set(value);
        } else {
            ((ObjectProperty<Object>) property).set(value);
        }
    }
    property.addListener(new InvalidationListener() {

        @Override
        public void invalidated(Observable o) {
            props.setProperty(propertyName, property.getValue().toString());
        }
    });
}
 
Example #16
Source File: NumberField.java    From trex-stateless-gui with Apache License 2.0 5 votes vote down vote up
private void handleFocusChanged(final Observable observable, final boolean oldValue, final boolean newValue) {
    final String text = getText();
    if (newValue) {
        setTextInner(convertValueToText(valueProperty.get(), false));
    } else if (text == null || text.equals("")) {
        setTextInner(String.valueOf(valueProperty.get()));
    } else {
        setTextInner(convertValueToText(valueProperty.get(), true));
    }
}
 
Example #17
Source File: SetMultimapPropertyBase.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void invalidated(Observable observable) {
	SetMultimapPropertyBase<K, V> setMultimapProperty = setMultimapPropertyRef
			.get();
	if (setMultimapProperty == null) {
		observable.removeListener(this);
	} else {
		setMultimapProperty.markInvalid(setMultimapProperty.value);
	}
}
 
Example #18
Source File: EnginesView.java    From phoenicis with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * constructor
 *
 * @param themeManager
 * @param enginesPath
 * @param javaFxSettingsManager
 */
public EnginesView(ThemeManager themeManager, String enginesPath, JavaFxSettingsManager javaFxSettingsManager) {
    super(tr("Engines"), themeManager);

    this.enginesPath = enginesPath;
    this.javaFxSettingsManager = javaFxSettingsManager;

    this.filter = new EnginesFilter(enginesPath);
    this.engines = new HashMap<>();
    this.engineCategories = FXCollections.observableArrayList();

    this.selectedListWidget = new SimpleObjectProperty<>();
    this.engineDTO = new SimpleObjectProperty<>();
    this.engine = new SimpleObjectProperty<>();

    this.filter.selectedEngineCategoryProperty().addListener((Observable invalidation) -> {
        final EngineCategoryDTO engineCategory = this.filter.getSelectedEngineCategory();

        if (engineCategory != null) {
            Optional.ofNullable(onSelectEngineCategory).ifPresent(listener -> listener.accept(engineCategory));
        }
    });

    final EngineSidebar engineSidebar = createEngineSidebar();

    setSidebar(engineSidebar);

    this.engineDetailsPanel = createEngineDetailsPanel();

    this.engineSubCategoryTabs = createEngineSubCategoryTabs(engineSidebar);

    this.availableEngines = createEngineVersion();
}
 
Example #19
Source File: MapTile.java    From maps with GNU General Public License v3.0 5 votes vote down vote up
private InvalidationListener createProgressListener(MapTile child) {
    return new InvalidationListener() {
        @Override
        public void invalidated(Observable o) {
            if (child.progress.get() >= 1.0d) {
                MapTile.this.coveredTiles.remove(child);
                child.progress.removeListener(this);
            }
        }
    };
}
 
Example #20
Source File: MainController.java    From neural-style-gui with GNU General Public License v3.0 5 votes vote down vote up
private void setupObservableLists() {
    styleImages = FXCollections.observableArrayList(neuralImage ->
            new Observable[] {neuralImage.selectedProperty(), neuralImage.weightProperty(),
                    styleMultipleSelect.selectedProperty()});
    contentImages = FXCollections.observableArrayList(neuralImage ->
            new Observable[] {neuralImage.selectedProperty()});
    gpuIndices = FXCollections.observableArrayList(gpuIndex ->
            new Observable[] {gpuIndex.valueProperty()});
    styleLayers = FXCollections.observableArrayList(neuralLayer ->
            new Observable[] {neuralLayer.valueProperty(), neuralLayer.nameProperty()});
    contentLayers = FXCollections.observableArrayList(neuralLayer ->
            new Observable[] {neuralLayer.valueProperty(), neuralLayer.nameProperty()});

    setDefaultNeuralBooleans();
}
 
Example #21
Source File: MultisetPropertyBase.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void invalidated(Observable observable) {
	MultisetPropertyBase<E> multisetProperty = multisetPropertyRef
			.get();
	if (multisetProperty == null) {
		observable.removeListener(this);
	} else {
		multisetProperty.markInvalid(multisetProperty.value);
	}
}
 
Example #22
Source File: DefaultTreeCell.java    From standalone-app with Apache License 2.0 5 votes vote down vote up
@Override
public void invalidated(Observable observable) {
    TreeItem<T> oldTreeItem = treeItemRef == null ? null : treeItemRef.get();
    if (oldTreeItem != null) {
        oldTreeItem.graphicProperty().removeListener(weakTreeItemGraphicListener);
    }

    TreeItem<T> newTreeItem = getTreeItem();
    if (newTreeItem != null) {
        newTreeItem.graphicProperty().addListener(weakTreeItemGraphicListener);
        treeItemRef = new WeakReference<TreeItem<T>>(newTreeItem);
    }
}
 
Example #23
Source File: ConfigurationUIController.java    From jace with GNU General Public License v2.0 5 votes vote down vote up
private Node buildDynamicSelectComponent(ConfigNode node, String settingName, Serializable value) {
    try {
        DynamicSelection sel = (DynamicSelection) node.subject.getClass().getField(settingName).get(node.subject);
        ChoiceBox widget = new ChoiceBox(FXCollections.observableList(new ArrayList(sel.getSelections().keySet())));
        widget.setMinWidth(175.0);
        widget.setConverter(new StringConverter() {
            @Override
            public String toString(Object object) {
                return (String) sel.getSelections().get(object);
            }
            
            @Override
            public Object fromString(String string) {
                return sel.findValueByMatch(string);
            }
        });
        Object selected = value == null ? null : widget.getConverter().fromString(String.valueOf(value));
        if (selected == null) {
            widget.getSelectionModel().selectFirst();
        } else {
            widget.setValue(selected);
        }
        widget.valueProperty().addListener((Observable e) -> {
            node.setFieldValue(settingName, widget.getConverter().toString(widget.getValue()));
        });
        return widget;
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
        Logger.getLogger(ConfigurationUIController.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
}
 
Example #24
Source File: SetMultimapBinding.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void dispose() {
	if (dependencies != null) {
		unbind(dependencies.toArray(new Observable[] {}));
	}
	invalidatingDependenciesObserver = null;
}
 
Example #25
Source File: WidgetTree.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Link selections in tree view and model */
private void bindSelections()
{
    // Update selected widgets in model from selection in tree_view
    final ObservableList<TreeItem<WidgetOrTab>> tree_selection = tree_view.getSelectionModel().getSelectedItems();
    InvalidationListener listener = (Observable observable) ->
    {
        if (! active.compareAndSet(false, true))
            return;
        try
        {
            final List<Widget> widgets = new ArrayList<>(tree_selection.size());

            for (TreeItem<WidgetOrTab> item : tree_selection)
            {
                final WidgetOrTab wot = item.getValue();
                final Widget widget = wot.isWidget()
                    ? wot.getWidget()
                    : wot.getTab().getWidget();
                if (! widgets.contains(widget))
                    widgets.add(widget);
            };
            logger.log(Level.FINE, "Selected in tree: {0}", widgets);
            editor.getWidgetSelectionHandler().setSelection(widgets);
        }
        finally
        {
            active.set(false);
        }
    };
    tree_selection.addListener(listener);

    // Update selection in tree_view from selected widgets in model
    editor.getWidgetSelectionHandler().addListener(this::setSelectedWidgets);
}
 
Example #26
Source File: ProcView.java    From erlyberly with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void invalidated(Observable ob) {
    ProcSort procSort = null;

    if(!processView.getSortOrder().isEmpty()) {
        TableColumn<ProcInfo, ?> tableColumn = processView.getSortOrder().get(0);

        procSort = new ProcSort(tableColumn.getId(), tableColumn.getSortType());
    }
    procController.procSortProperty().set(procSort);
}
 
Example #27
Source File: MapTile.java    From maps with GNU General Public License v3.0 5 votes vote down vote up
MapTile(BaseMap baseMap, int nearestZoom, long i, long j) {
        this.baseMap = baseMap;
        this.myZoom = nearestZoom;
        this.i = i;
        this.j = j;
        scale.setPivotX(0);
        scale.setPivotY(0);
        getTransforms().add(scale);
        debug("[JVDBG] load image [" + myZoom + "], i = " + i + ", j = " + j);

        ImageView imageView = new ImageView();
        imageView.setMouseTransparent(true);
        Image tile = TILE_RETRIEVER.loadTile(myZoom, i, j);
        imageView.setImage(tile);
        this.progress = tile.progressProperty();

//        Label l = new Label("Tile [" + myZoom + "], i = " + i + ", j = " + j);
        getChildren().addAll(imageView);//,l);
        this.progress.addListener(new InvalidationListener() {
            @Override
            public void invalidated(Observable observable) {
                if (progress.get() >= 1.0d) {
                    debug("[JVDBG] got image [" + myZoom + "], i = " + i + ", j = " + j);
                    setNeedsLayout(true);
                    progress.removeListener(this);
                }
            }
        });
        baseMap.zoom().addListener(new WeakInvalidationListener(zl));
        baseMap.translateXProperty().addListener(new WeakInvalidationListener(zl));
        baseMap.translateYProperty().addListener(new WeakInvalidationListener(zl));
        calculatePosition();
        this.setMouseTransparent(true);
    }
 
Example #28
Source File: SetMultimapBinding.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Stops observing the dependencies for changes. The binding will no longer
 * be marked as invalid if one of the dependencies changes.
 *
 * @param dependencies
 *            The dependencies to stop observing.
 */
protected void unbind(Observable... dependencies) {
	if (this.dependencies != null) {
		for (final Observable d : dependencies) {
			if (d != null) {
				this.dependencies.remove(d);
				d.removeListener(invalidatingDependenciesObserver);
			}
		}
		if (this.dependencies.size() == 0) {
			this.dependencies = null;
		}
	}
}
 
Example #29
Source File: SessionManager.java    From mokka7 with Eclipse Public License 1.0 5 votes vote down vote up
public void bind(final StringProperty property, final String propertyName) {
    String value = props.getProperty(propertyName);
    if (value != null) {
        property.set(value);
    }

    property.addListener(new InvalidationListener() {
        @Override
        public void invalidated(Observable o) {
            props.setProperty(propertyName, property.getValue());
        }
    });
}
 
Example #30
Source File: MultisetBinding.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void dispose() {
	if (dependencies != null) {
		unbind(dependencies.toArray(new Observable[] {}));
	}
	invalidatingDependenciesObserver = null;
}