Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ebf92c1

Browse files
Added new Functionality of share images & gif through the all clients.
1 parent 0317fcf commit ebf92c1

File tree

10 files changed

+151
-258
lines changed

10 files changed

+151
-258
lines changed

‎Client_Side/src/Controller/Client_Room.java

Lines changed: 136 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,27 @@
99
package Controller;
1010

1111
import animatefx.animation.FadeIn;
12+
import javafx.application.Platform;
1213
import javafx.embed.swing.SwingFXUtils;
1314
import javafx.event.ActionEvent;
1415
import javafx.fxml.Initializable;
15-
import javafx.geometry.NodeOrientation;
16+
import javafx.geometry.Pos;
1617
import javafx.scene.Node;
1718
import javafx.scene.control.Button;
1819
import javafx.scene.control.Label;
19-
import javafx.scene.control.TextArea;
2020
import javafx.scene.control.TextField;
2121
import javafx.scene.image.Image;
2222
import javafx.scene.image.ImageView;
2323
import javafx.scene.input.KeyEvent;
2424
import javafx.scene.input.MouseEvent;
25+
import javafx.scene.layout.HBox;
2526
import javafx.scene.layout.Pane;
27+
import javafx.scene.layout.VBox;
2628
import javafx.scene.paint.Color;
2729
import javafx.scene.paint.ImagePattern;
2830
import javafx.scene.shape.Circle;
29-
import javafx.scene.shape.Rectangle;
31+
import javafx.scene.text.Text;
32+
import javafx.scene.text.TextFlow;
3033
import javafx.stage.FileChooser;
3134
import javafx.stage.Stage;
3235

@@ -50,22 +53,9 @@ public class Client_Room extends Thread implements Initializable {
5053
public Label gender;
5154
public ImageView proImage;
5255
public TextField fileChoosePath;
53-
public TextArea msgRoom;
5456
public TextField msgField;
5557
public Pane chat;
56-
public Button a;
57-
public Button b;
58-
public Button c;
59-
public Button d;
60-
public Button e;
61-
public Button f;
62-
public Button g;
63-
public Button h;
64-
public Button i;
65-
public Button j;
66-
public Button k;
67-
public Button l;
68-
public Rectangle emojiBox;
58+
6959

7060
public boolean toggleChat = false, toggleProfile = false;
7161

@@ -74,6 +64,8 @@ public class Client_Room extends Thread implements Initializable {
7464
*/
7565

7666
public boolean saveControl = false;
67+
public VBox vbox;
68+
7769

7870
BufferedReader reader;
7971
PrintWriter writer;
@@ -96,24 +88,11 @@ public void initialize(URL location, ResourceBundle resources) {
9688
clientName.setText(Login_Signup.username);
9789
connectSocket();
9890

99-
emojiBox.setVisible(false);
100-
a.setVisible(false);
101-
b.setVisible(false);
102-
c.setVisible(false);
103-
d.setVisible(false);
104-
e.setVisible(false);
105-
f.setVisible(false);
106-
g.setVisible(false);
107-
h.setVisible(false);
108-
i.setVisible(false);
109-
j.setVisible(false);
110-
k.setVisible(false);
111-
l.setVisible(false);
11291
}
11392

11493
public void connectSocket() {
11594
try {
116-
socket = new Socket("localhost", 5006);
95+
socket = new Socket("localhost", 5007);
11796
System.out.println("Socket is connected with server!");
11897
reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
11998
writer = new PrintWriter(socket.getOutputStream(), true);
@@ -126,6 +105,121 @@ public void connectSocket() {
126105

127106
@Override
128107
public void run() {
108+
try {
109+
while (true) {
110+
111+
112+
String msg = reader.readLine();
113+
String[] tokens = msg.split(" ");
114+
String cmd = tokens[0];
115+
116+
// txtTextArea.appendText(cmd+"\n");
117+
StringBuilder fullMsg = new StringBuilder();
118+
for (int i = 1; i < tokens.length; i++) {
119+
fullMsg.append(tokens[i]);
120+
}
121+
122+
123+
String[] msgToAr = msg.split(" ");
124+
String st = "";
125+
for (int i = 0; i < msgToAr.length - 1; i++) {
126+
st += msgToAr[i + 1] + " ";
127+
}
128+
//======================================================================
129+
130+
131+
Text text = new Text(st);
132+
String firstChars = "";
133+
if (st.length() > 3) {
134+
firstChars = st.substring(0, 3);
135+
136+
}
137+
138+
139+
if (firstChars.equalsIgnoreCase("img")) {
140+
//for the Images
141+
142+
st = st.substring(3, st.length() - 1);
143+
144+
145+
File file = new File(st);
146+
Image image = new Image(file.toURI().toString());
147+
148+
ImageView imageView = new ImageView(image);
149+
150+
imageView.setFitHeight(75);
151+
imageView.setFitWidth(150);
152+
153+
154+
HBox hBox = new HBox(10);
155+
hBox.setAlignment(Pos.BOTTOM_RIGHT);
156+
157+
158+
if (!cmd.equalsIgnoreCase(Login_Signup.username)) {
159+
160+
vbox.setAlignment(Pos.TOP_LEFT);
161+
hBox.setAlignment(Pos.CENTER_LEFT);
162+
163+
164+
Text text1 = new Text(" " + cmd + " :");
165+
hBox.getChildren().add(text1);
166+
hBox.getChildren().add(imageView);
167+
168+
} else {
169+
hBox.setAlignment(Pos.BOTTOM_RIGHT);
170+
hBox.getChildren().add(imageView);
171+
Text text1 = new Text(": Me ");
172+
hBox.getChildren().add(text1);
173+
174+
}
175+
176+
Platform.runLater(() -> vbox.getChildren().addAll(hBox));
177+
178+
179+
} else {
180+
//For the Text
181+
/*text.setFill(Color.WHITE);*/
182+
text.getStyleClass().add("message");
183+
TextFlow tempFlow = new TextFlow();
184+
185+
if (!cmd.equalsIgnoreCase(Login_Signup.username + ":")) {
186+
Text txtName = new Text(cmd + " ");
187+
txtName.getStyleClass().add("txtName");
188+
tempFlow.getChildren().add(txtName);
189+
}
190+
191+
tempFlow.getChildren().add(text);
192+
tempFlow.setMaxWidth(200); //200
193+
194+
TextFlow flow = new TextFlow(tempFlow);
195+
196+
HBox hBox = new HBox(12); //12
197+
198+
//=================================================
199+
200+
201+
if (!cmd.equalsIgnoreCase(Login_Signup.username + ":")) {
202+
203+
vbox.setAlignment(Pos.TOP_LEFT);
204+
hBox.setAlignment(Pos.CENTER_LEFT);
205+
hBox.getChildren().add(flow);
206+
207+
} else {
208+
// text.setFill(Color.WHITE);
209+
210+
hBox.setAlignment(Pos.BOTTOM_RIGHT);
211+
hBox.getChildren().add(flow);
212+
}
213+
hBox.getStyleClass().add("hbox");
214+
Platform.runLater(() -> vbox.getChildren().addAll(hBox));
215+
}
216+
}
217+
218+
} catch (Exception e) {
219+
e.printStackTrace();
220+
}
221+
}
222+
/* public void run() {
129223
try {
130224
while (true) {
131225
String msg = reader.readLine();
@@ -150,7 +244,7 @@ public void run() {
150244
} catch (Exception e) {
151245
e.printStackTrace();
152246
}
153-
}
247+
}*/
154248

155249
public void handleProfileBtn(ActionEvent event) {
156250
if (event.getSource().equals(profileBtn) && !toggleProfile) {
@@ -193,8 +287,11 @@ public void handleSendEvent(MouseEvent mouseEvent) {
193287
public void send() {
194288
msg = msgField.getText();
195289
writer.println(Login_Signup.username + ": " + msg);
196-
msgRoom.setNodeOrientation(NodeOrientation.LEFT_TO_RIGHT);
197-
msgRoom.appendText("Me: " + msg + "\n");
290+
291+
/* msgRoom.setNodeOrientation(NodeOrientation.LEFT_TO_RIGHT);
292+
msgRoom.appendText("Me: " + msg + "\n");*/
293+
294+
198295
msgField.setText("");
199296
if (msg.equalsIgnoreCase("BYE") || (msg.equalsIgnoreCase("logout"))) {
200297
System.exit(0);
@@ -232,84 +329,12 @@ public void sendMessageByKey(KeyEvent event) {
232329
}
233330

234331

235-
public void mouseClickedAnotherArea(MouseEvent mouseEvent) {
236-
emojiBox.setVisible(false);
237-
a.setVisible(false);
238-
b.setVisible(false);
239-
c.setVisible(false);
240-
d.setVisible(false);
241-
e.setVisible(false);
242-
f.setVisible(false);
243-
g.setVisible(false);
244-
h.setVisible(false);
245-
i.setVisible(false);
246-
j.setVisible(false);
247-
k.setVisible(false);
248-
l.setVisible(false);
249-
}
250-
251332
public void cameraIconMouseClicked(MouseEvent mouseEvent) {
252-
emojiBox.setVisible(true);
253-
a.setVisible(true);
254-
b.setVisible(true);
255-
c.setVisible(true);
256-
d.setVisible(true);
257-
e.setVisible(true);
258-
f.setVisible(true);
259-
g.setVisible(true);
260-
h.setVisible(true);
261-
i.setVisible(true);
262-
j.setVisible(true);
263-
k.setVisible(true);
264-
l.setVisible(true);
265-
}
266-
267-
public void clickEmoji1(MouseEvent mouseEvent) {
268-
msgField.setText(msg + a.getText());
269-
}
270-
271-
public void clickEmoji2(MouseEvent mouseEvent) {
272-
msgField.setText(msg + b.getText());
273-
}
274333

275-
public void clickEmoji3(MouseEvent mouseEvent) {
276-
msgField.setText(msg + c.getText());
277-
}
278-
279-
public void clickEmoji4(MouseEvent mouseEvent) {
280-
msgField.setText(msg + d.getText());
281-
}
282-
283-
public void clickEmoji5(MouseEvent mouseEvent) {
284-
msgField.setText(msg + e.getText());
285-
}
286-
287-
public void clickEmoji6(MouseEvent mouseEvent) {
288-
msgField.setText(msg + f.getText());
289-
}
290-
291-
public void clickEmoji7(MouseEvent mouseEvent) {
292-
msgField.setText(msg + g.getText());
293-
}
294-
295-
public void clickEmoji8(MouseEvent mouseEvent) {
296-
msgField.setText(msg + h.getText());
297-
}
298-
299-
public void clickEmoji9(MouseEvent mouseEvent) {
300-
msgField.setText(msg + i.getText());
301-
}
302-
303-
public void clickEmoji10(MouseEvent mouseEvent) {
304-
msgField.setText(msg + j.getText());
305-
}
306-
307-
public void clickEmoji11(MouseEvent mouseEvent) {
308-
msgField.setText(msg + k.getText());
309-
}
310-
311-
public void clickEmoji12(MouseEvent mouseEvent) {
312-
msgField.setText(msg + l.getText());
334+
Stage stage = (Stage) ((Node) mouseEvent.getSource()).getScene().getWindow();
335+
fileChooser = new FileChooser();
336+
fileChooser.setTitle("Open Image");
337+
this.filePath = fileChooser.showOpenDialog(stage);
338+
writer.println(Login_Signup.username + " " + "img" + filePath.getPath());
313339
}
314-
315340
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /