List of usage examples for javafx.scene.control TextField getText
public final String getText()
From source file:com.danilafe.sbaccountmanager.StarboundServerAccountManager.java
private void createAccount(ListView<String> to_update) { Stage createAccountStage = new Stage(); createAccountStage.initModality(Modality.APPLICATION_MODAL); //Set the stage info createAccountStage.setTitle("Add Server Account"); //Create a layout GridPane gp = new GridPane(); gp.setAlignment(Pos.CENTER);//from w w w . j a v a 2 s .c om gp.setVgap(10); gp.setHgap(10); gp.setPadding(new Insets(25, 25, 25, 25)); //Ads the important things Text welcome = new Text("Create Server Account"); welcome.setFont(Font.font("Century Gothic", FontWeight.NORMAL, 20)); gp.add(welcome, 0, 0, 2, 1); Label username = new Label("Username"); Label password = new Label("Password"); Label r_password = new Label("Repeat Password"); TextField usernamefield = new TextField(); PasswordField passwordfield = new PasswordField(); PasswordField r_passwordfield = new PasswordField(); gp.add(username, 0, 1); gp.add(password, 0, 2); gp.add(r_password, 0, 3); gp.add(usernamefield, 1, 1); gp.add(passwordfield, 1, 2); gp.add(r_passwordfield, 1, 3); Text error = new Text(""); HBox error_box = new HBox(10); error_box.setAlignment(Pos.CENTER); error_box.getChildren().add(error); gp.add(error_box, 0, 4, 2, 1); Button finish = new Button("Finish"); finish.setDisable(true); HBox center_button = new HBox(10); center_button.setAlignment(Pos.CENTER); center_button.getChildren().add(finish); gp.add(center_button, 0, 5, 2, 1); ChangeListener name = new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { finish.setDisable(true); if (usernamefield.getText().equals("")) { error.setFill(Color.RED); error.setText("Username can not be blank!"); } if (!passwordfield.getText().equals(r_passwordfield.getText())) { error.setFill(Color.RED); error.setText("Passwords do not match!"); } if (passwordfield.getText().equals("") && r_passwordfield.getText().equals("")) { error.setFill(Color.RED); error.setText("Passwords can not be blank!"); } if (passwordfield.getText().equals(r_passwordfield.getText()) && !usernamefield.getText().equals("") && !passwordfield.getText().equals("")) { error.setFill(Color.GREEN); error.setText("No issues."); finish.setDisable(false); } } }; usernamefield.textProperty().addListener(name); passwordfield.textProperty().addListener(name); r_passwordfield.textProperty().addListener(name); finish.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { users.remove(usernamefield.getText()); users.add(usernamefield.getText()); userpasswords.put(usernamefield.getText(), passwordfield.getText()); to_update.setItems(FXCollections.observableArrayList(users)); createAccountStage.close(); } }); //Creates the scene Scene scene = new Scene(gp, 300, 275); scene.getStylesheets().add(this.getClass().getResource("login_css.css").toExternalForm()); createAccountStage.setScene(scene); createAccountStage.show(); }
From source file:de.perdoctus.ebikeconnect.gui.dialogs.LoginDialog.java
@PostConstruct public void init() { final ImageView graphic = new ImageView( new Image(getClass().getResource("/app-icon.png").toExternalForm())); graphic.setPreserveRatio(true);//from w ww . ja va 2 s. c o m graphic.setFitHeight(64); setGraphic(graphic); setResizable(true); setWidth(400); setResizable(false); setTitle(rb.getString("dialogTitle")); setHeaderText(rb.getString("dialogMessage")); final ButtonType loginButtonType = new ButtonType(rb.getString("loginButton"), ButtonBar.ButtonData.OK_DONE); getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL); // Create the username and password labels and fields. final GridPane grid = new GridPane(); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(20, 10, 10, 10)); grid.setPrefWidth(getWidth()); grid.getColumnConstraints().add(new ColumnConstraints(-1, -1, -1, Priority.NEVER, HPos.LEFT, true)); grid.getColumnConstraints().add(new ColumnConstraints(-1, -1, -1, Priority.ALWAYS, HPos.LEFT, true)); final String rbUsername = rb.getString(CFG_USERNAME); final TextField txtUsername = new TextField(); txtUsername.setPromptText(rbUsername); txtUsername.setText(config.getString(CFG_USERNAME, "")); final Label lblUsername = new Label(rbUsername); lblUsername.setLabelFor(txtUsername); grid.add(lblUsername, 0, 0); grid.add(txtUsername, 1, 0); final String rbPassword = rb.getString(CFG_PASSWORD); final PasswordField txtPassword = new PasswordField(); txtPassword.setPromptText(rbPassword); if (config.getBoolean(CFG_SAVE_PASSWORD, false)) { txtPassword.setText(config.getString(CFG_PASSWORD, "")); } final Label lblPassword = new Label(rbPassword); lblPassword.setLabelFor(txtPassword); grid.add(lblPassword, 0, 1); grid.add(txtPassword, 1, 1); final CheckBox cbSavePassword = new CheckBox(rb.getString("save-password")); cbSavePassword.setSelected(config.getBoolean(CFG_SAVE_PASSWORD, false)); grid.add(cbSavePassword, 1, 2); getDialogPane().setContent(grid); // Enable/Disable login button depending on whether a username was entered. final Node loginButton = getDialogPane().lookupButton(loginButtonType); loginButton.disableProperty() .bind(txtUsername.textProperty().isEmpty().or(txtPassword.textProperty().isEmpty())); setResultConverter(buttonType -> { if (buttonType == loginButtonType) { config.setProperty(CFG_USERNAME, txtUsername.getText()); config.setProperty(CFG_SAVE_PASSWORD, cbSavePassword.isSelected()); if (cbSavePassword.isSelected()) { config.setProperty(CFG_PASSWORD, txtPassword.getText()); config.setProperty(CFG_PASSWORD, txtPassword.getText()); } else { config.clearProperty(CFG_PASSWORD); } return new Credentials(txtUsername.getText(), txtPassword.getText()); } else { return null; } }); if (txtUsername.getText().isEmpty()) { txtUsername.requestFocus(); } else { txtPassword.requestFocus(); txtPassword.selectAll(); } }
From source file:fruitproject.FruitProject.java
public void first(final Stage primaryStage) { GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER);//from w w w .ja v a2s . c o m grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); rows = 0; addPairs.clear(); Text lb = new Text(); lb.setText("J-Fruit"); //lb.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20)); grid.add(lb, 1, 0); final ToggleGroup grp = new ToggleGroup(); RadioButton rb1 = new RadioButton(); rb1.setText("Add Fruit file"); rb1.setUserData("add"); rb1.setToggleGroup(grp); rb1.setSelected(true); grid.add(rb1, 1, 1); RadioButton rb2 = new RadioButton(); rb2.setText("Load Fruit file"); rb2.setUserData("load"); rb2.setToggleGroup(grp); grid.add(rb2, 1, 2); Label label1 = new Label("Enter File Name:"); final TextField tfFilename = new TextField(); final HBox hb = new HBox(); hb.getChildren().addAll(label1, tfFilename); hb.setSpacing(10); hb.setVisible(false); tfFilename.setText(""); grid.add(hb, 1, 3); grp.selectedToggleProperty().addListener(new ChangeListener<Toggle>() { public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) { if (grp.getSelectedToggle() != null) { // System.out.println(grp.getSelectedToggle().getUserData().toString()); if (grp.getSelectedToggle().getUserData().toString() == "load") hb.setVisible(true); else { hb.setVisible(false); tfFilename.setText(""); } } } }); if (rb2.isSelected() == true) { hb.setVisible(true); } Button btn = new Button(); btn.setText("GO"); grid.add(btn, 1, 4); btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { //System.out.println("Hello World!"); if (tfFilename.getText() == "") second(""); else second(tfFilename.getText()); primaryStage.close(); } }); //StackPane root = new StackPane(); //root.getChildren().add(lb); //root.getChildren().add(rb1); //root.getChildren().add(rb2); //root.getChildren().add(btn); Scene scene = new Scene(grid, 400, 450); primaryStage.setTitle("Hello World!"); primaryStage.setScene(scene); primaryStage.show(); }
From source file:boundary.GraphPane.java
private Node addThresholdSlider(float min, float max) { HBox hBox = new HBox(); hBox.setPadding(new Insets(15, 12, 15, 12)); hBox.setStyle("-fx-background-color: #66FFFF;"); Label lblThreshold = new Label("Threshold: "); lblThreshold.setPrefSize(100, 20);//from w w w . java 2 s. com Label lblValue = new Label("Value: "); lblValue.setPrefSize(50, 20); TextField tfValue = new TextField(String.valueOf(min)); Slider thresholdSlider = new Slider(); thresholdSlider.setMin(Math.floor(min)); thresholdSlider.setMax(Math.ceil(max)); thresholdSlider.setMajorTickUnit(Math.ceil((max - min) / 5)); thresholdSlider.setMinorTickCount(1); thresholdSlider.setBlockIncrement(1); thresholdSlider.setSnapToTicks(true); thresholdSlider.setShowTickMarks(true); thresholdSlider.valueProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { edgePredicate.setThreshold(newValue.floatValue()); vertexPredicate.setThreshold(newValue.floatValue()); vv.repaint(); tfValue.setText(String.format(Locale.US, "%.2f", newValue.floatValue())); } }); tfValue.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { float value; try { value = Float.parseFloat(tfValue.getText()); } catch (Exception ex) { value = 0; } edgePredicate.setThreshold(value); vertexPredicate.setThreshold(value); vv.repaint(); thresholdSlider.setValue(value); } }); Label lblSearch = new Label("Search: "); lblSearch.setPrefSize(70, 20); TextField tf = new TextField(); tf.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { String toFind = tf.getText().toLowerCase(); for (NodeInfo nodeInfo : nodesHighlighted) nodeInfo.setHighlighted(false); if (nodesHighlighted.size() > 0) { nodesHighlighted.clear(); vv.repaint(); } if (toFind.length() > 2) { for (NodeInfo nodeInfo : nodes.values()) { if (nodeInfo.getUserData().toLowerCase().contains((toFind))) { nodeInfo.setHighlighted(true); nodesHighlighted.add(nodeInfo); } } if (nodesHighlighted.size() == 1) { Layout<String, String> layout = vv.getGraphLayout(); Point2D q = layout.transform(nodesHighlighted.get(0).id); Point2D lvc = vv.getRenderContext().getMultiLayerTransformer() .inverseTransform(vv.getCenter()); final double dx = (lvc.getX() - q.getX()) / 10; final double dy = (lvc.getY() - q.getY()) / 10; Runnable animator = new Runnable() { public void run() { for (int i = 0; i < 10; i++) { vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT) .translate(dx, dy); try { Thread.sleep(100); } catch (InterruptedException ex) { } } } }; Thread thread = new Thread(animator); thread.start(); } vv.repaint(); } } }); hBox.getChildren().addAll(lblThreshold, thresholdSlider, lblValue, tfValue, lblSearch, tf); return hBox; }
From source file:com.chart.SwingChart.java
/** * Set lower and upper limits for an ordinate * @param axis Axis to configure// w ww . j a v a2 s.c om */ void setOrdinateRange(final NumberAxis axis) { axis.setAutoRange(false); GridPane grid = new GridPane(); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(0, 10, 0, 10)); final TextField tfMax; final TextField tfMin; final TextField tfTick; final TextField tfFuente; grid.add(new Label("Axis"), 0, 0); grid.add(new Label(axis.getLabel()), 1, 0); grid.add(new Label("Lower"), 0, 1); grid.add(tfMin = new TextField(), 1, 1); grid.add(new Label("Upper"), 0, 2); grid.add(tfMax = new TextField(), 1, 2); grid.add(new Label("Space"), 0, 3); grid.add(tfTick = new TextField(), 1, 3); tfMin.setText(String.valueOf(axis.getLowerBound())); tfMax.setText(String.valueOf(axis.getUpperBound())); tfTick.setText(String.valueOf(axis.getTickUnit().getSize())); new PseudoModalDialog(skeleton, grid, true) { @Override public boolean validation() { axis.setLowerBound(Double.valueOf(tfMin.getText())); axis.setUpperBound(Double.valueOf(tfMax.getText())); axis.setTickUnit(new NumberTickUnit(Double.valueOf(tfTick.getText()))); return true; } }.show(); }
From source file:com.chart.SwingChart.java
/** * Background edition/*from w ww. jav a 2s. c o m*/ */ final public void backgroundEdition() { final ColorPicker colorPickerChartBackground = new ColorPicker( javafx.scene.paint.Color.web(strChartBackgroundColor)); colorPickerChartBackground.setMaxWidth(Double.MAX_VALUE); final ColorPicker colorPickerGridline = new ColorPicker(javafx.scene.paint.Color.web(strGridlineColor)); colorPickerGridline.setMaxWidth(Double.MAX_VALUE); final ColorPicker colorPickerBackground = new ColorPicker(javafx.scene.paint.Color.web(strBackgroundColor)); colorPickerBackground.setMaxWidth(Double.MAX_VALUE); final ColorPicker colorPickerTick = new ColorPicker(javafx.scene.paint.Color.web(strTickColor)); colorPickerTick.setMaxWidth(Double.MAX_VALUE); final TextField tfFontSize = new TextField(); tfFontSize.setMaxWidth(Double.MAX_VALUE); GridPane grid = new GridPane(); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(0, 10, 0, 10)); grid.add(new Label("Background color"), 0, 0); grid.add(colorPickerChartBackground, 1, 0); grid.add(new Label("Gridline color"), 0, 1); grid.add(colorPickerGridline, 1, 1); grid.add(new Label("Frame color"), 0, 2); grid.add(colorPickerBackground, 1, 2); grid.add(new Label("Tick color"), 0, 3); grid.add(colorPickerTick, 1, 3); grid.add(new Label("Font size"), 0, 4); grid.add(tfFontSize, 1, 4); tfFontSize.setText(String.valueOf(fontSize)); new PseudoModalDialog(skeleton, grid, true) { @Override public boolean validation() { fontSize = Float.valueOf(tfFontSize.getText().replace(",", ".")); strBackgroundColor = colorPickerBackground.getValue().toString().replace("0x", "#"); for (Node le : legendFrame.getChildren()) { if (le instanceof LegendAxis) { le.setStyle("-fx-background-color:" + strBackgroundColor); ((LegendAxis) le).selected = false; } } chart.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor))); chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder( scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor))))); chartPanel.setBackground(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor))); legendFrame.setStyle("marco: " + colorPickerBackground.getValue().toString().replace("0x", "#") + ";-fx-background-color: marco;"); strChartBackgroundColor = colorPickerChartBackground.getValue().toString().replace("0x", "#"); plot.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strChartBackgroundColor))); for (Node le : legendFrame.getChildren()) { if (le instanceof LegendAxis) { le.setStyle("-fx-background-color:" + strBackgroundColor); ((LegendAxis) le).selected = false; for (Node nn : ((LegendAxis) le).getChildren()) { if (nn instanceof Label) { ((Label) nn).setStyle("fondo: " + colorPickerChartBackground.getValue().toString().replace("0x", "#") + ";-fx-background-color: fondo;-fx-text-fill: ladder(fondo, white 49%, black 50%);-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: " + String.valueOf(fontSize) + "px"); } } } } strGridlineColor = colorPickerGridline.getValue().toString().replace("0x", "#"); plot.setDomainGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor))); plot.setRangeGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor))); strTickColor = colorPickerTick.getValue().toString().replace("0x", "#"); abcissaAxis.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor))); abcissaAxis.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor))); abcissaAxis.setLabelFont(abcissaAxis.getLabelFont().deriveFont(fontSize)); abcissaAxis.setTickLabelFont(abcissaAxis.getLabelFont().deriveFont(fontSize)); for (NumberAxis ejeOrdenada : AxesList) { ejeOrdenada.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor))); ejeOrdenada.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor))); ejeOrdenada.setLabelFont(ejeOrdenada.getLabelFont().deriveFont(fontSize)); ejeOrdenada.setTickLabelFont(ejeOrdenada.getLabelFont().deriveFont(fontSize)); } return true; } }.show(); }
From source file:de.bayern.gdi.gui.Controller.java
private List<ProcessingStep> extractProcessingSteps() { List<ProcessingStep> steps = new ArrayList<>(); if (!this.chkChain.isSelected()) { return steps; }/*from ww w .ja va 2 s.co m*/ Set<Node> parameter = this.chainContainer.lookupAll("#process_parameter"); if (parameter.isEmpty()) { return steps; } String format = this.dataBean.getAttributeValue(OUTPUTFORMAT); if (format == null || format.isEmpty()) { setStatusTextUI(I18n.getMsg(GUI_PROCESS_NO_FORMAT)); logToAppLog(I18n.getMsg(GUI_PROCESS_NO_FORMAT)); return steps; } MIMETypes mtypes = Config.getInstance().getMimeTypes(); MIMEType mtype = mtypes.findByName(format); if (mtype == null) { setStatusTextUI(I18n.getMsg(GUI_PROCESS_FORMAT_NOT_FOUND)); logToAppLog(I18n.getMsg(GUI_PROCESS_FORMAT_NOT_FOUND)); return steps; } for (Node n : parameter) { Set<Node> vars = n.lookupAll("#process_var"); Node nameNode = n.lookup("#process_name"); ComboBox namebox = (ComboBox) nameNode; ProcessingStepConfiguration psc = (ProcessingStepConfiguration) namebox.getValue(); String name = psc.getName(); if (!psc.isCompatibleWithFormat(mtype.getType())) { setStatusTextUI(I18n.format(GUI_PROCESS_NOT_COMPATIBLE, name)); logToAppLog(I18n.format(GUI_PROCESS_NOT_COMPATIBLE, name)); continue; } ProcessingStep step = new ProcessingStep(); steps.add(step); step.setName(name); ArrayList<Parameter> parameters = new ArrayList<>(); step.setParameters(parameters); for (Node v : vars) { String varName = null; String varValue = null; if (v instanceof TextField) { TextField input = (TextField) v; varName = input.getUserData().toString(); varValue = input.getText(); } else if (v instanceof ComboBox) { ComboBox input = (ComboBox) v; varName = input.getUserData().toString(); varValue = input.getValue() != null ? ((Option) input.getValue()).getValue() : null; } if (varName != null && varValue != null) { Parameter p = new Parameter(varName, varValue); parameters.add(p); } } } return steps; }
From source file:qupath.lib.gui.tma.TMASummaryViewer.java
private Pane getCustomizeTablePane() { TableView<TreeTableColumn<TMAEntry, ?>> tableColumns = new TableView<>(); tableColumns.setPlaceholder(new Text("No columns available")); tableColumns.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); tableColumns.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); SortedList<TreeTableColumn<TMAEntry, ?>> sortedColumns = new SortedList<>( table.getColumns().filtered(p -> !p.getText().trim().isEmpty())); sortedColumns.setComparator((c1, c2) -> c1.getText().compareTo(c2.getText())); tableColumns.setItems(sortedColumns); sortedColumns.comparatorProperty().bind(tableColumns.comparatorProperty()); // sortedColumns.comparatorProperty().bind(tableColumns.comparatorProperty()); TableColumn<TreeTableColumn<TMAEntry, ?>, String> columnName = new TableColumn<>("Column"); columnName.setCellValueFactory(v -> v.getValue().textProperty()); TableColumn<TreeTableColumn<TMAEntry, ?>, Boolean> columnVisible = new TableColumn<>("Visible"); columnVisible.setCellValueFactory(v -> v.getValue().visibleProperty()); // columnVisible.setCellValueFactory(col -> { // SimpleBooleanProperty prop = new SimpleBooleanProperty(col.getValue().isVisible()); // prop.addListener((v, o, n) -> col.getValue().setVisible(n)); // return prop; // });/*from w w w.ja v a2 s . c o m*/ tableColumns.setEditable(true); columnVisible.setCellFactory(v -> new CheckBoxTableCell<>()); tableColumns.getColumns().add(columnName); tableColumns.getColumns().add(columnVisible); ContextMenu contextMenu = new ContextMenu(); Action actionShowSelected = new Action("Show selected", e -> { for (TreeTableColumn<?, ?> col : tableColumns.getSelectionModel().getSelectedItems()) { if (col != null) col.setVisible(true); else { // Not sure why this happens...? logger.trace("Selected column is null!"); } } }); Action actionHideSelected = new Action("Hide selected", e -> { for (TreeTableColumn<?, ?> col : tableColumns.getSelectionModel().getSelectedItems()) { if (col != null) col.setVisible(false); else { // Not sure why this happens...? logger.trace("Selected column is null!"); } } }); contextMenu.getItems().addAll(ActionUtils.createMenuItem(actionShowSelected), ActionUtils.createMenuItem(actionHideSelected)); tableColumns.setContextMenu(contextMenu); tableColumns.setTooltip( new Tooltip("Show or hide table columns - right-click to change multiple columns at once")); BorderPane paneColumns = new BorderPane(tableColumns); paneColumns.setBottom(PanelToolsFX.createColumnGridControls(ActionUtils.createButton(actionShowSelected), ActionUtils.createButton(actionHideSelected))); VBox paneRows = new VBox(); // Create a box to filter on some metadata text ComboBox<String> comboMetadata = new ComboBox<>(); comboMetadata.setItems(metadataNames); comboMetadata.getSelectionModel().getSelectedItem(); comboMetadata.setPromptText("Select column"); TextField tfFilter = new TextField(); CheckBox cbExact = new CheckBox("Exact"); // Set listeners cbExact.selectedProperty().addListener( (v, o, n) -> setMetadataTextPredicate(comboMetadata.getSelectionModel().getSelectedItem(), tfFilter.getText(), cbExact.isSelected(), !cbExact.isSelected())); tfFilter.textProperty().addListener( (v, o, n) -> setMetadataTextPredicate(comboMetadata.getSelectionModel().getSelectedItem(), tfFilter.getText(), cbExact.isSelected(), !cbExact.isSelected())); comboMetadata.getSelectionModel().selectedItemProperty().addListener( (v, o, n) -> setMetadataTextPredicate(comboMetadata.getSelectionModel().getSelectedItem(), tfFilter.getText(), cbExact.isSelected(), !cbExact.isSelected())); GridPane paneMetadata = new GridPane(); paneMetadata.add(comboMetadata, 0, 0); paneMetadata.add(tfFilter, 1, 0); paneMetadata.add(cbExact, 2, 0); paneMetadata.setPadding(new Insets(10, 10, 10, 10)); paneMetadata.setVgap(2); paneMetadata.setHgap(5); comboMetadata.setMaxWidth(Double.MAX_VALUE); GridPane.setHgrow(tfFilter, Priority.ALWAYS); GridPane.setFillWidth(comboMetadata, Boolean.TRUE); GridPane.setFillWidth(tfFilter, Boolean.TRUE); TitledPane tpMetadata = new TitledPane("Metadata filter", paneMetadata); tpMetadata.setExpanded(false); // tpMetadata.setCollapsible(false); Tooltip tooltipMetadata = new Tooltip( "Enter text to filter entries according to a selected metadata column"); Tooltip.install(paneMetadata, tooltipMetadata); tpMetadata.setTooltip(tooltipMetadata); paneRows.getChildren().add(tpMetadata); // Add measurement predicate TextField tfCommand = new TextField(); tfCommand.setTooltip(new Tooltip("Predicate used to filter entries for inclusion")); TextFields.bindAutoCompletion(tfCommand, e -> { int ind = tfCommand.getText().lastIndexOf("\""); if (ind < 0) return Collections.emptyList(); String part = tfCommand.getText().substring(ind + 1); return measurementNames.stream().filter(n -> n.startsWith(part)).map(n -> "\"" + n + "\" ") .collect(Collectors.toList()); }); String instructions = "Enter a predicate to filter entries.\n" + "Only entries passing the test will be included in any results.\n" + "Examples of predicates include:\n" + " \"Num Tumor\" > 200\n" + " \"Num Tumor\" > 100 && \"Num Stroma\" < 1000"; // labelInstructions.setTooltip(new Tooltip("Note: measurement names must be in \"inverted commands\" and\n" + // "&& indicates 'and', while || indicates 'or'.")); BorderPane paneMeasurementFilter = new BorderPane(tfCommand); Label label = new Label("Predicate: "); label.setAlignment(Pos.CENTER); label.setMaxHeight(Double.MAX_VALUE); paneMeasurementFilter.setLeft(label); Button btnApply = new Button("Apply"); btnApply.setOnAction(e -> { TablePredicate predicateNew = new TablePredicate(tfCommand.getText()); if (predicateNew.isValid()) { predicateMeasurements.set(predicateNew); } else { DisplayHelpers.showErrorMessage("Invalid predicate", "Current predicate '" + tfCommand.getText() + "' is invalid!"); } e.consume(); }); TitledPane tpMeasurementFilter = new TitledPane("Measurement filter", paneMeasurementFilter); tpMeasurementFilter.setExpanded(false); Tooltip tooltipInstructions = new Tooltip(instructions); tpMeasurementFilter.setTooltip(tooltipInstructions); Tooltip.install(paneMeasurementFilter, tooltipInstructions); paneMeasurementFilter.setRight(btnApply); paneRows.getChildren().add(tpMeasurementFilter); logger.info("Predicate set to: {}", predicateMeasurements.get()); VBox pane = new VBox(); // TitledPane tpColumns = new TitledPane("Select column", paneColumns); // tpColumns.setMaxHeight(Double.MAX_VALUE); // tpColumns.setCollapsible(false); pane.getChildren().addAll(paneColumns, new Separator(), paneRows); VBox.setVgrow(paneColumns, Priority.ALWAYS); return pane; }
From source file:de.bayern.gdi.gui.Controller.java
private void extractStoredQuery() { ItemModel data = this.dataBean.getDatatype(); if (data instanceof StoredQueryModel) { this.dataBean.setAttributes(new ArrayList<DataBean.Attribute>()); ObservableList<Node> children = this.simpleWFSContainer.getChildren(); for (Node n : children) { if (n.getClass() == HBox.class) { HBox hbox = (HBox) n;/*from ww w . j ava 2 s . c o m*/ ObservableList<Node> hboxChildren = hbox.getChildren(); String value = ""; String name = ""; String type = ""; Label l1 = null; Label l2 = null; TextField tf = null; ComboBox cb = null; for (Node hn : hboxChildren) { if (hn.getClass() == ComboBox.class) { cb = (ComboBox) hn; } if (hn.getClass() == TextField.class) { tf = (TextField) hn; } if (hn.getClass() == Label.class) { if (l1 == null) { l1 = (Label) hn; } if (l1 != (Label) hn) { l2 = (Label) hn; } } if (tf != null && (l1 != null || l2 != null)) { name = tf.getUserData().toString(); value = tf.getText(); if (l2 != null && l1.getText().equals(name)) { type = l2.getText(); } else { type = l1.getText(); } } if (cb != null && (l1 != null || l2 != null) && cb.getId().equals(UIFactory.getDataFormatID())) { name = OUTPUTFORMAT; if (cb.getSelectionModel() != null && cb.getSelectionModel().getSelectedItem() != null) { value = cb.getSelectionModel().getSelectedItem().toString(); type = ""; } else { Platform.runLater(() -> setStatusTextUI(I18n.getMsg(GUI_FORMAT_NOT_SELECTED))); } } if (!name.isEmpty() && !value.isEmpty()) { this.dataBean.addAttribute(name, value, type); } } } } } }
From source file:ambroafb.general.mapeditor.MapEditor.java
public MapEditor() { this.setEditable(true); itemsMap = new HashMap<>(); delimiter = " : "; // default value of delimiter keyPattern = ""; // (?<![\\d-])\\d+ valuePattern = ""; // [0-9]{1,13}(\\.[0-9]*)? keySpecChars = ""; valueSpecChars = ""; this.setCellFactory((ListView<MapEditorElement> param) -> new CustomCell()); removeElement = (MapEditorElement elem) -> { if (itemsMap.containsKey(elem.getKey())) { itemsMap.remove(elem.getKey()); if (getValue() != null && getValue().compare(elem) == 0) { getEditor().setText(delimiter); }//w ww . j a v a 2s. c om getItems().remove(elem); } }; editElement = (MapEditorElement elem) -> { getSelectionModel().select(-1); getEditor().setText(elem.getKey() + delimiter + elem.getValue()); itemsMap.remove(elem.getKey()); getItems().remove(elem); }; // Never hide comboBox items listView: this.setSkin(new ComboBoxListViewSkin(this) { @Override protected boolean isHideOnClickEnabled() { return false; } }); // Control textField input. TextField editor = getEditor(); editor.setText(delimiter); editor.textProperty() .addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> { if (newValue == null || newValue.isEmpty() || newValue.equals(delimiter)) { editor.setText(delimiter); } else if (!newValue.contains(delimiter)) { editor.setText(oldValue); } else { String keyInput = StringUtils.substringBefore(newValue, delimiter).trim(); String valueInput = StringUtils.substringAfter(newValue, delimiter).trim(); if (!keyInput.isEmpty() && !Pattern.matches(keyPattern, keyInput)) { keyInput = StringUtils.substringBefore(oldValue, delimiter).trim(); } if (!valueInput.isEmpty() && !Pattern.matches(valuePattern, valueInput)) { valueInput = StringUtils.substringAfter(oldValue, delimiter).trim(); } editor.setText(keyInput + delimiter + valueInput); } }); this.setConverter(new StringConverter<MapEditorElement>() { @Override public String toString(MapEditorElement object) { if (object == null) { return delimiter; } return object.getKey() + delimiter + object.getValue(); } @Override public MapEditorElement fromString(String input) { MapEditorElement result = null; if (input != null && input.contains(delimiter)) { result = getNewInstance(); if (result == null) return null; String keyInput = StringUtils.substringBefore(input, delimiter).trim(); String valueInput = StringUtils.substringAfter(input, delimiter).trim(); if (!keyInput.isEmpty()) { result.setKey(keyInput); } if (!valueInput.isEmpty()) { result.setValue(valueInput); } boolean keyOutOfSpec = keySpecChars.isEmpty() || !StringUtils.containsOnly(result.getKey(), keySpecChars); boolean valueOutOfSpec = valueSpecChars.isEmpty() || !StringUtils.containsOnly(result.getValue(), valueSpecChars); if (!keyInput.isEmpty() && !valueInput.isEmpty() && !itemsMap.containsKey(keyInput) && (keyOutOfSpec && valueOutOfSpec)) { itemsMap.put(keyInput, result); getItems().add(result); return null; } } return result; } }); // Control caret position in textField. editor.addEventFilter(KeyEvent.KEY_PRESSED, (KeyEvent event) -> { int caretOldPos = editor.getCaretPosition(); int delimiterIndex = editor.getText().indexOf(delimiter); if (event.getCode().equals(KeyCode.RIGHT)) { if (caretOldPos + 1 > delimiterIndex && caretOldPos + 1 <= delimiterIndex + delimiter.length()) { editor.positionCaret(delimiterIndex + delimiter.length()); event.consume(); } } else if (event.getCode().equals(KeyCode.LEFT)) { if (caretOldPos - 1 >= delimiterIndex && caretOldPos - 1 < delimiterIndex + delimiter.length()) { editor.positionCaret(delimiterIndex); event.consume(); } } }); }