Java 类javafx.beans.value.WeakChangeListener 实例源码

项目:IO    文件:MainScreenController.java   
private ChangeListener<Boolean> getWriteblockListener() {
    writeBlockListener = (observable, oldValue, newValue) -> Platform.runLater(() -> {
        if (newValue) {
            writeblockStatus.setText("ENABLED");
            writeblockStatus.setTextFill(Color.LIME);
            readyLabel.setVisible(true);
            writeblockStatus.autosize();
        }
        else {
            writeblockStatus.setText("DISABLED");
            writeblockStatus.setTextFill(Color.RED);
            readyLabel.setVisible(false);
            writeblockStatus.autosize();
        }
    });
    return new WeakChangeListener<>(writeBlockListener);
}
项目:IO    文件:ImagingController.java   
private ChangeListener<Number> getProgressUpdater() {
    ProgressStatus currentStatus = new ProgressStatus();
    progressListener = (arg0, oldVal, newVal) -> Platform.runLater(() -> {
        if (!progressBar.isDisabled()) {
            long newLong = newVal.longValue();
            if (newLong > 0) {
                currentStatus.onChange(newLong);
            }
            else if (newVal.intValue() == -1) {
                // failureLabel.setVisible(true);
                progressBar.setDisable(true);
                displayErrorPopup("Error: Failed to complete imaging.\n");
            }
        }
    });
    return new WeakChangeListener<>(progressListener);
}
项目:fx-animation-editor    文件:KeyFrameComponent.java   
private void initUi() {
    timeLabel.setValue(model.getTime());

    // Use weak listener here so view can be garbage collected when key frame is deleted, because model instance will hang around in command stack.
    ChangeListener<Number> timeChangeListener = (v, o, n) -> timeLabel.setValue(n.doubleValue());
    timeLabel.getProperties().put(TIME_CHANGE_LISTENER_KEY, timeChangeListener);
    model.timeProperty().addListener(new WeakChangeListener<>(timeChangeListener));

    incrementButton.setGraphic(createArrowGraphic(NodeOrientation.LEFT_TO_RIGHT));
    decrementButton.setGraphic(createArrowGraphic(NodeOrientation.RIGHT_TO_LEFT));
    deleteButton.setGraphic(Svg.MINUS_TINY.node());

    leftButtonBox.visibleProperty().bind(model.timeProperty().greaterThan(0));
    rightButtonBox.visibleProperty().bind(model.timeProperty().greaterThan(0));
    plusLabel.visibleProperty().bind(model.timeProperty().greaterThan(0));
    plusLabel.managedProperty().bind(plusLabel.visibleProperty());

    highlight.visibleProperty().bind(model.selectedProperty());
}
项目:leakdetectorFX    文件:LeakDetector.java   
/**
 * Check the scene property of a parent for getting null. If it gets null
 * and the Object retains in Memory (leakedObject List), it is likely a
 * leak.
 *
 * @param parent
 */
