|
@@ -30,6 +30,7 @@ import javafx.scene.text.TextAlignment;
|
30
|
30
|
import javafx.stage.FileChooser;
|
31
|
31
|
import javafx.stage.Stage;
|
32
|
32
|
import javafx.stage.WindowEvent;
|
|
33
|
+import org.apache.commons.io.FilenameUtils;
|
33
|
34
|
|
34
|
35
|
import javax.swing.*;
|
35
|
36
|
import java.awt.*;
|
|
@@ -37,6 +38,7 @@ import java.beans.PropertyChangeEvent;
|
37
|
38
|
import java.beans.PropertyChangeListener;
|
38
|
39
|
import java.io.File;
|
39
|
40
|
import java.io.IOException;
|
|
41
|
+import java.net.MalformedURLException;
|
40
|
42
|
import java.net.URL;
|
41
|
43
|
import java.text.SimpleDateFormat;
|
42
|
44
|
import java.util.ArrayList;
|
|
@@ -153,9 +155,9 @@ public class ChatWindowController implements Initializable, PropertyChangeListen
|
153
|
155
|
//Desktop.getDesktop().browseFileDirectory(msgFile.getFile());
|
154
|
156
|
}
|
155
|
157
|
});
|
|
158
|
+ HBox hbox = new HBox();
|
|
159
|
+ hbox.setSpacing(2.0);
|
156
|
160
|
if (item.getSourceId() == remoteUser.getId()) {
|
157
|
|
- HBox hbox = new HBox();
|
158
|
|
- hbox.setSpacing(2.0);
|
159
|
161
|
hbox.setAlignment(Pos.CENTER_RIGHT);
|
160
|
162
|
hbox.setBackground(new Background(new BackgroundFill(Paint.valueOf(Color.TRANSPARENT.toString()), null, null)));
|
161
|
163
|
setBackground(new Background(new BackgroundFill(Paint.valueOf(Color.AZURE.toString()), null, null)));
|
|
@@ -168,8 +170,7 @@ public class ChatWindowController implements Initializable, PropertyChangeListen
|
168
|
170
|
setTextAlignment(TextAlignment.RIGHT);
|
169
|
171
|
setPadding(new Insets(10, 0, 10, param.getWidth() * 0.3));
|
170
|
172
|
} else {
|
171
|
|
- HBox hbox = new HBox();
|
172
|
|
- hbox.setSpacing(2.0);
|
|
173
|
+ hbox.setAlignment(Pos.CENTER_LEFT);
|
173
|
174
|
hbox.setBackground(new Background(new BackgroundFill(Paint.valueOf(Color.TRANSPARENT.toString()), null, null)));
|
174
|
175
|
setBackground(new Background(new BackgroundFill(Paint.valueOf(Color.CORNSILK.toString()), null, null)));
|
175
|
176
|
ImageView img = new ImageView();
|
|
@@ -181,6 +182,45 @@ public class ChatWindowController implements Initializable, PropertyChangeListen
|
181
|
182
|
setTextAlignment(TextAlignment.LEFT);
|
182
|
183
|
setPadding(new Insets(10, param.getWidth() * 0.3, 10, 0));
|
183
|
184
|
}
|
|
185
|
+ } else if (item.getType() == 3){
|
|
186
|
+ MessageDisplayFile msgFile = (MessageDisplayFile) item;
|
|
187
|
+ Image imageFileSource = null;
|
|
188
|
+ try {
|
|
189
|
+ imageFileSource = new Image(msgFile.getFile().toURI().toURL().toExternalForm());
|
|
190
|
+ } catch (MalformedURLException e) {
|
|
191
|
+ e.printStackTrace();
|
|
192
|
+ }
|
|
193
|
+ ImageView imageFileView = new ImageView();
|
|
194
|
+ imageFileView.setImage(imageFileSource);
|
|
195
|
+ HBox hbox = new HBox();
|
|
196
|
+ hbox.setSpacing(2.0);
|
|
197
|
+ imageFileView.setPreserveRatio(true);
|
|
198
|
+ imageFileView.fitWidthProperty().bind(this.widthProperty());
|
|
199
|
+ if (item.getSourceId() == remoteUser.getId()) {
|
|
200
|
+ hbox.setAlignment(Pos.CENTER_RIGHT);
|
|
201
|
+ hbox.setBackground(new Background(new BackgroundFill(Paint.valueOf(Color.TRANSPARENT.toString()), null, null)));
|
|
202
|
+ setBackground(new Background(new BackgroundFill(Paint.valueOf(Color.AZURE.toString()), null, null)));
|
|
203
|
+ ImageView img = new ImageView();
|
|
204
|
+ img.setImage(imageRemote);
|
|
205
|
+ hbox.getChildren().addAll(imageFileView, img);
|
|
206
|
+ setGraphic(hbox);
|
|
207
|
+ setContentDisplay(ContentDisplay.RIGHT);
|
|
208
|
+ setAlignment(Pos.CENTER_RIGHT);
|
|
209
|
+ setTextAlignment(TextAlignment.RIGHT);
|
|
210
|
+ setPadding(new Insets(10, 0, 10, param.getWidth() * 0.3));
|
|
211
|
+ } else {
|
|
212
|
+ hbox.setAlignment(Pos.CENTER_LEFT);
|
|
213
|
+ hbox.setBackground(new Background(new BackgroundFill(Paint.valueOf(Color.TRANSPARENT.toString()), null, null)));
|
|
214
|
+ setBackground(new Background(new BackgroundFill(Paint.valueOf(Color.CORNSILK.toString()), null, null)));
|
|
215
|
+ ImageView img = new ImageView();
|
|
216
|
+ img.setImage(imageSource);
|
|
217
|
+ hbox.getChildren().addAll(img, imageFileView);
|
|
218
|
+ setGraphic(hbox);
|
|
219
|
+ setContentDisplay(ContentDisplay.LEFT);
|
|
220
|
+ setAlignment(Pos.CENTER_LEFT);
|
|
221
|
+ setTextAlignment(TextAlignment.LEFT);
|
|
222
|
+ setPadding(new Insets(10, param.getWidth() * 0.3, 10, 0));
|
|
223
|
+ }
|
184
|
224
|
}
|
185
|
225
|
}
|
186
|
226
|
}
|
|
@@ -279,7 +319,18 @@ public class ChatWindowController implements Initializable, PropertyChangeListen
|
279
|
319
|
|
280
|
320
|
//We send the File if the filed is not null
|
281
|
321
|
if (this.filePicked != null){
|
282
|
|
- MessageDisplayFile msgFile = new MessageDisplayFile(model.user.getId(),timeStamp,this.filePicked.getName(),2,this.filePicked);
|
|
322
|
+ String ext = FilenameUtils.getExtension(this.filePicked.getPath());
|
|
323
|
+ int type = 2;
|
|
324
|
+ switch (ext) {
|
|
325
|
+ case "png":
|
|
326
|
+ case "gif":
|
|
327
|
+ case "jpeg":
|
|
328
|
+ case "svg":
|
|
329
|
+ case "jpg":
|
|
330
|
+ type = 3;
|
|
331
|
+ break;
|
|
332
|
+ }
|
|
333
|
+ MessageDisplayFile msgFile = new MessageDisplayFile(model.user.getId(),timeStamp,this.filePicked.getName(),type,this.filePicked, ext);
|
283
|
334
|
this.listMessages.add(msgFile);
|
284
|
335
|
this.tcpCo.sendMessageFile(msgFile);
|
285
|
336
|
this.filePicked = null;
|