Skip to content
Snippets Groups Projects
Commit e488cca6 authored by vincent.steinman's avatar vincent.steinman
Browse files

check text fields

parent ebee825d
No related branches found
No related tags found
No related merge requests found
......@@ -126,8 +126,8 @@ public class Contact implements Comparable<Contact>{
w_social += elem + " ";
}
return String.valueOf(id) + " - " + w_names + " - " + this.last_name + " - " + this.addr + " - " + w_phone + " - " + w_email + " - "
+ w_social + " - " + this.job;
return String.valueOf(id) + " - " + w_names + "- " + this.last_name + " - " + this.addr + " - " + w_phone
+ "- " + w_email + "- " + w_social + "- " + this.job;
}
@Override
public int compareTo(Contact c){
......
......@@ -36,7 +36,7 @@ public class Family extends Contact{
w_social += elem + " ";
}
return String.valueOf(id) + " - " + w_names + " - " + this.last_name + " - " + this.addr + " - " + w_phone + " - " + w_email + " - "
+ w_social + " - " + this.job + " - " + this.relation;
return String.valueOf(id) + " - " + w_names + "- " + this.last_name + " - " + this.addr + " - " + w_phone
+ "- " + w_email + "- " + w_social + "- " + this.job + " - " + this.relation;
}
}
......@@ -8,10 +8,13 @@ import javafx.scene.control.*;
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class HelloController {
static ArrayList<Contact> contactArray = new ArrayList<Contact>();
int selectedID = 0;
boolean imported = false;
ObservableList<String> ctType = FXCollections.observableArrayList("Friend", "Family", "Professional");
@FXML
private TextField txtFirst;
......@@ -59,6 +62,7 @@ public class HelloController {
txtOther.setVisible(false);
btnEdit.setDisable(true);
btnDelete.setDisable(true);
btnAdd.setDisable(true);
}
@FXML
protected void AddCt() {
......@@ -131,16 +135,16 @@ public class HelloController {
for (Contact c: contactArray){
List<String> str_array = SplitLine(c.toString(), " - ");
writer.write(c.get_type() + "\n");
writer.write(String.valueOf(c.getId()) + "/");
writer.write(str_array.get(0) + "/");
writer.write(str_array.get(1) + "/");
writer.write(str_array.get(2) + "/");
writer.write(str_array.get(3) + "/");
writer.write(str_array.get(4) + "/");
writer.write(str_array.get(5) + "/");
writer.write(str_array.get(6));
writer.write(str_array.get(6) + "/");
writer.write(str_array.get(7));
if(c.get_type().equals("Family") || c.get_type().equals("Professional")){
writer.write("/" + str_array.get(7) + "\n");
writer.write("/" + str_array.get(8) + "\n");
} else{
writer.write("/" + "\n");
}
......@@ -152,10 +156,12 @@ public class HelloController {
}
@FXML
protected void Search() {
Pattern pat = Pattern.compile(txtSearch.getText());
LstCt.getItems().clear();
for(Contact c: contactArray){
for(String n: c.getFirst_name()){
if(n.equals(txtSearch.getText())){
Matcher match = pat.matcher(n);
if(match.find()){
LstCt.getItems().add(c);
}
}
......@@ -199,6 +205,9 @@ public class HelloController {
lblOther.setVisible(false);
cbxType.setValue("Friend");
}
cbxType.setDisable(true);
imported = true;
TestFields();
}
@FXML
protected void Delete() {
......@@ -231,6 +240,24 @@ public class HelloController {
ShowAll();
}
@FXML
public void TestFields(){
Pattern pat = Pattern.compile(txtEmail.getText());
Matcher match = pat.matcher("^(.+)@(.+)$*");
if(txtFirst.getText() != "" && txtLast.getText() != "" && match.find()){
if(imported){
btnEdit.setDisable(false);
btnAdd.setDisable(false);
} else{
btnEdit.setDisable(true);
btnAdd.setDisable(false);
}
} else {
btnEdit.setDisable(true);
btnAdd.setDisable(true);
}
}
@FXML
protected void ShowAll() {
int cpt = 0;
for(Contact cont: contactArray){
......@@ -241,6 +268,16 @@ public class HelloController {
for(Contact c: contactArray){
LstCt.getItems().add(c.toString());
}
txtFirst.setText("");
txtLast.setText("");
txtAdd.setText("");
txtPhone.setText("");
txtEmail.setText("");
txtSocial.setText("");
txtJob.setText("");
txtOther.setText("");
cbxType.setDisable(false);
imported = false;
}
public void AddPal(){
String firstName = txtFirst.getText();
......@@ -299,14 +336,6 @@ public class HelloController {
contactArray.add(c);
Collections.sort(contactArray);
ShowAll();
txtFirst.setText("");
txtLast.setText("");
txtAdd.setText("");
txtPhone.setText("");
txtEmail.setText("");
txtSocial.setText("");
txtJob.setText("");
txtOther.setText("");
}
public void ImportFriend(List<String> str_array){
Friend f = new Friend(
......@@ -370,26 +399,24 @@ public class HelloController {
return data;
}
public List<String> SplitArray(String str){
//str = str.substring(1, str.length() - 1);
String new_str = "";
for(char c: str.toCharArray()){
if(c !='[' && c !=']'){
new_str += c;
}
}
List<String> names = Arrays.asList(new_str.split(","));
List<String> names = Arrays.asList(new_str.split(" "));
return names;
}
//TODO
/*
Better toString in export
List first names & co
Add comments
Test contact exist
Control sur les champs
Virgules dans champs text
Unit Test
Edit relation/job?
*/
}
\ No newline at end of file
......@@ -34,7 +34,7 @@ public class Professional extends Contact{
w_social += elem + " ";
}
return String.valueOf(id) + " - " + w_names + " - " + last_name + " - " + this.addr + " - " + w_phone + " - " + w_email + " - "
+ w_social + " - " + this.job + " - " + this.work_place;
return String.valueOf(id) + " - " + w_names + "- " + last_name + " - " + this.addr + " - " + w_phone + "- "
+ w_email + "- " + w_social + "- " + this.job + " - " + this.work_place;
}
}
......@@ -46,15 +46,15 @@
<children>
<ListView fx:id="LstCt" layoutX="427.0" layoutY="38.0" onMouseClicked="#Selected" prefHeight="489.0" prefWidth="412.0" />
<Button fx:id="btnAdd" layoutX="229.0" layoutY="51.0" mnemonicParsing="false" onAction="#AddCt" prefHeight="24.0" prefWidth="62.0" text="Add" />
<TextField fx:id="txtFirst" layoutX="32.0" layoutY="52.0" />
<TextField fx:id="txtFirst" layoutX="32.0" layoutY="52.0" onInputMethodTextChanged="#TestFields" onKeyReleased="#TestFields" />
<Label layoutX="230.0" layoutY="300.0" text="First Name" />
<TextField fx:id="txtLast" layoutX="32.0" layoutY="107.0" />
<TextField fx:id="txtLast" layoutX="32.0" layoutY="107.0" onInputMethodTextChanged="#TestFields" onKeyReleased="#TestFields" />
<Label layoutX="32.0" layoutY="85.0" text="Last Name" />
<TextField fx:id="txtAdd" layoutX="32.0" layoutY="162.0" />
<Label layoutX="32.0" layoutY="140.0" text="Address" />
<TextField fx:id="txtPhone" layoutX="32.0" layoutY="216.0" />
<Label layoutX="32.0" layoutY="194.0" text="Phones" />
<TextField fx:id="txtEmail" layoutX="32.0" layoutY="270.0" />
<TextField fx:id="txtEmail" layoutX="32.0" layoutY="270.0" onInputMethodTextChanged="#TestFields" onKeyReleased="#TestFields" />
<Label layoutX="32.0" layoutY="248.0" text="Emails" />
<TextField fx:id="txtSocial" layoutX="32.0" layoutY="322.0" />
<Label layoutX="32.0" layoutY="300.0" text="Socials" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment