use of org.jivesoftware.spark.ui.ContactList in project Spark by igniterealtime.
the class UserManager method searchContacts.
public void searchContacts(String contact, final JFrame parent) {
if (parents.get(parent) == null && parent.getGlassPane() != null) {
parents.put(parent, parent.getGlassPane());
}
// Make sure we are using the default glass pane
final Component glassPane = parents.get(parent);
parent.setGlassPane(glassPane);
final Map<String, ContactItem> contactMap = new HashMap<>();
final List<ContactItem> contacts = new ArrayList<>();
final ContactList contactList = SparkManager.getWorkspace().getContactList();
for (ContactGroup contactGroup : contactList.getContactGroups()) {
contactGroup.clearSelection();
for (ContactItem contactItem : contactGroup.getContactItems()) {
if (!contactMap.containsKey(contactItem.getJID())) {
contacts.add(contactItem);
contactMap.put(contactItem.getJID(), contactItem);
}
}
}
// Sort
Collections.sort(contacts, itemComparator);
final JContactItemField contactField = new JContactItemField(new ArrayList<>(contacts));
JPanel layoutPanel = new JPanel();
layoutPanel.setLayout(new GridBagLayout());
JLabel enterLabel = new JLabel(Res.getString("label.contact.to.find"));
enterLabel.setFont(new Font("dialog", Font.BOLD, 10));
layoutPanel.add(enterLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0));
layoutPanel.add(contactField, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0));
layoutPanel.setBorder(BorderFactory.createBevelBorder(0));
contactField.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent keyEvent) {
if (keyEvent.getKeyChar() == KeyEvent.VK_ENTER) {
if (ModelUtil.hasLength(contactField.getText())) {
ContactItem item = contactMap.get(contactField.getText());
if (item == null) {
item = contactField.getSelectedContactItem();
}
if (item != null) {
parent.setGlassPane(glassPane);
parent.getGlassPane().setVisible(false);
contactField.dispose();
SparkManager.getChatManager().activateChat(item.getJID(), item.getDisplayName());
}
}
} else if (keyEvent.getKeyChar() == KeyEvent.VK_ESCAPE) {
parent.setGlassPane(glassPane);
parent.getGlassPane().setVisible(false);
contactField.dispose();
}
}
});
contactField.getList().addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
contactField.setSelectetIndex(e);
ContactItem item = contactField.getSelectedContactItem();
MouseEvent exx = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), e.getX() + 20, e.getY(), e.getClickCount(), false);
SparkManager.getContactList().setSelectedUser(item.getJID());
SparkManager.getContactList().showPopup(contactField.getPopup(), exx, item);
}
if (e.getClickCount() == 2) {
if (ModelUtil.hasLength(contactField.getText())) {
ContactItem item = contactMap.get(contactField.getText());
if (item == null) {
item = contactField.getSelectedContactItem();
}
if (item != null) {
parent.setGlassPane(glassPane);
parent.getGlassPane().setVisible(false);
contactField.dispose();
SparkManager.getChatManager().activateChat(item.getJID(), item.getDisplayName());
}
}
}
}
});
final JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.setLayout(new GridBagLayout());
mainPanel.add(layoutPanel, new GridBagConstraints(0, 0, 1, 1, 0.5, 0.5, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(SparkManager.getMainWindow().getTopToolBar().getHeight() + SparkManager.getWorkspace().getStatusBar().getHeight() + 47, 1, 5, 1), 200, 0));
mainPanel.setOpaque(false);
contactField.setText(contact);
parent.setGlassPane(mainPanel);
parent.getGlassPane().setVisible(true);
contactField.focus();
mainPanel.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent mouseEvent) {
parent.setGlassPane(glassPane);
parent.getGlassPane().setVisible(false);
contactField.dispose();
}
});
parent.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent) {
parent.setGlassPane(glassPane);
parent.getGlassPane().setVisible(false);
contactField.dispose();
parent.removeWindowListener(this);
}
public void windowDeactivated(final WindowEvent windowEvent) {
TimerTask task = new SwingTimerTask() {
public void doRun() {
if (contactField.canClose()) {
windowClosing(windowEvent);
}
}
};
TaskEngine.getInstance().schedule(task, 250);
}
});
}
use of org.jivesoftware.spark.ui.ContactList in project Spark by igniterealtime.
the class ReceiveFileTransfer method acceptRequest.
private void acceptRequest(final FileTransferRequest request) {
String requestor = request.getRequestor();
String bareJID = XmppStringUtils.parseBareJid(requestor);
ContactList contactList = SparkManager.getWorkspace().getContactList();
final ContactItem contactItem = contactList.getContactItemByJID(bareJID);
setBackground(new Color(239, 245, 250));
acceptButton.setVisible(false);
declineButton.setVisible(false);
titleLabel.setText(Res.getString("message.negotiate.file.transfer"));
titleLabel.setForeground(new Color(65, 139, 179));
add(progressBar, new GridBagConstraints(1, 2, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 150, 0));
add(progressLabel, new GridBagConstraints(1, 3, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 150, 0));
add(cancelButton, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
cancelButton.setVisible(true);
transfer = request.accept();
final File downloadedFile = new File(Downloads.getDownloadDirectory(), request.getFileName());
try {
_starttime = System.currentTimeMillis();
transfer.recieveFile(downloadedFile);
} catch (SmackException | IOException e) {
Log.error(e);
}
// setting it to percent
progressBar.setMaximum(100);
progressBar.setStringPainted(true);
final Timer timer = new Timer();
TimerTask updateProgessBar = new TimerTask() {
@Override
public void run() {
if (transfer.getAmountWritten() >= request.getFileSize() || transfer.getStatus() == FileTransfer.Status.error || transfer.getStatus() == FileTransfer.Status.refused || transfer.getStatus() == FileTransfer.Status.cancelled || transfer.getStatus() == FileTransfer.Status.complete) {
this.cancel();
timer.cancel();
_endtime = System.currentTimeMillis();
updateonFinished(request, downloadedFile);
} else {
// 100 % = Filesize
// x % = Currentsize
long p = (transfer.getAmountWritten() * 100 / transfer.getFileSize());
progressBar.setValue(Math.round(p));
}
}
};
final Timer timer2 = new Timer();
TimerTask updatePrograssBarText = new TimerTask() {
long timenow;
long timeearlier;
long bytesnow;
long bytesearlier;
@Override
public void run() {
if (transfer.getAmountWritten() >= request.getFileSize() || transfer.getStatus() == FileTransfer.Status.error || transfer.getStatus() == FileTransfer.Status.refused || transfer.getStatus() == FileTransfer.Status.cancelled || transfer.getStatus() == FileTransfer.Status.complete) {
this.cancel();
timer2.cancel();
} else {
timenow = System.currentTimeMillis();
bytesnow = transfer.getAmountWritten();
bytesRead = transfer.getAmountWritten();
if (bytesRead == -1) {
bytesRead = 0;
}
ByteFormat format = new ByteFormat();
String text = format.format(bytesRead);
FileTransfer.Status status = transfer.getStatus();
if (status == FileTransfer.Status.in_progress) {
titleLabel.setText(Res.getString("message.receiving.file", contactItem.getDisplayName()));
String speed = TransferUtils.calculateSpeed(bytesnow - bytesearlier, timenow - timeearlier);
String est = TransferUtils.calculateEstimate(bytesnow, transfer.getFileSize(), _starttime, System.currentTimeMillis());
progressLabel.setText(Res.getString("message.transfer.progressbar.text.received", text, speed, est));
} else if (status == FileTransfer.Status.negotiating_stream) {
titleLabel.setText(Res.getString("message.negotiate.stream"));
}
bytesearlier = bytesnow;
timeearlier = timenow;
}
}
};
timer.scheduleAtFixedRate(updateProgessBar, 10, 10);
timer2.scheduleAtFixedRate(updatePrograssBarText, 10, 500);
}
use of org.jivesoftware.spark.ui.ContactList in project Spark by igniterealtime.
the class ReceiveFileTransfer method transferDone.
private void transferDone(final FileTransferRequest request, FileTransfer transfer) {
cancelButton.setVisible(false);
showAlert(true);
String bareJID = XmppStringUtils.parseBareJid(request.getRequestor());
ContactList contactList = SparkManager.getWorkspace().getContactList();
ContactItem contactItem = contactList.getContactItemByJID(bareJID);
titleLabel.setText(Res.getString("message.received.file", contactItem.getDisplayName()));
fileLabel.setText(request.getFileName());
remove(acceptButton);
remove(declineButton);
remove(progressBar);
remove(pathButton);
final TransferButton openFileButton = new TransferButton();
final TransferButton openFolderButton = new TransferButton();
add(openFileButton, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
add(openFolderButton, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
final File downloadedFile = new File(Downloads.getDownloadDirectory(), request.getFileName());
openFileButton.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
openFileButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
public void mouseExited(MouseEvent e) {
openFileButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
public void mousePressed(MouseEvent e) {
launchFile(Downloads.getDownloadDirectory() + File.separator + request.getFileName());
}
});
openFolderButton.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
openFolderButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
public void mouseExited(MouseEvent e) {
openFolderButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
public void mousePressed(MouseEvent event) {
launchFile(Downloads.getDownloadDirectory());
}
});
add(fileLabel, new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
ResourceUtils.resButton(openFileButton, Res.getString("open"));
ResourceUtils.resButton(openFolderButton, Res.getString("open.folder"));
openFileButton.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(73, 113, 196)));
openFileButton.setForeground(new Color(73, 113, 196));
openFileButton.setFont(new Font("Dialog", Font.BOLD, 11));
openFolderButton.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(73, 113, 196)));
openFolderButton.setForeground(new Color(73, 113, 196));
openFolderButton.setFont(new Font("Dialog", Font.BOLD, 11));
imageLabel.setIcon(GraphicUtils.getIcon(downloadedFile));
imageLabel.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
showPopup(e, downloadedFile);
}
public void mouseReleased(MouseEvent e) {
showPopup(e, downloadedFile);
}
});
if (isImage(downloadedFile.getName())) {
try {
URL imageURL = downloadedFile.toURI().toURL();
ImageIcon image = new ImageIcon(imageURL);
image = GraphicUtils.scaleImageIcon(image, 64, 64);
imageLabel.setIcon(image);
} catch (MalformedURLException e) {
Log.error("Could not locate image.", e);
imageLabel.setIcon(SparkRes.getImageIcon(SparkRes.DOCUMENT_INFO_32x32));
}
}
invalidate();
validate();
repaint();
}
use of org.jivesoftware.spark.ui.ContactList in project Spark by igniterealtime.
the class SendFileTransfer method sendFile.
public void sendFile(final OutgoingFileTransfer transfer, FileTransferManager transferManager, final String jid, final String nickname) {
this.transferManager = transferManager;
// SPARK-1869
FileTransferNegotiator.getInstanceFor(SparkManager.getConnection());
FileTransferNegotiator.IBB_ONLY = SettingsManager.getLocalPreferences().isFileTransferIbbOnly();
cancelButton.setVisible(true);
retryButton.setVisible(false);
this.fullJID = jid;
this.nickname = nickname;
this.transfer = transfer;
String fileName = transfer.getFileName();
long fileSize = transfer.getFileSize();
ByteFormat format = new ByteFormat();
String text = format.format(fileSize);
fileToSend = new File(transfer.getFilePath());
imageLabel.setFile(fileToSend);
fileLabel.setText(fileName + " (" + text + ")");
ContactList contactList = SparkManager.getWorkspace().getContactList();
ContactItem contactItem = contactList.getContactItemByJID(jid);
titleLabel.setText(Res.getString("message.transfer.waiting.on.user", contactItem.getDisplayName()));
if (isImage(fileName)) {
try {
URL imageURL = new File(transfer.getFilePath()).toURI().toURL();
ImageIcon image = new ImageIcon(imageURL);
image = GraphicUtils.scaleImageIcon(image, 64, 64);
imageLabel.setIcon(image);
} catch (MalformedURLException e) {
Log.error("Could not locate image.", e);
imageLabel.setIcon(SparkRes.getImageIcon(SparkRes.DOCUMENT_INFO_32x32));
}
} else {
File file = new File(transfer.getFilePath());
Icon icon = GraphicUtils.getIcon(file);
imageLabel.setIcon(icon);
}
cancelButton.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent mouseEvent) {
transfer.cancel();
}
});
cancelButton.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
cancelButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
public void mouseExited(MouseEvent e) {
cancelButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
});
progressBar.setMaximum(100);
progressBar.setVisible(false);
progressBar.setStringPainted(true);
add(progressBar, new GridBagConstraints(1, 2, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 150, 0));
add(progressLabel, new GridBagConstraints(1, 3, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 150, 0));
SwingWorker worker = new SwingWorker() {
public Object construct() {
while (true) {
try {
if (transfer.getBytesSent() > 0 && _starttime == 0) {
_starttime = System.currentTimeMillis();
}
long starttime = System.currentTimeMillis();
long startbyte = transfer.getBytesSent();
Thread.sleep(500);
FileTransfer.Status status = transfer.getStatus();
if (status == Status.error || status == Status.complete || status == Status.cancelled || status == Status.refused) {
break;
}
long endtime = System.currentTimeMillis();
long endbyte = transfer.getBytesSent();
long timediff = endtime - starttime;
long bytediff = endbyte - startbyte;
updateBar(transfer, nickname, TransferUtils.calculateSpeed(bytediff, timediff));
} catch (InterruptedException e) {
Log.error("Unable to sleep thread.", e);
}
}
return "";
}
public void finished() {
updateBar(transfer, nickname, "??MB/s");
}
};
worker.start();
makeClickable(imageLabel);
makeClickable(titleLabel);
}
use of org.jivesoftware.spark.ui.ContactList in project Spark by igniterealtime.
the class ContactListAssistantPlugin method initialize.
@Override
public void initialize() {
moveToMenu = new JMenu(Res.getString("menuitem.move.to"));
copyToMenu = new JMenu(Res.getString("menuitem.copy.to"));
localPreferences = new LocalPreferences();
final ContactList contactList = SparkManager.getContactList();
contactList.addContextMenuListener(new ContextMenuListener() {
@Override
public void poppingUp(Object object, final JPopupMenu popup) {
final Collection<ContactItem> contactItems = Collections.unmodifiableCollection(contactList.getSelectedUsers());
if (!contactItems.isEmpty()) {
final List<ContactGroup> contactGroups = contactList.getContactGroups();
Collections.sort(contactGroups, ContactList.GROUP_COMPARATOR);
for (final ContactGroup group : contactGroups) {
if (group.isUnfiledGroup() || group.isOfflineGroup()) {
continue;
}
if (isContactItemInGroup(contactItems, group)) {
continue;
}
final Action moveAction = new AbstractAction() {
private static final long serialVersionUID = 6542011870221162331L;
@Override
public void actionPerformed(ActionEvent actionEvent) {
moveItems(contactItems, group.getGroupName());
}
};
final Action copyAction = new AbstractAction() {
private static final long serialVersionUID = 2232885525630977329L;
@Override
public void actionPerformed(ActionEvent actionEvent) {
copyItems(contactItems, group.getGroupName());
}
};
moveAction.putValue(Action.NAME, group.getGroupName());
moveToMenu.add(moveAction);
copyAction.putValue(Action.NAME, group.getGroupName());
copyToMenu.add(copyAction);
}
popup.addPopupMenuListener(new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent popupMenuEvent) {
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent popupMenuEvent) {
moveToMenu.removeAll();
copyToMenu.removeAll();
popup.removePopupMenuListener(this);
}
@Override
public void popupMenuCanceled(PopupMenuEvent popupMenuEvent) {
moveToMenu.removeAll();
copyToMenu.removeAll();
popup.removePopupMenuListener(this);
}
});
int index = -1;
if (!Default.getBoolean("DISABLE_RENAMES") && Enterprise.containsFeature(Enterprise.RENAMES_FEATURE)) {
for (int i = 0; i < popup.getComponentCount(); i++) {
Object o = popup.getComponent(i);
if (o instanceof JMenuItem && ((JMenuItem) o).getText().equals(Res.getString("menuitem.rename"))) {
index = i;
break;
}
}
} else
index = 3;
if (contactItems.size() == 1) {
// Add MOVE/COPY options right after the RENAME option or in it's place if it doesn't exist.
if (index != -1) {
// See if we should disable the "Move to" and "Copy to" menu options
if (!Default.getBoolean("DISABLE_MOVE_AND_COPY") && Enterprise.containsFeature(Enterprise.MOVE_COPY_FEATURE)) {
popup.add(moveToMenu, index + 1);
popup.add(copyToMenu, index + 2);
}
}
} else if (contactItems.size() > 1) {
// See if we should disable the "Move to" and "Copy to" menu options
if (!Default.getBoolean("DISABLE_MOVE_AND_COPY") && Enterprise.containsFeature(Enterprise.MOVE_COPY_FEATURE)) {
popup.addSeparator();
popup.add(moveToMenu);
popup.add(copyToMenu);
}
// Clean up the extra separator if "Broadcast" menu items are disabled
if (!Default.getBoolean("DISABLE_BROADCAST_MENU_ITEM") && Enterprise.containsFeature(Enterprise.BROADCAST_FEATURE))
popup.addSeparator();
}
}
}
@Override
public void poppingDown(JPopupMenu popup) {
}
@Override
public boolean handleDefaultAction(MouseEvent e) {
return false;
}
});
updateAvatarsInContactList();
SettingsManager.addPreferenceListener(preference -> updateAvatarsInContactList());
}
Aggregations