protected void registerLeakDetection(Node parent) {
    Optional<WeakRef<Node>> parentReference = map.keySet().stream()
            .filter(element -> element.get() == parent)
            .findFirst();

    WeakRef<Node> weakRef = new WeakRef<Node>(parent);
    ChangeListener<Scene> sceneListener = (observable, oldValue, newValue) -> {
        if (newValue == null) {
            if (!parentReference.isPresent()) {
                if(map.get(weakRef) == null) {
                    insertWeakRefIntoMap(weakRef);
                }
            }
        } else {
            if(parentReference.isPresent()) {
                map.remove(parentReference.get());
            }
        }
    };

    listeners.add(sceneListener);
    parent.sceneProperty().addListener(new WeakChangeListener<>(sceneListener));
}
项目:factoryfx    文件:DataTextFieldTreeCell.java   
@Override
public void updateItem(T item, boolean empty) {
    super.updateItem(item, empty);

    if (item != null) {
        if (dataSupplier.apply(item)!=null){
            if (displayText!=null){
                displayText.removeListener(changeListener);
            }

            displayText= dataSupplier.apply(item).internal().getDisplayTextObservable();
            changeListenerGarbageCollectionSave = (observable, oldValue, newValue) -> {
                setText(dataSupplier.apply(item).internal().getDisplayText());
            };
            changeListener = new WeakChangeListener<>(changeListenerGarbageCollectionSave);
            displayText.addListener(changeListener);
            changeListener.changed(displayText,null,displayText.get());
        } else {
            setText(alternativeDisplayText.apply(item));
        }

    }
    //CellUtils.updateItem(this, getConverter(), hbox, getTreeItemGraphic(), textField);
}
项目:factoryfx    文件:StringHtmlAttributeVisualisation.java   
@Override
public Node createVisualisation(SimpleObjectProperty<String> attributeValue, boolean readonly) {
    HTMLEditor htmlEditor = new HTMLEditor();

    changeListener = (observable, oldValue, newValue) -> htmlEditor.setHtmlText(newValue);
    attributeValue.addListener(new WeakChangeListener<>(changeListener));
    htmlEditor.setDisable(readonly);


    BorderPane borderPane = new BorderPane();
    borderPane.setCenter(htmlEditor);
    Button save = new Button("save");//strangely workaround HTMLEditor have no bind or change events
    save.setOnAction(event -> attributeValue.set(htmlEditor.getHtmlText()));
    htmlEditor.setHtmlText(attributeValue.get());
    BorderPane.setMargin(save,new Insets(3,0,3,0));
    borderPane.setTop(save);
    return borderPane;
}
项目:Cachoeira    文件:RelationLine.java   
public void setListener() {
    dependentTypeChangeListener = (observable, oldValue, newValue) -> {
        this.getChildren().clear();
        if (dependenceType.getValue().equals(TaskDependencyType.FINISHSTART)) {
            this.getChildren().addAll(initFinishStartRelationLine(parentTaskBar, childTaskBar));
        }
        if (dependenceType.getValue().equals(TaskDependencyType.STARTFINISH)) {
            this.getChildren().addAll(iniStartFinishRelationLine(parentTaskBar, childTaskBar));
        }
        if (dependenceType.getValue().equals(TaskDependencyType.FINISHFINISH)) {
            this.getChildren().addAll(initFinishFinishRelationLine(parentTaskBar, childTaskBar));
        }
        if (dependenceType.getValue().equals(TaskDependencyType.STARTSTART)) {
            this.getChildren().addAll(initStartStartRelationLine(parentTaskBar, childTaskBar));
        }
    };
    dependenceType.addListener(new WeakChangeListener<>(dependentTypeChangeListener));
}
项目:Cachoeira    文件:MainWindowController.java   
private AbstractTableView<ITask> createTaskTable(DoubleProperty horizontalScrollValue,
                                                 DoubleProperty verticalScrollValue) {
    taskTableView = new TaskTableView<>(horizontalScrollValue, verticalScrollValue);

    taskTableView.setRoot(new TreeItem<>(new Task()));
    taskTableView.setRowFactory(new TaskTreeTableViewRowFactory(this, new TaskTableDragAndDrop(this)));
    taskTableView.setRowFactory(new TaskTreeTableViewRowFactory(this, new TaskTableDragAndDrop(this)));
    taskListChangeListener = this::taskChangeListenerHandler;
    project.getTaskList().addListener(new WeakListChangeListener<>(taskListChangeListener));

    taskChangeListener = this::refreshSelectedTask;
    taskTableView.getSelectionModel().selectedItemProperty().addListener(new WeakChangeListener<>(taskChangeListener));

    taskTreeItemsChangeListener = this::setSelectedTaskNull;
    taskTableView.getRoot().getChildren().addListener(new WeakListChangeListener<>(taskTreeItemsChangeListener));
    return taskTableView;
}
项目:Cachoeira    文件:MainWindowController.java   
private AbstractTableView<IResource> createResourceTable(DoubleProperty horizontalScrollValue,
                                                         DoubleProperty verticalScrollValue) {
    resourceTableView = new ResourceTableView<>(horizontalScrollValue, verticalScrollValue);

    resourceTableView.setRoot(new TreeItem<>(new Resource()));
    resourceTableView.setRowFactory(new ResourceTreeTableViewRowFactory(this, new ResourceTableDragAndDrop(this)));
    resourceListChangeListener = this::resourceChangeListenerHandler;
    project.getResourceList().addListener(new WeakListChangeListener<>(resourceListChangeListener));

    resourceChangeListener = this::refreshSelectedResource;
    resourceTableView.getSelectionModel().selectedItemProperty().addListener(new WeakChangeListener<>(resourceChangeListener));

    resourceTreeItemsChangeListener = this::setSelectedResourceNull;
    resourceTableView.getRoot().getChildren().addListener(new WeakListChangeListener<>(resourceTreeItemsChangeListener));
    return resourceTableView;
}
项目:Cachoeira    文件:ResourceInformationModuleController.java   
@Override
public void initModule() {
    module.disableProperty().bind(controller.selectedResourceProperty().isNull());

    module.getResourceTypeComboBox().setItems(FXCollections.observableArrayList(ResourceType.values()));

    resourceChangeListener = this::selectedResourceObserver;
    nameFieldInvalidationListener = this::nameFieldUnfocused;
    emailFieldInvalidationListener = this::emailFieldUnfocused;
    descriptionTextAreaInvalidationListener = this::descriptionTextAreaUnfocused;

    controller.selectedResourceProperty().addListener(new WeakChangeListener<>(resourceChangeListener));

    module.getNameField().setOnKeyPressed(this::nameFieldObserver);
    module.getResourceTypeComboBox().setOnAction(this::resourceTypeComboBoxObserver);
    module.getEmailField().setOnKeyPressed(this::emailFieldObserver);
    module.getDescriptionTextArea().setOnKeyPressed(this::descriptionTextAreaObserver);

    module.getNameField().focusedProperty().addListener(new WeakInvalidationListener(nameFieldInvalidationListener));
    module.getEmailField().focusedProperty().addListener(new WeakInvalidationListener(emailFieldInvalidationListener));
    module.getDescriptionTextArea().focusedProperty().addListener(new WeakInvalidationListener(descriptionTextAreaInvalidationListener));
}
项目:myWMS    文件:LoginPreloader.java   
@Override
public void handleStateChangeNotification(StateChangeNotification evt) {
    if (evt.getType() == StateChangeNotification.Type.BEFORE_START) {
        //application is loaded => hide progress bar
        bar.setVisible(false);

        consumer = (MyWMS) evt.getApplication();
        consumer.loginServiceProperty().addListener(new WeakChangeListener<>(hideStageListener));

        checkLogin();
    }
}
项目:leakdetectorFX    文件:LeakDetectorBase.java   
protected void registerListenerOnSceneRoot(Scene scene) {
    scene.rootProperty().addListener(new WeakChangeListener<>((observable, oldValue, newValue) -> {
        safeRegisterTracking(newValue);
    }));

    Parent root = scene.getRoot();
    safeRegisterTracking(root);
}
项目:qupath    文件:TMASummaryViewer.java   
RootTreeItem(final Collection<? extends TMAEntry> entries, final ObservableValue<Predicate<TMAEntry>> combinedPredicate) {
    super(null);
    for (TMAEntry entry : entries) {
        if (entry instanceof TMASummaryEntry)
            this.entries.add(new SummaryTreeItem((TMASummaryEntry)entry));
        else
            this.entries.add(new TreeItem<>(entry));                    
    }
    this.combinedPredicate = combinedPredicate;
    this.combinedPredicate.addListener(new WeakChangeListener<>(this));
    updateChildren();
}
项目:Cachoeira    文件:TaskInformationModuleController.java   
@Override
public void initModule() {
    // set disable if selected task is null
    module.disableProperty().bind(controller.selectedTaskProperty().isNull());
    // init listeners
    taskChangeListener = this::selectedTaskObserver;
    nameFieldInvalidationListener = this::nameFieldUnfocused;
    costFieldInvalidationListener = this::costFieldUnfocused;
    descriptionTextAreaInvalidationListener = this::descriptionTextAreaUnfocused;
    // set listener on selected task
    controller.selectedTaskProperty().addListener(new WeakChangeListener<>(taskChangeListener));
    // set handlers on fields events
    module.getNameField().setOnKeyPressed(this::nameFieldHandler);
    module.getStartDatePicker().setOnAction(this::startDatePickerHandler);
    module.getFinishDatePicker().setOnAction(this::finishDatePickerHandler);
    module.getDonePercentSlider().setOnMouseReleased(this::donePercentSliderHandler);
    module.getCostField().setOnKeyPressed(this::costFieldHandler);
    module.getDescriptionTextArea().setOnKeyPressed(this::descriptionTextAreaHandler);
    // set listeners to discard changes when field is unfocused
    module.getNameField().focusedProperty().addListener(new WeakInvalidationListener(nameFieldInvalidationListener));
    module.getCostField().focusedProperty().addListener(new WeakInvalidationListener(costFieldInvalidationListener));
    module.getDescriptionTextArea().focusedProperty().addListener(new WeakInvalidationListener(descriptionTextAreaInvalidationListener));
    // set day cells disabled outer valid range
    module.getStartDatePicker().setDayCellFactory(this::makeStartDatePickerCellsDisabled);
    module.getFinishDatePicker().setDayCellFactory(this::makeFinishDatePickerCellsDisabled);
    // set date enabled only by mouse
    module.getStartDatePicker().setEditable(false);
    module.getFinishDatePicker().setEditable(false);
}
项目:pdfsam    文件:SummaryTab.java   
@EventListener
void requestShow(ShowPdfDescriptorRequest event) {
    if (current != event.getDescriptor()) {
        current = event.getDescriptor();
        current.loadingStatus().addListener(new WeakChangeListener<>(this));
    }
    setFileProperties(current.getFile());
    setPdfProperties();
}
项目:pdfsam    文件:KeywordsTab.java   
@EventListener
void requestShow(ShowPdfDescriptorRequest event) {
    if (current != event.getDescriptor()) {
        current = event.getDescriptor();
        current.loadingStatus().addListener(new WeakChangeListener<>(this));
    }
    keywords.setText(event.getDescriptor().getInformation(PdfMetadataKey.KEYWORDS.getKey()));
}
项目:pdfsam    文件:SingleSelectionPane.java   
private void initializeFor(PdfDocumentDescriptor docDescriptor) {
    invalidateDescriptor();
    PdfLoadRequestEvent loadEvent = new PdfLoadRequestEvent(getOwnerModule());
    descriptor = docDescriptor;
    descriptor.loadingStatus().addListener(new WeakChangeListener<>(onLoadingStatusChange));
    setContextMenuDisable(false);
    loadEvent.add(descriptor);
    eventStudio().broadcast(loadEvent);
}
项目:graphing-loan-analyzer    文件:DateCell.java   
/**
 * Updates the calendar view. This method should usually only be called by skin implementations.
 *
 * @param calendarView The calendar view.
 */
public void updateCalendarView(final CalendarView calendarView) {
    this.calendarView.set(calendarView);
    this.calendar = (Calendar) calendarView.getCalendar().clone();
    calendarView.selectedDateProperty().addListener(new WeakChangeListener<Date>(selectedDateChangeListener));
}
项目:graphing-loan-analyzer    文件:CalendarViewSkin.java   
private AnimatedStackPane(final DatePane firstPane, final DatePane secondPane) {

            viewedDateChangeListener = new ChangeListener<Date>() {
                @Override
                public void changed(ObservableValue<? extends Date> observableValue, Date oldDate, Date newDate) {

                    Calendar calendar = calendarView.getCalendar();

                    calendar.setTime(oldDate);
                    int oldYear = calendar.get(Calendar.YEAR);
                    int oldMonth = calendar.get(Calendar.MONTH);

                    calendar.setTime(newDate);
                    int newYear = calendar.get(Calendar.YEAR);
                    int newMonth = calendar.get(Calendar.MONTH);

                    // move the panes, if necessary.
                    if (getWidth() > 0 && ongoingTransitions == 0) {
                        int direction = oldDate.after(newDate) ? 1 : -1;
                        if (newYear > oldYear || newYear == oldYear && newMonth > oldMonth) {
                            slide(direction, oldDate, newDate);
                        } else if (newYear < oldYear || newYear == oldYear && newMonth < oldMonth) {
                            slide(direction, oldDate, newDate);
                        }
                    }
                }
            };

            // The first pane, which displays the old date.
            this.firstPane = firstPane;

            // The second pane, which displays the new date.
            this.secondPane = secondPane;

            // Set the first invisible as long as it is not needed.
            firstPane.setVisible(false);

            slideTransition = new ParallelTransition();

            getChildren().add(firstPane);
            getChildren().add(secondPane);

            layoutBoundsProperty().addListener(new ChangeListener<Bounds>() {
                @Override
                public void changed(ObservableValue<? extends Bounds> observableValue, Bounds bounds, Bounds bounds1) {
                    setClip(new Rectangle(getLayoutBounds().getWidth(), getLayoutBounds().getHeight()));
                }
            });

            // Listen to changes of the calendar date, if it changes, check if the new date has another month and move the panes accordingly.
            calendarView.viewedDateProperty().addListener(new WeakChangeListener<Date>(viewedDateChangeListener));
        }
