Java Code Examples for javafx.beans.property.StringProperty#addListener()

The following examples show how to use javafx.beans.property.StringProperty#addListener() . 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: StartPresenter.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void showResult (StringProperty answer) {
      MATCH_VIEW.switchView();
        Optional<Object> presenter = MATCH_VIEW.getPresenter();
        MatchPresenter p = (MatchPresenter) presenter.get();
        p.setResult(-1);
        answer.addListener(new InvalidationListener() {
            @Override
            public void invalidated(Observable o) {
                String astring = answer.get();
                System.out.println("got answer: "+astring);
                if (astring != null) {
                    p.setResult(Integer.valueOf(astring));
                }
            }
        });
        if (answer.get() != null) {
            p.setResult(Integer.valueOf(answer.get()));
        }
}
 
Example 2
Source File: RestQueryParamAspect.java    From milkman with MIT License 5 votes vote down vote up
public void linkToUrlTextfield(StringProperty urlProperty) {
	urlProperty.addListener((obs, o, n) -> {
		if (o != n && n != null) {
			parseQueryParams(n);
			onInvalidate.invoke();
		}
	});
}
 
Example 3
Source File: SenderConfigView.java    From kafka-message-tool with MIT License 5 votes vote down vote up
private void configureTextAreasTextChangeActions() {
    final StringProperty sharedScriptProperty = applicationSettings.appSettings().runBeforeFirstMessageSharedScriptContentProperty();
    beforeAllmessagesSharedScriptCodeArea.appendText(sharedScriptProperty.get());


    beforeAllmessagesSharedScriptCodeArea.textProperty().addListener((observable, oldValue, newValue) -> {
        if (oldValue.equals(newValue) || sharedScriptProperty.get().equals(newValue)) {
            return;
        }

        sharedScriptProperty.setValue(newValue);
    });

    sharedScriptProperty.addListener((observable, oldValue, newValue) -> {
        if (oldValue.equals(newValue) || beforeAllmessagesSharedScriptCodeArea.getText().equals(newValue)) {
            return;
        }

        beforeAllmessagesSharedScriptCodeArea.replaceText(0,
                                                          beforeAllmessagesSharedScriptCodeArea.getLength(),
                                                          newValue);
    });

    beforeAllMessagesScriptCodeArea.appendText(config.runBeforeAllMessagesScriptProperty().get());
    config.runBeforeAllMessagesScriptProperty().bind(beforeAllMessagesScriptCodeArea.textProperty());

    beforeEachMessagesScriptCodeArea.appendText(config.runBeforeEachMessageScriptProperty().get());
    config.runBeforeEachMessageScriptProperty().bind(beforeEachMessagesScriptCodeArea.textProperty());
}
 
Example 4
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 5
Source File: ConnectionInfoPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Adds a JTextArea with the given text
 *
 * @param text
 * 		The text
 */
private JComponent createTextArea(StringProperty text) {
	// Without the TextArea the GUI is collapsing
	JTextArea multi = new JTextArea(text.get());
	multi.setFont(OPEN_SANS_12);
	// update text
	text.addListener(l -> {
		if (!multi.getText().equals(text.get())) {
			SwingTools.invokeLater(() -> multi.setText(text.get()));
		}
	});
	multi.setWrapStyleWord(true);
	multi.setLineWrap(true);
	multi.setEditable(editable);
	if (!editable) {
		multi.setHighlighter(null);
		multi.setComponentPopupMenu(null);
		multi.setInheritsPopupMenu(false);
		multi.setBackground(getBackground());
		multi.setBorder(BorderFactory.createEmptyBorder());
	} else {
		multi.getDocument().addDocumentListener(new TextChangedDocumentListener(text));
		multi.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
	}
	if (!isTypeKnown) {
		multi.setForeground(UNKNOWN_TYPE_COLOR);
	}
	return createWithScrollPane(multi);
}
 
Example 6
Source File: SettingsController.java    From VocabHunter with Apache License 2.0 5 votes vote down vote up
private void initialiseField(final TextField field, final Supplier<Object> settingGetter) {
    StringProperty textProperty = field.textProperty();
    ReadOnlyBooleanProperty focusedProperty = field.focusedProperty();

    field.setText(settingGetter.get().toString());
    textProperty.addListener((o, oldValue, newValue) -> cleanNonNegativeInteger(field::setText, newValue, oldValue));
    focusedProperty.addListener((o, old, isFocused) -> applyDefaultIfEmpty(field::setText, field::getText, settingGetter));
}
 
Example 7
Source File: SessionContext.java    From jfxvnc with Apache License 2.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(o -> {
    props.setProperty(propertyName, property.getValue());
  });
}
 
Example 8
Source File: Util.java    From ResponsiveFX with Apache License 2.0 5 votes vote down vote up
public static void bindStyleSheetToWindow(Window window, StringProperty stylesheet) {
    window.sceneProperty().addListener(e -> {
        if (window.getScene() != null) {
            window.getScene().getStylesheets().add(stylesheet.get());
        }
    });
    if (window.getScene() != null) {
        window.getScene().getStylesheets().add(stylesheet.get());
    }

    stylesheet.addListener((obs, o, n) -> {
        if (window.getScene() != null) {
            int oldPos = -1;
            if (o != null) {
                oldPos = window.getScene().getStylesheets().indexOf(o);
                window.getScene().getStylesheets().remove(o);
            }
            if (n != null) {
                if (oldPos >= 0) {
                    window.getScene().getStylesheets().add(oldPos, n);
                } else {
                    window.getScene().getStylesheets().add(n);
                }
            }
        }
    });
}
 
Example 9
Source File: PrefBind.java    From erlyberly with GNU General Public License v3.0 5 votes vote down vote up
public static void bind(final String propName, StringProperty stringProp) {
    if(props == null) {
        return;
    }
    String storedValue = (String) props.get(propName);
    if(storedValue != null) {
        stringProp.set(storedValue);
    }
    stringProp.addListener((ObservableValue<? extends String> o, String oldValue, String newValue) -> {
        set(propName, newValue);
    });
}
 
Example 10
Source File: MetaCheat.java    From jace with GNU General Public License v2.0 5 votes vote down vote up
private void addNumericValidator(StringProperty stringProperty) {
    stringProperty.addListener((ObservableValue<? extends String> prop, String oldVal, String newVal) -> {
        if (newVal == null || newVal.isEmpty()) {
            return;
        }
        if (!newVal.matches("(\\+|-)?(x|$)?[0-9a-fA-F]*")) {
            stringProperty.set("");
        }
    });
}