use of org.jivesoftware.spark.ui.ContactList in project Spark by igniterealtime.
the class BroadcastDialog method hideOfflineUsers.
private void hideOfflineUsers() {
int i;
if (OfflineUsers.isSelected()) {
final ContactList contactList = SparkManager.getWorkspace().getContactList();
i = 0;
for (CheckNode node : nodes) {
if (contactList.getContactItemByDisplayName(node.toString()).getPresence().getType() == Presence.Type.unavailable) {
if (node.getParent() != null) {
TreeNode parent = node.getParent();
TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(parent);
((DefaultTreeModel) checkTree.getTree().getModel()).removeNodeFromParent(node);
checkTree.getTree().setSelectionPath(new TreePath(path));
NodesGroups.add(new ArrayList<>());
NodesGroups.get(i).add(parent);
NodesGroups.get(i).add(node);
i++;
}
}
}
for (int x = 0; x < groupNodes.size(); x++) {
if (groupNodes.get(x).toString().equals(Res.getString("group.offline"))) {
OfflineGroup = x;
TreeNode parent = groupNodes.get(x).getParent();
TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(parent);
((DefaultTreeModel) checkTree.getTree().getModel()).removeNodeFromParent(groupNodes.get(x));
checkTree.getTree().setSelectionPath(new TreePath(path));
}
}
} else {
i = 0;
DefaultMutableTreeNode child = groupNodes.get(OfflineGroup);
((DefaultTreeModel) checkTree.getTree().getModel()).insertNodeInto(child, rosterNode, rosterNode.getChildCount());
TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(rosterNode);
checkTree.getTree().expandPath(new TreePath(path));
checkTree.expandTree();
for (CheckNode node : nodes) {
if (node.getParent() == null) {
child = (CheckNode) NodesGroups.get(i).get(1);
((DefaultTreeModel) checkTree.getTree().getModel()).insertNodeInto(child, ((CheckNode) NodesGroups.get(i).get(0)), ((CheckNode) NodesGroups.get(i).get(0)).getChildCount());
path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(node);
checkTree.getTree().expandPath(new TreePath(path));
checkTree.expandTree();
i++;
}
}
}
}
use of org.jivesoftware.spark.ui.ContactList in project Spark by igniterealtime.
the class ReceiveFileTransfer method acceptFileTransfer.
public void acceptFileTransfer(final FileTransferRequest request) {
String fileName = request.getFileName();
long fileSize = request.getFileSize();
String requestor = request.getRequestor();
String bareJID = XmppStringUtils.parseBareJid(requestor);
// SPARK-1869
FileTransferNegotiator.getInstanceFor(SparkManager.getConnection());
FileTransferNegotiator.IBB_ONLY = SettingsManager.getLocalPreferences().isFileTransferIbbOnly();
ByteFormat format = new ByteFormat();
String text = format.format(fileSize);
fileLabel.setText(fileName + " (" + text + ")");
ContactList contactList = SparkManager.getWorkspace().getContactList();
ContactItem contactItem = contactList.getContactItemByJID(bareJID);
titleLabel.setText(Res.getString("message.user.is.sending.you.a.file", contactItem.getDisplayName()));
File tempFile = new File(Spark.getSparkUserHome(), "/tmp");
try {
tempFile.mkdirs();
File file = new File(tempFile, fileName);
file.delete();
BufferedWriter out = new BufferedWriter(new FileWriter(file));
out.write("a");
out.close();
imageLabel.setIcon(GraphicUtils.getIcon(file));
// Delete temp file when program exits.
file.delete();
} catch (IOException e) {
imageLabel.setIcon(SparkRes.getImageIcon(SparkRes.DOCUMENT_INFO_32x32));
Log.error(e);
}
acceptButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
try {
Downloads.checkDownloadDirectory();
acceptRequest(request);
} catch (Exception ex) {
// this means there is a problem with the download directory
try {
request.reject();
} catch (SmackException.NotConnectedException e1) {
Log.warning("Unable to reject the request.", ex);
}
setBackground(new Color(239, 245, 250));
acceptButton.setVisible(false);
declineButton.setVisible(false);
if (Downloads.getDownloadDirectory() == null) {
fileLabel.setText("");
} else {
ResourceUtils.resLabel(fileLabel, null, Res.getString("label.transfer.download.directory") + " " + Downloads.getDownloadDirectory().getAbsolutePath());
}
// option to set a new path for the file-download
pathButton.setVisible(true);
pathButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
Preference p = SparkManager.getPreferenceManager().getPreference(new FileTransferPreference().getNamespace());
// retrieve the filetransfer preferences and show the preference menu
// to the user
SparkManager.getPreferenceManager().showPreferences(p);
}
});
titleLabel.setText(ex.getMessage());
titleLabel.setForeground(new Color(65, 139, 179));
invalidate();
validate();
repaint();
}
}
});
declineButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
rejectRequest(request);
}
});
}
use of org.jivesoftware.spark.ui.ContactList in project Spark by igniterealtime.
the class OutgoingCall method handleOutgoingCall.
/**
* Handles a new outgoing call.
*
* @param session the JingleSession for the outgoing call.
* @param chatRoom the room the session is associated with.
* @param jid the users jid.
*/
public void handleOutgoingCall(final JingleSession session, ChatRoom chatRoom, final String jid) throws SmackException {
this.chatRoom = chatRoom;
JingleStateManager.getInstance().addJingleSession(chatRoom, JingleStateManager.JingleRoomState.ringing);
chatRoom.addClosingListener(this);
session.addListener(this);
cancelButton.setVisible(true);
this.session = session;
// Start the call
this.session.startOutgoing();
fileLabel.setText(jid);
ContactList contactList = SparkManager.getWorkspace().getContactList();
ContactItem contactItem = contactList.getContactItemByJID(jid);
titleLabel.setText(JingleResources.getString("label.outgoing.voicechat", contactItem.getNickname()));
cancelButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
cancel();
}
public void mouseEntered(MouseEvent e) {
cancelButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
public void mouseExited(MouseEvent e) {
cancelButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
});
makeClickable(imageLabel);
makeClickable(titleLabel);
// Notify state change
SparkManager.getChatManager().notifySparkTabHandlers(chatRoom);
updateOutgoingCallPanel();
}
use of org.jivesoftware.spark.ui.ContactList in project Spark by igniterealtime.
the class ScratchPadPlugin method initialize.
public void initialize() {
TimerTask startTask = new TimerTask() {
@Override
public void run() {
EventQueue.invokeLater(() -> {
panel_events = new JPanel();
mainPanel = new JPanel();
});
}
};
TaskEngine.getInstance().schedule(startTask, 500);
ContactList contactList = SparkManager.getWorkspace().getContactList();
contactList.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("control F6"), "viewNotes");
contactList.getActionMap().put("viewNotes", new AbstractAction("viewNotes") {
private static final long serialVersionUID = -3258500919859584696L;
public void actionPerformed(ActionEvent evt) {
// Retrieve notes and dispaly in editor.
retrieveNotes();
}
});
contactList.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("control F5"), "viewTasks");
contactList.getActionMap().put("viewTasks", new AbstractAction("viewTasks") {
private static final long serialVersionUID = 8589614513097901484L;
public void actionPerformed(ActionEvent evt) {
// Retrieve notes and dispaly in editor.
showTaskList();
}
});
// TODO REMOVE
@SuppressWarnings("unused") int index = -1;
JPanel commandPanel = SparkManager.getWorkspace().getCommandPanel();
for (int i = 0; i < commandPanel.getComponentCount(); i++) {
if (commandPanel.getComponent(i) instanceof JLabel) {
break;
}
}
JMenuItem taskMenu = new JMenuItem(Res.getString("button.view.tasklist"), SparkRes.getImageIcon(SparkRes.DESKTOP_IMAGE));
JMenuItem notesMenu = new JMenuItem(Res.getString("button.view.notes"), SparkRes.getImageIcon(SparkRes.DOCUMENT_16x16));
taskMenu.addActionListener(e -> showTaskList());
notesMenu.addActionListener(e -> retrieveNotes());
// Add To toolbar
final JMenu actionsMenu = SparkManager.getMainWindow().getMenuByName(Res.getString("menuitem.actions"));
actionsMenu.addSeparator();
// See if we should disable the "View task list" option under "Actions"
if (!Default.getBoolean("DISABLE_VIEW_TASK_LIST") && Enterprise.containsFeature(Enterprise.VIEW_TASKS_FEATURE))
actionsMenu.add(taskMenu);
// See if we should disable the "View notes" option under "Actions"
if (!Default.getBoolean("DISABLE_VIEW_NOTES") && Enterprise.containsFeature(Enterprise.VIEW_NOTES_FEATURE))
actionsMenu.add(notesMenu);
// Start notifications.
new TaskNotification();
}
use of org.jivesoftware.spark.ui.ContactList in project Spark by igniterealtime.
the class ConversationHistoryPlugin method showHistoryPopup.
/**
* Displays the Previous Conversation Window.
*/
private void showHistoryPopup() {
// Get Transcript Directory
if (!transcriptDir.exists()) {
return;
}
jidMap.clear();
model.clear();
final ContactList contactList = SparkManager.getWorkspace().getContactList();
int limit = historyList.size() > 10 ? 10 : historyList.size();
for (final String user : historyList.subList(0, limit)) {
ContactItem contactItem = contactList.getContactItemByJID(user);
Icon icon;
if (contactItem != null) {
icon = contactItem.getIcon();
if (icon == null) {
icon = SparkRes.getImageIcon(SparkRes.CLEAR_BALL_ICON);
}
JLabel label = new JLabel();
label.setText(contactItem.getDisplayName());
label.setIcon(icon);
model.addElement(label);
jidMap.put(label, user);
}
}
window.setSize(200, 200);
GraphicUtils.centerWindowOnComponent(window, SparkManager.getMainWindow());
if (model.size() > 0) {
contacts.setSelectedIndex(0);
}
window.setVisible(true);
}
Aggregations