javafx.scene.control.TextField#setOnAction ( )源码实例Demo

下面列出了javafx.scene.control.TextField#setOnAction ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pmd-designer   文件: SmartTextFieldListCell.java
private TextField getEditingGraphic(T t) {
    Var<String> stringVar = extractEditable(t);
    final TextField textField = new TextField(stringVar.getValue());

    textField.setPromptText(getPrompt());
    ControlUtil.makeTextFieldShowPromptEvenIfFocused(textField);

    // Use onAction here rather than onKeyReleased (with check for Enter),
    // as otherwise we encounter RT-34685
    textField.setOnAction(event -> {
        stringVar.setValue(textField.getText());
        commitEdit(t);
        event.consume();
    });
    textField.setOnKeyReleased(ke -> {
        if (ke.getCode() == KeyCode.ESCAPE) {
            cancelEdit();
            ke.consume();
        }
    });
    return textField;
}
 
源代码2 项目: oim-fx   文件: WebViewContextMenuTest.java
@Override
public void start(Stage primaryStage) {
	TextField locationField = new TextField(START_URL);

	webView.getEngine().load(START_URL);

	webView.setContextMenuEnabled(false);
	createContextMenu(webView);

	locationField.setOnAction(e -> {
		webView.getEngine().load(getUrl(locationField.getText()));
	});
	BorderPane root = new BorderPane(webView, locationField, null, null, null);
	primaryStage.setScene(new Scene(root, 800, 600));
	primaryStage.show();

}
 
源代码3 项目: Path-of-Leveling   文件: AddGem_Controller.java
private void addAutoCompleteListenerToTextField(TextField whichField, ArrayList<String> autoCompleteContents) {
    whichField.setOnAction(event -> onEnter(whichField));
    JFXAutoCompletePopup<String> autoCompletePopup = new JFXAutoCompletePopup<>();
    autoCompletePopup.getSuggestions().addAll(autoCompleteContents);
    //SelectionHandler sets the value of the comboBox
    autoCompletePopup.setSelectionHandler(event -> {
        whichField.setText(event.getObject());
        onEnter(whichField);
    });
    whichField.textProperty().addListener((observable, oldVal, newVal) -> {
        String searchVal = newVal;
        if (searchVal == null  || bTransferringText ) {
            return;
        }
        searchVal = searchVal.trim().toLowerCase();
        String finalSearchVal = searchVal;
        autoCompletePopup.filter(item -> item.toLowerCase().contains(finalSearchVal));
        //Hide the autocomplete popup if the filtered suggestions is empty or when the box's original popup is open
        if (searchVal.isEmpty() || autoCompletePopup.getFilteredSuggestions().isEmpty()) {
            autoCompletePopup.hide();
        } else {
            autoCompletePopup.show(whichField);
        }
    });
}
 
源代码4 项目: FXTutorials   文件: DownloaderApp.java
private Parent createContent() {
    VBox root = new VBox();
    root.setPrefSize(400, 600);

    TextField fieldURL = new TextField();
    root.getChildren().addAll(fieldURL);

    fieldURL.setOnAction(event -> {
        Task<Void> task = new DownloadTask(fieldURL.getText());
        ProgressBar progressBar = new ProgressBar();
        progressBar.setPrefWidth(350);
        progressBar.progressProperty().bind(task.progressProperty());
        root.getChildren().add(progressBar);

        fieldURL.clear();

        Thread thread = new Thread(task);
        thread.setDaemon(true);
        thread.start();
    });

    return root;
}
 
源代码5 项目: FXTutorials   文件: View.java
public View(Controller controller) {
    this.controller = controller;

    setPrefSize(635 * 2, 500);

    Image image = new Image("http://cdn.ndtv.com/tech/windows_10_startmenu_cropped.jpg");
    ImageView originalView = new ImageView(image);

    ImageView modifiedView = new ImageView();
    modifiedView.setTranslateX(635);

    TextField field = new TextField("Enter message");
    field.setTranslateY(454);
    field.setOnAction(e -> controller.onEncode());

    Button btnDecode = new Button("DECODE");
    btnDecode.setTranslateX(635);
    btnDecode.setTranslateY(454);
    btnDecode.setOnAction(e -> controller.onDecode());

    controller.injectUI(originalView, modifiedView, field);

    getChildren().addAll(originalView, modifiedView, field, btnDecode);
}
 