项目:factoryfx    文件:JavascriptVisual.java   
RootNode(List<SourceFile> externs, SimpleObjectProperty<Javascript<?>> boundTo) {
    this.getStylesheets().add(getClass().getResource("jsstyle.css").toExternalForm());
    List<SourceFile> externalSources = new ArrayList<>();
    externalSources.addAll(externs);
    this.contentAssistant = new ContentAssistant(externalSources, new WeakReference<>(processProoposals));
    this.errorsAndWarningsAssistant = new ErrorsAndWarningsAssistant(externalSources, new WeakReference<>(processErrorsAndWarnings));
    codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
    onUpdateScript = (observable, oldValue, newValue) ->{
        if (newValue != null && !newValue.getCode().equals(codeArea.getText())) {
            codeArea.replaceText(newValue.getCode());
        }
        updateAssistants(boundTo.get());
    };
    boundTo.addListener(new WeakChangeListener<>(onUpdateScript));
    codeArea.onKeyPressedProperty().set(this::handleKeys);
    codeArea.onKeyReleasedProperty().set(this::handleKeys);
    codeArea.setPopupWindow(popup);
    if (boundTo.get() != null)
        codeArea.insertText(0,boundTo.get().getCode());
    codeArea.textProperty().addListener((a,b,newValue)->{
        if (boundTo.get() == null || boundTo.get().getCode() == null) {
            boundTo.set(new Javascript(newValue));
        } else if (!boundTo.get().getCode().equals(newValue)) {
            boundTo.set(boundTo.get().copyWithNewCode(newValue));
        }

    });
    errorsAndWarnings.setCellFactory(lv->{
        ListCell<JSError> cell = new ListCell<>();
        Function<JSError,String> toText = e->{
            return e.getType().key + ". " + e.description + " at line " +
                    (e.getLineNumber() != -1 ? String.valueOf(e.getLineNumber()) : "(unknown line)") +
                    " : " + (e.getCharno() != -1 ? String.valueOf(e.getCharno()+1) : "(unknown column)");
        };
        cell.itemProperty().addListener((a,b,newValue)->{
            cell.getStyleClass().removeIf(c-> Arrays.stream(CheckLevel.values()).anyMatch(l->l.name().equals(c)));
            if (newValue != null) {
                cell.getStyleClass().add(newValue.getType().level.name());
                cell.setText(toText.apply(newValue).replaceAll("\\s+"," "));
            } else {
                cell.setText("");
            }
        });
        cell.setOnMouseClicked(e->{
            jumpToError(cell);
            Platform.runLater(codeArea::requestFocus);
        });
        cell.setOnKeyTyped(e->{
            if (e.getCode() == KeyCode.ENTER) {
                jumpToError(cell);
            }
            else if (!e.getCode().isNavigationKey()) {
                Platform.runLater(() -> {
                    codeArea.requestFocus();
                    codeArea.getOnKeyTyped().handle(e);
                });
            }
        });
        return cell;



    });
    errorsAndWarnings.getSelectionModel().selectedItemProperty().addListener((a,oldValue,newValue)->{
    });


    updateAssistants(boundTo.get());
    SplitPane area = new SplitPane();
    area.setOrientation(Orientation.VERTICAL);
    area.setDividerPosition(0,0.8);
    area.getItems().add(codeArea);
    area.getItems().add(errorsAndWarnings);
    SplitPane.setResizableWithParent(codeArea,true);
    getChildren().add(area);
    StackPane.setMargin(area, Insets.EMPTY);
}
项目:skadi    文件:ChannelGridCell.java   
@Override
protected void updateItem(final Channel item, final boolean empty) {
    super.updateItem(item, empty);

    if (lastItem != null && !lastItem.equals(item)) {
        lastItem.previewProperty().removeListener(weakPreviewListener);
    }
    lastItem = item;

    if (empty || item == null) {
        imageView.setImage(null);
        setGraphic(null);
        setText(null);
    } else {
        updateSelected(grid.isSelected(item));

        if (item.isOnline() != null) {
            if (item.isOnline()) {
                name.setStyle("-fx-font-weight: bold;-fx-text-fill: green");
            } else {
                name.setStyle("-fx-font-weight: bold;-fx-text-fill: red");
            }
        }

        name.textProperty().bind(item.nameProperty());

        title.textProperty().bind(item.titleProperty());

        viewer.textProperty().bind(Bindings.createStringBinding(() -> String.valueOf(item.getViewer()), item.viewerProperty()));
        viewer.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.USER));

        game.textProperty().bind(item.gameProperty());
        game.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.GAMEPAD));

        weakPreviewListener = new WeakChangeListener<>((observable, oldValue, newValue) -> imageView.setImage(newValue));
        item.previewProperty().addListener(weakPreviewListener);

        imageView.setImage(item.getPreview());

        setGraphic(vBox);

        setText(null);
    }
}
项目:reta    文件:SimpleObjectPropertyBuffering.java   
/**
 * @param newBeanType
 *            bean type
 * @param newPropertyName
 *            bean property name
 * @param newSubject
 *            property value
 */
public SimpleObjectPropertyBuffering(final Class<?> newBeanType, final String newPropertyName,
        final Property<T> newSubject)
{
    if (newBeanType != null || !(newSubject instanceof ReadOnlyProperty<?>))
    {
        beanType = newBeanType;
    }
    else
    {
        final Object bean = ((ReadOnlyProperty<?>) newSubject).getBean();
        beanType = (bean != null ? bean.getClass() : null);
    }

    if (newPropertyName != null || !(newSubject instanceof ReadOnlyProperty<?>))
    {
        propertyName = newPropertyName;
    }
    else
    {
        propertyName = ((ReadOnlyProperty<?>) newSubject).getName();
    }

    subject = java.util.Objects.requireNonNull(newSubject);

    setValue(subject.getValue());

    thisListener = (observable, oldValue, value) -> {
        if (equalsBuffering)
        {
            buffering.setValue(!Objects.equals(getValue(), subject.getValue()));
        }
        else
        {
            buffering.setValue(true);
        }
        validate();
    };

    subjectListener = (observable, oldValue, value) -> {
        if (!buffering.getValue())
        {
            revert();
        }
    };

    addListener(thisListener);

    weakSubjectListener = new WeakChangeListener<T>(subjectListener);
    subject.addListener(weakSubjectListener);

    validate();
}