private void onPaymentReceived(ActionEvent actionEvent) { log.debug("onPaymentReceived"); confirmFiatReceivedButton.setDisable(true); statusLabel.setText("Sending message to trading peer..."); statusProgressIndicator.setVisible(true); statusProgressIndicator.setProgress(-1); root = statusProgressIndicator.getScene().getRoot(); // We deactivate mouse interaction to avoid that user leaves screen root.setMouseTransparent(true); model.fiatPaymentReceived(); }
private void hideSendMsgInfo(Timer timer) { timer.stop(); inputTextArea.setDisable(false); FxTimer.runLater( Duration.ofMillis(5000), () -> { sendMsgInfoLabel.setVisible(false); sendMsgInfoLabel.setManaged(false); }); sendMsgProgressIndicator.setProgress(0); sendMsgProgressIndicator.setVisible(false); sendMsgProgressIndicator.setManaged(false); }
private void onSendMessage(String inputText, Dispute dispute) { DisputeDirectMessage disputeDirectMessage = disputeManager.sendDisputeDirectMessage( dispute, inputText, new ArrayList<>(tempAttachments)); tempAttachments.clear(); scrollToBottom(); inputTextArea.setDisable(true); inputTextArea.clear(); final Timer timer = FxTimer.runLater( Duration.ofMillis(500), () -> { sendMsgInfoLabel.setVisible(true); sendMsgInfoLabel.setManaged(true); sendMsgInfoLabel.setText("Sending Message..."); sendMsgProgressIndicator.setProgress(-1); sendMsgProgressIndicator.setVisible(true); sendMsgProgressIndicator.setManaged(true); }); disputeDirectMessage .arrivedProperty() .addListener( (observable, oldValue, newValue) -> { if (newValue) { hideSendMsgInfo(timer); } }); disputeDirectMessage .storedInMailboxProperty() .addListener( (observable, oldValue, newValue) -> { if (newValue) { sendMsgInfoLabel.setVisible(true); sendMsgInfoLabel.setManaged(true); sendMsgInfoLabel.setText( "Receiver is not online. Message is saved to his mailbox."); hideSendMsgInfo(timer); } }); }
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(); } }
@Override public void initialize(URL url, ResourceBundle rb) { loading.setVisible(false); checkTodos.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { boolean checked = ((CheckBox) t.getTarget()).isSelected(); for (Node node : servicos.getChildren()) { ((CheckBox) node).setSelected(checked); } } }); unidades.setItems(FXCollections.observableList(new ArrayList<ComboboxItem>())); unidades.setOnAction( new EventHandler() { @Override public void handle(Event t) { loading.setVisible(true); checkTodos.setSelected(false); ComboBox cb = (ComboBox) t.getTarget(); cb.getSelectionModel().selectedItemProperty(); ComboboxItem item = (ComboboxItem) cb.getSelectionModel().selectedItemProperty().getValue(); if (item != null && Integer.parseInt(item.getKey()) > 0) { unidadeAtual = Integer.parseInt(item.getKey()); updateServicos(main.getService().buscarServicos(unidadeAtual)); } loading.setVisible(false); } }); buscar.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { loading.setVisible(true); servicos.getChildren().clear(); unidadeAtual = 0; try { main.getService() .loadUrls( servidor.getText(), new Runnable() { @Override public void run() { updateUnidades(main.getService().buscarUnidades()); loading.setVisible(false); } }); } catch (Exception e) { loading.setVisible(false); } } }); salvar.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { loading.setVisible(true); try { List<Integer> idServicos = new ArrayList<Integer>(); for (Node node : servicos.getChildren()) { if (((CheckBox) node).isSelected()) { try { String id = node.getId().split("-")[1]; idServicos.add(Integer.parseInt(id)); } catch (Exception e) { } } } PainelConfig config = main.getConfig(); config.get(PainelConfig.KEY_SERVER).setValue(servidor.getText()); config.get(PainelConfig.KEY_UNIDADE, Integer.class).setValue(unidadeAtual); config .get(PainelConfig.KEY_SERVICOS, Integer[].class) .setValue(idServicos.toArray(new Integer[0])); // som e tema config.get(PainelConfig.KEY_SCREENSAVER_URL).setValue(videoUrl.getText()); config .get(PainelConfig.KEY_LANGUAGE) .setValue( ((ComboboxItem) language.getSelectionModel().getSelectedItem()).getKey()); config .get(PainelConfig.KEY_SOUND_VOICE, Boolean.class) .setValue(vocalizar.isSelected()); config.get(PainelConfig.KEY_COR_FUNDO).setValue(colorToHex(corFundo.getValue())); config .get(PainelConfig.KEY_COR_MENSAGEM) .setValue(colorToHex(corMensagem.getValue())); config.get(PainelConfig.KEY_COR_SENHA).setValue(colorToHex(corSenha.getValue())); config.get(PainelConfig.KEY_COR_GUICHE).setValue(colorToHex(corGuiche.getValue())); // screensaver layout config .get(PainelConfig.KEY_SCREENSAVER_LAYOUT, Integer.class) .setValue( Integer.parseInt(((RadioButton) svLayout.getSelectedToggle()).getText())); config.save(); main.getService().register(servidor.getText()); } catch (Exception e) { e.printStackTrace(); } loading.setVisible(false); } }); exibirPainel.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { main.getPainel().show(); } }); // language language.setItems(FXCollections.observableList(new ArrayList<ComboboxItem>())); SortedSet<String> keys = new TreeSet<String>(Main.locales.keySet()); for (String key : keys) { language.getItems().add(new ComboboxItem(key, Main.locales.get(key))); if (Locale.getDefault().getLanguage().equals(key)) { main.getConfig().get(PainelConfig.KEY_LANGUAGE).setValue(Locale.getDefault().getLanguage()); } } String defaultLang = main.getConfig().get(PainelConfig.KEY_LANGUAGE).getValue(); for (Object item : language.getItems()) { if (defaultLang.equals(((ComboboxItem) item).getKey())) { language.getSelectionModel().select(item); break; } } language.setOnAction( new EventHandler() { @Override public void handle(Event t) { ComboBox cb = (ComboBox) t.getTarget(); cb.getSelectionModel().selectedItemProperty(); ComboboxItem item = (ComboboxItem) cb.getSelectionModel().selectedItemProperty().getValue(); main.getConfig().get(PainelConfig.KEY_LANGUAGE).setValue(item.getKey()); } }); // video monitorId.setItems(FXCollections.observableList(new ArrayList<ComboboxItem>())); Integer defaultId = main.getConfig().get(PainelConfig.KEY_MONITOR_ID, Integer.class).getValue(); for (int i = 0; i < Screen.getScreens().size(); i++) { StringBuilder sb = new StringBuilder(); Rectangle2D b = Screen.getScreens().get(i).getBounds(); sb.append(i + 1) .append(" (") .append(b.getWidth()) .append(" x ") .append(b.getHeight()) .append(")"); ComboboxItem item = new ComboboxItem(i, sb.toString()); monitorId.getItems().add(item); if (defaultId.equals(i)) { monitorId.getSelectionModel().select(item); } } monitorId.setOnAction( new EventHandler() { @Override public void handle(Event t) { ComboBox cb = (ComboBox) t.getTarget(); cb.getSelectionModel().selectedItemProperty(); ComboboxItem item = (ComboboxItem) cb.getSelectionModel().selectedItemProperty().getValue(); Integer key = Integer.parseInt(item.getKey()); if (key >= 0 && key < Screen.getScreens().size()) { main.getConfig().get(PainelConfig.KEY_MONITOR_ID, Integer.class).setValue(key); } } }); // screen saver screenSaverTimeout.setItems(FXCollections.observableList(new ArrayList<ComboboxItem>())); Integer defaultTimeout = main.getConfig().get(PainelConfig.KEY_SCREENSAVER_TIMEOUT, Integer.class).getValue(); SortedSet<Integer> keys2 = new TreeSet<Integer>(Main.intervals.keySet()); for (Integer key : keys2) { ComboboxItem item = new ComboboxItem(key, Main.intervals.get(key)); screenSaverTimeout.getItems().add(item); if (defaultTimeout.equals(key)) { screenSaverTimeout.getSelectionModel().select(item); } } screenSaverTimeout.setOnAction( new EventHandler() { @Override public void handle(Event t) { ComboBox cb = (ComboBox) t.getTarget(); cb.getSelectionModel().selectedItemProperty(); ComboboxItem item = (ComboboxItem) cb.getSelectionModel().selectedItemProperty().getValue(); main.getConfig() .get(PainelConfig.KEY_SCREENSAVER_TIMEOUT, Integer.class) .setValue(Integer.parseInt(item.getKey())); } }); fileChooser.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { FileChooser fileChooser = new FileChooser(); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("MP4", "*.mp4")); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("AVI", "*.avi")); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("HLS", "*.m3u8")); try { File file = fileChooser.showOpenDialog(null); videoUrl.setText(file.toURI().toString()); } catch (Exception e) { } } }); testVideo.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { try { String url = videoUrl.getText(); if (url != null && !url.isEmpty()) { if (tester != null) { tester.destroy(); } tester = new VideoTester(url.trim()); Stage painelStage = new Stage(); painelStage.initOwner(stage); painelStage.setOnCloseRequest( new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent t) { tester.destroy(); } }); tester.start(painelStage); } } catch (Exception e) { e.printStackTrace(); } } }); // screesaver layout - marcando o padrao try { int id = main.getConfig().get(PainelConfig.KEY_SCREENSAVER_LAYOUT, Integer.class).getValue(); svLayout.getToggles().get(id - 1).setSelected(true); } catch (Exception e) { } // criando stage this.stage = new Stage(); stage.setTitle("Painel | Novo SGA"); stage.setScene(new Scene(getRoot())); // so esconde se suportar systray if (SystemTray.isSupported()) { final Controller self = this; stage.setOnCloseRequest( new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent t) { self.stage.hide(); } }); } }
@FXML void export() { progress.setVisible(true); controller.save(); controller.reload(); }
@Override protected void onRefresh(Void model) { super.onRefresh(model); progress.setVisible(false); }