Skip to content

Commit

Permalink
Merge pull request #10 from DarraghClarke/UI_updates
Browse files Browse the repository at this point in the history
Ui updates
  • Loading branch information
oisinq committed Dec 24, 2019
2 parents e1e0566 + 857fc39 commit deffd76
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 12 deletions.
13 changes: 12 additions & 1 deletion client/src/main/java/service/client/chatwindow/CellRenderer.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package service.client.chatwindow;

import com.sun.scenario.effect.impl.sw.java.JSWBlend_GREENPeer;
import javafx.geometry.Pos;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Shape;
import javafx.scene.text.Text;
import javafx.util.Callback;
import message.SessionMessage;
Expand All @@ -24,8 +28,15 @@ protected void updateItem(SessionMessage user, boolean bln) {
HBox hBox = new HBox();

Text username = new Text(user.getUsername());//atm just adds user name
Circle circle = new Circle(0, 0, 10);
if(System.currentTimeMillis() / 1000l - user.getTimestamp() > 60 ){
//online in the last minute
circle.setFill(Color.GRAY);
} else{
circle.setFill(Color.LIGHTGREEN);
}

hBox.getChildren().add(username);
hBox.getChildren().addAll(username,circle);
hBox.setAlignment(Pos.CENTER_LEFT);

setGraphic(hBox);
Expand Down
10 changes: 5 additions & 5 deletions client/src/main/java/service/client/chatwindow/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public void onClose(int code, String reason, boolean remote) {
public void onMessage(String message) {
Gson gson = new Gson();
//this is meant to be a logic to sort different types of messages, though for testing right now it only takes the user lists
// if (message.contains("message")){
// Message msg = gson.fromJson(message, Message.class);
// controller.addToChat(msg);
// }// else if (message.contains("sessionMessage")){
if (message.contains("\"sender\":")){//element unique to message tyoe
Message msg = gson.fromJson(message, Message.class);
controller.addToChat(msg);
} else if (message.contains("\"gateway\":")){//element unique to session type
Type collectionType = new TypeToken<ArrayList<SessionMessage>>(){}.getType();
ArrayList<SessionMessage> msg = (ArrayList<SessionMessage>) gson.fromJson( message , collectionType);
System.out.println("wow?");
controller.setOnline(msg);
//}
}
}

@Override
Expand Down
16 changes: 15 additions & 1 deletion client/src/main/java/service/client/chatwindow/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class Controller implements Initializable {
ListView chatPane;
@FXML
BorderPane borderPane;
@FXML
private Label userInfo;

private String username;
private Client client;
Expand Down Expand Up @@ -97,13 +99,25 @@ public HBox call() {
}
}

public void setUserInfo(SessionMessage user){
if (System.currentTimeMillis() / 1000l - user.getTimestamp() > 60) {//i think this means last minute online
userInfo.setText(user.getUsername() + "-Last online: " + (System.currentTimeMillis() / 1000l - user.getTimestamp())/60 + " minutes ago");
} else{
userInfo.setText(user.getUsername() + "-Online Now");
}
}

public void setOnline(ArrayList<SessionMessage> allUsers) {
Platform.runLater(() -> {
ObservableList<SessionMessage> users = FXCollections.observableList(allUsers);
userList.getItems().clear();
userList.setItems(users);
userList.setCellFactory(new CellRenderer());
userList.getSelectionModel().selectedItemProperty().addListener((ChangeListener<SessionMessage>)
(observable, oldValue, newValue) -> System.out.println("Selected item: " + newValue.getUsername()));
(observable, oldValue, newValue) -> {
System.out.println("Selected item: " + newValue.getUsername());
setUserInfo(newValue);
});
});

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public void loginButtonAction() throws IOException, URISyntaxException {
this.scene = new Scene(window);

//this gets the gateway from the load balancer
RestTemplate restTemplate = new RestTemplate();
String temp = restTemplate.getForObject("http://localhost:8081/getGateway", String.class);
//RestTemplate restTemplate = new RestTemplate();
//String temp = restTemplate.getForObject("http://192.168.99.100:8081/getGateway", String.class);
Client client = new Client(new URI("ws://localhost:8080/"), username, controller);
Thread x = new Thread(client);
x.start();
Expand Down
14 changes: 12 additions & 2 deletions client/src/main/resources/views/ChatView.fxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Point3D?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TextArea?>
Expand All @@ -9,11 +10,20 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<BorderPane fx:id="borderPane" maxHeight="620.0" maxWidth="1040.0" prefHeight="620.0" prefWidth="1040.0" xmlns="http://javafx.com/javafx/8.0.999-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="service.client.chatwindow.Controller">
<BorderPane fx:id="borderPane" maxHeight="620.0" maxWidth="1040.0" prefHeight="620.0" prefWidth="1040.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="service.client.chatwindow.Controller">
<center>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<children>
<ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" pannable="true" prefHeight="625.0" prefWidth="823.0" vbarPolicy="ALWAYS" vmin="1.0" vvalue="1.0" VBox.vgrow="ALWAYS">
<HBox alignment="TOP_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="100.0" prefHeight="25.0" prefWidth="822.0">
<children>
<BorderPane prefHeight="26.0" prefWidth="873.0">
<center>
<Label fx:id="userInfo" prefHeight="18.0" prefWidth="358.0" text="Welcome!" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
</children>
</HBox>
<ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" pannable="true" prefHeight="554.0" prefWidth="822.0" vbarPolicy="ALWAYS" vmin="1.0" vvalue="1.0" VBox.vgrow="ALWAYS">
<content>
<ListView fx:id="chatPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" />
</content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import com.mongodb.client.MongoDatabase;
import message.SessionMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.bson.Document;

import javax.jms.*;

import static com.mongodb.client.model.Filters.eq;

/**
* Thread for handling applications from the RESPONSES queue
*/
Expand Down Expand Up @@ -45,7 +48,15 @@ public void run() {
Object content = ((ObjectMessage) message).getObject();
if (content instanceof SessionMessage) {
SessionMessage response = (SessionMessage) content;
collection.insertOne(response);

SessionMessage existingSession = collection.find(eq("username", response.getUsername())).first();

if (existingSession == null) {
collection.insertOne(response);
} else {
collection.updateOne(eq("username", response.getUsername()),
new Document("$set", new Document("timestamp", response.getTimestamp())));
}
}

// Finally, we acknowledge the message
Expand Down

0 comments on commit deffd76

Please sign in to comment.