源代码6 项目: FXTutorials   文件: ChatApp.java
private Parent createContent() {
    messages.setFont(Font.font(72));
    messages.setPrefHeight(550);
    TextField input = new TextField();
    input.setOnAction(event -> {
        String message = isServer ? "Server: " : "Client: ";
        message += input.getText();
        input.clear();

        messages.appendText(message + "\n");

        try {
            connection.send(message);
        }
        catch (Exception e) {
            messages.appendText("Failed to send\n");
        }
    });

    VBox root = new VBox(20, messages, input);
    root.setPrefSize(600, 600);
    return root;
}
 
源代码7 项目: phoebus   文件: CellUtiles.java
static <T> TextField createTextField(final Cell<T> cell, final StringConverter<T> converter) {
    final TextField textField = new TextField(getItemText(cell, converter));

    // Use onAction here rather than onKeyReleased (with check for Enter),
    // as otherwise we encounter RT-34685
    textField.setOnAction(event -> {
        if (converter == null) {
            throw new IllegalStateException(
                    "Attempting to convert text input into Object, but provided "
                            + "StringConverter is null. Be sure to set a StringConverter "
                            + "in your cell factory.");
        }
        cell.commitEdit(converter.fromString(textField.getText()));
        event.consume();
    });
    textField.setOnKeyReleased(t -> {
        if (t.getCode() == KeyCode.ESCAPE) {
            cell.cancelEdit();
            t.consume();
        }
    });
    return textField;
}
 
源代码8 项目: tcMenu   文件: CreatorEditingTableCell.java
private void buildEditBox(CreatorProperty prop) {
    TextField textField = new TextField(prop.getLatestValue());
    textField.setMinWidth(this.getWidth() - this.getGraphicTextGap()* 2);
    textField.focusedProperty().addListener((ObservableValue<? extends Boolean> o, Boolean old, Boolean newVal) -> {
                if (!newVal) {
                    commitEdit(textField.getText());
                }
    });

    textField.setOnAction(actionEvent -> commitEdit(textField.getText()));
    editorNode = textField;
}
 
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
	SierpinskiTrianglePane trianglePane = new SierpinskiTrianglePane();
	TextField tfOrder = new TextField();
	tfOrder.setOnAction(
		e -> trianglePane.setOrder(Integer.parseInt(tfOrder.getText())));
	tfOrder.setPrefColumnCount(4);
	tfOrder.setAlignment(Pos.BOTTOM_RIGHT);

	// Pane to hold label, text field, and a button
	HBox hBox = new HBox(10);
	hBox.getChildren().addAll(new Label("Enter an order: "), tfOrder);
	hBox.setAlignment(Pos.CENTER);

	BorderPane borderPane = new BorderPane();
	borderPane.setCenter(trianglePane);
	borderPane.setBottom(hBox);

	// Create a scene and place it in the stage
	Scene scene = new Scene(borderPane, 200, 210);
	primaryStage.setTitle("Exercise_18_36"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage

	scene.widthProperty().addListener(ov -> trianglePane.paint());
	scene.heightProperty().addListener(ov -> trianglePane.paint());
}
 
源代码10 项目: netbeans   文件: WebViewBrowser.java
public WebViewPane() {
    VBox.setVgrow(this, Priority.ALWAYS);
    setMaxWidth(Double.MAX_VALUE);
    setMaxHeight(Double.MAX_VALUE);

    WebView view = new WebView();
    view.setMinSize(500, 400);
    view.setPrefSize(500, 400);
    final WebEngine eng = view.getEngine();
    eng.load("http://www.oracle.com/us/index.html");
    final TextField locationField = new TextField("http://www.oracle.com/us/index.html");
    locationField.setMaxHeight(Double.MAX_VALUE);
    Button goButton = new Button("Go");
    goButton.setDefaultButton(true);
    EventHandler<ActionEvent> goAction = new EventHandler<ActionEvent>() {
        @Override public void handle(ActionEvent event) {
            eng.load(locationField.getText().startsWith("http://") ? locationField.getText() :
                    "http://" + locationField.getText());
        }
    };
    goButton.setOnAction(goAction);
    locationField.setOnAction(goAction);
    eng.locationProperty().addListener(new ChangeListener<String>() {
        @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            locationField.setText(newValue);
        }
    });
    GridPane grid = new GridPane();
    grid.setVgap(5);
    grid.setHgap(5);
    GridPane.setConstraints(locationField, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.SOMETIMES);
    GridPane.setConstraints(goButton,1,0);
    GridPane.setConstraints(view, 0, 1, 2, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.ALWAYS);
    grid.getColumnConstraints().addAll(
            new ColumnConstraints(100, 100, Double.MAX_VALUE, Priority.ALWAYS, HPos.CENTER, true),
            new ColumnConstraints(40, 40, 40, Priority.NEVER, HPos.CENTER, true)
    );
    grid.getChildren().addAll(locationField, goButton, view);
    getChildren().add(grid);
}
 
源代码11 项目: phoebus   文件: ClearingTextFieldDemo.java
@Override
public void start(final Stage stage)
{
    final TextField text = new ClearingTextField();
    text.setMaxWidth(Double.MAX_VALUE);
    text.setOnAction(event -> System.out.println("Text is '" + text.getText() + "'"));
    final BorderPane layout = new BorderPane(text);
    stage.setScene(new Scene(layout));
    stage.show();
}
 
源代码12 项目: Recaf   文件: RenamingTextField.java
private RenamingTextField(GuiController controller, String initialText, Consumer<RenamingTextField> renameAction) {
	this.controller = controller;
	setHideOnEscape(true);
	setAutoHide(true);
	setOnShown(e -> {
		// Center on main window
		Stage main = controller.windows().getMainWindow().getStage();
		int x = (int) (main.getX() + Math.round((main.getWidth() / 2) - (getWidth() / 2)));
		int y = (int) (main.getY() + Math.round((main.getHeight() / 2) - (getHeight() / 2)));
		setX(x);
		setY(y);
	});
	text = new TextField(initialText);
	text.getStyleClass().add("remap-field");
	text.setPrefWidth(400);
	// Close on hitting escape/close-window bind
	text.setOnKeyPressed(e -> {
		if (controller.config().keys().closeWindow.match(e) || e.getCode() == KeyCode.ESCAPE)
			hide();
	});
	// Set on-enter action
	text.setOnAction(e -> renameAction.accept(this));
	// Setup & show
	getScene().setRoot(text);
	Platform.runLater(() -> {
		text.requestFocus();
		text.selectAll();
	});
}
 
源代码13 项目: chart-fx   文件: TransposedDataSetSample.java
@Override
public void start(final Stage primaryStage) {
    // init default 2D Chart
    final XYChart chart1 = getDefaultChart();
    final ErrorDataSetRenderer renderer = (ErrorDataSetRenderer) chart1.getRenderers().get(0);
    renderer.setAssumeSortedData(false); // necessary to suppress sorted-DataSet-only optimisations

    // alternate DataSet:
    // final CosineFunction dataSet1 = new CosineFunction("test cosine", N_SAMPLES);
    final DataSet dataSet1 = test8Function(0, 4, -1, 3, (Math.PI / N_SAMPLES) * 2 * N_TURNS, 0.2, N_SAMPLES);
    final TransposedDataSet transposedDataSet1 = TransposedDataSet.transpose(dataSet1, false);
    renderer.getDatasets().add(transposedDataSet1);

    // init default 3D Chart with HeatMapRenderer
    final XYChart chart2 = getDefaultChart();
    final ContourDataSetRenderer contourRenderer = new ContourDataSetRenderer();
    chart2.getRenderers().setAll(contourRenderer);

    final DataSet dataSet2 = createTestData();
    dataSet2.getAxisDescription(DIM_X).set("x-axis", "x-unit");
    dataSet2.getAxisDescription(DIM_Y).set("y-axis", "y-unit");
    final TransposedDataSet transposedDataSet2 = TransposedDataSet.transpose(dataSet2, false);
    contourRenderer.getDatasets().add(transposedDataSet2);

    // init ToolBar items to illustrate the two different methods to flip the DataSet
    final CheckBox cbTransposed = new CheckBox("flip data set");
    final TextField textPermutation = new TextField("0,1,2");
    textPermutation.setPrefWidth(100);
    cbTransposed.setTooltip(new Tooltip("press to transpose DataSet"));
    cbTransposed.setGraphic(new Glyph(FONT_AWESOME, FONT_SYMBOL_TRANSPOSE).size(FONT_SIZE));
    final Button bApplyPermutation = new Button(null, new Glyph(FONT_AWESOME, FONT_SYMBOL_CHECK).size(FONT_SIZE));
    bApplyPermutation.setTooltip(new Tooltip("press to apply permutation"));

    // flipping method #1: via 'setTransposed(boolean)' - flips only first two axes
    cbTransposed.setOnAction(evt -> {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.atInfo().addArgument(cbTransposed.isSelected()).log("set transpose state to '{}'");
        }
        transposedDataSet1.setTransposed(cbTransposed.isSelected());
        transposedDataSet2.setTransposed(cbTransposed.isSelected());
        textPermutation.setText(Arrays.stream(transposedDataSet2.getPermutation()).boxed().map(String::valueOf).collect(Collectors.joining(",")));
    });

    // flipping method #2: via 'setPermutation(int[])' - flips arbitrary combination of axes
    final Runnable permutationAction = () -> {
        final int[] parsedInt1 = Arrays.asList(textPermutation.getText().split(","))
                                         .subList(0, transposedDataSet1.getDimension())
                                         .stream()
                                         .map(String::trim)
                                         .mapToInt(Integer::parseInt)
                                         .toArray();
        final int[] parsedInt2 = Arrays.asList(textPermutation.getText().split(","))
                                         .subList(0, transposedDataSet2.getDimension())
                                         .stream()
                                         .map(String::trim)
                                         .mapToInt(Integer::parseInt)
                                         .toArray();

        transposedDataSet1.setPermutation(parsedInt1);
        transposedDataSet2.setPermutation(parsedInt2);
    };

    textPermutation.setOnAction(evt -> permutationAction.run());
    bApplyPermutation.setOnAction(evt -> permutationAction.run());

    // the usual JavaFX Application boiler-plate code
    final ToolBar toolBar = new ToolBar(new Label("method #1 - transpose: "), cbTransposed, new Separator(),
            new Label("method #2 - permutation: "), textPermutation, bApplyPermutation);
    final HBox hBox = new HBox(chart1, chart2);

    VBox.setVgrow(hBox, Priority.ALWAYS);
    final Scene scene = new Scene(new VBox(toolBar, hBox), 800, 600);
    primaryStage.setTitle(getClass().getSimpleName());
    primaryStage.setScene(scene);
    primaryStage.show();
    primaryStage.setOnCloseRequest(evt -> Platform.exit());
}
 
源代码14 项目: mars-sim   文件: HelloWebView.java
@Override
    public void start(Stage stage) {
        List<String> args = getParameters().getRaw();
        final String initialURL = args.size() > 0 ? args.get(0) : DEFAULT_URL;

        final WebView webView = new WebView();
    	final WebEngine webEngine = webView.getEngine();

        final TextField urlBox = new TextField();
        urlBox.setMinHeight(NAVI_BAR_MIN_DIMENSION);

        urlBox.setText(initialURL);
        HBox.setHgrow(urlBox, Priority.ALWAYS);
        urlBox.setOnAction(e -> webEngine.load(urlBox.getText()));

//-        Button goButton = new Button("Go");
//-        goButton.setOnAction(e -> webEngine.load(urlBox.getText()));
        final Label bottomTitle = new Label();
        bottomTitle.textProperty().bind(urlBox.textProperty());

//-        HBox naviBar = new HBox();
//-        naviBar.getChildren().addAll(urlBox, goButton);
        final Button goStopButton = new Button(goButtonUnicodeSymbol);
        goStopButton.setStyle(buttonStyle);
        goStopButton.setOnAction(e -> webEngine.load(urlBox.getText()));

//-        BorderPane root = new BorderPane();
//-        root.setTop(naviBar);
//-        root.setCenter(webView);
        final Button backButton = new Button(backButtonUnicodeSymbol);
        backButton.setStyle(buttonStyle);
        backButton.setDisable(true);
        backButton.setOnAction(e -> webEngine.getHistory().go(-1));

//-        webEngine.locationProperty().addListener((obs, oVal, nVal)
//-                -> urlBox.setText(nVal));
        final Button forwardButton = new Button(forwardButtonUnicodeSymbol);
        forwardButton.setStyle(buttonStyle);
        forwardButton.setDisable(true);
        forwardButton.setOnAction(e -> webEngine.getHistory().go(+1));

        final Button reloadButton = new Button(reloadButtonUnicodeSymbol);
        reloadButton.setStyle(buttonStyle);
        reloadButton.setOnAction(e -> webEngine.reload());

        final HBox naviBar = new HBox();
        naviBar.getChildren().addAll(backButton, forwardButton, urlBox,
                reloadButton, goStopButton);
        naviBar.setPadding(new Insets(PADDING_VALUE)); // Small padding in the navigation Bar

        final VBox root = new VBox();
        root.getChildren().addAll(naviBar, webView, bottomTitle);
        VBox.setVgrow(webView, Priority.ALWAYS);

        webEngine.locationProperty().addListener((observable, oldValue, newValue) ->
                urlBox.setText(newValue));

        // If the Worker.State is in lower State than SUCCEEDED (i.e. in READY, SCHEDULED or RUNNING State),
        // then the goStopButton should be in 'Stop' configuration
        // else the goStopButton should be in 'Go' configuration
        webEngine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {
            if (newValue.compareTo(Worker.State.SUCCEEDED) < 0) {
                bottomTitle.setVisible(true);
                goStopButton.setText(stopButtonUnicodeSymbol);
                goStopButton.setOnAction(e -> webEngine.getLoadWorker().cancel());
            } else {
                bottomTitle.setVisible(false);
                goStopButton.setText(goButtonUnicodeSymbol);
                goStopButton.setOnAction(e -> webEngine.load(urlBox.getText()));
            }
        });

        webEngine.getHistory().currentIndexProperty().addListener((observable, oldValue, newValue) -> {
            int length = webEngine.getHistory().getEntries().size();

            backButton.setDisable((int)newValue == 0);
            forwardButton.setDisable((int)newValue >= length - 1);
        });

        webEngine.load(initialURL);

        Scene scene = new Scene(root);
        stage.setScene(scene);

//-        SimpleStringProperty titleProp = new SimpleStringProperty("HelloWebView: ");
        SimpleStringProperty titleProp = new SimpleStringProperty("HelloWebView" +
                " (" + System.getProperty("java.version") + ") : ");
        stage.titleProperty().bind(titleProp.concat(urlBox.textProperty()));
        stage.show();
    }
 
源代码15 项目: oim-fx   文件: WebViewBrowser.java
public WebViewPane() {
	VBox.setVgrow(this, Priority.ALWAYS);
	setMaxWidth(Double.MAX_VALUE);
	setMaxHeight(Double.MAX_VALUE);

	WebView webView = new WebView();
	webView.setMinSize(500, 400);
	webView.setPrefSize(500, 400);
	final WebEngine webEngine = webView.getEngine();
	webEngine.load("http://www.baidu.com");

	final TextField locationField = new TextField("http://www.baidu.com");
	Button goButton = new Button("Go");

	EventHandler<ActionEvent> goAction = new EventHandler<ActionEvent>() {
		@Override
		public void handle(ActionEvent event) {
			webEngine.load(locationField.getText().startsWith("http://") ? locationField.getText() : "http://" + locationField.getText());
		}
	};

	goButton.setDefaultButton(true);
	goButton.setOnAction(goAction);

	locationField.setMaxHeight(Double.MAX_VALUE);
	locationField.setOnAction(goAction);
	
	webEngine.locationProperty().addListener(e->{
		System.out.println(webEngine.getLocation());
	});
	
	webEngine.locationProperty().addListener(new ChangeListener<String>() {
		@Override
		public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
			locationField.setText(newValue);
		}
	});
	
	WebPage webPage  = Accessor.getPageFor(webEngine);
	
	webPage.setEditable(true);
	
	GridPane grid = new GridPane();
	grid.setVgap(5);
	grid.setHgap(5);
	GridPane.setConstraints(locationField, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.SOMETIMES);
	GridPane.setConstraints(goButton, 1, 0);
	GridPane.setConstraints(webView, 0, 1, 2, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.ALWAYS);
	grid.getColumnConstraints().addAll(
			new ColumnConstraints(100, 100, Double.MAX_VALUE, Priority.ALWAYS, HPos.CENTER, true),
			new ColumnConstraints(40, 40, 40, Priority.NEVER, HPos.CENTER, true));
	grid.getChildren().addAll(locationField, goButton, webView);
	getChildren().add(grid);
}
 
源代码16 项目: phoebus   文件: SelectedWidgetUITracker.java
/** Create an inline editor
 *
 *  <p>Depending on the widget's properties, it will edit
 *  the PV name or the text.
 *
 *  @param widget Widget on which to create an inline editor
 */
private void createInlineEditor(final Widget widget)
{
    // Check for an inline-editable property
    Optional<WidgetProperty<String>> check;

    // Defaulting to PV name or text property with some hard-coded exceptions.
    // Alternative if the list of hard-coded widgets grows:
    // Add Widget#getInlineEditableProperty()
    if (widget instanceof ActionButtonWidget)
        check = Optional.of(((ActionButtonWidget) widget).propText());
    else if (widget instanceof GroupWidget)
        check = Optional.of(((GroupWidget) widget).propName());
    else
        check = widget.checkProperty(CommonWidgetProperties.propPVName);
    if (! check.isPresent())
        check = widget.checkProperty(CommonWidgetProperties.propText);
    if (! check.isPresent())
        return;

    // Create text field, aligned with widget, but assert minimum size
    final MacroizedWidgetProperty<String> property = (MacroizedWidgetProperty<String>)check.get();
    inline_editor = new TextField(property.getSpecification());
    // 'Managed' text field would assume some default size,
    // but we set the exact size in here
    inline_editor.setManaged(false);
    inline_editor.setPromptText(property.getDescription()); // Not really shown since TextField will have focus
    inline_editor.setTooltip(new Tooltip(property.getDescription()));
    inline_editor.relocate(tracker.getX(), tracker.getY());
    inline_editor.resize(Math.max(100, tracker.getWidth()), Math.max(20, tracker.getHeight()));
    getChildren().add(inline_editor);

    // Add autocomplete menu if editing property PVName
    if (property.getName().equals(CommonWidgetProperties.propPVName.getName()))
        PVAutocompleteMenu.INSTANCE.attachField(inline_editor);

    // On enter or lost focus, update the property. On Escape, just close.
    final ChangeListener<? super Boolean> focused_listener = (prop, old, focused) ->
    {
        if (! focused)
        {
            if (!property.getSpecification().equals(inline_editor.getText()))
                undo.execute(new SetMacroizedWidgetPropertyAction(property, inline_editor.getText()));
            // Close when focus lost
            closeInlineEditor();
        }
    };

    inline_editor.setOnAction(event ->
    {
        undo.execute(new SetMacroizedWidgetPropertyAction(property, inline_editor.getText()));
        inline_editor.focusedProperty().removeListener(focused_listener);
        closeInlineEditor();
    });

    inline_editor.setOnKeyPressed(event ->
    {
        switch (event.getCode())
        {
        case ESCAPE:
            event.consume();
            inline_editor.focusedProperty().removeListener(focused_listener);
            closeInlineEditor();
        default:
        }
    });

    inline_editor.focusedProperty().addListener(focused_listener);

    inline_editor.selectAll();
    inline_editor.requestFocus();
}
 
源代码17 项目: Intro-to-Java-Programming   文件: Exercise_16_15.java
@Override // Override the start method in the Appliction class
public void start(Stage primaryStage) {
	// Set properties for combobox
	cbo.getItems().addAll("TOP", "BOTTOM", "LEFT", "RIGHT");
	cbo.setStyle("-fx-color: green");
	cbo.setValue("LEFT");

	// Create a text field
	TextField tfGap = new TextField("0");
	tfGap.setPrefColumnCount(3);

	// Create a hox to hold labels a text field and combo box
	HBox paneForSettings = new HBox(10);
	paneForSettings.setAlignment(Pos.CENTER);
	paneForSettings.getChildren().addAll(new Label("contentDisplay:"),
		cbo, new Label("graphicTextGap:"), tfGap);

	// Create an imageview
	ImageView image = new ImageView(new Image("image/grapes.gif"));

	// Label the image
	Label lblGrapes = new Label("Grapes", image);
	lblGrapes.setGraphicTextGap(0);

	// Place the image and its label in a stack pane
	StackPane paneForImage = new StackPane(lblGrapes);

	// Create and register handlers
	cbo.setOnAction(e -> {
		lblGrapes.setContentDisplay(setDisplay());
	});

	tfGap.setOnAction(e -> {
		lblGrapes.setGraphicTextGap(Integer.parseInt(tfGap.getText()));
	});

	// Place nodes in a border pane
	BorderPane pane = new BorderPane();
	pane.setTop(paneForSettings);
	pane.setCenter(paneForImage);

	// Create a scene and place it in the stage
	Scene scene = new Scene(pane, 400, 200);
	primaryStage.setTitle("Exericse_16_15"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage
}
 
源代码18 项目: BowlerStudio   文件: LinkSliderWidget.java
public LinkSliderWidget(int linkIndex, DHLink dhlink, AbstractKinematicsNR d) {

		this.linkIndex = linkIndex;
		this.device = d;
		if (DHParameterKinematics.class.isInstance(device)) {
			dhdevice = (DHParameterKinematics) device;
		}

		abstractLink = device.getAbstractLink(linkIndex);

		TextField name = new TextField(abstractLink.getLinkConfiguration().getName());
		name.setMaxWidth(100.0);
		name.setOnAction(event -> {
			abstractLink.getLinkConfiguration().setName(name.getText());
		});

		setSetpoint(new EngineeringUnitsSliderWidget(this, abstractLink.getMinEngineeringUnits(),
				abstractLink.getMaxEngineeringUnits(), device.getCurrentJointSpaceVector()[linkIndex], 180,
				dhlink.getLinkType() == DhLinkType.ROTORY ? "degrees" : "mm"));

		GridPane panel = new GridPane();

		panel.getColumnConstraints().add(new ColumnConstraints(30)); // column 1
																		// is 75
																		// wide
		panel.getColumnConstraints().add(new ColumnConstraints(120)); // column
																		// 1 is
																		// 75
																		// wide
		panel.getColumnConstraints().add(new ColumnConstraints(120)); // column
																		// 2 is
																		// 300
																		// wide

		panel.add(new Text("#" + linkIndex), 0, 0);
		panel.add(name, 1, 0);
		panel.add(getSetpoint(), 2, 0);

		getChildren().add(panel);
		abstractLink.addLinkListener(this);
		// device.addJointSpaceListener(this);

	}
 
源代码19 项目: BowlerStudio   文件: DHLinkWidget.java
public DHLinkWidget(int linkIndex, DHLink dhlink, AbstractKinematicsNR device2, Button del,IOnEngineeringUnitsChange externalListener, MobileBaseCadManager manager ) {

		this.linkIndex = linkIndex;
		this.device = device2;
		if(DHParameterKinematics.class.isInstance(device2)){
			dhdevice=(DHParameterKinematics)device2;
		}
		this.del = del;
		AbstractLink abstractLink  = device2.getAbstractLink(linkIndex);
		
		
		TextField name = new TextField(abstractLink.getLinkConfiguration().getName());
		name.setMaxWidth(100.0);
		name.setOnAction(event -> {
			abstractLink.getLinkConfiguration().setName(name.getText());
		});
		
		setpoint = new EngineeringUnitsSliderWidget(new IOnEngineeringUnitsChange() {
			
			@Override
			public void onSliderMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onSliderDoneMoving(EngineeringUnitsSliderWidget source,
					double newAngleDegrees) {
	    		try {
					device2.setDesiredJointAxisValue(linkIndex, setpoint.getValue(), 2);
					
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				};
			}
		}, 
		abstractLink.getMinEngineeringUnits(), 
		abstractLink.getMaxEngineeringUnits(), 
		device2.getCurrentJointSpaceVector()[linkIndex], 
		180,dhlink.getLinkType()==DhLinkType.ROTORY?"degrees":"mm");
		
		
		
		final Accordion accordion = new Accordion();

		if(dhdevice!=null)
			accordion.getPanes().add(new TitledPane("Configure D-H", new DhSettingsWidget(dhdevice.getChain().getLinks().get(linkIndex),dhdevice,externalListener)));
		accordion.getPanes().add(new TitledPane("Configure Link", new LinkConfigurationWidget(abstractLink.getLinkConfiguration(), device2.getFactory(),setpoint,manager)));
		
		GridPane panel = new GridPane();
		
		panel.getColumnConstraints().add(new ColumnConstraints(80)); // column 1 is 75 wide
		panel.getColumnConstraints().add(new ColumnConstraints(30)); // column 1 is 75 wide
		panel.getColumnConstraints().add(new ColumnConstraints(120)); // column 2 is 300 wide
		
		
		panel.add(	del, 
				0, 
				0);
		panel.add(	new Text("#"+linkIndex), 
				1, 
				0);
		panel.add(	name, 
				2, 
				0);
		panel.add(	setpoint, 
				3, 
				0);
		panel.add(	accordion, 
				2, 
				1);

		getChildren().add(panel);
	}
 
源代码20 项目: BowlerStudio   文件: AdjustbodyMassWidget.java
public AdjustbodyMassWidget(MobileBase device) {
	this.device = device;
	manager = MobileBaseCadManager.get(device);
	GridPane pane = new GridPane();
	
	TextField mass = new TextField(CreatureLab.getFormatted(device.getMassKg()));
	mass.setOnAction(event -> {
		device.setMassKg(textToNum(mass));
		if(manager!=null)manager.generateCad();
	});
	TransformNR currentCentroid = device.getCenterOfMassFromCentroid();
	TextField massx = new TextField(CreatureLab.getFormatted(currentCentroid.getX()));
	massx.setOnAction(event -> {
		currentCentroid.setX(textToNum(massx));
		device.setCenterOfMassFromCentroid(currentCentroid);
		;
		if(manager!=null)manager.generateCad();

	});

	TextField massy = new TextField(CreatureLab.getFormatted(currentCentroid.getY()));
	massy.setOnAction(event -> {
		currentCentroid.setY(textToNum(massy));
		device.setCenterOfMassFromCentroid(currentCentroid);
		;
		if(manager!=null)manager.generateCad();

	});

	TextField massz = new TextField(CreatureLab.getFormatted(currentCentroid.getZ()));
	massz.setOnAction(event -> {
		currentCentroid.setZ(textToNum(massz));
		device.setCenterOfMassFromCentroid(currentCentroid);
		;
		if(manager!=null)manager.generateCad();

	});
	
	
	
	pane.add(new Text("Mass"), 0, 0);
	pane.add(mass, 1, 0);

	pane.add(new Text("Mass Centroid x"), 0, 1);
	pane.add(massx, 1, 1);

	pane.add(new Text("Mass Centroid y"), 0, 2);
	pane.add(massy, 1, 2);
	pane.add(new Text("Mass Centroid z"), 0, 3);
	pane.add(massz, 1,3);
	getChildren().add(pane);
}