public void stopAction() { collecting = false; jsonDataCollector.getListeners().stream().forEach(RecordListener::stop); toggleButtons(); jsonDataCollector.getListeners().stream().forEach(s -> s.dump("Data")); startButton.setDefaultButton(true); stopButton.setDefaultButton(false); }
public void startAction() { collecting = true; jsonDataCollector.getListeners().stream().forEach(RecordListener::start); startButton.setDefaultButton(false); stopButton.setDefaultButton(true); toggleButtons(); // todo must be killed by stop action new Thread( () -> { while (collecting) { hub.run(100); } System.out.println("collecting = " + collecting); }) .start(); }
public AlertHandler(String message, EventHandler<ActionEvent> confirmHandler) { super(14); // add controls to the popup. final Label promptMessage = new Label(message); final ImageView alertImage = new ImageView(ResourceUtil.getImage("alert_48.png")); alertImage.setFitHeight(32); alertImage.setPreserveRatio(true); promptMessage.setGraphic(alertImage); promptMessage.setWrapText(true); promptMessage.setPrefWidth(350); // action button text setup. HBox buttonBar = new HBox(20); final Button confirmButton = new Button(getString("dialog.continue")); confirmButton.setDefaultButton(true); buttonBar.getChildren().addAll(confirmButton); // layout the popup. setPadding(new Insets(10)); getStyleClass().add("alert-dialog"); getChildren().addAll(promptMessage, buttonBar); final DropShadow dropShadow = new DropShadow(); setEffect(dropShadow); // confirm and close the popup. confirmButton.setOnAction(confirmHandler); }
@Override public void initialize(URL arg0, ResourceBundle arg1) { btScan.disableProperty().bind(viewModel.scanAllowedProperty().not()); lbScan.textProperty().bind(viewModel.messageProperty()); tfScan.textProperty().bindBidirectional(viewModel.scannedValueProperty()); btScan.setDefaultButton(true); }
public static Button addButton(GridPane gridPane, int rowIndex, String title) { Button button = new Button(title); button.setDefaultButton(true); GridPane.setRowIndex(button, rowIndex); GridPane.setColumnIndex(button, 1); gridPane.getChildren().add(button); return button; }
public static Button addButtonAfterGroup(GridPane gridPane, int rowIndex, String title) { Button button = new Button(title); button.setDefaultButton(true); GridPane.setRowIndex(button, rowIndex); GridPane.setColumnIndex(button, 1); GridPane.setMargin(button, new Insets(15, 0, 0, 0)); gridPane.getChildren().add(button); return button; }
private void addContent() { addMultilineLabel( gridPane, ++rowIndex, "Please use that only in emergency case if you cannot access your fund from the UI.\n" + "Before you use this tool, you should backup your data directory. After you have successfully transferred your wallet balance, remove" + " the db directory inside the data directory to start with a newly created and consistent data structure.\n" + "Please make a bug report on Github so that we can investigate what was causing the problem.", 10); Coin totalBalance = walletService.getAvailableBalance(); boolean isBalanceSufficient = totalBalance.compareTo(FeePolicy.TX_FEE) >= 0; addressTextField = addLabelTextField( gridPane, ++rowIndex, "Your available wallet balance:", formatter.formatCoinWithCode(totalBalance), 10) .second; Tuple2<Label, InputTextField> tuple = addLabelInputTextField(gridPane, ++rowIndex, "Your destination address:"); addressInputTextField = tuple.second; emptyWalletButton = new Button("Empty wallet"); emptyWalletButton.setDefaultButton(isBalanceSufficient); emptyWalletButton.setDisable( !isBalanceSufficient && addressInputTextField.getText().length() > 0); emptyWalletButton.setOnAction( e -> { if (addressInputTextField.getText().length() > 0 && isBalanceSufficient) { if (walletService.getWallet().isEncrypted()) { walletPasswordPopup .onClose(() -> blurAgain()) .onAesKey(aesKey -> doEmptyWallet(aesKey)) .show(); } else { doEmptyWallet(null); } } }); closeButton = new Button("Cancel"); closeButton.setOnAction( e -> { hide(); closeHandlerOptional.ifPresent(closeHandler -> closeHandler.run()); }); HBox hBox = new HBox(); hBox.setSpacing(10); GridPane.setRowIndex(hBox, ++rowIndex); GridPane.setColumnIndex(hBox, 1); hBox.getChildren().addAll(emptyWalletButton, closeButton); gridPane.getChildren().add(hBox); GridPane.setMargin(hBox, new Insets(10, 0, 0, 0)); }
/** Shows this Notifications popup */ public void show() { // Use a gridpane to display the component GridPane pane = new GridPane(); // Need a new scene to display the popup Scene scene = new Scene(pane); // Set the padding and gaps to 5px pane.setPadding(new Insets(5)); pane.setHgap(5); pane.setVgap(5); // Add the message as a label if there is one if (message != null) { Label lblMsg = new Label(message); lblMsg.setPadding(new Insets(20)); pane.add(lblMsg, 0, 0, 3, 1); } // Add the yes/no buttons if there are any if (yesNoBtns) { Button btnYes = new Button("Yes"); Button btnNo = new Button("No"); // Add the events and set as default/cancel buttons btnYes.setDefaultButton(true); btnYes.setOnAction(yesNoEvent); btnNo.setCancelButton(true); btnNo.setOnAction(yesNoEvent); // Align them to the right GridPane.setHalignment(btnNo, HPos.RIGHT); GridPane.setHalignment(btnYes, HPos.RIGHT); // Push the buttons to the right Region spacer = new Region(); GridPane.setHgrow(spacer, Priority.ALWAYS); pane.add(spacer, 0, 1); pane.add(btnNo, 1, 1); pane.add(btnYes, 2, 1); } // Create a new stage to show the scene Stage stage = new Stage(); stage.setScene(scene); // Don't want the popup to be resizable stage.setResizable(false); // Set the title if there is one if (title != null) { stage.setTitle(title); } // Resize it and show it stage.sizeToScene(); stage.showAndWait(); }
private void addNewItemsDialog() { final Stage secondaryStage = new Stage(); final Group grp = new Group(); final Scene secondaryScene = new Scene(grp, 300, 200, Color.BISQUE); // ------------------------------------ Font fnt = Font.font("Dialog", 0xc); Text nameTxt = new Text(30, 30, "Enter name of Cafe Item!"); nameTxt.setFont(fnt); nameTxt.setFill(Color.DARKGRAY); grp.getChildren().add(nameTxt); final TextField nameField = new TextField(); nameField.setLayoutX(30); nameField.setLayoutY(40); nameField.setMinWidth(240); nameField.setPromptText("Enter Name of Item"); grp.getChildren().add(nameField); Text priceTxt = new Text(30, 90, "Enter price of Cafe Item! (NUMBER)"); priceTxt.setFont(fnt); priceTxt.setFill(Color.DARKGRAY); grp.getChildren().add(priceTxt); final TextField priceField = new TextField(); priceField.setLayoutX(30); priceField.setLayoutY(100); priceField.setMinWidth(240); priceField.setPromptText("Enter Price of Item (NUMBER)"); grp.getChildren().add(priceField); Button saveButton = new Button("Save"); saveButton.setLayoutX(230); saveButton.setLayoutY(170); saveButton.setDefaultButton(true); grp.getChildren().add(saveButton); saveButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { CafePricingPersistence.addCafeItems( nameField.getText().toUpperCase(), priceField.getText()); secondaryStage.close(); new CafePricingDialog(); } }); // ------------------------------------ secondaryStage.setScene(secondaryScene); secondaryStage.setResizable(false); secondaryStage.setTitle("Add Info"); secondaryStage.show(); }
public static Tuple2<Button, Button> add2ButtonsAfterGroup( GridPane gridPane, int rowIndex, String title1, String title2, double top) { HBox hBox = new HBox(); hBox.setSpacing(10); Button button1 = new Button(title1); button1.setDefaultButton(true); Button button2 = new Button(title2); hBox.getChildren().addAll(button1, button2); GridPane.setRowIndex(hBox, rowIndex); GridPane.setColumnIndex(hBox, 1); GridPane.setMargin(hBox, new Insets(top, 10, 0, 0)); gridPane.getChildren().add(hBox); return new Tuple2<>(button1, button2); }
public static Tuple2<Button, CheckBox> addButtonCheckBox( GridPane gridPane, int rowIndex, String buttonTitle, String checkBoxTitle, double top) { Button button = new Button(buttonTitle); button.setDefaultButton(true); CheckBox checkBox = new CheckBox(checkBoxTitle); HBox.setMargin(checkBox, new Insets(6, 0, 0, 0)); HBox hBox = new HBox(); hBox.setSpacing(20); hBox.getChildren().addAll(button, checkBox); GridPane.setRowIndex(hBox, rowIndex); GridPane.setColumnIndex(hBox, 1); hBox.setPadding(new Insets(top, 0, 0, 0)); gridPane.getChildren().add(hBox); return new Tuple2<>(button, checkBox); }
public static Tuple3<Label, ComboBox, Button> addLabelComboBoxButton( GridPane gridPane, int rowIndex, String title, String buttonTitle, double top) { Label label = addLabel(gridPane, rowIndex, title, top); HBox hBox = new HBox(); hBox.setSpacing(10); Button button = new Button(buttonTitle); button.setDefaultButton(true); ComboBox comboBox = new ComboBox(); hBox.getChildren().addAll(comboBox, button); GridPane.setRowIndex(hBox, rowIndex); GridPane.setColumnIndex(hBox, 1); GridPane.setMargin(hBox, new Insets(15, 0, 0, 0)); gridPane.getChildren().add(hBox); return new Tuple3<>(label, comboBox, button); }
public Parent createContent() { // create a button for initializing our new stage Button button = new Button("Create a Stage"); button.setStyle("-fx-font-size: 24;"); button.setDefaultButton(true); button.setOnAction( (ActionEvent t) -> { final Stage stage = new Stage(); // create root node of scene, i.e. group Group rootGroup = new Group(); // create scene with set width, height and color Scene scene = new Scene(rootGroup, 200, 200, Color.WHITESMOKE); // set scene to stage stage.setScene(scene); // set title to stage stage.setTitle("New stage"); // center stage on screen stage.centerOnScreen(); // show the stage stage.show(); // add some node to scene Text text = new Text(20, 110, "JavaFX"); text.setFill(Color.DODGERBLUE); text.setEffect(new Lighting()); text.setFont(Font.font(Font.getDefault().getFamily(), 50)); // add text to the main root group rootGroup.getChildren().add(text); }); return button; }
public static Tuple3<Button, ProgressIndicator, Label> addButtonWithStatus( GridPane gridPane, int rowIndex, String buttonTitle, double top) { HBox hBox = new HBox(); hBox.setSpacing(10); Button button = new Button(buttonTitle); button.setDefaultButton(true); ProgressIndicator progressIndicator = new ProgressIndicator(0); progressIndicator.setPrefHeight(24); progressIndicator.setPrefWidth(24); progressIndicator.setVisible(false); Label label = new Label(); label.setPadding(new Insets(5, 0, 0, 0)); hBox.getChildren().addAll(button, progressIndicator, label); GridPane.setRowIndex(hBox, rowIndex); GridPane.setColumnIndex(hBox, 1); GridPane.setMargin(hBox, new Insets(top, 0, 0, 0)); gridPane.getChildren().add(hBox); return new Tuple3<>(button, progressIndicator, label); }
private void onSelectDispute(Dispute dispute) { if (dispute == null) { if (root.getChildren().size() > 1) root.getChildren().remove(1); selectedDispute = null; } else if (selectedDispute != dispute) { this.selectedDispute = dispute; boolean isTrader = disputeManager.isTrader(dispute); TableGroupHeadline tableGroupHeadline = new TableGroupHeadline(); tableGroupHeadline.setText("Messages"); tableGroupHeadline.prefWidthProperty().bind(root.widthProperty()); AnchorPane.setTopAnchor(tableGroupHeadline, 10d); AnchorPane.setRightAnchor(tableGroupHeadline, 0d); AnchorPane.setBottomAnchor(tableGroupHeadline, 0d); AnchorPane.setLeftAnchor(tableGroupHeadline, 0d); ObservableList<DisputeDirectMessage> list = dispute.getDisputeDirectMessagesAsObservableList(); SortedList<DisputeDirectMessage> sortedList = new SortedList<>(list); sortedList.setComparator((o1, o2) -> o1.getDate().compareTo(o2.getDate())); list.addListener((ListChangeListener<DisputeDirectMessage>) c -> scrollToBottom()); messageListView = new ListView<>(sortedList); messageListView.setId("message-list-view"); messageListView.prefWidthProperty().bind(root.widthProperty()); messageListView.setMinHeight(150); AnchorPane.setTopAnchor(messageListView, 30d); AnchorPane.setRightAnchor(messageListView, 0d); AnchorPane.setLeftAnchor(messageListView, 0d); messagesAnchorPane = new AnchorPane(); messagesAnchorPane.prefWidthProperty().bind(root.widthProperty()); VBox.setVgrow(messagesAnchorPane, Priority.ALWAYS); inputTextArea = new TextArea(); inputTextArea.setPrefHeight(70); inputTextArea.setWrapText(true); Button sendButton = new Button("Send"); sendButton.setDefaultButton(true); sendButton.setOnAction(e -> onSendMessage(inputTextArea.getText(), dispute)); sendButton.setDisable(true); inputTextArea .textProperty() .addListener( (observable, oldValue, newValue) -> { sendButton.setDisable( newValue.length() == 0 && tempAttachments.size() == 0 && dispute.disputeResultProperty().get() == null); }); Button uploadButton = new Button("Add attachments"); uploadButton.setOnAction(e -> onRequestUpload()); sendMsgInfoLabel = new Label(); sendMsgInfoLabel.setVisible(false); sendMsgInfoLabel.setManaged(false); sendMsgInfoLabel.setPadding(new Insets(5, 0, 0, 0)); sendMsgProgressIndicator = new ProgressIndicator(0); sendMsgProgressIndicator.setPrefHeight(24); sendMsgProgressIndicator.setPrefWidth(24); sendMsgProgressIndicator.setVisible(false); sendMsgProgressIndicator.setManaged(false); dispute .isClosedProperty() .addListener( (observable, oldValue, newValue) -> { messagesInputBox.setVisible(!newValue); messagesInputBox.setManaged(!newValue); AnchorPane.setBottomAnchor(messageListView, newValue ? 0d : 120d); }); if (!dispute.isClosed()) { HBox buttonBox = new HBox(); buttonBox.setSpacing(10); buttonBox .getChildren() .addAll(sendButton, uploadButton, sendMsgProgressIndicator, sendMsgInfoLabel); if (!isTrader) { Button closeDisputeButton = new Button("Close ticket"); closeDisputeButton.setOnAction(e -> onCloseDispute(dispute)); closeDisputeButton.setDefaultButton(true); Pane spacer = new Pane(); HBox.setHgrow(spacer, Priority.ALWAYS); buttonBox.getChildren().addAll(spacer, closeDisputeButton); } messagesInputBox = new VBox(); messagesInputBox.setSpacing(10); messagesInputBox.getChildren().addAll(inputTextArea, buttonBox); VBox.setVgrow(buttonBox, Priority.ALWAYS); AnchorPane.setRightAnchor(messagesInputBox, 0d); AnchorPane.setBottomAnchor(messagesInputBox, 5d); AnchorPane.setLeftAnchor(messagesInputBox, 0d); AnchorPane.setBottomAnchor(messageListView, 120d); messagesAnchorPane .getChildren() .addAll(tableGroupHeadline, messageListView, messagesInputBox); } else { AnchorPane.setBottomAnchor(messageListView, 0d); messagesAnchorPane.getChildren().addAll(tableGroupHeadline, messageListView); } messageListView.setCellFactory( new Callback<ListView<DisputeDirectMessage>, ListCell<DisputeDirectMessage>>() { @Override public ListCell<DisputeDirectMessage> call(ListView<DisputeDirectMessage> list) { return new ListCell<DisputeDirectMessage>() { final Pane bg = new Pane(); final ImageView arrow = new ImageView(); final Label headerLabel = new Label(); final Label messageLabel = new Label(); final HBox attachmentsBox = new HBox(); final AnchorPane messageAnchorPane = new AnchorPane(); final Label statusIcon = new Label(); final double arrowWidth = 15d; final double attachmentsBoxHeight = 20d; final double border = 10d; final double bottomBorder = 25d; final double padding = border + 10d; { bg.setMinHeight(30); messageLabel.setWrapText(true); headerLabel.setTextAlignment(TextAlignment.CENTER); attachmentsBox.setSpacing(5); statusIcon.setStyle("-fx-font-size: 10;"); messageAnchorPane .getChildren() .addAll(bg, arrow, headerLabel, messageLabel, attachmentsBox, statusIcon); } @Override public void updateItem(final DisputeDirectMessage item, boolean empty) { super.updateItem(item, empty); if (item != null && !empty) { /* messageAnchorPane.prefWidthProperty().bind(EasyBind.map(messageListView.widthProperty(), w -> (double) w - padding - GUIUtil.getScrollbarWidth(messageListView)));*/ if (!messageAnchorPane.prefWidthProperty().isBound()) messageAnchorPane .prefWidthProperty() .bind( messageListView .widthProperty() .subtract(padding + GUIUtil.getScrollbarWidth(messageListView))); AnchorPane.setTopAnchor(bg, 15d); AnchorPane.setBottomAnchor(bg, bottomBorder); AnchorPane.setTopAnchor(headerLabel, 0d); AnchorPane.setBottomAnchor(arrow, bottomBorder + 5d); AnchorPane.setTopAnchor(messageLabel, 25d); AnchorPane.setBottomAnchor(attachmentsBox, bottomBorder + 10); boolean senderIsTrader = item.isSenderIsTrader(); boolean isMyMsg = isTrader ? senderIsTrader : !senderIsTrader; arrow.setVisible(!item.isSystemMessage()); arrow.setManaged(!item.isSystemMessage()); statusIcon.setVisible(false); if (item.isSystemMessage()) { headerLabel.setStyle("-fx-text-fill: -bs-green; -fx-font-size: 11;"); bg.setId("message-bubble-green"); messageLabel.setStyle("-fx-text-fill: white;"); } else if (isMyMsg) { headerLabel.setStyle("-fx-text-fill: -fx-accent; -fx-font-size: 11;"); bg.setId("message-bubble-blue"); messageLabel.setStyle("-fx-text-fill: white;"); if (isTrader) arrow.setId("bubble_arrow_blue_left"); else arrow.setId("bubble_arrow_blue_right"); sendMsgProgressIndicator .progressProperty() .addListener( (observable, oldValue, newValue) -> { if ((double) oldValue == -1 && (double) newValue == 0) { if (item.arrivedProperty().get()) showArrivedIcon(); else if (item.storedInMailboxProperty().get()) showMailboxIcon(); } }); if (item.arrivedProperty().get()) showArrivedIcon(); else if (item.storedInMailboxProperty().get()) showMailboxIcon(); // TODO show that icon on error /*else if (sendMsgProgressIndicator.getProgress() == 0) showNotArrivedIcon();*/ } else { headerLabel.setStyle("-fx-text-fill: -bs-light-grey; -fx-font-size: 11;"); bg.setId("message-bubble-grey"); messageLabel.setStyle("-fx-text-fill: black;"); if (isTrader) arrow.setId("bubble_arrow_grey_right"); else arrow.setId("bubble_arrow_grey_left"); } if (item.isSystemMessage()) { AnchorPane.setLeftAnchor(headerLabel, padding); AnchorPane.setRightAnchor(headerLabel, padding); AnchorPane.setLeftAnchor(bg, border); AnchorPane.setRightAnchor(bg, border); AnchorPane.setLeftAnchor(messageLabel, padding); AnchorPane.setRightAnchor(messageLabel, padding); AnchorPane.setLeftAnchor(attachmentsBox, padding); AnchorPane.setRightAnchor(attachmentsBox, padding); } else if (senderIsTrader) { AnchorPane.setLeftAnchor(headerLabel, padding + arrowWidth); AnchorPane.setLeftAnchor(bg, border + arrowWidth); AnchorPane.setRightAnchor(bg, border); AnchorPane.setLeftAnchor(arrow, border); AnchorPane.setLeftAnchor(messageLabel, padding + arrowWidth); AnchorPane.setRightAnchor(messageLabel, padding); AnchorPane.setLeftAnchor(attachmentsBox, padding + arrowWidth); AnchorPane.setRightAnchor(attachmentsBox, padding); AnchorPane.setRightAnchor(statusIcon, padding); } else { AnchorPane.setRightAnchor(headerLabel, padding + arrowWidth); AnchorPane.setLeftAnchor(bg, border); AnchorPane.setRightAnchor(bg, border + arrowWidth); AnchorPane.setRightAnchor(arrow, border); AnchorPane.setLeftAnchor(messageLabel, padding); AnchorPane.setRightAnchor(messageLabel, padding + arrowWidth); AnchorPane.setLeftAnchor(attachmentsBox, padding); AnchorPane.setRightAnchor(attachmentsBox, padding + arrowWidth); AnchorPane.setLeftAnchor(statusIcon, padding); } AnchorPane.setBottomAnchor(statusIcon, 7d); headerLabel.setText(formatter.formatDateTime(item.getDate())); messageLabel.setText(item.getMessage()); if (item.getAttachments().size() > 0) { AnchorPane.setBottomAnchor( messageLabel, bottomBorder + attachmentsBoxHeight + 10); attachmentsBox .getChildren() .add( new Label("Attachments: ") { { setPadding(new Insets(0, 0, 3, 0)); if (isMyMsg) setStyle("-fx-text-fill: white;"); else setStyle("-fx-text-fill: black;"); } }); item.getAttachments() .stream() .forEach( attachment -> { final Label icon = new Label(); setPadding(new Insets(0, 0, 3, 0)); if (isMyMsg) icon.getStyleClass().add("attachment-icon"); else icon.getStyleClass().add("attachment-icon-black"); AwesomeDude.setIcon(icon, AwesomeIcon.FILE_TEXT); icon.setPadding(new Insets(-2, 0, 0, 0)); icon.setTooltip(new Tooltip(attachment.getFileName())); icon.setOnMouseClicked(event -> onOpenAttachment(attachment)); attachmentsBox.getChildren().add(icon); }); } else { attachmentsBox.getChildren().clear(); AnchorPane.setBottomAnchor(messageLabel, bottomBorder + 10); } // TODO There are still some cell rendering issues on updates setGraphic(messageAnchorPane); } else { messageAnchorPane.prefWidthProperty().unbind(); AnchorPane.clearConstraints(bg); AnchorPane.clearConstraints(headerLabel); AnchorPane.clearConstraints(arrow); AnchorPane.clearConstraints(messageLabel); AnchorPane.clearConstraints(statusIcon); AnchorPane.clearConstraints(attachmentsBox); setGraphic(null); } } /* private void showNotArrivedIcon() { statusIcon.setVisible(true); AwesomeDude.setIcon(statusIcon, AwesomeIcon.WARNING_SIGN, "14"); Tooltip.install(statusIcon, new Tooltip("Message did not arrive. Please try to send again.")); statusIcon.setTextFill(Paint.valueOf("#dd0000")); }*/ private void showMailboxIcon() { statusIcon.setVisible(true); AwesomeDude.setIcon(statusIcon, AwesomeIcon.ENVELOPE_ALT, "14"); Tooltip.install(statusIcon, new Tooltip("Message saved in receivers mailbox")); statusIcon.setTextFill(Paint.valueOf("#0f87c3")); } private void showArrivedIcon() { statusIcon.setVisible(true); AwesomeDude.setIcon(statusIcon, AwesomeIcon.OK, "14"); Tooltip.install(statusIcon, new Tooltip("Message arrived at receiver")); statusIcon.setTextFill(Paint.valueOf("#0f87c3")); } }; } }); if (root.getChildren().size() > 1) root.getChildren().remove(1); root.getChildren().add(1, messagesAnchorPane); scrollToBottom(); } }
@FXML void initialize() { assert syncUserName != null : "fx:id=\"syncUserName\" was not injected: check your FXML file 'AddUser.fxml'."; assert cancelButton != null : "fx:id=\"cancelButton\" was not injected: check your FXML file 'AddUser.fxml'."; assert password != null : "fx:id=\"password\" was not injected: check your FXML file 'AddUser.fxml'."; assert fullNameUnique != null : "fx:id=\"fullNameUnique\" was not injected: check your FXML file 'AddUser.fxml'."; assert roles != null : "fx:id=\"roles\" was not injected: check your FXML file 'AddUser.fxml'."; assert layoutPane != null : "fx:id=\"layoutPane\" was not injected: check your FXML file 'AddUser.fxml'."; assert fullName != null : "fx:id=\"fullName\" was not injected: check your FXML file 'AddUser.fxml'."; assert okButton != null : "fx:id=\"okButton\" was not injected: check your FXML file 'AddUser.fxml'."; assert userName != null : "fx:id=\"userName\" was not injected: check your FXML file 'AddUser.fxml'."; assert workflowUserName != null : "fx:id=\"workflowUserName\" was not injected: check your FXML file 'AddUser.fxml'."; assert uuid != null : "fx:id=\"uuid\" was not injected: check your FXML file 'AddUser.fxml'."; for (RoleOption ro : RoleOption.values()) { roles.getItems().add(ro.value()); } upm_ = AppContext.getService(UserProfileManager.class); uuidValid_ = new ValidBooleanBinding() { { bind(uuid.textProperty()); } @Override protected boolean computeValue() { if (uuid.getText().length() == 0 || Utility.isUUID(uuid.getText())) { if (uuid.getText().length() > 0 && AppContext.getService(TerminologyStoreDI.class) .hasUuid(UUID.fromString(uuid.getText()))) { setInvalidReason("If a UUID is specified, it must be unique"); return false; } else { clearInvalidReason(); return true; } } else { setInvalidReason("Invalid uuid"); return false; } } }; ErrorMarkerUtils.setupErrorMarkerAndSwap(uuid, layoutPane, uuidValid_); userNameValid_ = new ValidBooleanBinding() { { bind(userName.textProperty()); } @Override protected boolean computeValue() { if (userName.getText().length() > 0 && !upm_.doesProfileExist(userName.getText())) { clearInvalidReason(); return true; } else { setInvalidReason("The user name is required, and must be unique"); return false; } } }; ErrorMarkerUtils.setupErrorMarkerAndSwap(userName, layoutPane, userNameValid_); fullNameUniqueValid_ = new ValidBooleanBinding() { { bind(fullNameUnique.textProperty(), uuid.textProperty()); } @Override protected boolean computeValue() { if (fullNameUnique.getText().length() > 0) { UUID userUuid; if (uuid.getText().length() > 0) { if (uuidValid_.get()) { userUuid = UUID.fromString(uuid.getText()); } else { setInvalidReason("If a UUID is specified, it must be valid."); return false; } } else { userUuid = GenerateUsers.calculateUserUUID(fullNameUnique.getText()); } if (AppContext.getService(TerminologyStoreDI.class).hasUuid(userUuid)) { setInvalidReason("The full name must be unique"); return false; } else { clearInvalidReason(); return true; } } else { setInvalidReason( "The Full Name is required, and must be unique. If a UUID is specified, it must be valid, and unique"); return false; } } }; ErrorMarkerUtils.setupErrorMarkerAndSwap(fullNameUnique, layoutPane, fullNameUniqueValid_); okButton.disableProperty().bind(fullNameUniqueValid_.and(userNameValid_).and(uuidValid_).not()); cancelButton.setCancelButton(true); // JavaFX is silly: https://javafx-jira.kenai.com/browse/RT-39145#comment-434189 cancelButton.setOnKeyPressed( new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { if (event.getCode() == KeyCode.ENTER) { event.consume(); cancelButton.fire(); } } }); cancelButton.setOnAction( (event) -> { layoutPane.getScene().getWindow().hide(); }); okButton.setDefaultButton(true); okButton.setOnAction( (event) -> { try { User u = new User(); u.setFullName(fullName.getText()); u.setPassword(password.getText()); u.setSyncUserName(syncUserName.getText()); u.setWorkflowUserName(workflowUserName.getText()); u.setUniqueFullName(fullNameUnique.getText()); u.setUniqueLogonName(userName.getText()); u.setUUID(uuid.getText()); for (String roleName : roles.getSelectionModel().getSelectedItems()) { u.getRoles().add(RoleOption.fromValue(roleName)); } upm_.createNewUser(u); layoutPane.getScene().getWindow().hide(); } catch (Exception e) { logger.error("Error creating user", e); AppContext.getCommonDialogs().showErrorDialog("Unexpected error adding user", e); } }); }
public void connectMyo() { try { LOGGER.info("Connecting to Myo"); updateMyoStatus("Attempting to find a Myo..."); Myo myo = hub.waitForMyo(10000); if (myo == null) { LOGGER.error("Unable to connect to Myo"); throw new RuntimeException("Unable to find a Myo!"); } myo.setStreamEmg(StreamEmgType.STREAM_EMG_ENABLED); LOGGER.info("EMG Stream enabled"); updateMyoStatus("Connected to a Myo armband!"); jsonDataCollector = new JsonDataCollector(); jsonDataCollector.addListsner(new FileMyoDataCollector("c:\\tmp\\myo")); jsonDataCollector.addListsner(new SocketServerCollector()); hub.addListener(jsonDataCollector); LOGGER.info("Listener added"); indicatorMyo.setIndicatorStyle(SimpleIndicator.IndicatorStyle.GREEN); startButton.setDisable(false); startButton.setDefaultButton(true); Task<ObservableList<String>> task = new Task<ObservableList<String>>() { @Override protected ObservableList<String> call() throws Exception { while (true) { List<RecordListener> collect = jsonDataCollector .getListeners() .stream() .filter(s -> s instanceof SocketServerCollector) .collect(Collectors.toList()); List<String> connections = collect .stream() .map(s -> ((SocketServerCollector) s).channels) .flatMap(c -> c.stream().map(f -> mapRemoteAddress(f))) .collect(Collectors.toList()); updateValue(FXCollections.observableList(connections)); Thread.sleep(10); } } }; Task<Boolean> booleanTask = new Task<Boolean>() { @Override protected Boolean call() throws Exception { while (true) { List<RecordListener> collect = jsonDataCollector .getListeners() .stream() .filter(s -> s instanceof SocketServerCollector) .collect(Collectors.toList()); long count = collect .stream() .map(s -> ((SocketServerCollector) s).channels) .flatMap(Collection::stream) .filter(AsynchronousSocketChannel::isOpen) .count(); updateValue(count > 0 ? Boolean.TRUE : Boolean.FALSE); Thread.sleep(10); } } }; Task<SimpleIndicator.IndicatorStyle> stringTask = new Task<SimpleIndicator.IndicatorStyle>() { @Override protected SimpleIndicator.IndicatorStyle call() throws Exception { while (true) { List<RecordListener> collect = jsonDataCollector .getListeners() .stream() .filter(s -> s instanceof SocketServerCollector) .collect(Collectors.toList()); long count = collect .stream() .map(s -> ((SocketServerCollector) s).channels) .flatMap(Collection::stream) .filter(AsynchronousSocketChannel::isOpen) .count(); updateValue( count > 0 ? SimpleIndicator.IndicatorStyle.RED : SimpleIndicator.IndicatorStyle.GREEN); Thread.sleep(10); } } }; inboundConnections.itemsProperty().bind(task.valueProperty()); indicatorServer.onProperty().bind(booleanTask.valueProperty()); // try { // indicatorServer.indicatorStyleProperty().bind(stringTask.valueProperty()); // } catch (Throwable e) { // //??Throws a null ppointer but it works?? // } Thread thread = new Thread(task); thread.setDaemon(true); thread.start(); Thread thread2 = new Thread(booleanTask); thread2.setDaemon(true); thread2.start(); Thread thread3 = new Thread(stringTask); thread3.setDaemon(true); thread3.start(); } catch (Exception e) { e.printStackTrace(); updateMyoStatus("Error: " + e.getMessage()); } }
/** * @param owner * @param title * @param titleLong * @param message * @return */ public Response show(Stage owner, String title, String titleLong, String message) { final Stage stage = new Stage(); final BooleanProperty isOK = new SimpleBooleanProperty(false); stage.setTitle(title); stage.initModality(Modality.APPLICATION_MODAL); stage.initOwner(owner); // BorderPane root = new BorderPane(); VBox root = new VBox(); Scene scene = new Scene(root); stage.setScene(scene); stage.setWidth(500); stage.setHeight(250); stage.initStyle(StageStyle.UTILITY); stage.setResizable(false); Node header = DialogHeader.getDialogHeader(ICON, titleLong); ImageView imageView = ResourceLoader.getImage(ICON, 65, 65); stage.getIcons().add(imageView.getImage()); HBox buttonPanel = new HBox(); Button ok = new Button("OK"); ok.setDefaultButton(true); buttonPanel.getChildren().addAll(ok); buttonPanel.setAlignment(Pos.CENTER_RIGHT); buttonPanel.setPadding(new Insets(10, 10, 10, 10)); buttonPanel.setSpacing(10); buttonPanel.setMaxHeight(25); HBox messagePanel = new HBox(); messagePanel.setPadding(new Insets(30, 30, 30, 30)); Label mewssage = new Label(message); messagePanel.getChildren().add(mewssage); mewssage.setWrapText(true); mewssage.setAlignment(Pos.CENTER_LEFT); Separator sep = new Separator(Orientation.HORIZONTAL); sep.setMinHeight(10); root.getChildren() .addAll(header, new Separator(Orientation.HORIZONTAL), messagePanel, buttonPanel); VBox.setVgrow(messagePanel, Priority.ALWAYS); VBox.setVgrow(buttonPanel, Priority.NEVER); VBox.setVgrow(header, Priority.NEVER); ok.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { // System.out.println("Size: h:" + stage.getHeight() + " w:" + // stage.getWidth()); stage.close(); // isOK.setValue(true); response = Response.OK; } }); stage.showAndWait(); return response; }
@Override public void start(Stage stage) { stage.setTitle("FX Keyboard (" + System.getProperty("javafx.runtime.version") + ")"); stage.setResizable(true); popup = KeyBoardPopupBuilder.create() .initLocale(Locale.ENGLISH) .addIRobot(RobotFactory.createFXRobot()) .build(); popup .getKeyBoard() .setOnKeyboardCloseButton( new EventHandler<Event>() { public void handle(Event event) { setPopupVisible(false, null); } }); FlowPane pane = new FlowPane(); pane.setVgap(20); pane.setHgap(20); pane.setPrefWrapLength(100); final TextField tf = new TextField(""); final TextArea ta = new TextArea(""); Button okButton = new Button("Ok"); okButton.setDefaultButton(true); Button cancelButton = new Button("Cancel"); cancelButton.setCancelButton(true); pane.getChildren().add(new Label("Text1")); pane.getChildren().add(tf); pane.getChildren().add(new Label("Text2")); pane.getChildren().add(ta); pane.getChildren().add(okButton); pane.getChildren().add(cancelButton); // pane.getChildren().add(KeyBoardBuilder.create().addIRobot(RobotFactory.createFXRobot()).build()); Scene scene = new Scene(pane, 200, 300); // add keyboard scene listener to all text components scene .focusOwnerProperty() .addListener( new ChangeListener<Node>() { @Override public void changed(ObservableValue<? extends Node> value, Node n1, Node n2) { if (n2 != null && n2 instanceof TextInputControl) { setPopupVisible(true, (TextInputControl) n2); } else { setPopupVisible(false, null); } } }); String css = this.getClass().getResource("/css/KeyboardButtonStyle.css").toExternalForm(); scene.getStylesheets().add(css); stage.setOnCloseRequest( new EventHandler<WindowEvent>() { public void handle(WindowEvent event) { System.exit(0); } }); popup.show(stage); stage.setScene(scene); stage.show(); }
private Button createCommandLinksButton(ButtonType buttonType) { // look up the CommandLinkButtonType for the given ButtonType CommandLinksButtonType commandLink = typeMap.getOrDefault(buttonType, new CommandLinksButtonType(buttonType)); // put the content inside a button final Button button = new Button(); button.getStyleClass().addAll("command-link-button"); // $NON-NLS-1$ button.setMaxHeight(Double.MAX_VALUE); button.setMaxWidth(Double.MAX_VALUE); button.setAlignment(Pos.CENTER_LEFT); final ButtonData buttonData = buttonType.getButtonData(); button.setDefaultButton(buttonData != null && buttonData.isDefaultButton()); button.setOnAction(ae -> setResult(buttonType)); final Label titleLabel = new Label(commandLink.getButtonType().getText()); titleLabel .minWidthProperty() .bind( new DoubleBinding() { { bind(titleLabel.prefWidthProperty()); } @Override protected double computeValue() { return titleLabel.getPrefWidth() + 400; } }); titleLabel.getStyleClass().addAll("line-1"); // $NON-NLS-1$ titleLabel.setWrapText(true); titleLabel.setAlignment(Pos.TOP_LEFT); GridPane.setVgrow(titleLabel, Priority.NEVER); Label messageLabel = new Label(commandLink.getLongText()); messageLabel.getStyleClass().addAll("line-2"); // $NON-NLS-1$ messageLabel.setWrapText(true); messageLabel.setAlignment(Pos.TOP_LEFT); messageLabel.setMaxHeight(Double.MAX_VALUE); GridPane.setVgrow(messageLabel, Priority.SOMETIMES); Node commandLinkImage = commandLink.getGraphic(); Node view = commandLinkImage == null ? new ImageView( CommandLinksDialog.class.getResource("arrow-green-right.png").toExternalForm()) : //$NON-NLS-1$ commandLinkImage; Pane graphicContainer = new Pane(view); graphicContainer.getStyleClass().add("graphic-container"); // $NON-NLS-1$ GridPane.setValignment(graphicContainer, VPos.TOP); GridPane.setMargin(graphicContainer, new Insets(0, 10, 0, 0)); GridPane grid = new GridPane(); grid.minWidthProperty().bind(titleLabel.prefWidthProperty()); grid.setMaxHeight(Double.MAX_VALUE); grid.setMaxWidth(Double.MAX_VALUE); grid.getStyleClass().add("container"); // $NON-NLS-1$ grid.add(graphicContainer, 0, 0, 1, 2); grid.add(titleLabel, 1, 0); grid.add(messageLabel, 1, 1); button.setGraphic(grid); button.minWidthProperty().bind(titleLabel.prefWidthProperty()); if (commandLink.isHidden) { button.setVisible(false); button.setPrefHeight(1); } return button; }
@FXML public void initialize() { ok.setDefaultButton(true); }
/* * Create and show a backup error dialog. This is probably overkill, but I * created this method just to make sure there always is an error dialog, * even when ErrorDialog.fxml cannot be loaded. */ private static void showBackupErrorDialog() { final RemindersException exception = Model.getInstance().getNextException(); final VBox root = new VBox(15); root.setPadding(new Insets(15)); root.getStylesheets() .add(Dialogs.class.getResource("/resources/css/styles.css").toExternalForm()); root.getChildren().add(TextBuilder.create().text("Oops...").styleClass("heading").build()); if (exception.isRecoverable()) { root.getChildren() .add( new Label( "Looks like something went wrong here.\nYou can continue working or quit and call it a day.")); } else { root.getChildren() .add( new Label( "Looks like something went wrong here.\nUnfortunately, the application cannot continue working.")); } HBox buttons = new HBox(15); buttons.setAlignment(Pos.CENTER_RIGHT); Button quitButton = ButtonBuilder.create() .text("Quit") .styleClass("quit-button") .graphic(LabelBuilder.create().text(Icons.QUIT).styleClass("button-icon").build()) .onAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { System.exit(1); } }) .build(); buttons.getChildren().add(quitButton); final Button continueButton = ButtonBuilder.create() .text("Continue") .onAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { root.getScene().getWindow().hide(); } }) .build(); if (exception.isRecoverable()) { continueButton.setDefaultButton(true); buttons.getChildren().add(continueButton); } else { quitButton.setDefaultButton(true); } root.getChildren().add(buttons); showDialog( root, new OnShownAction() { @Override public void perform() { for (Node node : root.lookupAll(".button")) { if (node instanceof Button && ((Button) node).isDefaultButton()) { node.requestFocus(); } } } }); }
@Override public void start(Stage primaryStage) { VBox loginPane = new VBox(); loginPane.setAlignment(Pos.CENTER); primaryStage.setTitle("Amoeba"); primaryStage.setScene(new Scene(loginPane, 800, 600)); primaryStage.show(); TextField username = new TextField(); username.setPromptText("Username"); username.setMaxSize(200, 50); Timeline renderTimer = new Timeline(); Timeline inputTimer = new Timeline(); ColorPicker colorPicker = new ColorPicker(); colorPicker.setEditable(true); colorPicker.setValue(Color.BLACK); lagLabel.setTranslateX(25); lagLabel.setTranslateY(10); lagLabel.setTextFill(Color.RED); TextField address = new TextField("localhost"); address.setPromptText("Server IP Address"); address.setMaxSize(200, 50); TextField port = new TextField("8080"); port.setPromptText("Port Number"); port.setMaxSize(200, 50); Button btn = new Button("Play"); btn.setDefaultButton(true); loginPane.getChildren().addAll(username, colorPicker, address, port, btn); primaryStage.setResizable(false); music.setCycleCount(MediaPlayer.INDEFINITE); renderPane.setBackground(new Background(backgroundImage)); renderPane.setPrefSize(800, 600); chatBox.setPrefSize(400, 100); chatBox.setTranslateX(0); chatBox.setTranslateY(468); chatBox.setWrapText(true); chatBox.setEditable(false); chatBox.setStyle("-fx-opacity: 0.5"); chatInput.setPrefSize(400, 10); chatInput.setTranslateX(0); chatInput.setTranslateY(570); chatInput.setStyle("-fx-opacity: 0.8"); highScores.setPrefSize(400, 210); highScores.setEditable(false); currentScores.setPrefSize(400, 250); currentScores.setEditable(false); currentScores.setLayoutY(210); scores.setTranslateX(-390); scores.setTranslateY(0); scores.setStyle("-fx-opacity: 0.8"); scores.setOnMouseEntered( (e) -> { scores.setTranslateX(0); }); scores.setOnMouseExited( (e) -> { if (e.getX() > 350) { scores.setTranslateX(-390); } }); btn.setOnAction( (e) -> { if (!networkController.isConnected()) { networkController.connect(address.getText(), Integer.parseInt(port.getText())); if (username.getText().isEmpty()) { username.setText("Anonymous"); } networkController.sendMessage(new LoginMessage(username.getText(), "")); ArrayList<KeyValuePair> properties = new ArrayList<>(); properties.add(new KeyValuePair("color", colorPicker.getValue().toString())); networkController.sendMessage(new SetBlobPropertiesMessage(properties)); primaryStage.setScene(new Scene(renderPane)); renderTimer.play(); inputTimer.play(); music.play(); } }); inputTimer.setCycleCount(Timeline.INDEFINITE); inputTimer .getKeyFrames() .add( new KeyFrame( Duration.seconds(0.05), (e) -> { if (sendCoordinates) { networkController.sendMessage(new MoveTowardCoordinatesMessage(x, y)); } })); renderTimer.setCycleCount(Timeline.INDEFINITE); renderTimer .getKeyFrames() .add( new KeyFrame( Duration.seconds(0.01), (e) -> { render(); })); renderPane.setOnMouseReleased( (e) -> { this.sendCoordinates = false; }); renderPane.setOnMouseDragged( (e) -> { this.sendCoordinates = true; this.x = e.getX(); this.y = e.getY(); }); renderPane.setOnMouseClicked( (e) -> { if (e.getButton() == MouseButton.SECONDARY) { networkController.sendMessage(new BoostMessage()); } else if (e.getClickCount() > 1 || e.getButton() == MouseButton.MIDDLE) { networkController.sendMessage(new SplitMessage()); } }); renderPane.setOnKeyPressed( (e) -> { if (e.getCode().equals(KeyCode.ENTER) && !chatInput.getText().isEmpty()) { networkController.sendMessage(new ChatMessage("", chatInput.getText())); chatInput.clear(); } }); primaryStage.setOnCloseRequest( (e) -> { networkController.sendMessage(new LogoutMessage()); try { Thread.sleep(100); } catch (InterruptedException ex) { Logger.getLogger(AmoebaClient.class.getName()).log(Level.WARNING, null, ex); } finally { System.exit(0); } }); }
public void buildForm() { try { URL location = getClass().getResource("/com/webfront/app/fxml/LedgerEntryForm.fxml"); ResourceBundle resources = ResourceBundle.getBundle("com.webfront.app.bank"); FXMLLoader loader = new FXMLLoader(location, resources); btnOk.setDefaultButton(true); btnCancel.setCancelButton(true); stage = new Stage(); scene = new Scene(this); stage.setScene(scene); stage.setTitle("Item Detail"); loader.setRoot(this); loader.setController(this); loader.load(); ObservableList<Category> cList = view.getCategoryManager().getCategories(); ObservableList<Account> accountList = javafx.collections.FXCollections.observableArrayList(Bank.accountList); accountList .stream() .forEach( (acct) -> { accountNum.getItems().add(acct.getId()); }); for (Category c : cList) { // Category parent = c.getParent(); Integer parent = c.getParent(); categoryMap.put(c.getDescription(), c); if (parent == 0) { primaryCat.getItems().add(c.getDescription()); } else if (oldItem != null) { if (oldItem.getPrimaryCat() != null) { if (parent == oldItem.getPrimaryCat().getId()) { subCat.getItems().add(c.getDescription()); } } } } if (oldItem != null) { if (oldItem.getSubCat() != null) { Category c = oldItem.getSubCat(); if (c != null) { String desc = c.getDescription(); if (!subCat.getItems().contains(desc)) { subCat.getItems().add(desc); } subCat.setValue(c.getDescription()); } } } primaryCat .getSelectionModel() .selectedItemProperty() .addListener( new ChangeListener() { @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { String newCat = newValue.toString(); if (categoryMap.containsKey(newCat)) { if (oldItem.getId() != null) { Category c = categoryMap.get(newCat); String sqlStmt = "SELECT * FROM categories WHERE parent = " + Integer.toString(c.getId()); sqlStmt += " order by description"; ObservableList<Category> subCatList = view.getCategoryManager().getCategories(sqlStmt); subCat.getItems().clear(); subCatMap.clear(); for (Category cat2 : subCatList) { subCatMap.put(cat2.getDescription(), cat2); } subCat.getItems().addAll(subCatMap.keySet()); if (oldItem.getPrimaryCat() == null) { oldItem.setPrimaryCat(c); btnOk.setDisable(false); } if (!oldItem.getPrimaryCat().getDescription().equals(primaryCat.getValue())) { oldItem.setPrimaryCat(c); btnOk.setDisable(false); } } } } }); subCat .getSelectionModel() .selectedItemProperty() .addListener( new ChangeListener() { @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { if (newValue != null) { String newCat = newValue.toString(); if (subCatMap.containsKey(newCat)) { if (oldItem != null) { oldItem.setSubCat(subCatMap.get(newCat)); btnOk.setDisable(false); } } } } }); transDescription.setOnKeyPressed( new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { if (!transDescription.getText().equals(oldItem.getTransDesc())) { oldItem.setTransDesc(transDescription.getText()); btnOk.setDisable(false); } } }); transDescription .textProperty() .addListener( new ChangeListener() { @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { if (!oldValue.equals(newValue)) { btnOk.setDisable(false); } } }); checkNum.setOnKeyPressed( new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { if (event.getCode() == KeyCode.TAB) { if (!checkNum.getText().equals(oldItem.getCheckNum())) { oldItem.setCheckNum(checkNum.getText()); btnOk.setDisable(false); } } } }); transAmt .textProperty() .addListener( new ChangeListener() { @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { if (!oldValue.equals(newValue)) { btnOk.setDisable(false); } } }); distView.setPrefSize(857.0, 175.0); paymentDetail.setPrefSize(857.0, 175.0); distView.getChildren().add(paymentDetail); stage.show(); } catch (IOException ex) { Logger.getLogger(LedgerForm.class.getName()).log(Level.SEVERE, null, ex); } }