javafx.beans.value.ChangeListener Java Examples

The following examples show how to use javafx.beans.value.ChangeListener. 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: RFXWebView.java    From marathonv5 with Apache License 2.0 7 votes vote down vote up
private void init(Node source) {
    WebView webview = (WebView) source;
    if (webview.getProperties().get("marathon_listener_installed") == null) {
        webview.getProperties().put("marathon_listener_installed", Boolean.TRUE);
        WebEngine webEngine = webview.getEngine();
        if (webEngine.getLoadWorker().stateProperty().get() == State.SUCCEEDED) {
            loadScript(webview);
        }
        webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
            @Override
            public void changed(ObservableValue<? extends State> ov, State oldState, State newState) {
                if (newState == State.SUCCEEDED) {
                    loadScript(webview);
                }
            }
        });
    }
    JavaFXWebViewElement.init(source);
}
 
Example #2
Source File: GenericEditableTreeTableCell.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
private void createEditorNode() {
    EventHandler<KeyEvent> keyEventsHandler = t -> {
        if (t.getCode() == KeyCode.ENTER) {
            commitHelper(false);
        } else if (t.getCode() == KeyCode.ESCAPE) {
            cancelEdit();
        } else if (t.getCode() == KeyCode.TAB) {
            commitHelper(false);
            editNext(!t.isShiftDown());
        }
    };

    ChangeListener<Boolean> focusChangeListener = (observable, oldValue, newValue) -> {
        //This focus listener fires at the end of cell editing when focus is lost
        //and when enter is pressed (because that causes the text field to lose focus).
        //The problem is that if enter is pressed then cancelEdit is called before this
        //listener runs and therefore the text field has been cleaned up. If the
        //text field is null we don't commit the edit. This has the useful side effect
        //of stopping the double commit.
        if (editorNode != null && !newValue) {
            commitHelper(true);
        }
    };
    editorNode = builder.createNode(getValue(), keyEventsHandler, focusChangeListener);
}
 
Example #3
Source File: GamePane.java    From fx2048 with GNU General Public License v3.0 6 votes vote down vote up
public GamePane() {
    gameManager = new GameManager(UserSettings.LOCAL.getGridSize());
    gameBounds = gameManager.getLayoutBounds();

    getChildren().add(gameManager);

    getStyleClass().addAll("game-root");
    ChangeListener<Number> resize = (ov, v, v1) -> {
        double scale = Math.min((getWidth() - UserSettings.MARGIN) / gameBounds.getWidth(),
                (getHeight() - UserSettings.MARGIN) / gameBounds.getHeight());
        gameManager.setScale(scale);
        gameManager.setLayoutX((getWidth() - gameBounds.getWidth()) / 2d);
        gameManager.setLayoutY((getHeight() - gameBounds.getHeight()) / 2d);
    };
    widthProperty().addListener(resize);
    heightProperty().addListener(resize);

    addKeyHandlers();
    addSwipeHandlers();
    setFocusTraversable(true);
    setOnMouseClicked(e -> requestFocus());
}
 
Example #4
Source File: VisualChangeListener.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Unregisters all previously registered listeners.
 */
public void unregister() {
	if (!isRegistered()) {
		return;
	}

	// remove bounds listener
	observed.layoutBoundsProperty().removeListener(layoutBoundsListener);
	observed.boundsInLocalProperty().removeListener(boundsInLocalListener);
	observed.boundsInParentProperty()
			.removeListener(boundsInParentListener);

	// remove transform listeners
	for (ChangeListener<Transform> l : localToParentTransformListeners
			.keySet()) {
		localToParentTransformListeners.get(l)
				.localToParentTransformProperty().removeListener(l);
	}

	// reset fields
	parent = null;
	observed = null;
	localToParentTransformListeners.clear();
}
 
Example #5
Source File: History.java    From PreferencesFX with Apache License 2.0 6 votes vote down vote up
/**
 * Adds a listener to the {@code setting}, so every time the value of the {@code setting} changes,
 * a new {@link Change} will be created and added to the list of changes.
 *
 * @param setting the setting to observe for changes
 */
public void attachChangeListener(Setting setting) {
  ChangeListener changeEvent = (observable, oldValue, newValue) -> {
    if (isListenerActive() && oldValue != newValue) {
      LOGGER.trace("Change detected, old: " + oldValue + " new: " + newValue);
      addChange(new Change(setting, oldValue, newValue));
    }
  };
  ChangeListener listChangeEvent = (observable, oldValue, newValue) -> {
    if (isListenerActive()) {
      LOGGER.trace("List Change detected: " + oldValue);
      addChange(new Change(setting, (ObservableList) oldValue, (ObservableList) newValue));
    }
  };

  if (setting.valueProperty() instanceof SimpleListProperty) {
    setting.valueProperty().addListener(listChangeEvent);
  } else {
    setting.valueProperty().addListener(changeEvent);
  }
}
 
Example #6
Source File: LabAssistantController.java    From HealthPlus with 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 #7
Source File: BrowserPanel.java    From zap-extensions with 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 #8
Source File: EditingStrCell.java    From CPUSim with GNU General Public License v3.0 6 votes vote down vote up
/**
 * creates a text field with listeners so that that edits will be committed 
 * at the proper time
 */
protected void createTextField() {
    textField = new TextField(getString());
    textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
    textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
        @Override
        public void changed(ObservableValue<? extends Boolean> arg0,
                            Boolean arg1, Boolean arg2) {
            if (!arg2) {
                commitEdit(textField.getText());
            }
        }
    });
    textField.setOnKeyPressed(new EventHandler<KeyEvent>() {
        @Override
        public void handle(KeyEvent t) {
            if (t.getCode() == KeyCode.ENTER) {
                commitEdit(textField.getText());
            } else if (t.getCode() == KeyCode.ESCAPE) {
                cancelEdit();
            }
        }
    });
}
 
Example #9
Source File: FilesMergeController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@Override
public void initTargetSection() {
    targetFileInput.textProperty().addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            try {
                targetFile = new File(newValue);
                targetFileInput.setStyle(null);
                recordFileWritten(targetFile.getParent());
            } catch (Exception e) {
                targetFile = null;
                targetFileInput.setStyle(badStyle);
            }
        }
    });

    operationBarController.openTargetButton.disableProperty().bind(Bindings.isEmpty(targetFileInput.textProperty())
            .or(targetFileInput.styleProperty().isEqualTo(badStyle))
    );

    startButton.disableProperty().bind(Bindings.isEmpty(targetFileInput.textProperty())
            .or(targetFileInput.styleProperty().isEqualTo(badStyle))
            .or(Bindings.isEmpty(tableData))
    );

}
 
Example #10
Source File: AddPreferenceStage.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Override
public Parent getContentPane() {
    VBox content = new VBox();
    content.getStyleClass().add("add-preference-stage");
    content.setId("addPreferenceStage");
    FormPane form = new FormPane("add-preference-stage-form", 3);
    integerValueField.textProperty().addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            if (!newValue.matches("\\d*")) {
                integerValueField.setText(newValue.replaceAll("[^\\d]", ""));
            }
        }
    });
    StackPane pane = new StackPane(stringValueField, integerValueField, booleanValueField);
    pane.setAlignment(Pos.CENTER_LEFT);
    //@formatter:off
    form.addFormField("Property name:", nameField)
        .addFormField("Method:", typeComboBox, new Region())
        .addFormField("Value:", pane);
    //@formatter:on
    GridPane.setHgrow(typeComboBox, Priority.NEVER);
    VBox.setVgrow(form, Priority.ALWAYS);
    content.getChildren().addAll(form, buttonBar);
    return content;
}
 
Example #11
Source File: ImageManufactureEnhancementController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@Override
public void initControls() {
    try {
        super.initControls();
        myPane = enhancementPane;

        enhancementGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
            @Override
            public void changed(ObservableValue ov, Toggle oldValue, Toggle newValue) {
                checkEnhanceType();
            }
        });

        manageView = new ImageView();

    } catch (Exception e) {
        logger.error(e.toString());
    }

}
 
