Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Alexandre Ducarne
ai12-othello
Commits
7ca04d65
Commit
7ca04d65
authored
Nov 27, 2019
by
Louis Bal Dit Sollier
Browse files
Merge branch 'feature/main/displayOwnUser' into 'int/v2'
display and modify own user See merge request
!34
parents
360616cf
8b92ffbc
Changes
3
Show whitespace changes
Inline
Side-by-side
src/main/java/client/main/controller/FXHome.java
View file @
7ca04d65
...
...
@@ -19,6 +19,9 @@ import javafx.scene.control.ListCell;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Date
;
public
class
FXHome
{
...
...
@@ -96,8 +99,10 @@ public class FXHome {
String
buttonSource
=
((
Button
)
e
.
getSource
()).
getId
();
switch
(
buttonSource
){
case
"homeButtonMyProfile"
:
FXProfileConsult
fxProfileConsult
=
new
FXProfileConsult
();
fxProfileConsult
.
initialize
(
"../fxml/viewProfile.fxml"
,
this
.
stage
);
BorderPane
layout
=
FXMLLoader
.
load
(
new
URL
(
FXHome
.
class
.
getResource
(
"../fxml/viewProfile.fxml"
).
toExternalForm
())
);
this
.
stage
.
setScene
(
new
Scene
(
layout
));
break
;
case
"homeButtonCreateGame"
:
BorderPane
layout
=
FXMLLoader
.
load
(
...
...
src/main/java/client/main/controller/FXModifyProfile.java
0 → 100644
View file @
7ca04d65
package
main.java.client.main.controller
;
import
javafx.fxml.FXML
;
import
javafx.fxml.FXMLLoader
;
import
javafx.fxml.Initializable
;
import
javafx.scene.Node
;
import
javafx.scene.Parent
;
import
javafx.scene.Scene
;
import
javafx.scene.control.Button
;
import
javafx.scene.control.DatePicker
;
import
javafx.scene.control.PasswordField
;
import
javafx.scene.control.TextField
;
import
javafx.scene.input.MouseEvent
;
import
javafx.scene.layout.BorderPane
;
import
javafx.scene.layout.Pane
;
import
javafx.scene.text.Text
;
import
javafx.stage.Stage
;
import
main.java.client.ClientApp
;
import
main.java.client.main.model.MainApplicationModel
;
import
main.java.common.dataModel.UserLight
;
import
java.awt.event.ActionEvent
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.time.LocalDate
;
import
java.time.ZoneId
;
import
java.util.Date
;
import
java.util.ResourceBundle
;
public
class
FXModifyProfile
implements
Initializable
{
private
MainApplicationModel
model
;
private
Stage
stage
;
@FXML
private
TextField
modifyProfileTextFieldName
;
@FXML
private
TextField
modifyProfileTextFieldFirstName
;
@FXML
private
PasswordField
modifyProfilePasswordFieldPassword
;
@FXML
private
DatePicker
modifyProfileTextFieldBirthDate
;
@FXML
private
TextField
modifyProfileTextFieldPseudo
;
public
FXModifyProfile
(){
this
.
model
=
ClientApp
.
mainCore
.
getFX
().
getModel
();
stage
=
new
Stage
();
}
public
void
setStage
(
Stage
stage
){
this
.
stage
=
stage
;
}
public
void
initialize
(
URL
fxmlResource
,
ResourceBundle
resource
)
{
UserLight
user
=
this
.
model
.
getUserLight
();
Date
date
=
user
.
getDateOfBirth
();
LocalDate
localdate
=
date
.
toInstant
().
atZone
(
ZoneId
.
systemDefault
()).
toLocalDate
();
modifyProfileTextFieldName
.
setText
(
user
.
getLastName
());
modifyProfileTextFieldFirstName
.
setText
(
user
.
getFirstName
());
modifyProfileTextFieldPseudo
.
setText
(
user
.
getPseudo
());
modifyProfileTextFieldBirthDate
.
setValue
(
localdate
);
}
@FXML
private
void
handleButtonClick
(
MouseEvent
e
)
throws
IOException
{
String
buttonSource
=
((
Button
)
e
.
getSource
()).
getId
();
switch
(
buttonSource
){
case
"modifyProfileButtonCancel"
:
setNewScene
(
"../fxml/viewProfile.fxml"
,
e
);
break
;
case
"modifyProfileButtonValidate"
:
UpdateUserProfile
();
setNewScene
(
"../fxml/viewProfile.fxml"
,
e
);
break
;
default
:
System
.
out
.
println
(
"["
+
buttonSource
+
"] A handler button was triggered, but no action was performed."
);
}
}
private
void
UpdateUserProfile
()
{
try
{
UserLight
user
=
this
.
model
.
getUserLight
();
LocalDate
localDate
=
this
.
modifyProfileTextFieldBirthDate
.
getValue
();
Date
date
=
Date
.
from
(
localDate
.
atStartOfDay
()
.
atZone
(
ZoneId
.
systemDefault
())
.
toInstant
());
user
.
setFirstName
(
this
.
modifyProfileTextFieldFirstName
.
getText
());
user
.
setLastName
(
this
.
modifyProfileTextFieldName
.
getText
());
user
.
setPseudo
(
this
.
modifyProfileTextFieldPseudo
.
getText
());
user
.
setDateOfBirth
(
date
);
ClientApp
.
mainCore
.
getMainToData
().
updatedProfile
(
user
);
}
catch
(
Exception
exception
){
System
.
out
.
println
(
"Exception caught: "
+
exception
.
getMessage
());
}
}
private
void
setNewScene
(
String
path
,
MouseEvent
e
)
throws
IOException
{
FXMLLoader
loader
=
new
FXMLLoader
(
getClass
().
getResource
(
path
));
Parent
padre
=
loader
.
load
();
Scene
switcher
=
new
Scene
(
padre
);
this
.
stage
=
(
Stage
)((
Node
)
e
.
getSource
()).
getScene
().
getWindow
();
this
.
stage
.
setScene
(
switcher
);
}
}
src/main/java/client/main/controller/FXProfileConsult.java
View file @
7ca04d65
package
main.java.client.main.controller
;
import
javafx.fxml.Initializable
;
import
main.java.client.ClientApp
;
import
main.java.client.main.model.MainApplicationModel
;
import
main.java.common.dataModel.UserHeavy
;
import
main.java.common.dataModel.UserLight
;
import
javafx.fxml.FXML
;
import
javafx.fxml.FXMLLoader
;
import
javafx.scene.Scene
;
import
javafx.scene.text.Text
;
import
javafx.scene.control.Button
;
import
javafx.scene.input.MouseEvent
;
import
javafx.scene.layout.BorderPane
;
import
javafx.scene.layout.Pane
;
import
javafx.stage.Stage
;
import
javafx.scene.Node
;
import
javafx.scene.Parent
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.time.LocalDate
;
import
java.time.Period
;
import
java.time.Year
;
import
java.time.ZoneId
;
import
java.util.Date
;
import
java.time.*
;
import
javafx.scene.control.DatePicker
;
import
javafx.scene.control.PasswordField
;
import
javafx.scene.control.TextField
;
import
java.io.IOException
;
import
java.util.ResourceBundle
;
public
class
FXProfileConsult
{
public
class
FXProfileConsult
implements
Initializable
{
private
MainApplicationModel
model
;
private
Stage
stage
;
@FXML
private
TextField
modifyProfileTextFieldName
;
private
Text
displayProfilePseudo
;
@FXML
private
Text
displayProfileLastName
;
@FXML
private
Text
Field
modifyProfileTextField
FirstName
;
private
Text
displayProfile
FirstName
;
@FXML
private
PasswordField
modifyProfilePasswordFieldPassword
;
private
Text
displayProfileAge
;
@FXML
private
DatePicker
modifyProfileTextFieldBirthDate
;
private
Text
displayProfileNbVictories
;
@FXML
private
Text
Field
modifyProfileTextFieldPseudo
;
private
Text
displayProfileNbGames
;
public
FXProfileConsult
(){
this
.
model
=
ClientApp
.
mainCore
.
getFX
().
getModel
();
...
...
@@ -50,106 +60,54 @@ public class FXProfileConsult {
this
.
stage
=
stage
;
}
public
void
initialize
(
String
fxmlResource
,
Stage
stage
)
throws
IOException
{
public
void
initialize
(
URL
fxmlResource
,
ResourceBundle
resource
)
{
FXMLLoader
fxmlLoader
=
new
FXMLLoader
(
getClass
()
.
getResource
(
fxmlResource
));
BorderPane
root
=
(
BorderPane
)
fxmlLoader
.
load
();
FXProfileConsult
controller
=
fxmlLoader
.
getController
();
controller
.
setStage
(
stage
);
UserLight
user
=
this
.
model
.
getUserLight
();
Scene
scene
=
new
Scene
(
root
,
ClientApp
.
APPLICATION_WIDTH
,
ClientApp
.
APPLICATION_HEIGHT
);
scene
.
getStylesheets
().
add
(
ClientApp
.
CSS_FILE_PATH
);
Date
date
=
user
.
getDateOfBirth
();
LocalDate
birthdate
=
date
.
toInstant
().
atZone
(
ZoneId
.
systemDefault
()).
toLocalDate
();
Date
now
=
new
Date
();
LocalDate
today
=
now
.
toInstant
().
atZone
(
ZoneId
.
systemDefault
()).
toLocalDate
();
int
age
=
Period
.
between
(
birthdate
,
today
).
getYears
();
displayProfileFirstName
.
setText
(
user
.
getFirstName
());
displayProfileAge
.
setText
(
Integer
.
toString
(
age
));
displayProfileLastName
.
setText
(
user
.
getLastName
());
displayProfilePseudo
.
setText
(
user
.
getPseudo
());
displayProfileNbGames
.
setText
(
Integer
.
toString
(
user
.
getPlayedGames
()));
displayProfileNbVictories
.
setText
(
Integer
.
toString
(
user
.
getWonGames
()));
stage
.
setScene
(
scene
);
stage
.
show
();
}
@FXML
private
void
handleButtonClick
(
MouseEvent
e
)
throws
IOException
{
private
void
handleButtonClick
(
MouseEvent
e
)
throws
NullPointerException
,
IOException
{
String
buttonSource
=
((
Button
)
e
.
getSource
()).
getId
();
switch
(
buttonSource
){
case
"viewProfileButtonClose"
:
this
.
stage
=
(
Stage
)((
Node
)
e
.
getSource
()).
getScene
().
getWindow
();
FXHome
fxHome
=
new
FXHome
();
fxHome
.
initialize
(
"../fxml/home.fxml"
,
this
.
stage
);
break
;
case
"viewProfileButtonEdit"
:
this
.
stage
.
setScene
(
ModifyProfileScene
());
break
;
case
"modifyProfileCancel"
:
this
.
stage
.
setScene
(
MyProfileScene
());
break
;
case
"modifyProfileValidate"
:
this
.
stage
.
setScene
(
UpdateUserProfile
());
FXMLLoader
loader
=
new
FXMLLoader
(
getClass
().
getResource
(
"../fxml/modifyProfile.fxml"
));
Parent
padre
=
loader
.
load
();
Scene
switcher
=
new
Scene
(
padre
);
this
.
stage
=
(
Stage
)((
Node
)
e
.
getSource
()).
getScene
().
getWindow
();
this
.
stage
.
setScene
(
switcher
);
break
;
default
:
System
.
out
.
println
(
"["
+
buttonSource
+
"] A handler button was triggered, but no action was performed."
);
}
}
private
Scene
MyProfileScene
(
)
throws
IOException
{
FXMLLoader
fxmlL
oader
=
new
FXMLLoader
(
getClass
()
.
getResource
(
"../fxml/viewProfile.fxml"
)
);
BorderPane
root
=
(
BorderPane
)
fxmlLoader
.
load
(
);
return
setNewScene
(
fxmlLoader
,
root
);
private
void
setNewScene
(
String
path
,
MouseEvent
e
)
throws
IOException
{
FXMLLoader
l
oader
=
new
FXMLLoader
(
getClass
()
.
getResource
(
path
));
Parent
padre
=
loader
.
load
(
);
Scene
switcher
=
new
Scene
(
padre
);
this
.
stage
=
(
Stage
)((
Node
)
e
.
getSource
()).
getScene
().
getWindow
();
this
.
stage
.
setScene
(
switcher
);
}
private
Scene
ModifyProfileScene
()
throws
IOException
{
FXMLLoader
fxmlLoader
=
new
FXMLLoader
(
getClass
()
.
getResource
(
"../fxml/modifyProfile.fxml"
));
BorderPane
root
=
(
BorderPane
)
fxmlLoader
.
load
();
UserLight
user
=
this
.
model
.
getUserLight
();
Date
date
=
user
.
getDateOfBirth
();
LocalDate
localdate
=
date
.
toInstant
().
atZone
(
ZoneId
.
systemDefault
()).
toLocalDate
();
this
.
modifyProfileTextFieldName
.
setText
(
user
.
getLastName
());
this
.
modifyProfileTextFieldFirstName
.
setText
(
user
.
getFirstName
());
this
.
modifyProfileTextFieldPseudo
.
setText
(
user
.
getPseudo
());
this
.
modifyProfileTextFieldBirthDate
.
setValue
(
localdate
);
return
setNewScene
(
fxmlLoader
,
root
);
}
private
Scene
UpdateUserProfile
()
throws
IOException
{
FXMLLoader
fxmlLoader
=
new
FXMLLoader
(
getClass
()
.
getResource
(
"../fxml/viewProfile.fxml"
));
BorderPane
root
=
(
BorderPane
)
fxmlLoader
.
load
();
try
{
UserLight
user
=
this
.
model
.
getUserLight
();
LocalDate
localDate
=
this
.
modifyProfileTextFieldBirthDate
.
getValue
();
Date
date
=
java
.
util
.
Date
.
from
(
localDate
.
atStartOfDay
()
.
atZone
(
ZoneId
.
systemDefault
())
.
toInstant
());
user
.
setFirstName
(
this
.
modifyProfileTextFieldFirstName
.
getText
());
user
.
setLastName
(
this
.
modifyProfileTextFieldName
.
getText
());
user
.
setPseudo
(
this
.
modifyProfileTextFieldPseudo
.
getText
());
user
.
setDateOfBirth
(
date
);
ClientApp
.
mainCore
.
getMainToData
().
updatedProfile
(
user
);
}
catch
(
Exception
exception
){
System
.
out
.
println
(
"Exception caught: "
+
exception
.
getMessage
());
}
return
setNewScene
(
fxmlLoader
,
root
);
}
private
Scene
setNewScene
(
FXMLLoader
loader
,
Pane
root
){
FXProfileConsult
controller
=
loader
.
getController
();
controller
.
setStage
(
stage
);
Scene
scene
=
new
Scene
(
root
,
ClientApp
.
APPLICATION_WIDTH
,
ClientApp
.
APPLICATION_HEIGHT
);
scene
.
getStylesheets
().
add
(
ClientApp
.
CSS_FILE_PATH
);
return
scene
;
}
}
Louis Bal Dit Sollier
@lbaldits
mentioned in commit
769919c8
·
Nov 27, 2019
mentioned in commit
769919c8
mentioned in commit 769919c88d6ccad80e861d5bbe6bfc96f64f611a
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment