Exemple #1
0
  private VBox LeftArea() {
    System.out.println("Gui.leftarea()");
    VBox leftArea = new VBox();

    input = new TextField();
    this.rawExile = new TextArea();
    input.setPrefColumnCount(88);
    rawExile.setPrefColumnCount(88);
    rawExile.setPrefHeight(1530);
    input.setPrefHeight(50);
    input.setOnKeyReleased(
        new EventHandler<KeyEvent>() {
          @Override
          public void handle(KeyEvent keyEvent) {
            if (keyEvent.getCode() == KeyCode.ENTER) {
              try {
                et.getOutputStream()
                    .write(input.getText().getBytes(), 0, input.getText().getBytes().length);
                et.getOutputStream().flush();
                input.setText("");
              } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
            }
          }
        });
    leftArea.getChildren().add(rawExile);
    leftArea.getChildren().add(input);
    return leftArea;
  }
 public SaveDialog(final Stage stg, String text) {
   width = 300;
   height = 100;
   final Stage stage = new Stage();
   stage.initModality(Modality.APPLICATION_MODAL);
   stage.initOwner(stg);
   stage.setTitle("提示框");
   Group root = new Group();
   AnchorPane anchorPane = new AnchorPane();
   area = new TextArea();
   area.setFont(new Font(30));
   area.setEditable(false);
   area.setWrapText(true);
   area.setPrefWidth(width);
   area.setPrefHeight(height);
   System.out.println(area.getWidth());
   System.out.println(area.getHeight());
   Scene scene = new Scene(root, width, height);
   area.setText(text);
   anchorPane.getChildren().add(area);
   root.getChildren().add(anchorPane);
   stage.setScene(scene);
   stage.show();
 }
  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();
    }
  }
