@Override public void initialize(URL url, ResourceBundle rb) { try { // Create a socket to connect to the server Socket socket = new Socket("localhost", 8000); FromServer = new DataInputStream(socket.getInputStream()); // Create an output stream to send data to the server ToServer = new DataOutputStream(socket.getOutputStream()); } catch (IOException ex) { lbout.setText(ex.toString() + '\n'); } while (loged) {} btlogout.setOnAction( e -> { try { ToServer.writeUTF("Logout"); Boolean logout = FromServer.readBoolean(); if (logout) { loged = false; isadmin = false; lbloginfo.setText("Loged Out"); tbuser.setDisable(!loged); tbadmin.setDisable(!isadmin); btlogout.setVisible(false); btlogin.setVisible(true); txaddpass.clear(); // btlogin.setText("Login"); tfname.setDisable(false); tfpass.setDisable(false); } else lbloginfo.setText("Logout Failed"); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }); btlogin.setOnAction( e -> { String name = tfname.getText(); String pass = tfpass.getText(); if (name.isEmpty() && pass.isEmpty()) lbloginfo.setText("Username and Password is empty"); else if (name.isEmpty()) lbloginfo.setText("Username is empty"); else if (pass.isEmpty()) lbloginfo.setText("Password is empty"); else { try { ToServer.writeUTF(tfname.getText()); ToServer.writeUTF(tfpass.getText()); loged = FromServer.readBoolean(); isadmin = FromServer.readBoolean(); if (loged) { lbloginfo.setText("Logged in"); lbloginfo.setText("Welcome Back " + name); // btlogin.setText("Logout"); tfname.setDisable(true); tfpass.setDisable(true); btlogin.setVisible(false); btlogout.setVisible(true); if (isadmin) { lbtypeuser.setText("Loged as Administrator"); } else lbtypeuser.setText("Loged as User"); // tbadmin.setDisable(!isadmin); tbuser.setDisable(!loged); tbadmin.setDisable(!isadmin); tb.getSelectionModel().select(tbuser); repo = FromServer.readUTF(); txgroup.setText(repo); // getuserinfo(repo); getFilesinfo(); getgroupe(); getusers(); gettars(); // cbbackups.getItems().addAll(tars); // cbgroup.getItems().addAll(groups); // cbselectuser.getItems().addAll(users); } else lbout.setText("Failed to log in"); } catch (IOException ex) { } } }); btbackup.setOnAction( e -> { try { tars.clear(); ToServer.writeUTF("Backup"); Boolean answer = FromServer.readBoolean(); if (answer) { lbadmininfo.setText("Backup finished"); gettars(); } else { lbadmininfo.setText("error accured during restore"); gettars(); } } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); try { gettars(); } catch (Exception e2) { // TODO Auto-generated catch block e2.printStackTrace(); } } }); btrestore.setOnAction( e -> { try { if (!cbbackups.selectionModelProperty().get().getSelectedItem().isEmpty()) { ToServer.writeUTF("Restore"); ToServer.writeUTF(cbbackups.selectionModelProperty().get().getSelectedItem()); Boolean answer = FromServer.readBoolean(); if (answer) lbadmininfo.setText("restore finished"); else lbadmininfo.setText("error accured during backup"); } else lbadmininfo.setText("please choose tar file"); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }); btcheckin.setOnAction( e -> { if (loged) { file = fileChooser.showOpenDialog(new Stage()); if (file != null) { try { ToServer.writeUTF("Checkin"); ToServer.writeUTF(file.getName()); ToServer.writeLong(file.lastModified()); sendFile(file); String choice = null; choice = FromServer.readUTF(); if (choice.equals("sync")) { getFilesinfo(); File newfile = GetFile(FromServer); writeFile(file, file.getPath() + "--old"); String path = file.getPath(); file.delete(); writeFile(newfile, path); lbout.setText("Performing Sync with the server"); } else if (choice.contains("locked")) { getFilesinfo(); lbout.setText(choice); } else if (choice.equals("not text")) { getFilesinfo(); lbout.setText("Check in only text files"); } else if (choice.equals("equal")) { getFilesinfo(); lbout.setText("The file is equal to the latest version"); } else { getFilesinfo(); lbout.setText("The file is uploaded successfully"); } // ToServer.writeUTF("Files"); // getFilesinfo(); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } }); btcheckout.setOnAction( e -> { try { ToServer.writeUTF("Checkout"); ToServer.writeUTF(tbl.selectionModelProperty().get().getSelectedItem().getName()); System.out.println(tbl.selectionModelProperty().get().getSelectedItem().getName()); ToServer.writeUTF(cbversion.selectionModelProperty().get().getSelectedItem()); System.out.println(cbversion.selectionModelProperty().get().getSelectedItem()); Boolean answer = FromServer.readBoolean(); if (answer) { String filename = FromServer.readUTF(); Long timestamp = FromServer.readLong(); File ver = GetFile(FromServer); String pa = System.getProperty("user.home") + "/" + filename; writeFile(ver, System.getProperty("user.home") + "/" + filename); File tim = new File(System.getProperty("user.home") + "/" + filename); tim.setLastModified(timestamp); lbout.setText("The file is saved on your home directory"); } else lbout.setText("Checkout failed"); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }); tbl.getSelectionModel() .selectedItemProperty() .addListener( (obs, oldSelection, newSelection) -> { if (newSelection != null) { versions.clear(); Float lastvers = Float.valueOf(tbl.getSelectionModel().selectedItemProperty().get().getLastv()); for (float i = 1f; i <= lastvers + 0.001; i += 0.001) { if (i == 1f) versions.add(Float.toString(i) + "00"); else versions.add(Float.toString(i).substring(0, 5)); } cbversion.getItems().addAll(versions); } }); cbgroup .getSelectionModel() .selectedItemProperty() .addListener( (obs, oldSelection, newSelection) -> { if (newSelection != null) { try { } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); btadduser.setOnAction( e -> { try { if (!txaddname.getText().isEmpty() && !txaddpass.getText().isEmpty() && !txgroup.getText().isEmpty()) { ToServer.writeUTF("Adduser"); ToServer.writeUTF(txaddname.getText()); ToServer.writeUTF(txaddpass.getText()); if (cboxadmin.isSelected()) ToServer.writeUTF("1"); else ToServer.writeUTF("0"); ToServer.writeUTF(txgroup.getText()); Boolean answer = FromServer.readBoolean(); try { if (answer) { lbadmininfo.setText("User Added"); users.clear(); getusers(); // users.add(txaddname.getText()); txaddname.setText(""); txaddpass.setText(""); cboxadmin.setSelected(false); } else { lbadmininfo.setText("User add failed"); getusers(); } } catch (Exception p) { getusers(); } } else { lbadmininfo.setText("All text must be field"); getusers(); } } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); try { getusers(); } catch (Exception e2) { // TODO Auto-generated catch block e2.printStackTrace(); } } }); btdeleteuser.setOnAction( e -> { try { if (!cbselectuser.selectionModelProperty().get().getSelectedItem().isEmpty()) { ToServer.writeUTF("Deleteuser"); ToServer.writeUTF(cbselectuser.selectionModelProperty().get().getSelectedItem()); cbselectuser.setValue(""); users.clear(); Boolean answer = FromServer.readBoolean(); if (answer) { lbadmininfo.setText("User deleted"); getusers(); // users.remove(cbselectuser.selectionModelProperty().get().getSelectedItem()); } else { lbadmininfo.setText("unable to delete user"); getusers(); } } else { lbadmininfo.setText("All text must be field"); getusers(); } } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); try { getusers(); } catch (Exception e2) { // TODO Auto-generated catch block e2.printStackTrace(); } } }); btaddgroup.setOnAction( e -> { try { if (!txgroupname.getText().isEmpty()) { ToServer.writeUTF("Addgroup"); ToServer.writeUTF(txgroupname.getText()); Boolean answer = FromServer.readBoolean(); if (answer) { lbadmininfo.setText("Group Added"); getgroupe(); } else { lbadmininfo.setText("Group add failed"); getgroupe(); } } else { lbadmininfo.setText("All text must be field"); getgroupe(); } } catch (Exception e1) { // TODO Auto-generated catch block try { getgroupe(); } catch (Exception e2) { // TODO Auto-generated catch block e2.printStackTrace(); } } }); }
/** Create and initialise the song panel. */ public BasicSongPanel() { final VBox centrePanel = new VBox(); transposeDialog = new TransposeDialog(); GridPane topPanel = new GridPane(); titleField = new TextField(); GridPane.setHgrow(titleField, Priority.ALWAYS); Label titleLabel = new Label(LabelGrabber.INSTANCE.getLabel("title.label")); GridPane.setConstraints(titleLabel, 1, 1); topPanel.getChildren().add(titleLabel); titleLabel.setLabelFor(titleField); GridPane.setConstraints(titleField, 2, 1); topPanel.getChildren().add(titleField); authorField = new TextField(); GridPane.setHgrow(authorField, Priority.ALWAYS); Label authorLabel = new Label(LabelGrabber.INSTANCE.getLabel("author.label")); GridPane.setConstraints(authorLabel, 1, 2); topPanel.getChildren().add(authorLabel); authorLabel.setLabelFor(authorField); GridPane.setConstraints(authorField, 2, 2); topPanel.getChildren().add(authorField); centrePanel.getChildren().add(topPanel); lyricsArea = new SpellTextArea(); lyricsArea.setMaxHeight(Double.MAX_VALUE); final VBox mainPanel = new VBox(); ToolBar lyricsToolbar = new ToolBar(); transposeButton = getTransposeButton(); nonBreakingLineButton = getNonBreakingLineButton(); lyricsToolbar.getItems().add(transposeButton); lyricsToolbar.getItems().add(nonBreakingLineButton); lyricsToolbar.getItems().add(new Separator()); Region spacer = new Region(); HBox.setHgrow(spacer, Priority.ALWAYS); lyricsToolbar.getItems().add(spacer); dictSelector = new ComboBox<>(); Tooltip.install( dictSelector, new Tooltip(LabelGrabber.INSTANCE.getLabel("dictionary.language.text"))); for (Dictionary dict : DictionaryManager.INSTANCE.getDictionaries()) { dictSelector.getItems().add(dict); } dictSelector .selectionModelProperty() .get() .selectedItemProperty() .addListener( new ChangeListener<Dictionary>() { @Override public void changed( ObservableValue<? extends Dictionary> ov, Dictionary t, Dictionary t1) { lyricsArea.setDictionary(dictSelector.getValue()); } }); dictSelector.getSelectionModel().select(QueleaProperties.get().getDictionary()); lyricsToolbar.getItems().add(dictSelector); lyricsToolbar.getItems().add(getDictButton()); VBox.setVgrow(mainPanel, Priority.ALWAYS); mainPanel.getChildren().add(lyricsToolbar); VBox.setVgrow(lyricsArea, Priority.ALWAYS); mainPanel.getChildren().add(lyricsArea); centrePanel.getChildren().add(mainPanel); setCenter(centrePanel); }