Example #12
Source File: RecoverFileController.java    From PeerWasp with MIT License 6 votes vote down vote up
private void initializeStatusBar() {
	statusBar = new StatusBar();
	pane.getChildren().add(statusBar);
	AnchorPane.setBottomAnchor(statusBar, 0.0);
	AnchorPane.setLeftAnchor(statusBar, 0.0);
	AnchorPane.setRightAnchor(statusBar, 0.0);
	busyProperty.addListener(new ChangeListener<Boolean>() {
		@Override
		public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue,
				Boolean newValue) {
			if(newValue != null && newValue.booleanValue()) {
				statusBar.setProgress(-1);
			} else {
				statusBar.setProgress(0);
			}
		}
	});

	statusBar.textProperty().bind(statusProperty);
}
 
Example #13
Source File: FileFilterController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeNext() {
    try {
        initFilterTab();

        filterTypeSelector.getItems().clear();
        for (StringFilterType type : StringFilterType.values()) {
            filterTypeSelector.getItems().add(message(type.name()));
        }
        filterTypeSelector.valueProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> ov,
                    String oldv, String newv) {
                checkFilterType();
            }
        });
        filterTypeSelector.getSelectionModel().select(0);

        FxmlControl.setTooltip(filterTypeSelector, new Tooltip(AppVariables.message("FilterTypesComments")));

    } catch (Exception e) {
        logger.error(e.toString());
    }
}
 
Example #14
Source File: MarkdownEditorPane.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void requestFocus() {
	Platform.runLater(() -> {
		if (textArea.getScene() != null)
			textArea.requestFocus();
		else {
			// text area still does not have a scene
			// --> use listener on scene to make sure that text area receives focus
			ChangeListener<Scene> l = new ChangeListener<Scene>() {
				@Override
				public void changed(ObservableValue<? extends Scene> observable, Scene oldValue, Scene newValue) {
					textArea.sceneProperty().removeListener(this);
					textArea.requestFocus();
				}
			};
			textArea.sceneProperty().addListener(l);
		}
	});
}
 
Example #15
Source File: CSSFXMonitor.java    From cssfx with Apache License 2.0 6 votes vote down vote up
private void monitorStageScene(ReadOnlyObjectProperty<Scene> stageSceneProperty) {
    // first listen to changes
    stageSceneProperty.addListener(new ChangeListener<Scene>() {
        @Override
        public void changed(ObservableValue<? extends Scene> ov, Scene o, Scene n) {
            if (o != null) {
                unregisterScene(o);
            }
            if (n != null) {
                registerScene(n);
            }
        }
    });

    if (stageSceneProperty.getValue() != null) {
        registerScene(stageSceneProperty.getValue());
    }
}
 
Example #16
Source File: FxmlControl.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static void setPathValidation(final TextField input) {
    if (input == null) {
        return;
    }
    input.textProperty().addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> observable,
                String oldValue, String newValue) {
            final File file = new File(newValue);
            if (!file.isDirectory()) {
                input.setStyle(badStyle);
                return;
            }
            input.setStyle(null);
        }
    });
}
 
Example #17
Source File: SpriteView.java    From training with MIT License 6 votes vote down vote up
public SpriteView(Image spriteSheet, Main.Location loc) {
    imageView = new ImageView(spriteSheet);
    this.location.set(loc);
    setTranslateX(loc.getX() * Main.CELL_SIZE);
    setTranslateY(loc.getY() * Main.CELL_SIZE);
    ChangeListener<Object> updateImage = (ov, o, o2) -> imageView.setViewport(
        new Rectangle2D(frame.get() * spriteWidth,
            direction.get().getOffset() * spriteHeight,
            spriteWidth, spriteHeight));
    direction.addListener(updateImage);
    frame.addListener(updateImage);
    spriteWidth = (int) (spriteSheet.getWidth() / 3);
    spriteHeight = (int) (spriteSheet.getHeight() / 4);
    direction.set(Main.Direction.RIGHT);
    getChildren().add(imageView);
}
 
Example #18
Source File: JavaFXWebViewElement.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static void init(Node source) {
    WebView webview = (WebView) source;
    if (webview.getProperties().get("marathon_player_installed") == null) {
        webview.getProperties().put("marathon_player_installed", Boolean.TRUE);
        WebEngine webEngine = webview.getEngine();
        if (webEngine.getLoadWorker().stateProperty().get() == State.SUCCEEDED) {
            loadScript(webview, webEngine);
        }
        webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
            @Override
            public void changed(ObservableValue<? extends State> ov, State oldState, State newState) {
                if (newState == State.SUCCEEDED) {
                    loadScript(webview, webEngine);
                }
            }
        });
    }
}
 
Example #19
Source File: ImageAnalyseController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public void initImageBox() {
    try {

        imageBox.disableProperty().bind(imageView.imageProperty().isNull());

        selectAreaCheck.selectedProperty().addListener(new ChangeListener<Boolean>() {
            @Override
            public void changed(ObservableValue ov, Boolean oldValue, Boolean newValue) {
                loadData(true, true, true);
            }
        });
        selectAreaCheck.setSelected(false);

    } catch (Exception e) {
        logger.error(e.toString());
    }
}
 
Example #20
Source File: FXValidationSupportTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void behaviour() {
    FXValidationSupport<String> victim = new FXValidationSupport<>();
    victim.setValidator(Validators.nonBlank());
    ChangeListener<ValidationState> listener = mock(ChangeListener.class);
    victim.validationStateProperty().addListener(listener);
    victim.validate("Chuck");
    verify(listener, times(1)).changed(any(ObservableValue.class), eq(ValidationState.NOT_VALIDATED),
            eq(ValidationState.VALID));
    assertEquals(ValidationState.VALID, victim.validationStateProperty().get());
    victim.validate(" ");
    verify(listener, times(1)).changed(any(ObservableValue.class), eq(ValidationState.VALID),
            eq(ValidationState.INVALID));
    assertEquals(ValidationState.INVALID, victim.validationStateProperty().get());
}
 
Example #21
Source File: BaseGraphApp.java    From diirt with MIT License 5 votes vote down vote up
public DataSelectionPanel() {
    this.setPadding( new Insets( 5 , 5 , 5 , 5 ) );

    GridPane pnlCenter = new GridPane();
    pnlCenter.setHgap( 5 );
    this.cboSelectData.setPrefWidth( 0 );
    pnlCenter.addRow( 0 , this.lblData , this.cboSelectData , this.cmdConfigure );

    ColumnConstraints allowResize = new ColumnConstraints();
    allowResize.setHgrow( Priority.ALWAYS );
    ColumnConstraints noResize = new ColumnConstraints();
    pnlCenter.getColumnConstraints().addAll( noResize , allowResize , noResize );

    this.setCenter( pnlCenter );

    //allow the combo box to stretch out and fill panel completely
    this.cboSelectData.setMaxSize( Double.MAX_VALUE , Double.MAX_VALUE );
    this.cboSelectData.setEditable( true );

    //watches for when the user selects a new data formula
    cboSelectData.valueProperty().addListener( new ChangeListener< String >() {

        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            pnlGraph.setFormula(newValue);
        }

    });

    this.cmdConfigure.setOnAction( new EventHandler< ActionEvent >() {

        @Override
        public void handle(ActionEvent event) {
            openConfigurationPanel();
        }

    });
}
 
Example #22
Source File: TextLineBreakBatchController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
@Override
public void initOptionsSection() {
    super.initOptionsSection();

    lbGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        @Override
        public void changed(ObservableValue<? extends Toggle> ov,
                Toggle old_toggle, Toggle new_toggle) {
            checkLineBreak();
        }
    });
    checkLineBreak();
}
 
Example #23
Source File: AuditLogTaskRecord.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public AuditLogTaskRecord(@Nonnull Task<?> task) {
  this.taskMessage = task.getMessage();
  this.taskTitle = task.getTitle();

  task.stateProperty().addListener(new ChangeListener<State>() {
    public void changed(ObservableValue<? extends State> ov, State oldState, State newState) {
      taskStatus = newState;
    }
  });

}
 
Example #24
Source File: MultisetBinding.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addListener(
		ChangeListener<? super ObservableMultiset<E>> listener) {
	if (helper == null) {
		helper = new MultisetExpressionHelper<>(this);
	}
	helper.addListener(listener);
}
 
Example #25
Source File: FX.java    From FxDock with Apache License 2.0 5 votes vote down vote up
public static <T> void addOneShotListener(Property<T> p, Consumer<T> c)
{
	p.addListener(new ChangeListener<T>()
	{
		public void changed(ObservableValue<? extends T> observable, T old, T cur)
		{
			c.accept(cur);
			p.removeListener(this);
		}
	});
}
 
Example #26
Source File: ReadOnlySetMultimapPropertyBase.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void removeListener(
		ChangeListener<? super ObservableSetMultimap<K, V>> listener) {
	if (helper != null) {
		helper.removeListener(listener);
	}
}
 
Example #27
Source File: DemoBrowser.java    From FxDock with Apache License 2.0 5 votes vote down vote up
public DemoBrowser()
{
	super(DemoGenerator.BROWSER);
	setTitle("Browser / " + CSystem.getJavaVersion());
	
	addressField = new TextField();
	addressField.addEventHandler(KeyEvent.KEY_PRESSED, (ev) -> handleKeyTyped(ev));
	LocalSettings.get(this).add("URL", addressField);
	
	view = new WebView();
	view.getEngine().setOnError((ev) -> handleError(ev));
	view.getEngine().setOnStatusChanged((ev) -> handleStatusChange(ev));
	Worker<Void> w = view.getEngine().getLoadWorker();
	w.stateProperty().addListener(new ChangeListener<Worker.State>()
	{
		public void changed(ObservableValue v, Worker.State old, Worker.State cur)
		{
			log.debug(cur);
			
			if(w.getException() != null && cur == State.FAILED)
			{
				log.error(w.getException());
			}
		}
	});

	statusField = new Label();
	
	CPane p = new CPane();
	p.setGaps(10, 5);
	p.setCenter(view);
	p.setBottom(statusField);
	setContent(p);
	
	FX.later(() -> reload());
}
 
Example #28
Source File: SecurityCertificatesController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
@Override
public void initializeNext() {
    try {
        tableData = FXCollections.observableArrayList();

        aliasColumn.setCellValueFactory(new PropertyValueFactory<>("alias"));
        timeColumn.setCellValueFactory(new PropertyValueFactory<>("createTime"));
        timeColumn.setCellFactory(new TableDateCell());

        tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
        tableView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
            @Override
            public void changed(ObservableValue ov, Object t, Object t1) {
                checkSelected();
            }
        });
        checkSelected();
        tableView.setItems(tableData);

        sourceFileInput.setText(SystemTools.keystore());
        passwordInput.setText(SystemTools.keystorePassword());
        htmlButton.setDisable(true);
        plusButton.setDisable(true);

    } catch (Exception e) {
        logger.error(e.toString());
    }
}
 
Example #29
Source File: PdfVersionFilterTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void failingAdd() {
    PdfVersionFilter victim = new PdfVersionFilter();
    victim.addFilter(PdfVersion.VERSION_1_4);
    assertEquals(PdfVersion.VERSION_1_4, victim.requiredProperty().get());
    ChangeListener<? super PdfVersion> listener = mock(ChangeListener.class);
    victim.requiredProperty().addListener(listener);
    victim.addFilter(PdfVersion.VERSION_1_4);
    verify(listener, never()).changed(any(ObservableValue.class), any(PdfVersion.class), any(PdfVersion.class));
}
 
Example #30
Source File: FXValidationSupportTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void startingState() {
    FXValidationSupport<String> victim = new FXValidationSupport<>();
    victim.setValidator(Validators.nonBlank());
    assertEquals(ValidationState.NOT_VALIDATED, victim.validationStateProperty().get());
    ChangeListener<ValidationState> listener = mock(ChangeListener.class);
    victim.validationStateProperty().addListener(listener);
    victim.validate("Chuck");
    verify(listener, times(1)).changed(any(ObservableValue.class), eq(ValidationState.NOT_VALIDATED),
            eq(ValidationState.VALID));
    assertEquals(ValidationState.VALID, victim.validationStateProperty().get());
}