Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PasswordUIController implements Initializable {
- private PasswordList passList;
- /**
- * Initializes the controller class.
- */
- @FXML
- TreeTableView passwordInfo;
- @FXML
- TreeTableColumn<String,String> acctColumn;
- @FXML
- Parent root;
- @FXML
- private void backButtonAction(ActionEvent event) throws Exception {
- Stage stage = (Stage) root.getScene().getWindow();
- FXMLLoader loader = new FXMLLoader(getClass().getResource("MainMenuUI.fxml"));
- Pane mainMenuUI = (Pane)loader.load();
- MainMenuController controller = loader.<MainMenuController>getController();
- controller.setPassList(passList);
- Scene scene = new Scene(mainMenuUI);
- stage.setTitle("Main Menu");
- stage.setScene(scene);
- stage.show();
- }
- @FXML
- private void addButtonAction(ActionEvent event) throws Exception {
- Stage stage = (Stage) root.getScene().getWindow();
- FXMLLoader loader = new FXMLLoader(getClass().getResource("CreatePasswordUI.fxml"));
- Pane createPassUI = (Pane)loader.load();
- CreatePasswordUIController controller = loader.<CreatePasswordUIController>getController();
- controller.setPassList(passList);
- Scene scene = new Scene(createPassUI);
- stage.setTitle("Create Password");
- stage.setScene(scene);
- stage.show();
- }
- @Override
- public void initialize(URL url, ResourceBundle rb) {
- PasswordList pList = passList;
- if (pList != null) {
- ArrayList<Password> thePasswords = pList.getPasswordList();
- TreeItem<String> passwords = new TreeItem<>("Passwords");
- for (int i = 0; i < thePasswords.size(); i++) {
- Password thePass = thePasswords.get(i);
- //Creating tree items
- TreeItem<String> username = new TreeItem<>("Username: " + thePass.getUsername());
- TreeItem<String> password = new TreeItem<>("Password: " + thePass.getPassword());
- TreeItem<String> comment = new TreeItem<>("Comment: " + thePass.getComment());
- //Creating the root element
- TreeItem<String> account = new TreeItem<>(thePass.getAccount());
- account.setExpanded(true);
- //Adding tree items to the root
- account.getChildren().setAll(username, password, comment);
- passwords.getChildren().add(account);
- }
- //Creating a column
- acctColumn = new TreeTableColumn<>("Account");
- //Defining cell content
- acctColumn.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<String, String>, ObservableValue<String>>() {
- @Override
- public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<String, String> param){
- return new SimpleStringProperty(param.getValue().getValue());
- }
- });
- //Creating a tree table view
- passwordInfo = new TreeTableView<>();
- passwordInfo.setRoot(passwords);
- passwordInfo.getColumns().add(acctColumn);
- } else {
- }
- }
- /**
- * @return the passList
- */
- public PasswordList getPassList() {
- return passList;
- }
- /**
- * @param passList the passList to set
- */
- public void setPassList(PasswordList passList) {
- this.passList = passList;
- }
- }
- public class CreatePasswordUIController implements Initializable {
- private PasswordList passList;
- /**
- * Initializes the controller class.
- */
- @FXML
- Parent root;
- @FXML
- TextField accountTxt;
- @FXML
- TextField usernameTxt;
- @FXML
- TextField passwordTxt;
- @FXML
- TextField passwordTxt2;
- @FXML
- TextArea commentArea;
- @FXML
- TextField passwordGeneratorTxt;
- @FXML
- Label rating;
- @FXML
- Label matching;
- @FXML
- Label incorrect;
- @FXML
- private void backButtonAction(ActionEvent event) throws Exception {
- Stage stage = (Stage) root.getScene().getWindow();
- FXMLLoader loader = new FXMLLoader(getClass().getResource("MainMenuUI.fxml"));
- Pane mainMenuUI = (Pane)loader.load();
- MainMenuController controller = loader.<MainMenuController>getController();
- controller.setPassList(passList);
- Scene scene = new Scene(mainMenuUI);
- stage.setTitle("Main Menu");
- stage.setScene(scene);
- stage.show();
- }
- @FXML
- private void submitButtonAction(ActionEvent event) throws Exception {
- String account = accountTxt.getText();
- String username = usernameTxt.getText();
- String password = passwordTxt.getText();
- String password2 = passwordTxt2.getText();
- String comment = commentArea.getText();
- if (password.equals(password2) && username.length()>2) {
- PasswordList pList = passList;
- Password thePass = new Password(account, username, password, comment);
- pList.addPassword(thePass);
- Stage stage = (Stage) root.getScene().getWindow();
- FXMLLoader loader = new FXMLLoader(getClass().getResource("PasswordUI.fxml"));
- Pane passwordUI = (Pane)loader.load();
- PasswordUIController controller = loader.<PasswordUIController>getController();
- controller.setPassList(pList);
- Scene scene = new Scene(passwordUI);
- stage.setTitle("Password");
- stage.setScene(scene);
- stage.show();
- } else {
- incorrect.setVisible(true);
- }
- }
- @FXML
- private void generateButtonAction(ActionEvent event) {
- PasswordGenerator passGen = new PasswordGenerator();
- String password = passGen.generatePassword(true);
- passwordGeneratorTxt.setText(password);
- }
- @Override
- public void initialize(URL url, ResourceBundle rb) {
- PasswordRater rater = new PasswordRater();
- passwordTxt.textProperty().addListener(new ChangeListener() {
- @Override
- public void changed(ObservableValue observable, Object oldVal,Object newVal) {
- String password = passwordTxt.getText();
- rater.setPassword(password);
- String ratingStr = rater.displayLevel();
- rating.setText(ratingStr);
- rating.setVisible(true);
- if (passwordTxt.getText().equals(passwordTxt2.getText()) && !password.equals("")) {
- matching.setText("Good!");
- }
- else
- {
- matching.setText("Passwords do not match.");
- }
- }
- });
- passwordTxt2.textProperty().addListener(new ChangeListener() {
- @Override
- public void changed(ObservableValue observable, Object oldVal,Object newVal) {
- String password = passwordTxt.getText();
- String password2 = passwordTxt2.getText();
- if (password.equals(password2) && !password.equals("")) {
- matching.setText("Good!");
- } else {
- matching.setText("Passwords do not match.");
- }
- matching.setVisible(true);
- }
- });
- }
- /**
- * @return the passList
- */
- public PasswordList getPassList() {
- return passList;
- }
- /**
- * @param passList the passList to set
- */
- public void setPassList(PasswordList passList) {
- this.passList = passList;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement