Skip to content
Snippets Groups Projects
Commit 0d9e2b8c authored by Alexis Durgnat's avatar Alexis Durgnat :milky_way:
Browse files

image added to chat message

parent 1e218dce
No related branches found
No related tags found
1 merge request!21*poof* final version
...@@ -16,8 +16,10 @@ import javafx.fxml.FXML; ...@@ -16,8 +16,10 @@ import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.canvas.Canvas; import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import javafx.scene.layout.Background; import javafx.scene.layout.Background;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
...@@ -31,9 +33,7 @@ import java.text.ParseException; ...@@ -31,9 +33,7 @@ import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javafx.scene.image.Image;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
public class MainWindowController implements Initializable { public class MainWindowController implements Initializable {
...@@ -111,32 +111,33 @@ public class MainWindowController implements Initializable { ...@@ -111,32 +111,33 @@ public class MainWindowController implements Initializable {
*/ */
private void drawConnection(Connection connection, int x, int y){ private void drawConnection(Connection connection, int x, int y){
List<Section> sections = connection.getSections(); List<Section> sections = connection.getSections();
connectionCanvas.getGraphicsContext2D().setFill(Color.RED); GraphicsContext gcx = connectionCanvas.getGraphicsContext2D();
connectionCanvas.getGraphicsContext2D().fillText(sections.get(0).getDeparture().getLocation().getName(), x, y - 20); gcx.setFill(Color.RED);
connectionCanvas.getGraphicsContext2D().setFill(Color.BLACK); gcx.fillText(sections.get(0).getDeparture().getLocation().getName(), x, y - 20);
connectionCanvas.getGraphicsContext2D().fillText(sections.get(0).getDeparture().getDepartureTime().toString(), x, y - 40); gcx.setFill(Color.BLACK);
connectionCanvas.getGraphicsContext2D().setFill(Color.RED); gcx.fillText(sections.get(0).getDeparture().getDepartureTime().toString(), x, y - 40);
connectionCanvas.getGraphicsContext2D().fillOval(x - 5, y - 5, 10, 10); gcx.setFill(Color.RED);
connectionCanvas.getGraphicsContext2D().strokeLine(x, y, x + 622 / (sections.size() + 1), y); gcx.fillOval(x - 5, y - 5, 10, 10);
gcx.strokeLine(x, y, x + 622 / (sections.size() + 1), y);
for (int i = 0; i < sections.size(); i++){ for (int i = 0; i < sections.size(); i++){
connectionCanvas.getGraphicsContext2D().strokeLine( gcx.strokeLine(
x + (622 / (sections.size() + 1)) * (i + 1), y, 622 / (sections.size()), y); x + (622 / (sections.size() + 1)) * (i + 1), y, 622 / (sections.size()), y);
connectionCanvas.getGraphicsContext2D().setFill(Color.RED); gcx.setFill(Color.RED);
connectionCanvas.getGraphicsContext2D().fillOval(x + (622 / (sections.size() + 1)) * (i + 1) - 5, y - 5, 10, 10); gcx.fillOval(x + (622 / (sections.size() + 1)) * (i + 1) - 5, y - 5, 10, 10);
connectionCanvas.getGraphicsContext2D().fillText(sections.get(i).getArrival().getLocation().getName(), gcx.fillText(sections.get(i).getArrival().getLocation().getName(),
x + (622 / (sections.size() + 1)) * (i + 1), y - 20); x + (622 / (sections.size() + 1)) * (i + 1), y - 20);
connectionCanvas.getGraphicsContext2D().setFill(Color.BLACK); gcx.setFill(Color.BLACK);
connectionCanvas.getGraphicsContext2D().fillText(sections.get(i).getArrival().getArrivalTime().toString(), gcx.fillText(sections.get(i).getArrival().getArrivalTime().toString(),
x + (622 / (sections.size() + 1)) * (i + 1), y - 40); x + (622 / (sections.size() + 1)) * (i + 1), y - 40);
Journey jrn = sections.get(i).getJourney(); Journey jrn = sections.get(i).getJourney();
String transportType = "MARCHE"; String transportType = "MARCHE";
if (!(jrn instanceof Journey.EmptyJourney)) { if (!(jrn instanceof Journey.EmptyJourney)) {
transportType = jrn.getCategory() + ", " + jrn.getNumber(); transportType = jrn.getCategory() + ", " + jrn.getNumber();
} }
connectionCanvas.getGraphicsContext2D().setFill(Color.BLUE); gcx.setFill(Color.BLUE);
connectionCanvas.getGraphicsContext2D().fillText(transportType, x + (622 / (sections.size() + 1)) * (i), y - 55); gcx.fillText(transportType, x + (622 / (sections.size() + 1)) * (i), y - 55);
connectionCanvas.getGraphicsContext2D().setFill(Color.RED); gcx.setFill(Color.RED);
} }
} }
...@@ -147,13 +148,13 @@ public class MainWindowController implements Initializable { ...@@ -147,13 +148,13 @@ public class MainWindowController implements Initializable {
private void drawMessage(User user, String message){ private void drawMessage(User user, String message){
Pane p = new Pane(); Pane p = new Pane();
p.setMaxWidth(326); p.setMaxWidth(326);
Image lblImg = new Image(Main.class.getResourceAsStream("/img/bubble.png"));
Label msg = new Label(); Label msg = new Label();
msg.setWrapText(true); msg.setWrapText(true);
msg.setStyle("-fx-padding: 8px"); msg.setStyle("-fx-padding: 8px");
msg.setText(message); msg.setText(message);
msg.setMaxWidth(310); msg.setMaxWidth(310);
msg.setGraphic(new ImageView(lblImg));
p.getChildren().add(msg); p.getChildren().add(msg);
insertMessageIntoQueue(); insertMessageIntoQueue();
chatContainer.getChildren().add(p); chatContainer.getChildren().add(p);
......
src/main/resources/img/bubble.png

15.6 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment