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