Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tp-4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pirkl-poo-2018
tp-4
Commits
cc7c5784
Verified
Commit
cc7c5784
authored
6 years ago
by
Théo Pirkl
Browse files
Options
Downloads
Patches
Plain Diff
Handles Events better
parent
55765ede
Branches
Branches containing commit
No related tags found
1 merge request
!21
*poof* final version
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/ch/hepia/ui/MainWindowController.java
+48
-26
48 additions, 26 deletions
src/main/java/ch/hepia/ui/MainWindowController.java
with
48 additions
and
26 deletions
src/main/java/ch/hepia/ui/MainWindowController.java
+
48
−
26
View file @
cc7c5784
...
...
@@ -291,46 +291,68 @@ public class MainWindowController implements Initializable {
}
/**
*
Create a new journey and broadcast it
*
Set the journey label and the current journey
* @param ap
p App context
* @
param pnl Panel containing the journey information
*
Handle current connection UI reactivity events
*
@param app The app context
* @param ap
i The Weather API
* @
throws IOException Whenever the Weather API goofs up
*/
private
void
createJourney
(
AppContext
app
,
Pane
pnl
)
throws
IOException
{
Integer
pos
=
Integer
.
parseInt
(
pnl
.
getId
());
// setConnectionPanelStyle(pnl, AppConfig.COLOR_GREEN_20_OPACITY);
WeatherAPI
api
=
new
WeatherAPI
();
Connection
connection
=
displayedConnections
.
get
(
pos
);
String
wtd
=
api
.
getWeatherFrom
(
connection
.
getTo
().
getLocation
().
getCoordinates
()).
getConditionsIcon
();
private
void
setupCurrentConnection
(
AppContext
app
,
WeatherAPI
api
)
throws
IOException
{
String
wtcd
=
api
.
getWeatherFrom
(
currentJourney
.
getTo
().
getLocation
().
getCoordinates
()).
getConditionsIcon
();
if
(!(
currentJourney
instanceof
Connection
.
EmptyConnection
)){
leaveJourney
(
app
,
wtcd
);
}
JoinedJourney
joinedJourney
=
new
JoinedJourney
(
app
.
getUser
().
get
(),
connection
,
wtd
);
app
.
getMessageManager
().
sendJoinedJourney
(
joinedJourney
);
currentJourney
=
displayedConnections
.
get
(
pos
);
currentJourneyLabel
.
setText
(
"Vous voyagez de "
+
currentJourney
.
getFrom
().
getLocation
().
getName
()
+
" vers "
+
currentJourney
.
getTo
().
getLocation
().
getName
()
+
"."
);
+
currentJourney
.
getTo
().
getLocation
().
getName
()
+
".
Cliquez ici pour quitter cet itinéraire.
"
);
currentJourneyLabel
.
setUnderline
(
true
);
currentJourneyLabel
.
setOnMouseClicked
(
event
->
{
Alert
alertQuit
=
new
Alert
(
Alert
.
AlertType
.
CONFIRMATION
);
alertQuit
.
setTitle
(
"Quitter le trajet"
);
alertQuit
.
setHeaderText
(
"Quitter le trajet"
);
alertQuit
.
setContentText
(
"Souhaitez-vous quitter ce trajet ?"
);
ButtonType
ouiQuit
=
new
ButtonType
(
"Oui"
);
ButtonType
nonQuit
=
new
ButtonType
(
"Non"
);
alertQuit
.
getButtonTypes
().
setAll
(
ouiQuit
,
nonQuit
);
Optional
<
ButtonType
>
resultQuit
=
alertQuit
.
showAndWait
();
if
(
resultQuit
.
get
().
equals
(
ouiQuit
)){
leaveJourney
(
app
,
wtcd
);
}
});
}
/**
* Create a new journey and broadcast it
* Set the journey label and the current journey
* @param app App context
* @param pnl Panel containing the journey information
*/
private
void
createJourney
(
AppContext
app
,
Pane
pnl
)
throws
IOException
,
ParseException
{
if
(
currentJourney
.
equals
(
new
Connection
.
EmptyConnection
())){
Alert
alert
=
new
Alert
(
Alert
.
AlertType
.
CONFIRMATION
);
alert
.
setTitle
(
"
Quitt
er le trajet"
);
alert
.
setHeaderText
(
"
Quitt
er le trajet"
);
alert
.
setContentText
(
"Souhaitez-vous
quitt
er ce trajet ?"
);
alert
.
setTitle
(
"
Valid
er le trajet"
);
alert
.
setHeaderText
(
"
Valid
er le trajet"
);
alert
.
setContentText
(
"Souhaitez-vous
sélectionn
er ce trajet ?"
);
ButtonType
oui
=
new
ButtonType
(
"Oui"
);
ButtonType
non
=
new
ButtonType
(
"Non"
);
alert
.
getButtonTypes
().
setAll
(
oui
,
non
);
Optional
<
ButtonType
>
result
=
alert
.
showAndWait
();
if
(
result
.
get
().
equals
(
oui
)){
leaveJourney
(
app
,
wtcd
);
Integer
pos
=
Integer
.
parseInt
(
pnl
.
getId
());
WeatherAPI
api
=
new
WeatherAPI
();
Connection
connection
=
displayedConnections
.
get
(
pos
);
String
wtd
=
api
.
getWeatherFrom
(
connection
.
getTo
().
getLocation
().
getCoordinates
()).
getConditionsIcon
();
JoinedJourney
joinedJourney
=
new
JoinedJourney
(
app
.
getUser
().
get
(),
connection
,
wtd
);
app
.
getMessageManager
().
sendJoinedJourney
(
joinedJourney
);
currentJourney
=
displayedConnections
.
get
(
pos
);
setupCurrentConnection
(
app
,
api
);
}
});
}
else
{
UiUtils
.
dialog
(
Alert
.
AlertType
.
WARNING
,
"Note"
,
"Vous avez un trajet en cours !"
,
"Veuillez s'il vous plait quitter le trajet actuel avant d'en choisir un autre."
);
}
}
/**
* Parse the line and search for chat command.
* @param cmd The line to parse.
...
...
@@ -513,7 +535,7 @@ public class MainWindowController implements Initializable {
Pane
pnl
=
(
Pane
)
e
.
getSource
();
try
{
createJourney
(
app
,
pnl
);
}
catch
(
IO
Exception
ex
){
}
catch
(
Exception
ex
){
showSadMessage
(
AppConfig
.
ERROR_API_MQ
);
ex
.
printStackTrace
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment