MenuItem sendFile = new MenuItem("Send file");
sendFile.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
FileTransferManager fileTransferManager = xmppSession.getExtensionManager(FileTransferManager.class);
FileChooser fileChooser = new FileChooser();
File file = fileChooser.showOpenDialog(stage);
try {
fileTransferManager.offerFile(file, "", xmppSession.getPresenceManager().getPresence(item.contact.get().getJid()).getFrom(), 10000);
} catch (XmppException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
MenuItem timeItem = new MenuItem("Get time");
timeItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
EntityTimeManager entityTimeManager = xmppSession.getExtensionManager(EntityTimeManager.class);
try {
EntityTime entityTime = entityTimeManager.getEntityTime(Jid.valueOf("juliet@example.net/balcony"));
} catch (XmppException e) {
if (e instanceof NoResponseException) {
// The entity did not respond
} else if (e instanceof StanzaException) {
StanzaError stanzaError = ((StanzaException) e).getStanza().getError();
if (stanzaError.getCondition() instanceof ServiceUnavailable) {
// The entity returned a <service-unavailable/> stanza error.
}
}
}
}
});
contextMenu.getItems().addAll(lastActivityMenuItem, pingMenuItem, searchMenuItem, softwareVersionItem, serviceDiscoveryMenuItem, vCardItem, storeAnnotationsItems, getAnnotationsItems, pubSubItem, pepItem, sendFile, timeItem);
setContextMenu(contextMenu);
}
}
};
listCell.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {
if (mouseEvent.getClickCount() == 2 && listCell.getItem() != null) {
Jid chatPartner = listCell.getItem().contact.get().getJid().asBareJid();
ChatWindow chatWindow = windows.get(chatPartner);
if (chatWindow == null) {
chatWindow = new ChatWindow(chatPartner, xmppSession);
windows.put(chatPartner, chatWindow);
}
chatWindow.show();
}
}
});
return listCell;
}
});
listView.setItems(contactItems);
Button btnClose = new Button("Close");
btnClose.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
try {
// Get the avatar manager
AvatarManager avatarManager = xmppSession.getExtensionManager(AvatarManager.class);
//avatarManager.publishAvatar(null);
//xmppSession.close();
//contactItems.clear();
} catch (Exception e) {
e.printStackTrace();
}
}
});
Button btn = new Button("Misc");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
try {
// Get the avatar manager
AvatarManager avatarManager = xmppSession.getExtensionManager(AvatarManager.class);
//avatarManager.publishAvatar(null);
// Choose a file with JavaFX file dialog.
FileChooser fileChooser = new FileChooser();
File file = fileChooser.showOpenDialog(null);
// If the user has chosen a file
if (file != null) {
// Read the file as image.
//BufferedImage bufferedImage = ImageIO.read(file);