You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.4 KiB

package model;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.image.Image;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
/**
* Created by Gondr on 1/06/2017.
*/
public class User {
protected int studentNumber;
protected String email;
protected String password;
protected String address;
protected String homephone;
protected String mobilephone;
protected AccountType accountType;
transient protected Image photo;
private byte[] image;
protected String ID;
public enum AccountType{
PASSENGER("Passenger"), DRIVER("Driver");
public String name;
AccountType(String name){
this.name = name;
}
public static AccountType getValueOf(String s){
switch(s){
case "Passenger":
return PASSENGER;
case "Driver":
return DRIVER;
default:
return null;
}
}
}
public User(int studentNumber, String email, String password, String address, String homephone, String mobilephone,
Image photo){
this.studentNumber = studentNumber;
this.ID = String.valueOf(studentNumber);
this.email = email;
this.password = password;
this.address = address;
this.homephone = homephone;
this.mobilephone = mobilephone;
this.photo = photo;
this.accountType = AccountType.PASSENGER;
}
public boolean checkPassword(String p){
return p.equals(password);
}
public int getStudentNumber() {
return studentNumber;
}
public String getID(){
return ID;
}
public void serialise(){
try {
BufferedImage bi = SwingFXUtils.fromFXImage(photo, null);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(bi, "png", out);
out.flush();
image = out.toByteArray();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void deserialise(){
ByteArrayInputStream in = new ByteArrayInputStream(image);
BufferedImage bi = null;
try {
bi = ImageIO.read(in);
} catch (IOException e) {
e.printStackTrace();
}
photo = SwingFXUtils.toFXImage(bi, null);
}
}