Exemplo n.º 1
0
 private String prompt(final String msg, final String value) {
   final String[] toReturn = new String[1];
   platformRunNow(
       () -> {
         final TextInputDialog dialog = new TextInputDialog(value == null ? "" : value);
         dialog.initOwner(application.getPrimaryStage());
         dialog.setHeaderText(msg);
         final Optional<String> result = dialog.showAndWait();
         toReturn[0] = result.isPresent() ? result.get() : null;
       });
   return toReturn[0];
 }
Exemplo n.º 2
0
 public static Integer showMsgQuantityPopup(String title, String header, String content) {
   TextInputDialog dialog = new TextInputDialog();
   dialog.setTitle(title);
   dialog.setHeaderText(header);
   dialog.setContentText(content);
   Integer retVal = null;
   Optional<String> result = dialog.showAndWait();
   if (result.isPresent() && result.get().matches("\\d+")) {
     retVal = Integer.parseInt(result.get());
   }
   return retVal;
 }
  public void HandleGoToLineAction() {
    TextInputDialog dialog = new TextInputDialog();
    dialog.setTitle("Aller à la ligne");
    dialog.setHeaderText(null);
    dialog.setContentText("Numéro de ligne: ");

    Optional<String> result = dialog.showAndWait();
    result.ifPresent(
        line ->
            SourceText.positionCaret(
                SourceText.position(Integer.parseInt(line) - 1, 0).toOffset()));
  }
Exemplo n.º 4
0
 private void onCreateNewCollection(ActionEvent ev) {
   TextInputDialog dialog = new TextInputDialog();
   dialog.setContentText("Enter Name:");
   dialog.setHeaderText("Create new collection");
   dialog
       .showAndWait()
       .ifPresent(
           r -> {
             DbTreeValue value = treeView.getSelectionModel().getSelectedItem().getValue();
             value.getMongoDatabase().createCollection(dialog.getResult());
             reloadSelectedTreeItem();
           });
 }
Exemplo n.º 5
0
  public boolean saveGame(String saveName, int index) {
    if (saveName == null || index < 1) {
      // User create new save slot

      TextInputDialog dialog = new TextInputDialog("Slot1");
      dialog.setTitle(SAVE_DIALOG);
      dialog.setHeaderText("Please enter save state name:");
      Optional<String> result = dialog.showAndWait();
      if (result.isPresent()) {
        // name was inputed
        if (saveGameDao.isSaveExists(result.get())) {
          // duplicated name
          Alert alert = new Alert(AlertType.ERROR);
          alert.setTitle("Save Error Dialog");
          alert.setHeaderText("Save with this name exists.");
          alert.showAndWait();
          return false;

        } else {
          // there are no saves with that name
          SaveGameDTO saveGame = game.getSaveGame(result.get());
          saveGameDao.insertSave(saveGame);

          Alert alert = new Alert(AlertType.INFORMATION);
          alert.setTitle(SAVE_DIALOG);
          alert.setHeaderText("You successfully save the game.");
          alert.showAndWait();
          return true;
        }
      } else {
        // no name typed

        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Save Error Dialog");
        alert.setHeaderText("No name typed.");
        alert.showAndWait();
        return false;
      }

    } else {
      // User override slot
      SaveGameDTO saveGame = game.getSaveGame(saveName);
      saveGameDao.updateSave(saveGame);

      Alert alert = new Alert(AlertType.INFORMATION);
      alert.setTitle(SAVE_DIALOG);
      alert.setHeaderText("You successfully save the game.");
      alert.showAndWait();
      return true;
    }
  }
  public void addTeam(ActionEvent event) {
    TextInputDialog dialog = new TextInputDialog();
    dialog.setTitle("Text Input Dialog");
    dialog.setHeaderText(null);
    dialog.setContentText("Please enter Team name:");

    // Traditional way to get the response value.
    Optional<String> result = dialog.showAndWait();
    if (result.isPresent()) {
      String actualresult = result.toString().replaceAll("Optional", "");
      actualresult = actualresult.replaceAll("[^a-zA-Z0-9]", "");
      list1.add(actualresult);
    }
  }
Exemplo n.º 7
0
  /** ******** */
  private String setPassword() {
    TextInputDialog dialog = new TextInputDialog("Password");
    dialog.setTitle("Password");
    dialog.setHeaderText("Password Setting");

    dialog.setContentText("Please enter the password:"******"";
    }
  }
  public void addPlayer(ActionEvent event) {

    if (cbst.getValue() == null) {
      Alert alert = new Alert(AlertType.ERROR);
      alert.setTitle("No Team Selected");
      alert.setHeaderText(null);
      alert.setContentText("Please select a team.");
      alert.showAndWait();
    } else {
      TextInputDialog dialog = new TextInputDialog();
      dialog.setTitle("Text Input Dialog");
      dialog.setHeaderText(null);
      dialog.setContentText("Please enter Player name:");
      String actualresult = " ";
      Optional<String> result = dialog.showAndWait();
    }
  }
Exemplo n.º 9
0
  void renameTrack() {
    if (interfaceDisabled) return;
    Playlist p = getSelectedPlaylist();
    if (p == null) return;
    Track t = getSelectedTrack();
    if (t == null) return;

    TextInputDialog dialog = new TextInputDialog(t.getTitle());
    dialog.setTitle(res.getString("rename_track"));
    dialog.setHeaderText(res.getString("rename_track"));
    dialog.setContentText(res.getString("enter_new_title"));
    dialog.getDialogPane().getStylesheets().add("/styles/dialogs.css");
    ((Stage) dialog.getDialogPane().getScene().getWindow()).getIcons().addAll(logoImages);
    Optional<String> result = dialog.showAndWait();
    result.ifPresent(
        title -> {
          if (StringUtils.isEmpty(title)) {
            return;
          }
          Cache.renameTrack(t, p, title);
          Platform.runLater(
              () -> {
                loadSelectedPlaylist();
              });
        });
  }
Exemplo n.º 10
0
  @FXML
  public void decipherButtonClick(ActionEvent event) {
    deOpenLabel.setText("");
    enSaveLabel.setText("");
    switch (choiceBox.getSelectionModel().getSelectedItem()) {
      case "Simple ASCII Cipher":
        textArea.setText(CipherMaker.decipherSimple(textArea.getText()));
        break;
      case "Cesar Chiper":
        textArea.setText(CipherMaker.decipherCesar(textArea.getText()));
        break;
      case "Vigenere":
        if (!textArea.getText().equals("")) {
          TextInputDialog dialog = new TextInputDialog();
          dialog.setTitle("Cipher-Code");
          dialog.setHeaderText("Type in a Password to decipher your text with!");
          dialog.setContentText("Enter your password here...");

          Optional<String> result = dialog.showAndWait();
          if (result.isPresent()) {
            textArea.setText(CipherMaker.decipherVigenere(textArea.getText(), result.get()));
          }
        }
        break;
      case "RC4":
        if (!textArea.getText().equals("")) {
          TextInputDialog dialog = new TextInputDialog();
          dialog.setTitle("Cipher-Code");
          dialog.setHeaderText("Type in the number to decipher!");
          dialog.setContentText("Enter your number here...");

          Optional<String> result = dialog.showAndWait();
          if (result.isPresent() && result.get().matches("[0-9]+")) {
            textArea.setText(
                CipherMaker.decipherRC4(textArea.getText(), Integer.parseInt(result.get())));
          } else {
            deOpenLabel.setText("Decipher not possible...");
          }
        }

        break;
    }
  }
Exemplo n.º 11
0
  private String getUserName() {
    TextInputDialog dialog = new TextInputDialog();
    dialog.setTitle("New Chat");
    dialog.setHeaderText("");
    dialog.setContentText("Please enter your name:");

    // Traditional way to get the response value.
    Optional<String> result = dialog.showAndWait();
    if (result.isPresent()) {
      String userName = result.get();
      if (!userName.equals("")) {
        return userName;
      } else {
        return String.format("user_%d", new Random().nextInt(10000));
      }
    } else {
      return String.format("user_%d", new Random().nextInt(10000));
    }
  }
Exemplo n.º 12
0
  @FXML
  public void onDragDroppedFolder(DragEvent event) {
    Dragboard dragboard = event.getDragboard();

    File folder = dragboard.getFiles().get(0);

    DestinationFolder dest = new DestinationFolder(folder);

    if (this.repository.existsSameFolder(dest)) {
      Alert alert = new Alert(AlertType.ERROR);
      alert.setTitle("エラー");
      alert.setHeaderText("既にフォルダが登録されています。");
      alert.getDialogPane().setContentText(dest.getDestPath());
      alert.show();
    } else {
      TextInputDialog dialog = new TextInputDialog();
      dialog.setTitle("フォルダ追加");
      dialog.setContentText("フォルダ名");
      dialog.setHeaderText(dest.getDestPath());
      dialog.getEditor().setText(dest.getName());

      dialog.setOnCloseRequest(
          e -> {
            TextInputDialog d = (TextInputDialog) e.getTarget();
            String result = d.getResult();

            if (result != null) {
              if (result.isEmpty()) {
                Alert alert = new Alert(AlertType.ERROR);
                alert.setTitle("エラー");
                alert.setHeaderText("フォルダ名に空は指定できません。");
                alert.show();
              } else {
                dest.setName(result);
                this.repository.registerFolder(dest);
                this.destinationFolders = repository.findAll();
                this.refreshDestFolderListView();
              }
            }
          });

      dialog.show();
    }

    event.setDropCompleted(true);
    event.consume();
  }
Exemplo n.º 13
0
  private void onReanameCollection(ActionEvent actionEvent) {
    TreeItem<DbTreeValue> selectedItem = treeView.getSelectionModel().getSelectedItem();
    if (selectedItem == null) {
      return;
    }

    DbTreeValue value = selectedItem.getValue();
    TextInputDialog dialog = new TextInputDialog(value.getDisplayValue());
    dialog.setContentText("New collection name:");
    dialog.setHeaderText("Rename collection");
    dialog
        .showAndWait()
        .ifPresent(
            targetCollection -> {
              MongoCollection<Document> collection =
                  value.getMongoDatabase().getMongoDb().getCollection(value.getDisplayValue());
              collection.renameCollection(
                  new MongoNamespace(value.getMongoDatabase().getName(), targetCollection));
              ((DynamicTreeItem) selectedItem.getParent()).reload();
            });
  }
Exemplo n.º 14
0
  public void onCreateNewDb(ActionEvent ev) {
    TreeItem<DbTreeValue> selectedItem = treeView.getSelectionModel().getSelectedItem();
    if (selectedItem == null
        || selectedItem.getValue().getValueType() != TreeValueType.CONNECTION) {
      return;
    }

    TextInputDialog dialog = new TextInputDialog();
    dialog.setContentText("Enter Name:");
    dialog.setHeaderText("Create new db");
    dialog
        .showAndWait()
        .ifPresent(
            r ->
                selectedItem
                    .getChildren()
                    .add(
                        createDbItem(
                            selectedItem
                                .getValue()
                                .getMongoConnection()
                                .createMongoDB(dialog.getResult()))));
  }
Exemplo n.º 15
0
  private void onCopyCollection(ActionEvent actionEvent) {
    TreeItem<DbTreeValue> selectedItem = treeView.getSelectionModel().getSelectedItem();
    if (selectedItem == null) {
      return;
    }

    DbTreeValue value = selectedItem.getValue();
    String sourceCollectionName = value.getDisplayValue();
    TextInputDialog dialog = new TextInputDialog(sourceCollectionName + "_copy");
    dialog.setContentText("New collection name:");
    dialog.setHeaderText("Copy collection");
    dialog
        .showAndWait()
        .ifPresent(
            targetCollection -> {
              new CopyCollectionHelper(
                      value.getMongoDatabase(), sourceCollectionName, targetCollection)
                  .copy();
              ((DynamicTreeItem) selectedItem.getParent()).reload();
              popupService.showInfo(
                  String.format(
                      "Collection %s copied to %s", sourceCollectionName, targetCollection));
            });
  }
Exemplo n.º 16
0
 void createOfflinePlaylist() {
   if (interfaceDisabled) return;
   TextInputDialog dialog = new TextInputDialog(res.getString("new_offline_playlist"));
   dialog.setTitle(res.getString("create_new_offline_playlist"));
   dialog.setHeaderText(res.getString("create_new_playlist"));
   dialog.setContentText(res.getString("enter_playlist_name"));
   dialog.getDialogPane().getStylesheets().add("/styles/dialogs.css");
   ((Stage) dialog.getDialogPane().getScene().getWindow()).getIcons().addAll(logoImages);
   Optional<String> result = dialog.showAndWait();
   result.ifPresent(
       title -> {
         Platform.runLater(
             () -> {
               Playlist newPlaylist = Cache.createPlaylist(title);
               Platform.runLater(
                   () -> {
                     playlistsView.getItems().add(newPlaylist);
                     playlistsView.getSelectionModel().select(newPlaylist);
                   });
             });
       });
 }
  @FXML
  private void changePasswordClicked(ActionEvent evt) {
    TextInputDialog changePwdDialog = new TextInputDialog();
    changePwdDialog.setTitle("Change password");
    changePwdDialog.setHeaderText(
        "Please enter the new password. \nPassword must be atleast 5 characters long.");
    // changePwdDialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK,
    // ButtonType.CANCEL);
    final Button btOk = (Button) changePwdDialog.getDialogPane().lookupButton(ButtonType.OK);
    btOk.addEventFilter(
        ActionEvent.ACTION,
        event -> {
          if (changePwdDialog.getEditor().getText().isEmpty()
              || changePwdDialog.getEditor().getText().length() < 5) {
            Notifications.create()
                .title("Empty password")
                .text(
                    "Password cannot be left empty and must be more than 5 characters. Try again.")
                .hideAfter(Duration.seconds(5))
                .showError();
            event.consume();
          }
        });
    Optional<String> result = changePwdDialog.showAndWait();
    if (result.isPresent()) {
      try {

        Connection con = Main.dbConnection;
        if (!con.isValid(0)) {
          con = Main.reconnect();
        }
        String deleteString = "update admin_login set password =? where username='******'";
        PreparedStatement deleteStmt = con.prepareStatement(deleteString);
        deleteStmt.setString(1, changePwdDialog.getEditor().getText());

        deleteStmt.executeUpdate();
        con.commit();

        Notifications.create()
            .title("Password updated")
            .text("Password was successfully updated. Please login again!")
            .hideAfter(Duration.seconds(5))
            .showInformation();
        logoutClicked(new ActionEvent());
      } catch (SQLException e) {

        Main._logger.debug("Error :", e);
        e.printStackTrace();
        Notifications.create()
            .hideAfter(Duration.seconds(5))
            .title("Delete failed")
            .text("Delete request of hawker bill has failed")
            .showError();
      } catch (IOException e) {

        Main._logger.debug("Error :", e);
        e.printStackTrace();
      } catch (Exception e) {

        Main._logger.debug("Error :", e);
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 18
0
  /** *************************File Creation************************** */
  @FXML
  private void CreateFile() throws SQLException {
    boolean isExist = false;

    if (Objects.equals(currProjectName, "") || selected == null) {
      warning("Can't create file under the main project");
    } else if (selected.getValue().isProject()) {
      TextInputDialog dialog = new TextInputDialog("");
      dialog.setTitle("Create File");
      dialog.setHeaderText("File");
      dialog.setContentText("Please enter the file name:");
      Optional<String> result = dialog.showAndWait();

      if (result.isPresent()) {
        final String inputFileName = result.get();

        String query =
            "SELECT pfname FROM PFiles WHERE pid like '" + currPID + "' AND pdid IS NULL";
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(query);

        while (rs.next()) {
          String tempName = rs.getString("pfname");
          if (Objects.equals(tempName, inputFileName)) {
            isExist = true;
            break;
          }
        }
        if (isExist == true) {
          warning("File name already exist.");
        } else {
          query =
              "INSERT INTO PFiles(pfname, pid,creatorID) VALUE('"
                  + inputFileName
                  + "','"
                  + currPID
                  + "','"
                  + MyuserID
                  + "')";
          st = conn.createStatement();
          st.executeUpdate(query);
          query = "SELECT LAST_INSERT_ID()";
          rs = st.executeQuery(query);
          if (rs.next()) {
            int currID = rs.getInt("LAST_INSERT_ID()");
            CheckBoxTreeItem<StrucTree> temptreeItem = new CheckBoxTreeItem<>();
            temptreeItem.setValue(new StrucTree("f", inputFileName, currID));
            selected.getChildren().add(temptreeItem);
            selected.setExpanded(true);
            iniFile(temptreeItem);
          }
        }
      }
    } else if (selected.getValue().isFile()) {

      TextInputDialog dialog = new TextInputDialog("");
      dialog.setTitle("Create File");
      dialog.setHeaderText("File");
      dialog.setContentText("Please enter the file name:");
      Optional<String> result = dialog.showAndWait();

      if (result.isPresent()) {
        final String inputFileName = result.get();
        String query = "";
        if (selected.getParent().getValue().isProject()) {
          query = "SELECT pfname FROM PFiles where pid like '" + currPID + "' AND pdid IS NULL";
        } else {
          query =
              "SELECT pfname FROM PFiles where pid like '"
                  + currPID
                  + "' AND pdid LIKE '"
                  + selected.getParent().getValue().getID()
                  + "'";
        }
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(query);

        while (rs.next()) {
          String tempName = rs.getString("pfname");
          if (Objects.equals(tempName, inputFileName)) {
            isExist = true;
            break;
          }
        }
        if (isExist == true) {
          warning("File name already exist.");

        } else {
          if (selected.getParent().getValue().isProject()) {
            query =
                "INSERT INTO PFiles(pfname, pid,creatorID) VALUE('"
                    + inputFileName
                    + "','"
                    + currPID
                    + "','"
                    + MyuserID
                    + "')";
          } else {
            query =
                "INSERT INTO PFiles(pfname, pid, pdid,creatorID) VALUE('"
                    + inputFileName
                    + "','"
                    + currPID
                    + "','"
                    + selected.getParent().getValue().getID()
                    + "','"
                    + MyuserID
                    + "')";
          }
          st = conn.createStatement();
          st.executeUpdate(query);
          query = "SELECT LAST_INSERT_ID()";
          rs = st.executeQuery(query);
          if (rs.next()) {
            int currID = rs.getInt("LAST_INSERT_ID()");
            CheckBoxTreeItem<StrucTree> temptreeItem = new CheckBoxTreeItem<>();
            if (selected.getParent().getValue().isProject()) {
              temptreeItem.setValue(new StrucTree("f", inputFileName, currID));
            } else {
              temptreeItem.setValue(
                  new StrucTree(
                      "f", inputFileName, currID, selected.getParent().getValue().getID()));
            }
            selected.getParent().getChildren().add(temptreeItem);
            selected.getParent().setExpanded(true);
            iniFile(temptreeItem);
          }
        }
      }
    } else if (selected.getValue().isDirectory()) {
      TextInputDialog dialog = new TextInputDialog("");
      dialog.setTitle("Create File");
      dialog.setHeaderText("File");
      dialog.setContentText("Please enter the file name:");
      Optional<String> result = dialog.showAndWait();

      if (result.isPresent()) {
        final String inputFileName = result.get();
        String query =
            "SELECT pfname FROM PFiles where pid like '"
                + currPID
                + "' AND pdid LIKE '"
                + selected.getValue().getID()
                + "'";

        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(query);

        while (rs.next()) {
          String tempName = rs.getString("pfname");
          if (Objects.equals(tempName, inputFileName)) {
            isExist = true;
            break;
          }
        }
        if (isExist == true) {
          warning("File name already exist.");
        } else {
          query =
              "INSERT INTO PFiles(pfname, pid, pdid,creatorID) VALUE('"
                  + inputFileName
                  + "','"
                  + currPID
                  + "','"
                  + selected.getValue().getID()
                  + "','"
                  + MyuserID
                  + "')";
          st = conn.createStatement();
          st.executeUpdate(query);
          query = "SELECT LAST_INSERT_ID()";
          rs = st.executeQuery(query);
          if (rs.next()) {
            int currID = rs.getInt("LAST_INSERT_ID()");
            CheckBoxTreeItem<StrucTree> temptreeItem = new CheckBoxTreeItem<>();
            temptreeItem.setValue(
                new StrucTree("f", inputFileName, currID, selected.getValue().getID()));
            selected.getChildren().add(temptreeItem);
            selected.setExpanded(true);
            iniFile(temptreeItem);
          }
        }
      }
    }
  }
Exemplo n.º 19
0
  /** *************************Project Creation************************** */
  @FXML
  public void CreateProject() throws SQLException, ClassNotFoundException {
    TextInputDialog dialog = new TextInputDialog("");
    dialog.setTitle("Create Project");
    dialog.setHeaderText("sQuire Project");
    dialog.setContentText("Please enter the project name:");
    Optional<String> result = dialog.showAndWait();
    Statement st = conn.createStatement();
    boolean isExist = false;
    String currProjName = "";

    if (result.isPresent()) {
      currProjName = result.get();

      String query = "SELECT PID FROM ProjectAccess where userID like '" + MyuserID + "'";
      ResultSet rs = st.executeQuery(query);

      while (rs.next()) {

        int myPid = rs.getInt("PID");

        String query2 = "SELECT pname FROM Projects where PID like '" + myPid + "'";
        Statement st1 = conn.createStatement();
        ResultSet re1 = st1.executeQuery(query2);
        if (re1.next()) {
          String projName = re1.getString("pname");
          if (Objects.equals(projName, currProjName)) {
            isExist = true;
            warning("Project name already exist.");
            break;
          }
        }
      }

      if (isExist == false) {
        String pass = setPassword();
        if (!Objects.equals(pass, "")) {

          String sql =
              "INSERT INTO Projects(pname,passHash,projectOwnerID)VALUE('"
                  + currProjName
                  + "','"
                  + pass
                  + "','"
                  + MyuserID
                  + "')";
          st.executeUpdate(sql);
          sql = "SELECT LAST_INSERT_ID()";
          rs = st.executeQuery(sql);
          if (rs.next()) {
            int currID = rs.getInt("LAST_INSERT_ID()");
            sql =
                "INSERT INTO ProjectAccess(PID, userID)VALUE('" + currID + "','" + MyuserID + "')";
            st.executeUpdate(sql);
          }
        } else {
          warning("Create Project Failed");
        }
      }
    }
    IniTree();
  }
Exemplo n.º 20
0
  /** *************************Rename Function************************** */
  @FXML
  public void Rename() throws SQLException {
    boolean isExist = false;

    if (selected == null) {
      warning("No project or file selected.");
    } else if (selected.getValue().isProject()) {
      TextInputDialog dialog = new TextInputDialog("");
      dialog.setTitle("Rename");
      dialog.setHeaderText("Rename Project");
      dialog.setContentText("Please enter the project name:");
      Optional<String> result = dialog.showAndWait();
      Statement st = conn.createStatement();
      String currProjName = "";

      if (result.isPresent()) {
        currProjName = result.get();
        String query = "SELECT PID FROM ProjectAccess where userID like '" + MyuserID + "'";
        ResultSet rs = st.executeQuery(query);
        while (rs.next()) {

          int myPid = rs.getInt("PID");

          String query2 = "SELECT pname FROM Projects where PID like '" + myPid + "'";
          Statement st1 = conn.createStatement();
          ResultSet re1 = st1.executeQuery(query2);
          if (re1.next()) {
            String projName = re1.getString("pname");
            if (Objects.equals(projName, currProjName)) {
              isExist = true;
              warning("Project name already exist.");
              break;
            }
          }
        }

        if (isExist == false) {
          String sql =
              "UPDATE Projects SET pname='"
                  + currProjName
                  + "' WHERE PID='"
                  + selected.getValue().getID()
                  + "'";
          st.executeUpdate(sql);
          selected.getValue().setName(currProjName);
          structure_tree.refresh();
        }
      }

    } else if (selected.getValue().isDirectory()) {
      TextInputDialog dialog = new TextInputDialog("");
      dialog.setTitle("Rename");
      dialog.setHeaderText("Rename Folder");
      dialog.setContentText("Please enter the folder name:");
      Optional<String> result = dialog.showAndWait();

      if (result.isPresent()) {
        final String inputFolderName = result.get();
        String query = "";
        if (selected.getParent().getValue().isProject()) {
          query = "SELECT pdname FROM PDirs where pid like '" + currPID + "' AND parentid IS NULL";
        } else {
          query =
              "SELECT pdname FROM PDirs where pid like '"
                  + currPID
                  + "' AND parentid like '"
                  + selected.getParent().getValue().getID()
                  + "'";
        }
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(query);

        while (rs.next()) {
          String tempName = rs.getString("pdname");
          if (Objects.equals(tempName, inputFolderName)) {
            isExist = true;
            break;
          }
        }

        if (isExist == true) {
          warning("Directory name already exist.");
        } else {
          query =
              "UPDATE PDirs SET pdname='"
                  + inputFolderName
                  + "' WHERE pdid='"
                  + selected.getValue().getID()
                  + "'";

          st = conn.createStatement();
          st.executeUpdate(query);
          selected.getValue().setName(inputFolderName);
          structure_tree.refresh();
        }
      }

    } else if (selected.getValue().isFile) {
      TextInputDialog dialog = new TextInputDialog("");
      dialog.setTitle("Rename");
      dialog.setHeaderText("Rename File");
      dialog.setContentText("Please enter the file name:");
      Optional<String> result = dialog.showAndWait();

      if (result.isPresent()) {
        final String inputFileName = result.get();
        String query = "";
        if (selected.getParent().getValue().isProject()) {
          query = "SELECT pfname FROM PFiles where pid like '" + currPID + "' AND pdid IS NULL";
        } else {
          query =
              "SELECT pfname FROM PFiles where pid like '"
                  + currPID
                  + "' AND pdid LIKE '"
                  + selected.getParent().getValue().getID()
                  + "'";
        }

        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(query);

        while (rs.next()) {
          String tempName = rs.getString("pfname");
          if (Objects.equals(tempName, inputFileName)) {
            isExist = true;
            break;
          }
        }
        if (isExist == true) {
          warning("File name already exist.");

        } else {
          query =
              "UPDATE PFiles SET pfname='"
                  + inputFileName
                  + "' WHERE pfid='"
                  + selected.getValue().getID()
                  + "'";

          st = conn.createStatement();
          st.executeUpdate(query);
          selected.getValue().setName(inputFileName);
          structure_tree.refresh();
        }
      }
    }
  }
  /**
   * Draws the MapMaker screen and displays it to the user
   *
   * @param primaryStage the stage to show it in
   * @throws Exception
   */
  public void drawScreen(Stage primaryStage) throws Exception {
    // Create the base BorderPane for the whole window
    BorderPane borderPane = new BorderPane();
    borderPane.setStyle("-fx-background-color: papayawhip");

    // Add some instructions to the user
    String text =
        "Instructions:\n"
            + "1. Click on the map component that you would like to place in the map\n"
            + "2. Click on the place in the map where you want to place the component\n"
            + "3. Repeat until you built the map you want!\n"
            + "4. Hit the 'Save' button when you are done";
    Label instructions = new Label(text);
    instructions.setFont(Font.font("Arial", FontWeight.BOLD, 12));
    instructions.setPadding(new Insets(5, 5, 5, 5));
    borderPane.setTop(instructions);

    // Create the blank Map
    Pane mapPane = new Pane();
    Map map = new Map(width, height);
    MapGridGUIDecorator mapGridGUIDecorator = new MapGridGUIDecorator(map.getGrid());
    ResizeFactor rf = ResizeFactor.getSuggestedResizeFactor(width, height);
    mapGridGUIDecorator.setResizeFactor(rf);
    GridPane mapGridPane = mapGridGUIDecorator.drawComponents();
    mapGridPane.setPadding(new Insets(0, 0, 5, 5));
    mapPane.getChildren().add(mapGridPane);
    borderPane.setCenter(mapPane);
    MapMakerController.setCurrentFocused(ComponentType.NOTHING);

    VBox sideComponents = new VBox();

    /* Add "Components" label */
    Label componentsLabel = new Label("Components");
    componentsLabel.setFont(Font.font("Arial", FontWeight.EXTRA_BOLD, 14));
    componentsLabel.setPadding(new Insets(15, 5, 0, 20));
    sideComponents.getChildren().add(componentsLabel);

    /* Add Intersection square image */
    VBox intersectionPane = new VBox();
    Label intersectionLabel = new Label("Intersection");
    intersectionLabel.setPadding(new Insets(5, 5, 0, 30));
    intersectionLabel.setFont(Font.font("Arial", FontWeight.SEMI_BOLD, 12));
    Image intersectionImg = new Image("IntersectionX.png", 60, 60, true, false);
    intersectionImgView = new ImageView(intersectionImg);
    StackPane intersectionStackPane = new StackPane(intersectionImgView);
    intersectionStackPane.setPadding(new Insets(0, 10, 10, 10));
    intersectionPane.getChildren().add(intersectionLabel);
    intersectionPane.getChildren().add(intersectionStackPane);
    sideComponents.getChildren().add(intersectionPane);

    /* Add RoadNS square image */
    VBox roadNSPane = new VBox();
    Label roadNSLabel = new Label("Road (North-South)");
    roadNSLabel.setPadding(new Insets(5, 5, 0, 15));
    roadNSLabel.setFont(Font.font("Arial", FontWeight.SEMI_BOLD, 12));
    Image roadNSImg = new Image("RoadBackgroundNS.png", 60, 60, true, false);
    roadNSImgView = new ImageView(roadNSImg);
    StackPane roadNSStackPane = new StackPane(roadNSImgView);
    roadNSStackPane.setPadding(new Insets(0, 10, 10, 10));
    roadNSPane.getChildren().add(roadNSLabel);
    roadNSPane.getChildren().add(roadNSStackPane);
    sideComponents.getChildren().add(roadNSPane);

    /* Add RoadEW square image */
    VBox roadEWPane = new VBox();
    Label roadEWLabel = new Label("Road (East-West)");
    roadEWLabel.setPadding(new Insets(5, 5, 0, 15));
    roadEWLabel.setFont(Font.font("Arial", FontWeight.SEMI_BOLD, 12));
    Image roadEWImg = new Image("RoadBackgroundEW.png", 60, 60, true, false);
    roadEWImgView = new ImageView(roadEWImg);
    StackPane roadEWStackPane = new StackPane(roadEWImgView);
    roadEWStackPane.setPadding(new Insets(0, 10, 10, 10));
    roadEWPane.getChildren().add(roadEWLabel);
    roadEWPane.getChildren().add(roadEWStackPane);
    sideComponents.getChildren().add(roadEWPane);

    /* Add Grass square image to empty out cells */
    VBox grassPane = new VBox();
    Label grassLabel = new Label("Grass (clear square)");
    grassLabel.setPadding(new Insets(5, 5, 0, 15));
    grassLabel.setFont(Font.font("Arial", FontWeight.SEMI_BOLD, 12));
    Image grassImg = new Image("Grass.png", 60, 60, true, false);
    grassImgView = new ImageView(grassImg);
    StackPane grassStackPane = new StackPane(grassImgView);
    grassStackPane.setPadding(new Insets(0, 10, 10, 10));
    grassPane.getChildren().add(grassLabel);
    grassPane.getChildren().add(grassStackPane);
    sideComponents.getChildren().add(grassPane);

    /* Add Save, Reset buttons */
    VBox buttonsPane = new VBox();
    buttonsPane.setPadding(new Insets(0, 0, 0, 10));
    Label toolsLabel = new Label("Tools");
    toolsLabel.setFont(Font.font("Arial", FontWeight.EXTRA_BOLD, 14));
    toolsLabel.setPadding(new Insets(15, 5, 5, 35));
    buttonsPane.getChildren().add(toolsLabel);
    Insets padding = new Insets(0, 0, 5, 0);
    Button saveButton = new Button("Save Map");
    StackPane saveButtonPane = new StackPane(saveButton);
    saveButtonPane.setPadding(padding);
    saveButton.setStyle("-fx-base:Gold");
    saveButton.setFont(Font.font("System Bold Italic", FontWeight.BOLD, 13));
    buttonsPane.getChildren().add(saveButtonPane);
    Button resetButton = new Button("Reset Map");
    resetButton.setStyle("-fx-base:Gold");
    resetButton.setFont(Font.font("System Bold Italic", FontWeight.BOLD, 13));
    StackPane resetButtonPane = new StackPane(resetButton);
    resetButtonPane.setPadding(padding);
    buttonsPane.getChildren().add(resetButtonPane);
    Button backButton = new Button("Go Back");
    backButton.setStyle("-fx-base:Gold");
    backButton.setFont(Font.font("System Bold Italic", FontWeight.BOLD, 13));
    StackPane backButtonPane = new StackPane(backButton);
    backButtonPane.setPadding(padding);
    buttonsPane.getChildren().add(backButtonPane);

    sideComponents.getChildren().add(buttonsPane);

    Ticker.start();

    /* Add click processing for Map grid squares */
    for (int i = 0; i < height; i++) {
      for (int j = 0; j < width; j++) {
        Node current = getNodeFromIndex(i, j, mapGridPane);
        final int x = j;
        final int y = i;
        current.setOnMouseClicked(
            (MouseEvent click) -> {
              MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused());
              MapMakerController.setCurrentFocused(ComponentType.MAP_SQUARE);
              current.requestFocus();
            });
        current
            .focusedProperty()
            .addListener(
                (ObservableValue<? extends Boolean> observable,
                    Boolean oldValue,
                    Boolean newValue) -> {
                  ComponentType previous = MapMakerController.getPreviousFocused();
                  if (previous == ComponentType.INTERSECTION) {
                    addIntersection(
                        x, y, map, mapGridGUIDecorator, mapGridPane, intersectionImgView);
                  } else if (previous == ComponentType.ROADNS) {
                    addRoadNS(x, y, map, mapGridGUIDecorator, mapGridPane, roadNSImgView);
                  } else if (previous == ComponentType.ROADEW) {
                    addRoadEW(x, y, map, mapGridGUIDecorator, mapGridPane, roadEWImgView);
                  } else if (previous == ComponentType.GRASS) {
                    addGrass(x, y, map, mapGridGUIDecorator, mapGridPane, grassImgView);
                  }
                });
      }
    }

    /* Add intersection icon click processing */
    DropShadow ds = new DropShadow(15, Color.BLUE);
    intersectionImgView.setOnMouseClicked(
        click -> {
          MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused());
          MapMakerController.setCurrentFocused(ComponentType.INTERSECTION);
          intersectionImgView.requestFocus();
        });
    intersectionImgView
        .focusedProperty()
        .addListener(
            (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
              if (newValue) intersectionImgView.setEffect(ds);
              else intersectionImgView.setEffect(null);
            });

    /* Add roadNS icon click processing */
    roadNSImgView.setOnMouseClicked(
        click -> {
          MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused());
          MapMakerController.setCurrentFocused(ComponentType.ROADNS);
          roadNSImgView.requestFocus();
        });
    roadNSImgView
        .focusedProperty()
        .addListener(
            (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
              if (newValue) roadNSImgView.setEffect(ds);
              else roadNSImgView.setEffect(null);
            });

    /* Add roadEW icon click processing */
    roadEWImgView.setOnMouseClicked(
        click -> {
          MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused());
          MapMakerController.setCurrentFocused(ComponentType.ROADEW);
          roadEWImgView.requestFocus();
        });
    roadEWImgView
        .focusedProperty()
        .addListener(
            (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
              if (newValue) roadEWImgView.setEffect(ds);
              else roadEWImgView.setEffect(null);
            });

    /* Add grass icon click processing */
    grassImgView.setOnMouseClicked(
        click -> {
          MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused());
          MapMakerController.setCurrentFocused(ComponentType.GRASS);
          grassImgView.requestFocus();
        });
    grassImgView
        .focusedProperty()
        .addListener(
            (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
              if (newValue) grassImgView.setEffect(ds);
              else grassImgView.setEffect(null);
            });

    /* Add save button functionality */
    saveButton.setOnMouseClicked(
        click -> {
          TextInputDialog nameDialog = new TextInputDialog();
          nameDialog.setTitle("Save Map");
          nameDialog.setHeaderText(
              "Please provide a name for your map (no spaces or special characters).\nSaved maps go into the /maps directory of your working directory.");
          nameDialog.setContentText("File name");
          Button btOk = (Button) nameDialog.getDialogPane().lookupButton(ButtonType.OK);
          TextField textfield = nameDialog.getEditor();
          Platform.runLater(() -> textfield.requestFocus());
          btOk.setDisable(true);
          textfield
              .textProperty()
              .addListener(
                  ((observable, oldValue, newValue) -> {
                    btOk.setDisable(newValue.trim().isEmpty());
                  }));

          Optional<String> result = nameDialog.showAndWait();
          result.ifPresent(
              name -> {
                name = name.concat(".map");
                try {
                  Map finalMap = buildAndSaveMap(map);
                  finalMap.saveMap(name);
                  goBack(primaryStage);
                } catch (Exception e) {
                  e.printStackTrace();
                }
              });
        });

    resetButton.setOnMouseClicked(
        click -> {
          for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
              Component component = map.getAtLocation(new Coordinate(x, y));
              if (component instanceof Road || component instanceof Intersection) {
                addGrass(x, y, map, mapGridGUIDecorator, mapGridPane, grassImgView);
              }
            }
          }
        });

    backButton.setOnMouseClicked(
        click -> {
          try {
            goBack(primaryStage);
          } catch (Exception e) {
            e.printStackTrace();
          }
        });

    borderPane.setRight(sideComponents);
    Scene scene = new Scene(borderPane);
    primaryStage.setScene(scene);
    primaryStage.centerOnScreen();
    primaryStage.setResizable(false);
  }