Exemple #4
0
  @Override
  public void start(Stage primaryStage) throws Exception {

    try {
      screenSize = Screen.getPrimary().getVisualBounds();
      width = screenSize.getWidth(); // gd.getDisplayMode().getWidth();
      height = screenSize.getHeight(); // gd.getDisplayMode().getHeight();
    } catch (Exception excep) {
      System.out.println("<----- Exception in  Get Screen Size ----->");
      excep.printStackTrace();
      System.out.println("<---------->\n");
    }

    try {
      dbCon =
          DriverManager.getConnection(
              "jdbc:mysql://192.168.1.6:3306/ale", "Root", "oqu#$XQgHFzDj@1MGg1G8");
      estCon = true;
    } catch (SQLException sqlExcep) {
      System.out.println("<----- SQL Exception in Establishing Database Connection ----->");
      sqlExcep.printStackTrace();
      System.out.println("<---------->\n");
    }

    xmlParser.generateUserInfo();
    superUser = xmlParser.getSuperUser();

    // ----------------------------------------------------------------------------------------------------> Top Panel Start

    closeBtn = new Button("");
    closeBtn.getStyleClass().add("systemBtn");
    closeBtn.setOnAction(
        e -> {
          systemClose();
        });

    minimizeBtn = new Button("");
    minimizeBtn.getStyleClass().add("systemBtn");
    minimizeBtn.setOnAction(
        e -> {
          primaryStage.setIconified(true);
        });

    miscContainer = new HBox();

    calcBtn = new Button();
    calcBtn.getStyleClass().addAll("calcBtn");
    calcBtn.setOnAction(
        e -> {
          calculator calculator = new calculator();
          scientificCalculator scientificCalculator = new scientificCalculator();
          calculator.start(calculatorName);
        });

    miscContainer.getChildren().add(calcBtn);

    topPanel = new HBox(1);
    topPanel.getStyleClass().add("topPanel");
    topPanel.setPrefWidth(width);
    topPanel.setAlignment(Pos.CENTER_RIGHT);
    topPanel.setPadding(new Insets(0, 0, 0, 0));
    topPanel.getChildren().addAll(miscContainer, minimizeBtn, closeBtn);

    // ------------------------------------------------------------------------------------------------------> Top Panel End

    // ----------------------------------------------------------------------------------------------> Navigation Panel Start

    Line initDivider = new Line();
    initDivider.setStartX(0.0f);
    initDivider.setEndX(205.0f);
    initDivider.setStroke(Color.GRAY);

    // <----- Dashboard ----->
    dashboardToolTip = new Tooltip("Dashboard");

    dashboardBtn = new Button("");
    dashboardBtn.getStyleClass().add("dashboardBtn");
    dashboardBtn.setTooltip(dashboardToolTip);
    dashboardBtn.setOnAction(
        e -> {
          resetBtns();
          rootPane.setCenter(dashBoardBase);
        });

    // <----- Profile ----->
    profileToolTip = new Tooltip("Profile");

    profileBtn = new Button();
    profileBtn.getStyleClass().add("profileBtn");
    profileBtn.setTooltip(profileToolTip);
    profileBtn.setOnAction(
        e -> {
          resetBtns();
          rootPane.setCenter(profilePanel);
        });

    // <----- Courses ----->
    courseToolTip = new Tooltip("Courses");

    coursesBtn = new Button("");
    coursesBtn.getStyleClass().add("coursesBtn");
    coursesBtn.setTooltip(courseToolTip);
    coursesBtn.setOnAction(
        e -> {
          resetBtns();
          rootPane.setCenter(coursesPanel);
          // miscContainer.getChildren().addAll(watchVidBtn);
          coursesPanel.setContent(coursesGridPanel);
        });

    Line mainDivider = new Line();
    mainDivider.setStartX(0.0f);
    mainDivider.setEndX(205.0f);
    mainDivider.setStroke(Color.GRAY);

    // <----- Simulations ----->
    simsToolTip = new Tooltip("Simulations");

    simsBtn = new Button();
    simsBtn.getStyleClass().add("simsBtn");
    simsBtn.setTooltip(simsToolTip);
    simsBtn.setOnAction(
        e -> {
          resetBtns();
          rootPane.setCenter(simsPanel);
          simsPanel.setContent(simsGridPanel);
        });

    // <----- Text Editor ----->
    textEditorToolTip = new Tooltip("Text Editor");

    textEditorBtn = new Button();
    textEditorBtn.getStyleClass().add("textEditorBtn");
    textEditorBtn.setTooltip(textEditorToolTip);
    textEditorBtn.setOnAction(
        e -> {
          resetBtns();
          rootPane.setCenter(textEditorPanel);
          miscContainer.getChildren().addAll(saveDocBtn);
        });

    Line toolsDivider = new Line();
    toolsDivider.setStartX(0.0f);
    toolsDivider.setEndX(205.0f);
    toolsDivider.setStroke(Color.GRAY);

    // <----- Wolfram Alpha ----->
    wolframToolTip = new Tooltip("Wolfram Alpha");

    wolframBtn = new Button();
    wolframBtn.getStyleClass().add("wolframBtn");
    wolframBtn.setTooltip(wolframToolTip);
    wolframBtn.setOnAction(
        e -> {
          resetBtns();
          rootPane.setCenter(wolframPanel);
        });

    // <----- Wikipedia ----->
    wikipediaToolTip = new Tooltip();

    wikipediaBtn = new Button();
    wikipediaBtn.getStyleClass().add("wikipediaBtn");
    wikipediaBtn.setTooltip(wikipediaToolTip);
    wikipediaBtn.setOnAction(
        e -> {
          resetBtns();
          rootPane.setCenter(wikipediaPanel);
        });

    Line sitesDivider = new Line();
    sitesDivider.setStartX(0.0f);
    sitesDivider.setEndX(205.0f);
    sitesDivider.setStroke(Color.GRAY);

    // <----- Settings ----->
    settingsToolTip = new Tooltip("Settings");

    settingsBtn = new Button();
    settingsBtn.getStyleClass().add("settingsBtn");
    settingsBtn.setTooltip(settingsToolTip);
    settingsBtn.setOnAction(
        e -> {
          resetBtns();
          rootPane.setCenter(settingsPanel);
        });

    leftPanel = new VBox(0);
    // leftPanel.setPrefWidth(1);
    leftPanel.getStyleClass().add("leftPane");
    leftPanel
        .getChildren()
        .addAll(
            initDivider,
            dashboardBtn,
            profileBtn,
            coursesBtn,
            mainDivider,
            simsBtn,
            textEditorBtn,
            toolsDivider,
            wolframBtn,
            wikipediaBtn,
            sitesDivider,
            settingsBtn);

    topPanel = new HBox(1);
    topPanel.getStyleClass().add("topPanel");
    topPanel.setPrefWidth(width);
    topPanel.setAlignment(Pos.CENTER_RIGHT);
    topPanel.setPadding(new Insets(0, 0, 0, 0));
    topPanel.getChildren().addAll(miscContainer, minimizeBtn, closeBtn);

    // ------------------------------------------------------------------------------------------------> Navigation Panel End

    // -----------------------------------------------------------------------------------------------> Dashboard Pane Start

    final WebView webVid = new WebView();
    final WebEngine webVidEngine = webVid.getEngine();
    webVid.setPrefHeight(860);
    webVid.setPrefWidth(width - 118);
    webVidEngine.loadContent("");

    final NumberAxis xAxis = new NumberAxis();
    final NumberAxis yAxis = new NumberAxis();
    xAxis.setLabel("Day");
    yAxis.setLabel("Score");
    final LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);

    lineChart.setTitle("Line Chart");
    XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
    series.setName("My Data");

    // populating the series with data
    series.getData().add(new XYChart.Data<Number, Number>(0.25, 36));
    series.getData().add(new XYChart.Data<Number, Number>(1, 23));
    series.getData().add(new XYChart.Data<Number, Number>(2, 114));
    series.getData().add(new XYChart.Data<Number, Number>(3, 15));
    series.getData().add(new XYChart.Data<Number, Number>(4, 124));
    lineChart.getData().add(series);
    lineChart.setPrefWidth(400);
    lineChart.setPrefHeight(300);
    lineChart.setLegendVisible(false);

    chatRoomField = new TextField();
    chatRoomField.getStyleClass().add("textField");
    chatRoomField.setPromptText("Enter Chat Room");
    chatRoomField.setOnKeyPressed(
        new EventHandler<KeyEvent>() {
          @Override
          public void handle(KeyEvent event) {
            if (event.getCode() == KeyCode.ENTER) {
              chatRoom = chatRoomField.getText();
              client.connect(messageArea, messageInputArea, superUser, chatRoom);
            }
          }
        });

    messageArea = new TextArea();
    messageArea.getStyleClass().add("textArea");
    messageArea.setWrapText(true);
    messageArea.setPrefHeight(740);
    messageArea.setEditable(false);

    messageInputArea = new TextArea();
    messageInputArea.getStyleClass().add("textArea");
    messageInputArea.setWrapText(true);
    messageInputArea.setPrefHeight(100);
    messageInputArea.setPromptText("Enter Message");
    messageInputArea.setOnKeyPressed(
        new EventHandler<KeyEvent>() {
          @Override
          public void handle(KeyEvent event) {
            if (event.getCode() == KeyCode.ENTER) {
              client.send(messageArea, messageInputArea, superUser, chatRoom);
              event.consume();
            }
          }
        });

    chatBox = new VBox();
    chatBox.setPrefWidth(250);
    chatBox.setMaxWidth(250);
    chatBox.getStyleClass().add("chatBox");
    chatBox.getChildren().addAll(chatRoomField, messageArea, messageInputArea);

    // client.test(messageArea, messageInputArea);

    dashboardGridPanel = new GridPane();
    dashboardGridPanel.getStyleClass().add("gridPane");
    dashboardGridPanel.setVgap(5);
    dashboardGridPanel.setHgap(5);
    dashboardGridPanel.setGridLinesVisible(false);
    dashboardGridPanel.setPrefWidth(width - 430);
    dashboardGridPanel.setPrefHeight(860);

    dashboardGridPanel.setColumnIndex(lineChart, 0);
    dashboardGridPanel.setRowIndex(lineChart, 0);
    dashboardGridPanel.getChildren().addAll(lineChart);

    dashboardPanel = new ScrollPane();
    dashboardPanel.getStyleClass().add("scrollPane");
    dashboardPanel.setPrefWidth(width - 400);
    dashboardPanel.setPrefHeight(860);
    dashboardPanel.setContent(dashboardGridPanel);

    dashBoardBase = new HBox();
    dashBoardBase.setPrefWidth(width - (leftPanel.getWidth() + chatBox.getWidth()));
    dashBoardBase.setPrefHeight(860);
    dashBoardBase.getChildren().addAll(dashboardPanel, chatBox);

    // -------------------------------------------------------------------------------------------------> Dashboard Pane End

    // -------------------------------------------------------------------------------------------------> Profile Pane Start

    profilePictureBtn = new Button();
    profilePictureBtn.getStyleClass().addAll("profilePictureBtn");

    String profileUserName = xmlParser.getSuperUser();

    String profileEmail = xmlParser.getEmail();
    String profileAge = xmlParser.getAge();
    String profileSchool = xmlParser.getSchool();
    String profileCountry = "";
    String profileCity = "";

    userNameLbl = new Label(profileUserName);
    userNameLbl.getStyleClass().add("profileLbl");
    userNameLbl.setAlignment(Pos.CENTER);

    emailLbl = new Label(profileEmail);
    emailLbl.getStyleClass().add("profileLbl");

    ageLbl = new Label(profileAge);
    ageLbl.getStyleClass().add("profileLbl");

    schoolLbl = new Label(profileSchool);
    schoolLbl.getStyleClass().add("profileLbl");

    profileGridPanel = new GridPane();
    profileGridPanel.getStyleClass().add("gridPane");
    profileGridPanel.setVgap(5);
    profileGridPanel.setHgap(5);
    profileGridPanel.setGridLinesVisible(false);
    profileGridPanel.setPrefWidth(width - 208);
    profileGridPanel.setPrefHeight(860);
    profileGridPanel.setAlignment(Pos.TOP_CENTER);

    profileGridPanel.setRowIndex(profilePictureBtn, 0);
    profileGridPanel.setColumnIndex(profilePictureBtn, 0);
    profileGridPanel.setRowIndex(userNameLbl, 1);
    profileGridPanel.setColumnIndex(userNameLbl, 0);
    profileGridPanel.setRowIndex(emailLbl, 2);
    profileGridPanel.setColumnIndex(emailLbl, 0);
    profileGridPanel.setRowIndex(ageLbl, 3);
    profileGridPanel.setColumnIndex(ageLbl, 0);
    profileGridPanel.setRowIndex(schoolLbl, 4);
    profileGridPanel.setColumnIndex(schoolLbl, 0);
    profileGridPanel
        .getChildren()
        .addAll(profilePictureBtn, userNameLbl, emailLbl, ageLbl, schoolLbl);

    profilePanel = new ScrollPane();
    profilePanel.getStyleClass().add("scrollPane");
    profilePanel.setContent(profileGridPanel);

    // ---------------------------------------------------------------------------------------------------> Profile Pane End

    // -------------------------------------------------------------------------------------------------> Courses Pane Start

    String course = "";

    // Media media = new Media("media.mp4");

    // mediaPlayer = new MediaPlayer(media);
    // mediaPlayer.setAutoPlay(true);

    // mediaView = new MediaView(mediaPlayer);

    watchVidBtn = new Button("Watch Video");
    watchVidBtn.getStyleClass().add("btn");
    watchVidBtn.setOnAction(
        e -> {

          // coursesPanel.setContent(mediaView);
        });

    chemistryBtn = new Button();
    chemistryBtn.getStyleClass().add("chemistryBtn");
    chemistryBtn.setOnAction(
        e -> {
          displayCourse("chemistry");
        });

    physicsBtn = new Button();
    physicsBtn.getStyleClass().add("physicsBtn");
    physicsBtn.setOnAction(
        e -> {
          displayCourse("physics");
        });

    mathsBtn = new Button();
    mathsBtn.getStyleClass().add("mathsBtn");

    bioBtn = new Button();
    bioBtn.getStyleClass().add("bioBtn");
    bioBtn.setOnAction(
        e -> {
          rootPane.setCenter(biologyCourse.biologyPane());
        });

    // Course Web View
    try {
      courseView = new WebView();
      courseWebEngine = courseView.getEngine();
      courseView.setPrefHeight(860);
      courseView.setPrefWidth(width - 208);
    } catch (Exception excep) {
      System.out.println("<----- Exception in Course Web ----->");
      excep.printStackTrace();
      System.out.println("<---------->\n");
    }

    coursesGridPanel = new GridPane();
    coursesGridPanel.getStyleClass().add("gridPane");
    coursesGridPanel.setVgap(5);
    coursesGridPanel.setHgap(5);
    coursesGridPanel.setGridLinesVisible(false);
    coursesGridPanel.setPrefWidth(width - 208);
    coursesGridPanel.setPrefHeight(860);

    coursesGridPanel.setRowIndex(chemistryBtn, 1);
    coursesGridPanel.setColumnIndex(chemistryBtn, 1);
    coursesGridPanel.setRowIndex(physicsBtn, 1);
    coursesGridPanel.setColumnIndex(physicsBtn, 2);
    coursesGridPanel.setRowIndex(mathsBtn, 1);
    coursesGridPanel.setColumnIndex(mathsBtn, 3);
    coursesGridPanel.setRowIndex(bioBtn, 1);
    coursesGridPanel.setColumnIndex(bioBtn, 4);
    coursesGridPanel.getChildren().addAll(chemistryBtn, physicsBtn, mathsBtn, bioBtn);

    coursesPanel = new ScrollPane();
    coursesPanel.getStyleClass().add("scrollPane");
    coursesPanel.setPrefWidth(width - 118);
    coursesPanel.setPrefHeight(860);
    coursesPanel.setContent(coursesGridPanel);

    // ---------------------------------------------------------------------------------------------------> Courses Pane End

    // ---------------------------------------------------------------------------------------------> Simulations Pane Start
    final WebView browser = new WebView();
    final WebEngine webEngine = browser.getEngine();
    browser.setPrefHeight(860);
    browser.setPrefWidth(width - 208);

    /*
    File phetImageFile = new File("img/styleDark/poweredByPHET.png");
    String phetImageURL = phetImageFile.toURI().toURL().toString();
    Image phetImage = new Image(phetImageURL, false);
    */

    final ImageView phetImageView = new ImageView();
    final Image phetImage =
        new Image(Main.class.getResourceAsStream("img/styleDark/poweredByPHET.png"));
    phetImageView.setImage(phetImage);

    Label motionLbl = new Label("Motion");
    motionLbl.getStyleClass().add("lbl");

    forcesAndMotionBtn = new Button();
    forcesAndMotionBtn.getStyleClass().add("forcesAndMotionBtn");
    forcesAndMotionBtn.setOnAction(
        e -> {
          webEngine.load(
              "https://phet.colorado.edu/sims/html/balancing-act/latest/balancing-act_en.html");
          simsPanel.setContent(browser);
        });

    balancingActBtn = new Button();
    balancingActBtn.getStyleClass().add("balancingActBtn");
    balancingActBtn.setOnAction(
        e -> {
          webEngine.load(
              "https://phet.colorado.edu/sims/html/balancing-act/latest/balancing-act_en.html");
          simsPanel.setContent(browser);
        });

    energySkateParkBtn = new Button();
    energySkateParkBtn.getStyleClass().add("energySkateParkBtn");
    energySkateParkBtn.setOnAction(
        e -> {
          webEngine.load(
              "https://phet.colorado.edu/sims/html/energy-skate-park-basics/latest/"
                  + "energy-skate-park-basics_en.html");
          simsPanel.setContent(browser);
        });

    balloonsAndStaticElectricityBtn = new Button();
    balloonsAndStaticElectricityBtn.getStyleClass().add("balloonsAndStaticElectricityBtn");
    balloonsAndStaticElectricityBtn.setOnAction(
        e -> {
          webEngine.load(
              "https://phet.colorado.edu/sims/html/balloons-and-static-electricity/latest/"
                  + "balloons-and-static-electricity_en.html");
          simsPanel.setContent(browser);
        });

    buildAnAtomBtn = new Button();
    buildAnAtomBtn.getStyleClass().add("buildAnAtomBtn");
    buildAnAtomBtn.setOnAction(
        e -> {
          webEngine.load(
              "https://phet.colorado.edu/sims/html/build-an-atom/latest/build-an-atom_en.html");
          simsPanel.setContent(browser);
        });

    colorVisionBtn = new Button();
    colorVisionBtn.getStyleClass().add("colorVisionBtn");
    colorVisionBtn.setOnAction(
        e -> {
          webEngine.load(
              "https://phet.colorado.edu/sims/html/color-vision/latest/color-vision_en.html");
          simsPanel.setContent(browser);
        });

    Label soundAndWavesLbl = new Label("Sound and Waves");
    soundAndWavesLbl.getStyleClass().add("lbl");

    wavesOnAStringBtn = new Button();
    wavesOnAStringBtn.getStyleClass().add("wavesOnAStringBtn");
    wavesOnAStringBtn.setOnAction(
        e -> {
          webEngine.load(
              "https://phet.colorado.edu/sims/html/wave-on-a-string/latest/wave-on-a-string_en.html");
          simsPanel.setContent(browser);
        });

    /*
    motionSimsFlowPane = new FlowPane();
    motionSimsFlowPane.getStyleClass().add("flowPane");
    motionSimsFlowPane.setVgap(5);
    motionSimsFlowPane.setHgap(5);
    motionSimsFlowPane.setAlignment(Pos.TOP_LEFT);
    motionSimsFlowPane.getChildren().addAll(forcesAndMotionBtn, balancingActBtn, energySkateParkBtn,
            buildAnAtomBtn, colorVisionBtn, wavesOnAStringBtn);


    soundAndWavesFlowPane = new FlowPane();
    soundAndWavesFlowPane.getStyleClass().add("flowPane");
    soundAndWavesFlowPane.setVgap(5);
    soundAndWavesFlowPane.setHgap(5);
    soundAndWavesFlowPane.setAlignment(Pos.TOP_LEFT);
    soundAndWavesFlowPane.getChildren().addAll(wavesOnAStringBtn);


    simsBox = new VBox();
    simsBox.getStyleClass().add("vbox");
    simsBox.setPrefHeight(height);
    simsBox.setPrefWidth(width);
    simsBox.getChildren().addAll(motionLbl, motionSimsFlowPane, soundAndWavesLbl, soundAndWavesFlowPane);
    */

    simsGridPanel = new GridPane();
    simsGridPanel.getStyleClass().add("gridPane");
    simsGridPanel.setVgap(5);
    simsGridPanel.setHgap(5);
    simsGridPanel.setGridLinesVisible(false);
    simsGridPanel.setPrefWidth(width - 208);
    simsGridPanel.setPrefHeight(860);

    simsGridPanel.setRowIndex(phetImageView, 0);
    simsGridPanel.setColumnIndex(phetImageView, 4);

    simsGridPanel.setRowIndex(motionLbl, 0);
    simsGridPanel.setColumnIndex(motionLbl, 0);
    simsGridPanel.setRowIndex(forcesAndMotionBtn, 1);
    simsGridPanel.setColumnIndex(forcesAndMotionBtn, 0);
    simsGridPanel.setRowIndex(balancingActBtn, 1);
    simsGridPanel.setColumnIndex(balancingActBtn, 1);
    simsGridPanel.setRowIndex(energySkateParkBtn, 1);
    simsGridPanel.setColumnIndex(energySkateParkBtn, 2);
    simsGridPanel.setRowIndex(buildAnAtomBtn, 1);
    simsGridPanel.setColumnIndex(buildAnAtomBtn, 3);
    simsGridPanel.setRowIndex(colorVisionBtn, 1);
    simsGridPanel.setColumnIndex(colorVisionBtn, 4);

    simsGridPanel.setRowIndex(soundAndWavesLbl, 2);
    simsGridPanel.setColumnIndex(soundAndWavesLbl, 0);
    simsGridPanel.setColumnSpan(soundAndWavesLbl, 4);
    simsGridPanel.setRowIndex(wavesOnAStringBtn, 3);
    simsGridPanel.setColumnIndex(wavesOnAStringBtn, 0);

    simsGridPanel
        .getChildren()
        .addAll(
            phetImageView,
            motionLbl,
            forcesAndMotionBtn,
            balancingActBtn,
            energySkateParkBtn,
            buildAnAtomBtn,
            colorVisionBtn,
            soundAndWavesLbl,
            wavesOnAStringBtn);

    simsPanel = new ScrollPane();
    simsPanel.getStyleClass().add("scrollPane");
    simsPanel.setContent(simsGridPanel);

    // -----------------------------------------------------------------------------------------------> Simulations Pane End

    // ---------------------------------------------------------------------------------------------> Text Editor Pane Start

    htmlEditor = new HTMLEditor();
    htmlEditor.setPrefHeight(860);
    htmlEditor.setPrefWidth(width - 208);

    // Prevents Scroll on Space Pressed
    htmlEditor.addEventFilter(
        KeyEvent.KEY_PRESSED,
        new EventHandler<KeyEvent>() {
          @Override
          public void handle(KeyEvent event) {
            if (event.getEventType() == KeyEvent.KEY_PRESSED) {
              if (event.getCode() == KeyCode.SPACE) {
                event.consume();
              }
            }
          }
        });

    XWPFDocument document = new XWPFDocument();
    XWPFParagraph tmpParagraph = document.createParagraph();
    XWPFRun tmpRun = tmpParagraph.createRun();

    saveDocBtn = new Button();
    saveDocBtn.getStyleClass().add("btn");
    saveDocBtn.setText("Save");
    saveDocBtn.setOnAction(
        e -> {
          tmpRun.setText(tools.stripHTMLTags(htmlEditor.getHtmlText()));
          tmpRun.setFontSize(12);
          saveDocument(document, primaryStage);
        });

    textEditorPanel = new ScrollPane();
    textEditorPanel.getStyleClass().add("scrollPane");
    textEditorPanel.setContent(htmlEditor);

    // -----------------------------------------------------------------------------------------------> Text Editor Pane End

    // -------------------------------------------------------------------------------------------------> Wolfram Pane Start

    Boolean wolframActive = false;
    try {
      final WebView wolframWeb = new WebView();
      wolframWeb.getStyleClass().add("webView");
      final WebEngine wolframWebEngine = wolframWeb.getEngine();
      wolframWeb.setPrefHeight(860);
      wolframWeb.setPrefWidth(width - 208);
      if (wolframActive == false) {
        wolframWebEngine.load("http://www.wolframalpha.com/");
        wolframActive = true;
      }
      wolframPanel = new ScrollPane();
      wolframPanel.setContent(wolframWeb);
    } catch (Exception excep) {
      System.out.println("<----- Exception in Wolfram Alpha Web ----->");
      excep.printStackTrace();
      System.out.println("<---------->\n");
    }

    // ---------------------------------------------------------------------------------------------------> Wolfram Pane End

    // ------------------------------------------------------------------------------------------------> Wikipedia Pane Start

    Boolean wikipediaActive = false;
    try {
      final WebView wikipediaWeb = new WebView();
      wikipediaWeb.getStyleClass().add("scrollPane");
      wikipediaWebEngine = wikipediaWeb.getEngine();
      wikipediaWeb.setPrefHeight(860);
      wikipediaWeb.setPrefWidth(width - 208);
      if (wikipediaActive == false) {
        wikipediaWebEngine.load("https://en.wikipedia.org/wiki/Main_Page");
        wikipediaActive = true;
      }
      wikipediaPanel = new ScrollPane();
      wikipediaPanel.setContent(wikipediaWeb);
    } catch (Exception e) {
      e.printStackTrace();
    }

    // --------------------------------------------------------------------------------------------------> Wikipedia Pane End

    // -------------------------------------------------------------------------------------------------> Settings Pane Start

    settingsGridPanel = new GridPane();
    settingsGridPanel.getStyleClass().add("gridPane");
    settingsGridPanel.setPrefWidth(width - 208);
    settingsGridPanel.setPrefHeight(height);
    settingsGridPanel.setVgap(5);
    settingsGridPanel.setHgap(5);

    settingsPanel = new ScrollPane();
    settingsPanel.getStyleClass().add("scrollPane");
    settingsPanel.setContent(settingsGridPanel);

    // ---------------------------------------------------------------------------------------------------> Settings Pane End
    rootPane = new BorderPane();
    rootPane.setLeft(leftPanel);
    rootPane.setTop(topPanel);
    rootPane.setCenter(dashBoardBase);
    rootPane.getStyleClass().add("rootPane");
    rootPane.getStylesheets().add(Main.class.getResource("css/styleDark.css").toExternalForm());

    programWidth = primaryStage.getWidth();
    programHeight = primaryStage.getHeight();

    primaryStage.setTitle("ALE");
    primaryStage.initStyle(StageStyle.UNDECORATED);
    primaryStage
        .getIcons()
        .add(new javafx.scene.image.Image(Main.class.getResourceAsStream("img/aleIcon.png")));
    primaryStage.setScene(new Scene(rootPane, width, height));
    primaryStage.show();
  }
Exemple #5
0
  public void setLyrics() throws IOException {

    lyrStage = new Stage();
    lyrStage.setTitle("Lyrics setting");
    lyrStage.setHeight(420);
    AnchorPane root = new AnchorPane();
    root.setStyle(
        "-fx-border-color: black, transparent; -fx-border-width: 1px, 5px; -fx-border-insets: 0px, 1px");

    root.setOnMouseDragged(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent me) {
            lyrStage.setX(me.getScreenX());
            lyrStage.setY(me.getScreenY());
          }
        });

    lyrStage.initStyle(StageStyle.UNDECORATED);
    Scene scene = new Scene(root);

    final TextArea lyricArea = new TextArea();

    lyrStage.setScene(scene);

    lyricArea.setPrefHeight(100);
    lyricArea.setPrefWidth(190);
    lyricArea.setMinHeight(100);
    lyricArea.setLayoutY(315);
    lyricArea.setLayoutX(7);
    lyricArea.setMaxWidth(TextField.USE_PREF_SIZE);

    final Label label = new Label();
    /*
            final ScrollPane sp = new ScrollPane();
            sp.setPrefSize(200, 200);
            sp.setHbarPolicy(ScrollBarPolicy.AS_NEEDED);
            sp.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
            sp.setPannable(true);
            sp.setContent(label);
            sp.vvalueProperty().addListener(new ChangeListener<Number>() {
                @Override
                public void changed(ObservableValue<? extends Number> ov,
                    Number old_val, Number new_val) {
                        label.setLayoutY(-new_val.doubleValue());
                        label.setLayoutX(-new_val.doubleValue());
                }
            });
    */

    label
        .textProperty()
        .bind(
            new StringBinding() {
              {
                bind(lyricArea.textProperty());
              }

              @Override
              protected String computeValue() {

                String text = lyricArea.getText();

                return "Lyric preview: \n\n " + songName + "\n\n" + text;
              }
            });

    final VBox vBox = new VBox();
    vBox.setPrefHeight(800); // ////////////////////////////////////////
    vBox.setPrefWidth(240);
    vBox.setPadding(new Insets(18));
    vBox.getChildren().addAll(label);

    final VBox vBox2 = new VBox();
    vBox2.setPrefHeight(340);
    vBox2.setPrefWidth(240);
    vBox2.setAlignment(Pos.BOTTOM_RIGHT);

    Button btnText = new Button();
    btnText.setText("Ok");
    btnText.setStyle("-fx-base: white;");
    btnText.setOnAction(
        new EventHandler<ActionEvent>() {

          @Override
          public void handle(ActionEvent event) {
            String txt = lyricArea.getText();
            textSet(txt);
            lyrStage.close();
          }
        });

    vBox2.getChildren().add(btnText);

    ScrollBar sc = new ScrollBar();
    sc.setMin(0);
    sc.setMax(500);
    sc.setValue(30);
    sc.setPrefWidth(3);
    sc.setPrefHeight(160);
    sc.setVisibleAmount(10);
    sc.setOrientation(Orientation.VERTICAL);

    sc.valueProperty()
        .addListener(
            new ChangeListener<Number>() {
              @Override
              public void changed(
                  ObservableValue<? extends Number> ov, Number old_val, Number new_val) {
                label.setLayoutY(-new_val.doubleValue());
              }
            });

    root.getChildren().addAll(vBox, lyricArea, vBox2, sc);

    lyrStage.setX(50);
    lyrStage.setY(50);

    lyrStage.show();
  }